-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Kill ArgumentShuffleExpr #23672
Conversation
91ea9a8
to
70b23aa
Compare
@@ -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); |
There was a problem hiding this comment.
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.
70b23aa
to
478c133
Compare
@swift-ci Please smoke test |
@swift-ci Please test source compatibility |
Nice! |
@rjmccall FWIW, I realized I might want to bring back the ArgSpecialDest stuff... if would help tidy up enum constructor call emission with payloads. |
I was wondering about that. |
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.