Skip to content

Commit a340ae9

Browse files
authored
Fix handling paths extending SharedCapability (#22564)
This partially reverts commit 7b3d3f4. It looks like this fixes the problems we had with CI timeouts as well.
2 parents a6a486e + 22a2e5a commit a340ae9

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

Diff for: compiler/src/dotty/tools/dotc/cc/CaptureOps.scala

+3-15
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,7 @@ extension (tp: Type)
232232
case tp @ ReachCapability(_) =>
233233
tp.singletonCaptureSet
234234
case ReadOnlyCapability(ref) =>
235-
val refDcs = ref.deepCaptureSet(includeTypevars)
236-
if refDcs.isConst then CaptureSet(refDcs.elems.map(_.readOnly))
237-
else refDcs // this case should not happen for correct programs
235+
ref.deepCaptureSet(includeTypevars).readOnly
238236
case tp: SingletonCaptureRef if tp.isTrackableRef =>
239237
tp.reach.singletonCaptureSet
240238
case _ =>
@@ -285,20 +283,10 @@ extension (tp: Type)
285283
* are of the form this.C but their pathroot is still this.C, not this.
286284
*/
287285
final def pathRoot(using Context): Type = tp.dealias match
288-
case tp1: TermRef if tp1.symbol.maybeOwner.isClass => tp1.prefix.pathRoot
289-
case tp1: TypeRef if !tp1.symbol.is(Param) => tp1.prefix.pathRoot
286+
case tp1: NamedType if tp1.symbol.maybeOwner.isClass && !tp1.symbol.is(TypeParam) =>
287+
tp1.prefix.pathRoot
290288
case tp1 => tp1
291289

292-
/** The first element of a path type, but stop at references extending
293-
* SharedCapability.
294-
*/
295-
final def pathRootOrShared(using Context): Type =
296-
if tp.derivesFromSharedCapability then tp
297-
else tp.dealias match
298-
case tp1: TermRef if tp1.symbol.maybeOwner.isClass => tp1.prefix.pathRoot
299-
case tp1: TypeRef if !tp1.symbol.is(Param) => tp1.prefix.pathRoot
300-
case tp1 => tp1
301-
302290
/** If this part starts with `C.this`, the class `C`.
303291
* Otherwise, if it starts with a reference `r`, `r`'s owner.
304292
* Otherwise NoSymbol.

Diff for: compiler/src/dotty/tools/dotc/cc/SepCheck.scala

+3-4
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,8 @@ class SepCheck(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
537537
val badParams = mutable.ListBuffer[Symbol]()
538538
def currentOwner = role.dclSym.orElse(ctx.owner)
539539
for hiddenRef <- prune(refsToCheck, tpe, role) do
540-
val proot = hiddenRef.pathRootOrShared
541-
if !proot.widen.derivesFromSharedCapability then
542-
proot match
540+
if !hiddenRef.derivesFromSharedCapability then
541+
hiddenRef.pathRoot match
543542
case ref: TermRef =>
544543
val refSym = ref.symbol
545544
if currentOwner.enclosingMethodOrClass.isProperlyContainedIn(refSym.maybeOwner.enclosingMethodOrClass) then
@@ -575,7 +574,7 @@ class SepCheck(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
575574
role match
576575
case _: TypeRole.Argument | _: TypeRole.Qualifier =>
577576
for ref <- refsToCheck do
578-
if !ref.pathRootOrShared.derivesFromSharedCapability then
577+
if !ref.derivesFromSharedCapability then
579578
consumed.put(ref, pos)
580579
case _ =>
581580
end checkConsumedRefs

0 commit comments

Comments
 (0)