Skip to content

Commit dd94d57

Browse files
authored
Merge pull request #29972 from slavapestov/clean-up-metadata-relative-pointers
ABI: Clean up context and method descriptor pointers
2 parents 91c7906 + a98f446 commit dd94d57

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

include/swift/ABI/Metadata.h

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -836,17 +836,40 @@ struct TargetVTableDescriptorHeader {
836836
}
837837
};
838838

839+
template<typename Runtime> struct TargetContextDescriptor;
840+
841+
template<typename Runtime>
842+
using TargetRelativeContextPointer =
843+
RelativeIndirectablePointer<const TargetContextDescriptor<Runtime>,
844+
/*nullable*/ true>;
845+
846+
using RelativeContextPointer = TargetRelativeContextPointer<InProcess>;
847+
848+
template<typename Runtime, typename IntTy,
849+
template<typename _Runtime> class Context = TargetContextDescriptor>
850+
using RelativeContextPointerIntPair =
851+
RelativeIndirectablePointerIntPair<const Context<Runtime>, IntTy,
852+
/*nullable*/ true, int32_t>;
853+
854+
template<typename Runtime> struct TargetMethodDescriptor;
855+
856+
template<typename Runtime>
857+
using TargetRelativeMethodDescriptorPointer =
858+
RelativeIndirectablePointer<const TargetMethodDescriptor<Runtime>,
859+
/*nullable*/ true>;
860+
861+
using RelativeMethodDescriptorPointer =
862+
TargetRelativeMethodDescriptorPointer<InProcess>;
863+
839864
/// An entry in the method override table, referencing a method from one of our
840865
/// ancestor classes, together with an implementation.
841866
template <typename Runtime>
842867
struct TargetMethodOverrideDescriptor {
843868
/// The class containing the base method.
844-
TargetRelativeIndirectablePointer<Runtime, TargetClassDescriptor<Runtime>,
845-
/*nullable*/ true> Class;
869+
TargetRelativeContextPointer<Runtime> Class;
846870

847871
/// The base method.
848-
TargetRelativeIndirectablePointer<Runtime, TargetMethodDescriptor<Runtime>,
849-
/*nullable*/ true> Method;
872+
TargetRelativeMethodDescriptorPointer<Runtime> Method;
850873

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

21922215
using TypeMetadataRecord = TargetTypeMetadataRecord<InProcess>;
21932216

2194-
template<typename Runtime> struct TargetContextDescriptor;
2195-
2196-
template<typename Runtime>
2197-
using RelativeContextPointer =
2198-
RelativeIndirectablePointer<const TargetContextDescriptor<Runtime>,
2199-
/*nullable*/ true>;
2200-
22012217
/// The structure of a protocol reference record.
22022218
template <typename Runtime>
22032219
struct TargetProtocolRecord {
22042220
/// The protocol referenced.
22052221
///
22062222
/// The remaining low bit is reserved for future use.
2207-
RelativeIndirectablePointerIntPair<TargetProtocolDescriptor<Runtime>,
2208-
/*reserved=*/bool>
2223+
RelativeContextPointerIntPair<Runtime, /*reserved=*/bool,
2224+
TargetProtocolDescriptor>
22092225
Protocol;
22102226
};
22112227
using ProtocolRecord = TargetProtocolRecord<InProcess>;
@@ -2333,15 +2349,15 @@ template <typename Runtime>
23332349
struct TargetProtocolConformanceDescriptor final
23342350
: public swift::ABI::TrailingObjects<
23352351
TargetProtocolConformanceDescriptor<Runtime>,
2336-
RelativeContextPointer<Runtime>,
2352+
TargetRelativeContextPointer<Runtime>,
23372353
TargetGenericRequirementDescriptor<Runtime>,
23382354
TargetResilientWitnessesHeader<Runtime>,
23392355
TargetResilientWitness<Runtime>,
23402356
TargetGenericWitnessTable<Runtime>> {
23412357

23422358
using TrailingObjects = swift::ABI::TrailingObjects<
23432359
TargetProtocolConformanceDescriptor<Runtime>,
2344-
RelativeContextPointer<Runtime>,
2360+
TargetRelativeContextPointer<Runtime>,
23452361
TargetGenericRequirementDescriptor<Runtime>,
23462362
TargetResilientWitnessesHeader<Runtime>,
23472363
TargetResilientWitness<Runtime>,
@@ -2408,7 +2424,8 @@ struct TargetProtocolConformanceDescriptor final
24082424
const TargetContextDescriptor<Runtime> *getRetroactiveContext() const {
24092425
if (!Flags.isRetroactive()) return nullptr;
24102426

2411-
return this->template getTrailingObjects<RelativeContextPointer<Runtime>>();
2427+
return this->template getTrailingObjects<
2428+
TargetRelativeContextPointer<Runtime>>();
24122429
}
24132430

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

24822499
private:
24832500
size_t numTrailingObjects(
2484-
OverloadToken<RelativeContextPointer<Runtime>>) const {
2501+
OverloadToken<TargetRelativeContextPointer<Runtime>>) const {
24852502
return Flags.isRetroactive() ? 1 : 0;
24862503
}
24872504

@@ -2527,7 +2544,7 @@ struct TargetContextDescriptor {
25272544
ContextDescriptorFlags Flags;
25282545

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

25322549
bool isGeneric() const { return Flags.isGeneric(); }
25332550
bool isUnique() const { return Flags.isUnique(); }

stdlib/public/runtime/Metadata.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2372,7 +2372,7 @@ static void initClassVTable(ClassMetadata *self) {
23722372
auto &descriptor = overrideDescriptors[i];
23732373

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

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

0 commit comments

Comments
 (0)