Skip to content

Commit 7e350bb

Browse files
committed
Revert "[concurrency] Add Concurrent/ConcurrentUnsafe and use it instead of ActorIsolation::Nonisolated."
This reverts commit 0cb6463.
1 parent f05f08c commit 7e350bb

30 files changed

+225
-387
lines changed

include/swift/AST/ActorIsolation.h

Lines changed: 4 additions & 49 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.
@@ -85,20 +74,6 @@ class ActorIsolation {
8574
/// DISCUSSION: This is used for nonisolated asynchronous functions that we
8675
/// want to inherit from their context the context's actor isolation.
8776
CallerIsolationInheriting,
88-
/// The declaration is explicitly specified to be not isolated to any actor,
89-
/// meaning that it can be used from any actor but is also unable to
90-
/// refer to the isolated state of any given actor.
91-
///
92-
/// NOTE: This used to be nonisolated, but we changed nonisolated to have a
93-
/// weaker definition of nonisolated that allows for actor isolated state to
94-
/// be manipulated by code generated to work with the actor as long as all
95-
/// such code generation is guaranteed to always run on whatever actor
96-
/// isolation it is invoked in consistently and not escape the value to any
97-
/// other isolation domain.
98-
Concurrent,
99-
/// The declaration is explicitly specified to be concurrent and with the
100-
/// "unsafe" annotation, which means that we do not enforce isolation.
101-
ConcurrentUnsafe,
10277
};
10378

10479
private:
@@ -107,13 +82,13 @@ class ActorIsolation {
10782
Type globalActor;
10883
void *pointer;
10984
};
110-
unsigned kind : 4;
85+
unsigned kind : 3;
11186
unsigned isolatedByPreconcurrency : 1;
11287

11388
/// Set to true if this was parsed from SIL.
11489
unsigned silParsed : 1;
11590

116-
unsigned parameterIndex : 26;
91+
unsigned parameterIndex : 27;
11792

11893
ActorIsolation(Kind kind, NominalTypeDecl *actor, unsigned parameterIndex);
11994

@@ -137,10 +112,6 @@ class ActorIsolation {
137112
return ActorIsolation(unsafe ? NonisolatedUnsafe : Nonisolated);
138113
}
139114

