Skip to content

Commit 91998f6

Browse files
committed
[Constriant solver] Don't adjust types in calls to @preconcurrency functions
When calling a `@preconcurrency` function, don't adjust the types of parameters. Instead, we'll suppress or alter diagnostics later on to deal with Sendable and global-actor mismatches. Fixes the crash from rdar://95995193, but diagnostics need more work.
1 parent fc24be2 commit 91998f6

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,10 @@ static bool isSendableClosure(
544544
if (forActorIsolation && explicitClosure->inheritsActorContext()) {
545545
return false;
546546
}
547+
548+
if (explicitClosure->isIsolatedByPreconcurrency() &&
549+
!shouldDiagnoseExistingDataRaces(closure->getParent()))
550+
return false;
547551
}
548552

549553
if (auto type = closure->getType()) {
@@ -4032,12 +4036,19 @@ bool swift::contextRequiresStrictConcurrencyChecking(
40324036

40334037
while (!dc->isModuleScopeContext()) {
40344038
if (auto closure = dyn_cast<AbstractClosureExpr>(dc)) {
4035-
// A closure with an explicit global actor or nonindependent
4039+
// A closure with an explicit global actor, async, or Sendable
40364040
// uses concurrency features.
40374041
if (auto explicitClosure = dyn_cast<ClosureExpr>(closure)) {
40384042
if (getExplicitGlobalActor(const_cast<ClosureExpr *>(explicitClosure)))
40394043
return true;
40404044

4045+
// Don't take any more cues if this only got its type information by
4046+
// being provided to a `@preconcurrency` operation.
4047+
if (explicitClosure->isIsolatedByPreconcurrency()) {
4048+
dc = dc->getParent();
4049+
continue;
4050+
}
4051+
40414052
if (auto type = getType(closure)) {
40424053
if (auto fnType = type->getAs<AnyFunctionType>())
40434054
if (fnType->isAsync() || fnType->isSendable())
@@ -4641,7 +4652,7 @@ static AnyFunctionType *applyUnsafeConcurrencyToFunctionType(
46414652
if (addSendable || addMainActor) {
46424653
newParamType = applyUnsafeConcurrencyToParameterType(
46434654
param.getPlainType(), addSendable, addMainActor);
4644-
} else if (stripConcurrency) {
4655+
} else if (stripConcurrency && numApplies == 0) {
46454656
newParamType = param.getPlainType()->stripConcurrency(
46464657
/*recurse=*/false, /*dropGlobalActor=*/numApplies == 0);
46474658
}

test/SILGen/preconcurrency.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ func testModuleMethodWithSendable(any: Any) {
1414

1515
// CHECK: function_ref @$s14preconcurrency1fyyypF : $@convention(thin) (@in_guaranteed Sendable) -> ()
1616
let _ = preconcurrency.f
17-
// f(any)
18-
// preconcurrency.f(any)
17+
f(any)
18+
preconcurrency.f(any)
1919
}
2020

2121
// CHECK-LABEL: sil hidden [ossa] @$s14preconcurrency30testInstanceMethodWithSendable1c3anyyAA1CC_yptF : $@convention(thin) (@guaranteed C, @in_guaranteed Any) -> () {
@@ -25,5 +25,5 @@ func testInstanceMethodWithSendable(c: C, any: Any) {
2525
let _ = c.f
2626
let _ = C.f
2727
let _ = C.g
28-
// c.f(any)
28+
c.f(any)
2929
}

0 commit comments

Comments
 (0)