Skip to content

[6.0][region-isolation] Upstreaming some fixes #73483

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 17 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
b389bb5
[region-isolation] Look through actor isolated, non-Sendable struct_e…
gottesmm Apr 26, 2024
1e915f7
Fix how we look through (or not) and find the isolation ofunchecked_t…
gottesmm Apr 30, 2024
94a6546
[transferring] Make transferring suppressible and validate that we do…
gottesmm Apr 19, 2024
3ad4585
Fix a test since we cherry-picked this out of order from main with an…
gottesmm May 7, 2024
e35440c
[region-isolation] Some small gardening updates in preparation for th…
gottesmm May 9, 2024
d3053b3
[region-isolation] When inferring isolation for an argument, handle n…
gottesmm May 8, 2024
d34752f
[region-isolation] Fix isolation inference for init accessors.
gottesmm May 9, 2024
bc44f5c
fix a test
gottesmm May 10, 2024
7cc6a83
[region-isolation] Return the old way of printing ActorIsolation for …
gottesmm May 10, 2024
c2abdd5
[ast] Move ActorIsolation::dump out of line so we don't call print in…
gottesmm May 10, 2024
49bea46
[region-isolation] Avoid using the function isolation when determinin…
gottesmm May 11, 2024
d4f48e3
[sil] Restrict sil_isolated to only being able to be applied to any a…
gottesmm May 11, 2024
b7eb17e
Fix test case.
gottesmm May 13, 2024
17f564a
[region-isolation] Fix verifier check.
gottesmm May 13, 2024
5c353a9
[region-isolation] When computing isolation for isolated parameters, …
gottesmm May 13, 2024
900f9c7
[region-isolation] Allow for Sendable global actor isolated closures …
gottesmm May 13, 2024
2b1c380
[concurrency] Make GlobalActorIsolatedTypesUsability an upcoming swif…
gottesmm May 13, 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
12 changes: 12 additions & 0 deletions docs/SIL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,18 @@ autorelease in the callee.
type behaves like a non-generic type, as if the substitutions were
actually applied to the underlying function type.

- SIL functions may optionally mark a function parameter as
``@sil_isolated``. An ``@sil_isolated`` parameter must be one of:

- An actor or any actor type.
- A generic type that conforms to Actor or AnyActor.

and must be the actor instance that a function is isolated to. Importantly
this means that global actor isolated nominal types are never
``@sil_isolated``. Only one parameter can ever be marked as ``@sil_isolated``
since a function cannot be isolated to multiple actors at the same time.


