Skip to content

ABI: Clean up context and method descriptor pointers #29972

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
Show file tree
Hide file tree
Changes from all commits
Commits
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
53 changes: 35 additions & 18 deletions include/swift/ABI/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -836,17 +836,40 @@ struct TargetVTableDescriptorHeader {
}
};

template<typename Runtime> struct TargetContextDescriptor;

template<typename Runtime>
using TargetRelativeContextPointer =
RelativeIndirectablePointer<const TargetContextDescriptor<Runtime>,
/*nullable*/ true>;

using RelativeContextPointer = TargetRelativeContextPointer<InProcess>;

template<typename Runtime, typename IntTy,
template<typename _Runtime> class Context = TargetContextDescriptor>
using RelativeContextPointerIntPair =
RelativeIndirectablePointerIntPair<const Context<Runtime>, IntTy,
/*nullable*/ true, int32_t>;

template<typename Runtime> struct TargetMethodDescriptor;

template<typename Runtime>
using TargetRelativeMethodDescriptorPointer =
RelativeIndirectablePointer<const TargetMethodDescriptor<Runtime>,
/*nullable*/ true>;

using RelativeMethodDescriptorPointer =
TargetRelativeMethodDescriptorPointer<InProcess>;

/// An entry in the method override table, referencing a method from one of our
/// ancestor classes, together with an implementation.
template <typename Runtime>
struct TargetMethodOverrideDescriptor {
/// The class containing the base method.
TargetRelativeIndirectablePointer<Runtime, TargetClassDescriptor<Runtime>,
/*nullable*/ true> Class;
TargetRelativeContextPointer<Runtime> Class;

/// The base method.
TargetRelativeIndirectablePointer<Runtime, TargetMethodDescriptor<Runtime>,
/*nullable*/ true> Method;
TargetRelativeMethodDescriptorPointer<Runtime> Method;

/// The implementation of the override.
TargetRelativeDirectPointer<Runtime, void, /*nullable*/ true> Impl;
Expand Down Expand Up @@ -2191,21 +2214,14 @@ struct TargetTypeMetadataRecord {

using TypeMetadataRecord = TargetTypeMetadataRecord<InProcess>;

template<typename Runtime> struct TargetContextDescriptor;

template<typename Runtime>
using RelativeContextPointer =
RelativeIndirectablePointer<const TargetContextDescriptor<Runtime>,
/*nullable*/ true>;

/// The structure of a protocol reference record.
template <typename Runtime>
struct TargetProtocolRecord {
/// The protocol referenced.
///
/// The remaining low bit is reserved for future use.
RelativeIndirectablePointerIntPair<TargetProtocolDescriptor<Runtime>,
/*reserved=*/bool>
RelativeContextPointerIntPair<Runtime, /*reserved=*/bool,
TargetProtocolDescriptor>
Protocol;
};
using ProtocolRecord = TargetProtocolRecord<InProcess>;
Expand Down Expand Up @@ -2333,15 +2349,15 @@ template <typename Runtime>
struct TargetProtocolConformanceDescriptor final
: public swift::ABI::TrailingObjects<
TargetProtocolConformanceDescriptor<Runtime>,
RelativeContextPointer<Runtime>,
TargetRelativeContextPointer<Runtime>,
TargetGenericRequirementDescriptor<Runtime>,
TargetResilientWitnessesHeader<Runtime>,
TargetResilientWitness<Runtime>,
TargetGenericWitnessTable<Runtime>> {

using TrailingObjects = swift::ABI::TrailingObjects<
TargetProtocolConformanceDescriptor<Runtime>,
RelativeContextPointer<Runtime>,
TargetRelativeContextPointer<Runtime>,
TargetGenericRequirementDescriptor<Runtime>,
TargetResilientWitnessesHeader<Runtime>,
TargetResilientWitness<Runtime>,
Expand Down Expand Up @@ -2408,7 +2424,8 @@ struct TargetProtocolConformanceDescriptor final
const TargetContextDescriptor<Runtime> *getRetroactiveContext() const {
if (!Flags.isRetroactive()) return nullptr;

return this->template getTrailingObjects<RelativeContextPointer<Runtime>>();
return this->template getTrailingObjects<
TargetRelativeContextPointer<Runtime>>();
}

/// Whether this conformance is non-unique because it has been synthesized
Expand Down Expand Up @@ -2481,7 +2498,7 @@ struct TargetProtocolConformanceDescriptor final

private:
size_t numTrailingObjects(
OverloadToken<RelativeContextPointer<Runtime>>) const {
OverloadToken<TargetRelativeContextPointer<Runtime>>) const {
return Flags.isRetroactive() ? 1 : 0;
}

Expand Down Expand Up @@ -2527,7 +2544,7 @@ struct TargetContextDescriptor {
ContextDescriptorFlags Flags;

/// The parent context, or null if this is a top-level context.
RelativeContextPointer<Runtime> Parent;
TargetRelativeContextPointer<Runtime> Parent;

bool isGeneric() const { return Flags.isGeneric(); }
bool isUnique() const { return Flags.isUnique(); }
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/runtime/Metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2372,7 +2372,7 @@ static void initClassVTable(ClassMetadata *self) {
auto &descriptor = overrideDescriptors[i];

// Get the base class and method.
auto *baseClass = descriptor.Class.get();
auto *baseClass = cast_or_null<ClassDescriptor>(descriptor.Class.get());
auto *baseMethod = descriptor.Method.get();

// If the base method is null, it's an unavailable weak-linked
Expand Down