Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions docs/ABI/Mangling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ types where the metadata itself has unknown layout.)
global ::= global 'Twb' // back deployment thunk
global ::= global 'TwB' // back deployment fallback function
global ::= global 'Twc' // coro function pointer of a function
global ::= global 'Twd' // default override of a function
global ::= entity entity 'TV' // vtable override thunk, derived followed by base
global ::= type label-list? 'D' // type mangling for the debugger with label list for function types.
global ::= type 'TC' // continuation prototype (not actually used for real symbols)
Expand Down
90 changes: 87 additions & 3 deletions include/swift/ABI/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,54 @@ using TargetRelativeProtocolRequirementPointer =
using RelativeProtocolRequirementPointer =
TargetRelativeProtocolRequirementPointer<InProcess>;

/// An entry in the default override table, consisting of one of our methods
/// `replacement` together with (1) another of our methods `original` which
/// might have been overridden by a subclass and (2) an implementation of
/// `replacement` to be used by such a subclass if it does not provide its own
/// implementation.
template <typename Runtime>
struct TargetMethodDefaultOverrideDescriptor {
/// The method which replaced the original at call-sites.
TargetRelativeMethodDescriptorPointer<Runtime> Replacement;

/// The method originally called at such call sites.
TargetRelativeMethodDescriptorPointer<Runtime> Original;

union {
TargetCompactFunctionPointer<Runtime, void, /*nullable*/ true> Impl;
TargetRelativeDirectPointer<Runtime, void, /*nullable*/ true> AsyncImpl;
TargetRelativeDirectPointer<Runtime, void, /*nullable*/ true> CoroImpl;
};

bool isData() const {
auto *replacement = Replacement.get();
assert(replacement && "no replacement");
return replacement->Flags.isData();
}

void *getImpl() const {
auto *replacement = Replacement.get();
assert(replacement && "no replacement");
if (replacement->Flags.isAsync()) {
return AsyncImpl.get();
} else if (replacement->Flags.isCalleeAllocatedCoroutine()) {
return CoroImpl.get();
} else {
return Impl.get();
}
}
};

/// Header for a table of default override descriptors. Such a table is a
/// variable-sized structure whose length is stored in this header which is
/// followed by that many TargetMethodDefaultOverrideDescriptors.
template <typename Runtime>
struct TargetMethodDefaultOverrideTableHeader {
/// The number of TargetMethodDefaultOverrideDescriptor records following this
/// header in the class's nominal type descriptor.
uint32_t NumEntries;
};

/// An entry in the method override table, referencing a method from one of our
/// ancestor classes, together with an implementation.
template <typename Runtime>
Expand Down Expand Up @@ -4205,9 +4253,11 @@ class swift_ptrauth_struct_context_descriptor(ClassDescriptor)
TargetCanonicalSpecializedMetadataAccessorsListEntry<Runtime>,
TargetCanonicalSpecializedMetadatasCachingOnceToken<Runtime>,
InvertibleProtocolSet,
TargetSingletonMetadataPointer<Runtime>> {
TargetSingletonMetadataPointer<Runtime>,
TargetMethodDefaultOverrideTableHeader<Runtime>,
TargetMethodDefaultOverrideDescriptor<Runtime>> {
private:
using TrailingGenericContextObjects =
using TrailingGenericContextObjects =
swift::TrailingGenericContextObjects<TargetClassDescriptor<Runtime>,
TargetTypeGenericContextDescriptorHeader,
TargetResilientSuperclass<Runtime>,
Expand All @@ -4223,7 +4273,9 @@ class swift_ptrauth_struct_context_descriptor(ClassDescriptor)
TargetCanonicalSpecializedMetadataAccessorsListEntry<Runtime>,
TargetCanonicalSpecializedMetadatasCachingOnceToken<Runtime>,
InvertibleProtocolSet,
TargetSingletonMetadataPointer<Runtime>>;
TargetSingletonMetadataPointer<Runtime>,
TargetMethodDefaultOverrideTableHeader<Runtime>,
TargetMethodDefaultOverrideDescriptor<Runtime>>;

using TrailingObjects =
typename TrailingGenericContextObjects::TrailingObjects;
Expand Down Expand Up @@ -4254,6 +4306,10 @@ class swift_ptrauth_struct_context_descriptor(ClassDescriptor)
using MetadataCachingOnceToken =
TargetCanonicalSpecializedMetadatasCachingOnceToken<Runtime>;
using SingletonMetadataPointer = TargetSingletonMetadataPointer<Runtime>;
using DefaultOverrideTableHeader =
TargetMethodDefaultOverrideTableHeader<Runtime>;
using DefaultOverrideDescriptor =
TargetMethodDefaultOverrideDescriptor<Runtime>;

using StoredPointer = typename Runtime::StoredPointer;
using StoredPointerDifference = typename Runtime::StoredPointerDifference;
Expand Down Expand Up @@ -4399,6 +4455,16 @@ class swift_ptrauth_struct_context_descriptor(ClassDescriptor)
return this->hasSingletonMetadataPointer() ? 1 : 0;
}

size_t numTrailingObjects(OverloadToken<DefaultOverrideTableHeader>) const {
return hasDefaultOverrideTable() ? 1 : 0;
}

size_t numTrailingObjects(OverloadToken<DefaultOverrideDescriptor>) const {
if (!hasDefaultOverrideTable())
return 0;
return getDefaultOverrideTable()->NumEntries;
}

public:
const TargetRelativeDirectPointer<Runtime, const void, /*nullable*/true> &
getResilientSuperclass() const {
Expand Down Expand Up @@ -4430,6 +4496,10 @@ class swift_ptrauth_struct_context_descriptor(ClassDescriptor)
return FieldOffsetVectorOffset;
}

bool hasDefaultOverrideTable() const {
return getTypeContextDescriptorFlags().class_hasDefaultOverrideTable();
}

bool isActor() const {
return this->getTypeContextDescriptorFlags().class_isActor();
}
Expand Down Expand Up @@ -4476,6 +4546,20 @@ class swift_ptrauth_struct_context_descriptor(ClassDescriptor)
numTrailingObjects(OverloadToken<MethodOverrideDescriptor>{})};
}

