Skip to content

Commit 32f240d

Browse files
committed
Drop CaptureRoot and AddTryOwners
1 parent 2be1b41 commit 32f240d

File tree

7 files changed

+12
-246
lines changed

7 files changed

+12
-246
lines changed

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

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

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ class IllegalCaptureRef(tpe: Type) extends Exception(tpe.toString)
6161
/** Capture checking state, which is known to other capture checking components */
6262
class CCState:
6363

64-
/** Cache for level ownership */
65-
val isLevelOwner: mutable.HashMap[Symbol, Boolean] = new mutable.HashMap
66-
6764
/** Associates nesting level owners with the local roots valid in their scopes. */
6865
val localRoots: mutable.HashMap[Symbol, Symbol] = new mutable.HashMap
6966

@@ -72,11 +69,6 @@ class CCState:
7269
*/
7370
var levelError: Option[CaptureSet.CompareResult.LevelError] = None
7471

75-
/** Under saferExceptions: The <try block> symbol generated for a try.
76-
* Installed by Setup, removed by CheckCaptures.
77-
*/
78-
val tryBlockOwner: mutable.HashMap[Try, Symbol] = new mutable.HashMap
79-
8072
end CCState
8173

8274
/** The currently valid CCState */

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

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

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,6 @@ object CaptureSet:
536536
levelLimit.isContainedIn(sym.levelOwner)
537537
case elem: ThisType =>
538538
levelLimit.isContainedIn(elem.cls.levelOwner)
539-
case elem: CaptureRoot.Var =>
540-
elem.encloses(levelLimit.localRoot.termRef)
541539
case _ => true
542540

543541
def addDependent(cs: CaptureSet)(using Context, VarState): CompareResult =

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class CheckCaptures extends Recheck, SymTransformer:
195195
def phaseName: String = "cc"
196196

197197
override def isRunnable(using Context) = super.isRunnable && Feature.ccEnabledSomewhere
198-
override def firstPrepPhase = preRecheckPhase.prev.asInstanceOf[AddTryOwners]
198+
override def firstPrepPhase = preRecheckPhase
199199

200200
def newRechecker()(using Context) = CaptureChecker(ctx)
201201

@@ -221,14 +221,6 @@ class CheckCaptures extends Recheck, SymTransformer:
221221
refs match
222222
case refs: CaptureSet.Var if variance < 0 => refs.solve()
223223
case _ =>
224-
for ref <- refs.elems do
225-
ref match
226-
case ref: CaptureRoot.Var =>
227-
ref.followAlias match
228-
case rv: CaptureRoot.Var if rv.innerLimit == ctx.owner.levelOwner =>
229-
rv.alias = ctx.owner.localRoot.termRef
230-
case _ =>
231-
case _ =>
232224
traverse(parent)
233225
case t @ defn.RefinedFunctionOf(rinfo) =>
234226
traverse(rinfo)
@@ -683,14 +675,13 @@ class CheckCaptures extends Recheck, SymTransformer:
683675
super.recheckTyped(tree)
684676

