Skip to content

Commit 17952d4

Browse files
Merge pull request #80221 from nate-chandler/general-coro/20250320/1
[CoroutineAccessors] Default overrides of new symbols.
2 parents 5af7e0d + 5534eb4 commit 17952d4

Some content is hidden

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

47 files changed

+2389
-113
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ types where the metadata itself has unknown layout.)
239239
global ::= global 'Twb' // back deployment thunk
240240
global ::= global 'TwB' // back deployment fallback function
241241
global ::= global 'Twc' // coro function pointer of a function
242+
global ::= global 'Twd' // default override of a function
242243
global ::= entity entity 'TV' // vtable override thunk, derived followed by base
243244
global ::= type label-list? 'D' // type mangling for the debugger with label list for function types.
244245
global ::= type 'TC' // continuation prototype (not actually used for real symbols)

include/swift/ABI/Metadata.h

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,54 @@ using TargetRelativeProtocolRequirementPointer =
654654
using RelativeProtocolRequirementPointer =
655655
TargetRelativeProtocolRequirementPointer<InProcess>;
656656

657+
/// An entry in the default override table, consisting of one of our methods
658+
/// `replacement` together with (1) another of our methods `original` which
659+
/// might have been overridden by a subclass and (2) an implementation of
660+
/// `replacement` to be used by such a subclass if it does not provide its own
661+
/// implementation.
662+
template <typename Runtime>
663+
struct TargetMethodDefaultOverrideDescriptor {
664+
/// The method which replaced the original at call-sites.
665+
TargetRelativeMethodDescriptorPointer<Runtime> Replacement;
666+
667+
/// The method originally called at such call sites.
668+
TargetRelativeMethodDescriptorPointer<Runtime> Original;
669+
670+
union {
671+
TargetCompactFunctionPointer<Runtime, void, /*nullable*/ true> Impl;
672+
TargetRelativeDirectPointer<Runtime, void, /*nullable*/ true> AsyncImpl;
673+
TargetRelativeDirectPointer<Runtime, void, /*nullable*/ true> CoroImpl;
674+
};
675+
676+
bool isData() const {
677+
auto *replacement = Replacement.get();
678+
assert(replacement && "no replacement");
679+
return replacement->Flags.isData();
680+
}
681+
682+
void *getImpl() const {
683+
auto *replacement = Replacement.get();
684+
assert(replacement && "no replacement");
685+
if (replacement->Flags.isAsync()) {
686+
return AsyncImpl.get();
687+
} else if (replacement->Flags.isCalleeAllocatedCoroutine()) {
688+
return CoroImpl.get();
689+
} else {
690+
return Impl.get();
691+
}
692+
}
693+
};
694+
695+
/// Header for a table of default override descriptors. Such a table is a
696+
/// variable-sized structure whose length is stored in this header which is
697+
/// followed by that many TargetMethodDefaultOverrideDescriptors.
698+
template <typename Runtime>
699+
struct TargetMethodDefaultOverrideTableHeader {
700+
/// The number of TargetMethodDefaultOverrideDescriptor records following this
701+
/// header in the class's nominal type descriptor.
702+
uint32_t NumEntries;
703+
};
704+
657705
/// An entry in the method override table, referencing a method from one of our
658706
/// ancestor classes, together with an implementation.
659707
template <typename Runtime>
@@ -4205,9 +4253,11 @@ class swift_ptrauth_struct_context_descriptor(ClassDescriptor)
42054253
TargetCanonicalSpecializedMetadataAccessorsListEntry<Runtime>,
42064254
TargetCanonicalSpecializedMetadatasCachingOnceToken<Runtime>,
42074255
InvertibleProtocolSet,
4208-
TargetSingletonMetadataPointer<Runtime>> {
4256+
TargetSingletonMetadataPointer<Runtime>,
4257+
TargetMethodDefaultOverrideTableHeader<Runtime>,
4258+
TargetMethodDefaultOverrideDescriptor<Runtime>> {
42094259
private:
4210-
using TrailingGenericContextObjects =
4260+
using TrailingGenericContextObjects =
42114261
swift::TrailingGenericContextObjects<TargetClassDescriptor<Runtime>,
42124262
TargetTypeGenericContextDescriptorHeader,
42134263
TargetResilientSuperclass<Runtime>,
@@ -4223,7 +4273,9 @@ class swift_ptrauth_struct_context_descriptor(ClassDescriptor)
42234273
TargetCanonicalSpecializedMetadataAccessorsListEntry<Runtime>,
42244274
TargetCanonicalSpecializedMetadatasCachingOnceToken<Runtime>,
42254275
InvertibleProtocolSet,
4226-
TargetSingletonMetadataPointer<Runtime>>;
4276+
TargetSingletonMetadataPointer<Runtime>,
4277+
TargetMethodDefaultOverrideTableHeader<Runtime>,
4278+
TargetMethodDefaultOverrideDescriptor<Runtime>>;
42274279

42284280
using TrailingObjects =
42294281
typename TrailingGenericContextObjects::TrailingObjects;
@@ -4254,6 +4306,10 @@ class swift_ptrauth_struct_context_descriptor(ClassDescriptor)
42544306
using MetadataCachingOnceToken =
42554307
TargetCanonicalSpecializedMetadatasCachingOnceToken<Runtime>;
42564308
using SingletonMetadataPointer = TargetSingletonMetadataPointer<Runtime>;
4309+
using DefaultOverrideTableHeader =
4310+
TargetMethodDefaultOverrideTableHeader<Runtime>;
4311+
using DefaultOverrideDescriptor =
4312+
TargetMethodDefaultOverrideDescriptor<Runtime>;
42574313

42584314
using StoredPointer = typename Runtime::StoredPointer;
42594315
using StoredPointerDifference = typename Runtime::StoredPointerDifference;
@@ -4399,6 +4455,16 @@ class swift_ptrauth_struct_context_descriptor(ClassDescriptor)
43994455
return this->hasSingletonMetadataPointer() ? 1 : 0;
44004456
}
44014457

4458+
size_t numTrailingObjects(OverloadToken<DefaultOverrideTableHeader>) const {
4459+
return hasDefaultOverrideTable() ? 1 : 0;
4460+
}
4461+
4462+
size_t numTrailingObjects(OverloadToken<DefaultOverrideDescriptor>) const {
4463+
if (!hasDefaultOverrideTable())
4464+
return 0;
4465+
return getDefaultOverrideTable()->NumEntries;
4466+
}
4467+
44024468
public:
44034469
const TargetRelativeDirectPointer<Runtime, const void, /*nullable*/true> &
44044470
getResilientSuperclass() const {
@@ -4430,6 +4496,10 @@ class swift_ptrauth_struct_context_descriptor(ClassDescriptor)
44304496
return FieldOffsetVectorOffset;
44314497
}
44324498

4499+
bool hasDefaultOverrideTable() const {
4500+
return getTypeContextDescriptorFlags().class_hasDefaultOverrideTable();
4501+
}
4502+
44334503
bool isActor() const {
44344504
return this->getTypeContextDescriptorFlags().class_isActor();
44354505
}
@@ -4476,6 +4546,20 @@ class swift_ptrauth_struct_context_descriptor(ClassDescriptor)
44764546
numTrailingObjects(OverloadToken<MethodOverrideDescriptor>{})};
44774547
}
44784548

