[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.
This commit is contained in:
Doug Gregor
2025-03-10 22:57:47 -07:00
parent 04bb69f426
commit 81e8f75f93
2 changed files with 12 additions and 5 deletions

View File

@@ -165,11 +165,6 @@ void swift::diagnoseUnsafeUse(const UnsafeUse &use) {
/// Determine whether a reference to the given variable is treated as
/// nonisolated(unsafe).
static bool isReferenceToNonisolatedUnsafe(ValueDecl *decl) {
auto isolation = getActorIsolationForReference(
decl, decl->getDeclContext());
if (!isolation.isNonisolated())
return false;
auto attr = decl->getAttrs().getAttribute<NonisolatedAttr>();
return attr && attr->isUnsafe();
}

View File

@@ -43,3 +43,15 @@ final class MyExecutor: SerialExecutor {
func enqueue(_ job: consuming ExecutorJob) { fatalError("boom") }
@unsafe func asUnownedSerialExecutor() -> UnownedSerialExecutor { fatalError("boom") }
}
// Ensure that this does not cause a reference cycle.
public struct TokenSyntax { }
public struct Syntax { }
open class SyntaxVisitor {
open func visit(_ token: TokenSyntax) { }
}
open class SyntaxAnyVisitor: SyntaxVisitor {
override open func visit(_ token: TokenSyntax) { }
}