Skip to content

[TypeChecker] Adjust Double<->CGFloat conversion to always preserve its location #59762

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 2 commits into from
Jun 29, 2022

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Jun 28, 2022

Unfortunately current approach of making a conversion independent of location
doesn't work when conversion is required for multiple arguments to the
same call because solver expects that either there are no Double<->CGFloat
conversions, or one of them has already been applied which is not the case.

The reason why locations weren't preserved in the first place is due to
how a solution is applied to AST - AST is mutated first and then, if there
are any conversions, they are applied to the already mutated version of
original AST. This creates a problem for Double<->CGFloat which depends
on an overload choice of injected call and it's impossible to find it based
on the mutated AST. But it turns out that this is only an issue in two
specific cases - conversions against contextual type and after optional injection.
This situations could be mitigated by dropping parts of the locator which are
unimportant for the Double<->CGFloat conversion - anchor in case of contextual
and OptionalPayload element(s) in case of optional injection.

Resolves: #59374

xedin added 2 commits June 28, 2022 13:07
Before these changes filtering would not favor some members because their
function types have `escaping` bit set when argument function type never
has it.

Double/CGFloat implicit conversion is one of such cases where `CGFloat.init`
overloads have `escaping` bit, which leads to solver checking more overloads
then it should.

Note that the difference in effects such as `async` is going to be handled
by scoring and ranking after partial solution is produced, so overloads that
differ only in `async` or `throws` are still going to be solved for as part
of "favored" set.
…ts location

Unfortunately current approach of making a conversion independent of location
doesn't work when conversion is required for multiple arguments to the
same call because solver expects that either there are no Double<->CGFloat
conversions, or one of them has already been applied which is not the case.

The reason why locations weren't preserved in the first place is due to
how a solution is applied to AST - AST is mutated first and then, if there
are any conversions, they are applied to the already mutated version of
original AST. This creates a problem for Double<->CGFloat which depends
on an overload choice of injected call and it's impossible to find it based
on the mutated AST. But it turns out that this is only an issue in two
specific cases - conversions against contextual type and after optional injection.
This situations could be mitigated by dropping parts of the locator which are
unimportant for the Double<->CGFloat conversion - anchor in case of contextual
and `OptionalPayload` element(s) in case of optional injection.

Resolves: swiftlang#59374
@xedin xedin requested a review from hborla June 28, 2022 20:59
@xedin
Copy link
Contributor Author

xedin commented Jun 28, 2022

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Jun 28, 2022

@swift-ci please test source compatibility

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.

Assert in swiftc while typechecking a function in a blockbuiler
2 participants