Skip to content

[region-isolation] Cherry-pick to swift 6 #72584

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 45 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d6a8987
[region-isolation] Remove redundant test transfernonsendable_globalac…
gottesmm Mar 16, 2024
f39ce01
[region-isolation] Add a test specifically for ownership.
gottesmm Mar 18, 2024
c909cb9
[region-isolation] Rename callback handleFailure -> handleLocalUseAft…
gottesmm Mar 17, 2024
cd307f9
[ast] Add a helper method ActorIsolation::getActorOrNullPtr().
gottesmm Mar 18, 2024
8b2a16f
[region-isolation] Move ValueIsolationRegionInfo from RegionAnalysis.…
gottesmm Mar 18, 2024
d4400cb
[region-isolation] Define getIsolationRegionInfo(Element elt) on Part…
gottesmm Mar 18, 2024
992c0d9
[region-isolation] Change named transfer non transferable error to us…
gottesmm Mar 18, 2024
b49bbeb
[region-isolation] Rename ValueIsolationRegionInfo -> IsolationRegion…
gottesmm Mar 18, 2024
edeb3f8
Update a test I missed
gottesmm Mar 18, 2024
b4a14a5
Add include <variant> in a place that I missed.
gottesmm Mar 18, 2024
efd48cf
[region-isolation] Remove variable_defined_here from named use after …
gottesmm Mar 19, 2024
782340c
[region-isolation] Teach variable_name_inference how to infer through…
gottesmm Mar 19, 2024
9ea61cc
[region-isolation] Teach variable name utils how to handle more tuple…
gottesmm Mar 19, 2024
a51678f
[cmake] Prevent linker errors by linking libswiftAST into SwiftBasicT…
gottesmm Mar 21, 2024
b1ba9b5
[region-isolation] Convert TransferringOperand to be a bump allocated…
gottesmm Mar 19, 2024
3972f96
[ast] Implement ActorIsolation::Profile(...).
gottesmm Mar 20, 2024
93238e7
[ast] Improve the debug dump for ActorIsolation.
gottesmm Mar 20, 2024
242cabb
[region-isolation] Move IsolationRegionInfo higher up in PartitionUti…
gottesmm Mar 20, 2024
de7a82d
[region-isolation] Define an == on IsolationRegionInfo.
gottesmm Mar 20, 2024
0309c44
[region-isolation] Add ability to Profile an IsolationRegionInfo.
gottesmm Mar 20, 2024
6b2ecfd
[region-isolation] Refactor RegionAnalysis AST pattern matching onto …
gottesmm Mar 20, 2024
e1d5604
[region-isolation] Refactor out dynamic getIsolationRegionInfo for an…
gottesmm Mar 20, 2024
54b4efb
[region-isolation] Rename IsolationRegionInfo -> SILIsolationInfo.
gottesmm Mar 20, 2024
8c98af9
[region-isolation] Add a helper for getting an ApplyIsolationCrossing…
gottesmm Mar 20, 2024
9d9316e
[region-isolation] Remove an assert that doesnt add anything.
gottesmm Mar 20, 2024
43003a9
[region-isolation] Move computation of SILIsolationInfo for a SILFunc…
gottesmm Mar 20, 2024
0beac1c
[region-isolation] Use SILRegionInfo::get to compute actor isolation …
gottesmm Mar 20, 2024
9e74a56
Fix unittest
gottesmm Mar 21, 2024
5ca0f27
Revert "[cmake] Prevent linker errors by linking libswiftAST into Swi…
gottesmm Mar 21, 2024
80208d6
Instead of linking libswiftAST into SwiftBasicTests, define ActorIsol…
gottesmm Mar 21, 2024
4a1686e
[region-isolation] Clean up use after transfer error to use the dynam…
gottesmm Mar 21, 2024
2fc1aff
[region-isolation] Wordsmith "{access,use} here could race".
gottesmm Mar 24, 2024
9c9d818
[transferring] Implement swift_attr support for transferring results …
gottesmm Mar 22, 2024
203a013
[region-isolation] Add a named variant of the use after pass via stro…
gottesmm Mar 24, 2024
b71970b
[region-isolation] Add a named variant of the transfer via closure ca…
gottesmm Mar 24, 2024
8b7a173
[region-isolation] Convert the isolation having autoclosure expr erro…
gottesmm Mar 24, 2024
6f4e337
Update a test I missed
gottesmm Mar 24, 2024
345b65a
[region-isolation] Shrink PartitionUtils.h by moving large functions …
gottesmm Mar 24, 2024
3e47fe2
[region-isolation] Change printing of values before dataflow to dump …
gottesmm Mar 25, 2024
dce9ccf
[region-isolation] Change a test to use the name "CustomActor" instea…
gottesmm Mar 25, 2024
3ea42ff
[region-isolation] When emitting an error for an isolated closure use…
gottesmm Mar 25, 2024
c90e2e5
[region-isolation] Change the transfer non-transferrable value due to…
gottesmm Mar 25, 2024
fa2cc90
[region-isolation] If a value is dynamically actor isolated, do not c…
gottesmm Mar 25, 2024
cbf57c9
[region-isolation] Squelch use after transfer if the use has effectiv…
gottesmm Mar 26, 2024
dacc4b0
[region-isolation] Do not squelch errors in the unittests.
gottesmm Mar 26, 2024
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
25 changes: 21 additions & 4 deletions include/swift/AST/ActorIsolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class ActorIsolation {
}

