Skip to content

Commit 29f34de

Browse files
committed
Simplification: drop ccNestingLevel
1 parent 046dff9 commit 29f34de

File tree

4 files changed

+10
-47
lines changed

4 files changed

+10
-47
lines changed

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

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ class CCState:
5757
/** Cache for level ownership */
5858
val isLevelOwner: mutable.HashMap[Symbol, Boolean] = new mutable.HashMap
5959

60-
/** Associates certain symbols (the nesting level owners) with their ccNestingLevel */
61-
val nestingLevels: mutable.HashMap[Symbol, Int] = new mutable.HashMap
62-
6360
/** Associates nesting level owners with the local roots valid in their scopes. */
6461
val localRoots: mutable.HashMap[Symbol, Symbol] = new mutable.HashMap
6562

@@ -451,24 +448,6 @@ extension (sym: Symbol)
451448
recur(sym, NoSymbol)
452449
.showing(i"find outer $sym [ $name ] = $result", capt)
453450

454-
/** The nesting level of `sym` for the purposes of `cc`,
455-
* -1 for NoSymbol
456-
*/
457-
def ccNestingLevel(using Context): Int =
458-
if sym.exists then
459-
val lowner = sym.levelOwner
460-
ccState.nestingLevels.getOrElseUpdate(lowner,
461-
if lowner.isRoot then 0 else lowner.owner.ccNestingLevel + 1)
462-
else -1
463-
464-
/** Optionally, the nesting level of `sym` for the purposes of `cc`, provided
465-
* a capture checker is running.
466-
*/
467-
def ccNestingLevelOpt(using Context): Option[Int] =
468-
if ctx.phase == Phases.checkCapturesPhase || ctx.phase == Phases.checkCapturesPhase.prev
469-
then Some(ccNestingLevel)
470-
else None
471-
472451
/** The parameter with type caps.Cap in the leading term parameter section,
473452
* or NoSymbol, if none exists.
474453
*/
@@ -482,7 +461,7 @@ extension (sym: Symbol)
482461
val owner = sym.levelOwner
483462
assert(owner.exists)
484463
def newRoot = newSymbol(if owner.isClass then newLocalDummy(owner) else owner,
485-
nme.LOCAL_CAPTURE_ROOT, Synthetic, defn.Caps_Cap.typeRef, nestingLevel = owner.ccNestingLevel)
464+
nme.LOCAL_CAPTURE_ROOT, Synthetic, defn.Caps_Cap.typeRef)
486465
def lclRoot =
487466
if owner.isTerm then owner.definedLocalRoot.orElse(newRoot)
488467
else newRoot
@@ -500,12 +479,6 @@ extension (sym: Symbol)
500479
else if !sym.exists || sym.isContainedIn(other) then other
501480
else sym.owner.minNested(other.owner)
502481

503-
extension (tp: TermRef | ThisType)
504-
/** The nesting level of this reference as defined by capture checking */
505-
def ccNestingLevel(using Context): Int = tp match
506-
case tp: TermRef => tp.symbol.ccNestingLevel
507-
case tp: ThisType => tp.cls.ccNestingLevel
508-
509482
extension (tp: AnnotatedType)
510483
/** Is this a boxed capturing type? */
511484
def isBoxed(using Context): Boolean = tp.annot match

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

Lines changed: 1 addition & 1 deletion
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, ccNestingLevel, CaptureRoot}
39+
import cc.{CapturingType, CaptureSet, derivedCapturingType, isBoxedCapturing, RetainingType, CaptureRoot}
4040
import CaptureSet.{CompareResult, IdempotentCaptRefMap, IdentityCaptRefMap}
4141

4242
import scala.annotation.internal.sharable

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

Lines changed: 6 additions & 13 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, ccNestingLevel, levelOwner, retainedElems}
18+
import cc.{CapturingType, RetainingType, CaptureSet, CaptureRoot, isBoxed, levelOwner, retainedElems}
1919

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

@@ -374,10 +374,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
374374
*/
375375
protected def idString(sym: Symbol): String =
376376
(if (showUniqueIds || Printer.debugPrintUnique) "#" + sym.id else "") +
377-
(if showNestingLevel then
378-
if ctx.phase == Phases.checkCapturesPhase then "%" + sym.ccNestingLevel
379-
else "%" + sym.nestingLevel
380-
else "")
377+
(if showNestingLevel then "%" + sym.nestingLevel else "")
381378

382379
def nameString(sym: Symbol): String =
383380
simpleNameString(sym) + idString(sym) // + "<" + (if (sym.exists) sym.owner else "") + ">"
@@ -408,11 +405,9 @@ class PlainPrinter(_ctx: Context) extends Printer {
408405
tp match {
409406
case tp: TermRef =>
410407
if tp.symbol.name == nme.LOCAL_CAPTURE_ROOT then // TODO: Move to toTextCaptureRef
411-
if ctx.owner.levelOwner == tp.localRootOwner && !printDebug && shortenCap then
412-
Str("cap")
413-
else
414-
Str(s"cap[${tp.localRootOwner.name}]") ~
415-
Str(s"%${tp.symbol.ccNestingLevel}").provided(showNestingLevel)
408+
if ctx.owner.levelOwner == tp.localRootOwner && !printDebug && shortenCap
409+
then Str("cap")
410+
else Str(s"cap[${tp.localRootOwner.name}]")
416411
else toTextPrefixOf(tp) ~ selectionString(tp)
417412
case tp: ThisType =>
418413
nameString(tp.cls) + ".this"
@@ -436,9 +431,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
436431
if tp.followAlias ne tp then toTextRef(tp.followAlias)
437432
else
438433
def boundText(sym: Symbol): Text =
439-
(toTextRef(sym.termRef)
440-
~ Str(s"/${sym.ccNestingLevel}").provided(showNestingLevel)
441-
).provided(sym.exists)
434+
toTextRef(sym.termRef).provided(sym.exists)
442435
"'cap["
443436
~ toTextRef(tp.outerLimit.termRef).provided(!tp.outerLimit.isRoot)
444437
~ ".."

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import config.{Config, Feature}
2929

3030
import dotty.tools.dotc.util.SourcePosition
3131
import dotty.tools.dotc.ast.untpd.{MemberDef, Modifiers, PackageDef, RefTree, Template, TypeDef, ValOrDefDef}
32-
import cc.{CaptureSet, CapturingType, toCaptureSet, IllegalCaptureRef, ccNestingLevelOpt}
32+
import cc.{CaptureSet, CapturingType, toCaptureSet, IllegalCaptureRef}
3333

3434
class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
3535

@@ -868,13 +868,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
868868

869869
protected def optAscription[T <: Untyped](tpt: Tree[T]): Text = optText(tpt)(": " ~ _)
870870

871-
private def nestingLevel(sym: Symbol): Int =
872-
sym.ccNestingLevelOpt.getOrElse(sym.nestingLevel)
873-
874871
private def idText(tree: untpd.Tree): Text =
875872
(if showUniqueIds && tree.hasType && tree.symbol.exists then s"#${tree.symbol.id}" else "") ~
876873
(if showNestingLevel then tree.typeOpt match
877-
case tp: NamedType if !tp.symbol.isStatic => s"%${nestingLevel(tp.symbol)}"
874+
case tp: NamedType if !tp.symbol.isStatic => s"%${tp.symbol.nestingLevel}"
878875
case tp: TypeVar => s"%${tp.nestingLevel}"
879876
case tp: TypeParamRef => ctx.typerState.constraint.typeVarOfParam(tp) match
880877
case tvar: TypeVar => s"%${tvar.nestingLevel}"

0 commit comments

Comments
 (0)