Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Drop redundant matches against ReadOnly(...)
  • Loading branch information
odersky committed Oct 28, 2025
commit 0a0e666db3a1327e60931604699a9133652c54bc
15 changes: 2 additions & 13 deletions compiler/src/dotty/tools/dotc/cc/Capability.scala
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,9 @@ object Capabilities:
case tp: SetCapability => tp.captureSetOfInfo.isReadOnly
case _ => this ne stripReadOnly

/** The restriction of this capability or NoSymbol if there is none */
final def restriction(using Context): Symbol = this match
case Restricted(_, cls) => cls
case ReadOnly(ref1) => ref1.restriction
case Maybe(ref1) => ref1.restriction
case _ => NoSymbol

Expand All @@ -396,10 +396,9 @@ object Capabilities:
case Maybe(ref1) => ref1.stripReadOnly.maybe
case _ => this

/** Drop restrictions with clss `cls` or a superclass of `cls` */
/** Drop restrictions with class `cls` or a superclass of `cls` */
final def stripRestricted(cls: ClassSymbol)(using Context): Capability = this match
case Restricted(ref1, cls1) if cls.isSubClass(cls1) => ref1
case ReadOnly(ref1) => ref1.stripRestricted(cls).readOnly
case Maybe(ref1) => ref1.stripRestricted(cls).maybe
case _ => this

Expand All @@ -408,7 +407,6 @@ object Capabilities:

final def stripReach(using Context): Capability = this match
case Reach(ref1) => ref1
case ReadOnly(ref1) => ref1.stripReach.readOnly
case Restricted(ref1, cls) => ref1.stripReach.restrict(cls)
case Maybe(ref1) => ref1.stripReach.maybe
case _ => this
Expand Down Expand Up @@ -590,7 +588,6 @@ object Capabilities:
def computeHiddenSet(f: Refs => Refs)(using Context): Refs = this match
case self: FreshCap => f(self.hiddenSet.elems)
case Restricted(elem1, cls) => elem1.computeHiddenSet(f).map(_.restrict(cls))
case ReadOnly(elem1) => elem1.computeHiddenSet(f).map(_.readOnly)
case _ => emptyRefs

/** The transitive classifiers of this capability. */
Expand All @@ -608,8 +605,6 @@ object Capabilities:
assert(cls != defn.AnyClass)
if cls == defn.NothingClass then ClassifiedAs(Nil)
else ClassifiedAs(cls :: Nil)
case ReadOnly(ref1) =>
ref1.transClassifiers
case Maybe(ref1) =>
ref1.transClassifiers
case Reach(_) =>
Expand All @@ -633,8 +628,6 @@ object Capabilities:
case Restricted(_, cls1) =>
assert(cls != defn.AnyClass)
cls1.isSubClass(cls)
case ReadOnly(ref1) =>
ref1.tryClassifyAs(cls)
case Maybe(ref1) =>
ref1.tryClassifyAs(cls)
case Reach(_) =>
Expand All @@ -655,7 +648,6 @@ object Capabilities:
cs.forall(c => leastClassifier(c, cls) == defn.NothingClass)
case _ => false
isEmpty || ref1.isKnownEmpty
case ReadOnly(ref1) => ref1.isKnownEmpty
case Maybe(ref1) => ref1.isKnownEmpty
case _ => false

Expand Down Expand Up @@ -716,7 +708,6 @@ object Capabilities:
case _ => false
|| viaInfo(y.info)(subsumingRefs(this, _))
case Maybe(y1) => this.stripMaybe.subsumes(y1)
case ReadOnly(y1) => this.stripReadOnly.subsumes(y1)
case Restricted(y1, cls) => this.stripRestricted(cls).subsumes(y1)
case y: TypeRef if y.derivesFrom(defn.Caps_CapSet) =>
// The upper and lower bounds don't have to be in the form of `CapSet^{...}`.
Expand Down Expand Up @@ -803,7 +794,6 @@ object Capabilities:
y.isKnownClassifiedAs(cls) && x1.maxSubsumes(y, canAddHidden)
case _ =>
y match
case ReadOnly(y1) => this.stripReadOnly.maxSubsumes(y1, canAddHidden)
case Restricted(y1, cls) => this.stripRestricted(cls).maxSubsumes(y1, canAddHidden)
case _ => false

Expand Down Expand Up @@ -891,7 +881,6 @@ object Capabilities:
case c: DerivedCapability =>
val c1 = c.underlying.toType
c match
case ReadOnly(_) => ReadOnlyCapability(c1)
case Restricted(_, cls) => OnlyCapability(c1, cls)
case _: Reach => ReachCapability(c1)
case _: Maybe => MaybeCapability(c1)
Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/cc/CaptureSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1578,8 +1578,6 @@ object CaptureSet:
case Restricted(c1, cls) =>
if cls == defn.NothingClass then CaptureSet.empty
else c1.captureSetOfInfo.restrict(cls) // todo: should we simplify using subsumption here?
case ReadOnly(c1) =>
c1.captureSetOfInfo.readOnly
case Maybe(c1) =>
c1.captureSetOfInfo.maybe
case c: RootCapability =>
Expand Down
5 changes: 0 additions & 5 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6384,11 +6384,6 @@ object Types extends TypeUtils {
mapCapability(c1) match
case c2: Capability => c2.restrict(cls)
case (cs: CaptureSet, exact) => (cs.restrict(cls), exact)
case ReadOnly(c1) =>
assert(!deep)
mapCapability(c1) match
case c2: Capability => c2.readOnly
case (cs: CaptureSet, exact) => (cs.readOnly, exact)
case Maybe(c1) =>
assert(!deep)
mapCapability(c1) match
Expand Down