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

SILGen: Kill "scalar" PreparedArguments #23650

Merged

Conversation

slavapestov
Copy link
Contributor

The PreparedArguments abstraction could be used in two ways: you could either build it from a decomposed argument list with one expression per argument, or build a "scalar" one with a single expression for all the arguments.

This PR removes the "scalar" case, except when the expression is an ArgumentShuffleExpr. That's not a problem because my next PR will completely remove ArgumentShuffleExpr.

@slavapestov slavapestov requested a review from rjmccall March 29, 2019 03:23
VarargExpansionExpr shows up in call argument lists in synthesized
initializers and modify accessors when we need to forward arguments
to a call taking varargs.

Previously we would say that the type of VarargExpansionExpr is
$T when its subexpression type is [$T]. matchCallArguments() would
then 'collect' the single VarargExpansionExpr into a variadic
argument list with a single element, and build an ArgumentShuffleExpr
for the argument list.

In turn, SILGen would peephole vararg emission of a variadic
argument list with a single entry that happens to be a
VarargExpansionExpr, by returning the subexpression's value,
which happened to be an array of the right element type,
instead of building a new array containing the elements of the
variadic argument list.

This was all too complicated. Instead, let's say that the type of
a VarargExpansionExpr is [$T], except that when it appears in a
TupleExpr, the variadic bit of the corresponding element is set.

Then, matchCallArguments() needs to support a case where both
the parameter and argument list have a matching vararg element.
In this case, instead of collecting multiple arguments into a
single variadic argument list, we treat the variadic argument like
an ordinary parameter, bypassing construction of the
ArgumentShuffleExpr altogether.

Finally, SILGen now needs to be able to emit a VarargExpansionExpr
in ordinary rvalue position, since it now appears as a child of a
TupleExpr; it can do this by simply emitting the sub-expression
to produce an array value.
This is equivalent to the trivial case of an ArrayExpr with the
Array.init(arrayLiteral: T...) initializer; it will be used by
CSApply to build vararg arrays.
This introduces a bit of repetition for now, but I'm going to factor
it out a different way later.
…uments

This eliminates another place where we built "scalar" PreparedArguments.
…fleExpr

For anything else, we can decompose the argument list on the spot.

Note that builtins that are implemented as EarlyEmitters now take a
the argument list as a PreparedArguments instead of a single Expr.

Since the PreparedArguments can still be a scalar with an
ArgumentShuffleExpr, we have to jump through some hoops to turn
it into a list of argument Exprs. This will all go away soon.
They still exist when an ArgumentShuffleExpr is decomposed, but that's
about to go away.
@slavapestov slavapestov force-pushed the kill-scalar-prepared-arguments branch from 2b0ff1f to 1417647 Compare March 29, 2019 03:24
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 1417647

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test macOS

@slavapestov slavapestov merged commit a823e48 into swiftlang:master Mar 29, 2019
@compnerd
Copy link
Member

compnerd commented Mar 29, 2019

This broke the MSVC build (#23670)

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