Skip to content

Commit 1467f55

Browse files
committed
AST: Remove ArgumentShuffleExpr
1 parent e212d45 commit 1467f55

18 files changed

+18
-1050
lines changed

include/swift/AST/Expr.h

Lines changed: 2 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -295,19 +295,6 @@ class alignas(8) Expr {
295295
NumElements : 16
296296
);
297297

298-
SWIFT_INLINE_BITFIELD_FULL(ArgumentShuffleExpr, ImplicitConversionExpr, 2+16+16+16,
299-
TypeImpact : 2,
300-
: NumPadBits,
301-
NumCallerDefaultArgs : 16,
302-
/// This contains an entry for each element in the Expr type. Each element
303-
/// specifies which index from the SubExpr that the destination element gets.
304-
/// If the element value is DefaultInitialize, then the destination value
305-
/// gets the default initializer for that tuple element value.
306-
NumElementMappings : 16,
307-
/// The arguments that are packed into the variadic element.
308-
NumVariadicArgs : 16
309-
);
310-
311298
SWIFT_INLINE_BITFIELD(ForceValueExpr, Expr, 1,
312299
ForcedIUO : 1
313300
);
@@ -3020,157 +3007,6 @@ class DestructureTupleExpr final : public ImplicitConversionExpr,
30203007
}
30213008
};
30223009

