Skip to content

Commit 082b824

Browse files
committed
[rbi] Change Region Based Isolation for closures to not use the AST and instead just use SIL.
The reason why I am doing this is that in certain cases the AST captures indices will never actually line up with partial apply capture indices since we seem to "smush" together closures and locally defined functions. NOTE: The reason for the really small amount of test changes is that this change does not change the actual output by design. The only cases I had to change were a case where we began to emit a better diagnostic and also where I added code coverage around _ and let _ since those require ignored_use to be implemented so that they would be diagnosed (previously we just did not emit anything so we couldn't emit the diagnostic at the SIL level). rdar://142661388
1 parent 6058b1d commit 082b824

10 files changed

+428
-152
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,12 @@ NOTE(regionbasedisolation_typed_tns_passed_to_sending_closure_helper_have_value_
10561056
NOTE(regionbasedisolation_typed_tns_passed_to_sending_closure_helper_multiple_value, none,
10571057
"closure captures non-Sendable %0",
10581058
(DeclName))
1059+
NOTE(regionbasedisolation_closure_captures, none,
1060+
"closure captures %0",
1061+
(DeclName))
1062+
NOTE(regionbasedisolation_closure_captures_actor, none,
1063+
"closure captures %0 allowing access to %1 state within the closure",
1064+
(DeclName, StringRef))
10591065

10601066
NOTE(regionbasedisolation_typed_tns_passed_to_sending_callee, none,
10611067
"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",

include/swift/SIL/InstructionUtils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ bool isEndOfScopeMarker(SILInstruction *user);
129129
/// only used in recognizable patterns without otherwise "escaping".
130130
bool isIncidentalUse(SILInstruction *user);
131131

132+
/// Returns true if this is a move only wrapper use.
133+
///
134+
/// E.x.: moveonlywrapper_to_copyable_addr, copyable_to_moveonlywrapper_value
135+
bool isMoveOnlyWrapperUse(SILInstruction *user);
136+
132137
/// Return true if the given `user` instruction modifies the value's refcount
133138
/// without propagating the value or having any other effect aside from
134139
/// potentially destroying the value itself (and executing associated cleanups).

include/swift/SILOptimizer/Utils/PartitionUtils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,12 @@ struct PartitionOpEvaluator {
13741374
Region sentRegion = p.getRegion(sentElement);
13751375
bool isClosureCapturedElt = false;
13761376
SILDynamicMergedIsolationInfo sentRegionIsolation;
1377+
1378+
// TODO: Today we only return the first element in our region that has
1379+
// some form of isolation. This causes us to in the case of sending
1380+
// partial_applies to only emit a diagnostic for the first element in the
1381+
// capture list of the partial_apply. If we returned a list of potential
1382+
// errors... we could emit the error for each capture individually.
13771383
auto pairOpt = getIsolationRegionInfo(sentRegion, op.getSourceOp());
13781384
if (!pairOpt) {
13791385
return handleError(UnknownCodePatternError(op));

lib/SIL/Utils/InstructionUtils.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,19 @@ bool swift::isIncidentalUse(SILInstruction *user) {
339339
isa<IgnoredUseInst>(user);
340340
}
341341

342+
bool swift::isMoveOnlyWrapperUse(SILInstruction *user) {
343+
switch (user->getKind()) {
344+
case SILInstructionKind::MoveOnlyWrapperToCopyableValueInst:
345+
case SILInstructionKind::MoveOnlyWrapperToCopyableBoxInst:
346+
case SILInstructionKind::MoveOnlyWrapperToCopyableAddrInst:
347+
case SILInstructionKind::CopyableToMoveOnlyWrapperValueInst:
348+
case SILInstructionKind::CopyableToMoveOnlyWrapperAddrInst:
349+
return true;
350+
default:
351+
return false;
352+
}
353+
}
354+
342355
bool swift::onlyAffectsRefCount(SILInstruction *user) {
343356
switch (user->getKind()) {
344357
default:

0 commit comments

Comments
 (0)