AST: Split off ArgumentShuffleExpr from TupleShuffleExpr

Right now we use TupleShuffleExpr for two completely different things:

- Tuple conversions, where elements can be re-ordered and labels can be
  introduced/eliminated
- Complex argument lists, involving default arguments or varargs

The first case does not allow default arguments or varargs, and the
second case does not allow re-ordering or introduction/elimination
of labels. Furthermore, the first case has a representation limitation
that prevents us from expressing tuple conversions that change the
type of tuple elements.

For all these reasons, it is better if we use two separate Expr kinds
for these purposes. For now, just make an identical copy of
TupleShuffleExpr and call it ArgumentShuffleExpr. In CSApply, use
ArgumentShuffleExpr when forming the arguments to a call, and keep
using TupleShuffleExpr for tuple conversions. Each usage of
TupleShuffleExpr has been audited to see if it should instead look at
ArgumentShuffleExpr.

In sequent commits I plan on redesigning TupleShuffleExpr to correctly
represent all tuple conversions without any unnecessary baggage.

Longer term, we actually want to change the representation of CallExpr
to directly store an argument list; then instead of a single child
expression that must be a ParenExpr, TupleExpr or ArgumentShuffleExpr,
all CallExprs will have a uniform representation and ArgumentShuffleExpr
will go away altogether. This should reduce memory usage and radically
simplify parts of SILGen.
This commit is contained in:
Slava Pestov
2019-03-21 00:51:41 -04:00
parent 8fcd4e6ee3
commit d470e9df4d
19 changed files with 391 additions and 102 deletions

View File

@@ -2856,8 +2856,8 @@ static CallExpr *findTrailingClosureTarget(SourceManager &SM,
if (!Args)
return nullptr;
Expr *LastArg;
if (auto *TSE = dyn_cast<TupleShuffleExpr>(Args))
Args = TSE->getSubExpr();
if (auto *ASE = dyn_cast<ArgumentShuffleExpr>(Args))
Args = ASE->getSubExpr();
if (auto *PE = dyn_cast<ParenExpr>(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<TupleShuffleExpr>(Args))
Args = TSE->getSubExpr();
if (auto *ASE = dyn_cast<ArgumentShuffleExpr>(Args))
Args = ASE->getSubExpr();
Expr *ClosureArg = nullptr;
Expr *PrevArg = nullptr;