Skip to content

Commit c270597

Browse files
committed
SIL: Fix false positive in FlowIsolation with DynamicSelfType usage
If an instruction references the DynamicSelfType by calling a static member with `Self.foo()`, we consider this a type-dependent use of `self`. This means that at runtime we may need to load the isa pointer, but we don't need to touch any other protected state from the instance. Therefore, we can skip type-dependent uses in the analysis to avoid false positives in this case. An existing test case already exercised the overly-conservative behavior, so I just updated it to not expect an error. Fixes rdar://129676769.
1 parent 3dd4198 commit c270597

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/SILOptimizer/Mandatory/FlowIsolation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,12 @@ void AnalysisInfo::analyze(const SILArgument *selfParam) {
582582
worklist.pushUsesOfValueIfNotVisited(selfParam);
583583

584584
while (Operand *operand = worklist.pop()) {
585+
// A type-dependent use of `self` is an instruction that contains the
586+
// DynamicSelfType. These instructions do not access any protected
587+
// state.
588+
if (operand->isTypeDependent())
589+
continue;
590+
585591
SILInstruction *user = operand->getUser();
586592

587593
// First, check if this is an apply that involves `self`

test/Concurrency/flow_isolation.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,7 @@ actor OhBrother {
684684
static var DefaultResult: Int { 10 }
685685

686686
init() {
687-
// expected-note@+2 {{after this closure involving 'self', only non-isolated properties of 'self' can be accessed from this init}}
688-
// expected-warning@+1 {{cannot access property 'giver' here in non-isolated initializer; this is an error in the Swift 6 language mode}}
687+
// this is OK: we're using DynamicSelfType but that doesn't access protected state.
689688
self.giver = { (x: OhBrother) -> Int in Self.DefaultResult }
690689
}
691690

0 commit comments

Comments
 (0)