Skip to content

Commit c8270d0

Browse files
authored
Merge pull request #72584 from gottesmm/release/6.0-region-iso
[region-isolation] Cherry-pick to swift 6
2 parents 3823350 + dacc4b0 commit c8270d0

File tree

41 files changed

+2908
-1793
lines changed

Some content is hidden

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

41 files changed

+2908
-1793
lines changed

include/swift/AST/ActorIsolation.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ class ActorIsolation {
192192
}
193193

194194
NominalTypeDecl *getActor() const;
195+
NominalTypeDecl *getActorOrNullPtr() const;
195196

196197
VarDecl *getActorInstance() const;
197198

@@ -244,10 +245,18 @@ class ActorIsolation {
244245
return !(lhs == rhs);
245246
}
246247

248+
void Profile(llvm::FoldingSetNodeID &id) {
249+
id.AddInteger(getKind());
250+
id.AddPointer(pointer);
251+
id.AddBoolean(isolatedByPreconcurrency);
252+
id.AddBoolean(silParsed);
253+
id.AddInteger(parameterIndex);
254+
}
255+
247256
friend llvm::hash_code hash_value(const ActorIsolation &state) {
248-
return llvm::hash_combine(
249-
state.kind, state.pointer, state.isolatedByPreconcurrency,
250-
state.parameterIndex);
257+
return llvm::hash_combine(state.kind, state.pointer,
258+
state.isolatedByPreconcurrency, state.silParsed,
259+
state.parameterIndex);
251260
}
252261

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

280-
SWIFT_DEBUG_DUMP { print(llvm::dbgs()); }
289+
SWIFT_DEBUG_DUMP {
290+
print(llvm::dbgs());
291+
llvm::dbgs() << '\n';
292+
}
293+
294+
// Defined out of line to prevent linker errors since libswiftBasic would
295+
// include this header exascerbating a layering violation where libswiftBasic
296+
// depends on libswiftAST.
297+
SWIFT_DEBUG_DUMPER(dumpForDiagnostics());
281298
};
282299

283300
/// Determine how the given value declaration is isolated.

include/swift/AST/DiagnosticsSIL.def

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ NOTE(sil_referencebinding_inout_binding_here, none,
932932
//===----------------------------------------------------------------------===//
933933

934934
NOTE(regionbasedisolation_maybe_race, none,
935-
"access here could race", ())
935+
"use here could race", ())
936936
ERROR(regionbasedisolation_unknown_pattern, none,
937937
"pattern that the region based isolation checker does not understand how to check. Please file a bug",
938938
())
@@ -951,7 +951,7 @@ ERROR(regionbasedisolation_isolated_capture_yields_race, none,
951951
"%1 closure captures value of non-Sendable type %0 from %2 context; later accesses to value could race",
952952
(Type, ActorIsolation, ActorIsolation))
953953
ERROR(regionbasedisolation_transfer_yields_race_stronglytransferred_binding, none,
954-
"binding of non-Sendable type %0 accessed after being transferred; later accesses could race",
954+
"value of non-Sendable type %0 accessed after being transferred; later accesses could race",
955955
(Type))
956956
ERROR(regionbasedisolation_arg_transferred, none,
957957
"%0 value of type %1 transferred to %2 context; later accesses to value could race",
@@ -972,17 +972,23 @@ ERROR(regionbasedisolation_named_transfer_yields_race, none,
972972
(Identifier))
973973

974974
NOTE(regionbasedisolation_named_info_transfer_yields_race, none,
975-
"%0 is transferred from %1 caller to %2 callee. Later uses in caller could race with potential uses in callee",
976-
(Identifier, ActorIsolation, ActorIsolation))
975+
"transferring %1 %0 to %2 callee could cause races in between callee %2 and local %3 uses",
976+
(Identifier, StringRef, ActorIsolation, ActorIsolation))
977977
NOTE(regionbasedisolation_named_transfer_non_transferrable, none,
978978
"transferring %1 %0 to %2 callee could cause races between %2 and %1 uses",
979-
(Identifier, ActorIsolation, ActorIsolation))
979+
(Identifier, StringRef, ActorIsolation))
980980
NOTE(regionbasedisolation_named_transfer_into_transferring_param, none,
981981
"%0 %1 is passed as a transferring parameter; Uses in callee may race with later %0 uses",
982982
(StringRef, Identifier))
983983
NOTE(regionbasedisolation_named_notransfer_transfer_into_result, none,
984984
"%0 %1 cannot be a transferring result. %0 uses may race with caller uses",
985985
(StringRef, Identifier))
986+
NOTE(regionbasedisolation_named_stronglytransferred_binding, none,
987+
"%0 used after being passed as a transferring parameter; Later uses could race",
988+
(Identifier))
989+
NOTE(regionbasedisolation_named_isolated_closure_yields_race, none,
990+
"%0 %1 is captured by a %2 closure. %2 uses in closure may race against later %3 uses",
991+
(StringRef, Identifier, ActorIsolation, ActorIsolation))
986992

