Skip to content

Commit 19f59ce

Browse files
authored
Merge pull request #75087 from xedin/rdar-130776220-limited
[Concurrency] Fix disallowed override isolation to carry `@preconcurr…
2 parents a89c5a0 + 65fb35c commit 19f59ce

File tree

6 files changed

+23
-33
lines changed

6 files changed

+23
-33
lines changed

include/swift/AST/Decl.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2828,10 +2828,6 @@ class ValueDecl : public Decl {
28282828
/// optional result.
28292829
unsigned isIUO : 1;
28302830

2831-
/// Whether we're in the common case where the ActorIsolationRequest
2832-
/// request returned ActorIsolation::forUnspecified().
2833-
unsigned noActorIsolation : 1;
2834-
28352831
/// Whether we've evaluated the ApplyAccessNoteRequest.
28362832
unsigned accessNoteApplied : 1;
28372833
} LazySemanticInfo = { };
@@ -2847,6 +2843,7 @@ class ValueDecl : public Decl {
28472843
friend class ActorIsolationRequest;
28482844
friend class DynamicallyReplacedDeclRequest;
28492845
friend class ApplyAccessNoteRequest;
2846+
28502847
friend class Decl;
28512848
SourceLoc getLocFromSource() const { return NameLoc; }
28522849
protected:

include/swift/AST/TypeCheckRequests.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,8 +1537,7 @@ class GlobalActorAttributeRequest
15371537
class ActorIsolationRequest :
15381538
public SimpleRequest<ActorIsolationRequest,
15391539
ActorIsolation(ValueDecl *),
1540-
RequestFlags::SeparatelyCached |
1541-
RequestFlags::SplitCached> {
1540+
RequestFlags::Cached> {
15421541
public:
15431542
using SimpleRequest::SimpleRequest;
15441543

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

15501549
public:
1551-
// Separate.
1550+
// Caching
15521551
bool isCached() const { return true; }
1553-
std::optional<ActorIsolation> getCachedResult() const;
1554-
void cacheResult(ActorIsolation value) const;
15551552
};
15561553

15571554
/// Determine whether the given function should have an isolated 'self'.

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ SWIFT_REQUEST(TypeChecker, GlobalActorAttributeRequest,
178178
SeparatelyCached | SplitCached, NoLocationInfo)
179179
SWIFT_REQUEST(TypeChecker, ActorIsolationRequest,
180180
ActorIsolationState(ValueDecl *),
181-
SeparatelyCached | SplitCached, NoLocationInfo)
181+
Cached, NoLocationInfo)
182182
SWIFT_REQUEST(TypeChecker, HasIsolatedSelfRequest,
183183
bool(ValueDecl *),
184184
Uncached, NoLocationInfo)

lib/AST/TypeCheckRequests.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,28 +2013,6 @@ GlobalActorAttributeRequest::cacheResult(std::optional<CustomAttrNominalPair> va
20132013
}
20142014
}
20152015

2016-
//----------------------------------------------------------------------------//
2017-
// ActorIsolationRequest computation.
2018-
//----------------------------------------------------------------------------//
2019-
2020-
std::optional<ActorIsolation> ActorIsolationRequest::getCachedResult() const {
2021-
auto *decl = std::get<0>(getStorage());
2022-
if (decl->LazySemanticInfo.noActorIsolation)
2023-
return ActorIsolation::forUnspecified();
2024-
2025-
return decl->getASTContext().evaluator.getCachedNonEmptyOutput(*this);
2026-
}
2027-
2028-
void ActorIsolationRequest::cacheResult(ActorIsolation value) const {
2029-
auto *decl = std::get<0>(getStorage());
2030-
if (value.isUnspecified()) {
2031-
decl->LazySemanticInfo.noActorIsolation = 1;
2032-
return;
2033-
}
2034-
2035-
decl->getASTContext().evaluator.cacheNonEmptyOutput(*this, std::move(value));
2036-
}
2037-
20382016
//----------------------------------------------------------------------------//
20392017
// ResolveMacroRequest computation.
20402018
//----------------------------------------------------------------------------//

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5290,7 +5290,12 @@ ActorIsolation ActorIsolationRequest::evaluate(
52905290
break;
52915291

52925292
case OverrideIsolationResult::Disallowed:
5293-
inferred = *overriddenIso;
5293+
if (overriddenValue->hasClangNode() &&
5294+
overriddenIso->isUnspecified()) {
5295+
inferred = overriddenIso->withPreconcurrency(true);
5296+
} else {
5297+
inferred = *overriddenIso;
5298+
}
52945299
break;
52955300
}
52965301
}

test/ClangImporter/objc_isolation_complete.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,16 @@ class IsolatedSub: NXSender {
3131
return mainActorState
3232
}
3333
}
34+
35+
@objc
36+
@MainActor
37+
class Test : NSObject {
38+
static var shared: Test? // expected-note {{mutation of this static property is only permitted within the actor}}
39+
40+
override init() {
41+
super.init()
42+
43+
Self.shared = self
44+
// 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}}
45+
}
46+
}

0 commit comments

Comments
 (0)