@@ -290,7 +290,13 @@ class alignas(8) Expr {
290
290
291
291
SWIFT_INLINE_BITFIELD_EMPTY (ImplicitConversionExpr, Expr);
292
292
293
- SWIFT_INLINE_BITFIELD_FULL (TupleShuffleExpr, ImplicitConversionExpr, 2 +16 +16 +16 ,
293
+ SWIFT_INLINE_BITFIELD_FULL (TupleShuffleExpr, ImplicitConversionExpr, 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
+ NumElementMappings : 16
297
+ );
298
+
299
+ SWIFT_INLINE_BITFIELD_FULL (ArgumentShuffleExpr, ImplicitConversionExpr, 2 +16 +16 +16 ,
294
300
TypeImpact : 2 ,
295
301
: NumPadBits,
296
302
NumCallerDefaultArgs : 16 ,
@@ -2956,22 +2962,56 @@ class UnevaluatedInstanceExpr : public ImplicitConversionExpr {
2956
2962
2957
2963
// / TupleShuffleExpr - This represents a permutation of a tuple value to a new
2958
2964
// / tuple type.
2965
+ class TupleShuffleExpr final : public ImplicitConversionExpr,
2966
+ private llvm::TrailingObjects<TupleShuffleExpr, unsigned > {
2967
+ friend TrailingObjects;
2968
+
2969
+ size_t numTrailingObjects (OverloadToken<unsigned >) const {
2970
+ return Bits.TupleShuffleExpr .NumElementMappings ;
2971
+ }
2972
+
2973
+ private:
2974
+ TupleShuffleExpr (Expr *subExpr, ArrayRef<unsigned > elementMapping,
2975
+ Type ty)
2976
+ : ImplicitConversionExpr(ExprKind::TupleShuffle, subExpr, ty) {
2977
+ Bits.TupleShuffleExpr .NumElementMappings = elementMapping.size ();
2978
+ std::uninitialized_copy (elementMapping.begin (), elementMapping.end (),
2979
+ getTrailingObjects<unsigned >());
2980
+ }
2981
+
2982
+ public:
2983
+ static TupleShuffleExpr *create (ASTContext &ctx, Expr *subExpr,
2984
+ ArrayRef<unsigned > elementMapping,
2985
+ Type ty);
2986
+
2987
+ ArrayRef<unsigned > getElementMapping () const {
2988
+ return {getTrailingObjects<unsigned >(),
2989
+ static_cast <size_t >(Bits.TupleShuffleExpr .NumElementMappings )};
2990
+ }
2991
+
2992
+ static bool classof (const Expr *E) {
2993
+ return E->getKind () == ExprKind::TupleShuffle;
2994
+ }
2995
+ };
2996
+
2997
+ // / ArgumentShuffleExpr - This represents a "complex" argument list of an
2998
+ // / ApplyExpr, with default arguments or varargs.
2959
2999
// /
2960
3000
// / If hasScalarSource() is true, the subexpression should be treated
2961
3001
// / as if it were implicitly injected into a single-element tuple
2962
3002
// / type. Otherwise, the subexpression is known to have a tuple type.
2963
- class TupleShuffleExpr final : public ImplicitConversionExpr,
2964
- private llvm::TrailingObjects<TupleShuffleExpr , Expr *, int , unsigned > {
3003
+ class ArgumentShuffleExpr final : public ImplicitConversionExpr,
3004
+ private llvm::TrailingObjects<ArgumentShuffleExpr , Expr *, int , unsigned > {
2965
3005
friend TrailingObjects;
2966
3006
2967
3007
size_t numTrailingObjects (OverloadToken<Expr *>) const {
2968
- return Bits.TupleShuffleExpr .NumCallerDefaultArgs ;
3008
+ return Bits.ArgumentShuffleExpr .NumCallerDefaultArgs ;
2969
3009
}
2970
3010
size_t numTrailingObjects (OverloadToken<int >) const {
2971
- return Bits.TupleShuffleExpr .NumElementMappings ;
3011
+ return Bits.ArgumentShuffleExpr .NumElementMappings ;
2972
3012
}
2973
3013
size_t numTrailingObjects (OverloadToken<unsigned >) const {
2974
- return Bits.TupleShuffleExpr .NumVariadicArgs ;
3014
+ return Bits.ArgumentShuffleExpr .NumVariadicArgs ;
2975
3015
}
2976
3016
2977
3017
public:
@@ -2984,27 +3024,34 @@ class TupleShuffleExpr final : public ImplicitConversionExpr,
2984
3024
// / The element mapping value indicating that the field of the
2985
3025
// / destination tuple should be default-initialized with an expression
2986
3026
// / provided by the caller.
2987
- // / FIXME: Yet another indication that TupleShuffleExpr uses the wrong
3027
+ // / FIXME: Yet another indication that ArgumentShuffleExpr uses the wrong
2988
3028
// / formulation.
2989
3029
CallerDefaultInitialize = -3
2990
3030
};
2991
3031
2992
3032
enum TypeImpact {
2993
3033
// / The source value is a tuple which is destructured and modified to
2994
3034
// / create the result, which is a tuple.
3035
+ // /
3036
+ // / Example: (x: Int) => (x: Int, y: Int = 0).
2995
3037
TupleToTuple,
2996
3038
2997
3039
// / The source value is a tuple which is destructured and modified to
2998
3040
// / create the result, which is a scalar because it has one element and
2999
3041
// / no labels.
3042
+ // /
3043
+ // / Example: () -> (_: Int = 0)
3044
+ // / Another example: (Int, Int) => (_: Int...)
3000
3045
TupleToScalar,
3001
3046
3002
3047
// / The source value is an individual value (possibly one with tuple
3003
3048
// / type) which is inserted into a particular position in the result,
3004
3049
// / which is a tuple.
3050
+ // /
3051
+ // / Example: (Int) -> (_: Int, y: Int = 0)
3005
3052
ScalarToTuple
3006
3053
3007
- // (TupleShuffleExprs are never created for a scalar-to-scalar conversion.)
3054
+ // (ArgumentShuffleExpr are never created for a scalar-to-scalar conversion.)
3008
3055
};
3009
3056
3010
3057
private:
@@ -3015,19 +3062,19 @@ class TupleShuffleExpr final : public ImplicitConversionExpr,
3015
3062
// / declaration.
3016
3063
ConcreteDeclRef DefaultArgsOwner;
3017
3064
3018
- TupleShuffleExpr (Expr *subExpr, ArrayRef<int > elementMapping,
3019
- TypeImpact typeImpact,
3020
- ConcreteDeclRef defaultArgsOwner,
3021
- ArrayRef<unsigned > VariadicArgs,
3022
- Type VarargsArrayTy,
3023
- ArrayRef<Expr *> CallerDefaultArgs,
3024
- Type ty)
3025
- : ImplicitConversionExpr(ExprKind::TupleShuffle , subExpr, ty),
3065
+ ArgumentShuffleExpr (Expr *subExpr, ArrayRef<int > elementMapping,
3066
+ TypeImpact typeImpact,
3067
+ ConcreteDeclRef defaultArgsOwner,
3068
+ ArrayRef<unsigned > VariadicArgs,
3069
+ Type VarargsArrayTy,
3070
+ ArrayRef<Expr *> CallerDefaultArgs,
3071
+ Type ty)
3072
+ : ImplicitConversionExpr(ExprKind::ArgumentShuffle , subExpr, ty),
3026
3073
VarargsArrayTy (VarargsArrayTy), DefaultArgsOwner(defaultArgsOwner) {
3027
- Bits.TupleShuffleExpr .TypeImpact = typeImpact;
3028
- Bits.TupleShuffleExpr .NumCallerDefaultArgs = CallerDefaultArgs.size ();
3029
- Bits.TupleShuffleExpr .NumElementMappings = elementMapping.size ();
3030
- Bits.TupleShuffleExpr .NumVariadicArgs = VariadicArgs.size ();
3074
+ Bits.ArgumentShuffleExpr .TypeImpact = typeImpact;
3075
+ Bits.ArgumentShuffleExpr .NumCallerDefaultArgs = CallerDefaultArgs.size ();
3076
+ Bits.ArgumentShuffleExpr .NumElementMappings = elementMapping.size ();
3077
+ Bits.ArgumentShuffleExpr .NumVariadicArgs = VariadicArgs.size ();
3031
3078
std::uninitialized_copy (CallerDefaultArgs.begin (), CallerDefaultArgs.end (),
3032
3079
getTrailingObjects<Expr*>());
3033
3080
std::uninitialized_copy (elementMapping.begin (), elementMapping.end (),
@@ -3037,23 +3084,23 @@ class TupleShuffleExpr final : public ImplicitConversionExpr,
3037
3084
}
3038
3085
3039
3086
public:
3040
- static TupleShuffleExpr *create (ASTContext &ctx, Expr *subExpr,
3041
- ArrayRef<int > elementMapping,
3042
- TypeImpact typeImpact,
3043
- ConcreteDeclRef defaultArgsOwner,
3044
- ArrayRef<unsigned > VariadicArgs,
3045
- Type VarargsArrayTy,
3046
- ArrayRef<Expr *> CallerDefaultArgs,
3047
- Type ty);
3087
+ static ArgumentShuffleExpr *create (ASTContext &ctx, Expr *subExpr,
3088
+ ArrayRef<int > elementMapping,
3089
+ TypeImpact typeImpact,
3090
+ ConcreteDeclRef defaultArgsOwner,
3091
+ ArrayRef<unsigned > VariadicArgs,
3092
+ Type VarargsArrayTy,
3093
+ ArrayRef<Expr *> CallerDefaultArgs,
3094
+ Type ty);
3048
3095
3049
3096
ArrayRef<int > getElementMapping () const {
3050
3097
return {getTrailingObjects<int >(),
3051
- static_cast <size_t >(Bits.TupleShuffleExpr .NumElementMappings )};
3098
+ static_cast <size_t >(Bits.ArgumentShuffleExpr .NumElementMappings )};
3052
3099
}
3053
3100
3054
3101
// / What is the type impact of this shuffle?
3055
3102
TypeImpact getTypeImpact () const {
3056
- return TypeImpact (Bits.TupleShuffleExpr .TypeImpact );
3103
+ return TypeImpact (Bits.ArgumentShuffleExpr .TypeImpact );
3057
3104
}
3058
3105
3059
3106
bool isSourceScalar () const {
@@ -3075,7 +3122,7 @@ class TupleShuffleExpr final : public ImplicitConversionExpr,
3075
3122
// / Retrieve the argument indices for the variadic arguments.
3076
3123
ArrayRef<unsigned > getVariadicArgs () const {
3077
3124
return {getTrailingObjects<unsigned >(),
3078
- static_cast <size_t >(Bits.TupleShuffleExpr .NumVariadicArgs )};
3125
+ static_cast <size_t >(Bits.ArgumentShuffleExpr .NumVariadicArgs )};
3079
3126
}
3080
3127
3081
3128
// / Retrieve the owner of the default arguments.
@@ -3084,17 +3131,17 @@ class TupleShuffleExpr final : public ImplicitConversionExpr,
3084
3131
// / Retrieve the caller-defaulted arguments.
3085
3132
ArrayRef<Expr *> getCallerDefaultArgs () const {
3086
3133
return {getTrailingObjects<Expr*>(),
3087
- static_cast <size_t >(Bits.TupleShuffleExpr .NumCallerDefaultArgs )};
3134
+ static_cast <size_t >(Bits.ArgumentShuffleExpr .NumCallerDefaultArgs )};
3088
3135
}
3089
3136
3090
3137
// / Retrieve the caller-defaulted arguments.
3091
3138
MutableArrayRef<Expr *> getCallerDefaultArgs () {
3092
3139
return {getTrailingObjects<Expr*>(),
3093
- static_cast <size_t >(Bits.TupleShuffleExpr .NumCallerDefaultArgs )};
3140
+ static_cast <size_t >(Bits.ArgumentShuffleExpr .NumCallerDefaultArgs )};
3094
3141
}
3095
3142
3096
3143
static bool classof (const Expr *E) {
3097
- return E->getKind () == ExprKind::TupleShuffle ;
3144
+ return E->getKind () == ExprKind::ArgumentShuffle ;
3098
3145
}
3099
3146
};
3100
3147
@@ -3975,7 +4022,7 @@ class ApplyExpr : public Expr {
3975
4022
3976
4023
// / Returns true if \c e could be used as the call's argument. For most \c ApplyExpr
3977
4024
// / subclasses, this means it is a \c ParenExpr, \c TupleExpr, or
3978
- // / \c TupleShuffleExpr .
4025
+ // / \c ArgumentShuffleExpr .
3979
4026
bool validateArg (Expr *e) const ;
3980
4027
3981
4028
protected:
@@ -5355,7 +5402,7 @@ inline bool ApplyExpr::validateArg(Expr *e) const {
5355
5402
else if (isa<BinaryExpr>(this ))
5356
5403
return isa<TupleExpr>(e);
5357
5404
else
5358
- return isa<ParenExpr>(e) || isa<TupleExpr>(e) || isa<TupleShuffleExpr >(e);
5405
+ return isa<ParenExpr>(e) || isa<TupleExpr>(e) || isa<ArgumentShuffleExpr >(e);
5359
5406
}
5360
5407
5361
5408
inline Expr *const *CollectionExpr::getTrailingObjectsPointer () const {
0 commit comments