NominalTypeDecl *getActor() const;
NominalTypeDecl *getActorOrNullPtr() const;

VarDecl *getActorInstance() const;

Expand Down Expand Up @@ -244,10 +245,18 @@ class ActorIsolation {
return !(lhs == rhs);
}

void Profile(llvm::FoldingSetNodeID &id) {
id.AddInteger(getKind());
id.AddPointer(pointer);
id.AddBoolean(isolatedByPreconcurrency);
id.AddBoolean(silParsed);
id.AddInteger(parameterIndex);
}

friend llvm::hash_code hash_value(const ActorIsolation &state) {
return llvm::hash_combine(
state.kind, state.pointer, state.isolatedByPreconcurrency,
state.parameterIndex);
return llvm::hash_combine(state.kind, state.pointer,
state.isolatedByPreconcurrency, state.silParsed,
state.parameterIndex);
}

void print(llvm::raw_ostream &os) const {
Expand Down Expand Up @@ -277,7 +286,15 @@ class ActorIsolation {
void printForDiagnostics(llvm::raw_ostream &os,
StringRef openingQuotationMark = "'") const;

SWIFT_DEBUG_DUMP { print(llvm::dbgs()); }
SWIFT_DEBUG_DUMP {
print(llvm::dbgs());
llvm::dbgs() << '\n';
}

// Defined out of line to prevent linker errors since libswiftBasic would
// include this header exascerbating a layering violation where libswiftBasic
// depends on libswiftAST.
SWIFT_DEBUG_DUMPER(dumpForDiagnostics());
};

/// Determine how the given value declaration is isolated.
Expand Down
16 changes: 11 additions & 5 deletions include/swift/AST/DiagnosticsSIL.def
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ NOTE(sil_referencebinding_inout_binding_here, none,
//===----------------------------------------------------------------------===//

NOTE(regionbasedisolation_maybe_race, none,
"access here could race", ())
"use here could race", ())
ERROR(regionbasedisolation_unknown_pattern, none,
"pattern that the region based isolation checker does not understand how to check. Please file a bug",
())
Expand All @@ -949,7 +949,7 @@ 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,
"binding of non-Sendable type %0 accessed after being transferred; later accesses could race",
"value of non-Sendable type %0 accessed after being transferred; later accesses could race",
(Type))
ERROR(regionbasedisolation_arg_transferred, none,
"%0 value of type %1 transferred to %2 context; later accesses to value could race",
Expand All @@ -970,17 +970,23 @@ ERROR(regionbasedisolation_named_transfer_yields_race, none,
(Identifier))

NOTE(regionbasedisolation_named_info_transfer_yields_race, none,
"%0 is transferred from %1 caller to %2 callee. Later uses in caller could race with potential uses in callee",
(Identifier, ActorIsolation, ActorIsolation))
"transferring %1 %0 to %2 callee could cause races in between callee %2 and local %3 uses",
(Identifier, StringRef, ActorIsolation, ActorIsolation))
NOTE(regionbasedisolation_named_transfer_non_transferrable, none,
"transferring %1 %0 to %2 callee could cause races between %2 and %1 uses",
(Identifier, ActorIsolation, ActorIsolation))
(Identifier, StringRef, ActorIsolation))
NOTE(regionbasedisolation_named_transfer_into_transferring_param, none,
"%0 %1 is passed as a transferring parameter; Uses in callee may race with later %0 uses",
(StringRef, Identifier))
NOTE(regionbasedisolation_named_notransfer_transfer_into_result, none,
"%0 %1 cannot be a transferring result. %0 uses may race with caller uses",
(StringRef, Identifier))
NOTE(regionbasedisolation_named_stronglytransferred_binding, none,
"%0 used after being passed as a transferring parameter; Later uses could race",
(Identifier))
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))

