Skip to content

Commit 7bfd48d

Browse files
committed
Harden ReTyper so that it's fit for inlining
1. Imlement typedUnapply 2. Disable implicit view searches and searches for equality checks - these should have already happened in the first typer run.
1 parent 545f565 commit 7bfd48d

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
862862
/** A typed unapply hook, can be overridden by re any-typers between frontend
863863
* and pattern matcher.
864864
*/
865-
def typedUnApply(tree: untpd.UnApply, selType: Type)(implicit ctx: Context) =
865+
def typedUnApply(tree: untpd.UnApply, selType: Type)(implicit ctx: Context): UnApply =
866866
throw new UnsupportedOperationException("cannot type check an UnApply node")
867867

868868
/** Is given method reference applicable to type arguments `targs` and argument trees `args`?

src/dotty/tools/dotc/typer/ReTyper.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import typer.ProtoTypes._
1010
import ast.{tpd, untpd}
1111
import ast.Trees._
1212
import scala.util.control.NonFatal
13+
import util.Positions.Position
1314
import config.Printers.typr
1415

1516
/** A version of Typer that keeps all symbols defined and referenced in a
@@ -62,6 +63,13 @@ class ReTyper extends Typer {
6263
untpd.cpy.Bind(tree)(tree.name, body1).withType(tree.typeOpt)
6364
}
6465

66+
override def typedUnApply(tree: untpd.UnApply, selType: Type)(implicit ctx: Context): UnApply = {
67+
val fun1 = typedExpr(tree.fun, AnyFunctionProto)
68+
val implicits1 = tree.implicits.map(typedExpr(_))
69+
val patterns1 = tree.patterns.mapconserve(pat => typed(pat, pat.tpe))
70+
untpd.cpy.UnApply(tree)(fun1, implicits1, patterns1).withType(tree.tpe)
71+
}
72+
6573
override def localDummy(cls: ClassSymbol, impl: untpd.Template)(implicit ctx: Context) = impl.symbol
6674

6775
override def retrieveSym(tree: untpd.Tree)(implicit ctx: Context): Symbol = tree.symbol
@@ -99,4 +107,7 @@ class ReTyper extends Typer {
99107
}
100108

101109
override def checkVariance(tree: Tree)(implicit ctx: Context) = ()
110+
override def inferView(from: Tree, to: Type)(implicit ctx: Context): Implicits.SearchResult =
111+
Implicits.NoImplicitMatches
112+
override def checkCanEqual(ltp: Type, rtp: Type, pos: Position)(implicit ctx: Context): Unit = ()
102113
}

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
15331533
}
15341534
}
15351535

1536-
def adapt(tree: Tree, pt: Type, original: untpd.Tree = untpd.EmptyTree)(implicit ctx: Context) = /*>|>*/ track("adapt") /*<|<*/ {
1536+
def adapt(tree: Tree, pt: Type, original: untpd.Tree = untpd.EmptyTree)(implicit ctx: Context): Tree = /*>|>*/ track("adapt") /*<|<*/ {
15371537
/*>|>*/ ctx.traceIndented(i"adapting $tree of type ${tree.tpe} to $pt", typr, show = true) /*<|<*/ {
15381538
if (tree.isDef) interpolateUndetVars(tree, tree.symbol)
15391539
else if (!tree.tpe.widen.isInstanceOf[MethodOrPoly]) interpolateUndetVars(tree, NoSymbol)

0 commit comments

Comments
 (0)