Skip to content

Commit 8c5b49e

Browse files
authored
Merge pull request #79204 from gottesmm/undo-concurrent-for-now
[concurrency] For now undo ActorIsolation::Concurrent refactoring.
2 parents 453b997 + 7e350bb commit 8c5b49e

39 files changed

+402
-480
lines changed

include/swift/AST/ActorIsolation.h

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,8 @@ class ActorIsolation {
5757
/// the actor is isolated to the instance of that actor.
5858
ActorInstance,
5959
/// The declaration is explicitly specified to be not isolated to any actor,
60-
/// meaning it cannot itself access actor isolated state but /does/ allow
61-
/// for indirect access to actor isolated state if the declaration can
62-
/// guarantee that all code generated to work with the declaration will run
63-
/// on said actor.
64-
///
65-
/// E.x.: a nonisolated function can accept actor-isolated values as
66-
/// arguments since the caller knows that it will not escape the values to
67-
/// another isolation domain and that the function will remain on the
68-
/// caller's actor.
69-
///
70-
/// NOTE: This used to have the meaning of Concurrent which is a stricter
71-
/// definition of nonisolated that prevents the code generated to work with
72-
/// the declaration to never touch actor isolated state.
60+
/// meaning that it can be used from any actor but is also unable to
61+
/// refer to the isolated state of any given actor.
7362
Nonisolated,
7463
/// The declaration is explicitly specified to be not isolated and with the
7564
/// "unsafe" annotation, which means that we do not enforce isolation.
@@ -80,20 +69,11 @@ class ActorIsolation {
8069
/// The actor isolation iss statically erased, as for a call to
8170
/// an isolated(any) function. This is not possible for declarations.
8271
Erased,
83-
/// The declaration is explicitly specified to be not isolated to any actor,
84-
/// meaning that it can be used from any actor but is also unable to
85-
/// refer to the isolated state of any given actor.
72+
/// Inherits isolation from the caller of the given function.
8673
///
87-
/// NOTE: This used to be nonisolated, but we changed nonisolated to have a
88-
/// weaker definition of nonisolated that allows for actor isolated state to
89-
/// be manipulated by code generated to work with the actor as long as all
90-
/// such code generation is guaranteed to always run on whatever actor
91-
/// isolation it is invoked in consistently and not escape the value to any
92-
/// other isolation domain.
93-
Concurrent,
94-
/// The declaration is explicitly specified to be concurrent and with the
95-
/// "unsafe" annotation, which means that we do not enforce isolation.
96-
ConcurrentUnsafe,
74+
/// DISCUSSION: This is used for nonisolated asynchronous functions that we
75+
/// want to inherit from their context the context's actor isolation.
76+
CallerIsolationInheriting,
9777
};
9878

9979
private:
@@ -108,7 +88,7 @@ class ActorIsolation {
10888
/// Set to true if this was parsed from SIL.
10989
unsigned silParsed : 1;
11090

111-
unsigned parameterIndex : 26;
91+
unsigned parameterIndex : 27;
11292

11393
ActorIsolation(Kind kind, NominalTypeDecl *actor, unsigned parameterIndex);
11494

@@ -132,8 +112,10 @@ class ActorIsolation {
132112
return ActorIsolation(unsafe ? NonisolatedUnsafe : Nonisolated);
133113
}
134114

135-
static ActorIsolation forConcurrent(bool unsafe) {
136-
return ActorIsolation(unsafe ? ConcurrentUnsafe : Concurrent);
115+
static ActorIsolation forCallerIsolationInheriting() {
116+
// NOTE: We do not use parameter indices since the parameter is implicit
117+
// from the perspective of the AST.
118+
return ActorIsolation(CallerIsolationInheriting);
137119
}
138120

139121
static ActorIsolation forActorInstanceSelf(ValueDecl *decl);
@@ -183,10 +165,9 @@ class ActorIsolation {
183165
std::optional<ActorIsolation>(ActorIsolation::GlobalActor))
184166
.Case("global_actor_unsafe",
185167
std::optional<ActorIsolation>(ActorIsolation::GlobalActor))
186-
.Case("concurrent",
187-
std::optional<ActorIsolation>(ActorIsolation::Concurrent))
188-
.Case("concurrent_unsafe", std::optional<ActorIsolation>(
189-
ActorIsolation::ConcurrentUnsafe))
168+
.Case("caller_isolation_inheriting",
169+
std::optional<ActorIsolation>(
170+
ActorIsolation::CallerIsolationInheriting))
190171
.Default(std::nullopt);
191172
if (kind == std::nullopt)
192173
return std::nullopt;
@@ -199,17 +180,11 @@ class ActorIsolation {
199180

200181
bool isUnspecified() const { return kind == Unspecified; }
201182

202-
bool isConcurrent() const {
203-
return (kind == Concurrent) || (kind == ConcurrentUnsafe);
204-
}
205-
206183
bool isNonisolated() const {
207184
return (kind == Nonisolated) || (kind == NonisolatedUnsafe);
208185
}
209186

210-
bool isUnsafe() const {
211-
return kind == NonisolatedUnsafe || kind == ConcurrentUnsafe;
212-
}
187+
bool isNonisolatedUnsafe() const { return kind == NonisolatedUnsafe; }
213188

214189
/// Retrieve the parameter to which actor-instance isolation applies.
215190
///
@@ -237,8 +212,7 @@ class ActorIsolation {
237212
case Unspecified:
238213
case Nonisolated:
239214
case NonisolatedUnsafe:
240-
case Concurrent:
241-
case ConcurrentUnsafe:
215+
case CallerIsolationInheriting:
242216
return false;
243217
}
244218
}

lib/AST/ASTDumper.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3905,21 +3905,20 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, Label>,
39053905
switch (auto isolation = E->getActorIsolation()) {
39063906
case ActorIsolation::Unspecified:
39073907
case ActorIsolation::NonisolatedUnsafe:
3908-
case ActorIsolation::ConcurrentUnsafe:
39093908
break;
39103909

39113910
case ActorIsolation::Nonisolated:
39123911
printFlag(true, "nonisolated", CapturesColor);
39133912
break;
39143913

3915-
case ActorIsolation::Concurrent:
3916-
printFlag(true, "concurrent", CapturesColor);
3917-
break;
3918-
39193914
case ActorIsolation::Erased:
39203915
printFlag(true, "dynamically_isolated", CapturesColor);
39213916
break;
39223917

3918+
case ActorIsolation::CallerIsolationInheriting:
3919+
printFlag(true, "isolated_to_caller_isolation", CapturesColor);
3920+
break;
3921+
39233922
case ActorIsolation::ActorInstance:
39243923
printReferencedDeclWithContextField(isolation.getActorInstance(),
39253924
Label::always("actor_isolated"),

lib/AST/ActorIsolation.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ ActorIsolation::ActorIsolation(Kind kind, Expr *actor, unsigned parameterIndex)
3939

4040
ActorIsolation::ActorIsolation(Kind kind, Type globalActor)
4141
: globalActor(globalActor), kind(kind), isolatedByPreconcurrency(false),
42-
silParsed(false), parameterIndex(0) {
43-
assert((silParsed || globalActor) &&
44-
"If we are not sil parsed, global actor must be a real type");
45-
}
42+
silParsed(false), parameterIndex(0) {}
4643

4744
ActorIsolation
4845
ActorIsolation::forActorInstanceParameter(Expr *actor,
@@ -52,7 +49,7 @@ ActorIsolation::forActorInstanceParameter(Expr *actor,
5249
// An isolated value of `nil` is statically nonisolated.
5350
// FIXME: Also allow 'Optional.none'
5451
if (isa<NilLiteralExpr>(actor))
55-
return ActorIsolation::forConcurrent(/*unsafe*/ false);
52+
return ActorIsolation::forNonisolated(/*unsafe*/ false);
5653

5754
// An isolated value of `<global actor type>.shared` is statically
5855
// global actor isolated.
@@ -165,8 +162,8 @@ bool ActorIsolation::isEqual(const ActorIsolation &lhs,
165162
return false;
166163

167164
switch (lhs.getKind()) {
168-
case Concurrent:
169-
case ConcurrentUnsafe:
165+
case Nonisolated:
166+
case NonisolatedUnsafe:
170167
case Unspecified:
171168
return true;
172169

@@ -177,8 +174,7 @@ bool ActorIsolation::isEqual(const ActorIsolation &lhs,
177174
// to answer.
178175
return false;
179176

180-
case Nonisolated:
181-
case NonisolatedUnsafe:
177+
case CallerIsolationInheriting:
182178
// This returns false for the same reason as erased. The caller has to check
183179
// against the actual caller isolation.
184180
return false;

lib/AST/Decl.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2757,7 +2757,6 @@ static bool deferMatchesEnclosingAccess(const FuncDecl *defer) {
27572757
switch (isolation) {
27582758
case ActorIsolation::Unspecified:
27592759
case ActorIsolation::NonisolatedUnsafe:
2760-
case ActorIsolation::ConcurrentUnsafe:
27612760
break;
27622761

27632762
case ActorIsolation::GlobalActor:
@@ -2766,9 +2765,9 @@ static bool deferMatchesEnclosingAccess(const FuncDecl *defer) {
27662765

27672766
return true;
27682767

2768+
case ActorIsolation::CallerIsolationInheriting:
27692769
case ActorIsolation::ActorInstance:
27702770
case ActorIsolation::Nonisolated:
2771-
case ActorIsolation::Concurrent:
27722771
case ActorIsolation::Erased: // really can't happen
27732772
return true;
27742773
}
@@ -11452,10 +11451,9 @@ bool VarDecl::isSelfParamCaptureIsolated() const {
1145211451
case ActorIsolation::Unspecified:
1145311452
case ActorIsolation::Nonisolated:
1145411453
case ActorIsolation::NonisolatedUnsafe:
11455-
case ActorIsolation::Concurrent:
11456-
case ActorIsolation::ConcurrentUnsafe:
1145711454
case ActorIsolation::GlobalActor:
1145811455
case ActorIsolation::Erased:
11456+
case ActorIsolation::CallerIsolationInheriting:
1145911457
return false;
1146011458

1146111459
case ActorIsolation::ActorInstance:

lib/AST/TypeCheckRequests.cpp

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,11 +1856,10 @@ SourceLoc MacroDefinitionRequest::getNearestLoc() const {
18561856

18571857
bool ActorIsolation::requiresSubstitution() const {
18581858
switch (kind) {
1859+
case CallerIsolationInheriting:
18591860
case ActorInstance:
18601861
case Nonisolated:
18611862
case NonisolatedUnsafe:
1862-
case Concurrent:
1863-
case ConcurrentUnsafe:
18641863
case Unspecified:
18651864
return false;
18661865

@@ -1873,10 +1872,9 @@ bool ActorIsolation::requiresSubstitution() const {
18731872
ActorIsolation ActorIsolation::subst(SubstitutionMap subs) const {
18741873
switch (kind) {
18751874
case ActorInstance:
1875+
case CallerIsolationInheriting:
18761876
case Nonisolated:
18771877
case NonisolatedUnsafe:
1878-
case Concurrent:
1879-
case ConcurrentUnsafe:
18801878
case Unspecified:
18811879
return *this;
18821880

@@ -1895,6 +1893,11 @@ void ActorIsolation::printForDiagnostics(llvm::raw_ostream &os,
18951893
os << "actor" << (asNoun ? " isolation" : "-isolated");
18961894
break;
18971895

1896+
case ActorIsolation::CallerIsolationInheriting:
1897+
os << "caller isolation inheriting"
1898+
<< (asNoun ? " isolation" : "-isolated");
1899+
break;
1900+
18981901
case ActorIsolation::GlobalActor: {
18991902
if (isMainActor()) {
19001903
os << "main actor" << (asNoun ? " isolation" : "-isolated");
@@ -1909,13 +1912,11 @@ void ActorIsolation::printForDiagnostics(llvm::raw_ostream &os,
19091912
os << "@isolated(any)";
19101913
break;
19111914

1912-
case ActorIsolation::Concurrent:
1913-
case ActorIsolation::ConcurrentUnsafe:
19141915
case ActorIsolation::Nonisolated:
19151916
case ActorIsolation::NonisolatedUnsafe:
19161917
case ActorIsolation::Unspecified:
19171918
os << "nonisolated";
1918-
if (isUnsafe()) {
1919+
if (*this == ActorIsolation::NonisolatedUnsafe) {
19191920
os << "(unsafe)";
19201921
}
19211922
break;
@@ -1933,18 +1934,15 @@ void ActorIsolation::print(llvm::raw_ostream &os) const {
19331934
os << ". name: '" << vd->getBaseIdentifier() << "'";
19341935
}
19351936
return;
1937+
case CallerIsolationInheriting:
1938+
os << "caller_isolation_inheriting";
1939+
return;
19361940
case Nonisolated:
19371941
os << "nonisolated";
19381942
return;
19391943
case NonisolatedUnsafe:
19401944
os << "nonisolated_unsafe";
19411945
return;
1942-
case Concurrent:
1943-
os << "concurrent";
1944-
return;
1945-
case ConcurrentUnsafe:
1946-
os << "concurrent_unsafe";
1947-
return;
19481946
case GlobalActor:
19491947
os << "global_actor. type: " << getGlobalActor();
19501948
return;
@@ -1963,18 +1961,15 @@ void ActorIsolation::printForSIL(llvm::raw_ostream &os) const {
19631961
case ActorInstance:
19641962
os << "actor_instance";
19651963
return;
1964+
case CallerIsolationInheriting:
1965+
os << "caller_isolation_inheriting";
1966+
return;
19661967
case Nonisolated:
19671968
os << "nonisolated";
19681969
return;
19691970
case NonisolatedUnsafe:
19701971
os << "nonisolated_unsafe";
19711972
return;
1972-
case Concurrent:
1973-
os << "concurrent";
1974-
return;
1975-
case ConcurrentUnsafe:
1976-
os << "concurrent_unsafe";
1977-
return;
19781973
case GlobalActor:
19791974
os << "global_actor";
19801975
return;
@@ -2014,12 +2009,14 @@ void swift::simple_display(
20142009
}
20152010
break;
20162011

2012+
case ActorIsolation::CallerIsolationInheriting:
2013+
out << "isolated to isolation of caller";
2014+
break;
2015+
20172016
case ActorIsolation::Nonisolated:
20182017
case ActorIsolation::NonisolatedUnsafe:
2019-
case ActorIsolation::Concurrent:
2020-
case ActorIsolation::ConcurrentUnsafe:
20212018
out << "nonisolated";
2022-
if (state.isUnsafe()) {
2019+
if (state == ActorIsolation::NonisolatedUnsafe) {
20232020
out << "(unsafe)";
20242021
}
20252022
break;

lib/IDE/CompletionLookup.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,9 +827,8 @@ void CompletionLookup::analyzeActorIsolation(
827827
break;
828828
case ActorIsolation::Unspecified:
829829
case ActorIsolation::Nonisolated:
830+
case ActorIsolation::CallerIsolationInheriting:
830831
case ActorIsolation::NonisolatedUnsafe:
831-
case ActorIsolation::Concurrent:
832-
case ActorIsolation::ConcurrentUnsafe:
833832
return;
834833
}
835834
}

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,8 @@ class DestructureInputs {
16511651
// enabled.
16521652
if (TC.Context.LangOpts.hasFeature(
16531653
Feature::NonIsolatedAsyncInheritsIsolationFromContext) &&
1654-
IsolationInfo && IsolationInfo->isNonisolated() &&
1654+
IsolationInfo &&
1655+
IsolationInfo->getKind() == ActorIsolation::CallerIsolationInheriting &&
16551656
extInfoBuilder.isAsync()) {
16561657
auto actorProtocol = TC.Context.getProtocol(KnownProtocolKind::Actor);
16571658
auto actorType =
@@ -2529,15 +2530,15 @@ static CanSILFunctionType getSILFunctionType(
25292530
std::optional<ActorIsolation> actorIsolation;
25302531
if (constant) {
25312532
if (constant->kind == SILDeclRef::Kind::Deallocator) {
2532-
actorIsolation = ActorIsolation::forConcurrent(false);
2533+
actorIsolation = ActorIsolation::forNonisolated(false);
25332534
} else if (auto *decl = constant->getAbstractFunctionDecl();
25342535
decl && decl->getExecutionBehavior().has_value()) {
25352536
switch (*decl->getExecutionBehavior()) {
25362537
case ExecutionKind::Concurrent:
2537-
actorIsolation = ActorIsolation::forConcurrent(false /*unsafe*/);
2538+
actorIsolation = ActorIsolation::forNonisolated(false /*unsafe*/);
25382539
break;
25392540
case ExecutionKind::Caller:
2540-
actorIsolation = ActorIsolation::forNonisolated(false /*unsafe*/);
2541+
actorIsolation = ActorIsolation::forCallerIsolationInheriting();
25412542
break;
25422543
}
25432544
} else {

lib/SILGen/SILGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ static ActorIsolation getActorIsolationForFunction(SILFunction &fn) {
735735
if (constant.kind == SILDeclRef::Kind::Deallocator) {
736736
// Deallocating destructor is always nonisolated. Isolation of the deinit
737737
// applies only to isolated deallocator and destroyer.
738-
return ActorIsolation::forConcurrent(false);
738+
return ActorIsolation::forNonisolated(false);
739739
}
740740

741741
// If we have actor isolation for our constant, put the isolation onto the

lib/SILGen/SILGenApply.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,9 +3104,8 @@ static void emitDelayedArguments(SILGenFunction &SGF,
31043104

31053105
case ActorIsolation::Unspecified:
31063106
case ActorIsolation::Nonisolated:
3107+
case ActorIsolation::CallerIsolationInheriting:
31073108
case ActorIsolation::NonisolatedUnsafe:
3108-
case ActorIsolation::Concurrent:
3109-
case ActorIsolation::ConcurrentUnsafe:
31103109
llvm_unreachable("Not isolated");
31113110
}
31123111

@@ -5833,9 +5832,8 @@ RValue SILGenFunction::emitApply(
58335832

58345833
case ActorIsolation::Unspecified:
58355834
case ActorIsolation::Nonisolated:
5835+
case ActorIsolation::CallerIsolationInheriting:
58365836
case ActorIsolation::NonisolatedUnsafe:
5837-
case ActorIsolation::Concurrent:
5838-
case ActorIsolation::ConcurrentUnsafe:
58395837
llvm_unreachable("Not isolated");
58405838
break;
58415839
}

0 commit comments

Comments
 (0)