Skip to content

Commit f786979

Browse files
committed
Drop BoxedTypeCache
1 parent 16a2216 commit f786979

File tree

7 files changed

+25
-77
lines changed

7 files changed

+25
-77
lines changed

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

Lines changed: 0 additions & 19 deletions
This file was deleted.

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

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import config.Feature
1515
import collection.mutable
1616

1717
private val Captures: Key[CaptureSet] = Key()
18-
private val BoxedType: Key[BoxedTypeCache] = Key()
1918

2019
object ccConfig:
2120

@@ -25,14 +24,6 @@ object ccConfig:
2524
*/
2625
private[cc] val adaptUnpickledFunctionTypes = false
2726

28-
/** Switch whether we constrain a root var that includes the source of a
29-
* root map to be an alias of that source (so that it can be mapped)
30-
*/
31-
private[cc] val constrainRootsWhenMapping = true
32-
33-
/** Use old scheme for refining vars, which should be no longer necessary
34-
*/
35-
val oldRefiningVars = false
3627
end ccConfig
3728

3829
def allowUniversalInBoxed(using Context) =
@@ -132,21 +123,15 @@ extension (tp: Type)
132123
if (parent eq p) && (refs eq r) then tp
133124
else CapturingType(parent, refs, tp.isBoxed)
134125

135-
// TODO Move boxed/unboxed to CaapturingType?
136126
/** If this is a unboxed capturing type with nonempty capture set, its boxed version.
137127
* Or, if type is a TypeBounds of capturing types, the version where the bounds are boxed.
138128
* The identity for all other types.
139129
*/
140130
def boxed(using Context): Type = tp.dealias match
141131
case tp @ CapturingType(parent, refs) if !tp.isBoxed && !refs.isAlwaysEmpty =>
142132
tp.annot match
143-
case ann: CaptureAnnotation =>
144-
AnnotatedType(parent, ann.boxedAnnot)
145-
case ann =>
146-
ann.tree.getAttachment(BoxedType) match // TODO drop
147-
case None => ann.tree.putAttachment(BoxedType, BoxedTypeCache())
148-
case _ =>
149-
ann.tree.attachment(BoxedType)(tp)
133+
case ann: CaptureAnnotation => AnnotatedType(parent, ann.boxedAnnot)
134+
case ann => tp
150135
case tp: RealTypeBounds =>
151136
tp.derivedTypeBounds(tp.lo.boxed, tp.hi.boxed)
152137
case _ =>

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

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ sealed abstract class CaptureSet extends Showable:
5656
*/
5757
def isAlwaysEmpty: Boolean
5858

59-
/** An optinal level limit, or NoSymbol if none exists. All elements of the set
59+
/** An optional level limit, or NoSymbol if none exists. All elements of the set
6060
* must be in scopes visible from the level limit.
6161
*/
6262
def levelLimit: Symbol
@@ -78,13 +78,11 @@ sealed abstract class CaptureSet extends Showable:
7878

7979
/** Does this capture set contain the root reference `cap` as element? */
8080
final def isUniversal(using Context) =
81-
elems.exists(_.isGenericRootCapability)
81+
elems.exists(_.isUniversalRootCapability)
8282

8383
/** Does this capture set contain the root reference `cap` as element? */
8484
final def containsRoot(using Context) =
85-
elems.exists:
86-
case ref: TermRef => ref.isRootCapability
87-
case _ => false
85+
elems.exists(_.isRootCapability)
8886

8987
final def disallowsUniversal(using Context) =
9088
if isConst then !isUniversal && elems.exists(_.isLocalRootCapability)
@@ -144,7 +142,7 @@ sealed abstract class CaptureSet extends Showable:
144142
|| y.match
145143
case y: TermRef => y.prefix eq x
146144
case _ => false
147-
|| (x.isGenericRootCapability || y.isRootCapability && x.isRootCapability)
145+
|| (x.isUniversalRootCapability || y.isRootCapability && x.isRootCapability)
148146
&& ctx.property(LooseRootChecking).isDefined
149147

150148
/** x <:< cap, cap[x] <:< cap
@@ -153,8 +151,8 @@ sealed abstract class CaptureSet extends Showable:
153151
*/
154152
private def isSuperRootOf(y: CaptureRef): Boolean = x match
155153
case x: TermRef =>
156-
if x.isGenericRootCapability then true
157-
else if x.isLocalRootCapability && !y.isGenericRootCapability then
154+
if x.isUniversalRootCapability then true
155+
else if x.isLocalRootCapability && !y.isUniversalRootCapability then
158156
val xowner = x.localRootOwner
159157
y match
160158
case y: TermRef =>
@@ -287,11 +285,6 @@ sealed abstract class CaptureSet extends Showable:
287285
else Const(elems.filter(p))
288286
else Filtered(asVar, p)
289287

