Skip to content

Commit bec5eda

Browse files
committed
Add config switch for mapRoots to constrain root vars or not
1 parent ab76eb2 commit bec5eda

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureOps.scala

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ import collection.mutable
1717
private val Captures: Key[CaptureSet] = Key()
1818
private val BoxedType: Key[BoxedTypeCache] = Key()
1919

20-
private val enableRootMapping = true
21-
2220
/** Switch whether unpickled function types and byname types should be mapped to
2321
* impure types. With the new gradual typing using Fluid capture sets, this should
2422
* be no longer needed. Also, it has bad interactions with pickling tests.
2523
*/
2624
private val adaptUnpickledFunctionTypes = false
2725

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+
2831
/** The arguments of a @retains or @retainsByName annotation */
2932
private[cc] def retainedElems(tree: Tree)(using Context): List[Tree] = tree match
3033
case Apply(_, Typed(SeqLiteral(elems, _), _) :: Nil) => elems
@@ -77,21 +80,22 @@ trait FollowAliases extends TypeMap:
7780
class mapRoots(from: CaptureRoot, to: CaptureRoot)(using Context) extends BiTypeMap, FollowAliases:
7881
thisMap =>
7982

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)
9599

96100
def inverse = mapRoots(to, from)
97101
end mapRoots

0 commit comments

Comments
 (0)