@@ -130,15 +130,12 @@ object CheckCaptures:
130130 report.error(em " Singleton type $parent cannot have capture set " , parent.srcPos)
131131 case _ =>
132132 for elem <- ann.retainedElems do
133- elem match
134- case QualifiedRoot (outer) =>
135- // Will be checked by Setup's checkOuterRoots
136- case _ => elem.tpe match
137- case ref : CaptureRef =>
138- if ! ref.isTrackableRef then
139- report.error(em " $elem cannot be tracked since it is not a parameter or local value " , elem.srcPos)
140- case tpe =>
141- report.error(em " $elem: $tpe is not a legal element of a capture set " , elem.srcPos)
133+ elem.tpe match
134+ case ref : CaptureRef =>
135+ if ! ref.isTrackableRef then
136+ report.error(em " $elem cannot be tracked since it is not a parameter or local value " , elem.srcPos)
137+ case tpe =>
138+ report.error(em " $elem: $tpe is not a legal element of a capture set " , elem.srcPos)
142139
143140 /** Report an error if some part of `tp` contains the root capability in its capture set
144141 * or if it refers to an unsealed type parameter that could possibly be instantiated with
@@ -837,13 +834,9 @@ class CheckCaptures extends Recheck, SymTransformer:
837834 }
838835 checkNotUniversal(parent)
839836 case _ =>
840- val adapted =
841- if ccConfig.allowUniversalInBoxed then
842- adaptUniversal(tpe, pt, tree)
843- else
844- if needsUniversalCheck then checkNotUniversal(tpe)
845- tpe
846- super .recheckFinish(adapted, tree, pt)
837+ if ! ccConfig.allowUniversalInBoxed && needsUniversalCheck then
838+ checkNotUniversal(tpe)
839+ super .recheckFinish(tpe, tree, pt)
847840 end recheckFinish
848841
849842 // ------------------ Adaptation -------------------------------------
@@ -855,56 +848,7 @@ class CheckCaptures extends Recheck, SymTransformer:
855848 // - Relax expected capture set containing `this.type`s by adding references only
856849 // accessible through those types (c.f. addOuterRefs, also #14930 for a discussion).
857850 // - Adapt box status and environment capture sets by simulating box/unbox operations.
858- // - Instantiate `cap` in actual as needed to a local root.
859-
860- /** The local root that is implied for the expression `tree`.
861- * This is the local root of the outermost level owner that includes
862- * all free variables of the expression that have in their types
863- * some capturing type occuring in covariant or invariant position.
864- */
865- def impliedRoot (tree : Tree )(using Context ) =
866- def isTrackedSomewhere (sym : Symbol ): Boolean =
867- val search = new TypeAccumulator [Boolean ]:
868- def apply (found : Boolean , tp : Type ) =
869- def isTrackedHere = variance >= 0 && ! tp.captureSet.isAlwaysEmpty
870- found || isTrackedHere || foldOver(found, tp)
871- if sym.is(Method )
872- then ! capturedVars(sym).elems.isEmpty || search(false , sym.info.finalResultType)
873- else search(false , sym.info)
874-
875- val acc = new TreeAccumulator [Symbol ]:
876- val locals = mutable.Set [Symbol ]()
877- private def max (sym1 : Symbol , sym2 : Symbol )(using Context ) =
878- sym1.maxNested(sym2, onConflict = (_, _) => throw NoCommonRoot (sym1, sym2))
879- def apply (s : Symbol , t : Tree )(using Context ) = t match
880- case t : (Ident | This )
881- if ! locals.contains(t.symbol) && isTrackedSomewhere(t.symbol) =>
882- max(s, t.symbol.levelOwner)
883- case t : DefTree =>
884- locals += t.symbol
885- foldOver(s, t)
886- case _ =>
887- foldOver(s, t)
888- acc(NoSymbol , tree).orElse(ctx.owner).localRoot
889-
890- /** Assume `actual` is the type of an expression `tree` with the given
891- * `expected` type. If `actual` captures `cap` and `cap` is not allowed
892- * in the capture set of `expected`, narrow `cap` to the root capability
893- * that is implied for `tree`.
894- */
895- def adaptUniversal (actual : Type , expected : Type , tree : Tree )(using Context ): Type =
896- if expected.captureSet.disallowsUniversal && actual.captureSet.isUniversal then
897- if actual.isInstanceOf [SingletonType ] then
898- // capture set is only exposed when widening
899- adaptUniversal(actual.widen, expected, tree)
900- else
901- val localRoot = impliedRoot(tree)
902- CapturingType (
903- actual.stripCapturing,
904- localRoot.termRef.singletonCaptureSet,
905- actual.isBoxedCapturing)
906- .showing(i " adapt universal $actual vs $expected = $result" , capt)
907- else actual
851+ // - Instantiate covariant occurrenves of `cap` in actual to reach capabilities.
908852
909853 private inline val debugSuccesses = false
910854
@@ -1369,20 +1313,6 @@ class CheckCaptures extends Recheck, SymTransformer:
13691313 checker.traverse(tree.knownType)
13701314 end healTypeParam
13711315
1372- def checkNoLocalRootIn (sym : Symbol , info : Type , pos : SrcPos )(using Context ): Unit =
1373- val check = new TypeTraverser :
1374- def traverse (tp : Type ) = tp match
1375- case tp : TermRef if tp.isLocalRootCapability =>
1376- if tp.localRootOwner == sym then
1377- report.error(i " local root $tp cannot appear in type of $sym" , pos)
1378- case tp : ClassInfo =>
1379- traverseChildren(tp)
1380- for mbr <- tp.decls do
1381- if ! mbr.is(Private ) then checkNoLocalRootIn(sym, mbr.info, mbr.srcPos)
1382- case _ =>
1383- traverseChildren(tp)
1384- check.traverse(info)
1385-
13861316 def checkArraysAreSealedIn (tp : Type , pos : SrcPos )(using Context ): Unit =
13871317 val check = new TypeTraverser :
13881318 def traverse (t : Type ): Unit =
@@ -1426,8 +1356,6 @@ class CheckCaptures extends Recheck, SymTransformer:
14261356 checkBounds(normArgs, tl)
14271357 args.lazyZip(tl.paramNames).foreach(healTypeParam(_, _, fun.symbol))
14281358 case _ =>
1429- case _ : ValOrDefDef | _ : TypeDef =>
1430- checkNoLocalRootIn(tree.symbol, tree.symbol.info, tree.symbol.srcPos)
14311359 case tree : TypeTree =>
14321360 checkArraysAreSealedIn(tree.tpe, tree.srcPos)
14331361 case _ =>
0 commit comments