diff --git a/include/swift/AST/Decl.h b/include/swift/AST/Decl.h index 50337a1d8b795..925b8f2197859 100644 --- a/include/swift/AST/Decl.h +++ b/include/swift/AST/Decl.h @@ -2828,10 +2828,6 @@ class ValueDecl : public Decl { /// optional result. unsigned isIUO : 1; - /// Whether we're in the common case where the ActorIsolationRequest - /// request returned ActorIsolation::forUnspecified(). - unsigned noActorIsolation : 1; - /// Whether we've evaluated the ApplyAccessNoteRequest. unsigned accessNoteApplied : 1; } LazySemanticInfo = { }; @@ -2847,6 +2843,7 @@ class ValueDecl : public Decl { friend class ActorIsolationRequest; friend class DynamicallyReplacedDeclRequest; friend class ApplyAccessNoteRequest; + friend class Decl; SourceLoc getLocFromSource() const { return NameLoc; } protected: diff --git a/include/swift/AST/TypeCheckRequests.h b/include/swift/AST/TypeCheckRequests.h index 733158976e377..682daeddc392c 100644 --- a/include/swift/AST/TypeCheckRequests.h +++ b/include/swift/AST/TypeCheckRequests.h @@ -1537,8 +1537,7 @@ class GlobalActorAttributeRequest class ActorIsolationRequest : public SimpleRequest { + RequestFlags::Cached> { public: using SimpleRequest::SimpleRequest; @@ -1548,10 +1547,8 @@ class ActorIsolationRequest : ActorIsolation evaluate(Evaluator &evaluator, ValueDecl *value) const; public: - // Separate. + // Caching bool isCached() const { return true; } - std::optional getCachedResult() const; - void cacheResult(ActorIsolation value) const; }; /// Determine whether the given function should have an isolated 'self'. diff --git a/include/swift/AST/TypeCheckerTypeIDZone.def b/include/swift/AST/TypeCheckerTypeIDZone.def index 3ea5f9fb1af03..5658a2eefb1ac 100644 --- a/include/swift/AST/TypeCheckerTypeIDZone.def +++ b/include/swift/AST/TypeCheckerTypeIDZone.def @@ -178,7 +178,7 @@ SWIFT_REQUEST(TypeChecker, GlobalActorAttributeRequest, SeparatelyCached | SplitCached, NoLocationInfo) SWIFT_REQUEST(TypeChecker, ActorIsolationRequest, ActorIsolationState(ValueDecl *), - SeparatelyCached | SplitCached, NoLocationInfo) + Cached, NoLocationInfo) SWIFT_REQUEST(TypeChecker, HasIsolatedSelfRequest, bool(ValueDecl *), Uncached, NoLocationInfo) diff --git a/lib/AST/TypeCheckRequests.cpp b/lib/AST/TypeCheckRequests.cpp index 32218a1601894..4edab3e3d8b0f 100644 --- a/lib/AST/TypeCheckRequests.cpp +++ b/lib/AST/TypeCheckRequests.cpp @@ -2013,28 +2013,6 @@ GlobalActorAttributeRequest::cacheResult(std::optional va } } -//----------------------------------------------------------------------------// -// ActorIsolationRequest computation. -//----------------------------------------------------------------------------// - -std::optional ActorIsolationRequest::getCachedResult() const { - auto *decl = std::get<0>(getStorage()); - if (decl->LazySemanticInfo.noActorIsolation) - return ActorIsolation::forUnspecified(); - - return decl->getASTContext().evaluator.getCachedNonEmptyOutput(*this); -} - -void ActorIsolationRequest::cacheResult(ActorIsolation value) const { - auto *decl = std::get<0>(getStorage()); - if (value.isUnspecified()) { - decl->LazySemanticInfo.noActorIsolation = 1; - return; - } - - decl->getASTContext().evaluator.cacheNonEmptyOutput(*this, std::move(value)); -} - //----------------------------------------------------------------------------// // ResolveMacroRequest computation. //----------------------------------------------------------------------------// diff --git a/lib/Sema/TypeCheckConcurrency.cpp b/lib/Sema/TypeCheckConcurrency.cpp index 1380823bd715a..7ddab53579551 100644 --- a/lib/Sema/TypeCheckConcurrency.cpp +++ b/lib/Sema/TypeCheckConcurrency.cpp @@ -5290,7 +5290,12 @@ ActorIsolation ActorIsolationRequest::evaluate( break; case OverrideIsolationResult::Disallowed: - inferred = *overriddenIso; + if (overriddenValue->hasClangNode() && + overriddenIso->isUnspecified()) { + inferred = overriddenIso->withPreconcurrency(true); + } else { + inferred = *overriddenIso; + } break; } } diff --git a/test/ClangImporter/objc_isolation_complete.swift b/test/ClangImporter/objc_isolation_complete.swift index d094acecd73c5..eb3259ec58449 100644 --- a/test/ClangImporter/objc_isolation_complete.swift +++ b/test/ClangImporter/objc_isolation_complete.swift @@ -31,3 +31,16 @@ class IsolatedSub: NXSender { return mainActorState } } + +@objc +@MainActor +class Test : NSObject { + static var shared: Test? // expected-note {{mutation of this static property is only permitted within the actor}} + + override init() { + super.init() + + Self.shared = self + // expected-warning@-1 {{main actor-isolated static property 'shared' can not be mutated from a nonisolated context; this is an error in the Swift 6 language mode}} + } +}