3023-
/// ArgumentShuffleExpr - This represents a "complex" argument list of an
3024-
/// ApplyExpr, with default arguments or varargs.
3025-
///
3026-
/// If hasScalarSource() is true, the subexpression should be treated
3027-
/// as if it were implicitly injected into a single-element tuple
3028-
/// type. Otherwise, the subexpression is known to have a tuple type.
3029-
class ArgumentShuffleExpr final : public ImplicitConversionExpr,
3030-
private llvm::TrailingObjects<ArgumentShuffleExpr, Expr *, int, unsigned> {
3031-
friend TrailingObjects;
3032-
3033-
size_t numTrailingObjects(OverloadToken<Expr *>) const {
3034-
return Bits.ArgumentShuffleExpr.NumCallerDefaultArgs;
3035-
}
3036-
size_t numTrailingObjects(OverloadToken<int>) const {
3037-
return Bits.ArgumentShuffleExpr.NumElementMappings;
3038-
}
3039-
size_t numTrailingObjects(OverloadToken<unsigned>) const {
3040-
return Bits.ArgumentShuffleExpr.NumVariadicArgs;
3041-
}
3042-
3043-
public:
3044-
enum : int {
3045-
/// The element mapping value indicating that a field of the destination
3046-
/// tuple should be default-initialized.
3047-
DefaultInitialize = -1,
3048-
/// The element mapping is part of the variadic field.
3049-
Variadic = -2,
3050-
/// The element mapping value indicating that the field of the
3051-
/// destination tuple should be default-initialized with an expression
3052-
/// provided by the caller.
3053-
/// FIXME: Yet another indication that ArgumentShuffleExpr uses the wrong
3054-
/// formulation.
3055-
CallerDefaultInitialize = -3
3056-
};
3057-
3058-
enum TypeImpact {
3059-
/// The source value is a tuple which is destructured and modified to
3060-
/// create the result, which is a tuple.
3061-
///
3062-
/// Example: (x: Int) => (x: Int, y: Int = 0).
3063-
TupleToTuple,
3064-
3065-
/// The source value is a tuple which is destructured and modified to
3066-
/// create the result, which is a scalar because it has one element and
3067-
/// no labels.
3068-
///
3069-
/// Example: () -> (_: Int = 0)
3070-
/// Another example: (Int, Int) => (_: Int...)
3071-
TupleToScalar,
3072-
3073-
/// The source value is an individual value (possibly one with tuple
3074-
/// type) which is inserted into a particular position in the result,
3075-
/// which is a tuple.
3076-
///
3077-
/// Example: (Int) -> (_: Int, y: Int = 0)
3078-
ScalarToTuple
3079-
3080-
// (ArgumentShuffleExpr are never created for a scalar-to-scalar conversion.)
3081-
};
3082-
3083-
private:
3084-
/// If we're doing a varargs shuffle, this is the array type to build.
3085-
Type VarargsArrayTy;
3086-
3087-
/// If there are any default arguments, the owning function
3088-
/// declaration.
3089-
ConcreteDeclRef DefaultArgsOwner;
3090-
3091-
ArgumentShuffleExpr(Expr *subExpr, ArrayRef<int> elementMapping,
3092-
TypeImpact typeImpact,
3093-
ConcreteDeclRef defaultArgsOwner,
3094-
ArrayRef<unsigned> VariadicArgs,
3095-
Type VarargsArrayTy,
3096-
ArrayRef<Expr *> CallerDefaultArgs,
3097-
Type ty)
3098-
: ImplicitConversionExpr(ExprKind::ArgumentShuffle, subExpr, ty),
3099-
VarargsArrayTy(VarargsArrayTy), DefaultArgsOwner(defaultArgsOwner) {
3100-
Bits.ArgumentShuffleExpr.TypeImpact = typeImpact;
3101-
Bits.ArgumentShuffleExpr.NumCallerDefaultArgs = CallerDefaultArgs.size();
3102-
Bits.ArgumentShuffleExpr.NumElementMappings = elementMapping.size();
3103-
Bits.ArgumentShuffleExpr.NumVariadicArgs = VariadicArgs.size();
3104-
std::uninitialized_copy(CallerDefaultArgs.begin(), CallerDefaultArgs.end(),
3105-
getTrailingObjects<Expr*>());
3106-
std::uninitialized_copy(elementMapping.begin(), elementMapping.end(),
3107-
getTrailingObjects<int>());
3108-
std::uninitialized_copy(VariadicArgs.begin(), VariadicArgs.end(),
3109-
getTrailingObjects<unsigned>());
3110-
}
3111-
3112-
public:
3113-
static ArgumentShuffleExpr *create(ASTContext &ctx, Expr *subExpr,
3114-
ArrayRef<int> elementMapping,
3115-
TypeImpact typeImpact,
3116-
ConcreteDeclRef defaultArgsOwner,
3117-
ArrayRef<unsigned> VariadicArgs,
3118-
Type VarargsArrayTy,
3119-
ArrayRef<Expr *> CallerDefaultArgs,
3120-
Type ty);
3121-
3122-
ArrayRef<int> getElementMapping() const {
3123-
return {getTrailingObjects<int>(),
3124-
static_cast<size_t>(Bits.ArgumentShuffleExpr.NumElementMappings)};
3125-
}
3126-
3127-
/// What is the type impact of this shuffle?
3128-
TypeImpact getTypeImpact() const {
3129-
return TypeImpact(Bits.ArgumentShuffleExpr.TypeImpact);
3130-
}
3131-
3132-
bool isSourceScalar() const {
3133-
return getTypeImpact() == ScalarToTuple;
3134-
}
3135-
3136-
bool isResultScalar() const {
3137-
return getTypeImpact() == TupleToScalar;
3138-
}
3139-
3140-
Type getVarargsArrayType() const {
3141-
assert(!VarargsArrayTy.isNull());
3142-
return VarargsArrayTy;
3143-
}
3144-
Type getVarargsArrayTypeOrNull() const {
3145-
return VarargsArrayTy;
3146-
}
3147-
3148-
/// Retrieve the argument indices for the variadic arguments.
3149-
ArrayRef<unsigned> getVariadicArgs() const {
3150-
return {getTrailingObjects<unsigned>(),
3151-
static_cast<size_t>(Bits.ArgumentShuffleExpr.NumVariadicArgs)};
3152-
}
3153-
3154-
/// Retrieve the owner of the default arguments.
3155-
ConcreteDeclRef getDefaultArgsOwner() const { return DefaultArgsOwner; }
3156-
3157-
/// Retrieve the caller-defaulted arguments.
3158-
ArrayRef<Expr *> getCallerDefaultArgs() const {
3159-
return {getTrailingObjects<Expr*>(),
3160-
static_cast<size_t>(Bits.ArgumentShuffleExpr.NumCallerDefaultArgs)};
3161-
}
3162-
3163-
/// Retrieve the caller-defaulted arguments.
3164-
MutableArrayRef<Expr *> getCallerDefaultArgs() {
3165-
return {getTrailingObjects<Expr*>(),
3166-
static_cast<size_t>(Bits.ArgumentShuffleExpr.NumCallerDefaultArgs)};
3167-
}
3168-
3169-
static bool classof(const Expr *E) {
3170-
return E->getKind() == ExprKind::ArgumentShuffle;
3171-
}
3172-
};
3173-
31743010
/// LoadExpr - Turn an l-value into an r-value by performing a "load"
31753011
/// operation. This operation may actually be a logical operation,
31763012
/// i.e. one implemented using a call to a potentially user-defined
@@ -4123,8 +3959,7 @@ class ApplyExpr : public Expr {
41233959
llvm::PointerIntPair<Expr *, 1, bool> ArgAndIsSuper;
41243960

41253961
/// Returns true if \c e could be used as the call's argument. For most \c ApplyExpr
4126-
/// subclasses, this means it is a \c ParenExpr, \c TupleExpr, or
4127-
/// \c ArgumentShuffleExpr.
3962+
/// subclasses, this means it is a \c ParenExpr or \c TupleExpr.
41283963
bool validateArg(Expr *e) const;
41293964

41303965
protected:
@@ -5504,7 +5339,7 @@ inline bool ApplyExpr::validateArg(Expr *e) const {
55045339
else if (isa<BinaryExpr>(this))
55055340
return isa<TupleExpr>(e);
55065341
else
5507-
return isa<ParenExpr>(e) || isa<TupleExpr>(e) || isa<ArgumentShuffleExpr>(e);
5342+
return isa<ParenExpr>(e) || isa<TupleExpr>(e);
55085343
}
55095344

55105345
inline Expr *const *CollectionExpr::getTrailingObjectsPointer() const {

include/swift/AST/ExprNodes.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ ABSTRACT_EXPR(Apply, Expr)
146146
ABSTRACT_EXPR(ImplicitConversion, Expr)
147147
EXPR(Load, ImplicitConversionExpr)
148148
EXPR(DestructureTuple, ImplicitConversionExpr)
149-
EXPR(ArgumentShuffle, ImplicitConversionExpr)
150149
EXPR(UnresolvedTypeConversion, ImplicitConversionExpr)
151150
EXPR(FunctionConversion, ImplicitConversionExpr)
152151
EXPR(CovariantFunctionConversion, ImplicitConversionExpr)

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,42 +2156,6 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
21562156
printRec(E->getResultExpr());
21572157
PrintWithColorRAII(OS, ParenthesisColor) << ')';
21582158
}
2159-
void visitArgumentShuffleExpr(ArgumentShuffleExpr *E) {
2160-
printCommon(E, "argument_shuffle_expr");
2161-
switch (E->getTypeImpact()) {
2162-
case ArgumentShuffleExpr::ScalarToTuple:
2163-
OS << " scalar_to_tuple";
2164-
break;
2165-
case ArgumentShuffleExpr::TupleToTuple:
2166-
OS << " tuple_to_tuple";
2167-
break;
2168-
case ArgumentShuffleExpr::TupleToScalar:
2169-
OS << " tuple_to_scalar";
2170-
break;
2171-
}
2172-
OS << " elements=[";
2173-
for (unsigned i = 0, e = E->getElementMapping().size(); i != e; ++i) {
2174-
if (i) OS << ", ";
2175-
OS << E->getElementMapping()[i];
2176-
}
2177-
OS << "]";
2178-
OS << " variadic_sources=[";
2179-
interleave(E->getVariadicArgs(),
2180-
[&](unsigned source) {
2181-
OS << source;
2182-
},
2183-
[&] { OS << ", "; });
2184-
OS << "]";
2185-
2186-
if (auto defaultArgsOwner = E->getDefaultArgsOwner()) {
2187-
OS << " default_args_owner=";
2188-
defaultArgsOwner.dump(OS);
2189-
}
2190-
2191-
OS << "\n";
2192-
printRec(E->getSubExpr());
2193-
PrintWithColorRAII(OS, ParenthesisColor) << ')';
2194-
}
21952159
void visitUnresolvedTypeConversionExpr(UnresolvedTypeConversionExpr *E) {
21962160
printCommon(E, "unresolvedtype_conversion_expr") << '\n';
21972161
printRec(E->getSubExpr());

lib/AST/ASTVerifier.cpp

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,12 +1729,6 @@ class Verifier : public ASTWalker {
17291729
}
17301730
};
17311731

1732-
// If we have an argument shuffle, strip it off. We want to visit the
1733-
// underlying paren or tuple expr.
1734-
if (auto *ArgShuffle = dyn_cast<ArgumentShuffleExpr>(Arg)) {
1735-
Arg = ArgShuffle->getSubExpr();
1736-
}
1737-
17381732
if (auto *ParentExprArg = dyn_cast<ParenExpr>(Arg)) {
17391733
return handleSubExpr(ParentExprArg->getSubExpr());
17401734
}
@@ -2039,66 +2033,7 @@ class Verifier : public ASTWalker {
20392033

20402034
verifyCheckedBase(E);
20412035
}
2042-
2043-
void verifyChecked(ArgumentShuffleExpr *E) {
2044-
PrettyStackTraceExpr debugStack(Ctx, "verifying ArgumentShuffleExpr", E);
2045-
2046-
auto getSubElementType = [&](unsigned i) {
2047-
if (E->isSourceScalar()) {
2048-
assert(i == 0);
2049-
return E->getSubExpr()->getType();
2050-
} else {
2051-
return (E->getSubExpr()->getType()->castTo<TupleType>()
2052-
->getElementType(i));
2053-
}
2054-
};
20552036

2056-
/// Retrieve the ith element type from the resulting tuple type.
2057-
auto getOuterElementType = [&](unsigned i) -> Type {
2058-
if (E->isResultScalar()) {
2059-
assert(i == 0);
2060-
return E->getType()->getWithoutParens();
2061-
} else {
2062-
return E->getType()->castTo<TupleType>()->getElementType(i);
2063-
}
2064-
};
2065-
2066-
Type varargsType;
2067-
unsigned callerDefaultArgIndex = 0;
2068-
for (unsigned i = 0, e = E->getElementMapping().size(); i != e; ++i) {
2069-
int subElem = E->getElementMapping()[i];
2070-
if (subElem == ArgumentShuffleExpr::DefaultInitialize)
2071-
continue;
2072-
if (subElem == ArgumentShuffleExpr::Variadic) {
2073-
varargsType = (E->getType()->castTo<TupleType>()
2074-
->getElement(i).getVarargBaseTy());
2075-
break;
2076-
}
2077-
if (subElem == ArgumentShuffleExpr::CallerDefaultInitialize) {
2078-
auto init = E->getCallerDefaultArgs()[callerDefaultArgIndex++];
2079-
if (!getOuterElementType(i)->isEqual(init->getType())) {
2080-
Out << "Type mismatch in ArgumentShuffleExpr\n";
2081-
abort();
2082-
}
2083-
continue;
2084-
}
2085-
if (!getOuterElementType(i)->isEqual(getSubElementType(subElem))) {
2086-
Out << "Type mismatch in ArgumentShuffleExpr\n";
2087-
abort();
2088-
}
2089-
}
2090-
if (varargsType) {
2091-
for (auto sourceIdx : E->getVariadicArgs()) {
2092-
if (!getSubElementType(sourceIdx)->isEqual(varargsType)) {
2093-
Out << "Vararg type mismatch in ArgumentShuffleExpr\n";
2094-
abort();
2095-
}
2096-
}
2097-
}
2098-
2099-
verifyCheckedBase(E);
2100-
}
2101-
21022037
void verifyChecked(DynamicTypeExpr *E) {
21032038
PrettyStackTraceExpr debugStack(Ctx, "verifying DynamicTypeExpr", E);
21042039

lib/AST/ASTWalker.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -666,23 +666,6 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
666666
return E;
667667
}
668668

669-
Expr *visitArgumentShuffleExpr(ArgumentShuffleExpr *E) {
670-
if (Expr *E2 = doIt(E->getSubExpr())) {
671-
E->setSubExpr(E2);
672-
} else {
673-
return nullptr;
674-
}
675-
676-
for (auto &defaultArg : E->getCallerDefaultArgs()) {
677-
if (Expr *newDefaultArg = doIt(defaultArg))
678-
defaultArg = newDefaultArg;
679-
else
680-
return nullptr;
681-
}
682-
683-
return E;
684-
}
685-
686669
Expr *visitTryExpr(TryExpr *E) {
687670
if (Expr *E2 = doIt(E->getSubExpr())) {
688671
E->setSubExpr(E2);

lib/AST/Expr.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ ConcreteDeclRef Expr::getReferencedDecl() const {
326326
PASS_THROUGH_REFERENCE(ConstructorRefCall, getFn);
327327
PASS_THROUGH_REFERENCE(Load, getSubExpr);
328328
NO_REFERENCE(DestructureTuple);
329-
NO_REFERENCE(ArgumentShuffle);
330329
NO_REFERENCE(UnresolvedTypeConversion);
331330
PASS_THROUGH_REFERENCE(FunctionConversion, getSubExpr);
332331
PASS_THROUGH_REFERENCE(CovariantFunctionConversion, getSubExpr);
@@ -643,7 +642,6 @@ bool Expr::canAppendPostfixExpression(bool appendingPostfixOperator) const {
643642

644643
case ExprKind::Load:
645644
case ExprKind::DestructureTuple:
646-
case ExprKind::ArgumentShuffle:
647645
case ExprKind::UnresolvedTypeConversion:
648646
case ExprKind::FunctionConversion:
649647
case ExprKind::CovariantFunctionConversion:
@@ -1348,24 +1346,6 @@ DestructureTupleExpr::create(ASTContext &ctx,
13481346
srcExpr, dstExpr, ty);
13491347
}
13501348

1351-
ArgumentShuffleExpr *ArgumentShuffleExpr::create(ASTContext &ctx,
1352-
Expr *subExpr,
1353-
ArrayRef<int> elementMapping,
1354-
TypeImpact typeImpact,
1355-
ConcreteDeclRef defaultArgsOwner,
1356-
ArrayRef<unsigned> VariadicArgs,
1357-
Type VarargsArrayTy,
1358-
ArrayRef<Expr *> CallerDefaultArgs,
1359-
Type ty) {
1360-
auto size = totalSizeToAlloc<Expr*, int, unsigned>(CallerDefaultArgs.size(),
1361-
elementMapping.size(),
1362-
VariadicArgs.size());
1363-
auto mem = ctx.Allocate(size, alignof(ArgumentShuffleExpr));
1364-
return ::new(mem) ArgumentShuffleExpr(subExpr, elementMapping, typeImpact,
1365-
defaultArgsOwner, VariadicArgs,
1366-
VarargsArrayTy, CallerDefaultArgs, ty);
1367-
}
1368-
13691349
SourceRange TupleExpr::getSourceRange() const {
13701350
SourceLoc start = SourceLoc();
13711351
SourceLoc end = SourceLoc();

0 commit comments

Comments
 (0)