Skip to content

Commit e653423

Browse files
committed
[Concurrency] Make sure to record the actor for #isolation when used as
a default argument for a regular (not isolated) parameter.
1 parent a8a55eb commit e653423

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,6 +2427,8 @@ namespace {
24272427
}
24282428

24292429
void checkDefaultArgument(DefaultArgumentExpr *expr) {
2430+
getCurrentContextIsolation(expr);
2431+
24302432
// Check the context isolation against the required isolation for
24312433
// evaluating the default argument synchronously. If the default
24322434
// argument must be evaluated asynchronously, record that in the
@@ -3378,19 +3380,8 @@ namespace {
33783380

33793381
// FIXME: CurrentContextIsolationExpr does not have its actor set
33803382
// at this point.
3381-
if (auto *defaultArg = dyn_cast<DefaultArgumentExpr>(arg)) {
3382-
// Look through caller-side default arguments for #isolation.
3383-
if (defaultArg->isCallerSide()) {
3384-
arg = defaultArg->getCallerSideDefaultExpr();
3385-
}
3386-
}
3387-
if (auto *macro = dyn_cast<MacroExpansionExpr>(arg)) {
3388-
auto *expansion = macro->getRewritten();
3389-
if (auto *isolation = dyn_cast<CurrentContextIsolationExpr>(expansion)) {
3390-
recordCurrentContextIsolation(isolation);
3391-
arg = isolation->getActor();
3392-
}
3393-
}
3383+
if (auto isolation = getCurrentContextIsolation(arg))
3384+
arg = isolation;
33943385

33953386
argForIsolatedParam = arg;
33963387
unsatisfiedIsolation = std::nullopt;
@@ -3553,6 +3544,25 @@ namespace {
35533544
return false;
35543545
}
35553546

3547+
Expr *getCurrentContextIsolation(Expr *expr) {
3548+
// Look through caller-side default arguments for #isolation.
3549+
auto *defaultArg = dyn_cast<DefaultArgumentExpr>(expr);
3550+
if (defaultArg && defaultArg->isCallerSide()) {
3551+
expr = defaultArg->getCallerSideDefaultExpr();
3552+
}
3553+
3554+
if (auto *macro = dyn_cast<MacroExpansionExpr>(expr)) {
3555+
expr = macro->getRewritten();
3556+
}
3557+
3558+
if (auto *isolation = dyn_cast<CurrentContextIsolationExpr>(expr)) {
3559+
recordCurrentContextIsolation(isolation);
3560+
return isolation->getActor();
3561+
}
3562+
3563+
return nullptr;
3564+
}
3565+
35563566
void recordCurrentContextIsolation(
35573567
CurrentContextIsolationExpr *isolationExpr) {
35583568
// If an actor has already been assigned, we're done.

test/Concurrency/isolated_parameters.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,11 @@ public func useDefaultIsolation(
482482
_ isolation: isolated (any Actor)? = #isolation
483483
) {}
484484

485+
public func useDefaultIsolationWithoutIsolatedParam(
486+
_ isolation: (any Actor)? = #isolation
487+
) {}
488+
485489
@MainActor func callUseDefaultIsolation() async {
486490
useDefaultIsolation()
491+
useDefaultIsolationWithoutIsolatedParam()
487492
}

0 commit comments

Comments
 (0)