@@ -290,7 +290,13 @@ class alignas(8) Expr {
290290
291291 SWIFT_INLINE_BITFIELD_EMPTY (ImplicitConversionExpr, Expr);
292292
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 ,
294300 TypeImpact : 2 ,
295301 : NumPadBits,
296302 NumCallerDefaultArgs : 16 ,
@@ -2956,22 +2962,56 @@ class UnevaluatedInstanceExpr : public ImplicitConversionExpr {
29562962
29572963// / TupleShuffleExpr - This represents a permutation of a tuple value to a new
29582964// / 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.
29592999// /
29603000// / If hasScalarSource() is true, the subexpression should be treated
29613001// / as if it were implicitly injected into a single-element tuple
29623002// / 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 > {
29653005 friend TrailingObjects;
29663006
29673007 size_t numTrailingObjects (OverloadToken<Expr *>) const {
2968- return Bits.TupleShuffleExpr .NumCallerDefaultArgs ;
3008+ return Bits.ArgumentShuffleExpr .NumCallerDefaultArgs ;
29693009 }
29703010 size_t numTrailingObjects (OverloadToken<int >) const {
2971- return Bits.TupleShuffleExpr .NumElementMappings ;
3011+ return Bits.ArgumentShuffleExpr .NumElementMappings ;
29723012 }
29733013 size_t numTrailingObjects (OverloadToken<unsigned >) const {
2974- return Bits.TupleShuffleExpr .NumVariadicArgs ;
3014+ return Bits.ArgumentShuffleExpr .NumVariadicArgs ;
29753015 }
29763016
29773017public:
@@ -2984,27 +3024,34 @@ class TupleShuffleExpr final : public ImplicitConversionExpr,
29843024 // / The element mapping value indicating that the field of the
29853025 // / destination tuple should be default-initialized with an expression
29863026 // / provided by the caller.
2987- // / FIXME: Yet another indication that TupleShuffleExpr uses the wrong
3027+ // / FIXME: Yet another indication that ArgumentShuffleExpr uses the wrong
29883028 // / formulation.
29893029 CallerDefaultInitialize = -3
29903030 };
29913031
29923032 enum TypeImpact {
29933033 // / The source value is a tuple which is destructured and modified to
29943034 // / create the result, which is a tuple.
3035+ // /
3036+ // / Example: (x: Int) => (x: Int, y: Int = 0).
29953037 TupleToTuple,
29963038
29973039 // / The source value is a tuple which is destructured and modified to
29983040 // / create the result, which is a scalar because it has one element and
29993041 // / no labels.
3042+ // /
3043+ // / Example: () -> (_: Int = 0)
3044+ // / Another example: (Int, Int) => (_: Int...)
30003045 TupleToScalar,
30013046
30023047 // / The source value is an individual value (possibly one with tuple
30033048 // / type) which is inserted into a particular position in the result,
30043049 // / which is a tuple.
3050+ // /
3051+ // / Example: (Int) -> (_: Int, y: Int = 0)
30053052 ScalarToTuple
30063053
3007- // (TupleShuffleExprs are never created for a scalar-to-scalar conversion.)
3054+ // (ArgumentShuffleExpr are never created for a scalar-to-scalar conversion.)
30083055 };
30093056
30103057private:
@@ -3015,19 +3062,19 @@ class TupleShuffleExpr final : public ImplicitConversionExpr,
30153062 // / declaration.
30163063 ConcreteDeclRef DefaultArgsOwner;
30173064
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),
30263073 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 ();
30313078 std::uninitialized_copy (CallerDefaultArgs.begin (), CallerDefaultArgs.end (),
30323079 getTrailingObjects<Expr*>());
30333080 std::uninitialized_copy (elementMapping.begin (), elementMapping.end (),
@@ -3037,23 +3084,23 @@ class TupleShuffleExpr final : public ImplicitConversionExpr,
30373084 }
30383085
30393086public:
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);
30483095
30493096 ArrayRef<int > getElementMapping () const {
30503097 return {getTrailingObjects<int >(),
3051- static_cast <size_t >(Bits.TupleShuffleExpr .NumElementMappings )};
3098+ static_cast <size_t >(Bits.ArgumentShuffleExpr .NumElementMappings )};
30523099 }
30533100
30543101 // / What is the type impact of this shuffle?
30553102 TypeImpact getTypeImpact () const {
3056- return TypeImpact (Bits.TupleShuffleExpr .TypeImpact );
3103+ return TypeImpact (Bits.ArgumentShuffleExpr .TypeImpact );
30573104 }
30583105
30593106 bool isSourceScalar () const {
@@ -3075,7 +3122,7 @@ class TupleShuffleExpr final : public ImplicitConversionExpr,
30753122 // / Retrieve the argument indices for the variadic arguments.
30763123 ArrayRef<unsigned > getVariadicArgs () const {
30773124 return {getTrailingObjects<unsigned >(),
3078- static_cast <size_t >(Bits.TupleShuffleExpr .NumVariadicArgs )};
3125+ static_cast <size_t >(Bits.ArgumentShuffleExpr .NumVariadicArgs )};
30793126 }
30803127
30813128 // / Retrieve the owner of the default arguments.
@@ -3084,17 +3131,17 @@ class TupleShuffleExpr final : public ImplicitConversionExpr,
30843131 // / Retrieve the caller-defaulted arguments.
30853132 ArrayRef<Expr *> getCallerDefaultArgs () const {
30863133 return {getTrailingObjects<Expr*>(),
3087- static_cast <size_t >(Bits.TupleShuffleExpr .NumCallerDefaultArgs )};
3134+ static_cast <size_t >(Bits.ArgumentShuffleExpr .NumCallerDefaultArgs )};
30883135 }
30893136
30903137 // / Retrieve the caller-defaulted arguments.
30913138 MutableArrayRef<Expr *> getCallerDefaultArgs () {
30923139 return {getTrailingObjects<Expr*>(),
3093- static_cast <size_t >(Bits.TupleShuffleExpr .NumCallerDefaultArgs )};
3140+ static_cast <size_t >(Bits.ArgumentShuffleExpr .NumCallerDefaultArgs )};
30943141 }
30953142
30963143 static bool classof (const Expr *E) {
3097- return E->getKind () == ExprKind::TupleShuffle ;
3144+ return E->getKind () == ExprKind::ArgumentShuffle ;
30983145 }
30993146};
31003147
@@ -3975,7 +4022,7 @@ class ApplyExpr : public Expr {
39754022
39764023 // / Returns true if \c e could be used as the call's argument. For most \c ApplyExpr
39774024 // / subclasses, this means it is a \c ParenExpr, \c TupleExpr, or
3978- // / \c TupleShuffleExpr .
4025+ // / \c ArgumentShuffleExpr .
39794026 bool validateArg (Expr *e) const ;
39804027
39814028protected:
@@ -5355,7 +5402,7 @@ inline bool ApplyExpr::validateArg(Expr *e) const {
53555402 else if (isa<BinaryExpr>(this ))
53565403 return isa<TupleExpr>(e);
53575404 else
5358- return isa<ParenExpr>(e) || isa<TupleExpr>(e) || isa<TupleShuffleExpr >(e);
5405+ return isa<ParenExpr>(e) || isa<TupleExpr>(e) || isa<ArgumentShuffleExpr >(e);
53595406}
53605407
53615408inline Expr *const *CollectionExpr::getTrailingObjectsPointer () const {
0 commit comments