290-
/** This set with a new owner and therefore also a new levelLimit */
291-
def changeOwner(newOwner: Symbol)(using Context): CaptureSet =
292-
if this.isConst then this
293-
else ChangedOwner(asVar, newOwner)
294-
295288
/** Capture set obtained by applying `tm` to all elements of the current capture set
296289
* and joining the results. If the current capture set is a variable, the same
297290
* transformation is applied to all future additions of new elements.
@@ -517,7 +510,7 @@ object CaptureSet:
517510
else
518511
//assert(id != 19 || !elem.isLocalRootCapability, elem.asInstanceOf[TermRef].localRootOwner)
519512
elems += elem
520-
if elem.isGenericRootCapability then rootAddedHandler()
513+
if elem.isUniversalRootCapability then rootAddedHandler()
521514
newElemAddedHandler(elem)
522515
// assert(id != 5 || elems.size != 3, this)
523516
val res = (CompareResult.OK /: deps) { (r, dep) =>
@@ -527,7 +520,7 @@ object CaptureSet:
527520
res
528521

529522
private def levelOK(elem: CaptureRef)(using Context): Boolean =
530-
if elem.isGenericRootCapability then !noUniversal
523+
if elem.isUniversalRootCapability then !noUniversal
531524
else !levelLimit.exists
532525
|| elem.match
533526
case elem: TermRef =>
@@ -560,7 +553,7 @@ object CaptureSet:
560553

561554
/** Roughly: the intersection of all constant known supersets of this set.
562555
* The aim is to find an as-good-as-possible constant set that is a superset
563-
* of this set. The associated root set {cap[owner]} is a sound fallback.
556+
* of this set. The universal set {cap} is a sound fallback.
564557
*/
565558
final def upperApprox(origin: CaptureSet)(using Context): CaptureSet =
566559
if isConst then this
@@ -758,10 +751,6 @@ object CaptureSet:
758751
override def toString = s"BiMapped$id($source, elems = $elems)"
759752
end BiMapped
760753

