Skip to content

Commit abfa475

Browse files
authored
Merge pull request #73483 from gottesmm/release/6.0-more-fixes
[6.0][region-isolation] Upstreaming some fixes
2 parents 3037564 + 2b1c380 commit abfa475

Some content is hidden

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

42 files changed

+1294
-319
lines changed

docs/SIL.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,18 @@ autorelease in the callee.
692692
type behaves like a non-generic type, as if the substitutions were
693693
actually applied to the underlying function type.
694694

695+
- SIL functions may optionally mark a function parameter as
696+
``@sil_isolated``. An ``@sil_isolated`` parameter must be one of:
697+
698+
- An actor or any actor type.
699+
- A generic type that conforms to Actor or AnyActor.
700+
701+
and must be the actor instance that a function is isolated to. Importantly
702+
this means that global actor isolated nominal types are never
703+
``@sil_isolated``. Only one parameter can ever be marked as ``@sil_isolated``
704+
since a function cannot be isolated to multiple actors at the same time.
705+
706+
695707
Async Functions
696708
```````````````
697709

include/swift/AST/ActorIsolation.h

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ class ActorIsolation {
205205
return getKind() == GlobalActor;
206206
}
207207

208+
bool isActorInstanceIsolated() const { return getKind() == ActorInstance; }
209+
208210
bool isMainActor() const;
209211

210212
bool isDistributedActor() const;
@@ -262,37 +264,14 @@ class ActorIsolation {
262264
state.parameterIndex);
263265
}
264266

265-
void print(llvm::raw_ostream &os) const {
266-
switch (getKind()) {
267-
case Unspecified:
268-
os << "unspecified";
269-
return;
270-
case ActorInstance:
271-
os << "actor_instance";
272-
return;
273-
case Nonisolated:
274-
os << "nonisolated";
275-
return;
276-
case NonisolatedUnsafe:
277-
os << "nonisolated_unsafe";
278-
return;
279-
case GlobalActor:
280-
os << "global_actor";
281-
return;
282-
case Erased:
283-
os << "erased";
284-
return;
285-
}
286-
llvm_unreachable("Covered switch isn't covered?!");
287-
}
267+
void print(llvm::raw_ostream &os) const;
268+
269+
void printForSIL(llvm::raw_ostream &os) const;
288270

289271
void printForDiagnostics(llvm::raw_ostream &os,
290272
StringRef openingQuotationMark = "'") const;
291273

292-
SWIFT_DEBUG_DUMP {
293-
print(llvm::dbgs());
294-
llvm::dbgs() << '\n';
295-
}
274+
SWIFT_DEBUG_DUMPER(dump());
296275

297276
// Defined out of line to prevent linker errors since libswiftBasic would
298277
// include this header exascerbating a layering violation where libswiftBasic

include/swift/AST/PrintOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,9 @@ struct PrintOptions {
382382
/// Suppress 'isolated' and '#isolation' on isolated parameters with optional type.
383383
bool SuppressOptionalIsolatedParams = false;
384384

385+
/// Suppress 'transferring' on arguments and results.
386+
bool SuppressTransferringArgsAndResults = false;
387+
385388
/// Suppress Noncopyable generics.
386389
bool SuppressNoncopyableGenerics = false;
387390

include/swift/Basic/Features.def

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ UPCOMING_FEATURE(ImplicitOpenExistentials, 352, 6)
196196
UPCOMING_FEATURE(RegionBasedIsolation, 414, 6)
197197
UPCOMING_FEATURE(DynamicActorIsolation, 423, 6)
198198
UPCOMING_FEATURE(NonfrozenEnumExhaustivity, 192, 6)
199+
UPCOMING_FEATURE(GlobalActorIsolatedTypesUsability, 0434, 6)
199200
UPCOMING_FEATURE(BorrowingSwitch, 432, 6)
200201

201202
// Swift 7
@@ -349,7 +350,7 @@ EXPERIMENTAL_FEATURE(FixedArrays, true)
349350
EXPERIMENTAL_FEATURE(GroupActorErrors, true)
350351

351352
// Allow for the 'transferring' keyword to be applied to arguments and results.
352-
EXPERIMENTAL_FEATURE(TransferringArgsAndResults, true)
353+
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(TransferringArgsAndResults, true)
353354

354355
// Enable explicit isolation of closures.
355356
EXPERIMENTAL_FEATURE(ClosureIsolation, true)
@@ -372,9 +373,6 @@ EXPERIMENTAL_FEATURE(CImplementation, true)
372373
// Enable the stdlib @DebugDescription macro.
373374
EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE(DebugDescriptionMacro, true)
374375

375-
// Enable usability improvements for global-actor-isolated types.
376-
EXPERIMENTAL_FEATURE(GlobalActorIsolatedTypesUsability, true)
377-
378376
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
379377
#undef EXPERIMENTAL_FEATURE
380378
#undef UPCOMING_FEATURE

include/swift/SIL/SILFunction.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,17 @@ class SILFunction
15391539
return getArguments().back();
15401540
}
15411541

1542+
/// If we have an isolated argument, return that. Returns nullptr otherwise.
1543+
const SILArgument *maybeGetIsolatedArgument() const {
1544+
for (auto *arg : getArgumentsWithoutIndirectResults()) {
1545+
if (cast<SILFunctionArgument>(arg)->getKnownParameterInfo().hasOption(
1546+
SILParameterInfo::Isolated))
1547+
return arg;
1548+
}
1549+
1550+
return nullptr;
1551+
}
1552+
15421553
const SILArgument *getDynamicSelfMetadata() const {
15431554
assert(hasDynamicSelfMetadata() && "This method can only be called if the "
15441555
"SILFunction has a self-metadata parameter");

include/swift/SILOptimizer/Analysis/RegionAnalysis.h

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,6 @@ using TransferringOperandSetFactory = Partition::TransferringOperandSetFactory;
3131
using Element = PartitionPrimitives::Element;
3232
using Region = PartitionPrimitives::Region;
3333

34-
/// Check if the passed in type is NonSendable.
35-
///
36-
/// NOTE: We special case RawPointer and NativeObject to ensure they are
37-
/// treated as non-Sendable and strict checking is applied to it.
38-
inline bool isNonSendableType(SILType type, SILFunction *fn) {
39-
// Treat Builtin.NativeObject and Builtin.RawPointer as non-Sendable.
40-
if (type.getASTType()->is<BuiltinNativeObjectType>() ||
41-
type.getASTType()->is<BuiltinRawPointerType>()) {
42-
return true;
43-
}
44-
45-
// Treat Builtin.SILToken as Sendable. It cannot escape from the current
46-
// function. We should change isSendable to hardwire this.
47-
if (type.getASTType()->is<SILTokenType>()) {
48-
return false;
49-
}
50-
51-
// Otherwise, delegate to seeing if type conforms to the Sendable protocol.
52-
return !type.isSendable(fn);
53-
}
54-
5534
/// Return the ApplyIsolationCrossing for a specific \p inst if it
5635
/// exists. Returns std::nullopt otherwise.
5736
std::optional<ApplyIsolationCrossing>
@@ -305,7 +284,10 @@ class regionanalysisimpl::TrackableValue {
305284
os << "\n Rep Value: " << getRepresentative();
306285
}
307286

308-
SWIFT_DEBUG_DUMP { print(llvm::dbgs()); }
287+
SWIFT_DEBUG_DUMP {
288+
print(llvm::dbgs());
289+
llvm::dbgs() << '\n';
290+
}
309291
};
310292

311293
class RegionAnalysis;

0 commit comments

Comments
 (0)