From 5e9e41c2e332863cad4d2579de2688b9cd4b71ea Mon Sep 17 00:00:00 2001 From: odersky Date: Sun, 9 Feb 2025 17:05:40 +0100 Subject: [PATCH 1/2] Fix handling paths extending SharedCapabiolity This partially reverts commit 7b3d3f4eb25ba1d169392ee8f6cbf6a0082a46d7. It looks like this fixes the problems we had with CI timeouts as well. --- compiler/src/dotty/tools/dotc/cc/CaptureOps.scala | 14 ++------------ compiler/src/dotty/tools/dotc/cc/SepCheck.scala | 7 +++---- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/cc/CaptureOps.scala b/compiler/src/dotty/tools/dotc/cc/CaptureOps.scala index 349711ef21b0..6fde983b9a5c 100644 --- a/compiler/src/dotty/tools/dotc/cc/CaptureOps.scala +++ b/compiler/src/dotty/tools/dotc/cc/CaptureOps.scala @@ -285,20 +285,10 @@ 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: TermRef if tp1.symbol.maybeOwner.isClass => tp1.prefix.pathRoot - case tp1: TypeRef if !tp1.symbol.is(Param) => tp1.prefix.pathRoot + case tp1: NamedType if tp1.symbol.maybeOwner.isClass && !tp1.symbol.is(TypeParam) => + 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. diff --git a/compiler/src/dotty/tools/dotc/cc/SepCheck.scala b/compiler/src/dotty/tools/dotc/cc/SepCheck.scala index b2318eb798dd..ad6205617b1d 100644 --- a/compiler/src/dotty/tools/dotc/cc/SepCheck.scala +++ b/compiler/src/dotty/tools/dotc/cc/SepCheck.scala @@ -537,9 +537,8 @@ 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 - val proot = hiddenRef.pathRootOrShared - if !proot.widen.derivesFromSharedCapability then - proot match + if !hiddenRef.derivesFromSharedCapability then + hiddenRef.pathRoot match case ref: TermRef => val refSym = ref.symbol if currentOwner.enclosingMethodOrClass.isProperlyContainedIn(refSym.maybeOwner.enclosingMethodOrClass) then @@ -575,7 +574,7 @@ class SepCheck(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser: role match case _: TypeRole.Argument | _: TypeRole.Qualifier => for ref <- refsToCheck do - if !ref.pathRootOrShared.derivesFromSharedCapability then + if !ref.derivesFromSharedCapability then consumed.put(ref, pos) case _ => end checkConsumedRefs From 22a2e5ae750dc7f16e477ce522976e923d3b8bac Mon Sep 17 00:00:00 2001 From: odersky Date: Sun, 9 Feb 2025 17:11:19 +0100 Subject: [PATCH 2/2] Streamline deepCaptureSet --- compiler/src/dotty/tools/dotc/cc/CaptureOps.scala | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/cc/CaptureOps.scala b/compiler/src/dotty/tools/dotc/cc/CaptureOps.scala index 6fde983b9a5c..7692cf191bf9 100644 --- a/compiler/src/dotty/tools/dotc/cc/CaptureOps.scala +++ b/compiler/src/dotty/tools/dotc/cc/CaptureOps.scala @@ -232,9 +232,7 @@ extension (tp: Type) case tp @ ReachCapability(_) => tp.singletonCaptureSet case ReadOnlyCapability(ref) => - val refDcs = ref.deepCaptureSet(includeTypevars) - if refDcs.isConst then CaptureSet(refDcs.elems.map(_.readOnly)) - else refDcs // this case should not happen for correct programs + ref.deepCaptureSet(includeTypevars).readOnly case tp: SingletonCaptureRef if tp.isTrackableRef => tp.reach.singletonCaptureSet case _ =>