Skip to content

Commit e7f7900

Browse files
authored
Merge pull request swiftlang#71829 from gottesmm/pr-071a183496e8c0d173d958388af193d807f57f56
[region-isolation] Change two diagnostics to use the user facing sugared type instead of the SIL type
2 parents 1306f2b + c698f7c commit e7f7900

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

lib/SILOptimizer/Mandatory/TransferNonSendable.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,12 +1038,13 @@ class TransferNonTransferrableDiagnosticInferrer {
10381038
}
10391039

10401040
static UseDiagnosticInfo
1041-
forFunctionArgumentClosure(ApplyIsolationCrossing isolation) {
1042-
return {UseDiagnosticInfoKind::FunctionArgumentClosure, isolation};
1041+
forFunctionArgumentClosure(ApplyIsolationCrossing isolation, Type inferredType) {
1042+
return {UseDiagnosticInfoKind::FunctionArgumentClosure, isolation, inferredType};
10431043
}
10441044

1045-
static UseDiagnosticInfo forFunctionArgumentApplyStronglyTransferred() {
1046-
return {UseDiagnosticInfoKind::FunctionArgumentApplyStronglyTransferred};
1045+
static UseDiagnosticInfo forFunctionArgumentApplyStronglyTransferred(Type inferredType) {
1046+
return {UseDiagnosticInfoKind::FunctionArgumentApplyStronglyTransferred, {},
1047+
inferredType};
10471048
}
10481049

10491050
static UseDiagnosticInfo
@@ -1106,8 +1107,9 @@ bool TransferNonTransferrableDiagnosticInferrer::initForIsolatedPartialApply(
11061107
for (auto &p : foundCapturedIsolationCrossing) {
11071108
if (std::get<1>(p) == opIndex) {
11081109
loc = std::get<0>(p).getLoc();
1110+
Type type = std::get<0>(p).getDecl()->getInterfaceType();
11091111
diagnosticInfo =
1110-
UseDiagnosticInfo::forFunctionArgumentClosure(std::get<2>(p));
1112+
UseDiagnosticInfo::forFunctionArgumentClosure(std::get<2>(p), type);
11111113
return true;
11121114
}
11131115
}
@@ -1155,8 +1157,14 @@ bool TransferNonTransferrableDiagnosticInferrer::run() {
11551157
if (auto fas = FullApplySite::isa(op->getUser())) {
11561158
if (fas.getArgumentParameterInfo(*op).hasOption(
11571159
SILParameterInfo::Transferring)) {
1160+
Type type = op->get()->getType().getASTType();
1161+
if (auto *inferredArgExpr =
1162+
inferArgumentExprFromApplyExpr(sourceApply, fas, op)) {
1163+
type = inferredArgExpr->findOriginalType();
1164+
}
1165+
11581166
diagnosticInfo =
1159-
UseDiagnosticInfo::forFunctionArgumentApplyStronglyTransferred();
1167+
UseDiagnosticInfo::forFunctionArgumentApplyStronglyTransferred(type);
11601168
return true;
11611169
}
11621170
}
@@ -1262,7 +1270,7 @@ void TransferNonSendableImpl::emitTransferredNonTransferrableDiagnostics() {
12621270
}
12631271
case UseDiagnosticInfoKind::FunctionArgumentClosure: {
12641272
diagnoseError(astContext, loc, diag::regionbasedisolation_arg_transferred,
1265-
op->get()->getType().getASTType(),
1273+
diagnosticInfo.getType(),
12661274
diagnosticInfo.getIsolationCrossing().getCalleeIsolation())
12671275
.highlight(op->getUser()->getLoc().getSourceRange());
12681276
// Only emit the note if our value is different from the function
@@ -1283,7 +1291,7 @@ void TransferNonSendableImpl::emitTransferredNonTransferrableDiagnostics() {
12831291
diagnoseError(
12841292
astContext, loc,
12851293
diag::regionbasedisolation_arg_passed_to_strongly_transferred_param,
1286-
op->get()->getType().getASTType())
1294+
diagnosticInfo.getType())
12871295
.highlight(op->getUser()->getLoc().getSourceRange());
12881296
break;
12891297
}

test/Concurrency/transfernonsendable.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,3 +1465,9 @@ final actor FinalActorWithSetter {
14651465
// expected-tns-warning @-1 {{task isolated value of type 'NonSendableKlass' transferred to main actor-isolated context}}
14661466
}
14671467
}
1468+
1469+
func functionArgumentIntoClosure(_ x: @escaping () -> ()) async {
1470+
let _ = { @MainActor in
1471+
let _ = x // expected-tns-warning {{task isolated value of type '() -> ()' transferred to main actor-isolated context}}
1472+
}
1473+
}

test/Concurrency/transfernonsendable_strong_transferring_params.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,9 @@ func testTransferOtherParamClassStructTuple(_ x: transferring Klass, y: KlassWit
346346
x = y.ns2.1.second // expected-warning {{assigning 'y.ns2.1.second' to transferring parameter 'x' may cause a race}}
347347
// expected-note @-1 {{'y.ns2.1.second' is a task isolated value that is assigned into transferring parameter 'x'. Transferred uses of 'x' may race with caller uses of 'y.ns2.1.second'}}
348348
}
349+
350+
func useSugaredTypeNameWhenEmittingTaskIsolationError(_ x: @escaping @MainActor () async -> ()) {
351+
func fakeInit(operation: transferring @escaping () async -> ()) {}
352+
353+
fakeInit(operation: x) // expected-warning {{task isolated value of type '@MainActor () async -> ()' passed as a strongly transferred parameter}}
354+
}

0 commit comments

Comments
 (0)