@@ -34,6 +34,8 @@ import ast.TreeInfo
3434object Inliner {
3535 import tpd ._
3636
37+ val typedInline = true
38+
3739 /** A key to be used in a context property that provides a map from enclosing implicit
3840 * value bindings to their right hand sides.
3941 */
@@ -382,7 +384,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
382384 // Compute bindings for all this-proxies, appending them to bindingsBuf
383385 computeThisBindings()
384386
385- val inlineTyper = new InlineTyper
387+ val inlineTyper =
388+ if (typedInline) new InlineReTyper else new TransparentTyper
389+
386390 val inlineCtx = inlineContext(call).fresh.setTyper(inlineTyper).setNewScope
387391
388392 // A tree type map to prepare the inlined body for typechecked.
@@ -857,7 +861,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
857861 * 4. Make sure inlined code is type-correct.
858862 * 5. Make sure that the tree's typing is idempotent (so that future -Ycheck passes succeed)
859863 */
860- class InlineTyper extends Typer {
864+ trait InlineTyping extends Typer {
861865 import reducer ._
862866
863867 override def ensureAccessible (tpe : Type , superAccess : Boolean , pos : Position )(implicit ctx : Context ): Type = {
@@ -873,12 +877,6 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
873877 super .ensureAccessible(tpe, superAccess, pos)
874878 }
875879
876- override def typedTypedSplice (tree : untpd.TypedSplice )(implicit ctx : Context ): Tree =
877- reduceProjection(tryInline(tree.splice) `orElse` super .typedTypedSplice(tree))
878-
879- override def typedSelect (tree : untpd.Select , pt : Type )(implicit ctx : Context ) =
880- constToLiteral(reduceProjection(super .typedSelect(tree, pt)))
881-
882880 override def typedIf (tree : untpd.If , pt : Type )(implicit ctx : Context ) =
883881 typed(tree.cond, defn.BooleanType ) match {
884882 case cond1 @ ConstantValue (b : Boolean ) =>
@@ -895,6 +893,19 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
895893 super .typedIf(if1, pt)
896894 }
897895
896+ override def typedApply (tree : untpd.Apply , pt : Type )(implicit ctx : Context ) =
897+ constToLiteral(betaReduce(super .typedApply(tree, pt)))
898+ }
899+
900+ private class TransparentTyper extends Typer with InlineTyping {
901+ import reducer ._
902+
903+ override def typedTypedSplice (tree : untpd.TypedSplice )(implicit ctx : Context ): Tree =
904+ reduceProjection(tryInline(tree.splice) `orElse` super .typedTypedSplice(tree))
905+
906+ override def typedSelect (tree : untpd.Select , pt : Type )(implicit ctx : Context ) =
907+ constToLiteral(reduceProjection(super .typedSelect(tree, pt)))
908+
898909 override def typedMatchFinish (tree : untpd.Match , sel : Tree , selType : Type , pt : Type )(implicit ctx : Context ) = tree match {
899910 case _ : untpd.InlineMatch if ! ctx.owner.isInlineMethod => // don't reduce match of nested inline method yet
900911 reduceInlineMatch(sel, sel.tpe, tree.cases, this ) match {
@@ -916,10 +927,24 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
916927 super .typedMatchFinish(tree, sel, selType, pt)
917928 }
918929
919- override def typedApply (tree : untpd.Apply , pt : Type )(implicit ctx : Context ) =
920- constToLiteral(betaReduce(super .typedApply(tree, pt)))
930+ override def newLikeThis : Typer = new TransparentTyper
931+ }
932+
933+ private class InlineReTyper extends ReTyper with InlineTyping {
934+ import reducer ._
935+
936+ override def typedIdent (tree : untpd.Ident , pt : Type )(implicit ctx : Context ) =
937+ tryInline(tree.asInstanceOf [tpd.Tree ]) `orElse` super .typedIdent(tree, pt)
938+
939+ override def typedSelect (tree : untpd.Select , pt : Type )(implicit ctx : Context ): Tree = {
940+ assert(tree.hasType, tree)
941+ val qual1 = typed(tree.qualifier, selectionProto(tree.name, pt, this ))
942+ val res = untpd.cpy.Select (tree)(qual1, tree.name).withType(tree.typeOpt)
943+ ensureAccessible(res.tpe, tree.qualifier.isInstanceOf [untpd.Super ], tree.pos)
944+ res
945+ }
921946
922- override def newLikeThis : Typer = new InlineTyper
947+ override def newLikeThis : Typer = new InlineReTyper
923948 }
924949
925950 /** Drop any side-effect-free bindings that are unused in expansion or other reachable bindings.
0 commit comments