Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kill ArgumentShuffleExpr #23672

Merged
merged 3 commits into from
Mar 31, 2019

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Mar 29, 2019

This completes a refactoring that simplifies our call argument expressions.

In Swift 5, we used a rather complex TupleShuffleExpr to represent tuple conversions as well as call arguments containing varargs and default arguments. This included array literals, which were a degenerate case of varargs.

In #23591 I split up TupleShuffleExpr into DestructureTupleExpr (for tuple conversions) and ArgumentShuffleExpr (for argument lists containing default arguments and varargs).

However ArgumentShuffleExpr was still far too general. Ever since https://github.com/apple/swift-evolution/blob/master/proposals/0060-defaulted-parameter-order.md was accepted for Swift 3.0, we always evaluate arguments in the order they're written in the source, so the "shuffling" part was never taken advantage of.

Recently @pschuh implemented a way to form arrays directly in SIL by lowering an ArrayExpr, without using an ArgumentShuffleExpr. This work landed in #23618.

This meant that Sema could now collect varargs into a single ArrayExpr, without using an ArgumentShuffleExpr. The only remaining case where an ArgumentShuffleExpr was needed was argument lists with default arguments.

I did some preliminary refactoring in #23650, to ensure that all argument lists are split up into individual argument expressions when building the PreparedArguments object.

This PR builds on top of that by introducing a DefaultArgumentExpr and CallerDefaultArgumentExpr. Now Sema knows how to build argument lists containing ArrayExpr for varargs, and DefaultArgumentExpr and CallerDefaultArgumentExpr for default arguments. SILGen's ArgEmitter now knows how to directly emit delayed arguments, without going through the ArgumentShuffleExpr code path.

Note that after this change, all CallExprs now have a ParenExpr or TupleExpr as their argument. So the next step is 'flattening' the representation so that a CallExpr can hold multiple argument expressions.

@slavapestov slavapestov force-pushed the kill-argument-shuffle-expr branch 2 times, most recently from 91ea9a8 to 70b23aa Compare March 29, 2019 21:53
@slavapestov slavapestov requested a review from rjmccall March 29, 2019 22:01
@@ -5428,7 +5339,7 @@ inline bool ApplyExpr::validateArg(Expr *e) const {
else if (isa<BinaryExpr>(this))
return isa<TupleExpr>(e);
else
return isa<ParenExpr>(e) || isa<TupleExpr>(e) || isa<ArgumentShuffleExpr>(e);
return isa<ParenExpr>(e) || isa<TupleExpr>(e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been waiting for this day since I first added ApplyExpr::validateArg(). 🎉

Instead of building ArgumentShuffleExprs, lets just build a TupleExpr,
with explicit representation of collected varargs and default
arguments.

This isn't quite as elegant as it should be, because when re-typechecking,
SanitizeExpr needs to restore the 'old' parameter list by stripping out
the nodes inserted by type checking. However that hackery is all isolated
in one place and will go away soon.

Note that there's a minor change the generated SIL. Caller default
arguments (#file, #line, etc) are no longer delayed and are instead
evaluated in their usual argument position. I don't believe this actually
results in an observable change in behavior, but if it turns out to be
a problem, we can pretty easily change it back to the old behavior with a
bit of extra work.
@slavapestov slavapestov force-pushed the kill-argument-shuffle-expr branch from 70b23aa to 478c133 Compare March 31, 2019 05:58
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov slavapestov merged commit 8975875 into swiftlang:master Mar 31, 2019
@rjmccall
Copy link
Contributor

rjmccall commented Apr 1, 2019

Nice!

@slavapestov
Copy link
Contributor Author

@rjmccall FWIW, I realized I might want to bring back the ArgSpecialDest stuff... if would help tidy up enum constructor call emission with payloads.

@rjmccall
Copy link
Contributor

rjmccall commented Apr 2, 2019

I was wondering about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants