Skip to content

[SR-2705][Sema] Always favor non-autoclosure parameter function overload on ranking #36076

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

Conversation

LucianoPAlmeida
Copy link
Contributor

Implement a rule on ranking where overload choices that has @autoclosure parameters are disfavored over the ones that aren't to avoid ambiguity in situations like

func f<T>(_: () -> T) {}
func f<T>(_: @autoclosure () -> T) {}

f { } // ok

Resolves SR-2705.

@LucianoPAlmeida
Copy link
Contributor Author

@swift-ci Please smoke test

@LucianoPAlmeida
Copy link
Contributor Author

@swift-ci Please smoke test macOS platform

@LucianoPAlmeida
Copy link
Contributor Author

@swift-ci Please smoke test Linux platform

Copy link
Contributor

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

I think CSRanking might be too big of a hammer here, how about we either increment an existing score kind i.e. SK_FunctionConversion or add a new kind to use specifically for situations when closure is an argument for autoclosure coversion?

@LucianoPAlmeida LucianoPAlmeida force-pushed the SR-2705-ranking-autoclosure branch from 3724e44 to 1c86133 Compare February 23, 2021 03:50
@LucianoPAlmeida
Copy link
Contributor Author

I think CSRanking might be too big of a hammer here, how about we either increment an existing score kind i.e. SK_FunctionConversion or add a new kind to use specifically for situations when closure is an argument for autoclosure coversion?

Thanks, I've updated and that indeed feels like a better solution :)

Copy link
Contributor

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

Definitely looks better now! I think we should add a new ScoreKind at the end of the list though to make sure that it doesn’t interfere in ranking too much since SK_FunctionConversion seems too high of a priority for this...

…ersion to increase impact of a function to autoclosure
@LucianoPAlmeida
Copy link
Contributor Author

I think we should add a new ScoreKind at the end of the list though to make sure that it doesn’t interfere in ranking too much since SK_FunctionConversion seems too high of a priority for this...

That makes sense, changes done :)

Copy link
Contributor

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

I think we are almost there just need a couple of final changes to tests.

Copy link
Contributor

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

Great work, thank you!

@LucianoPAlmeida LucianoPAlmeida force-pushed the SR-2705-ranking-autoclosure branch from 5046f27 to 419baee Compare February 23, 2021 23:43
@LucianoPAlmeida
Copy link
Contributor Author

@swift-ci Please smoke test

@xedin
Copy link
Contributor

xedin commented Feb 23, 2021

@swift-ci please test source compatibility debug

@LucianoPAlmeida
Copy link
Contributor Author

Windows is failing, that may started before that #36107 was merged, let's try again

@swift-ci Please test Windows Platform

@LucianoPAlmeida LucianoPAlmeida merged commit 8b0b89e into swiftlang:main Feb 24, 2021
@LucianoPAlmeida LucianoPAlmeida deleted the SR-2705-ranking-autoclosure branch February 24, 2021 10:00
@LucianoPAlmeida
Copy link
Contributor Author

Thanks @xedin!

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