Skip to content

Commit 67e3326

Browse files
committed
[Concurrency] Remove swift::computeRequiredIsolation and change all callers to go
through the DefaultInitializerIsolation request.
1 parent 3cb9bb8 commit 67e3326

File tree

6 files changed

+59
-57
lines changed

6 files changed

+59
-57
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2273,7 +2273,9 @@ class PatternBindingDecl final : public Decl,
22732273
void setInitializerSubsumed(unsigned i) {
22742274
getMutablePatternList()[i].setInitializerSubsumed();
22752275
}
2276-
2276+
2277+
ActorIsolation getInitializerIsolation(unsigned i) const;
2278+
22772279
/// Does this binding declare something that requires storage?
22782280
bool hasStorage() const;
22792281

lib/AST/Decl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,6 +2088,14 @@ bool PatternBindingDecl::isAsyncLet() const {
20882088
return false;
20892089
}
20902090

2091+
ActorIsolation
2092+
PatternBindingDecl::getInitializerIsolation(unsigned i) const {
2093+
auto *var = getPatternList()[i].getAnchoringVarDecl();
2094+
if (!var)
2095+
return ActorIsolation::forUnspecified();
2096+
2097+
return var->getInitializerIsolation();
2098+
}
20912099

20922100
bool PatternBindingDecl::hasStorage() const {
20932101
// Walk the pattern, to check to see if any of the VarDecls included in it

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3582,12 +3582,6 @@ void swift::checkFunctionActorIsolation(AbstractFunctionDecl *decl) {
35823582
}
35833583
}
35843584

