Skip to content

Commit 87e34ed

Browse files
committed
Cleanup ccConfig settings
1 parent bca3978 commit 87e34ed

File tree

4 files changed

+18
-36
lines changed

4 files changed

+18
-36
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,19 @@ object ccConfig:
2727
*/
2828
inline val allowUnsoundMaps = false
2929

30-
/** If true, expand capability classes in Setup instead of treating them
31-
* in adapt.
32-
*/
33-
inline val expandCapabilityInSetup = true
34-
30+
/** If true, use existential capture set variables */
3531
def useExistentials(using Context) =
3632
Feature.sourceVersion.stable.isAtLeast(SourceVersion.`3.5`)
3733

38-
/** If true, use `sealed` as encapsulation mechanism instead of the
39-
* previous global retriction that `cap` can't be boxed or unboxed.
34+
/** If true, use "sealed" as encapsulation mechanism, meaning that we
35+
* check that type variable instantiations don't have `cap` in any of
36+
* their capture sets. This is an alternative of the original restriction
37+
* that `cap` can't be boxed or unboxed. It is used in 3.3 and 3.4 but
38+
* dropped again in 3.5.
4039
*/
41-
def allowUniversalInBoxed(using Context) =
40+
def useSealed(using Context) =
4241
Feature.sourceVersion.stable == SourceVersion.`3.3`
4342
|| Feature.sourceVersion.stable == SourceVersion.`3.4`
44-
//|| Feature.sourceVersion.stable == SourceVersion.`3.5` // drop `//` if you want to test with the sealed type params strategy
4543
end ccConfig
4644

4745

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,9 +1059,8 @@ object CaptureSet:
10591059
tp.captureSet
10601060
case tp: TermParamRef =>
10611061
tp.captureSet
1062-
case tp: TypeRef =>
1063-
if !ccConfig.expandCapabilityInSetup && tp.derivesFromCapability then universal
1064-
else empty
1062+
case _: TypeRef =>
1063+
empty
10651064
case _: TypeParamRef =>
10661065
empty
10671066
case CapturingType(parent, refs) =>

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

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ object CheckCaptures:
170170
traverse(parent)
171171
case t =>
172172
traverseChildren(t)
173-
if ccConfig.allowUniversalInBoxed then check.traverse(tp)
173+
if ccConfig.useSealed then check.traverse(tp)
174174
end disallowRootCapabilitiesIn
175175

176176
/** Attachment key for bodies of closures, provided they are values */
@@ -581,7 +581,7 @@ class CheckCaptures extends Recheck, SymTransformer:
581581
end instantiate
582582

583583
override def recheckTypeApply(tree: TypeApply, pt: Type)(using Context): Type =
584-
if ccConfig.allowUniversalInBoxed then
584+
if ccConfig.useSealed then
585585
val TypeApply(fn, args) = tree
586586
val polyType = atPhase(thisPhase.prev):
587587
fn.tpe.widen.asInstanceOf[TypeLambda]
@@ -806,7 +806,7 @@ class CheckCaptures extends Recheck, SymTransformer:
806806

807807
override def recheckTry(tree: Try, pt: Type)(using Context): Type =
808808
val tp = super.recheckTry(tree, pt)
809-
if ccConfig.allowUniversalInBoxed && Feature.enabled(Feature.saferExceptions) then
809+
if ccConfig.useSealed && Feature.enabled(Feature.saferExceptions) then
810810
disallowRootCapabilitiesIn(tp, ctx.owner,
811811
"result of `try`", "have type",
812812
"This is often caused by a locally generated exception capability leaking as part of its result.",
@@ -875,7 +875,7 @@ class CheckCaptures extends Recheck, SymTransformer:
875875
}
876876
checkNotUniversal(parent)
877877
case _ =>
878-
if !ccConfig.allowUniversalInBoxed
878+
if !ccConfig.useSealed
879879
&& !tpe.hasAnnotation(defn.UncheckedCapturesAnnot)
880880
&& needsUniversalCheck
881881
then
@@ -1100,7 +1100,7 @@ class CheckCaptures extends Recheck, SymTransformer:
11001100
def msg = em"""$actual cannot be box-converted to $expected
11011101
|since at least one of their capture sets contains the root capability `cap`"""
11021102
def allowUniversalInBoxed =
1103-
ccConfig.allowUniversalInBoxed
1103+
ccConfig.useSealed
11041104
|| expected.hasAnnotation(defn.UncheckedCapturesAnnot)
11051105
|| actual.widen.hasAnnotation(defn.UncheckedCapturesAnnot)
11061106
if criticalSet.isUnboxable && expected.isValueType && !allowUniversalInBoxed then
@@ -1129,20 +1129,6 @@ class CheckCaptures extends Recheck, SymTransformer:
11291129
recur(actual, expected, covariant)
11301130
end adaptBoxed
11311131

1132-
/** If actual derives from caps.Capability, yet is not a capturing type itself,
1133-
* make its capture set explicit.
1134-
*/
1135-
private def makeCaptureSetExplicit(actual: Type)(using Context): Type =
1136-
if ccConfig.expandCapabilityInSetup then actual
1137-
else actual match
1138-
case CapturingType(_, _) => actual
1139-
case _ if actual.derivesFromCapability =>
1140-
val cap: CaptureRef = actual match
1141-
case ref: CaptureRef if ref.isTracked => ref
1142-
case _ => defn.captureRoot.termRef // TODO: skolemize?
1143-
CapturingType(actual, cap.singletonCaptureSet)
1144-
case _ => actual
1145-
11461132
/** If actual is a tracked CaptureRef `a` and widened is a capturing type T^C,
11471133
* improve `T^C` to `T^{a}`, following the VAR rule of CC.
11481134
*/
@@ -1163,12 +1149,11 @@ class CheckCaptures extends Recheck, SymTransformer:
11631149
if expected == LhsProto || expected.isSingleton && actual.isSingleton then
11641150
actual
11651151
else
1166-
val normalized = makeCaptureSetExplicit(actual)
1167-
val widened = improveCaptures(normalized.widen.dealiasKeepAnnots, actual)
1152+
val widened = improveCaptures(actual.widen.dealiasKeepAnnots, actual)
11681153
val adapted = adaptBoxed(
11691154
widened.withReachCaptures(actual), expected, pos,
11701155
covariant = true, alwaysConst = false, boxErrors)
1171-
if adapted eq widened then normalized
1156+
if adapted eq widened then actual
11721157
else adapted.showing(i"adapt boxed $actual vs $expected = $adapted", capt)
11731158
end adapt
11741159

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
317317
this(expandThrowsAlias(res, exc, Nil))
318318
case t =>
319319
// Map references to capability classes C to C^
320-
if ccConfig.expandCapabilityInSetup && t.derivesFromCapability && t.typeSymbol != defn.Caps_Exists
320+
if t.derivesFromCapability && t.typeSymbol != defn.Caps_Exists
321321
then CapturingType(t, CaptureSet.universal, boxed = false)
322322
else normalizeCaptures(mapOver(t))
323323
end toCapturing
@@ -397,7 +397,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
397397
transformTT(tpt,
398398
boxed =
399399
sym.is(Mutable, butNot = Method)
400-
&& !ccConfig.allowUniversalInBoxed
400+
&& !ccConfig.useSealed
401401
&& !sym.hasAnnotation(defn.UncheckedCapturesAnnot),
402402
// types of mutable variables are boxed in pre 3.3 code
403403
exact = sym.allOverriddenSymbols.hasNext,

0 commit comments

Comments
 (0)