Skip to content

Commit 2f135cc

Browse files
committed
Address review comments
1 parent 802ae17 commit 2f135cc

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

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

+13-2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ trait CaptureRef extends TypeProxy, ValueType:
128128
final def isExclusive(using Context): Boolean =
129129
!isReadOnly && (isRootCapability || captureSetOfInfo.isExclusive)
130130

131+
/** The owning symbol associated with a capability this is
132+
* - for Fresh capabilities: the owner of the hidden set
133+
* - for TermRefs and TypeRefs: the symbol it refers to
134+
* - for derived and path capabilities: the owner of the underlying capability
135+
* - otherwise NoSymbol
136+
*/
131137
final def ccOwner(using Context): Symbol = this match
132138
case root.Fresh(hidden) =>
133139
hidden.owner
@@ -143,7 +149,12 @@ trait CaptureRef extends TypeProxy, ValueType:
143149
case _ =>
144150
NoSymbol
145151

146-
final def adjustedOwner(using Context): Symbol =
152+
/** The symbol that represents the level closest-enclosing ccOwner.
153+
* Symbols representing levels are
154+
* - class symbols, but not inner (non-static) module classes
155+
* - method symbols, but not accessors or constructors
156+
*/
157+
final def levelOwner(using Context): Symbol =
147158
def adjust(owner: Symbol): Symbol =
148159
if !owner.exists
149160
|| owner.isClass && (!owner.is(Flags.Module) || owner.isStatic)
@@ -296,7 +307,7 @@ trait CaptureRef extends TypeProxy, ValueType:
296307
case x @ root.Fresh(hidden) =>
297308
def levelOK =
298309
if ccConfig.useFreshLevels && !CCState.ignoreFreshLevels then
299-
val yOwner = y.adjustedOwner
310+
val yOwner = y.levelOwner
300311
yOwner.isStaticOwner || x.ccOwner.isContainedIn(yOwner)
301312
else
302313
!y.stripReadOnly.isCap

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ class CheckCaptures extends Recheck, SymTransformer:
744744
val argType = recheck(arg, freshenedFormal)
745745
.showing(i"recheck arg $arg vs $freshenedFormal = $result", capt)
746746
if formal.hasAnnotation(defn.UseAnnot) || formal.hasAnnotation(defn.ConsumeAnnot) then
747-
// The @use and/or @consume annotation is added to `formal` by `prep areFunction`
747+
// The @use and/or @consume annotation is added to `formal` by `prepareFunction`
748748
capt.println(i"charging deep capture set of $arg: ${argType} = ${argType.deepCaptureSet}")
749749
markFree(argType.deepCaptureSet, arg)
750750
if formal.containsCap then
@@ -1277,7 +1277,7 @@ class CheckCaptures extends Recheck, SymTransformer:
12771277
val msg = note match
12781278
case CompareResult.LevelError(cs, ref) =>
12791279
if ref.stripReadOnly.isCapOrFresh then
1280-
i"""the universa capability $ref
1280+
i"""the universal capability $ref
12811281
|cannot be included in capture set $cs"""
12821282
else
12831283
val levelStr = ref match

compiler/src/dotty/tools/dotc/core/Types.scala

+1-9
Original file line numberDiff line numberDiff line change
@@ -868,19 +868,11 @@ object Types extends TypeUtils {
868868
pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, overridingRefinement)
869869
else
870870
val isRefinedMethod = rinfo.isInstanceOf[MethodOrPoly]
871-
val joint = try
872-
CCState.ignoringFreshLevels:
871+
val joint = CCState.ignoringFreshLevels:
873872
pdenot.meet(
874873
new JointRefDenotation(NoSymbol, rinfo, Period.allInRun(ctx.runId), pre, isRefinedMethod),
875874
pre,
876875
safeIntersection = ctx.base.pendingMemberSearches.contains(name))
877-
pdenot.meet(
878-
new JointRefDenotation(NoSymbol, rinfo, Period.allInRun(ctx.runId), pre, isRefinedMethod),
879-
pre,
880-
safeIntersection = ctx.base.pendingMemberSearches.contains(name))
881-
catch case ex: AssertionError =>
882-
println(i"error while do refined $tp . $name, ${pdenot.info} / $rinfo")
883-
throw ex
884876
joint match
885877
case joint: SingleDenotation
886878
if isRefinedMethod

tests/neg-custom-args/captures/i15772.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
| reference cap is not included in the allowed capture set ?
2525
| of the enclosing method main3
2626
|
27-
| Note that the universa capability cap
27+
| Note that the universal capability cap
2828
| cannot be included in capture set ?
2929
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15772.scala:46:2 ----------------------------------------
3030
46 | x: (() -> Unit) // error

tests/neg-custom-args/captures/reaches.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
| reference cap is not included in the allowed capture set ?
2828
| of the enclosing method runAll2
2929
|
30-
| Note that the universa capability cap
30+
| Note that the universal capability cap
3131
| cannot be included in capture set ?
3232
-- Error: tests/neg-custom-args/captures/reaches.scala:44:16 -----------------------------------------------------------
3333
44 | val cur = Ref[List[Proc]](xs) // error

0 commit comments

Comments
 (0)