Skip to content

Commit f4b75ac

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 9d111b1 commit f4b75ac

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()) {
@@ -3981,12 +3985,19 @@ bool swift::contextRequiresStrictConcurrencyChecking(
39813985

39823986
while (!dc->isModuleScopeContext()) {
39833987
if (auto closure = dyn_cast<AbstractClosureExpr>(dc)) {
3984-
// A closure with an explicit global actor or nonindependent
3988+
// A closure with an explicit global actor, async, or Sendable
39853989
// uses concurrency features.
39863990
if (auto explicitClosure = dyn_cast<ClosureExpr>(closure)) {
39873991
if (getExplicitGlobalActor(const_cast<ClosureExpr *>(explicitClosure)))
39883992
return true;
39893993

3994+
// Don't take any more cues if this only got its type information by
3995+
// being provided to a `@preconcurrency` operation.
3996+
if (explicitClosure->isIsolatedByPreconcurrency()) {
3997+
dc = dc->getParent();
3998+
continue;
3999+
}
4000+
39904001
if (auto type = getType(closure)) {
39914002
if (auto fnType = type->getAs<AnyFunctionType>())
39924003
if (fnType->isAsync() || fnType->isSendable())
@@ -4590,7 +4601,7 @@ static AnyFunctionType *applyUnsafeConcurrencyToFunctionType(
45904601
if (addSendable || addMainActor) {
45914602
newParamType = applyUnsafeConcurrencyToParameterType(
45924603
param.getPlainType(), addSendable, addMainActor);
4593-
} else if (stripConcurrency) {
4604+
} else if (stripConcurrency && numApplies == 0) {
45944605
newParamType = param.getPlainType()->stripConcurrency(
45954606
/*recurse=*/false, /*dropGlobalActor=*/numApplies == 0);
45964607
}

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)