@@ -461,24 +461,19 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
461461 }
462462
463463 // Drop unused bindings
464- val matchBindings = reducer.matchBindingsBuf.toList
465- val (finalBindings, finalExpansion) = dropUnusedDefs(bindingsBuf.toList ++ matchBindings, expansion1)
466- val (finalMatchBindings, finalArgBindings) = finalBindings.partition(matchBindings.contains(_))
464+ val (finalBindings, finalExpansion) = dropUnusedDefs(bindingsBuf.toList, expansion1)
467465
468466 if (inlinedMethod == defn.Typelevel_error ) issueError()
469467
470468 // Take care that only argument bindings go into `bindings`, since positions are
471469 // different for bindings from arguments and bindings from body.
472- tpd.Inlined (call, finalArgBindings, seq(finalMatchBindings, finalExpansion) )
470+ tpd.Inlined (call, finalBindings, finalExpansion)
473471 }
474472 }
475473
476474 /** A utility object offering methods for rewriting inlined code */
477475 object reducer {
478476
479- /** Additional bindings established by reducing match expressions */
480- val matchBindingsBuf = new mutable.ListBuffer [MemberDef ]
481-
482477 /** An extractor for terms equivalent to `new C(args)`, returning the class `C`,
483478 * a list of bindings, and the arguments `args`. Can see inside blocks and Inlined nodes and can
484479 * follow a reference to an inline value binding to its right hand side.
@@ -599,7 +594,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
599594 def unapply (tree : Trees .Ident [_])(implicit ctx : Context ): Option [Tree ] = {
600595 def search (buf : mutable.ListBuffer [MemberDef ]) = buf.find(_.name == tree.name)
601596 if (paramProxies.contains(tree.typeOpt))
602- search(bindingsBuf).orElse(search(matchBindingsBuf)) match {
597+ search(bindingsBuf) match {
603598 case Some (vdef : ValDef ) if vdef.symbol.is(Inline ) =>
604599 Some (integrate(vdef.rhs, vdef.symbol))
605600 case Some (ddef : DefDef ) =>
@@ -611,7 +606,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
611606 }
612607
613608 object ConstantValue {
614- def unapply (tree : Tree )(implicit ctx : Context ): Option [Any ] = tree.tpe.widenTermRefExpr match {
609+ def unapply (tree : Tree )(implicit ctx : Context ): Option [Any ] = tree.tpe.widenTermRefExpr.normalized match {
615610 case ConstantType (Constant (x)) => Some (x)
616611 case _ => None
617612 }
@@ -662,7 +657,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
662657 * for the pattern-bound variables and the RHS of the selected case.
663658 * Returns `None` if no case was selected.
664659 */
665- type MatchRedux = Option [(List [MemberDef ], untpd .Tree )]
660+ type MatchRedux = Option [(List [MemberDef ], tpd .Tree )]
666661
667662 /** Reduce an inline match
668663 * @param mtch the match tree
@@ -674,7 +669,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
674669 * @return optionally, if match can be reduced to a matching case: A pair of
675670 * bindings for all pattern-bound variables and the RHS of the case.
676671 */
677- def reduceInlineMatch (scrutinee : Tree , scrutType : Type , cases : List [untpd. CaseDef ], typer : Typer )(implicit ctx : Context ): MatchRedux = {
672+ def reduceInlineMatch (scrutinee : Tree , scrutType : Type , cases : List [CaseDef ], typer : Typer )(implicit ctx : Context ): MatchRedux = {
678673
679674 val isImplicit = scrutinee.isEmpty
680675 val gadtSyms = typer.gadtSyms(scrutType)
@@ -712,7 +707,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
712707 val getBoundVars = new TreeAccumulator [List [TypeSymbol ]] {
713708 def apply (syms : List [TypeSymbol ], t : Tree )(implicit ctx : Context ) = {
714709 val syms1 = t match {
715- case t : Bind if t.symbol.isType && t.name != tpnme. WILDCARD =>
710+ case t : Bind if t.symbol.isType =>
716711 t.symbol.asType :: syms
717712 case _ =>
718713 syms
@@ -739,7 +734,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
739734 // ConstraintHandler#approximation does. However, this only works for constrained paramrefs
740735 // not GADT-bound variables. Hopefully we will get some way to improve this when we
741736 // re-implement GADTs in terms of constraints.
742- bindingsBuf += TypeDef (bv)
737+ if (bv.name != nme. WILDCARD ) bindingsBuf += TypeDef (bv)
743738 }
744739 reducePattern(bindingsBuf, scrut, pat1)
745740 }
@@ -805,7 +800,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
805800 val scrutineeSym = newSym(InlineScrutineeName .fresh(), Synthetic , scrutType).asTerm
806801 val scrutineeBinding = normalizeBinding(ValDef (scrutineeSym, scrutinee))
807802
808- def reduceCase (cdef : untpd. CaseDef ): MatchRedux = {
803+ def reduceCase (cdef : CaseDef ): MatchRedux = {
809804 val caseBindingsBuf = new mutable.ListBuffer [MemberDef ]()
810805 def guardOK (implicit ctx : Context ) = cdef.guard.isEmpty || {
811806 val guardCtx = ctx.fresh.setNewScope
@@ -824,7 +819,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
824819 None
825820 }
826821
827- def recur (cases : List [untpd. CaseDef ]): MatchRedux = cases match {
822+ def recur (cases : List [CaseDef ]): MatchRedux = cases match {
828823 case Nil => None
829824 case cdef :: cases1 => reduceCase(cdef) `orElse` recur(cases1)
830825 }
@@ -895,14 +890,15 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
895890 super .typedMatchFinish(tree, sel, wideSelType, cases, pt)
896891 else {
897892 val selType = if (sel.isEmpty) wideSelType else sel.tpe
898- reduceInlineMatch(sel, selType, cases, this ) match {
899- case Some ((caseBindings, rhs)) =>
900- var rhsCtx = ctx.fresh.setNewScope
901- for (binding <- caseBindings) {
902- matchBindingsBuf += binding
903- rhsCtx.enter(binding.symbol)
904- }
905- typedExpr(rhs, pt)(rhsCtx)
893+ reduceInlineMatch(sel, selType, cases.asInstanceOf [List [CaseDef ]], this ) match {
894+ case Some ((caseBindings, rhs0)) =>
895+ val (usedBindings, rhs1) = dropUnusedDefs(caseBindings, rhs0)
896+ val rhs = seq(usedBindings, rhs1)
897+ inlining.println(i """ --- reduce:
898+ | $tree
899+ |--- to:
900+ | $rhs""" )
901+ typedExpr(rhs, pt)
906902 case None =>
907903 def guardStr (guard : untpd.Tree ) = if (guard.isEmpty) " " else i " if $guard"
908904 def patStr (cdef : untpd.CaseDef ) = i " case ${cdef.pat}${guardStr(cdef.guard)}"
@@ -993,7 +989,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
993989 val dealiasedType = dealias(t.tpe)
994990 val t1 = t match {
995991 case t : RefTree =>
996- if (boundTypes.contains(t.symbol)) TypeTree (dealiasedType).withPos(t.pos)
992+ if (t.name != nme. WILDCARD && boundTypes.contains(t.symbol)) TypeTree (dealiasedType).withPos(t.pos)
997993 else t.withType(dealiasedType)
998994 case t : DefTree =>
999995 t.symbol.info = dealias(t.symbol.info)
0 commit comments