761-
/** Same as `source` but with a new directOwner */
762-
class ChangedOwner private[CaptureSet](val source: Var, newOwner: Symbol)(using @constructorOnly ctx: Context)
763-
extends DerivedVar(newOwner, source.elems)
764-
765754
/** A variable with elements given at any time as { x <- source.elems | p(x) } */
766755
class Filtered private[CaptureSet]
767756
(val source: Var, p: Context ?=> CaptureRef => Boolean)(using @constructorOnly ctx: Context)
@@ -1087,7 +1076,7 @@ object CaptureSet:
10871076
override def toAdd(using Context) =
10881077
for CompareResult.LevelError(cs, ref) <- ccState.levelError.toList yield
10891078
ccState.levelError = None
1090-
if ref.isGenericRootCapability then
1079+
if ref.isUniversalRootCapability then
10911080
i"""
10921081
|
10931082
|Note that the universal capability `cap`

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object CapturingType:
2828

2929
/** Smart constructor that
3030
* - drops empty capture sets
31-
* - drops capability class ecpansion if they are refined with another capturing type
31+
* - drops a capability class expansion if it is further refined with another capturing type
3232
* - fuses compatible capturiong types.
3333
* An outer type capturing type A can be fused with an inner capturing type B if their
3434
* boxing status is the same or if A is boxed.
@@ -77,7 +77,7 @@ object CapturingType:
7777
None
7878

7979
/** Check whether a type is uncachable when computing `baseType`.
80-
* We avoid caching capturing types when IgnoreCaptures mode is set, since the
80+
* We avoid caching capturing types when IgnoreCaptures mode is set.
8181
*/
8282
def isUncachable(tp: Type)(using Context): Boolean =
8383
ctx.mode.is(Mode.IgnoreCaptures) && decomposeCapturingType(tp).isDefined

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ object CheckCaptures:
140140
case tpe =>
141141
report.error(em"$elem: $tpe is not a legal element of a capture set", elem.srcPos)
142142

143-
/** Report an error if some part of `tp` contains the root capability in its capture set */
143+
/** Report an error if some part of `tp` contains the root capability in its capture set
144+
* or if it refers to an unsealed type parameter that could possibly be instantiated with
145+
* cap in a way that's visible at the type.
146+
*/
144147
def disallowRootCapabilitiesIn(tp: Type, carrier: Symbol, what: String, have: String, addendum: String, pos: SrcPos)(using Context) =
145148
val check = new TypeTraverser:
146149
extension (tparam: Symbol) def isParametricIn(carrier: Symbol): Boolean =
@@ -195,7 +198,6 @@ class CheckCaptures extends Recheck, SymTransformer:
195198
def phaseName: String = "cc"
196199

197200
override def isRunnable(using Context) = super.isRunnable && Feature.ccEnabledSomewhere
198-
override def firstPrepPhase = preRecheckPhase
199201

200202
def newRechecker()(using Context) = CaptureChecker(ctx)
201203

@@ -525,7 +527,7 @@ class CheckCaptures extends Recheck, SymTransformer:
525527
augmentConstructorType(parent, initCs ++ refs)
526528
case _ =>
527529
val (refined, cs) = addParamArgRefinements(core, initCs)
528-
refined.capturing(cs.changeOwner(ctx.owner))
530+
refined.capturing(cs)
529531

530532
augmentConstructorType(ownType, capturedVars(cls) ++ capturedVars(sym))
531533
.showing(i"constr type $mt with $argTypes%, % in $cls = $result", capt)
@@ -675,12 +677,6 @@ class CheckCaptures extends Recheck, SymTransformer:
675677
super.recheckTyped(tree)
676678

677679
override def recheckTry(tree: Try, pt: Type)(using Context): Type =
678-
/*
679-
val saved = curEnv
680-
curEnv = Env(tryOwner, EnvKind.Regular, CaptureSet.Var(curEnv.owner), curEnv)
681-
val tp =
682-
try super.recheckTry(tree, pt)
683-
finally curEnv = saved*/
684680
val tp = super.recheckTry(tree, pt)
685681
if allowUniversalInBoxed && Feature.enabled(Feature.saferExceptions) then
686682
disallowRootCapabilitiesIn(tp, ctx.owner,
@@ -805,7 +801,7 @@ class CheckCaptures extends Recheck, SymTransformer:
805801
.showing(i"adapt universal $actual vs $expected = $result", capt)
806802
else actual
807803

808-
val debugSuccesses = false
804+
private inline val debugSuccesses = false
809805

810806
/** Massage `actual` and `expected` types before checking conformance.
811807
* Massaging is done by the methods following this one:

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,9 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
311311
if sym.isClass then t
312312
else t.info match
313313
case TypeAlias(alias) =>
314-
val transformed =
315-
if sym.isStatic || true then this(alias)
316-
else transformExplicitType(alias)(
317-
using ctx.withOwner(sym.owner))
314+
val transformed = this(alias)
318315
if transformed ne alias then transformed else t
319-
//.showing(i"EXPAND $t with ${t.info} to $result in ${t.symbol.owner}/${ctx.owner}")
316+
//.showing(i"EXPAND $t with ${t.info} to $result in ${t.symbol.owner}/${ctx.owner}")
320317
case _ =>
321318
recur(t)
322319
case t @ AppliedType(tycon: TypeProxy, args) if true =>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,7 +2182,7 @@ object Types {
21822182
isTrackableRef && (isRootCapability || !captureSetOfInfo.isAlwaysEmpty)
21832183

21842184
/** Is this reference the generic root capability `cap` ? */
2185-
def isGenericRootCapability(using Context): Boolean = false
2185+
def isUniversalRootCapability(using Context): Boolean = false
21862186

21872187
/** Is this reference a local root capability `{<cap in owner>}`
21882188
* for some level owner?
@@ -2193,7 +2193,7 @@ object Types {
21932193

21942194
/** Is this reference the a (local or generic) root capability? */
21952195
def isRootCapability(using Context): Boolean =
2196-
isGenericRootCapability || isLocalRootCapability
2196+
isUniversalRootCapability || isLocalRootCapability
21972197

21982198
/** Normalize reference so that it can be compared with `eq` for equality */
21992199
def normalizedRef(using Context): CaptureRef = this
@@ -2927,7 +2927,7 @@ object Types {
29272927
|| isRootCapability
29282928
) && !symbol.isOneOf(UnstableValueFlags)
29292929

2930-
override def isGenericRootCapability(using Context): Boolean =
2930+
override def isUniversalRootCapability(using Context): Boolean =
29312931
name == nme.CAPTURE_ROOT && symbol == defn.captureRoot
29322932

29332933
def localRootOwner(using Context): Symbol =

0 commit comments

Comments
 (0)