Skip to content

Commit e9e71f8

Browse files
committed
Target-ize more of the generic-context-header declarations; NFC.
1 parent f2bb319 commit e9e71f8

File tree

1 file changed

+51
-33
lines changed

1 file changed

+51
-33
lines changed

include/swift/Runtime/Metadata.h

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,17 +2581,20 @@ struct TargetModuleContextDescriptor final : TargetContextDescriptor<Runtime> {
25812581

25822582
using ModuleContextDescriptor = TargetModuleContextDescriptor<InProcess>;
25832583

2584-
struct GenericContextDescriptorHeader {
2585-
unsigned NumParams, NumRequirements, NumKeyArguments, NumExtraArguments;
2584+
template<typename Runtime>
2585+
struct TargetGenericContextDescriptorHeader {
2586+
uint32_t NumParams, NumRequirements, NumKeyArguments, NumExtraArguments;
25862587

2587-
unsigned getNumArguments() const {
2588+
uint32_t getNumArguments() const {
25882589
return NumKeyArguments + NumExtraArguments;
25892590
}
2590-
2591+
25912592
bool hasArguments() const {
25922593
return getNumArguments() > 0;
25932594
}
25942595
};
2596+
using GenericContextDescriptorHeader =
2597+
TargetGenericContextDescriptorHeader<InProcess>;
25952598

25962599
/// A reference to a generic parameter that is the subject of a requirement.
25972600
/// This can refer either directly to a generic parameter or to a path to an
@@ -2812,32 +2815,36 @@ using GenericRequirementDescriptor =
28122815

28132816
/// CRTP class for a context descriptor that includes trailing generic
28142817
/// context description.
2815-
template<typename Self,
2816-
typename HeaderType = GenericContextDescriptorHeader,
2817-
typename...FollowingTrailingObjects>
2818+
template<class Self,
2819+
template <typename> class TargetGenericContextHeaderType =
2820+
TargetGenericContextDescriptorHeader,
2821+
typename... FollowingTrailingObjects>
28182822
class TrailingGenericContextObjects;
28192823

2820-
template<template<typename> class TargetSelf,
2821-
typename Runtime,
2822-
typename HeaderType,
2823-
typename...FollowingTrailingObjects>
2824-
class TrailingGenericContextObjects<
2825-
TargetSelf<Runtime>,
2826-
HeaderType,
2827-
FollowingTrailingObjects...
2828-
> : protected swift::ABI::TrailingObjects<TargetSelf<Runtime>,
2829-
HeaderType,
2824+
// This oddity with partial specialization is necessary to get
2825+
// reasonable-looking code while also working around various kinds of
2826+
// compiler bad behavior with injected class names.
2827+
template<class Runtime,
2828+
template <typename> class TargetSelf,
2829+
template <typename> class TargetGenericContextHeaderType,
2830+
typename... FollowingTrailingObjects>
2831+
class TrailingGenericContextObjects<TargetSelf<Runtime>,
2832+
TargetGenericContextHeaderType,
2833+
FollowingTrailingObjects...> :
2834+
protected swift::ABI::TrailingObjects<TargetSelf<Runtime>,
2835+
TargetGenericContextHeaderType<Runtime>,
28302836
GenericParamDescriptor,
28312837
TargetGenericRequirementDescriptor<Runtime>,
28322838
FollowingTrailingObjects...>
28332839
{
28342840
protected:
28352841
using Self = TargetSelf<Runtime>;
2842+
using GenericContextHeaderType = TargetGenericContextHeaderType<Runtime>;
28362843
using GenericRequirementDescriptor =
28372844
TargetGenericRequirementDescriptor<Runtime>;
28382845

28392846
using TrailingObjects = swift::ABI::TrailingObjects<Self,
2840-
HeaderType,
2847+
GenericContextHeaderType,
28412848
GenericParamDescriptor,
28422849
GenericRequirementDescriptor,
28432850
FollowingTrailingObjects...>;
@@ -2850,12 +2857,16 @@ class TrailingGenericContextObjects<
28502857
return static_cast<const Self *>(this);
28512858
}
28522859
public:
2853-
const HeaderType &getFullGenericContextHeader() const {
2860+
using StoredSize = typename Runtime::StoredSize;
2861+
using StoredPointer = typename Runtime::StoredPointer;
2862+
2863+
const GenericContextHeaderType &getFullGenericContextHeader() const {
28542864
assert(asSelf()->isGeneric());
2855-
return *this->template getTrailingObjects<HeaderType>();
2865+
return *this->template getTrailingObjects<GenericContextHeaderType>();
28562866
}
28572867

2858-
const GenericContextDescriptorHeader &getGenericContextHeader() const {
2868+
const TargetGenericContextDescriptorHeader<Runtime> &
2869+
getGenericContextHeader() const {
28592870
/// HeaderType ought to be convertible to GenericContextDescriptorHeader.
28602871
return getFullGenericContextHeader();
28612872
}
@@ -2885,8 +2896,13 @@ class TrailingGenericContextObjects<
28852896
getGenericContextHeader().NumRequirements};
28862897
}
28872898

2899+
StoredSize getGenericArgumentsStorageSize() const {
2900+
return StoredSize(getGenericContextHeader().getNumArguments())
2901+
* sizeof(StoredPointer);
2902+
}
2903+
28882904
protected:
2889-
size_t numTrailingObjects(OverloadToken<HeaderType>) const {
2905+
size_t numTrailingObjects(OverloadToken<GenericContextHeaderType>) const {
28902906
return asSelf()->isGeneric() ? 1 : 0;
28912907
}
28922908

@@ -2902,7 +2918,8 @@ class TrailingGenericContextObjects<
29022918
/// Reference to a generic context.
29032919
template<typename Runtime>
29042920
struct TargetGenericContext final
2905-
: TrailingGenericContextObjects<TargetGenericContext<Runtime>>
2921+
: TrailingGenericContextObjects<TargetGenericContext<Runtime>,
2922+
TargetGenericContextDescriptorHeader>
29062923
{
29072924
// This struct is supposed to be empty, but TrailingObjects respects the
29082925
// unique-address-per-object C++ rule, so even if this type is empty, the
@@ -2921,7 +2938,7 @@ struct TargetExtensionContextDescriptor final
29212938
{
29222939
private:
29232940
using TrailingGenericContextObjects
2924-
= TrailingGenericContextObjects<TargetExtensionContextDescriptor>;
2941+
= TrailingGenericContextObjects<TargetExtensionContextDescriptor<Runtime>>;
29252942

29262943
/// A mangling of the `Self` type context that the extension extends.
29272944
/// The mangled name represents the type in the generic context encoded by
@@ -2991,9 +3008,9 @@ struct TargetTypeGenericContextDescriptorHeader {
29913008
}
29923009

29933010
/// The base header. Must always be the final member.
2994-
GenericContextDescriptorHeader Base;
3011+
TargetGenericContextDescriptorHeader<Runtime> Base;
29953012

2996-
operator const GenericContextDescriptorHeader &() const {
3013+
operator const TargetGenericContextDescriptorHeader<Runtime> &() const {
29973014
return Base;
29983015
}
29993016
};
@@ -3124,7 +3141,8 @@ class TargetTypeContextDescriptor
31243141
const TargetTypeGenericContextDescriptorHeader<Runtime> &
31253142
getFullGenericContextHeader() const;
31263143

3127-
const GenericContextDescriptorHeader &getGenericContextHeader() const {
3144+
const TargetGenericContextDescriptorHeader<Runtime> &
3145+
getGenericContextHeader() const {
31283146
return getFullGenericContextHeader();
31293147
}
31303148

@@ -3155,14 +3173,14 @@ template <typename Runtime>
31553173
class TargetClassDescriptor final
31563174
: public TargetTypeContextDescriptor<Runtime>,
31573175
public TrailingGenericContextObjects<TargetClassDescriptor<Runtime>,
3158-
TargetTypeGenericContextDescriptorHeader<Runtime>,
3176+
TargetTypeGenericContextDescriptorHeader,
31593177
/*additional trailing objects:*/
31603178
TargetVTableDescriptorHeader<Runtime>,
31613179
TargetMethodDescriptor<Runtime>> {
31623180
private:
31633181
using TrailingGenericContextObjects =
31643182
TrailingGenericContextObjects<TargetClassDescriptor<Runtime>,
3165-
TargetTypeGenericContextDescriptorHeader<Runtime>,
3183+
TargetTypeGenericContextDescriptorHeader,
31663184
TargetVTableDescriptorHeader<Runtime>,
31673185
TargetMethodDescriptor<Runtime>>;
31683186

@@ -3334,11 +3352,11 @@ template <typename Runtime>
33343352
class TargetStructDescriptor final
33353353
: public TargetValueTypeDescriptor<Runtime>,
33363354
public TrailingGenericContextObjects<TargetStructDescriptor<Runtime>,
3337-
TargetTypeGenericContextDescriptorHeader<Runtime>> {
3355+
TargetTypeGenericContextDescriptorHeader> {
33383356
private:
33393357
using TrailingGenericContextObjects =
33403358
TrailingGenericContextObjects<TargetStructDescriptor<Runtime>,
3341-
TargetTypeGenericContextDescriptorHeader<Runtime>>;
3359+
TargetTypeGenericContextDescriptorHeader>;
33423360

33433361
using TrailingObjects =
33443362
typename TrailingGenericContextObjects::TrailingObjects;
@@ -3376,11 +3394,11 @@ template <typename Runtime>
33763394
class TargetEnumDescriptor final
33773395
: public TargetValueTypeDescriptor<Runtime>,
33783396
public TrailingGenericContextObjects<TargetEnumDescriptor<Runtime>,
3379-
TargetTypeGenericContextDescriptorHeader<Runtime>> {
3397+
TargetTypeGenericContextDescriptorHeader> {
33803398
private:
33813399
using TrailingGenericContextObjects =
33823400
TrailingGenericContextObjects<TargetEnumDescriptor<Runtime>,
3383-
TargetTypeGenericContextDescriptorHeader<Runtime>>;
3401+
TargetTypeGenericContextDescriptorHeader>;
33843402

33853403
using TrailingObjects =
33863404
typename TrailingGenericContextObjects::TrailingObjects;

0 commit comments

Comments
 (0)