3585-
ActorIsolation
3586-
swift::computeRequiredIsolation(Initializer *init, Expr *expr) {
3587-
ActorIsolationChecker checker(init);
3588-
return checker.computeRequiredIsolation(expr);
3589-
}
3590-
35913585
void swift::checkEnumElementActorIsolation(
35923586
EnumElementDecl *element, Expr *expr) {
35933587
ActorIsolationChecker checker(element);
@@ -4618,6 +4612,48 @@ bool HasIsolatedSelfRequest::evaluate(
46184612
return true;
46194613
}
46204614

4615+
ActorIsolation
4616+
DefaultInitializerIsolation::evaluate(Evaluator &evaluator,
4617+
VarDecl *var) const {
4618+
if (var->isInvalid())
4619+
return ActorIsolation::forUnspecified();
4620+
4621+
Initializer *dc = nullptr;
4622+
Expr *initExpr = nullptr;
4623+
4624+
if (auto *pbd = var->getParentPatternBinding()) {
4625+
if (!var->isParentInitialized())
4626+
return ActorIsolation::forUnspecified();
4627+
4628+
auto i = pbd->getPatternEntryIndexForVarDecl(var);
4629+
dc = cast<Initializer>(pbd->getInitContext(i));
4630+
initExpr = var->getParentInitializer();
4631+
} else if (auto *param = dyn_cast<ParamDecl>(var)) {
4632+
// If this parameter corresponds to a stored property for a
4633+
// memberwise initializer, the default argument is the default
4634+
// initializer expression.
4635+
if (auto *property = param->getStoredProperty()) {
4636+
// FIXME: Force computation of property wrapper initializers.
4637+
if (auto *wrapped = property->getOriginalWrappedProperty())
4638+
(void)property->getPropertyWrapperInitializerInfo();
4639+
4640+
return property->getInitializerIsolation();
4641+
}
4642+
4643+
if (!param->hasDefaultExpr())
4644+
return ActorIsolation::forUnspecified();
4645+
4646+
dc = param->getDefaultArgumentInitContext();
4647+
initExpr = param->getTypeCheckedDefaultExpr();
4648+
}
4649+
4650+
if (!dc || !initExpr)
4651+
return ActorIsolation::forUnspecified();
4652+
4653+
ActorIsolationChecker checker(dc);
4654+
return checker.computeRequiredIsolation(initExpr);
4655+
}
4656+
46214657
void swift::checkOverrideActorIsolation(ValueDecl *value) {
46224658
if (isa<TypeDecl>(value))
46234659
return;

lib/Sema/TypeCheckConcurrency.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ void checkFunctionActorIsolation(AbstractFunctionDecl *decl);
5959
void checkEnumElementActorIsolation(EnumElementDecl *element, Expr *expr);
6060
void checkPropertyWrapperActorIsolation(VarDecl *wrappedVar, Expr *expr);
6161

62-
/// Compute the actor isolation required in order to evaluate the given
63-
/// initializer expression synchronously.
64-
ActorIsolation computeRequiredIsolation(Initializer *init, Expr *expr);
65-
6662
/// States the reason for checking the Sendability of a given declaration.
6763
enum class SendableCheckReason {
6864
/// A reference to an actor from outside that actor.

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,47 +1156,6 @@ Expr *DefaultArgumentExprRequest::evaluate(Evaluator &evaluator,
11561156
return initExpr;
11571157
}
11581158

1159-
ActorIsolation
1160-
DefaultInitializerIsolation::evaluate(Evaluator &evaluator,
1161-
VarDecl *var) const {
1162-
if (var->isInvalid())
1163-
return ActorIsolation::forUnspecified();
1164-
1165-
Initializer *dc = nullptr;
1166-
Expr *initExpr = nullptr;
1167-
1168-
if (auto *pbd = var->getParentPatternBinding()) {
1169-
if (!var->isParentInitialized())
1170-
return ActorIsolation::forUnspecified();
1171-
1172-
auto i = pbd->getPatternEntryIndexForVarDecl(var);
1173-
dc = cast<Initializer>(pbd->getInitContext(i));
1174-
initExpr = var->getParentInitializer();
1175-
} else if (auto *param = dyn_cast<ParamDecl>(var)) {
1176-
// If this parameter corresponds to a stored property for a
1177-
// memberwise initializer, the default argument is the default
1178-
// initializer expression.
1179-
if (auto *property = param->getStoredProperty()) {
1180-
// FIXME: Force computation of property wrapper initializers.
1181-
if (auto *wrapped = property->getOriginalWrappedProperty())
1182-
(void)property->getPropertyWrapperInitializerInfo();
1183-
1184-
return property->getInitializerIsolation();
1185-
}
1186-
1187-
if (!param->hasDefaultExpr())
1188-
return ActorIsolation::forUnspecified();
1189-
1190-
dc = param->getDefaultArgumentInitContext();
1191-
initExpr = param->getTypeCheckedDefaultExpr();
1192-
}
1193-
1194-
if (!dc || !initExpr)
1195-
return ActorIsolation::forUnspecified();
1196-
1197-
return computeRequiredIsolation(dc, initExpr);
1198-
}
1199-
12001159
Type DefaultArgumentTypeRequest::evaluate(Evaluator &evaluator,
12011160
ParamDecl *param) const {
12021161
if (auto *expr = param->getTypeCheckedDefaultExpr()) {
@@ -2507,11 +2466,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
25072466
PBD->getInitContext(i));
25082467
if (initContext) {
25092468
TypeChecker::contextualizeInitializer(initContext, init);
2510-
if (auto *singleVar = PBD->getSingleVar()) {
2511-
(void)singleVar->getInitializerIsolation();
2512-
} else {
2513-
computeRequiredIsolation(initContext, init);
2514-
}
2469+
(void)PBD->getInitializerIsolation(i);
25152470
TypeChecker::checkInitializerEffects(initContext, init);
25162471
}
25172472
}

test/Concurrency/isolated_default_arguments.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ struct S2 {
147147
static var z: Int = requiresSomeGlobalActor()
148148
}
149149

150+
struct S3 {
151+
// expected-error@+1 {{default argument cannot be both main actor-isolated and global actor 'SomeGlobalActor'-isolated}}
152+
var (x, y, z) = (requiresMainActor(), requiresSomeGlobalActor(), 10)
153+
}
154+
150155
@MainActor
151156
func initializeFromMainActor() {
152157
_ = S1(required: 10)

0 commit comments

Comments
 (0)