@@ -1056,8 +1056,29 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
10561056 */
10571057 def dropUnusedDefs (bindings : List [MemberDef ], tree : Tree )(implicit ctx : Context ): (List [MemberDef ], Tree ) = {
10581058 // inlining.println(i"drop unused $bindings%, % in $tree")
1059-
1060- def inlineTermBindings (termBindings : List [MemberDef ], tree : Tree )(implicit ctx : Context ): (List [MemberDef ], Tree ) = {
1059+ val (termBindings, typeBindings) = bindings.partition(_.symbol.isTerm)
1060+ if (typeBindings.nonEmpty) {
1061+ val typeBindingsSet = typeBindings.foldLeft[SimpleIdentitySet [Symbol ]](SimpleIdentitySet .empty)(_ + _.symbol)
1062+ val inlineTypeBindings = new TreeTypeMap (
1063+ typeMap = new TypeMap () {
1064+ override def apply (tp : Type ): Type = tp match {
1065+ case tr : TypeRef if tr.prefix.eq(NoPrefix ) && typeBindingsSet.contains(tr.symbol) =>
1066+ val TypeAlias (res) = tr.info
1067+ res
1068+ case tp => mapOver(tp)
1069+ }
1070+ },
1071+ treeMap = {
1072+ case ident : Ident if ident.isType && typeBindingsSet.contains(ident.symbol) =>
1073+ val TypeAlias (r) = ident.symbol.info
1074+ TypeTree (r).withSpan(ident.span)
1075+ case tree => tree
1076+ }
1077+ )
1078+ val Block (termBindings1, tree1) = inlineTypeBindings(Block (termBindings, tree))
1079+ dropUnusedDefs(termBindings1.asInstanceOf [List [ValOrDefDef ]], tree1)
1080+ }
1081+ else {
10611082 val refCount = newMutableSymbolMap[Int ]
10621083 val bindingOfSym = newMutableSymbolMap[MemberDef ]
10631084
@@ -1066,7 +1087,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
10661087 case vdef @ ValDef (_, _, _) => isPureExpr(vdef.rhs)
10671088 case _ => false
10681089 }
1069- for (binding <- termBindings if isInlineable(binding)) {
1090+ for (binding <- bindings if isInlineable(binding)) {
10701091 refCount(binding.symbol) = 0
10711092 bindingOfSym(binding.symbol) = binding
10721093 }
@@ -1124,40 +1145,15 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
11241145 }
11251146 }
11261147
1127- val retained = termBindings .filterConserve(binding => retain(binding.symbol))
1128- if (retained `eq` termBindings ) {
1129- (termBindings , tree)
1148+ val retained = bindings .filterConserve(binding => retain(binding.symbol))
1149+ if (retained `eq` bindings ) {
1150+ (bindings , tree)
11301151 }
11311152 else {
11321153 val expanded = inlineBindings.transform(tree)
11331154 dropUnusedDefs(retained, expanded)
11341155 }
11351156 }
1136-
1137- val (termBindings, typeBindings) = bindings.partition(_.symbol.isTerm)
1138- if (typeBindings.isEmpty) inlineTermBindings(termBindings, tree)
1139- else {
1140- val typeBindingsSet = typeBindings.foldLeft[SimpleIdentitySet [Symbol ]](SimpleIdentitySet .empty)(_ + _.symbol)
1141- val inlineTypeBindings = new TreeTypeMap (
1142- typeMap = new TypeMap () {
1143- override def apply (tp : Type ): Type = tp match {
1144- case tr : TypeRef if tr.prefix.eq(NoPrefix ) && typeBindingsSet.contains(tr.symbol) =>
1145- val TypeAlias (res) = tr.info
1146- res
1147- case tp => mapOver(tp)
1148- }
1149- },
1150- treeMap = {
1151- case ident : Ident if ident.isType && typeBindingsSet.contains(ident.symbol) =>
1152- val TypeAlias (r) = ident.symbol.info
1153- TypeTree (r).withSpan(ident.span)
1154- case tree => tree
1155- }
1156- )
1157-
1158- val Block (termBindings1, tree1) = inlineTypeBindings(Block (termBindings, tree))
1159- inlineTermBindings(termBindings1.asInstanceOf [List [ValOrDefDef ]], tree1)
1160- }
11611157 }
11621158
11631159 private def expandMacro (body : Tree , span : Span )(implicit ctx : Context ) = {
0 commit comments