Skip to content

Commit 187b1ee

Browse files
authored
Merge pull request #82776 from gottesmm/release/6.2-154139237
[6.2] [nonisolated-nonsending] Make the AST not consider nonisolated(nonsending) to be an actor isolation crossing point.
2 parents 6e20651 + 1f9e302 commit 187b1ee

File tree

48 files changed

+1147
-551
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1147
-551
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,12 @@ ERROR(missing_never_call_closure,none,
315315
(Type))
316316

317317
ERROR(missing_return_decl,none,
318-
"missing return in %1 expected to return %0",
319-
(Type, DescriptiveDeclKind))
318+
"missing return in %kindonly1 expected to return %0",
319+
(Type, const AbstractFunctionDecl *))
320320
ERROR(missing_never_call_decl,none,
321-
"%1 with uninhabited return type %0 is missing "
321+
"%kindonly1 with uninhabited return type %0 is missing "
322322
"call to another never-returning function on all paths",
323-
(Type, DescriptiveDeclKind))
323+
(Type, const AbstractFunctionDecl *))
324324

325325
NOTE(missing_return_last_expr_note,none,
326326
"did you mean to return the last expression?", ())
@@ -701,8 +701,9 @@ WARNING(warning_int_to_fp_inexact, none,
701701

702702
// Flow-isolation diagnostics
703703
ERROR(isolated_after_nonisolated, none,
704-
"cannot access %1 %2 here in %select{nonisolated initializer|deinitializer}0",
705-
(bool, DescriptiveDeclKind, DeclName))
704+
"cannot access %kind1 here in "
705+
"%select{nonisolated initializer|deinitializer}0",
706+
(bool, const ValueDecl *))
706707
NOTE(nonisolated_blame, none, "after %1%2 %3, "
707708
"only nonisolated properties of 'self' can be accessed from "
708709
"%select{this init|a deinit}0", (bool, StringRef, StringRef, DeclName))
@@ -982,23 +983,23 @@ GROUPED_ERROR(regionbasedisolation_type_send_yields_race, SendingRisksDataRace,
982983
(Type))
983984
NOTE(regionbasedisolation_type_use_after_send, none,
984985
"sending value of non-Sendable type %0 to %1 callee risks causing data races between %1 and local %2 uses",
985-
(Type, ActorIsolation, ActorIsolation))
986+
(Type, StringRef, StringRef))
986987
NOTE(regionbasedisolation_type_use_after_send_callee, none,
987-
"sending value of non-Sendable type %0 to %1 %2 %3 risks causing data "
988-
"races between %1 and local %4 uses",
989-
(Type, ActorIsolation, DescriptiveDeclKind, DeclName, ActorIsolation))
988+
"sending value of non-Sendable type %0 to %1 %kind2 risks causing data "
989+
"races between %1 and local %3 uses",
990+
(Type, StringRef, const ValueDecl *, StringRef))
990991

991992
NOTE(regionbasedisolation_named_info_send_yields_race, none,
992-
"sending %1%0 to %2 callee risks causing data races between %2 and local %3 uses",
993-
(Identifier, StringRef, ActorIsolation, ActorIsolation))
993+
"sending %select{%2 |}0%1 to %3 callee risks causing data races between %3 and local %4 uses",
994+
(bool, Identifier, StringRef, StringRef, StringRef))
994995
NOTE(regionbasedisolation_named_info_send_yields_race_callee, none,
995-
"sending %1%0 to %2 %3 %4 risks causing data races between %2 and local %5 uses",
996-
(Identifier, StringRef, ActorIsolation, DescriptiveDeclKind, DeclName, ActorIsolation))
996+
"sending %select{%2 |}0%1 to %3 %kind4 risks causing data races between %3 and local %5 uses",
997+
(bool, Identifier, StringRef, StringRef, const ValueDecl *, StringRef))
997998

