Skip to content

Commit 7d1ce78

Browse files
committed
Revert "Revert "Isolated synchronous deinit""
1 parent 8fe0fd1 commit 7d1ce78

File tree

88 files changed

+4226
-509
lines changed

Some content is hidden

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

88 files changed

+4226
-509
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ Entities
365365
entity-spec ::= 'fP' // property wrapper backing initializer
366366
entity-spec ::= 'fW' // property wrapper init from projected value
367367
entity-spec ::= 'fD' // deallocating destructor; untyped
368+
entity-spec ::= 'fZ' // isolated deallocating destructor; untyped
368369
entity-spec ::= 'fd' // non-deallocating destructor; untyped
369370
entity-spec ::= 'fE' // ivar destroyer; untyped
370371
entity-spec ::= 'fe' // ivar initializer; untyped

include/swift/ABI/Executor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ using ThrowingTaskFutureWaitContinuationFunction =
295295
SWIFT_CC(swiftasync)
296296
void (SWIFT_ASYNC_CONTEXT AsyncContext *, SWIFT_CONTEXT void *);
297297

298+
using DeinitWorkFunction = SWIFT_CC(swift) void(void *);
298299

299300
template <class AsyncSignature>
300301
class AsyncFunctionPointer;

include/swift/ABI/MetadataValues.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2549,7 +2549,8 @@ enum class JobKind : size_t {
25492549
DefaultActorInline = First_Reserved,
25502550
DefaultActorSeparate,
25512551
DefaultActorOverride,
2552-
NullaryContinuation
2552+
NullaryContinuation,
2553+
IsolatedDeinit,
25532554
};
25542555

25552556
/// The priority of a job. Higher priorities are larger values.

include/swift/AST/ASTMangler.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ class RootProtocolConformance;
3434