685677
override def recheckTry(tree: Try, pt: Type)(using Context): Type =
686-
val tryOwner = ccState.tryBlockOwner.remove(tree).getOrElse(ctx.owner)
678+
/*
687679
val saved = curEnv
688680
curEnv = Env(tryOwner, EnvKind.Regular, CaptureSet.Var(curEnv.owner), curEnv)
689-
val tp = try
690-
inContext(ctx.withOwner(tryOwner)):
691-
super.recheckTry(tree, pt)
692-
finally
693-
curEnv = saved
681+
val tp =
682+
try super.recheckTry(tree, pt)
683+
finally curEnv = saved*/
684+
val tp = super.recheckTry(tree, pt)
694685
if allowUniversalInBoxed && Feature.enabled(Feature.saferExceptions) then
695686
disallowRootCapabilitiesIn(tp, ctx.owner,
696687
"result of `try`", "have type",

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import config.Printers.{core, typr, matchTypes}
3636
import reporting.{trace, Message}
3737
import java.lang.ref.WeakReference
3838
import compiletime.uninitialized
39-
import cc.{CapturingType, CaptureSet, derivedCapturingType, isBoxedCapturing, RetainingType, CaptureRoot, isCaptureChecking}
39+
import cc.{CapturingType, CaptureSet, derivedCapturingType, isBoxedCapturing, RetainingType, isCaptureChecking}
4040
import CaptureSet.{CompareResult, IdempotentCaptRefMap, IdentityCaptRefMap}
4141

4242
import scala.annotation.internal.sharable
@@ -2189,7 +2189,6 @@ object Types {
21892189
*/
21902190
def isLocalRootCapability(using Context): Boolean = this match
21912191
case tp: TermRef => tp.localRootOwner.exists
2192-
case tp: CaptureRoot.Var => true
21932192
case _ => false
21942193

21952194
/** Is this reference the a (local or generic) root capability? */

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

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import util.SourcePosition
1515
import scala.util.control.NonFatal
1616
import scala.annotation.switch
1717
import config.{Config, Feature}
18-
import cc.{CapturingType, RetainingType, CaptureSet, CaptureRoot, isBoxed, levelOwner, retainedElems}
18+
import cc.{CapturingType, RetainingType, CaptureSet, isBoxed, levelOwner, retainedElems}
1919

2020
class PlainPrinter(_ctx: Context) extends Printer {
2121

@@ -48,12 +48,6 @@ class PlainPrinter(_ctx: Context) extends Printer {
4848
protected def homogenizedView: Boolean = ctx.settings.YtestPickler.value
4949
protected def debugPos: Boolean = ctx.settings.YdebugPos.value
5050

51-
/** If true, shorten local roots of current owner tp `cap`,
52-
* For now it is better to turn this off, so that we get the best info for diagnosis.
53-
* TODO: we should consider dropping this switch once we implemented disambiguation of capture roots.
54-
*/
55-
private val shortenCap = false
56-
5751
def homogenize(tp: Type): Type =
5852
if (homogenizedView)
5953
tp match {
@@ -253,16 +247,9 @@ class PlainPrinter(_ctx: Context) extends Printer {
253247
val rootsInRefs = refs.elems.filter(isRootCap(_)).toList
254248
val showAsCap = rootsInRefs match
255249
case (tp: TermRef) :: Nil =>
256-
if tp.symbol == defn.captureRoot then
257-
refs.elems.size == 1 || !printDebug
258-
// {caps.cap} gets printed as `{cap}` even under printDebug as long as there
259-
// are no other elements in the set
260-
else
261-
tp.symbol.name == nme.LOCAL_CAPTURE_ROOT
262-
&& ctx.owner.levelOwner == tp.localRootOwner
263-
&& !printDebug
264-
&& shortenCap // !!!
265-
// local roots get printed as themselves under printDebug
250+
tp.symbol == defn.captureRoot && (refs.elems.size == 1 || !printDebug)
251+
// {caps.cap} gets printed as `{cap}` even under printDebug as long as there
252+
// are no other elements in the set
266253
case _ =>
267254
false
268255
val refsText = if showAsCap then rootSetText else toTextCaptureSet(refs)
@@ -405,9 +392,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
405392
tp match {
406393
case tp: TermRef =>
407394
if tp.symbol.name == nme.LOCAL_CAPTURE_ROOT then // TODO: Move to toTextCaptureRef
408-
if ctx.owner.levelOwner == tp.localRootOwner && !printDebug && shortenCap
409-
then Str("cap")
410-
else Str(s"cap[${nameString(tp.localRootOwner)}]")
395+
Str(s"cap[${nameString(tp.localRootOwner)}]")
411396
else toTextPrefixOf(tp) ~ selectionString(tp)
412397
case tp: ThisType =>
413398
nameString(tp.cls) + ".this"
@@ -427,17 +412,6 @@ class PlainPrinter(_ctx: Context) extends Printer {
427412
if (homogenizedView) toText(tp.info)
428413
else if (ctx.settings.XprintTypes.value) "<" ~ toText(tp.repr) ~ ":" ~ toText(tp.info) ~ ">"
429414
else toText(tp.repr)
430-
case tp: CaptureRoot.Var =>
431-
if tp.followAlias ne tp then toTextRef(tp.followAlias)
432-
else
433-
def boundText(sym: Symbol): Text =
434-
toTextRef(sym.termRef).provided(sym.exists)
435-
"'cap["
436-
~ toTextRef(tp.outerLimit.termRef).provided(!tp.outerLimit.isRoot)
437-
~ ".."
438-
~ toTextRef(tp.innerLimit.termRef)
439-
~ "]"
440-
~ ("(from instantiating " ~ nameString(tp.source) ~ ")").provided(tp.source.exists)
441415
}
442416
}
443417

0 commit comments

Comments
 (0)