Skip to content

Commit 6056ae2

Browse files
committed
Implement level checking for Fresh roots
1 parent 18a5228 commit 6056ae2

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,30 @@ trait CaptureRef extends TypeProxy, ValueType:
122122
final def isExclusive(using Context): Boolean =
123123
!isReadOnly && (isRootCapability || captureSetOfInfo.isExclusive)
124124

125+
final def ccOwner(using Context): Symbol = this match
126+
case root.Fresh(hidden) =>
127+
hidden.owner
128+
case ref: TermRef =>
129+
if ref.isCap then NoSymbol
130+
else ref.prefix match
131+
case prefix: CaptureRef => prefix.ccOwner
132+
case _ => ref.symbol
133+
case ref: ThisType =>
134+
ref.cls
135+
case QualifiedCapability(ref1) =>
136+
ref1.ccOwner
137+
case _ =>
138+
NoSymbol
139+
140+
final def adjustedOwner(using Context): Symbol =
141+
def adjust(owner: Symbol): Symbol =
142+
if !owner.exists
143+
|| owner.isClass && (!owner.is(Flags.Module) || owner.isStatic)
144+
|| owner.is(Flags.Method, butNot = Flags.Accessor) && !owner.isConstructor
145+
then owner
146+
else adjust(owner.owner)
147+
adjust(ccOwner)
148+
125149
// With the support of paths, we don't need to normalize the `TermRef`s anymore.
126150
// /** Normalize reference so that it can be compared with `eq` for equality */
127151
// final def normalizedRef(using Context): CaptureRef = this match

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
467467
vbleText ~ hashStr(binder) ~ Str(idStr).provided(showUniqueIds)
468468
case tp @ root.Fresh(hidden) =>
469469
val idStr = if showUniqueIds then s"#${tp.rootAnnot.id}" else ""
470-
if ccVerbose then s"<fresh$idStr hiding " ~ toTextCaptureSet(hidden) ~ ">"
470+
if ccVerbose then s"<fresh$idStr in ${tp.ccOwner} hiding " ~ toTextCaptureSet(hidden) ~ ">"
471471
else if ccVerbose then "fresh"
472472
else "cap"
473473
case tp => toText(tp)

tests/pos-custom-args/captures/skolems2.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ def Test(@consume c: Object^, @consume f: Object^ => Object^) =
1313
val x4: Object^ =
1414
{ unsafeAssumeSeparate(f)(cc) }
1515

16+
def Test2(@consume c: Object^, @consume f: Object^ => Object^) =
17+
def cc(): Object^ = unsafeAssumeSeparate(c)
18+
val x1 =
19+
{ f(cc()) }
20+
val x2 =
21+
f(cc())
22+
val x3: Object^ =
23+
f(cc())
24+
val x4: Object^ =
25+
{ unsafeAssumeSeparate(f)(cc()) }
26+
1627

1728

1829

0 commit comments

Comments
 (0)