@@ -17,14 +17,17 @@ import collection.mutable
17
17
private val Captures : Key [CaptureSet ] = Key ()
18
18
private val BoxedType : Key [BoxedTypeCache ] = Key ()
19
19
20
- private val enableRootMapping = true
21
-
22
20
/** Switch whether unpickled function types and byname types should be mapped to
23
21
* impure types. With the new gradual typing using Fluid capture sets, this should
24
22
* be no longer needed. Also, it has bad interactions with pickling tests.
25
23
*/
26
24
private val adaptUnpickledFunctionTypes = false
27
25
26
+ /** Switch whether we constrain a root var that includes the source of a
27
+ * root map to be an alias of that source (so that it can be mapped)
28
+ */
29
+ private val constrainRootsWhenMapping = true
30
+
28
31
/** The arguments of a @retains or @retainsByName annotation */
29
32
private [cc] def retainedElems (tree : Tree )(using Context ): List [Tree ] = tree match
30
33
case Apply (_, Typed (SeqLiteral (elems, _), _) :: Nil ) => elems
@@ -77,21 +80,22 @@ trait FollowAliases extends TypeMap:
77
80
class mapRoots (from : CaptureRoot , to : CaptureRoot )(using Context ) extends BiTypeMap , FollowAliases :
78
81
thisMap =>
79
82
80
- def apply (t : Type ): Type = t match
81
- case t : TermRef if (t eq from) && enableRootMapping =>
82
- to
83
- case t : CaptureRoot .Var =>
84
- val ta = t.followAlias
85
- if ta ne t then apply(ta)
86
- else from match
87
- case from : TermRef
88
- if t.upperLevel >= from.symbol.ccNestingLevel
89
- && CaptureRoot .isEnclosingRoot(from, t)
90
- && CaptureRoot .isEnclosingRoot(t, from) => to
91
- case from : CaptureRoot .Var if from.followAlias eq t => to
92
- case _ => from
93
- case _ =>
94
- mapOverFollowingAliases(t)
83
+ def apply (t : Type ): Type =
84
+ if t eq from then to
85
+ else t match
86
+ case t : CaptureRoot .Var =>
87
+ val ta = t.followAlias
88
+ if ta ne t then apply(ta)
89
+ else from match
90
+ case from : TermRef
91
+ if t.upperLevel >= from.symbol.ccNestingLevel
92
+ && constrainRootsWhenMapping // next two lines do the constraining
93
+ && CaptureRoot .isEnclosingRoot(from, t)
94
+ && CaptureRoot .isEnclosingRoot(t, from) => to
95
+ case from : CaptureRoot .Var if from.followAlias eq t => to
96
+ case _ => t
97
+ case _ =>
98
+ mapOverFollowingAliases(t)
95
99
96
100
def inverse = mapRoots(to, from)
97
101
end mapRoots
0 commit comments