4549+
const DefaultOverrideTableHeader *getDefaultOverrideTable() const {
4550+
if (!hasDefaultOverrideTable())
4551+
return nullptr;
4552+
return this->template getTrailingObjects<DefaultOverrideTableHeader>();
4553+
}
4554+
4555+
llvm::ArrayRef<DefaultOverrideDescriptor> getDefaultOverrideDescriptors()
4556+
const {
4557+
if (!hasDefaultOverrideTable())
4558+
return {};
4559+
return {this->template getTrailingObjects<DefaultOverrideDescriptor>(),
4560+
numTrailingObjects(OverloadToken<DefaultOverrideDescriptor>{})};
4561+
}
4562+
44794563
/// Return the bounds of this class's metadata.
44804564
TargetClassMetadataBounds<Runtime> getMetadataBounds() const {
44814565
if (!hasResilientSuperclass())

include/swift/ABI/MetadataValues.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,8 +1955,12 @@ class TypeContextDescriptorFlags : public FlagSet<uint16_t> {
19551955
/// Set if the metadata contains a pointer to a layout string
19561956
HasLayoutString = 4,
19571957

1958+
/// WARNING: 5 is the last bit!
1959+
19581960
// Type-specific flags:
19591961

1962+
Class_HasDefaultOverrideTable = 6,
1963+
19601964
/// Set if the class is an actor.
19611965
///
19621966
/// Only meaningful for class descriptors.
@@ -2062,6 +2066,9 @@ class TypeContextDescriptorFlags : public FlagSet<uint16_t> {
20622066
FLAGSET_DEFINE_FLAG_ACCESSORS(Class_IsActor,
20632067
class_isActor,
20642068
class_setIsActor)
2069+
FLAGSET_DEFINE_FLAG_ACCESSORS(Class_HasDefaultOverrideTable,
2070+
class_hasDefaultOverrideTable,
2071+
class_setHasDefaultOverrideTable)
20652072

20662073
FLAGSET_DEFINE_FIELD_ACCESSORS(Class_ResilientSuperclassReferenceKind,
20672074
Class_ResilientSuperclassReferenceKind_width,

include/swift/AST/DiagnosticsParse.def

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,14 @@ ERROR(sil_witness_assoc_conf_not_found,none,
763763
ERROR(sil_witness_protocol_conformance_not_found,none,
764764
"sil protocol conformance not found", ())
765765

766+
// SIL default override table
767+
ERROR(sil_default_override_func_not_found,none,
768+
"sil function not found %0", (Identifier))
769+
ERROR(sil_default_override_class_not_found,none,
770+
"sil class not found %0", (Identifier))
771+
ERROR(sil_default_override_decl_not_class,none,
772+
"sil decl found for %0 is not a class", (Identifier))
773+
766774
// SIL differentiability witnesses
767775
ERROR(sil_diff_witness_expected_token,PointsToFirstBadToken,
768776
"expected '%0' in differentiability witness", (StringRef))

include/swift/AST/TokenKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ SIL_KEYWORD(sil_moveonlydeinit)
272272
SIL_KEYWORD(sil_global)
273273
SIL_KEYWORD(sil_witness_table)
274274
SIL_KEYWORD(sil_default_witness_table)
275+
SIL_KEYWORD(sil_default_override_table)
275276
SIL_KEYWORD(sil_differentiability_witness)
276277
SIL_KEYWORD(sil_coverage_map)
277278
SIL_KEYWORD(sil_scope)

include/swift/Demangling/DemangleNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ NODE(Integer)
411411
NODE(NegativeInteger)
412412
NODE(DependentGenericParamValueMarker)
413413
NODE(CoroFunctionPointer)
414+
NODE(DefaultOverride)
414415

415416
#undef CONTEXT_NODE
416417
#undef NODE

include/swift/Parse/ParseSILSupport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace swift {
3333
virtual bool parseSILGlobal(Parser &P) = 0;
3434
virtual bool parseSILWitnessTable(Parser &P) = 0;
3535
virtual bool parseSILDefaultWitnessTable(Parser &P) = 0;
36+
virtual bool parseSILDefaultOverrideTable(Parser &P) = 0;
3637
virtual bool parseSILDifferentiabilityWitness(Parser &P) = 0;
3738
virtual bool parseSILCoverageMap(Parser &P) = 0;
3839
virtual bool parseSILProperty(Parser &P) = 0;

include/swift/SIL/Notifications.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class SILNode;
2727
class ModuleDecl;
2828
class SILFunction;
2929
class SILWitnessTable;
30+
class SILDefaultOverrideTable;
3031
class SILDefaultWitnessTable;
3132
class SILGlobalVariable;
3233
class SILVTable;
@@ -50,6 +51,12 @@ class DeserializationNotificationHandlerBase {
5051
virtual void didDeserializeWitnessTableEntries(ModuleDecl *mod,
5152
SILWitnessTable *wt) = 0;
5253

54+
/// Observe that we successfully deserialized a default override table's
55+
/// entries.
56+
virtual void
57+
didDeserializeDefaultOverrideTableEntries(ModuleDecl *mod,
58+
SILDefaultOverrideTable *ot) = 0;
59+
5360
/// Observe that we successfully deserialized a default witness table's
5461
/// entries.
5562
virtual void
@@ -69,6 +76,10 @@ class DeserializationNotificationHandlerBase {
6976
virtual void didDeserialize(ModuleDecl *mod,
7077
SILDefaultWitnessTable *wtable) = 0;
7178

79+
/// Observe that we deserialized a default override table declaration.
80+
virtual void didDeserialize(ModuleDecl *mod,
81+
SILDefaultOverrideTable *otable) = 0;
82+
7283
/// Observe that we deserialized a move only deinit declaration.
7384
virtual void didDeserialize(ModuleDecl *mod, SILMoveOnlyDeinit *deinit) = 0;
7485

@@ -93,6 +104,10 @@ class DeserializationNotificationHandler
93104
SILWitnessTable *wt) override {
94105
}
95106

107+
/// Observe that we successfully deserialized a override table's entries.
108+
virtual void didDeserializeDefaultOverrideTableEntries(
109+
ModuleDecl *mod, SILDefaultOverrideTable *ot) override {}
110+
96111
/// Observe that we successfully deserialized a default witness table's
97112
/// entries.
98113
virtual void didDeserializeDefaultWitnessTableEntries(
@@ -113,6 +128,10 @@ class DeserializationNotificationHandler
113128
virtual void didDeserialize(ModuleDecl *mod,
114129
SILDefaultWitnessTable *wtable) override {}
115130

131+
/// Observe that we deserialized a default override table declaration.
132+
virtual void didDeserialize(ModuleDecl *mod,
133+
SILDefaultOverrideTable *otable) override {}
134+
116135
/// Observe that we deserialized a move only deinit declaration.
117136
virtual void didDeserialize(ModuleDecl *mod,
118137
SILMoveOnlyDeinit *deinit) override {}
@@ -242,11 +261,15 @@ class DeserializationNotificationHandlerSet final
242261
void
243262
didDeserializeDefaultWitnessTableEntries(ModuleDecl *mod,
244263
SILDefaultWitnessTable *wt) override;
264+
void didDeserializeDefaultOverrideTableEntries(
265+
ModuleDecl *mod, SILDefaultOverrideTable *ot) override;
245266
void didDeserialize(ModuleDecl *mod, SILGlobalVariable *var) override;
246267
void didDeserialize(ModuleDecl *mod, SILVTable *vtable) override;
247268
void didDeserialize(ModuleDecl *mod, SILWitnessTable *wtable) override;
248269
void didDeserialize(ModuleDecl *mod,
249270
SILDefaultWitnessTable *wtable) override;
271+
void didDeserialize(ModuleDecl *mod,
272+
SILDefaultOverrideTable *otable) override;
250273
void didDeserialize(ModuleDecl *mod, SILMoveOnlyDeinit *deinit) override;
251274
};
252275
} // namespace swift

include/swift/SIL/SILDeclRef.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#ifndef SWIFT_SIL_SILDECLREF_H
2020
#define SWIFT_SIL_SILDECLREF_H
2121

22+
#include "swift/AST/Attr.h"
23+
#include "swift/AST/AutoDiff.h"
2224
#include "swift/AST/AvailabilityRange.h"
2325
#include "swift/AST/ClangNode.h"
2426
#include "swift/AST/GenericSignature.h"
@@ -36,7 +38,6 @@ namespace swift {
3638
enum class EffectsKind : uint8_t;
3739
class AbstractFunctionDecl;
3840
class AbstractClosureExpr;
39-
class AutoDiffDerivativeFunctionIdentifier;
4041
class ValueDecl;
4142
class FuncDecl;
4243
class ClosureExpr;
@@ -53,7 +54,6 @@ namespace swift {
5354
enum class SILLinkage : uint8_t;
5455
class AnyFunctionRef;
5556
class GenericSignature;
56-
class CustomAttr;
5757

5858
/// How a method is dispatched.
5959
enum class MethodDispatch {

0 commit comments

Comments
 (0)