140-
static ActorIsolation forConcurrent(bool unsafe) {
141-
return ActorIsolation(unsafe ? ConcurrentUnsafe : Concurrent);
142-
}
143-
144115
static ActorIsolation forCallerIsolationInheriting() {
145116
// NOTE: We do not use parameter indices since the parameter is implicit
146117
// from the perspective of the AST.
@@ -197,10 +168,6 @@ class ActorIsolation {
197168
.Case("caller_isolation_inheriting",
198169
std::optional<ActorIsolation>(
199170
ActorIsolation::CallerIsolationInheriting))
200-
.Case("concurrent",
201-
std::optional<ActorIsolation>(ActorIsolation::Concurrent))
202-
.Case("concurrent_unsafe", std::optional<ActorIsolation>(
203-
ActorIsolation::ConcurrentUnsafe))
204171
.Default(std::nullopt);
205172
if (kind == std::nullopt)
206173
return std::nullopt;
@@ -213,22 +180,12 @@ class ActorIsolation {
213180

214181
bool isUnspecified() const { return kind == Unspecified; }
215182

216-
bool isConcurrent() const {
217-
return (kind == Concurrent) || (kind == ConcurrentUnsafe);
218-
}
219-
220-
bool isConcurrentUnsafe() const { return kind == ConcurrentUnsafe; }
221-
222183
bool isNonisolated() const {
223184
return (kind == Nonisolated) || (kind == NonisolatedUnsafe);
224185
}
225186

226187
bool isNonisolatedUnsafe() const { return kind == NonisolatedUnsafe; }
227188

228-
bool isUnsafe() const {
229-
return kind == NonisolatedUnsafe || kind == ConcurrentUnsafe;
230-
}
231-
232189
/// Retrieve the parameter to which actor-instance isolation applies.
233190
///
234191
/// Parameter 0 is `self`.
@@ -256,8 +213,6 @@ class ActorIsolation {
256213
case Nonisolated:
257214
case NonisolatedUnsafe:
258215
case CallerIsolationInheriting:
259-
case Concurrent:
260-
case ConcurrentUnsafe:
261216
return false;
262217
}
263218
}

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3905,17 +3905,12 @@ 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;

lib/AST/ActorIsolation.cpp

Lines changed: 2 additions & 7 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.
@@ -167,8 +164,6 @@ bool ActorIsolation::isEqual(const ActorIsolation &lhs,
167164
switch (lhs.getKind()) {
168165
case Nonisolated:
169166
case NonisolatedUnsafe:
170-
case Concurrent:
171-
case ConcurrentUnsafe:
172167
case Unspecified:
173168
return true;
174169

lib/AST/Decl.cpp

Lines changed: 0 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:
@@ -2769,7 +2768,6 @@ static bool deferMatchesEnclosingAccess(const FuncDecl *defer) {
27692768
case ActorIsolation::CallerIsolationInheriting:
27702769
case ActorIsolation::ActorInstance:
27712770
case ActorIsolation::Nonisolated:
2772-
case ActorIsolation::Concurrent:
27732771
case ActorIsolation::Erased: // really can't happen
27742772
return true;
27752773
}
@@ -11463,8 +11461,6 @@ bool VarDecl::isSelfParamCaptureIsolated() const {
1146311461
case ActorIsolation::Unspecified:
1146411462
case ActorIsolation::Nonisolated:
1146511463
case ActorIsolation::NonisolatedUnsafe:
11466-
case ActorIsolation::Concurrent:
11467-
case ActorIsolation::ConcurrentUnsafe:
1146811464
case ActorIsolation::GlobalActor:
1146911465
case ActorIsolation::Erased:
1147011466
case ActorIsolation::CallerIsolationInheriting:

lib/AST/TypeCheckRequests.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,8 +1860,6 @@ bool ActorIsolation::requiresSubstitution() const {
18601860
case ActorInstance:
18611861
case Nonisolated:
18621862
case NonisolatedUnsafe:
1863-
case Concurrent:
1864-
case ConcurrentUnsafe:
18651863
case Unspecified:
18661864
return false;
18671865

@@ -1877,8 +1875,6 @@ ActorIsolation ActorIsolation::subst(SubstitutionMap subs) const {
18771875
case CallerIsolationInheriting:
18781876
case Nonisolated:
18791877
case NonisolatedUnsafe:
1880-
case Concurrent:
1881-
case ConcurrentUnsafe:
18821878
case Unspecified:
18831879
return *this;
18841880

@@ -1916,13 +1912,11 @@ void ActorIsolation::printForDiagnostics(llvm::raw_ostream &os,
19161912
os << "@isolated(any)";
19171913
break;
19181914

1919-
case ActorIsolation::Concurrent:
1920-
case ActorIsolation::ConcurrentUnsafe:
19211915
case ActorIsolation::Nonisolated:
19221916
case ActorIsolation::NonisolatedUnsafe:
19231917
case ActorIsolation::Unspecified:
19241918
os << "nonisolated";
1925-
if (isUnsafe()) {
1919+
if (*this == ActorIsolation::NonisolatedUnsafe) {
19261920
os << "(unsafe)";
19271921
}
19281922
break;
@@ -1949,12 +1943,6 @@ void ActorIsolation::print(llvm::raw_ostream &os) const {
19491943
case NonisolatedUnsafe:
19501944
os << "nonisolated_unsafe";
19511945
return;
1952-
case Concurrent:
1953-
os << "concurrent";
1954-
return;
1955-
case ConcurrentUnsafe:
1956-
os << "concurrent_unsafe";
1957-
return;
19581946
case GlobalActor:
19591947
os << "global_actor. type: " << getGlobalActor();
19601948
return;
@@ -1982,12 +1970,6 @@ void ActorIsolation::printForSIL(llvm::raw_ostream &os) const {
19821970
case NonisolatedUnsafe:
19831971
os << "nonisolated_unsafe";
19841972
return;
1985-
case Concurrent:
1986-
os << "concurrent";
1987-
return;
1988-
case ConcurrentUnsafe:
1989-
os << "concurrent_unsafe";
1990-
return;
19911973
case GlobalActor:
19921974
os << "global_actor";
19931975
return;
@@ -2033,10 +2015,8 @@ void swift::simple_display(
20332015

20342016
case ActorIsolation::Nonisolated:
20352017
case ActorIsolation::NonisolatedUnsafe:
2036-
case ActorIsolation::Concurrent:
2037-
case ActorIsolation::ConcurrentUnsafe:
20382018
out << "nonisolated";
2039-
if (state.isUnsafe()) {
2019+
if (state == ActorIsolation::NonisolatedUnsafe) {
20402020
out << "(unsafe)";
20412021
}
20422022
break;

lib/IDE/CompletionLookup.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -827,10 +827,8 @@ void CompletionLookup::analyzeActorIsolation(
827827
break;
828828
case ActorIsolation::Unspecified:
829829
case ActorIsolation::Nonisolated:
830-
case ActorIsolation::NonisolatedUnsafe:
831-
case ActorIsolation::Concurrent:
832-
case ActorIsolation::ConcurrentUnsafe:
833830
case ActorIsolation::CallerIsolationInheriting:
831+
case ActorIsolation::NonisolatedUnsafe:
834832
return;
835833
}
836834
}

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,12 +2530,12 @@ static CanSILFunctionType getSILFunctionType(
25302530
std::optional<ActorIsolation> actorIsolation;
25312531
if (constant) {
25322532
if (constant->kind == SILDeclRef::Kind::Deallocator) {
2533-
actorIsolation = ActorIsolation::forConcurrent(false);
2533+
actorIsolation = ActorIsolation::forNonisolated(false);
25342534
} else if (auto *decl = constant->getAbstractFunctionDecl();
25352535
decl && decl->getExecutionBehavior().has_value()) {
25362536
switch (*decl->getExecutionBehavior()) {
25372537
case ExecutionKind::Concurrent:
2538-
actorIsolation = ActorIsolation::forConcurrent(false /*unsafe*/);
2538+
actorIsolation = ActorIsolation::forNonisolated(false /*unsafe*/);
25392539
break;
25402540
case ExecutionKind::Caller:
25412541
actorIsolation = ActorIsolation::forCallerIsolationInheriting();

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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,10 +3104,8 @@ static void emitDelayedArguments(SILGenFunction &SGF,
31043104

31053105
case ActorIsolation::Unspecified:
31063106
case ActorIsolation::Nonisolated:
3107-
case ActorIsolation::NonisolatedUnsafe:
3108-
case ActorIsolation::Concurrent:
3109-
case ActorIsolation::ConcurrentUnsafe:
31103107
case ActorIsolation::CallerIsolationInheriting:
3108+
case ActorIsolation::NonisolatedUnsafe:
31113109
llvm_unreachable("Not isolated");
31123110
}
31133111

@@ -5834,10 +5832,8 @@ RValue SILGenFunction::emitApply(
58345832

58355833
case ActorIsolation::Unspecified:
58365834
case ActorIsolation::Nonisolated:
5837-
case ActorIsolation::NonisolatedUnsafe:
5838-
case ActorIsolation::Concurrent:
5839-
case ActorIsolation::ConcurrentUnsafe:
58405835
case ActorIsolation::CallerIsolationInheriting:
5836+
case ActorIsolation::NonisolatedUnsafe:
58415837
llvm_unreachable("Not isolated");
58425838
break;
58435839
}

lib/SILGen/SILGenConcurrency.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ void SILGenFunction::emitExpectedExecutorProlog() {
106106
// the instance properties of the class.
107107
return false;
108108

109-
case ActorIsolation::Concurrent:
110-
case ActorIsolation::ConcurrentUnsafe:
111109
case ActorIsolation::Nonisolated:
112110
case ActorIsolation::NonisolatedUnsafe:
113111
case ActorIsolation::Unspecified:
@@ -167,8 +165,6 @@ void SILGenFunction::emitExpectedExecutorProlog() {
167165
case ActorIsolation::Unspecified:
168166
case ActorIsolation::Nonisolated:
169167
case ActorIsolation::NonisolatedUnsafe:
170-
case ActorIsolation::Concurrent:
171-
case ActorIsolation::ConcurrentUnsafe:
172168
break;
173169

174170
case ActorIsolation::Erased:
@@ -209,10 +205,8 @@ void SILGenFunction::emitExpectedExecutorProlog() {
209205
switch (actorIsolation.getKind()) {
210206
case ActorIsolation::Unspecified:
211207
case ActorIsolation::Nonisolated:
212-
case ActorIsolation::NonisolatedUnsafe:
213-
case ActorIsolation::Concurrent:
214-
case ActorIsolation::ConcurrentUnsafe:
215208
case ActorIsolation::CallerIsolationInheriting:
209+
case ActorIsolation::NonisolatedUnsafe:
216210
break;
217211

218212
case ActorIsolation::Erased:
@@ -639,10 +633,8 @@ SILGenFunction::emitClosureIsolation(SILLocation loc, SILDeclRef constant,
639633
switch (isolation) {
640634
case ActorIsolation::Unspecified:
641635
case ActorIsolation::Nonisolated:
642-
case ActorIsolation::NonisolatedUnsafe:
643-
case ActorIsolation::Concurrent:
644-
case ActorIsolation::ConcurrentUnsafe:
645636
case ActorIsolation::CallerIsolationInheriting:
637+
case ActorIsolation::NonisolatedUnsafe:
646638
return emitNonIsolatedIsolation(loc);
647639

648640
case ActorIsolation::Erased:
@@ -693,10 +685,8 @@ SILGenFunction::emitExecutor(SILLocation loc, ActorIsolation isolation,
693685
switch (isolation.getKind()) {
694686
case ActorIsolation::Unspecified:
695687
case ActorIsolation::Nonisolated:
696-
case ActorIsolation::NonisolatedUnsafe:
697-
case ActorIsolation::Concurrent:
698-
case ActorIsolation::ConcurrentUnsafe:
699688
case ActorIsolation::CallerIsolationInheriting:
689+
case ActorIsolation::NonisolatedUnsafe:
700690
return std::nullopt;
701691

702692
case ActorIsolation::Erased:
@@ -726,8 +716,6 @@ void SILGenFunction::emitHopToActorValue(SILLocation loc, ManagedValue actor) {
726716
});
727717
if (isolation != ActorIsolation::Nonisolated &&
728718
isolation != ActorIsolation::NonisolatedUnsafe &&
729-
isolation != ActorIsolation::Concurrent &&
730-
isolation != ActorIsolation::ConcurrentUnsafe &&
731719
isolation != ActorIsolation::Unspecified) {
732720
// TODO: Explicit hop with no hop-back should only be allowed in nonisolated
733721
// async functions. But it needs work for any closure passed to

lib/SILGen/SILGenConstructor.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,6 @@ static bool ctorHopsInjectedByDefiniteInit(ConstructorDecl *ctor,
603603
case ActorIsolation::Unspecified:
604604
case ActorIsolation::Nonisolated:
605605
case ActorIsolation::NonisolatedUnsafe:
606-
case ActorIsolation::Concurrent:
607-
case ActorIsolation::ConcurrentUnsafe:
608606
case ActorIsolation::GlobalActor:
609607
case ActorIsolation::CallerIsolationInheriting:
610608
return false;
@@ -1560,8 +1558,6 @@ void SILGenFunction::emitMemberInitializer(DeclContext *dc, VarDecl *selfDecl,
15601558
case ActorIsolation::Unspecified:
15611559
case ActorIsolation::Nonisolated:
15621560
case ActorIsolation::NonisolatedUnsafe:
1563-
case ActorIsolation::Concurrent:
1564-
case ActorIsolation::ConcurrentUnsafe:
15651561
case ActorIsolation::CallerIsolationInheriting:
15661562
break;
15671563

0 commit comments

Comments
 (0)