Skip to content

[region-isolation] Excise 'transfer' in favor of 'sending' #77370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions include/swift/AST/DiagnosticsSIL.def
Original file line number Diff line number Diff line change
Expand Up @@ -963,28 +963,28 @@ NOTE(regionbasedisolation_type_is_non_sendable, none,
//===
// Use After Send Emitter

ERROR(regionbasedisolation_named_transfer_yields_race, none,
ERROR(regionbasedisolation_named_send_yields_race, none,
"sending %0 risks causing data races",
(Identifier))
ERROR(regionbasedisolation_type_transfer_yields_race, none,
ERROR(regionbasedisolation_type_send_yields_race, none,
"sending value of non-Sendable type %0 risks causing data races",
(Type))
NOTE(regionbasedisolation_type_use_after_transfer, none,
NOTE(regionbasedisolation_type_use_after_send, none,
"sending value of non-Sendable type %0 to %1 callee risks causing data races between %1 and local %2 uses",
(Type, ActorIsolation, ActorIsolation))
NOTE(regionbasedisolation_type_use_after_transfer_callee, none,
NOTE(regionbasedisolation_type_use_after_send_callee, none,
"sending value of non-Sendable type %0 to %1 %2 %3 risks causing data "
"races between %1 and local %4 uses",
(Type, ActorIsolation, DescriptiveDeclKind, DeclName, ActorIsolation))

NOTE(regionbasedisolation_named_info_transfer_yields_race, none,
NOTE(regionbasedisolation_named_info_send_yields_race, none,
"sending %1%0 to %2 callee risks causing data races between %2 and local %3 uses",
(Identifier, StringRef, ActorIsolation, ActorIsolation))
NOTE(regionbasedisolation_named_info_transfer_yields_race_callee, none,
NOTE(regionbasedisolation_named_info_send_yields_race_callee, none,
"sending %1%0 to %2 %3 %4 risks causing data races between %2 and local %5 uses",
(Identifier, StringRef, ActorIsolation, DescriptiveDeclKind, DeclName, ActorIsolation))

// Use after transfer closure.
// Use after send closure.
NOTE(regionbasedisolation_type_isolated_capture_yields_race, none,
"sending value of non-Sendable type %0 to %1 closure due to closure capture risks causing races in between %1 and %2 uses",
(Type, ActorIsolation, ActorIsolation))
Expand All @@ -1011,18 +1011,18 @@ NOTE(regionbasedisolation_typed_use_after_sending_callee, none,
//===
// Sending Never Sendable Emitter

NOTE(regionbasedisolation_named_transfer_non_transferrable, none,
NOTE(regionbasedisolation_named_send_never_sendable, none,
"sending %1%0 to %2 callee risks causing data races between %2 and %3 uses",
(Identifier, StringRef, ActorIsolation, StringRef))
NOTE(regionbasedisolation_named_transfer_non_transferrable_callee, none,
NOTE(regionbasedisolation_named_send_never_sendable_callee, none,
"sending %1%0 to %2 %3 %4 risks causing data races between %2 and %5 uses",
(Identifier, StringRef, ActorIsolation, DescriptiveDeclKind, DeclName, StringRef))

NOTE(regionbasedisolation_named_transfer_into_sending_param, none,
NOTE(regionbasedisolation_named_send_into_sending_param, none,
"%0%1 is passed as a 'sending' parameter; Uses in callee may race with "
"later %0uses",
(StringRef, Identifier))
NOTE(regionbasedisolation_named_notransfer_transfer_into_result, none,
NOTE(regionbasedisolation_named_nosend_send_into_result, none,
"%0%1 cannot be a 'sending' result. %2 uses may race with caller uses",
(StringRef, Identifier, StringRef))
NOTE(regionbasedisolation_typed_tns_passed_to_sending, none,
Expand Down Expand Up @@ -1054,19 +1054,19 @@ NOTE(regionbasedisolation_typed_tns_passed_to_sending_callee, none,
"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",
(StringRef, Type, DescriptiveDeclKind, DeclName))

NOTE(regionbasedisolation_named_transfer_nt_asynclet_capture, none,
NOTE(regionbasedisolation_named_send_nt_asynclet_capture, none,
"sending %1 %0 into async let risks causing data races between nonisolated and %1 uses",
(Identifier, StringRef))
NOTE(regionbasedisolation_typed_transferneversendable_via_arg, none,
NOTE(regionbasedisolation_typed_sendneversendable_via_arg, none,
"sending %0 value of non-Sendable type %1 to %2 callee risks causing races in between %0 and %2 uses",
(StringRef, Type, ActorIsolation))
NOTE(regionbasedisolation_typed_transferneversendable_via_arg_callee, none,
NOTE(regionbasedisolation_typed_sendneversendable_via_arg_callee, none,
"sending %0 value of non-Sendable type %1 to %2 %3 %4 risks causing races in between %0 and %2 uses",
(StringRef, Type, ActorIsolation, DescriptiveDeclKind, DeclName))

// Error that is only used when the send non sendable emitter cannot discover any
// information to give a better diagnostic.
ERROR(regionbasedisolation_task_or_actor_isolated_transferred, none,
ERROR(regionbasedisolation_task_or_actor_isolated_sent, none,
"task or actor isolated value cannot be sent", ())

//===
Expand Down
23 changes: 11 additions & 12 deletions include/swift/SILOptimizer/Analysis/RegionAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static inline bool shouldAbortOnUnknownPatternMatchError() {
return AbortOnUnknownPatternMatchError;
}

using TransferringOperandSetFactory = Partition::TransferringOperandSetFactory;
using SendingOperandSetFactory = Partition::SendingOperandSetFactory;
using Element = PartitionPrimitives::Element;
using Region = PartitionPrimitives::Region;

Expand Down Expand Up @@ -74,15 +74,15 @@ class BlockPartitionState {
/// block.
std::vector<PartitionOp> blockPartitionOps = {};

TransferringOperandSetFactory &ptrSetFactory;
SendingOperandSetFactory &ptrSetFactory;

TransferringOperandToStateMap &transferringOpToStateMap;
SendingOperandToStateMap &sendingOpToStateMap;

BlockPartitionState(SILBasicBlock *basicBlock,
PartitionOpTranslator &translator,
TransferringOperandSetFactory &ptrSetFactory,
SendingOperandSetFactory &ptrSetFactory,
IsolationHistory::Factory &isolationHistoryFactory,
TransferringOperandToStateMap &transferringOpToStateMap);
SendingOperandToStateMap &sendingOpToStateMap);

public:
bool getLiveness() const { return isLive; }
Expand Down Expand Up @@ -359,8 +359,7 @@ class RegionAnalysisValueMap {
class RegionAnalysisFunctionInfo {
using BlockPartitionState = regionanalysisimpl::BlockPartitionState;
using PartitionOpTranslator = regionanalysisimpl::PartitionOpTranslator;
using TransferringOperandSetFactory =
regionanalysisimpl::TransferringOperandSetFactory;
using SendingOperandSetFactory = regionanalysisimpl::SendingOperandSetFactory;
using BasicBlockData = BasicBlockData<BlockPartitionState>;

llvm::BumpPtrAllocator allocator;
Expand All @@ -373,11 +372,11 @@ class RegionAnalysisFunctionInfo {
// allocator when we allocate everything.
PartitionOpTranslator *translator;

TransferringOperandSetFactory ptrSetFactory;
SendingOperandSetFactory ptrSetFactory;

IsolationHistory::Factory isolationHistoryFactory;

TransferringOperandToStateMap transferringOpToStateMap;
SendingOperandToStateMap sendingOperandToStateMap;

// We make this optional to prevent an issue that we have seen on windows when
// capturing a field in a closure that is used to initialize a different
Expand Down Expand Up @@ -464,7 +463,7 @@ class RegionAnalysisFunctionInfo {
reverse_range getReverseRange() { return {rbegin(), rend()}; }
const_reverse_range getReverseRange() const { return {rbegin(), rend()}; }

TransferringOperandSetFactory &getOperandSetFactory() {
SendingOperandSetFactory &getOperandSetFactory() {
assert(supportedFunction && "Unsupported Function?!");
return ptrSetFactory;
}
Expand All @@ -479,9 +478,9 @@ class RegionAnalysisFunctionInfo {
return isolationHistoryFactory;
}

TransferringOperandToStateMap &getTransferringOpToStateMap() {
SendingOperandToStateMap &getSendingOperandToStateMap() {
assert(supportedFunction && "Unsupported Function?!");
return transferringOpToStateMap;
return sendingOperandToStateMap;
}

bool isClosureCaptured(SILValue value, Operand *op);
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SILOptimizer/PassManager/Passes.def
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ PASS(TempRValueOpt, "temp-rvalue-opt",
"Remove short-lived immutable temporary copies")
PASS(IRGenPrepare, "irgen-prepare",
"Cleanup SIL in preparation for IRGen")
PASS(TransferNonSendable, "transfer-non-sendable",
PASS(SendNonSendable, "send-non-sendable",
"Checks calls that send non-sendable values between isolation domains")
PASS(LowerTupleAddrConstructor, "lower-tuple-addr-constructor",
"Lower tuple addr constructor to tuple_element_addr+copy_addr")
Expand Down
5 changes: 2 additions & 3 deletions include/swift/SILOptimizer/Utils/PartitionOpError.def
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@
///
/// 2. The element in the PartitionOp that was asked to be alive.
///
/// 3. The operand of the instruction that originally transferred the
/// region. Can be used to get the immediate value transferred or the
/// transferring instruction.
/// 3. The operand of the instruction that originally sent the region. Can be
/// used to get the immediate value sent or the sending instruction.
PARTITION_OP_ERROR(LocalUseAfterSend)

/// This is called if we detect a never sendable element that was actually sent.
Expand Down
Loading