@@ -287,8 +287,17 @@ class alignas(8) Expr {
287
287
288
288
SWIFT_INLINE_BITFIELD_EMPTY (ImplicitConversionExpr, Expr);
289
289
290
- SWIFT_INLINE_BITFIELD (TupleShuffleExpr, ImplicitConversionExpr, 2 ,
291
- TypeImpact : 2
290
+ SWIFT_INLINE_BITFIELD_FULL (TupleShuffleExpr, ImplicitConversionExpr, 2 +16 +16 +16 ,
291
+ TypeImpact : 2 ,
292
+ : NumPadBits,
293
+ NumCallerDefaultArgs : 16 ,
294
+ // / This contains an entry for each element in the Expr type. Each element
295
+ // / specifies which index from the SubExpr that the destination element gets.
296
+ // / If the element value is DefaultInitialize, then the destination value
297
+ // / gets the default initializer for that tuple element value.
298
+ NumElementMappings : 16 ,
299
+ // / The arguments that are packed into the variadic element.
300
+ NumVariadicArgs : 16
292
301
);
293
302
294
303
SWIFT_INLINE_BITFIELD (InOutToPointerExpr, ImplicitConversionExpr, 1 ,
@@ -2842,7 +2851,20 @@ class UnevaluatedInstanceExpr : public ImplicitConversionExpr {
2842
2851
// / If hasScalarSource() is true, the subexpression should be treated
2843
2852
// / as if it were implicitly injected into a single-element tuple
2844
2853
// / type. Otherwise, the subexpression is known to have a tuple type.
2845
- class TupleShuffleExpr : public ImplicitConversionExpr {
2854
+ class TupleShuffleExpr final : public ImplicitConversionExpr,
2855
+ private llvm::TrailingObjects<TupleShuffleExpr, Expr *, int , unsigned > {
2856
+ friend TrailingObjects;
2857
+
2858
+ size_t numTrailingObjects (OverloadToken<Expr *>) const {
2859
+ return Bits.TupleShuffleExpr .NumCallerDefaultArgs ;
2860
+ }
2861
+ size_t numTrailingObjects (OverloadToken<int >) const {
2862
+ return Bits.TupleShuffleExpr .NumElementMappings ;
2863
+ }
2864
+ size_t numTrailingObjects (OverloadToken<unsigned >) const {
2865
+ return Bits.TupleShuffleExpr .NumVariadicArgs ;
2866
+ }
2867
+
2846
2868
public:
2847
2869
enum : int {
2848
2870
// / The element mapping value indicating that a field of the destination
@@ -2877,41 +2899,48 @@ class TupleShuffleExpr : public ImplicitConversionExpr {
2877
2899
};
2878
2900
2879
2901
private:
2880
- // / This contains an entry for each element in the Expr type. Each element
2881
- // / specifies which index from the SubExpr that the destination element gets.
2882
- // / If the element value is DefaultInitialize, then the destination value
2883
- // / gets the default initializer for that tuple element value.
2884
- ArrayRef<int > ElementMapping;
2885
-
2886
2902
// / If we're doing a varargs shuffle, this is the array type to build.
2887
2903
Type VarargsArrayTy;
2888
2904
2889
2905
// / If there are any default arguments, the owning function
2890
2906
// / declaration.
2891
2907
ConcreteDeclRef DefaultArgsOwner;
2892
2908
2893
- // / The arguments that are packed into the variadic element.
2894
- ArrayRef<unsigned > VariadicArgs;
2895
-
2896
- MutableArrayRef<Expr *> CallerDefaultArgs;
2897
-
2898
- public:
2899
- TupleShuffleExpr (Expr *subExpr, ArrayRef<int > elementMapping,
2909
+ TupleShuffleExpr (Expr *subExpr, ArrayRef<int > elementMapping,
2900
2910
TypeImpact typeImpact,
2901
2911
ConcreteDeclRef defaultArgsOwner,
2902
2912
ArrayRef<unsigned > VariadicArgs,
2903
2913
Type VarargsArrayTy,
2904
- MutableArrayRef <Expr *> CallerDefaultArgs,
2914
+ ArrayRef <Expr *> CallerDefaultArgs,
2905
2915
Type ty)
2906
2916
: ImplicitConversionExpr(ExprKind::TupleShuffle, subExpr, ty),
2907
- ElementMapping (elementMapping), VarargsArrayTy(VarargsArrayTy),
2908
- DefaultArgsOwner(defaultArgsOwner), VariadicArgs(VariadicArgs),
2909
- CallerDefaultArgs(CallerDefaultArgs)
2910
- {
2917
+ VarargsArrayTy (VarargsArrayTy), DefaultArgsOwner(defaultArgsOwner) {
2911
2918
Bits.TupleShuffleExpr .TypeImpact = typeImpact;
2919
+ Bits.TupleShuffleExpr .NumCallerDefaultArgs = CallerDefaultArgs.size ();
2920
+ Bits.TupleShuffleExpr .NumElementMappings = elementMapping.size ();
2921
+ Bits.TupleShuffleExpr .NumVariadicArgs = VariadicArgs.size ();
2922
+ std::uninitialized_copy (CallerDefaultArgs.begin (), CallerDefaultArgs.end (),
2923
+ getTrailingObjects<Expr*>());
2924
+ std::uninitialized_copy (elementMapping.begin (), elementMapping.end (),
2925
+ getTrailingObjects<int >());
2926
+ std::uninitialized_copy (VariadicArgs.begin (), VariadicArgs.end (),
2927
+ getTrailingObjects<unsigned >());
2912
2928
}
2913
2929
2914
- ArrayRef<int > getElementMapping () const { return ElementMapping; }
2930
+ public:
2931
+ static TupleShuffleExpr *create (ASTContext &ctx, Expr *subExpr,
2932
+ ArrayRef<int > elementMapping,
2933
+ TypeImpact typeImpact,
2934
+ ConcreteDeclRef defaultArgsOwner,
2935
+ ArrayRef<unsigned > VariadicArgs,
2936
+ Type VarargsArrayTy,
2937
+ ArrayRef<Expr *> CallerDefaultArgs,
2938
+ Type ty);
2939
+
2940
+ ArrayRef<int > getElementMapping () const {
2941
+ return {getTrailingObjects<int >(),
2942
+ Bits.TupleShuffleExpr .NumElementMappings };
2943
+ }
2915
2944
2916
2945
// / What is the type impact of this shuffle?
2917
2946
TypeImpact getTypeImpact () const {
@@ -2935,16 +2964,25 @@ class TupleShuffleExpr : public ImplicitConversionExpr {
2935
2964
}
2936
2965
2937
2966
// / Retrieve the argument indices for the variadic arguments.
2938
- ArrayRef<unsigned > getVariadicArgs () const { return VariadicArgs; }
2967
+ ArrayRef<unsigned > getVariadicArgs () const {
2968
+ return {getTrailingObjects<unsigned >(),
2969
+ Bits.TupleShuffleExpr .NumVariadicArgs };
2970
+ }
2939
2971
2940
2972
// / Retrieve the owner of the default arguments.
2941
2973
ConcreteDeclRef getDefaultArgsOwner () const { return DefaultArgsOwner; }
2942
2974
2943
2975
// / Retrieve the caller-defaulted arguments.
2944
- ArrayRef<Expr *> getCallerDefaultArgs () const { return CallerDefaultArgs; }
2976
+ ArrayRef<Expr *> getCallerDefaultArgs () const {
2977
+ return {getTrailingObjects<Expr*>(),
2978
+ Bits.TupleShuffleExpr .NumCallerDefaultArgs };
2979
+ }
2945
2980
2946
2981
// / Retrieve the caller-defaulted arguments.
2947
- MutableArrayRef<Expr *> getCallerDefaultArgs () { return CallerDefaultArgs; }
2982
+ MutableArrayRef<Expr *> getCallerDefaultArgs () {
2983
+ return {getTrailingObjects<Expr*>(),
2984
+ Bits.TupleShuffleExpr .NumCallerDefaultArgs };
2985
+ }
2948
2986
2949
2987
static bool classof (const Expr *E) {
2950
2988
return E->getKind () == ExprKind::TupleShuffle;
0 commit comments