Skip to content

Commit c64905f

Browse files
committed
Record level of current owner when creating Fresh instances
1 parent e52986c commit c64905f

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ object CaptureSet:
423423
def universalImpliedByCapability(using Context) =
424424
defn.universalCSImpliedByCapability
425425

426-
def fresh(owner: Symbol = NoSymbol)(using Context): CaptureSet =
427-
root.Fresh.withOwner(owner).singletonCaptureSet
426+
def fresh()(using Context): CaptureSet =
427+
root.Fresh().singletonCaptureSet
428428

429429
/** The shared capture set `{cap.rd}` */
430430
def shared(using Context): CaptureSet =
@@ -689,7 +689,7 @@ object CaptureSet:
689689
def solve()(using Context): Unit =
690690
CCState.withCapAsRoot: // // OK here since we infer parameter types that get checked later
691691
val approx = upperApprox(empty)
692-
.map(root.CapToFresh(NoSymbol).inverse) // Fresh --> cap
692+
.map(root.CapToFresh().inverse) // Fresh --> cap
693693
.showing(i"solve $this = $result", capt)
694694
//println(i"solving var $this $approx ${approx.isConst} deps = ${deps.toList}")
695695
val newElems = approx.elems -- elems
@@ -1392,7 +1392,7 @@ object CaptureSet:
13921392
def capturingCase(acc: CaptureSet, parent: Type, refs: CaptureSet) =
13931393
this(acc, parent) ++ refs
13941394
def abstractTypeCase(acc: CaptureSet, t: TypeRef, upperBound: Type) =
1395-
if includeTypevars && upperBound.isExactlyAny then CaptureSet.fresh(t.symbol)
1395+
if includeTypevars && upperBound.isExactlyAny then CaptureSet.fresh()
13961396
else this(acc, upperBound)
13971397
collect(CaptureSet.empty, tp)
13981398

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ class CheckCaptures extends Recheck, SymTransformer:
825825
var refined: Type = core
826826
var allCaptures: CaptureSet =
827827
if core.derivesFromMutable then initCs ++ CaptureSet.fresh()
828-
else if core.derivesFromCapability then initCs ++ root.Fresh.withOwner(core.classSymbol).readOnly.singletonCaptureSet
828+
else if core.derivesFromCapability then initCs ++ root.Fresh().readOnly.singletonCaptureSet
829829
else initCs
830830
for (getterName, argType) <- mt.paramNames.lazyZip(argTypes) do
831831
val getter = cls.info.member(getterName).suchThat(_.isRefiningParamAccessor).symbol

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ object root:
125125
/** The type of fresh references */
126126
type Fresh = AnnotatedType
127127

128+
/** Constructor and extractor methods for "fresh" capabilities */
128129
object Fresh:
129-
/** Constructor and extractor methods for "fresh" capabilities */
130-
private def make(owner: Symbol)(using Context): CaptureRef =
130+
def apply(using Context)(owner: Symbol = ctx.owner): CaptureRef =
131131
if ccConfig.useSepChecks then
132132
val hiddenSet = CaptureSet.HiddenSet(owner)
133133
val res = AnnotatedType(cap, Annot(Kind.Fresh(hiddenSet)))
@@ -137,9 +137,6 @@ object root:
137137
else
138138
cap
139139

140-
def withOwner(owner: Symbol)(using Context): CaptureRef = make(owner)
141-
def apply()(using Context): CaptureRef = make(NoSymbol)
142-
143140
def unapply(tp: AnnotatedType): Option[CaptureSet.HiddenSet] = tp.annot match
144141
case Annot(Kind.Fresh(hidden)) => Some(hidden)
145142
case _ => None
@@ -168,14 +165,14 @@ object root:
168165
/** Map each occurrence of cap to a different Fresh instance
169166
* Exception: CapSet^ stays as it is.
170167
*/
171-
class CapToFresh(owner: Symbol)(using Context) extends BiTypeMap, FollowAliasesMap:
168+
class CapToFresh()(using Context) extends BiTypeMap, FollowAliasesMap:
172169
thisMap =>
173170

174171
override def apply(t: Type) =
175172
if variance <= 0 then t
176173
else t match
177174
case t: CaptureRef if t.isCap =>
178-
Fresh.withOwner(owner)
175+
Fresh()
179176
case t @ CapturingType(parent: TypeRef, _) if parent.symbol == defn.Caps_CapSet =>
180177
t
181178
case t @ CapturingType(_, _) =>
@@ -213,12 +210,12 @@ object root:
213210
end CapToFresh
214211

215212
/** Maps cap to fresh */
216-
def capToFresh(tp: Type, owner: Symbol = NoSymbol)(using Context): Type =
217-
if ccConfig.useSepChecks then CapToFresh(owner)(tp) else tp
213+
def capToFresh(tp: Type)(using Context): Type =
214+
if ccConfig.useSepChecks then CapToFresh()(tp) else tp
218215

219216
/** Maps fresh to cap */
220217
def freshToCap(tp: Type)(using Context): Type =
221-
if ccConfig.useSepChecks then CapToFresh(NoSymbol).inverse(tp) else tp
218+
if ccConfig.useSepChecks then CapToFresh().inverse(tp) else tp
222219

223220
/** Map top-level free existential variables one-to-one to Fresh instances */
224221
def resultToFresh(tp: Type)(using Context): Type =

0 commit comments

Comments
 (0)