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

[SE-0284] Allow Multiple Variadic Parameters in Functions, Subscripts, and Initializers #29735

Merged
merged 1 commit into from Sep 5, 2020

Conversation

owenv
Copy link
Collaborator

@owenv owenv commented Feb 10, 2020

The restriction that the argument following a variadic argument must have a label is still in place. This allows the following:

func twoVariadics(_ a: Int..., b: Int...) { }
func splitUnlabeledVariadics(_ a: Int..., b: Int, _ c: String...) { }

Because varargs get automatic default expressions of [], the following is also allowed right now, and maybe shouldn't be:

func splitByDefaultArgVariadics(_ a: Int..., b: Int = 0, _ c: Int...) { }
splitByDefaultArgVariadics(1,2,3, b: 4, 5, 6, 7) // a is [1,2,3], b is 4, c is [5,6,7]
splitByDefaultArgVariadics(1,2,3) // a is [1,2,3], b is 0, c is []

The alternative is to just require every vararg have a label if there's more than one, which won't be difficult to enforce if that ends up being preferable.

@owenv owenv changed the title [DNM] Experiment: Lift the 1-vararg-per-function restriction [DNM, Draft] Experiment: Lift the 1-vararg-per-function restriction Feb 10, 2020
@owenv
Copy link
Collaborator Author

owenv commented Feb 10, 2020

Oops, I meant to submit this as a draft

@owenv owenv added the swift evolution pending discussion Flag → feature: A feature that has a Swift evolution proposal currently in review label Feb 10, 2020
@theblixguy
Copy link
Collaborator

Nice. Does this SILGen and run properly as well?

@owenv
Copy link
Collaborator Author

owenv commented Feb 10, 2020

@theblixguy yep, although I need to write some tests for it at some point :). Everything just gets passed around in Arrays so having 2+ hasn’t been a problem.

@owenv owenv changed the title [DNM, Draft] Experiment: Lift the 1-vararg-per-function restriction [Pending-Evolution] Lift the 1-vararg-per-function restriction Feb 11, 2020
@owenv
Copy link
Collaborator Author

owenv commented Feb 12, 2020

@swift-ci please test

@owenv
Copy link
Collaborator Author

owenv commented Feb 12, 2020

@swift-ci please test source compatibility

@owenv
Copy link
Collaborator Author

owenv commented Feb 12, 2020

That’s odd, I’m seeing some unexpected passes on the source compatibility suite...

@owenv
Copy link
Collaborator Author

owenv commented Feb 15, 2020

Let's see if we might be able to get away with making the following declarations an error:

subscript(a: Int..., b: Int)
let closure = {(a: Int..., b: Int) in}

These are allowed today because of a bug, but there's no way to successfully call them. It's also possible to write:

subscript(a: Int..., b: Int = 1)