3535
namespace Mangle {
3636

37+
enum class DestructorKind {
38+
NonDeallocating,
39+
Deallocating,
40+
IsolatedDeallocating
41+
};
42+
3743
/// The mangler for AST declarations.
3844
class ASTMangler : public Mangler {
3945
protected:
@@ -202,7 +208,7 @@ class ASTMangler : public Mangler {
202208
SymbolKind SKind = SymbolKind::Default);
203209

204210
std::string mangleDestructorEntity(const DestructorDecl *decl,
205-
bool isDeallocating,
211+
DestructorKind kind,
206212
SymbolKind SKind = SymbolKind::Default);
207213

208214
std::string mangleConstructorEntity(const ConstructorDecl *ctor,
@@ -700,8 +706,8 @@ class ASTMangler : public Mangler {
700706
bool tryAppendStandardSubstitution(const GenericTypeDecl *type);
701707

702708
void appendConstructorEntity(const ConstructorDecl *ctor, bool isAllocating);
703-
704-
void appendDestructorEntity(const DestructorDecl *decl, bool isDeallocating);
709+
710+
void appendDestructorEntity(const DestructorDecl *decl, DestructorKind kind);
705711

706712
/// \param accessorKindCode The code to describe the accessor and addressor
707713
/// kind. Usually retrieved using getCodeForAccessorKind.

include/swift/AST/Decl.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,10 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
13661366
std::optional<std::pair<CustomAttr *, NominalTypeDecl *>>
13671367
getGlobalActorAttr() const;
13681368

1369+
/// Determine whether there is an explicit isolation attribute
1370+
/// of any kind.
1371+
bool hasExplicitIsolationAttribute() const;
1372+
13691373
/// If an alternative module name is specified for this decl, e.g. using
13701374
/// @_originalDefinedIn attribute, this function returns this module name.
13711375
StringRef getAlternateModuleName() const;
@@ -3093,6 +3097,10 @@ class ValueDecl : public Decl {
30933097
/// Retrieve the declaration that this declaration overrides, if any.
30943098
ValueDecl *getOverriddenDecl() const;
30953099

3100+
/// Retrieve the declaration that this declaration overrides, including super
3101+
/// deinit.
3102+
ValueDecl *getOverriddenDeclOrSuperDeinit() const;
3103+
30963104
/// Retrieve the declarations that this declaration overrides, if any.
30973105
llvm::TinyPtrVector<ValueDecl *> getOverriddenDecls() const;
30983106

@@ -8892,6 +8900,10 @@ class DestructorDecl : public AbstractFunctionDecl {
88928900
/// Retrieve the Objective-C selector for destructors.
88938901
ObjCSelector getObjCSelector() const;
88948902

8903+
/// Retrieves destructor decl from the superclass, or nil if there is no
8904+
/// superclass
8905+
DestructorDecl *getSuperDeinit() const;
8906+
88958907
static bool classof(const Decl *D) {
88968908
return D->getKind() == DeclKind::Destructor;
88978909
}

include/swift/AST/DeclAttr.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,14 +434,17 @@ SIMPLE_DECL_ATTR(rethrows, Rethrows,
434434
CONTEXTUAL_SIMPLE_DECL_ATTR(indirect, Indirect,
435435
DeclModifier | OnEnum | OnEnumElement | ABIBreakingToAdd | ABIBreakingToRemove | APIStableToAdd | APIStableToRemove,
436436
60)
437+
CONTEXTUAL_SIMPLE_DECL_ATTR(isolated, Isolated,
438+
DeclModifier | OnDestructor | ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,
439+
103)
437440
CONTEXTUAL_SIMPLE_DECL_ATTR(async, Async,
438441
DeclModifier | OnVar | OnFunc | ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,
439442
106)
440443
SIMPLE_DECL_ATTR(reasync, Reasync,
441444
OnFunc | OnConstructor | RejectByParser | ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,
442445
109)
443446
CONTEXTUAL_DECL_ATTR(nonisolated, Nonisolated,
444-
DeclModifier | OnFunc | OnConstructor | OnVar | OnSubscript | ABIStableToAdd | ABIStableToRemove | APIBreakingToAdd | APIStableToRemove,
447+
DeclModifier | OnFunc | OnConstructor | OnDestructor | OnVar | OnSubscript | ABIStableToAdd | ABIStableToRemove | APIBreakingToAdd | APIStableToRemove,
445448
112)
446449
CONTEXTUAL_SIMPLE_DECL_ATTR(distributed, DistributedActor,
447450
DeclModifier | OnClass | OnFunc | OnAccessor | OnVar | ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,

include/swift/AST/DiagnosticsSema.def

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5890,9 +5890,12 @@ ERROR(global_actor_not_usable_from_inline,none,
58905890
NOTE(move_global_actor_attr_to_storage_decl,none,
58915891
"move global actor attribute to %kind0", (const ValueDecl *))
58925892

5893-
ERROR(actor_isolation_multiple_attr,none,
5893+
ERROR(actor_isolation_multiple_attr_2,none,
58945894
"%kind0 has multiple actor-isolation attributes ('%1' and '%2')",
58955895
(const Decl *, StringRef, StringRef))
5896+
ERROR(actor_isolation_multiple_attr_3,none,
5897+
"%0 %1 has multiple actor-isolation attributes ('%2', '%3' and '%4')",
5898+
(const Decl *, StringRef, StringRef, StringRef))
58965899
ERROR(actor_isolation_override_mismatch,none,
58975900
"%0 %kind1 has different actor isolation from %2 overridden declaration",
58985901
(ActorIsolation, const ValueDecl *, ActorIsolation))
@@ -5909,6 +5912,14 @@ ERROR(async_named_decl_must_be_available_from_async,none,
59095912
ERROR(async_unavailable_decl,none,
59105913
"%kindbase0 is unavailable from asynchronous contexts%select{|; %1}1",
59115914
(const ValueDecl *, StringRef))
5915+
5916+
5917+
ERROR(isolated_deinit_no_isolation,none,
5918+
"deinit is marked isolated, but containing class %0 is not isolated to an actor",
5919+
(DeclName))
5920+
ERROR(isolated_deinit_on_value_type,none,
5921+
"only classes and actors can have isolated deinit",
5922+
())
59125923

59135924
//------------------------------------------------------------------------------
59145925
// MARK: String Processing

include/swift/AST/PrintOptions.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class DeclContext;
3737
class Type;
3838
class ModuleDecl;
3939
enum class DeclAttrKind : unsigned;
40+
class DeclAttribute;
41+
class CustomAttr;
4042
class SynthesizedExtensionAnalyzer;
4143
struct PrintOptions;
4244
class SILPrintContext;
@@ -342,6 +344,10 @@ struct PrintOptions {
342344
/// Suppress emitting @available(*, noasync)
343345
bool SuppressNoAsyncAvailabilityAttr = false;
344346

347+
/// Suppress emitting isolated or async deinit, and emit open containing class
348+
/// as public
349+
bool SuppressIsolatedDeinit = false;
350+
345351
/// Whether to print the \c{/*not inherited*/} comment on factory initializers.
346352
bool PrintFactoryInitializerComment = true;
347353

@@ -396,6 +402,8 @@ struct PrintOptions {
396402
DeclAttrKind::FixedLayout, DeclAttrKind::ShowInInterface,
397403
};
398404

405+
std::vector<CustomAttr *> ExcludeCustomAttrList = {};
406+
399407
/// List of attribute kinds that should be printed exclusively.
400408
/// Empty means allow all.
401409
std::vector<AnyAttrKind> ExclusiveAttrList;
@@ -627,6 +635,8 @@ struct PrintOptions {
627635
return false;
628636
}
629637

638+
bool excludeAttr(const DeclAttribute *DA) const;
639+
630640
/// Retrieve the set of options for verbose printing to users.
631641
static PrintOptions printVerbose() {
632642
PrintOptions result;
@@ -681,7 +691,8 @@ struct PrintOptions {
681691
result.SkipPrivateSystemDecls = true;
682692
result.SkipUnderscoredSystemProtocols = true;
683693
result.SkipUnsafeCXXMethods = true;
684-
result.SkipDeinit = true;
694+
result.SkipDeinit = false; // Deinit may have isolation attributes, which
695+
// are part of the interface
685696
result.EmptyLineBetweenDecls = true;
686697
result.CascadeDocComment = true;
687698
result.ShouldQualifyNestedDeclarations =

include/swift/Basic/Features.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ SUPPRESSIBLE_EXPERIMENTAL_FEATURE(AllowUnsafeAttribute, true)
408408
/// Warn on use of unsafe constructs.
409409
EXPERIMENTAL_FEATURE(WarnUnsafe, true)
410410

411+
EXPERIMENTAL_FEATURE(IsolatedDeinit, true)
412+
411413
// Enable values in generic signatures, e.g. <let N: Int>
412414
EXPERIMENTAL_FEATURE(ValueGenerics, true)
413415

include/swift/Demangling/DemangleNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ NODE(InfixOperator)
153153
CONTEXT_NODE(Initializer)
154154
CONTEXT_NODE(InitAccessor)
155155
NODE(Isolated)
156+
CONTEXT_NODE(IsolatedDeallocator)
156157
NODE(Sending)
157158
NODE(IsolatedAnyFunctionType)
158159
NODE(SendingResultFunctionType)

0 commit comments

Comments
 (0)