Skip to content

[Concurrency] Fix disallowed override isolation to carry `@preconcurr… #75087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = { };
Expand All @@ -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:
Expand Down
7 changes: 2 additions & 5 deletions include/swift/AST/TypeCheckRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -1537,8 +1537,7 @@ class GlobalActorAttributeRequest
class ActorIsolationRequest :
public SimpleRequest<ActorIsolationRequest,
ActorIsolation(ValueDecl *),
RequestFlags::SeparatelyCached |
RequestFlags::SplitCached> {
RequestFlags::Cached> {
public:
using SimpleRequest::SimpleRequest;

Expand All @@ -1548,10 +1547,8 @@ class ActorIsolationRequest :
ActorIsolation evaluate(Evaluator &evaluator, ValueDecl *value) const;

public:
// Separate.
// Caching
bool isCached() const { return true; }
std::optional<ActorIsolation> getCachedResult() const;
void cacheResult(ActorIsolation value) const;
};

/// Determine whether the given function should have an isolated 'self'.
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/TypeCheckerTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 0 additions & 22 deletions lib/AST/TypeCheckRequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2013,28 +2013,6 @@ GlobalActorAttributeRequest::cacheResult(std::optional<CustomAttrNominalPair> va
}
}

//----------------------------------------------------------------------------//
// ActorIsolationRequest computation.
//----------------------------------------------------------------------------//

std::optional<ActorIsolation> 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.
//----------------------------------------------------------------------------//
Expand Down
7 changes: 6 additions & 1 deletion lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
13 changes: 13 additions & 0 deletions test/ClangImporter/objc_isolation_complete.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
}
}