diff --git a/include/swift/AST/Expr.h b/include/swift/AST/Expr.h index 7a962ecd474e8..2fe2b97aa0e32 100644 --- a/include/swift/AST/Expr.h +++ b/include/swift/AST/Expr.h @@ -290,7 +290,13 @@ class alignas(8) Expr { SWIFT_INLINE_BITFIELD_EMPTY(ImplicitConversionExpr, Expr); - SWIFT_INLINE_BITFIELD_FULL(TupleShuffleExpr, ImplicitConversionExpr, 2+16+16+16, + SWIFT_INLINE_BITFIELD_FULL(TupleShuffleExpr, ImplicitConversionExpr, 16, + /// This contains an entry for each element in the Expr type. Each element + /// specifies which index from the SubExpr that the destination element gets. + NumElementMappings : 16 + ); + + SWIFT_INLINE_BITFIELD_FULL(ArgumentShuffleExpr, ImplicitConversionExpr, 2+16+16+16, TypeImpact : 2, : NumPadBits, NumCallerDefaultArgs : 16, @@ -2956,22 +2962,56 @@ class UnevaluatedInstanceExpr : public ImplicitConversionExpr { /// TupleShuffleExpr - This represents a permutation of a tuple value to a new /// tuple type. +class TupleShuffleExpr final : public ImplicitConversionExpr, + private llvm::TrailingObjects { + friend TrailingObjects; + + size_t numTrailingObjects(OverloadToken) const { + return Bits.TupleShuffleExpr.NumElementMappings; + } + +private: + TupleShuffleExpr(Expr *subExpr, ArrayRef elementMapping, + Type ty) + : ImplicitConversionExpr(ExprKind::TupleShuffle, subExpr, ty) { + Bits.TupleShuffleExpr.NumElementMappings = elementMapping.size(); + std::uninitialized_copy(elementMapping.begin(), elementMapping.end(), + getTrailingObjects()); + } + +public: + static TupleShuffleExpr *create(ASTContext &ctx, Expr *subExpr, + ArrayRef elementMapping, + Type ty); + + ArrayRef getElementMapping() const { + return {getTrailingObjects(), + static_cast(Bits.TupleShuffleExpr.NumElementMappings)}; + } + + static bool classof(const Expr *E) { + return E->getKind() == ExprKind::TupleShuffle; + } +}; + +/// ArgumentShuffleExpr - This represents a "complex" argument list of an +/// ApplyExpr, with default arguments or varargs. /// /// If hasScalarSource() is true, the subexpression should be treated /// as if it were implicitly injected into a single-element tuple /// type. Otherwise, the subexpression is known to have a tuple type. -class TupleShuffleExpr final : public ImplicitConversionExpr, - private llvm::TrailingObjects { +class ArgumentShuffleExpr final : public ImplicitConversionExpr, + private llvm::TrailingObjects { friend TrailingObjects; size_t numTrailingObjects(OverloadToken) const { - return Bits.TupleShuffleExpr.NumCallerDefaultArgs; + return Bits.ArgumentShuffleExpr.NumCallerDefaultArgs; } size_t numTrailingObjects(OverloadToken) const { - return Bits.TupleShuffleExpr.NumElementMappings; + return Bits.ArgumentShuffleExpr.NumElementMappings; } size_t numTrailingObjects(OverloadToken) const { - return Bits.TupleShuffleExpr.NumVariadicArgs; + return Bits.ArgumentShuffleExpr.NumVariadicArgs; } public: @@ -2984,7 +3024,7 @@ class TupleShuffleExpr final : public ImplicitConversionExpr, /// The element mapping value indicating that the field of the /// destination tuple should be default-initialized with an expression /// provided by the caller. - /// FIXME: Yet another indication that TupleShuffleExpr uses the wrong + /// FIXME: Yet another indication that ArgumentShuffleExpr uses the wrong /// formulation. CallerDefaultInitialize = -3 }; @@ -2992,19 +3032,26 @@ class TupleShuffleExpr final : public ImplicitConversionExpr, enum TypeImpact { /// The source value is a tuple which is destructured and modified to /// create the result, which is a tuple. + /// + /// Example: (x: Int) => (x: Int, y: Int = 0). TupleToTuple, /// The source value is a tuple which is destructured and modified to /// create the result, which is a scalar because it has one element and /// no labels. + /// + /// Example: () -> (_: Int = 0) + /// Another example: (Int, Int) => (_: Int...) TupleToScalar, /// The source value is an individual value (possibly one with tuple /// type) which is inserted into a particular position in the result, /// which is a tuple. + /// + /// Example: (Int) -> (_: Int, y: Int = 0) ScalarToTuple - // (TupleShuffleExprs are never created for a scalar-to-scalar conversion.) + // (ArgumentShuffleExpr are never created for a scalar-to-scalar conversion.) }; private: @@ -3015,19 +3062,19 @@ class TupleShuffleExpr final : public ImplicitConversionExpr, /// declaration. ConcreteDeclRef DefaultArgsOwner; - TupleShuffleExpr(Expr *subExpr, ArrayRef elementMapping, - TypeImpact typeImpact, - ConcreteDeclRef defaultArgsOwner, - ArrayRef VariadicArgs, - Type VarargsArrayTy, - ArrayRef CallerDefaultArgs, - Type ty) - : ImplicitConversionExpr(ExprKind::TupleShuffle, subExpr, ty), + ArgumentShuffleExpr(Expr *subExpr, ArrayRef elementMapping, + TypeImpact typeImpact, + ConcreteDeclRef defaultArgsOwner, + ArrayRef VariadicArgs, + Type VarargsArrayTy, + ArrayRef CallerDefaultArgs, + Type ty) + : ImplicitConversionExpr(ExprKind::ArgumentShuffle, subExpr, ty), VarargsArrayTy(VarargsArrayTy), DefaultArgsOwner(defaultArgsOwner) { - Bits.TupleShuffleExpr.TypeImpact = typeImpact; - Bits.TupleShuffleExpr.NumCallerDefaultArgs = CallerDefaultArgs.size(); - Bits.TupleShuffleExpr.NumElementMappings = elementMapping.size(); - Bits.TupleShuffleExpr.NumVariadicArgs = VariadicArgs.size(); + Bits.ArgumentShuffleExpr.TypeImpact = typeImpact; + Bits.ArgumentShuffleExpr.NumCallerDefaultArgs = CallerDefaultArgs.size(); + Bits.ArgumentShuffleExpr.NumElementMappings = elementMapping.size(); + Bits.ArgumentShuffleExpr.NumVariadicArgs = VariadicArgs.size(); std::uninitialized_copy(CallerDefaultArgs.begin(), CallerDefaultArgs.end(), getTrailingObjects()); std::uninitialized_copy(elementMapping.begin(), elementMapping.end(), @@ -3037,23 +3084,23 @@ class TupleShuffleExpr final : public ImplicitConversionExpr, } public: - static TupleShuffleExpr *create(ASTContext &ctx, Expr *subExpr, - ArrayRef elementMapping, - TypeImpact typeImpact, - ConcreteDeclRef defaultArgsOwner, - ArrayRef VariadicArgs, - Type VarargsArrayTy, - ArrayRef CallerDefaultArgs, - Type ty); + static ArgumentShuffleExpr *create(ASTContext &ctx, Expr *subExpr, + ArrayRef elementMapping, + TypeImpact typeImpact, + ConcreteDeclRef defaultArgsOwner, + ArrayRef VariadicArgs, + Type VarargsArrayTy, + ArrayRef CallerDefaultArgs, + Type ty); ArrayRef getElementMapping() const { return {getTrailingObjects(), - static_cast(Bits.TupleShuffleExpr.NumElementMappings)}; + static_cast(Bits.ArgumentShuffleExpr.NumElementMappings)}; } /// What is the type impact of this shuffle? TypeImpact getTypeImpact() const { - return TypeImpact(Bits.TupleShuffleExpr.TypeImpact); + return TypeImpact(Bits.ArgumentShuffleExpr.TypeImpact); } bool isSourceScalar() const { @@ -3075,7 +3122,7 @@ class TupleShuffleExpr final : public ImplicitConversionExpr, /// Retrieve the argument indices for the variadic arguments. ArrayRef getVariadicArgs() const { return {getTrailingObjects(), - static_cast(Bits.TupleShuffleExpr.NumVariadicArgs)}; + static_cast(Bits.ArgumentShuffleExpr.NumVariadicArgs)}; } /// Retrieve the owner of the default arguments. @@ -3084,17 +3131,17 @@ class TupleShuffleExpr final : public ImplicitConversionExpr, /// Retrieve the caller-defaulted arguments. ArrayRef getCallerDefaultArgs() const { return {getTrailingObjects(), - static_cast(Bits.TupleShuffleExpr.NumCallerDefaultArgs)}; + static_cast(Bits.ArgumentShuffleExpr.NumCallerDefaultArgs)}; } /// Retrieve the caller-defaulted arguments. MutableArrayRef getCallerDefaultArgs() { return {getTrailingObjects(), - static_cast(Bits.TupleShuffleExpr.NumCallerDefaultArgs)}; + static_cast(Bits.ArgumentShuffleExpr.NumCallerDefaultArgs)}; } static bool classof(const Expr *E) { - return E->getKind() == ExprKind::TupleShuffle; + return E->getKind() == ExprKind::ArgumentShuffle; } }; @@ -3975,7 +4022,7 @@ class ApplyExpr : public Expr { /// Returns true if \c e could be used as the call's argument. For most \c ApplyExpr /// subclasses, this means it is a \c ParenExpr, \c TupleExpr, or - /// \c TupleShuffleExpr. + /// \c ArgumentShuffleExpr. bool validateArg(Expr *e) const; protected: @@ -5355,7 +5402,7 @@ inline bool ApplyExpr::validateArg(Expr *e) const { else if (isa(this)) return isa(e); else - return isa(e) || isa(e) || isa(e); + return isa(e) || isa(e) || isa(e); } inline Expr *const *CollectionExpr::getTrailingObjectsPointer() const { diff --git a/include/swift/AST/ExprNodes.def b/include/swift/AST/ExprNodes.def index 84d49ebe617d5..98dce858b3d43 100644 --- a/include/swift/AST/ExprNodes.def +++ b/include/swift/AST/ExprNodes.def @@ -144,6 +144,7 @@ ABSTRACT_EXPR(Apply, Expr) ABSTRACT_EXPR(ImplicitConversion, Expr) EXPR(Load, ImplicitConversionExpr) EXPR(TupleShuffle, ImplicitConversionExpr) + EXPR(ArgumentShuffle, ImplicitConversionExpr) EXPR(UnresolvedTypeConversion, ImplicitConversionExpr) EXPR(FunctionConversion, ImplicitConversionExpr) EXPR(CovariantFunctionConversion, ImplicitConversionExpr) diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp index 7bf103f3dcd78..d80031691ea5d 100644 --- a/lib/AST/ASTDumper.cpp +++ b/lib/AST/ASTDumper.cpp @@ -2118,15 +2118,26 @@ class PrintExpr : public ExprVisitor { PrintWithColorRAII(OS, ParenthesisColor) << ')'; } void visitTupleShuffleExpr(TupleShuffleExpr *E) { + printCommon(E, "tuple_shuffle_expr"); + OS << " elements=["; + for (unsigned i = 0, e = E->getElementMapping().size(); i != e; ++i) { + if (i) OS << ", "; + OS << E->getElementMapping()[i]; + } + OS << "]\n"; + printRec(E->getSubExpr()); + PrintWithColorRAII(OS, ParenthesisColor) << ')'; + } + void visitArgumentShuffleExpr(ArgumentShuffleExpr *E) { printCommon(E, "tuple_shuffle_expr"); switch (E->getTypeImpact()) { - case TupleShuffleExpr::ScalarToTuple: + case ArgumentShuffleExpr::ScalarToTuple: OS << " scalar_to_tuple"; break; - case TupleShuffleExpr::TupleToTuple: + case ArgumentShuffleExpr::TupleToTuple: OS << " tuple_to_tuple"; break; - case TupleShuffleExpr::TupleToScalar: + case ArgumentShuffleExpr::TupleToScalar: OS << " tuple_to_scalar"; break; } diff --git a/lib/AST/ASTVerifier.cpp b/lib/AST/ASTVerifier.cpp index e82af99ba0d2e..a285ce696c186 100644 --- a/lib/AST/ASTVerifier.cpp +++ b/lib/AST/ASTVerifier.cpp @@ -1709,10 +1709,10 @@ class Verifier : public ASTWalker { } }; - // If we have a tuple_shuffle, strip it off. We want to visit the + // If we have an argument shuffle, strip it off. We want to visit the // underlying paren or tuple expr. - if (auto *TupleShuffle = dyn_cast(Arg)) { - Arg = TupleShuffle->getSubExpr(); + if (auto *ArgShuffle = dyn_cast(Arg)) { + Arg = ArgShuffle->getSubExpr(); } if (auto *ParentExprArg = dyn_cast(Arg)) { @@ -1991,6 +1991,30 @@ class Verifier : public ASTWalker { void verifyChecked(TupleShuffleExpr *E) { PrettyStackTraceExpr debugStack(Ctx, "verifying TupleShuffleExpr", E); + auto getSubElementType = [&](unsigned i) { + return (E->getSubExpr()->getType()->castTo() + ->getElementType(i)); + }; + + /// Retrieve the ith element type from the resulting tuple type. + auto getOuterElementType = [&](unsigned i) -> Type { + return E->getType()->castTo()->getElementType(i); + }; + + for (unsigned i = 0, e = E->getElementMapping().size(); i != e; ++i) { + int subElem = E->getElementMapping()[i]; + if (!getOuterElementType(i)->isEqual(getSubElementType(subElem))) { + Out << "Type mismatch in TupleShuffleExpr\n"; + abort(); + } + } + + verifyCheckedBase(E); + } + + void verifyChecked(ArgumentShuffleExpr *E) { + PrettyStackTraceExpr debugStack(Ctx, "verifying ArgumentShuffleExpr", E); + auto getSubElementType = [&](unsigned i) { if (E->isSourceScalar()) { assert(i == 0); @@ -2015,30 +2039,30 @@ class Verifier : public ASTWalker { unsigned callerDefaultArgIndex = 0; for (unsigned i = 0, e = E->getElementMapping().size(); i != e; ++i) { int subElem = E->getElementMapping()[i]; - if (subElem == TupleShuffleExpr::DefaultInitialize) + if (subElem == ArgumentShuffleExpr::DefaultInitialize) continue; - if (subElem == TupleShuffleExpr::Variadic) { + if (subElem == ArgumentShuffleExpr::Variadic) { varargsType = (E->getType()->castTo() ->getElement(i).getVarargBaseTy()); break; } - if (subElem == TupleShuffleExpr::CallerDefaultInitialize) { + if (subElem == ArgumentShuffleExpr::CallerDefaultInitialize) { auto init = E->getCallerDefaultArgs()[callerDefaultArgIndex++]; if (!getOuterElementType(i)->isEqual(init->getType())) { - Out << "Type mismatch in TupleShuffleExpr\n"; + Out << "Type mismatch in ArgumentShuffleExpr\n"; abort(); } continue; } if (!getOuterElementType(i)->isEqual(getSubElementType(subElem))) { - Out << "Type mismatch in TupleShuffleExpr\n"; + Out << "Type mismatch in ArgumentShuffleExpr\n"; abort(); } } if (varargsType) { for (auto sourceIdx : E->getVariadicArgs()) { if (!getSubElementType(sourceIdx)->isEqual(varargsType)) { - Out << "Vararg type mismatch in TupleShuffleExpr\n"; + Out << "Vararg type mismatch in ArgumentShuffleExpr\n"; abort(); } } diff --git a/lib/AST/ASTWalker.cpp b/lib/AST/ASTWalker.cpp index 07bb21dd4bca7..82a020d62ddb2 100644 --- a/lib/AST/ASTWalker.cpp +++ b/lib/AST/ASTWalker.cpp @@ -646,6 +646,16 @@ class Traversal : public ASTVisitorgetSubExpr())) { + E->setSubExpr(E2); + } else { + return nullptr; + } + for (auto &defaultArg : E->getCallerDefaultArgs()) { if (Expr *newDefaultArg = doIt(defaultArg)) defaultArg = newDefaultArg; diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 55f8886ca3bd2..17f9082915ecd 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -323,6 +323,7 @@ ConcreteDeclRef Expr::getReferencedDecl() const { PASS_THROUGH_REFERENCE(ConstructorRefCall, getFn); PASS_THROUGH_REFERENCE(Load, getSubExpr); NO_REFERENCE(TupleShuffle); + NO_REFERENCE(ArgumentShuffle); NO_REFERENCE(UnresolvedTypeConversion); PASS_THROUGH_REFERENCE(FunctionConversion, getSubExpr); PASS_THROUGH_REFERENCE(CovariantFunctionConversion, getSubExpr); @@ -637,6 +638,7 @@ bool Expr::canAppendPostfixExpression(bool appendingPostfixOperator) const { case ExprKind::Load: case ExprKind::TupleShuffle: + case ExprKind::ArgumentShuffle: case ExprKind::UnresolvedTypeConversion: case ExprKind::FunctionConversion: case ExprKind::CovariantFunctionConversion: @@ -1333,20 +1335,29 @@ CaptureListExpr *CaptureListExpr::create(ASTContext &ctx, TupleShuffleExpr *TupleShuffleExpr::create(ASTContext &ctx, Expr *subExpr, - ArrayRef elementMapping, - TypeImpact typeImpact, - ConcreteDeclRef defaultArgsOwner, - ArrayRef VariadicArgs, - Type VarargsArrayTy, - ArrayRef CallerDefaultArgs, + ArrayRef elementMapping, Type ty) { + auto size = totalSizeToAlloc(elementMapping.size()); + auto mem = ctx.Allocate(size, alignof(TupleShuffleExpr)); + return ::new(mem) TupleShuffleExpr(subExpr, elementMapping, ty); +} + +ArgumentShuffleExpr *ArgumentShuffleExpr::create(ASTContext &ctx, + Expr *subExpr, + ArrayRef elementMapping, + TypeImpact typeImpact, + ConcreteDeclRef defaultArgsOwner, + ArrayRef VariadicArgs, + Type VarargsArrayTy, + ArrayRef CallerDefaultArgs, + Type ty) { auto size = totalSizeToAlloc(CallerDefaultArgs.size(), elementMapping.size(), VariadicArgs.size()); - auto mem = ctx.Allocate(size, alignof(TupleShuffleExpr)); - return ::new(mem) TupleShuffleExpr(subExpr, elementMapping, typeImpact, - defaultArgsOwner, VariadicArgs, - VarargsArrayTy, CallerDefaultArgs, ty); + auto mem = ctx.Allocate(size, alignof(ArgumentShuffleExpr)); + return ::new(mem) ArgumentShuffleExpr(subExpr, elementMapping, typeImpact, + defaultArgsOwner, VariadicArgs, + VarargsArrayTy, CallerDefaultArgs, ty); } SourceRange TupleExpr::getSourceRange() const { diff --git a/lib/IDE/ExprContextAnalysis.cpp b/lib/IDE/ExprContextAnalysis.cpp index 277311353c401..abf03c4f86d7d 100644 --- a/lib/IDE/ExprContextAnalysis.cpp +++ b/lib/IDE/ExprContextAnalysis.cpp @@ -439,12 +439,12 @@ bool collectPossibleCalleesForSubscript( } /// Get index of \p CCExpr in \p Args. \p Args is usually a \c TupleExpr, -/// \c ParenExpr, or a \c TupleShuffleExpr. +/// \c ParenExpr, or a \c ArgumentShuffleExpr. /// \returns \c true if success, \c false if \p CCExpr is not a part of \p Args. bool getPositionInArgs(DeclContext &DC, Expr *Args, Expr *CCExpr, unsigned &Position, bool &HasName) { - if (auto TSE = dyn_cast(Args)) - Args = TSE->getSubExpr(); + if (auto ASE = dyn_cast(Args)) + Args = ASE->getSubExpr(); if (isa(Args)) { HasName = false; @@ -469,28 +469,28 @@ bool getPositionInArgs(DeclContext &DC, Expr *Args, Expr *CCExpr, } /// Translate argument index in \p Args to parameter index. -/// Does nothing unless \p Args is \c TupleShuffleExpr. +/// Does nothing unless \p Args is \c ArgumentShuffleExpr. bool translateArgIndexToParamIndex(Expr *Args, unsigned &Position, bool &HasName) { - auto TSE = dyn_cast(Args); - if (!TSE) + auto ASE = dyn_cast(Args); + if (!ASE) return true; - auto mapping = TSE->getElementMapping(); + auto mapping = ASE->getElementMapping(); for (unsigned destIdx = 0, e = mapping.size(); destIdx != e; ++destIdx) { auto srcIdx = mapping[destIdx]; if (srcIdx == (signed)Position) { Position = destIdx; return true; } - if (srcIdx == TupleShuffleExpr::Variadic && - llvm::is_contained(TSE->getVariadicArgs(), Position)) { + if (srcIdx == ArgumentShuffleExpr::Variadic && + llvm::is_contained(ASE->getVariadicArgs(), Position)) { // The arg is a part of variadic args. Position = destIdx; HasName = false; - if (auto Args = dyn_cast(TSE->getSubExpr())) { + if (auto Args = dyn_cast(ASE->getSubExpr())) { // Check if the first variadiac argument has the label. - auto firstVarArgIdx = TSE->getVariadicArgs().front(); + auto firstVarArgIdx = ASE->getVariadicArgs().front(); HasName = Args->getElementNameLoc(firstVarArgIdx).isValid(); } return true; @@ -749,7 +749,7 @@ class ExprContextAnalyzer { auto ParentE = Parent.getAsExpr(); return !ParentE || (!isa(ParentE) && !isa(ParentE) && - !isa(ParentE) && !isa(ParentE)); + !isa(ParentE) && !isa(ParentE)); } case ExprKind::Closure: { // Note: we cannot use hasSingleExpressionBody, because we explicitly diff --git a/lib/IDE/Refactoring.cpp b/lib/IDE/Refactoring.cpp index be0ed4643ac86..87121278406f9 100644 --- a/lib/IDE/Refactoring.cpp +++ b/lib/IDE/Refactoring.cpp @@ -2856,8 +2856,8 @@ static CallExpr *findTrailingClosureTarget(SourceManager &SM, if (!Args) return nullptr; Expr *LastArg; - if (auto *TSE = dyn_cast(Args)) - Args = TSE->getSubExpr(); + if (auto *ASE = dyn_cast(Args)) + Args = ASE->getSubExpr(); if (auto *PE = dyn_cast(Args)) { LastArg = PE->getSubExpr(); } else { @@ -2886,8 +2886,8 @@ bool RefactoringActionTrailingClosure::performChange() { if (!CE) return true; Expr *Args = CE->getArg(); - if (auto *TSE = dyn_cast(Args)) - Args = TSE->getSubExpr(); + if (auto *ASE = dyn_cast(Args)) + Args = ASE->getSubExpr(); Expr *ClosureArg = nullptr; Expr *PrevArg = nullptr; diff --git a/lib/SILGen/ArgumentSource.cpp b/lib/SILGen/ArgumentSource.cpp index bd95cf70cd8d9..e221bc52b8375 100644 --- a/lib/SILGen/ArgumentSource.cpp +++ b/lib/SILGen/ArgumentSource.cpp @@ -35,21 +35,7 @@ bool ArgumentSource::isShuffle() const { case Kind::LValue: return false; case Kind::Expr: - // FIXME: TupleShuffleExprs come in two flavors: - // - // 1) as apply arguments, where they're used to insert default - // argument value and collect varargs - // - // 2) as tuple conversions, where they can introduce, eliminate - // and re-order fields - // - // Case 1) must be emitted by ArgEmitter, and Case 2) must be - // emitted by RValueEmitter. - // - // It would be good to split up TupleShuffleExpr into these two - // cases, and simplify ArgEmitter since it no longer has to deal - // with re-ordering. - return isa(asKnownExpr()); + return isa(asKnownExpr()); } llvm_unreachable("bad kind"); } diff --git a/lib/SILGen/ArgumentSource.h b/lib/SILGen/ArgumentSource.h index 7a8361a164696..4f49a4a56ed25 100644 --- a/lib/SILGen/ArgumentSource.h +++ b/lib/SILGen/ArgumentSource.h @@ -240,7 +240,7 @@ class ArgumentSource { AbstractionPattern origFormalType, SILType expectedType = SILType()) &&; - /// Whether this argument source is a TupleShuffleExpr. + /// Whether this argument source is an ArgumentShuffleExpr. bool isShuffle() const; bool isObviouslyEqual(const ArgumentSource &other) const; diff --git a/lib/SILGen/SILGenApply.cpp b/lib/SILGen/SILGenApply.cpp index 46c85d1f1a18f..be6184dc99ae4 100644 --- a/lib/SILGen/SILGenApply.cpp +++ b/lib/SILGen/SILGenApply.cpp @@ -2676,12 +2676,12 @@ struct ArgSpecialDest { using ArgSpecialDestArray = MutableArrayRef; -class TupleShuffleArgEmitter; +class ArgumentShuffleEmitter; class ArgEmitter { - // TODO: Refactor out the parts of ArgEmitter needed by TupleShuffleArgEmitter + // TODO: Refactor out the parts of ArgEmitter needed by ArgumentShuffleEmitter // into its own "context struct". - friend class TupleShuffleArgEmitter; + friend class ArgumentShuffleEmitter; SILGenFunction &SGF; SILFunctionTypeRepresentation Rep; @@ -2731,7 +2731,7 @@ class ArgEmitter { auto origParamType = AbstractionPattern::getTuple(origParamTypes); if (arg.isShuffle()) { - auto *shuffle = cast(std::move(arg).asKnownExpr()); + auto *shuffle = cast(std::move(arg).asKnownExpr()); emitShuffle(shuffle, origParamType); maybeEmitForeignErrorArgument(); return; @@ -2940,7 +2940,7 @@ class ArgEmitter { emitExpanded({ e, SGF.emitRValue(e) }, origParamType); } - void emitShuffle(TupleShuffleExpr *shuffle, AbstractionPattern origType); + void emitShuffle(ArgumentShuffleExpr *shuffle, AbstractionPattern origType); void emitIndirect(ArgumentSource &&arg, SILType loweredSubstArgType, @@ -3466,7 +3466,7 @@ struct ElementExtent { } }; -class TupleShuffleArgEmitter { +class ArgumentShuffleEmitter { Expr *inner; Expr *outer; ArrayRef innerElts; @@ -3500,7 +3500,7 @@ class TupleShuffleArgEmitter { SmallVector innerDelayedArgs; public: - TupleShuffleArgEmitter(TupleShuffleExpr *e, ArrayRef innerElts, + ArgumentShuffleEmitter(ArgumentShuffleExpr *e, ArrayRef innerElts, AbstractionPattern origParamType) : inner(e->getSubExpr()), outer(e), innerElts(innerElts), defaultArgsOwner(e->getDefaultArgsOwner()), @@ -3528,10 +3528,10 @@ class TupleShuffleArgEmitter { canVarargsArrayType = varargsArrayType->getCanonicalType(); } - TupleShuffleArgEmitter(const TupleShuffleArgEmitter &) = delete; - TupleShuffleArgEmitter &operator=(const TupleShuffleArgEmitter &) = delete; - TupleShuffleArgEmitter(TupleShuffleArgEmitter &&) = delete; - TupleShuffleArgEmitter &operator=(TupleShuffleArgEmitter &&) = delete; + ArgumentShuffleEmitter(const ArgumentShuffleEmitter &) = delete; + ArgumentShuffleEmitter &operator=(const ArgumentShuffleEmitter &) = delete; + ArgumentShuffleEmitter(ArgumentShuffleEmitter &&) = delete; + ArgumentShuffleEmitter &operator=(ArgumentShuffleEmitter &&) = delete; void emit(ArgEmitter &parent); @@ -3548,7 +3548,7 @@ class TupleShuffleArgEmitter { VarargExpansionExpr *getVarargExpansion(unsigned innerIndex) { Expr *expr = inner->getSemanticsProvidingExpr(); - if (cast(outer)->isSourceScalar()) { + if (cast(outer)->isSourceScalar()) { assert(innerIndex == 0); } else { auto tuple = dyn_cast(expr); @@ -3561,7 +3561,7 @@ class TupleShuffleArgEmitter { } // end anonymous namespace -void TupleShuffleArgEmitter::constructInnerTupleTypeInfo(ArgEmitter &parent) { +void ArgumentShuffleEmitter::constructInnerTupleTypeInfo(ArgEmitter &parent) { unsigned nextParamIndex = 0; for (unsigned outerIndex : indices(outerElements)) { CanType substEltType = @@ -3596,7 +3596,7 @@ void TupleShuffleArgEmitter::constructInnerTupleTypeInfo(ArgEmitter &parent) { #endif innerExtents[innerIndex].Params = eltParams; origInnerElts[innerIndex] = origEltType; - } else if (innerIndex == TupleShuffleExpr::Variadic) { + } else if (innerIndex == ArgumentShuffleExpr::Variadic) { auto &varargsField = outerElements[outerIndex]; assert(varargsField.isVararg()); assert(!varargsInfo.hasValue() && "already had varargs entry?"); @@ -3669,7 +3669,7 @@ void TupleShuffleArgEmitter::constructInnerTupleTypeInfo(ArgEmitter &parent) { } } -void TupleShuffleArgEmitter::flattenPatternFromInnerExtendIntoInnerParams( +void ArgumentShuffleEmitter::flattenPatternFromInnerExtendIntoInnerParams( ArgEmitter &parent) { for (auto &extent : innerExtents) { assert(extent.Used && "didn't use all the inner tuple elements!"); @@ -3700,7 +3700,7 @@ void TupleShuffleArgEmitter::flattenPatternFromInnerExtendIntoInnerParams( } } -void TupleShuffleArgEmitter::splitInnerArgumentsCorrectly(ArgEmitter &parent) { +void ArgumentShuffleEmitter::splitInnerArgumentsCorrectly(ArgEmitter &parent) { ArrayRef nextArgs = innerArgs; MutableArrayRef nextDelayedArgs = innerDelayedArgs; for (auto &extent : innerExtents) { @@ -3725,7 +3725,7 @@ void TupleShuffleArgEmitter::splitInnerArgumentsCorrectly(ArgEmitter &parent) { assert(nextDelayedArgs.empty() && "didn't claim all inout args"); } -void TupleShuffleArgEmitter::emitDefaultArgsAndFinalize(ArgEmitter &parent) { +void ArgumentShuffleEmitter::emitDefaultArgsAndFinalize(ArgEmitter &parent) { unsigned nextCallerDefaultArg = 0; for (unsigned outerIndex = 0, e = outerElements.size(); outerIndex != e; ++outerIndex) { @@ -3750,7 +3750,7 @@ void TupleShuffleArgEmitter::emitDefaultArgsAndFinalize(ArgEmitter &parent) { // If this is default initialization, prepare to emit the default argument // generator later. - if (innerIndex == TupleShuffleExpr::DefaultInitialize) { + if (innerIndex == ArgumentShuffleExpr::DefaultInitialize) { // Otherwise, emit the default initializer, then map that as a // default argument. CanType eltType = outerElements[outerIndex].getType()->getCanonicalType(); @@ -3769,7 +3769,7 @@ void TupleShuffleArgEmitter::emitDefaultArgsAndFinalize(ArgEmitter &parent) { // If this is caller default initialization, generate the // appropriate value. - if (innerIndex == TupleShuffleExpr::CallerDefaultInitialize) { + if (innerIndex == ArgumentShuffleExpr::CallerDefaultInitialize) { auto arg = callerDefaultArgs[nextCallerDefaultArg++]; parent.emit(ArgumentSource(arg), getOutputOrigElementType(outerIndex)); @@ -3777,7 +3777,7 @@ void TupleShuffleArgEmitter::emitDefaultArgsAndFinalize(ArgEmitter &parent) { } // If we're supposed to create a varargs array with the rest, do so. - if (innerIndex == TupleShuffleExpr::Variadic) { + if (innerIndex == ArgumentShuffleExpr::Variadic) { auto &varargsField = outerElements[outerIndex]; assert(varargsField.isVararg() && "Cannot initialize nonvariadic element"); @@ -3807,7 +3807,7 @@ void TupleShuffleArgEmitter::emitDefaultArgsAndFinalize(ArgEmitter &parent) { } } -void TupleShuffleArgEmitter::emit(ArgEmitter &parent) { +void ArgumentShuffleEmitter::emit(ArgEmitter &parent) { // We could support dest addrs here, but it can't actually happen // with the current limitations on default arguments in tuples. assert(!parent.SpecialDests && "shuffle nested within varargs expansion?"); @@ -3848,7 +3848,7 @@ void TupleShuffleArgEmitter::emit(ArgEmitter &parent) { emitDefaultArgsAndFinalize(parent); } -void ArgEmitter::emitShuffle(TupleShuffleExpr *E, +void ArgEmitter::emitShuffle(ArgumentShuffleExpr *E, AbstractionPattern origParamType) { ArrayRef srcElts; TupleTypeElt singletonSrcElt; @@ -3864,7 +3864,7 @@ void ArgEmitter::emitShuffle(TupleShuffleExpr *E, srcElts = cast(srcEltTy)->getElements(); } - TupleShuffleArgEmitter(E, srcElts, origParamType).emit(*this); + ArgumentShuffleEmitter(E, srcElts, origParamType).emit(*this); } namespace { diff --git a/lib/SILGen/SILGenBuiltin.cpp b/lib/SILGen/SILGenBuiltin.cpp index 7aa928217194c..a5770c09dedd5 100644 --- a/lib/SILGen/SILGenBuiltin.cpp +++ b/lib/SILGen/SILGenBuiltin.cpp @@ -30,7 +30,7 @@ using namespace swift; using namespace Lowering; -static bool isTrivialShuffle(TupleShuffleExpr *shuffle) { +static bool isTrivialShuffle(ArgumentShuffleExpr *shuffle) { // Each element must be mapped to the corresponding element of the input. auto mapping = shuffle->getElementMapping(); for (auto index : indices(mapping)) { @@ -56,7 +56,7 @@ static ArrayRef decomposeArguments(SILGenFunction &SGF, // The use of owned parameters can trip up CSApply enough to introduce // a trivial tuple shuffle here. arg = arg->getSemanticsProvidingExpr(); - if (auto shuffle = dyn_cast(arg)) { + if (auto shuffle = dyn_cast(arg)) { if (isTrivialShuffle(shuffle)) arg = shuffle->getSubExpr(); } diff --git a/lib/SILGen/SILGenExpr.cpp b/lib/SILGen/SILGenExpr.cpp index 5fdaf5623c99b..48fc0f6358ba6 100644 --- a/lib/SILGen/SILGenExpr.cpp +++ b/lib/SILGen/SILGenExpr.cpp @@ -450,6 +450,7 @@ namespace { RValue visitDynamicSubscriptExpr(DynamicSubscriptExpr *E, SGFContext C); RValue visitTupleShuffleExpr(TupleShuffleExpr *E, SGFContext C); + RValue visitArgumentShuffleExpr(ArgumentShuffleExpr *E, SGFContext C); RValue visitDynamicTypeExpr(DynamicTypeExpr *E, SGFContext C); RValue visitCaptureListExpr(CaptureListExpr *E, SGFContext C); RValue visitAbstractClosureExpr(AbstractClosureExpr *E, SGFContext C); @@ -2288,19 +2289,14 @@ static void emitTupleShuffleExprInto(RValueEmitter &emitter, // Map outer initializations into a tuple of inner initializations: // - fill out the initialization elements with null TupleInitialization innerTupleInit; - if (E->isSourceScalar()) { - innerTupleInit.SubInitializations.push_back(nullptr); - } else { - CanTupleType innerTuple = - cast(E->getSubExpr()->getType()->getCanonicalType()); - innerTupleInit.SubInitializations.resize(innerTuple->getNumElements()); - } + + CanTupleType innerTuple = + cast(E->getSubExpr()->getType()->getCanonicalType()); + innerTupleInit.SubInitializations.resize(innerTuple->getNumElements()); // Map all the outer initializations to their appropriate targets. for (unsigned outerIndex = 0; outerIndex != outerInits.size(); outerIndex++) { auto innerMapping = E->getElementMapping()[outerIndex]; - assert(innerMapping >= 0 && - "non-argument tuple shuffle with default arguments or variadics?"); innerTupleInit.SubInitializations[innerMapping] = std::move(outerInits[outerIndex]); } @@ -2312,22 +2308,13 @@ static void emitTupleShuffleExprInto(RValueEmitter &emitter, #endif // Emit the sub-expression into the tuple initialization we just built. - if (E->isSourceScalar()) { - emitter.SGF.emitExprInto(E->getSubExpr(), - innerTupleInit.SubInitializations[0].get()); - } else { - emitter.SGF.emitExprInto(E->getSubExpr(), &innerTupleInit); - } + emitter.SGF.emitExprInto(E->getSubExpr(), &innerTupleInit); outerTupleInit->finishInitialization(emitter.SGF); } RValue RValueEmitter::visitTupleShuffleExpr(TupleShuffleExpr *E, SGFContext C) { - // FIXME: Once we're no longer using this code path for enum element payloads, - // also assert that !E->isSourceScalar(). - assert(!E->isResultScalar()); - // If we're emitting into an initialization, we can try shuffling the // elements of the initialization. if (Initialization *I = C.getEmitInto()) { @@ -2339,12 +2326,8 @@ RValue RValueEmitter::visitTupleShuffleExpr(TupleShuffleExpr *E, // Emit the sub-expression tuple and destructure it into elements. SmallVector elements; - if (E->isSourceScalar()) { - elements.push_back(visit(E->getSubExpr())); - } else { - visit(E->getSubExpr()).extractElements(elements); - } - + visit(E->getSubExpr()).extractElements(elements); + // Prepare a new tuple to hold the shuffled result. RValue result(E->getType()->getCanonicalType()); @@ -2358,11 +2341,6 @@ RValue RValueEmitter::visitTupleShuffleExpr(TupleShuffleExpr *E, "ran out of shuffle indexes before running out of fields?!"); int shuffleIndex = *shuffleIndexIterator++; - assert(shuffleIndex != TupleShuffleExpr::DefaultInitialize && - shuffleIndex != TupleShuffleExpr::CallerDefaultInitialize && - shuffleIndex != TupleShuffleExpr::Variadic && - "Only argument tuples can have default initializers & varargs"); - // Map from a different tuple element. result.addElement( std::move(elements[shuffleIndex]).ensurePlusOne(SGF, E)); @@ -2371,6 +2349,11 @@ RValue RValueEmitter::visitTupleShuffleExpr(TupleShuffleExpr *E, return result; } +RValue RValueEmitter::visitArgumentShuffleExpr(ArgumentShuffleExpr *E, + SGFContext C) { + llvm_unreachable("ArgumentShuffleExpr cannot appear in rvalue position"); +} + static SILValue emitMetatypeOfDelegatingInitExclusivelyBorrowedSelf( SILGenFunction &SGF, SILLocation loc, DeclRefExpr *dre, SILType metaTy) { SGFContext ctx; diff --git a/lib/Sema/CSApply.cpp b/lib/Sema/CSApply.cpp index 77e84dd38e1e9..4200a6fbe472b 100644 --- a/lib/Sema/CSApply.cpp +++ b/lib/Sema/CSApply.cpp @@ -5108,23 +5108,10 @@ Expr *ExprRewriter::coerceTupleToTuple(Expr *expr, TupleType *fromTuple, return expr; } - // computeTupleShuffle() produces an array of unsigned (since it can only - // contain tuple element indices). However TupleShuffleExpr is also used - // for call argument lists which can contain special things like default - // arguments and variadics; those are presented by negative integers. - // - // FIXME: Design and implement a new AST where argument lists are - // separate from rvalue tuple conversions. - ArrayRef sourcesRef = sources; - ArrayRef sourcesCast((const int *) sourcesRef.data(), - sourcesRef.size()); - // Create the tuple shuffle. return cs.cacheType(TupleShuffleExpr::create(tc.Context, - expr, sourcesCast, - TupleShuffleExpr::TupleToTuple, - ConcreteDeclRef(), {}, Type(), {}, + expr, sources, toSugarType)); } @@ -5532,7 +5519,7 @@ Expr *ExprRewriter::coerceCallArguments( sliceType = tc.getArraySliceType(arg->getLoc(), paramBaseType); toSugarFields.push_back( TupleTypeElt(sliceType, param.getLabel(), param.getParameterFlags())); - sources.push_back(TupleShuffleExpr::Variadic); + sources.push_back(ArgumentShuffleExpr::Variadic); // Convert the arguments. for (auto argIdx : parameterBindings[paramIdx]) { @@ -5582,9 +5569,9 @@ Expr *ExprRewriter::coerceCallArguments( if (defArg) { callerDefaultArgs.push_back(defArg); - sources.push_back(TupleShuffleExpr::CallerDefaultInitialize); + sources.push_back(ArgumentShuffleExpr::CallerDefaultInitialize); } else { - sources.push_back(TupleShuffleExpr::DefaultInitialize); + sources.push_back(ArgumentShuffleExpr::DefaultInitialize); } continue; } @@ -5722,7 +5709,7 @@ Expr *ExprRewriter::coerceCallArguments( /*canonicalVararg=*/false); // If we came from a scalar, create a scalar-to-tuple conversion. - TupleShuffleExpr::TypeImpact typeImpact; + ArgumentShuffleExpr::TypeImpact typeImpact; if (argTuple == nullptr) { // Deal with a difference in only scalar ownership. if (auto paramParenTy = dyn_cast(paramType.getPointer())) { @@ -5735,20 +5722,20 @@ Expr *ExprRewriter::coerceCallArguments( return cs.cacheType(argParen); } - typeImpact = TupleShuffleExpr::ScalarToTuple; + typeImpact = ArgumentShuffleExpr::ScalarToTuple; assert(isa(paramType.getPointer())); } else if (isa(paramType.getPointer())) { - typeImpact = TupleShuffleExpr::TupleToTuple; + typeImpact = ArgumentShuffleExpr::TupleToTuple; } else { - typeImpact = TupleShuffleExpr::TupleToScalar; + typeImpact = ArgumentShuffleExpr::TupleToScalar; assert(isa(paramType.getPointer())); } - // Create the tuple shuffle. - return cs.cacheType(TupleShuffleExpr::create(tc.Context, arg, sources, - typeImpact, callee, variadicArgs, - sliceType, callerDefaultArgs, - paramType)); + // Create the argument shuffle. + return cs.cacheType(ArgumentShuffleExpr::create(tc.Context, arg, sources, + typeImpact, callee, variadicArgs, + sliceType, callerDefaultArgs, + paramType)); } static ClosureExpr *getClosureLiteralExpr(Expr *expr) { @@ -7016,7 +7003,7 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType, return nullptr; } - if (auto shuffle = dyn_cast(arg)) + if (auto shuffle = dyn_cast(arg)) arg = shuffle->getSubExpr(); if (auto tuple = dyn_cast(arg)) @@ -7219,8 +7206,8 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType, // Extract all arguments. auto *CEA = arg; - if (auto *TSE = dyn_cast(CEA)) - CEA = TSE->getSubExpr(); + if (auto *ASE = dyn_cast(CEA)) + CEA = ASE->getSubExpr(); // The argument is either a ParenExpr or TupleExpr. ArrayRef arguments; diff --git a/lib/Sema/CSDiag.cpp b/lib/Sema/CSDiag.cpp index e4fa23e4aa999..0f4f99a718529 100644 --- a/lib/Sema/CSDiag.cpp +++ b/lib/Sema/CSDiag.cpp @@ -3533,7 +3533,7 @@ class ArgumentMatcher : public MatchCallArgumentListener { "unexpected argument expression type"); insertLoc = ArgExpr->getLoc(); - // Can't be TupleShuffleExpr because this argExpr is not yet resolved. + // Can't be ArgumentShuffleExpr because this argExpr is not yet resolved. } assert(insertLoc.isValid() && "missing argument after trailing closure?"); diff --git a/lib/Sema/MiscDiagnostics.cpp b/lib/Sema/MiscDiagnostics.cpp index e1a5d018c4737..8c26c7acb4277 100644 --- a/lib/Sema/MiscDiagnostics.cpp +++ b/lib/Sema/MiscDiagnostics.cpp @@ -145,9 +145,9 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E, if (isa(Base)) checkUseOfMetaTypeName(Base); - if (auto *TSE = dyn_cast(E)) { - if (CallArgs.count(TSE)) - CallArgs.insert(TSE->getSubExpr()); + if (auto *ASE = dyn_cast(E)) { + if (CallArgs.count(ASE)) + CallArgs.insert(ASE->getSubExpr()); } if (auto *SE = dyn_cast(E)) { @@ -331,8 +331,8 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E, fn) { // The argument could be shuffled if it includes default arguments, // label differences, or other exciting things like that. - if (auto *TSE = dyn_cast(arg)) - arg = TSE->getSubExpr(); + if (auto *ASE = dyn_cast(arg)) + arg = ASE->getSubExpr(); // The argument is either a ParenExpr or TupleExpr. if (auto *TE = dyn_cast(arg)) { @@ -2927,8 +2927,8 @@ void swift::fixItEncloseTrailingClosure(TypeChecker &TC, const CallExpr *call, Identifier closureLabel) { auto argsExpr = call->getArg(); - if (auto TSE = dyn_cast(argsExpr)) - argsExpr = TSE->getSubExpr(); + if (auto ASE = dyn_cast(argsExpr)) + argsExpr = ASE->getSubExpr(); SmallString<32> replacement; SourceLoc lastLoc; @@ -2983,8 +2983,8 @@ static void checkStmtConditionTrailingClosure(TypeChecker &TC, const Expr *E) { // Ignore invalid argument type. Some diagnostics are already emitted. if (!argsTy || argsTy->hasError()) return; - if (auto TSE = dyn_cast(argsExpr)) - argsExpr = TSE->getSubExpr(); + if (auto ASE = dyn_cast(argsExpr)) + argsExpr = ASE->getSubExpr(); SourceLoc closureLoc; if (auto PE = dyn_cast(argsExpr)) diff --git a/lib/Sema/PlaygroundTransform.cpp b/lib/Sema/PlaygroundTransform.cpp index 21065b6f96be7..c4e6778e4b094 100644 --- a/lib/Sema/PlaygroundTransform.cpp +++ b/lib/Sema/PlaygroundTransform.cpp @@ -344,8 +344,8 @@ class Instrumenter : InstrumenterBase { return dyn_cast( inout->getSubExpr()->getSemanticsProvidingExpr()); - // Drill through tuple shuffles, ignoring non-default-argument inouts. - } else if (auto shuffle = dyn_cast(E)) { + // Drill through argument shuffles, ignoring non-default-argument inouts. + } else if (auto shuffle = dyn_cast(E)) { return digForInoutDeclRef(shuffle->getSubExpr()); // Try to find a unique inout argument in a tuple. diff --git a/lib/Sema/TypeCheckAvailability.cpp b/lib/Sema/TypeCheckAvailability.cpp index 2c2fee41ea10d..24beba941ba06 100644 --- a/lib/Sema/TypeCheckAvailability.cpp +++ b/lib/Sema/TypeCheckAvailability.cpp @@ -1738,7 +1738,7 @@ static void fixItAvailableAttrRename(InFlightDiagnostic &diag, return labelStr.empty() ? Identifier() : ctx.getIdentifier(labelStr); }); - if (auto args = dyn_cast(argExpr)) { + if (auto args = dyn_cast(argExpr)) { argExpr = args->getSubExpr(); // Coerce the `argumentLabelIDs` to the user supplied arguments. @@ -1758,12 +1758,12 @@ static void fixItAvailableAttrRename(InFlightDiagnostic &diag, auto I = argumentLabelIDs.begin(); for (auto shuffleIdx : elementMap) { switch (shuffleIdx) { - case TupleShuffleExpr::DefaultInitialize: - case TupleShuffleExpr::CallerDefaultInitialize: + case ArgumentShuffleExpr::DefaultInitialize: + case ArgumentShuffleExpr::CallerDefaultInitialize: // Defaulted: remove param label of it. I = argumentLabelIDs.erase(I); break; - case TupleShuffleExpr::Variadic: { + case ArgumentShuffleExpr::Variadic: { auto variadicArgsNum = args->getVariadicArgs().size(); if (variadicArgsNum == 0) { // No arguments: Remove param label of it. diff --git a/lib/Sema/TypeCheckError.cpp b/lib/Sema/TypeCheckError.cpp index f5c4d198cfe42..60084c8c6b501 100644 --- a/lib/Sema/TypeCheckError.cpp +++ b/lib/Sema/TypeCheckError.cpp @@ -694,7 +694,7 @@ class ApplyClassifier { if (auto paramTupleType = dyn_cast(paramType.getPointer())) { if (auto tuple = dyn_cast(arg)) { return classifyTupleRethrowsArgument(tuple, paramTupleType); - } else if (auto shuffle = dyn_cast(arg)) { + } else if (auto shuffle = dyn_cast(arg)) { return classifyShuffleRethrowsArgument(shuffle, paramTupleType); } @@ -709,7 +709,7 @@ class ApplyClassifier { // FIXME: There's a case where we can end up with an ApplyExpr that // has a single-element-tuple argument type, but the argument is just - // a ClosureExpr and not a TupleExpr/TupleShuffleExpr. + // a ClosureExpr and not a TupleExpr/ArgumentShuffleExpr. paramType = paramTupleType->getElementType(0); } @@ -757,7 +757,7 @@ class ApplyClassifier { } /// Classify an argument to a 'rethrows' function that's a tuple shuffle. - Classification classifyShuffleRethrowsArgument(TupleShuffleExpr *shuffle, + Classification classifyShuffleRethrowsArgument(ArgumentShuffleExpr *shuffle, TupleType *paramTupleType) { auto reversedParamType = reverseShuffleParamType(shuffle, paramTupleType); @@ -777,8 +777,8 @@ class ApplyClassifier { // Otherwise, it might come from a default argument. It still // might contribute to 'rethrows', but treat it as an opaque source. - } else if (elt == TupleShuffleExpr::DefaultInitialize || - elt == TupleShuffleExpr::CallerDefaultInitialize) { + } else if (elt == ArgumentShuffleExpr::DefaultInitialize || + elt == ArgumentShuffleExpr::CallerDefaultInitialize) { result.merge(classifyArgumentByType(paramTupleType->getElementType(i), PotentialReason::forDefaultArgument())); } @@ -790,7 +790,7 @@ class ApplyClassifier { /// Given a tuple shuffle and an original parameter type, construct /// the type of the source of the tuple shuffle preserving as much /// information as possible from the original parameter type. - Type reverseShuffleParamType(TupleShuffleExpr *shuffle, + Type reverseShuffleParamType(ArgumentShuffleExpr *shuffle, TupleType *origParamTupleType) { SmallVector origSrcElts; if (shuffle->isSourceScalar()) { @@ -805,10 +805,10 @@ class ApplyClassifier { auto srcIndex = mapping[destIndex]; if (srcIndex >= 0) { origSrcElts[srcIndex] = origParamTupleType->getElement(destIndex); - } else if (srcIndex == TupleShuffleExpr::DefaultInitialize || - srcIndex == TupleShuffleExpr::CallerDefaultInitialize) { + } else if (srcIndex == ArgumentShuffleExpr::DefaultInitialize || + srcIndex == ArgumentShuffleExpr::CallerDefaultInitialize) { // Nothing interesting from the source expression. - } else if (srcIndex == TupleShuffleExpr::Variadic) { + } else if (srcIndex == ArgumentShuffleExpr::Variadic) { // Variadic arguments never contribute to 'rethrows'. // Assign the rest of the source elements parameter types that will // cause the recursive walker to ignore them.