998999
// Use after send closure.
9991000
NOTE(regionbasedisolation_type_isolated_capture_yields_race, none,
10001001
"sending value of non-Sendable type %0 to %1 closure due to closure capture risks causing races in between %1 and %2 uses",
1001-
(Type, ActorIsolation, ActorIsolation))
1002+
(Type, StringRef, StringRef))
10021003

10031004
// Value captured in async let and reused.
10041005
NOTE(regionbasedisolation_named_nonisolated_asynclet_name, none,
@@ -1009,33 +1010,33 @@ NOTE(regionbasedisolation_named_value_used_after_explicit_sending, none,
10091010
"%0 used after being passed as a 'sending' parameter; Later uses could race",
10101011
(Identifier))
10111012
NOTE(regionbasedisolation_named_isolated_closure_yields_race, none,
1012-
"%0%1 is captured by a %2 closure. %2 uses in closure may race against later %3 uses",
1013-
(StringRef, Identifier, ActorIsolation, ActorIsolation))
1013+
"%select{%1 |}0%2 is captured by a %3 closure. %3 uses in closure may race against later %4 uses",
1014+
(bool, StringRef, Identifier, StringRef, StringRef))
10141015

10151016
NOTE(regionbasedisolation_typed_use_after_sending, none,
10161017
"Passing value of non-Sendable type %0 as a 'sending' argument risks causing races in between local and caller code",
10171018
(Type))
10181019
NOTE(regionbasedisolation_typed_use_after_sending_callee, none,
1019-
"Passing value of non-Sendable type %0 as a 'sending' argument to %1 %2 risks causing races in between local and caller code",
1020-
(Type, DescriptiveDeclKind, DeclName))
1020+
"Passing value of non-Sendable type %0 as a 'sending' argument to %kind1 risks causing races in between local and caller code",
1021+
(Type, const ValueDecl *))
10211022

10221023
//===
10231024
// Sending Never Sendable Emitter
10241025

10251026
NOTE(regionbasedisolation_named_send_never_sendable, none,
1026-
"sending %1%0 to %2 callee risks causing data races between %2 and %3 uses",
1027-
(Identifier, StringRef, ActorIsolation, StringRef))
1027+
"sending %select{%2 |}0%1 to %3 callee risks causing data races between %3 and %4 uses",
1028+
(bool, Identifier, StringRef, StringRef, StringRef))
10281029
NOTE(regionbasedisolation_named_send_never_sendable_callee, none,
1029-
"sending %1%0 to %2 %3 %4 risks causing data races between %2 and %5 uses",
1030-
(Identifier, StringRef, ActorIsolation, DescriptiveDeclKind, DeclName, StringRef))
1030+
"sending %select{%2 |}0%1 to %3 %kind4 risks causing data races between %3 and %5 uses",
1031+
(bool, Identifier, StringRef, StringRef, const ValueDecl *, StringRef))
10311032

10321033
NOTE(regionbasedisolation_named_send_into_sending_param, none,
1033-
"%0%1 is passed as a 'sending' parameter; Uses in callee may race with "
1034-
"later %0uses",
1035-
(StringRef, Identifier))
1034+
"%select{%1 |}0%2 is passed as a 'sending' parameter; Uses in callee may race with "
1035+
"later %1 uses",
1036+
(bool, StringRef, Identifier))
10361037
NOTE(regionbasedisolation_named_nosend_send_into_result, none,
1037-
"%0%1 cannot be a 'sending' result. %2 uses may race with caller uses",
1038-
(StringRef, Identifier, StringRef))
1038+
"%select{%1 |}0%2 cannot be a 'sending' result. %3 uses may race with caller uses",
1039+
(bool, StringRef, Identifier, StringRef))
10391040
NOTE(regionbasedisolation_typed_tns_passed_to_sending, none,
10401041
"Passing %0 value of non-Sendable type %1 as a 'sending' parameter risks "
10411042
"causing races inbetween %0 uses and uses reachable from the callee",
@@ -1051,8 +1052,8 @@ NOTE(regionbasedisolation_typed_tns_passed_to_sending_closure_helper_have_value_
10511052
"closure captures %0 which is accessible to code in the current task",
10521053
(DeclName))
10531054
NOTE(regionbasedisolation_typed_tns_passed_to_sending_closure_helper_have_boxed_value_task_isolated, none,
1054-
"closure captures reference to mutable %1 %0 which is accessible to code in the current task",
1055-
(DeclName, DescriptiveDeclKind))
1055+
"closure captures reference to mutable %kind0 which is accessible to code in the current task",
1056+
(const ValueDecl *))
10561057
NOTE(regionbasedisolation_typed_tns_passed_to_sending_closure_helper_have_value_region, none,
10571058
"closure captures %1 which is accessible to %0 code",
10581059
(StringRef, DeclName))
@@ -1068,18 +1069,18 @@ NOTE(regionbasedisolation_closure_captures_actor, none,
10681069
(DeclName, StringRef))
10691070

