Skip to content

Commit

Permalink
Revert "Fix handling paths extending SharedCapability"
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzaremmal authored Feb 10, 2025
1 parent a340ae9 commit 0818005
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
18 changes: 15 additions & 3 deletions compiler/src/dotty/tools/dotc/cc/CaptureOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ extension (tp: Type)
case tp @ ReachCapability(_) =>
tp.singletonCaptureSet
case ReadOnlyCapability(ref) =>
ref.deepCaptureSet(includeTypevars).readOnly
val refDcs = ref.deepCaptureSet(includeTypevars)
if refDcs.isConst then CaptureSet(refDcs.elems.map(_.readOnly))
else refDcs // this case should not happen for correct programs
case tp: SingletonCaptureRef if tp.isTrackableRef =>
tp.reach.singletonCaptureSet
case _ =>
Expand Down Expand Up @@ -283,10 +285,20 @@ extension (tp: Type)
* are of the form this.C but their pathroot is still this.C, not this.
*/
final def pathRoot(using Context): Type = tp.dealias match
case tp1: NamedType if tp1.symbol.maybeOwner.isClass && !tp1.symbol.is(TypeParam) =>
tp1.prefix.pathRoot
case tp1: TermRef if tp1.symbol.maybeOwner.isClass => tp1.prefix.pathRoot
case tp1: TypeRef if !tp1.symbol.is(Param) => tp1.prefix.pathRoot
case tp1 => tp1

/** The first element of a path type, but stop at references extending
* SharedCapability.
*/
final def pathRootOrShared(using Context): Type =
if tp.derivesFromSharedCapability then tp
else tp.dealias match
case tp1: TermRef if tp1.symbol.maybeOwner.isClass => tp1.prefix.pathRoot
case tp1: TypeRef if !tp1.symbol.is(Param) => tp1.prefix.pathRoot
case tp1 => tp1

/** If this part starts with `C.this`, the class `C`.
* Otherwise, if it starts with a reference `r`, `r`'s owner.
* Otherwise NoSymbol.
Expand Down
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/cc/SepCheck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,9 @@ class SepCheck(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
val badParams = mutable.ListBuffer[Symbol]()
def currentOwner = role.dclSym.orElse(ctx.owner)
for hiddenRef <- prune(refsToCheck, tpe, role) do
if !hiddenRef.derivesFromSharedCapability then
hiddenRef.pathRoot match
val proot = hiddenRef.pathRootOrShared
if !proot.widen.derivesFromSharedCapability then
proot match
case ref: TermRef =>
val refSym = ref.symbol
if currentOwner.enclosingMethodOrClass.isProperlyContainedIn(refSym.maybeOwner.enclosingMethodOrClass) then
Expand Down Expand Up @@ -574,7 +575,7 @@ class SepCheck(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
role match
case _: TypeRole.Argument | _: TypeRole.Qualifier =>
for ref <- refsToCheck do
if !ref.derivesFromSharedCapability then
if !ref.pathRootOrShared.derivesFromSharedCapability then
consumed.put(ref, pos)
case _ =>
end checkConsumedRefs
Expand Down

0 comments on commit 0818005

Please sign in to comment.