Skip to content

Commit d060f01

Browse files
authored
Merge pull request swiftlang#78837 from gottesmm/rdar-142661388
[rbi] Change Region Based Isolation for closures to not use the AST and instead just use SIL.
2 parents 0558d3f + 05511c9 commit d060f01

File tree

59 files changed

+710
-220
lines changed

Some content is hidden

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

59 files changed

+710
-220
lines changed

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,3 +1736,6 @@ final public class ThunkInst : Instruction {
17361736

17371737
final public class MergeIsolationRegionInst : Instruction {
17381738
}
1739+
1740+
final public class IgnoredUseInst : Instruction, UnaryInstruction {
1741+
}

SwiftCompilerSources/Sources/SIL/Registration.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,5 @@ public func registerSILClasses() {
258258
register(CheckedCastAddrBranchInst.self)
259259
register(ThunkInst.self)
260260
register(MergeIsolationRegionInst.self)
261+
register(IgnoredUseInst.self)
261262
}

docs/SIL/Instructions.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5551,3 +5551,21 @@ sil-instruction ::= 'has_symbol' sil-decl-ref
55515551
Returns true if each of the underlying symbol addresses associated with
55525552
the given declaration are non-null. This can be used to determine
55535553
whether a weakly-imported declaration is available at runtime.
5554+
5555+
## Miscellaneous instructions
5556+
5557+
### ignored_use
5558+
5559+
```none
5560+
sil-instruction ::= 'ignored_use'
5561+
```
5562+
5563+
This instruction acts as a synthetic use instruction that suppresses unused
5564+
variable warnings. In Swift the equivalent operation is '_ = x'. This
5565+
importantly also provides a way to find the source location for '_ = x' when
5566+
emitting SIL diagnostics. It is only legal in Raw SIL and is removed as dead
5567+
code when we convert to Canonical SIL.
5568+
5569+
DISCUSSION: Before the introduction of this instruction, in certain cases,
5570+
SILGen would just not emit anything for '_ = x'... so one could not emit
5571+
diagnostics upon this case.

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/SIL/SILBuilder.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3089,6 +3089,15 @@ class SILBuilder {
30893089
getModule(), getSILDebugLocation(Loc), Decl));
30903090
}
30913091

3092+
//===--------------------------------------------------------------------===//
3093+
// Misc Uses
3094+
//===--------------------------------------------------------------------===//
3095+
3096+
IgnoredUseInst *createIgnoredUse(SILLocation loc, SILValue value) {
3097+
return insert(new (getModule())
3098+
IgnoredUseInst(getSILDebugLocation(loc), value));
3099+
}
3100+
30923101
//===--------------------------------------------------------------------===//
30933102
// Private Helper Methods
30943103
//===--------------------------------------------------------------------===//

include/swift/SIL/SILCloner.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3796,6 +3796,14 @@ void SILCloner<ImplClass>::visitHasSymbolInst(HasSymbolInst *Inst) {
37963796
Inst->getDecl()));
37973797
}
37983798

3799+
template <typename ImplClass>
3800+
void SILCloner<ImplClass>::visitIgnoredUseInst(IgnoredUseInst *Inst) {
3801+
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
3802+
recordClonedInstruction(
3803+
Inst, getBuilder().createIgnoredUse(getOpLocation(Inst->getLoc()),
3804+
getOpValue(Inst->getOperand())));
3805+
}
3806+
37993807
} // end namespace swift
38003808

38013809
#endif

include/swift/SIL/SILInstruction.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11725,6 +11725,17 @@ class MergeIsolationRegionInst final
1172511725
}
1172611726
};
1172711727

11728+
/// An instruction that represents a semantic-less use that is used to
11729+
/// suppresses unused value variable warnings. E.x.: _ = x.
11730+
class IgnoredUseInst final
11731+
: public UnaryInstructionBase<SILInstructionKind::IgnoredUseInst,
11732+
NonValueInstruction> {
11733+
friend SILBuilder;
11734+
11735+
IgnoredUseInst(SILDebugLocation loc, SILValue operand)
11736+
: UnaryInstructionBase(loc, operand) {}
11737+
};
11738+
1172811739
inline SILType *AllocRefInstBase::getTypeStorage() {
1172911740
// If the size of the subclasses are equal, then all of this compiles away.
1173011741
if (auto I = dyn_cast<AllocRefInst>(this))

include/swift/SIL/SILNodes.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,9 @@ NON_VALUE_INST(MarkUnresolvedMoveAddrInst, mark_unresolved_move_addr,
897897
NON_VALUE_INST(MergeIsolationRegionInst, merge_isolation_region,
898898
SILInstruction, None, DoesNotRelease)
899899

900+
NON_VALUE_INST(IgnoredUseInst, ignored_use,
901+
SILInstruction, None, DoesNotRelease)
902+
900903
NON_VALUE_INST(IncrementProfilerCounterInst, increment_profiler_counter,
901904
SILInstruction, MayReadWrite, DoesNotRelease)
902905

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));

0 commit comments

Comments
 (0)