Skip to content

[region-isolation] Incremental diagnostic updates #75597

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 11 commits into from
Aug 2, 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
60 changes: 33 additions & 27 deletions include/swift/AST/DiagnosticsSIL.def
Original file line number Diff line number Diff line change
Expand Up @@ -944,39 +944,25 @@ ERROR(regionbasedisolation_unknown_pattern, none,
"pattern that the region based isolation checker does not understand how to check. Please file a bug",
())

//===---
// Old Transfer Non Sendable Diagnostics
//

ERROR(regionbasedisolation_transfer_yields_race_no_isolation, none,
"sending value of non-Sendable type %0 with later accesses risks causing data races",
(Type))
ERROR(regionbasedisolation_transfer_yields_race_with_isolation, none,
"sending value of non-Sendable type %0 with later accesses from %1 context to %2 context risks causing data races",
(Type, ActorIsolation, ActorIsolation))
ERROR(regionbasedisolation_isolated_capture_yields_race, none,
"%1 closure captures value of non-Sendable type %0 from %2 context; later accesses to value could race",
(Type, ActorIsolation, ActorIsolation))
ERROR(regionbasedisolation_transfer_yields_race_stronglytransferred_binding, none,
"value of non-Sendable type %0 accessed after being transferred; later accesses could race",
(Type))
ERROR(regionbasedisolation_arg_transferred, none,
"sending %0 value of type %1 with later accesses to %2 context risks causing data races",
(StringRef, Type, ActorIsolation))
ERROR(regionbasedisolation_arg_passed_to_strongly_transferred_param, none,
"%0 value of type %1 passed as a strongly transferred parameter; later accesses could race",
(StringRef, Type))

//===---
// New Transfer Non Sendable Diagnostics
//

ERROR(regionbasedisolation_named_transfer_yields_race, none,
"sending %0 risks causing data races",
(Identifier))
NOTE(regionbasedisolation_type_is_non_sendable, none,
"%0 is a non-Sendable type",
(Type))
ERROR(regionbasedisolation_type_transfer_yields_race, none,
"sending value of non-Sendable type %0 risks causing data races",
(Type))

NOTE(regionbasedisolation_type_use_after_transfer, 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,
"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_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))

ERROR(regionbasedisolation_inout_sending_cannot_be_actor_isolated, none,
"'inout sending' parameter %0 cannot be %1at end of function",
Expand Down Expand Up @@ -1028,11 +1014,31 @@ NOTE(regionbasedisolation_named_value_used_after_explicit_sending, none,
NOTE(regionbasedisolation_named_isolated_closure_yields_race, none,
"%0%1 is captured by a %2 closure. %2 uses in closure may race against later %3 uses",
(StringRef, Identifier, ActorIsolation, ActorIsolation))
NOTE(regionbasedisolation_typed_tns_passed_to_sending, none,
"Passing %0 value of non-Sendable type %1 as a 'sending' parameter risks causing races inbetween %0 uses and uses reachable from the callee",
(StringRef, Type))
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,
"sending %1 %0 into async let risks causing data races between nonisolated and %1 uses",
(Identifier, StringRef))

NOTE(regionbasedisolation_typed_use_after_sending, none,
"Passing value of non-Sendable type %0 as a 'sending' argument risks causing races in between local and caller code",
(Type))
NOTE(regionbasedisolation_typed_use_after_sending_callee, none,
"Passing value of non-Sendable type %0 as a 'sending' argument to %1 %2 risks causing races in between local and caller code",
(Type, DescriptiveDeclKind, DeclName))

NOTE(regionbasedisolation_typed_transferneversendable_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,
"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))

// Misc Error.
ERROR(regionbasedisolation_task_or_actor_isolated_transferred, none,
"task or actor isolated value cannot be sent", ())
Expand Down
26 changes: 14 additions & 12 deletions include/swift/SILOptimizer/Utils/SILIsolationInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,18 +346,6 @@ class SILIsolationInfo {
Flag::UnappliedIsolatedAnyParameter};
}

/// Only use this as a fallback if we cannot find better information.
static SILIsolationInfo
getWithIsolationCrossing(ApplyIsolationCrossing crossing) {
if (crossing.getCalleeIsolation().isActorIsolated()) {
// SIL level, just let it through
return SILIsolationInfo(SILValue(), SILValue(),
crossing.getCalleeIsolation());
}

return {};
}

static SILIsolationInfo getActorInstanceIsolated(SILValue isolatedValue,
SILValue actorInstance,
NominalTypeDecl *typeDecl) {
Expand Down Expand Up @@ -463,6 +451,20 @@ class SILIsolationInfo {

private:
void printOptions(llvm::raw_ostream &os) const;

/// This is used only to let through apply isolation crossings that we define
/// in SIL just for testing. Do not use this in any other contexts!
static SILIsolationInfo
getWithIsolationCrossing(ApplyIsolationCrossing crossing) {
if (!crossing.getCalleeIsolation().isActorIsolated())
return {};

// SIL level, just let it through without an actor instance. We assume since
// we are using this for SIL tests that we do not need to worry about having
// a null actor instance.
return SILIsolationInfo(SILValue(), SILValue(),
crossing.getCalleeIsolation());
}
};

/// A SILIsolationInfo that has gone through merging and represents the dynamic
Expand Down
Loading