@@ -2581,17 +2581,20 @@ struct TargetModuleContextDescriptor final : TargetContextDescriptor<Runtime> {
2581
2581
2582
2582
using ModuleContextDescriptor = TargetModuleContextDescriptor<InProcess>;
2583
2583
2584
- struct GenericContextDescriptorHeader {
2585
- unsigned NumParams, NumRequirements, NumKeyArguments, NumExtraArguments;
2584
+ template <typename Runtime>
2585
+ struct TargetGenericContextDescriptorHeader {
2586
+ uint32_t NumParams, NumRequirements, NumKeyArguments, NumExtraArguments;
2586
2587
2587
- unsigned getNumArguments () const {
2588
+ uint32_t getNumArguments () const {
2588
2589
return NumKeyArguments + NumExtraArguments;
2589
2590
}
2590
-
2591
+
2591
2592
bool hasArguments () const {
2592
2593
return getNumArguments () > 0 ;
2593
2594
}
2594
2595
};
2596
+ using GenericContextDescriptorHeader =
2597
+ TargetGenericContextDescriptorHeader<InProcess>;
2595
2598
2596
2599
// / A reference to a generic parameter that is the subject of a requirement.
2597
2600
// / This can refer either directly to a generic parameter or to a path to an
@@ -2812,32 +2815,36 @@ using GenericRequirementDescriptor =
2812
2815
2813
2816
// / CRTP class for a context descriptor that includes trailing generic
2814
2817
// / 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>
2818
2822
class TrailingGenericContextObjects ;
2819
2823
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>,
2830
2836
GenericParamDescriptor,
2831
2837
TargetGenericRequirementDescriptor<Runtime>,
2832
2838
FollowingTrailingObjects...>
2833
2839
{
2834
2840
protected:
2835
2841
using Self = TargetSelf<Runtime>;
2842
+ using GenericContextHeaderType = TargetGenericContextHeaderType<Runtime>;
2836
2843
using GenericRequirementDescriptor =
2837
2844
TargetGenericRequirementDescriptor<Runtime>;
2838
2845
2839
2846
using TrailingObjects = swift::ABI::TrailingObjects<Self,
2840
- HeaderType ,
2847
+ GenericContextHeaderType ,
2841
2848
GenericParamDescriptor,
2842
2849
GenericRequirementDescriptor,
2843
2850
FollowingTrailingObjects...>;
@@ -2850,12 +2857,16 @@ class TrailingGenericContextObjects<
2850
2857
return static_cast <const Self *>(this );
2851
2858
}
2852
2859
public:
2853
- const HeaderType &getFullGenericContextHeader () const {
2860
+ using StoredSize = typename Runtime::StoredSize;
2861
+ using StoredPointer = typename Runtime::StoredPointer;
2862
+
2863
+ const GenericContextHeaderType &getFullGenericContextHeader () const {
2854
2864
assert (asSelf ()->isGeneric ());
2855
- return *this ->template getTrailingObjects <HeaderType >();
2865
+ return *this ->template getTrailingObjects <GenericContextHeaderType >();
2856
2866
}
2857
2867
2858
- const GenericContextDescriptorHeader &getGenericContextHeader () const {
2868
+ const TargetGenericContextDescriptorHeader<Runtime> &
2869
+ getGenericContextHeader () const {
2859
2870
// / HeaderType ought to be convertible to GenericContextDescriptorHeader.
2860
2871
return getFullGenericContextHeader ();
2861
2872
}
@@ -2885,8 +2896,13 @@ class TrailingGenericContextObjects<
2885
2896
getGenericContextHeader ().NumRequirements };
2886
2897
}
2887
2898
2899
+ StoredSize getGenericArgumentsStorageSize () const {
2900
+ return StoredSize (getGenericContextHeader ().getNumArguments ())
2901
+ * sizeof (StoredPointer);
2902
+ }
2903
+
2888
2904
protected:
2889
- size_t numTrailingObjects (OverloadToken<HeaderType >) const {
2905
+ size_t numTrailingObjects (OverloadToken<GenericContextHeaderType >) const {
2890
2906
return asSelf ()->isGeneric () ? 1 : 0 ;
2891
2907
}
2892
2908
@@ -2902,7 +2918,8 @@ class TrailingGenericContextObjects<
2902
2918
// / Reference to a generic context.
2903
2919
template <typename Runtime>
2904
2920
struct TargetGenericContext final
2905
- : TrailingGenericContextObjects<TargetGenericContext<Runtime>>
2921
+ : TrailingGenericContextObjects<TargetGenericContext<Runtime>,
2922
+ TargetGenericContextDescriptorHeader>
2906
2923
{
2907
2924
// This struct is supposed to be empty, but TrailingObjects respects the
2908
2925
// unique-address-per-object C++ rule, so even if this type is empty, the
@@ -2921,7 +2938,7 @@ struct TargetExtensionContextDescriptor final
2921
2938
{
2922
2939
private:
2923
2940
using TrailingGenericContextObjects
2924
- = TrailingGenericContextObjects<TargetExtensionContextDescriptor>;
2941
+ = TrailingGenericContextObjects<TargetExtensionContextDescriptor<Runtime> >;
2925
2942
2926
2943
// / A mangling of the `Self` type context that the extension extends.
2927
2944
// / The mangled name represents the type in the generic context encoded by
@@ -2991,9 +3008,9 @@ struct TargetTypeGenericContextDescriptorHeader {
2991
3008
}
2992
3009
2993
3010
// / The base header. Must always be the final member.
2994
- GenericContextDescriptorHeader Base;
3011
+ TargetGenericContextDescriptorHeader<Runtime> Base;
2995
3012
2996
- operator const GenericContextDescriptorHeader &() const {
3013
+ operator const TargetGenericContextDescriptorHeader<Runtime> &() const {
2997
3014
return Base;
2998
3015
}
2999
3016
};
@@ -3124,7 +3141,8 @@ class TargetTypeContextDescriptor
3124
3141
const TargetTypeGenericContextDescriptorHeader<Runtime> &
3125
3142
getFullGenericContextHeader () const ;
3126
3143
3127
- const GenericContextDescriptorHeader &getGenericContextHeader () const {
3144
+ const TargetGenericContextDescriptorHeader<Runtime> &
3145
+ getGenericContextHeader () const {
3128
3146
return getFullGenericContextHeader ();
3129
3147
}
3130
3148
@@ -3155,14 +3173,14 @@ template <typename Runtime>
3155
3173
class TargetClassDescriptor final
3156
3174
: public TargetTypeContextDescriptor<Runtime>,
3157
3175
public TrailingGenericContextObjects<TargetClassDescriptor<Runtime>,
3158
- TargetTypeGenericContextDescriptorHeader<Runtime> ,
3176
+ TargetTypeGenericContextDescriptorHeader,
3159
3177
/* additional trailing objects:*/
3160
3178
TargetVTableDescriptorHeader<Runtime>,
3161
3179
TargetMethodDescriptor<Runtime>> {
3162
3180
private:
3163
3181
using TrailingGenericContextObjects =
3164
3182
TrailingGenericContextObjects<TargetClassDescriptor<Runtime>,
3165
- TargetTypeGenericContextDescriptorHeader<Runtime> ,
3183
+ TargetTypeGenericContextDescriptorHeader,
3166
3184
TargetVTableDescriptorHeader<Runtime>,
3167
3185
TargetMethodDescriptor<Runtime>>;
3168
3186
@@ -3334,11 +3352,11 @@ template <typename Runtime>
3334
3352
class TargetStructDescriptor final
3335
3353
: public TargetValueTypeDescriptor<Runtime>,
3336
3354
public TrailingGenericContextObjects<TargetStructDescriptor<Runtime>,
3337
- TargetTypeGenericContextDescriptorHeader<Runtime> > {
3355
+ TargetTypeGenericContextDescriptorHeader> {
3338
3356
private:
3339
3357
using TrailingGenericContextObjects =
3340
3358
TrailingGenericContextObjects<TargetStructDescriptor<Runtime>,
3341
- TargetTypeGenericContextDescriptorHeader<Runtime> >;
3359
+ TargetTypeGenericContextDescriptorHeader>;
3342
3360
3343
3361
using TrailingObjects =
3344
3362
typename TrailingGenericContextObjects::TrailingObjects;
@@ -3376,11 +3394,11 @@ template <typename Runtime>
3376
3394
class TargetEnumDescriptor final
3377
3395
: public TargetValueTypeDescriptor<Runtime>,
3378
3396
public TrailingGenericContextObjects<TargetEnumDescriptor<Runtime>,
3379
- TargetTypeGenericContextDescriptorHeader<Runtime> > {
3397
+ TargetTypeGenericContextDescriptorHeader> {
3380
3398
private:
3381
3399
using TrailingGenericContextObjects =
3382
3400
TrailingGenericContextObjects<TargetEnumDescriptor<Runtime>,
3383
- TargetTypeGenericContextDescriptorHeader<Runtime> >;
3401
+ TargetTypeGenericContextDescriptorHeader>;
3384
3402
3385
3403
using TrailingObjects =
3386
3404
typename TrailingGenericContextObjects::TrailingObjects;
0 commit comments