const DefaultOverrideTableHeader *getDefaultOverrideTable() const {
if (!hasDefaultOverrideTable())
return nullptr;
return this->template getTrailingObjects<DefaultOverrideTableHeader>();
}

llvm::ArrayRef<DefaultOverrideDescriptor> getDefaultOverrideDescriptors()
const {
if (!hasDefaultOverrideTable())
return {};
return {this->template getTrailingObjects<DefaultOverrideDescriptor>(),
numTrailingObjects(OverloadToken<DefaultOverrideDescriptor>{})};
}

/// Return the bounds of this class's metadata.
TargetClassMetadataBounds<Runtime> getMetadataBounds() const {
if (!hasResilientSuperclass())
Expand Down
7 changes: 7 additions & 0 deletions include/swift/ABI/MetadataValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -1955,8 +1955,12 @@ class TypeContextDescriptorFlags : public FlagSet<uint16_t> {
/// Set if the metadata contains a pointer to a layout string
HasLayoutString = 4,

/// WARNING: 5 is the last bit!

// Type-specific flags:

Class_HasDefaultOverrideTable = 6,

/// Set if the class is an actor.
///
/// Only meaningful for class descriptors.
Expand Down Expand Up @@ -2062,6 +2066,9 @@ class TypeContextDescriptorFlags : public FlagSet<uint16_t> {
FLAGSET_DEFINE_FLAG_ACCESSORS(Class_IsActor,
class_isActor,
class_setIsActor)
FLAGSET_DEFINE_FLAG_ACCESSORS(Class_HasDefaultOverrideTable,
class_hasDefaultOverrideTable,
class_setHasDefaultOverrideTable)

FLAGSET_DEFINE_FIELD_ACCESSORS(Class_ResilientSuperclassReferenceKind,
Class_ResilientSuperclassReferenceKind_width,
Expand Down
8 changes: 8 additions & 0 deletions include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,14 @@ ERROR(sil_witness_assoc_conf_not_found,none,
ERROR(sil_witness_protocol_conformance_not_found,none,
"sil protocol conformance not found", ())

// SIL default override table
ERROR(sil_default_override_func_not_found,none,
"sil function not found %0", (Identifier))
ERROR(sil_default_override_class_not_found,none,
"sil class not found %0", (Identifier))
ERROR(sil_default_override_decl_not_class,none,
"sil decl found for %0 is not a class", (Identifier))

// SIL differentiability witnesses
ERROR(sil_diff_witness_expected_token,PointsToFirstBadToken,
"expected '%0' in differentiability witness", (StringRef))
Expand Down
1 change: 1 addition & 0 deletions include/swift/AST/TokenKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ SIL_KEYWORD(sil_moveonlydeinit)
SIL_KEYWORD(sil_global)
SIL_KEYWORD(sil_witness_table)
SIL_KEYWORD(sil_default_witness_table)
SIL_KEYWORD(sil_default_override_table)
SIL_KEYWORD(sil_differentiability_witness)
SIL_KEYWORD(sil_coverage_map)
SIL_KEYWORD(sil_scope)
Expand Down
1 change: 1 addition & 0 deletions include/swift/Demangling/DemangleNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ NODE(Integer)
NODE(NegativeInteger)
NODE(DependentGenericParamValueMarker)
NODE(CoroFunctionPointer)
NODE(DefaultOverride)

#undef CONTEXT_NODE
#undef NODE
1 change: 1 addition & 0 deletions include/swift/Parse/ParseSILSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace swift {
virtual bool parseSILGlobal(Parser &P) = 0;
virtual bool parseSILWitnessTable(Parser &P) = 0;
virtual bool parseSILDefaultWitnessTable(Parser &P) = 0;
virtual bool parseSILDefaultOverrideTable(Parser &P) = 0;
virtual bool parseSILDifferentiabilityWitness(Parser &P) = 0;
virtual bool parseSILCoverageMap(Parser &P) = 0;
virtual bool parseSILProperty(Parser &P) = 0;
Expand Down
23 changes: 23 additions & 0 deletions include/swift/SIL/Notifications.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SILNode;
class ModuleDecl;
class SILFunction;
class SILWitnessTable;
class SILDefaultOverrideTable;
class SILDefaultWitnessTable;
class SILGlobalVariable;
class SILVTable;
Expand All @@ -50,6 +51,12 @@ class DeserializationNotificationHandlerBase {
virtual void didDeserializeWitnessTableEntries(ModuleDecl *mod,
SILWitnessTable *wt) = 0;

/// Observe that we successfully deserialized a default override table's
/// entries.
virtual void
didDeserializeDefaultOverrideTableEntries(ModuleDecl *mod,
SILDefaultOverrideTable *ot) = 0;

/// Observe that we successfully deserialized a default witness table's
/// entries.
virtual void
Expand All @@ -69,6 +76,10 @@ class DeserializationNotificationHandlerBase {
virtual void didDeserialize(ModuleDecl *mod,
SILDefaultWitnessTable *wtable) = 0;

/// Observe that we deserialized a default override table declaration.
virtual void didDeserialize(ModuleDecl *mod,
SILDefaultOverrideTable *otable) = 0;

/// Observe that we deserialized a move only deinit declaration.
virtual void didDeserialize(ModuleDecl *mod, SILMoveOnlyDeinit *deinit) = 0;

Expand All @@ -93,6 +104,10 @@ class DeserializationNotificationHandler
SILWitnessTable *wt) override {
}

/// Observe that we successfully deserialized a override table's entries.
virtual void didDeserializeDefaultOverrideTableEntries(
ModuleDecl *mod, SILDefaultOverrideTable *ot) override {}

/// Observe that we successfully deserialized a default witness table's
/// entries.
virtual void didDeserializeDefaultWitnessTableEntries(
Expand All @@ -113,6 +128,10 @@ class DeserializationNotificationHandler
virtual void didDeserialize(ModuleDecl *mod,
SILDefaultWitnessTable *wtable) override {}

/// Observe that we deserialized a default override table declaration.
virtual void didDeserialize(ModuleDecl *mod,
SILDefaultOverrideTable *otable) override {}

/// Observe that we deserialized a move only deinit declaration.
virtual void didDeserialize(ModuleDecl *mod,
SILMoveOnlyDeinit *deinit) override {}
Expand Down Expand Up @@ -242,11 +261,15 @@ class DeserializationNotificationHandlerSet final
void
didDeserializeDefaultWitnessTableEntries(ModuleDecl *mod,
SILDefaultWitnessTable *wt) override;
void didDeserializeDefaultOverrideTableEntries(
ModuleDecl *mod, SILDefaultOverrideTable *ot) override;
void didDeserialize(ModuleDecl *mod, SILGlobalVariable *var) override;
void didDeserialize(ModuleDecl *mod, SILVTable *vtable) override;
void didDeserialize(ModuleDecl *mod, SILWitnessTable *wtable) override;
void didDeserialize(ModuleDecl *mod,
SILDefaultWitnessTable *wtable) override;
void didDeserialize(ModuleDecl *mod,
SILDefaultOverrideTable *otable) override;
void didDeserialize(ModuleDecl *mod, SILMoveOnlyDeinit *deinit) override;
};
} // namespace swift
Expand Down
4 changes: 2 additions & 2 deletions include/swift/SIL/SILDeclRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef SWIFT_SIL_SILDECLREF_H
#define SWIFT_SIL_SILDECLREF_H

#include "swift/AST/Attr.h"
#include "swift/AST/AutoDiff.h"
#include "swift/AST/AvailabilityRange.h"
#include "swift/AST/ClangNode.h"
#include "swift/AST/GenericSignature.h"
Expand All @@ -36,7 +38,6 @@ namespace swift {
enum class EffectsKind : uint8_t;
class AbstractFunctionDecl;
class AbstractClosureExpr;
class AutoDiffDerivativeFunctionIdentifier;
class ValueDecl;
class FuncDecl;
class ClosureExpr;
Expand All @@ -53,7 +54,6 @@ namespace swift {
enum class SILLinkage : uint8_t;
class AnyFunctionRef;
class GenericSignature;
class CustomAttr;

/// How a method is dispatched.
enum class MethodDispatch {
Expand Down
Loading