@@ -1056,8 +1056,29 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
1056
1056
*/
1057
1057
def dropUnusedDefs (bindings : List [MemberDef ], tree : Tree )(implicit ctx : Context ): (List [MemberDef ], Tree ) = {
1058
1058
// 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 {
1061
1082
val refCount = newMutableSymbolMap[Int ]
1062
1083
val bindingOfSym = newMutableSymbolMap[MemberDef ]
1063
1084
@@ -1066,7 +1087,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
1066
1087
case vdef @ ValDef (_, _, _) => isPureExpr(vdef.rhs)
1067
1088
case _ => false
1068
1089
}
1069
- for (binding <- termBindings if isInlineable(binding)) {
1090
+ for (binding <- bindings if isInlineable(binding)) {
1070
1091
refCount(binding.symbol) = 0
1071
1092
bindingOfSym(binding.symbol) = binding
1072
1093
}
@@ -1124,40 +1145,15 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
1124
1145
}
1125
1146
}
1126
1147
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)
1130
1151
}
1131
1152
else {
1132
1153
val expanded = inlineBindings.transform(tree)
1133
1154
dropUnusedDefs(retained, expanded)
1134
1155
}
1135
1156
}
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
- }
1161
1157
}
1162
1158
1163
1159
private def expandMacro (body : Tree , span : Span )(implicit ctx : Context ) = {
0 commit comments