which can be called (but b can't be manually specified), but really shouldn't be allowed.

If the source break is too large, I'll probably try to make these at least a warning as part of the proposal.

@owenv
Copy link
Collaborator Author

owenv commented Feb 15, 2020

@swift-ci please test

@owenv
Copy link
Collaborator Author

owenv commented Feb 15, 2020

@swift-ci please test source compatibility

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@owenv
Copy link
Collaborator Author

owenv commented Feb 16, 2020

Looks like swift-nio and swift-nio-extras are the only failures and are affecting other PRs as well.

@owenv
Copy link
Collaborator Author

owenv commented Mar 25, 2020

@swift-ci please test

@owenv
Copy link
Collaborator Author

owenv commented Mar 25, 2020

@swift-ci please test source compatibility

@swift-ci
Copy link
Collaborator

Build failed
Swift Test Linux Platform
Git Sha - 42c8912afa199741f6566f90bff9e0c5eae6b02c

@owenv
Copy link
Collaborator Author

owenv commented Mar 25, 2020

@swift-ci please test Linux

@owenv owenv force-pushed the multiple-varargs branch 2 times, most recently from c0d931a to a83f19b Compare May 30, 2020 23:46
@owenv
Copy link
Collaborator Author

owenv commented May 30, 2020

rebasing on recent changes

@swift-ci please test

@owenv
Copy link
Collaborator Author

owenv commented May 30, 2020

@swift-ci please test source compatibility

@swift-ci
Copy link
Collaborator

Build failed
Swift Test Linux Platform
Git Sha - a83f19b7f0f5ee61325646ce5b383ac8fc649ce2

@owenv
Copy link
Collaborator Author

owenv commented Jul 19, 2020

@swift-ci test

@owenv
Copy link
Collaborator Author

owenv commented Jul 19, 2020

@swift-ci test source compatibility

@apple apple deleted a comment from swift-ci Jul 19, 2020
@owenv
Copy link
Collaborator Author

owenv commented Jul 19, 2020

@swift-ci please test Linux

@owenv owenv requested review from CodaFi and rintaro July 20, 2020 02:32
Copy link
Member

@rintaro rintaro left a comment

Choose a reason for hiding this comment

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

Parser changes looks great 👍
Could you add some test cases in test/Syntax/round_trip_parse_gen.swift?

let closure2 = {(x: Int..., y: Int) in } // expected-error {{no parameters may follow a variadic parameter in a closure}}
let closure3 = {(x: Int..., y: Int, z: Int...) in } // expected-error {{no parameters may follow a variadic parameter in a closure}}
let closure4 = {(x: Int...) in }
let closure5 = {(x: Int, y: Int...) in }
Copy link
Member

Choose a reason for hiding this comment

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

I guess {(x: Int..., y z: Int) in } is still diagnosed as error: closure cannot have keyword arguments, but it should be error: no parameters may follow a variadic parameter in a closure because removing the argument label doesn't resolve the issue.

It would be great if we can improve this. (not in this PR)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added a test case for this, right now both diagnostics are emitted.

@owenv
Copy link
Collaborator Author

owenv commented Jul 21, 2020

@swift-ci smoke test

@rintaro
Copy link
Member

rintaro commented Jul 21, 2020

@swift-ci Please smoke test macOS

Copy link
Member

@rintaro rintaro left a comment

Choose a reason for hiding this comment

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

Parser change looks good.

@rintaro
Copy link
Member

rintaro commented Jul 21, 2020

@swift-ci Please smoke test macOS

@owenv
Copy link
Collaborator Author

owenv commented Jul 24, 2020

@swift-ci please test Windows platform

[SE-0284] Add round_trip_parse_gen tests

[SE-0284] Add missing test cases
@owenv
Copy link
Collaborator Author

owenv commented Aug 24, 2020

@swift-ci test

@owenv
Copy link
Collaborator Author

owenv commented Aug 24, 2020

I added a couple more argument matching tests for forward matching of multiple trailing closures + multiple varargs now that SE-286 is implemented.

@xedin do you mind reviewing the argument matching test cases before this is merged? There aren't any code changes to argument matching, but I want to make sure I haven't missed any newly introduced edge cases

@owenv owenv requested a review from xedin August 24, 2020 04:41
@xedin
Copy link
Member

xedin commented Aug 24, 2020

@owenv Sure, I'll take a look as soon as possible!

Copy link
Member

@xedin xedin left a comment

Choose a reason for hiding this comment

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

Tests look reasonable to me!

@owenv
Copy link
Collaborator Author

owenv commented Sep 4, 2020

Thanks for all the help on this @rintaro and @xedin!

@owenv
Copy link
Collaborator Author

owenv commented Sep 4, 2020

Rerunning tests before I merge this since the master-rebranch merge happened recently

@swift-ci test

@owenv
Copy link
Collaborator Author

owenv commented Sep 4, 2020

@swift-ci please test source compatibility

@swift-ci
Copy link
Collaborator

swift-ci commented Sep 4, 2020

Build failed
Swift Test Linux Platform
Git Sha - 9708247

@owenv
Copy link
Collaborator Author

owenv commented Sep 4, 2020

@swift-ci please test Linux platform

@owenv
Copy link
Collaborator Author

owenv commented Sep 5, 2020

Looks like the debug source compatibility failures (BlueSocket and ReactiveCocoa) are also happening in all other PRs from the past few days, so unrelated to this change.

@owenv owenv merged commit c6a266e into apple:master Sep 5, 2020
@rintaro
Copy link
Member

rintaro commented Sep 5, 2020

@owenv Thank you! Could you update CHANGELOG.md as well?

@owenv owenv mentioned this pull request Sep 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
swift evolution approved Flag → feature: A feature that was approved through the Swift evolution process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants