Skip to content

Commit 81e8f75

Browse files
committed
[Strict memory safety] Eliminate false cycle when checking nonisolated(unsafe)
Whenc hecking for nonisolated(unsafe), don't evaluate the full isolation of the entity, because doing so causes a reference cycle.
1 parent 04bb69f commit 81e8f75

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/Sema/TypeCheckUnsafe.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,6 @@ void swift::diagnoseUnsafeUse(const UnsafeUse &use) {
165165
/// Determine whether a reference to the given variable is treated as
166166
/// nonisolated(unsafe).
167167
static bool isReferenceToNonisolatedUnsafe(ValueDecl *decl) {
168-
auto isolation = getActorIsolationForReference(
169-
decl, decl->getDeclContext());
170-
if (!isolation.isNonisolated())
171-
return false;
172-
173168
auto attr = decl->getAttrs().getAttribute<NonisolatedAttr>();
174169
return attr && attr->isUnsafe();
175170
}

test/Unsafe/unsafe_concurrency.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,15 @@ final class MyExecutor: SerialExecutor {
4343
func enqueue(_ job: consuming ExecutorJob) { fatalError("boom") }
4444
@unsafe func asUnownedSerialExecutor() -> UnownedSerialExecutor { fatalError("boom") }
4545
}
46+
47+
// Ensure that this does not cause a reference cycle.
48+
public struct TokenSyntax { }
49+
public struct Syntax { }
50+
51+
open class SyntaxVisitor {
52+
open func visit(_ token: TokenSyntax) { }
53+
}
54+
55+
open class SyntaxAnyVisitor: SyntaxVisitor {
56+
override open func visit(_ token: TokenSyntax) { }
57+
}

0 commit comments

Comments
 (0)