// Misc Error.
ERROR(regionbasedisolation_task_or_actor_isolated_transferred, none,
Expand Down
49 changes: 49 additions & 0 deletions include/swift/Basic/ImmutablePointerSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,55 @@ class ImmutablePointerSetFactory {
return NewNode;
}

template <typename U, typename... Args>
struct IsTrivialTypedPointerAndHasProfile {
constexpr static bool hasProfile =
std::is_same_v<decltype(std::remove_pointer<U>::type::Profile(
std::declval<Args>()...)),
void>;
constexpr static bool value =
hasProfile && std::is_trivial_v<U> && std::is_pointer_v<U>;
};

/// Emplace a new value with \p args if we do not yet have one. We allocate
/// the object with our bump ptr allocator, so we require that the type be
/// trivial.
template <typename... Args>
typename std::enable_if_t<IsTrivialTypedPointerAndHasProfile<
T, llvm::FoldingSetNodeID &, Args...>::value,
PtrSet> *
emplace(Args... args) {
llvm::FoldingSetNodeID ID;
using NoPointerTy = typename std::remove_pointer<T>::type;
NoPointerTy::Profile(ID, std::forward<Args>(args)...);

void *InsertPt;
if (auto *PSet = Set.FindNodeOrInsertPos(ID, InsertPt)) {
return PSet;
}

size_t NumElts = 1;
size_t MemSize = sizeof(PtrSet) + sizeof(NoPointerTy);

// Allocate the memory.
auto *Mem =
reinterpret_cast<PtrSet *>(Allocator.Allocate(MemSize, AllocAlignment));

// Copy in the pointers into the tail allocated memory. We do not need to do
// any sorting/uniquing ourselves since we assume that our users perform
// this task for us.
llvm::MutableArrayRef<NoPointerTy *> DataMem(
reinterpret_cast<NoPointerTy **>(&Mem[1]), NumElts);
NoPointerTy *type =
new (Allocator) NoPointerTy(std::forward<Args>(args)...);
DataMem[0] = type;

// Allocate the new node and insert it into the Set.
auto *NewNode = new (Mem) PtrSet(this, DataMem);
Set.InsertNode(NewNode, InsertPt);
return NewNode;
}

PtrSet *get(T value) {
llvm::FoldingSetNodeID ID;
ID.AddPointer(PtrTraits::getAsVoidPointer(value));
Expand Down
11 changes: 11 additions & 0 deletions include/swift/SIL/SILFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ class SILFunction
/// block indices.
unsigned BlockListChangeIdx = 0;

/// The isolation of this function.
std::optional<ActorIsolation> actorIsolation;

/// The function's bare attribute. Bare means that the function is SIL-only
/// and does not require debug info.
unsigned Bare : 1;
Expand Down Expand Up @@ -1367,6 +1370,14 @@ class SILFunction
return false;
}

void setActorIsolation(ActorIsolation newActorIsolation) {
actorIsolation = newActorIsolation;
}

std::optional<ActorIsolation> getActorIsolation() const {
return actorIsolation;
}

//===--------------------------------------------------------------------===//
// Block List Access
//===--------------------------------------------------------------------===//
Expand Down
Loading