@@ -21,6 +21,9 @@ import Decorators.*
21
21
* @param newOwners New owners, replacing previous owners.
22
22
* @param substFrom The symbols that need to be substituted.
23
23
* @param substTo The substitution targets.
24
+ * @param cpy A tree copier that is used to create new trees.
25
+ * @param alwaysCopySymbols If set, symbols are always copied, even when they
26
+ * are not impacted by the transformation.
24
27
*
25
28
* The reason the substitution is broken out from the rest of the type map is
26
29
* that all symbols have to be substituted at the same time. If we do not do this,
@@ -38,7 +41,9 @@ class TreeTypeMap(
38
41
val newOwners : List [Symbol ] = Nil ,
39
42
val substFrom : List [Symbol ] = Nil ,
40
43
val substTo : List [Symbol ] = Nil ,
41
- cpy : tpd.TreeCopier = tpd.cpy)(using Context ) extends tpd.TreeMap (cpy) {
44
+ cpy : tpd.TreeCopier = tpd.cpy,
45
+ alwaysCopySymbols : Boolean = false ,
46
+ )(using Context ) extends tpd.TreeMap (cpy) {
42
47
import tpd .*
43
48
44
49
def copy (
@@ -48,7 +53,7 @@ class TreeTypeMap(
48
53
newOwners : List [Symbol ],
49
54
substFrom : List [Symbol ],
50
55
substTo : List [Symbol ])(using Context ): TreeTypeMap =
51
- new TreeTypeMap (typeMap, treeMap, oldOwners, newOwners, substFrom, substTo)
56
+ new TreeTypeMap (typeMap, treeMap, oldOwners, newOwners, substFrom, substTo, cpy, alwaysCopySymbols )
52
57
53
58
/** If `sym` is one of `oldOwners`, replace by corresponding symbol in `newOwners` */
54
59
def mapOwner (sym : Symbol ): Symbol = sym.subst(oldOwners, newOwners)
@@ -202,7 +207,7 @@ class TreeTypeMap(
202
207
* between original and mapped symbols.
203
208
*/
204
209
def withMappedSyms (syms : List [Symbol ]): TreeTypeMap =
205
- withMappedSyms(syms, mapSymbols(syms, this ))
210
+ withMappedSyms(syms, mapSymbols(syms, this , mapAlways = alwaysCopySymbols ))
206
211
207
212
/** The tree map with the substitution between originals `syms`
208
213
* and mapped symbols `mapped`. Also goes into mapped classes
@@ -224,6 +229,10 @@ class TreeTypeMap(
224
229
tmap1
225
230
}
226
231
232
+ def withAlwaysCopySymbols : TreeTypeMap =
233
+ if alwaysCopySymbols then this
234
+ else new TreeTypeMap (typeMap, treeMap, oldOwners, newOwners, substFrom, substTo, cpy, alwaysCopySymbols = true )
235
+
227
236
override def toString =
228
237
def showSyms (syms : List [Symbol ]) =
229
238
syms.map(sym => s " $sym# ${sym.id}" ).mkString(" , " )
0 commit comments