10701071
NOTE(regionbasedisolation_typed_tns_passed_to_sending_callee, none,
1071-
"Passing %0 value of non-Sendable type %1 as a 'sending' parameter to %2 %3 risks causing races inbetween %0 uses and uses reachable from %3",
1072-
(StringRef, Type, DescriptiveDeclKind, DeclName))
1072+
"Passing %0 value of non-Sendable type %1 as a 'sending' parameter to %kind2 risks causing races inbetween %0 uses and uses reachable from %2",
1073+
(StringRef, Type, const ValueDecl *))
10731074

10741075
NOTE(regionbasedisolation_named_send_nt_asynclet_capture, none,
10751076
"sending %1 %0 into async let risks causing data races between nonisolated and %1 uses",
10761077
(Identifier, StringRef))
10771078
NOTE(regionbasedisolation_typed_sendneversendable_via_arg, none,
10781079
"sending %0 value of non-Sendable type %1 to %2 callee risks causing races in between %0 and %2 uses",
1079-
(StringRef, Type, ActorIsolation))
1080+
(StringRef, Type, StringRef))
10801081
NOTE(regionbasedisolation_typed_sendneversendable_via_arg_callee, none,
1081-
"sending %0 value of non-Sendable type %1 to %2 %3 %4 risks causing races in between %0 and %2 uses",
1082-
(StringRef, Type, ActorIsolation, DescriptiveDeclKind, DeclName))
1082+
"sending %0 value of non-Sendable type %1 to %2 %kind3 risks causing races in between %0 and %2 uses",
1083+
(StringRef, Type, StringRef, const ValueDecl *))
10831084

10841085
NOTE(regionbasedisolation_isolated_conformance_introduced, none,
10851086
"isolated conformance to %kind0 can be introduced here",
@@ -1097,10 +1098,10 @@ NOTE(regionbasedisolation_inout_sending_must_be_reinitialized, none,
10971098
"'inout sending' parameter must be reinitialized before function exit with a non-actor isolated value",
10981099
())
10991100
ERROR(regionbasedisolation_inout_sending_cannot_be_actor_isolated, none,
1100-
"'inout sending' parameter %0 cannot be %1at end of function",
1101+
"'inout sending' parameter %0 cannot be %1 at end of function",
11011102
(Identifier, StringRef))
11021103
NOTE(regionbasedisolation_inout_sending_cannot_be_actor_isolated_note, none,
1103-
"%1%0 risks causing races in between %1uses and caller uses since caller assumes value is not actor isolated",
1104+
"%1 %0 risks causing races in between %1 uses and caller uses since caller assumes value is not actor isolated",
11041105
(Identifier, StringRef))
11051106

11061107
//===
@@ -1125,10 +1126,10 @@ NOTE(regionbasedisolation_out_sending_cannot_be_actor_isolated_note_named, none,
11251126
// Example: returning main-actor isolated result to a custom-actor isolated context risks causing data races
11261127
ERROR(rbi_isolation_crossing_result, none,
11271128
"non-Sendable %0-typed result can not be returned from %1 %kind2 to %3 context",
1128-
(Type, ActorIsolation, const ValueDecl *, ActorIsolation))
1129+
(Type, StringRef, const ValueDecl *, StringRef))
11291130
ERROR(rbi_isolation_crossing_result_no_decl, none,
11301131
"non-Sendable %0-typed result can not be returned from %1 function to %2 context",
1131-
(Type, ActorIsolation, ActorIsolation))
1132+
(Type, StringRef, StringRef))
11321133
NOTE(rbi_non_sendable_nominal,none,
11331134
"%kind0 does not conform to the 'Sendable' protocol",
11341135
(const ValueDecl *))

