@@ -22,6 +22,8 @@ import core.tasty.TreePickler.Hole
22
22
* @param newOwners New owners, replacing previous owners.
23
23
* @param substFrom The symbols that need to be substituted.
24
24
* @param substTo The substitution targets.
25
+ * @param stopAtInlinedArgument Whether one should stop at an inlined argument,
26
+ * i.e. a node of form Inlined(EmptyTree, _, _).
25
27
*
26
28
* The reason the substitution is broken out from the rest of the type map is
27
29
* that all symbols have to be substituted at the same time. If we do not do this,
@@ -31,14 +33,19 @@ import core.tasty.TreePickler.Hole
31
33
* do S2 we get outer#2.inner#4. But that means that the named type outer#2.inner
32
34
* gets two different denotations in the same period. Hence, if -Yno-double-bindings is
33
35
* set, we would get a data race assertion error.
36
+ *
37
+ * Note: TreeTypeMap is final, since derived maps are created dynamically for
38
+ * nested scopes. Any subclass of TreeTypeMap would revert to the standard
39
+ * TreeTypeMap in these recursive invocations.
34
40
*/
35
- class TreeTypeMap (
41
+ final class TreeTypeMap (
36
42
val typeMap : Type => Type = IdentityTypeMap ,
37
43
val treeMap : tpd.Tree => tpd.Tree = identity _,
38
44
val oldOwners : List [Symbol ] = Nil ,
39
45
val newOwners : List [Symbol ] = Nil ,
40
46
val substFrom : List [Symbol ] = Nil ,
41
- val substTo : List [Symbol ] = Nil )(using Context ) extends tpd.TreeMap {
47
+ val substTo : List [Symbol ] = Nil ,
48
+ stopAtInlinedArgument : Boolean = false )(using Context ) extends tpd.TreeMap {
42
49
import tpd ._
43
50
44
51
/** If `sym` is one of `oldOwners`, replace by corresponding symbol in `newOwners` */
@@ -76,8 +83,11 @@ class TreeTypeMap(
76
83
updateDecls(prevStats.tail, newStats.tail)
77
84
}
78
85
79
- /** If true, stop return Inlined(Empty, _, _) nodes unchanged */
80
- def stopAtInlinedArgument : Boolean = false
86
+ def transformInlined (tree : tpd.Inlined )(using Context ): tpd.Tree =
87
+ val Inlined (call, bindings, expanded) = tree
88
+ val (tmap1, bindings1) = transformDefs(bindings)
89
+ val expanded1 = tmap1.transform(expanded)
90
+ cpy.Inlined (tree)(call, bindings1, expanded1)
81
91
82
92
override def transform (tree : tpd.Tree )(using Context ): tpd.Tree = treeMap(tree) match {
83
93
case impl @ Template (constr, parents, self, _) =>
@@ -111,7 +121,9 @@ class TreeTypeMap(
111
121
cpy.Block (blk)(stats1, expr1)
112
122
case inlined @ Inlined (call, bindings, expanded) =>
113
123
if stopAtInlinedArgument && call.isEmpty then
114
- inlined
124
+ expanded match
125
+ case expanded : TypeTree => assert(bindings.isEmpty); expanded
126
+ case _ => inlined
115
127
else
116
128
val (tmap1, bindings1) = transformDefs(bindings)
117
129
val expanded1 = tmap1.transform(expanded)
@@ -177,7 +189,8 @@ class TreeTypeMap(
177
189
from ++ oldOwners,
178
190
to ++ newOwners,
179
191
from ++ substFrom,
180
- to ++ substTo)
192
+ to ++ substTo,
193
+ stopAtInlinedArgument)
181
194
}
182
195
183
196
/** Apply `typeMap` and `ownerMap` to given symbols `syms`
0 commit comments