Skip to content

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

Merged
merged 4 commits into from
Apr 6, 2018

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Apr 1, 2018

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.

@slavapestov
Copy link
Contributor Author

@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?

@jrose-apple
Copy link
Contributor

I still would say no but I defer to @DougGregor (including @DougGregor deciding either the core team or the forums needs to discuss it).

@DougGregor
Copy link
Member

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.

Copy link
Member

@DougGregor DougGregor left a 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.

@slavapestov slavapestov force-pushed the se-0193-default-args branch from b753e55 to 121288c Compare April 5, 2018 23:10
@slavapestov slavapestov changed the title Sema: Default argument diagnostics can now talk about @usableFromInline SE-0193: Public default argument generators cannot reference declarations that are @usableFromInline Apr 5, 2018
@slavapestov slavapestov force-pushed the se-0193-default-args branch from 121288c to 9ca34c8 Compare April 5, 2018 23:17
…ine references are allowed

For now, always true, soon, default arguments of public functions
will return false here.
@slavapestov slavapestov force-pushed the se-0193-default-args branch from 9ca34c8 to 9cc1a50 Compare April 5, 2018 23:49
@slavapestov slavapestov force-pushed the se-0193-default-args branch from 9cc1a50 to 96901f1 Compare April 5, 2018 23:56
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

Copy link
Contributor

@jrose-apple jrose-apple left a 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.)

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov slavapestov merged commit a4b91d2 into swiftlang:master Apr 6, 2018
tshortli added a commit to tshortli/swift that referenced this pull request Jul 11, 2023
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.
tshortli added a commit to tshortli/swift that referenced this pull request Jul 12, 2023
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.
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