Async Functions
```````````````

Expand Down
33 changes: 6 additions & 27 deletions include/swift/AST/ActorIsolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ class ActorIsolation {
return getKind() == GlobalActor;
}

bool isActorInstanceIsolated() const { return getKind() == ActorInstance; }

bool isMainActor() const;

bool isDistributedActor() const;
Expand Down Expand Up @@ -262,37 +264,14 @@ class ActorIsolation {
state.parameterIndex);
}

void print(llvm::raw_ostream &os) const {
switch (getKind()) {
case Unspecified:
os << "unspecified";
return;
case ActorInstance:
os << "actor_instance";
return;
case Nonisolated:
os << "nonisolated";
return;
case NonisolatedUnsafe:
os << "nonisolated_unsafe";
return;
case GlobalActor:
os << "global_actor";
return;
case Erased:
os << "erased";
return;
}
llvm_unreachable("Covered switch isn't covered?!");
}
void print(llvm::raw_ostream &os) const;

void printForSIL(llvm::raw_ostream &os) const;

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

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

// Defined out of line to prevent linker errors since libswiftBasic would
// include this header exascerbating a layering violation where libswiftBasic
Expand Down
3 changes: 3 additions & 0 deletions include/swift/AST/PrintOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ struct PrintOptions {
/// Suppress 'isolated' and '#isolation' on isolated parameters with optional type.
bool SuppressOptionalIsolatedParams = false;

/// Suppress 'transferring' on arguments and results.
bool SuppressTransferringArgsAndResults = false;

/// Suppress Noncopyable generics.
bool SuppressNoncopyableGenerics = false;

Expand Down
6 changes: 2 additions & 4 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ UPCOMING_FEATURE(ImplicitOpenExistentials, 352, 6)
UPCOMING_FEATURE(RegionBasedIsolation, 414, 6)
UPCOMING_FEATURE(DynamicActorIsolation, 423, 6)
UPCOMING_FEATURE(NonfrozenEnumExhaustivity, 192, 6)
UPCOMING_FEATURE(GlobalActorIsolatedTypesUsability, 0434, 6)
UPCOMING_FEATURE(BorrowingSwitch, 432, 6)

// Swift 7
Expand Down Expand Up @@ -349,7 +350,7 @@ EXPERIMENTAL_FEATURE(FixedArrays, true)
EXPERIMENTAL_FEATURE(GroupActorErrors, true)

// Allow for the 'transferring' keyword to be applied to arguments and results.
EXPERIMENTAL_FEATURE(TransferringArgsAndResults, true)
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(TransferringArgsAndResults, true)

// Enable explicit isolation of closures.
EXPERIMENTAL_FEATURE(ClosureIsolation, true)
Expand All @@ -372,9 +373,6 @@ EXPERIMENTAL_FEATURE(CImplementation, true)
// Enable the stdlib @DebugDescription macro.
EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE(DebugDescriptionMacro, true)

// Enable usability improvements for global-actor-isolated types.
EXPERIMENTAL_FEATURE(GlobalActorIsolatedTypesUsability, true)

#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
#undef EXPERIMENTAL_FEATURE
#undef UPCOMING_FEATURE
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 @@ -1539,6 +1539,17 @@ class SILFunction
return getArguments().back();
}

/// If we have an isolated argument, return that. Returns nullptr otherwise.
const SILArgument *maybeGetIsolatedArgument() const {
for (auto *arg : getArgumentsWithoutIndirectResults()) {
if (cast<SILFunctionArgument>(arg)->getKnownParameterInfo().hasOption(
SILParameterInfo::Isolated))
return arg;
}

return nullptr;
}

const SILArgument *getDynamicSelfMetadata() const {
assert(hasDynamicSelfMetadata() && "This method can only be called if the "
"SILFunction has a self-metadata parameter");
Expand Down
26 changes: 4 additions & 22 deletions include/swift/SILOptimizer/Analysis/RegionAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,6 @@ using TransferringOperandSetFactory = Partition::TransferringOperandSetFactory;
using Element = PartitionPrimitives::Element;
using Region = PartitionPrimitives::Region;

/// Check if the passed in type is NonSendable.
///
/// NOTE: We special case RawPointer and NativeObject to ensure they are
/// treated as non-Sendable and strict checking is applied to it.
inline bool isNonSendableType(SILType type, SILFunction *fn) {
// Treat Builtin.NativeObject and Builtin.RawPointer as non-Sendable.
if (type.getASTType()->is<BuiltinNativeObjectType>() ||
type.getASTType()->is<BuiltinRawPointerType>()) {
return true;
}

// Treat Builtin.SILToken as Sendable. It cannot escape from the current
// function. We should change isSendable to hardwire this.
if (type.getASTType()->is<SILTokenType>()) {
return false;
}

// Otherwise, delegate to seeing if type conforms to the Sendable protocol.
return !type.isSendable(fn);
}

/// Return the ApplyIsolationCrossing for a specific \p inst if it
/// exists. Returns std::nullopt otherwise.
std::optional<ApplyIsolationCrossing>
Expand Down Expand Up @@ -305,7 +284,10 @@ class regionanalysisimpl::TrackableValue {
os << "\n Rep Value: " << getRepresentative();
}

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

class RegionAnalysis;
Expand Down
Loading