include/swift/AST/Identifier.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class Identifier {
230230
private:
231231
bool isOperatorSlow() const;
232232
};
233-
233+
234234
class DeclName;
235235
class DeclNameRef;
236236
class ObjCSelector;

include/swift/SILOptimizer/Analysis/RegionAnalysis.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,16 @@ class regionanalysisimpl::TrackableValueState {
179179

180180
void removeFlag(TrackableValueFlag flag) { flagSet -= flag; }
181181

182-
void print(llvm::raw_ostream &os) const {
182+
void print(SILFunction *fn, llvm::raw_ostream &os) const {
183183
os << "TrackableValueState[id: " << id
184184
<< "][is_no_alias: " << (isNoAlias() ? "yes" : "no")
185185
<< "][is_sendable: " << (isSendable() ? "yes" : "no")
186186
<< "][region_value_kind: ";
187-
getIsolationRegionInfo().printForOneLineLogging(os);
187+
getIsolationRegionInfo().printForOneLineLogging(fn, os);
188188
os << "].";
189189
}
190190

191-
SWIFT_DEBUG_DUMP { print(llvm::dbgs()); }
191+
SWIFT_DEBUG_DUMPER(dump(SILFunction *fn)) { print(fn, llvm::dbgs()); }
192192

193193
private:
194194
bool hasIsolationRegionInfo() const { return bool(regionInfo); }
@@ -249,26 +249,26 @@ class regionanalysisimpl::TrackableValue {
249249
/// parameter.
250250
bool isSendingParameter() const;
251251

252-
void printIsolationInfo(SmallString<64> &outString) const {
252+
void printIsolationInfo(SILFunction *fn, SmallString<64> &outString) const {
253253
llvm::raw_svector_ostream os(outString);
254-
getIsolationRegionInfo().printForDiagnostics(os);
254+
getIsolationRegionInfo().printForDiagnostics(fn, os);
255255
}
256256

257-
void print(llvm::raw_ostream &os) const {
257+
void print(SILFunction *fn, llvm::raw_ostream &os) const {
258258
os << "TrackableValue. State: ";
259-
valueState.print(os);
259+
valueState.print(fn, os);
260260
os << "\n Rep Value: ";
261261
getRepresentative().print(os);
262262
}
263263

264-
void printVerbose(llvm::raw_ostream &os) const {
264+
void printVerbose(SILFunction *fn, llvm::raw_ostream &os) const {
265265
os << "TrackableValue. State: ";
266-
valueState.print(os);
266+
valueState.print(fn, os);
267267
os << "\n Rep Value: " << getRepresentative();
268268
}
269269

270-
SWIFT_DEBUG_DUMP {
271-
print(llvm::dbgs());
270+
SWIFT_DEBUG_DUMPER(dump(SILFunction *fn)) {
271+
print(fn, llvm::dbgs());
272272
llvm::dbgs() << '\n';
273273
}
274274
};
@@ -288,8 +288,8 @@ struct regionanalysisimpl::TrackableValueLookupResult {
288288
/// TrackableValue.
289289
std::optional<TrackableValue> base;
290290

291-
void print(llvm::raw_ostream &os) const;
292-
SWIFT_DEBUG_DUMP { print(llvm::dbgs()); }
291+
void print(SILFunction *fn, llvm::raw_ostream &os) const;
292+
SWIFT_DEBUG_DUMPER(dumper(SILFunction *fn)) { print(fn, llvm::dbgs()); }
293293
};
294294

295295
class RegionAnalysis;
@@ -390,6 +390,8 @@ class RegionAnalysisValueMap {
390390
return getUnderlyingTrackedValue(value).value;
391391
}
392392

393+
SILFunction *getFunction() const { return fn; }
394+
393395
/// Returns the value for this instruction if it isn't a fake "represenative
394396
/// value" to inject actor isolatedness. Asserts in such a case.
395397
SILValue getRepresentative(Element trackableValueID) const;

include/swift/SILOptimizer/Utils/PartitionUtils.h

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,9 +1598,32 @@ struct PartitionOpEvaluator {
15981598
}
15991599

16001600
private:
1601-
bool isConvertFunctionFromSendableType(SILValue equivalenceClassRep) const {
1601+
/// To work around not having isolation in interface types, the type checker
1602+
/// inserts casts and other AST nodes that are used to enrich the AST with
1603+
/// isolation information. This results in Sendable functions being
1604+
/// wrapped/converted/etc in ways that hide the Sendability. This helper looks
1605+
/// through these conversions/wrappers/thunks to see if the original
1606+
/// underlying function is Sendable.
1607+
///
1608+
/// The two ways this can happen is that we either get an actual function_ref
1609+
/// that is Sendable or we get a convert function with a Sendable operand.
1610+
bool isHiddenSendableFunctionType(SILValue equivalenceClassRep) const {
16021611
SILValue valueToTest = equivalenceClassRep;
16031612
while (true) {
1613+
if (auto *pai = dyn_cast<PartialApplyInst>(valueToTest)) {
1614+
if (auto *calleeFunction = pai->getCalleeFunction()) {
1615+
if (pai->getNumArguments() >= 1 &&
1616+
pai->getArgument(0)->getType().isFunction() &&
1617+
calleeFunction->isThunk()) {
1618+
valueToTest = pai->getArgument(0);
1619+
continue;
1620+
}
1621+
1622+
if (calleeFunction->getLoweredFunctionType()->isSendable())
1623+
return true;
1624+
}
1625+
}
1626+
16041627
if (auto *i = dyn_cast<ThinToThickFunctionInst>(valueToTest)) {
16051628
valueToTest = i->getOperand();
16061629
continue;
@@ -1612,6 +1635,9 @@ struct PartitionOpEvaluator {
16121635
break;
16131636
}
16141637

1638+
if (auto *fn = dyn_cast<FunctionRefInst>(valueToTest))
1639+
return fn->getReferencedFunction()->getLoweredFunctionType()->isSendable();
1640+
16151641
auto *cvi = dyn_cast<ConvertFunctionInst>(valueToTest);
16161642
if (!cvi)
16171643
return false;
@@ -1644,7 +1670,7 @@ struct PartitionOpEvaluator {
16441670

16451671
// See if we have a convert function from a `@Sendable` type. In this
16461672
// case, we want to squelch the error.
1647-
if (isConvertFunctionFromSendableType(equivalenceClassRep))
1673+
if (isHiddenSendableFunctionType(equivalenceClassRep))
16481674
return;
16491675
}
16501676

@@ -1689,7 +1715,7 @@ struct PartitionOpEvaluator {
16891715

16901716
// See if we have a convert function from a `@Sendable` type. In this
16911717
// case, we want to squelch the error.
1692-
if (isConvertFunctionFromSendableType(equivalenceClassRep))
1718+
if (isHiddenSendableFunctionType(equivalenceClassRep))
16931719
return;
16941720
}
16951721
}

0 commit comments

Comments
 (0)