-
Notifications
You must be signed in to change notification settings - Fork 10.5k
SE-0193: Public default argument generators cannot reference declarations that are @usableFromInline #15666
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-0193: Public default argument generators cannot reference declarations that are @usableFromInline #15666
Conversation
@DougGregor @jrose-apple Can you two decide if we're taking this change, or if we're going to only allow public functions to be referenced from default arguments? |
I still would say no but I defer to @DougGregor (including @DougGregor deciding either the core team or the forums needs to discuss it). |
The patch looks good, but I feel like we need core team approval to go ahead and merge it. I'll add it to the agenda for the upcoming meeting. |
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.
The Core Team discussed this today and decided that default arguments should not be able to reference @usableFromInline
entities that would otherwise be inaccessible. In other words, default arguments should follow the access-control rules strictly.
b753e55
to
121288c
Compare
121288c
to
9ca34c8
Compare
…ine references are allowed For now, always true, soon, default arguments of public functions will return false here.
9ca34c8
to
9cc1a50
Compare
…ions that are @usableFromInline
9cc1a50
to
96901f1
Compare
@swift-ci Please smoke test |
@swift-ci Please test source compatibility |
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.
Thanks, this new version looks good. (We did some back-and-forth on internal chat.)
@swift-ci Please test source compatibility |
The restriction that default arguments be disallowed from accessing `@usableFromInline` decls is overbearing for library developers who need to write non-trivial code to compute a default value, since it forces them to either write a verbose closure inline in the function signature or expose a `public` helper function which unnecessarily expands API surface. A `@usableFromInline` function a more reasonable way to encapsulate a verbose default value computation. This reverses the semantic changes included in swiftlang#15666. Resolves rdar://112093794.
The restriction that default arguments be disallowed from accessing `@usableFromInline` decls is overbearing for library developers who need to write non-trivial code to compute a default value, since it forces them to either write a verbose closure inline in the function signature or expose a `public` helper function which unnecessarily expands API surface. A `@usableFromInline` function a more reasonable way to encapsulate a verbose default value computation. This reverses the semantic changes included in swiftlang#15666. Resolves rdar://112093794.
Refactor resilience diagnostics to enforce more restrictions on default argument expressions of public functions. They can only reference other public declarations, and not @usableFromInline declarations.
This is a source-breaking change from Swift 4.1, where public default argument expressions could reference @_versioned declarations; hopefully nobody relied on that, but it would be easy enough to add an
isSwiftVersionAtLeast(5)
check in there if we have to.