987993
// Misc Error.
988994
ERROR(regionbasedisolation_task_or_actor_isolated_transferred, none,

include/swift/Basic/ImmutablePointerSet.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,55 @@ class ImmutablePointerSetFactory {
250250
return NewNode;
251251
}
252252

253+
template <typename U, typename... Args>
254+
struct IsTrivialTypedPointerAndHasProfile {
255+
constexpr static bool hasProfile =
256+
std::is_same_v<decltype(std::remove_pointer<U>::type::Profile(
257+
std::declval<Args>()...)),
258+
void>;
259+
constexpr static bool value =
260+
hasProfile && std::is_trivial_v<U> && std::is_pointer_v<U>;
261+
};
262+
263+
/// Emplace a new value with \p args if we do not yet have one. We allocate
264+
/// the object with our bump ptr allocator, so we require that the type be
265+
/// trivial.
266+
template <typename... Args>
267+
typename std::enable_if_t<IsTrivialTypedPointerAndHasProfile<
268+
T, llvm::FoldingSetNodeID &, Args...>::value,
269+
PtrSet> *
270+
emplace(Args... args) {
271+
llvm::FoldingSetNodeID ID;
272+
using NoPointerTy = typename std::remove_pointer<T>::type;
273+
NoPointerTy::Profile(ID, std::forward<Args>(args)...);
274+
275+
void *InsertPt;
276+
if (auto *PSet = Set.FindNodeOrInsertPos(ID, InsertPt)) {
277+
return PSet;
278+
}
279+
280+
size_t NumElts = 1;
281+
size_t MemSize = sizeof(PtrSet) + sizeof(NoPointerTy);
282+
283+
// Allocate the memory.
284+
auto *Mem =
285+
reinterpret_cast<PtrSet *>(Allocator.Allocate(MemSize, AllocAlignment));
286+
287+
// Copy in the pointers into the tail allocated memory. We do not need to do
288+
// any sorting/uniquing ourselves since we assume that our users perform
289+
// this task for us.
290+
llvm::MutableArrayRef<NoPointerTy *> DataMem(
291+
reinterpret_cast<NoPointerTy **>(&Mem[1]), NumElts);
292+
NoPointerTy *type =
293+
new (Allocator) NoPointerTy(std::forward<Args>(args)...);
294+
DataMem[0] = type;
295+
296+
// Allocate the new node and insert it into the Set.
297+
auto *NewNode = new (Mem) PtrSet(this, DataMem);
298+
Set.InsertNode(NewNode, InsertPt);
299+
return NewNode;
300+
}
301+
253302
PtrSet *get(T value) {
254303
llvm::FoldingSetNodeID ID;
255304
ID.AddPointer(PtrTraits::getAsVoidPointer(value));

include/swift/SIL/SILFunction.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ class SILFunction
347347
/// block indices.
348348
unsigned BlockListChangeIdx = 0;
349349

350+
/// The isolation of this function.
351+
std::optional<ActorIsolation> actorIsolation;
352+
350353
/// The function's bare attribute. Bare means that the function is SIL-only
351354
/// and does not require debug info.
352355
unsigned Bare : 1;
@@ -1367,6 +1370,14 @@ class SILFunction
13671370
return false;
13681371
}
13691372

1373+
void setActorIsolation(ActorIsolation newActorIsolation) {
1374+
actorIsolation = newActorIsolation;
1375+
}
1376+
1377+
std::optional<ActorIsolation> getActorIsolation() const {
1378+
return actorIsolation;
1379+
}
1380+
13701381
//===--------------------------------------------------------------------===//
13711382
// Block List Access
13721383
//===--------------------------------------------------------------------===//

0 commit comments

Comments
 (0)