Skip to content

Commit 5c56541

Browse files
committed
[Concurrency] Remove swift::computeRequiredIsolation and change all callers to go
through the DefaultInitializerIsolation request. (cherry picked from commit 67e3326)
1 parent db69307 commit 5c56541

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
@@ -2250,7 +2250,9 @@ class PatternBindingDecl final : public Decl,
22502250
void setInitializerSubsumed(unsigned i) {
22512251
getMutablePatternList()[i].setInitializerSubsumed();
22522252
}
2253-
2253+
2254+
ActorIsolation getInitializerIsolation(unsigned i) const;
2255+
22542256
/// Does this binding declare something that requires storage?
22552257
bool hasStorage() const;
22562258

lib/AST/Decl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,6 +2065,14 @@ bool PatternBindingDecl::isAsyncLet() const {
20652065
return false;
20662066
}
20672067

2068+
ActorIsolation
2069+
PatternBindingDecl::getInitializerIsolation(unsigned i) const {
2070+
auto *var = getPatternList()[i].getAnchoringVarDecl();
2071+
if (!var)
2072+
return ActorIsolation::forUnspecified();
2073+
2074+
return var->getInitializerIsolation();
2075+
}
20682076

20692077
bool PatternBindingDecl::hasStorage() const {
20702078
// 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
@@ -3621,12 +3621,6 @@ void swift::checkFunctionActorIsolation(AbstractFunctionDecl *decl) {
36213621
}
36223622
}
36233623

3624-
ActorIsolation
3625-
swift::computeRequiredIsolation(Initializer *init, Expr *expr) {
3626-
ActorIsolationChecker checker(init);
3627-
return checker.computeRequiredIsolation(expr);
3628-
}
3629-
36303624
void swift::checkEnumElementActorIsolation(
36313625
EnumElementDecl *element, Expr *expr) {
36323626
ActorIsolationChecker checker(element);
@@ -4647,6 +4641,48 @@ bool HasIsolatedSelfRequest::evaluate(
46474641
return true;
46484642
}
46494643

4644+
ActorIsolation
4645+
DefaultInitializerIsolation::evaluate(Evaluator &evaluator,
4646+
VarDecl *var) const {
4647+
if (var->isInvalid())
4648+
return ActorIsolation::forUnspecified();
4649+
4650+
Initializer *dc = nullptr;
4651+
Expr *initExpr = nullptr;
4652+
4653+
if (auto *pbd = var->getParentPatternBinding()) {
4654+
if (!var->isParentInitialized())
4655+
return ActorIsolation::forUnspecified();
4656+
4657+
auto i = pbd->getPatternEntryIndexForVarDecl(var);
4658+
dc = cast<Initializer>(pbd->getInitContext(i));
4659+
initExpr = var->getParentInitializer();
4660+
} else if (auto *param = dyn_cast<ParamDecl>(var)) {
4661+
// If this parameter corresponds to a stored property for a
4662+
// memberwise initializer, the default argument is the default
4663+
// initializer expression.
4664+
if (auto *property = param->getStoredProperty()) {
4665+
// FIXME: Force computation of property wrapper initializers.
4666+
if (auto *wrapped = property->getOriginalWrappedProperty())
4667+
(void)property->getPropertyWrapperInitializerInfo();
4668+
4669+
return property->getInitializerIsolation();
4670+
}
4671+
4672+
if (!param->hasDefaultExpr())
4673+
return ActorIsolation::forUnspecified();
4674+
4675+
dc = param->getDefaultArgumentInitContext();
4676+
initExpr = param->getTypeCheckedDefaultExpr();
4677+
}
4678+
4679+
if (!dc || !initExpr)
4680+
return ActorIsolation::forUnspecified();
4681+
4682+
ActorIsolationChecker checker(dc);
4683+
return checker.computeRequiredIsolation(initExpr);
4684+
}
4685+
46504686
void swift::checkOverrideActorIsolation(ValueDecl *value) {
46514687
if (isa<TypeDecl>(value))
46524688
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)