Skip to content

Sema: Correctly treat overloads in unavailable extensions as unavailable #77258

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

Conversation

tshortli
Copy link
Contributor

@tshortli tshortli commented Oct 28, 2024

Instead of checking for unavailability attributes directly in the solver, which does not correctly handle members of unavailable extensions, query checkDeclarationAvailability() instead. By using the same underlying logic as the availability checker the constraint solver can be confident in the accuracy of this result.

Now that availability of overloads is being checked consistently, an ambiguity in Embedded Swift has been revealed. Functions like fatalError() have overloads for Embedded Swift only that take StaticString instead of String, since String is unavailable. Unfortunately, many of these overloads create the opportunity for ambiguity in certain unavailable contexts. The easiest way to avoid the ambiguities is to mark each of the overloads taking String as @_disfavoredOverload. Another approach that could work would be to remove the default arguments from the String variants in Embedded Swift only, but that would create even more duplication of source code so it doesn't seem worth it.

Resolves rdar://87403752.

@tshortli tshortli requested a review from slavapestov October 28, 2024 21:28
@tshortli tshortli requested review from hborla and xedin as code owners October 28, 2024 21:28
@tshortli
Copy link
Contributor Author

@swift-ci please smoke test

@tshortli
Copy link
Contributor Author

Looks like I will need to resolve an ambiguity error that arises in Embedded Swift first. Because @_unavailableInEmbedded is just sugar for @available(*, unavailable), that mode allows universally unavailable functions to call other universally unavailable functions (normally this is disallowed). It seems we were skating by with the previously incorrect Constraint Solver logic but now there are some ambiguities.

@tshortli
Copy link
Contributor Author

tshortli commented Nov 1, 2024

This is now close to being unblocked. These need to land first:

#77307
#77316

Functions like `fatalError()` have overloads for Embedded Swift only that take
StaticString instead of String, since String is unavailable. Unfortunately,
many of these overloads create the opportunity for ambiguity in certain
contexts. The easiest way to avoid the ambiguities is to mark each of the
overloads taking `String` as `@_disfavoredOverload`. Another approach that
could work would be to remove the default arguments from the `String` variants
in Embedded Swift only, but that would create even more duplication of source
code so it doesn't seem worth it.
@tshortli tshortli force-pushed the discard-overloads-in-unavailable-extensions-in-constraint-solver branch from 007b7e0 to 91d73b2 Compare November 2, 2024 17:41
@tshortli tshortli requested a review from kubamracek November 2, 2024 17:46
@tshortli tshortli marked this pull request as ready for review November 2, 2024 17:46
@tshortli tshortli requested a review from a team as a code owner November 2, 2024 17:46
@tshortli tshortli force-pushed the discard-overloads-in-unavailable-extensions-in-constraint-solver branch from 91d73b2 to 1bededa Compare November 2, 2024 22:53
…ble.

Instead of checking for unavailability attributes directly in the solver, which
does not correctly handle members of unavailable extensions, query
`checkDeclarationAvailability()` instead. By using the same underlying logic as
the availability checker the constraint solver can be confident in the accuracy
of this result.

Resolves rdar://87403752.
@tshortli tshortli force-pushed the discard-overloads-in-unavailable-extensions-in-constraint-solver branch from 1bededa to 98b34c6 Compare November 3, 2024 00:16
@tshortli
Copy link
Contributor Author

tshortli commented Nov 3, 2024

@swift-ci please test

@tshortli
Copy link
Contributor Author

tshortli commented Nov 3, 2024

@swift-ci please test source compatibility

@tshortli tshortli merged commit e089c58 into swiftlang:main Nov 3, 2024
7 checks passed
@tshortli tshortli deleted the discard-overloads-in-unavailable-extensions-in-constraint-solver branch November 3, 2024 05:56
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.

2 participants