Skip to content

Warn about async-imported selector conflicts #59743

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

beccadax
Copy link
Contributor

The change in #59479 inadvertently fixed another bug in selector conflict checking: Swift did not notice when an ObjC header declared an async-imported method, but a Swift extension to the same class added another method with the same selector. Unfortunately, fixing this bug was source-breaking, and it also caused Swift to diagnose spurious conflicts between the various names that a single ObjC method might be imported with. Soften the error to a warning in Swift 5 mode and suppress the spurious diagnostics.

Fixes rdar://95887113.

The change in swiftlang#59479 inadvertently fixed another bug in selector conflict checking: Swift did not notice when an ObjC header declared an async-imported method, but a Swift extension to the same class added another method with the same selector. Unfortunately, fixing this bug was source-breaking, and it also caused Swift to diagnose spurious conflicts between the various names that a single ObjC method might be imported with. Soften the error to a warning in Swift 5 mode and suppress the spurious diagnostics.

Fixes rdar://95887113.
@beccadax beccadax requested a review from kavon June 28, 2022 09:07
@beccadax
Copy link
Contributor Author

@swift-ci please smoke test

@beccadax
Copy link
Contributor Author

@swift-ci please test source compatibility

Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Been a little while since I've worked in this area, I'm not sure I fully understand why this issue doesn't come up for the non-async-alternative imported version, but this LGTM modulo the question on ordering.

Copy link
Member

@kavon kavon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Have a question though!

Refactor ObjC conflict diagnosis code to sort conflict data more thoroughly, filter out unwanted declarations earlier, and just generally behave in ways that are more likely to work correctly.

This change increases the determinism of the ordering of diagnostics and the selection of the “correct” declaration that the others are considered to conflict with, increasing my confidence that the diagnostics will work correctly in untested corner cases or if the compiler is refactored so that declarations are recorded in a different order. It also adds a new selection rule—@objc without vs. with explicit selector—that I believe will slightly improve the diagnostics we produce. And it replaces a lot of really dodgy-looking logic that may have only worked reliably when a conflict involved exactly two methods.
@beccadax beccadax force-pushed the hyrums-law-strikes-again branch from a8a614d to 8c9a6ce Compare June 29, 2022 01:16
@beccadax beccadax requested a review from kavon June 29, 2022 01:18
@beccadax
Copy link
Contributor Author

@swift-ci please smoke test

@beccadax
Copy link
Contributor Author

@swift-ci please test source compatibility

@beccadax
Copy link
Contributor Author

When I looked more closely at the existing code, I became less and less convinced that it would reliably do the right thing when there were more than two methods involved in a conflict, so I’ve rewritten the function to work in a way that I think will be more reliable. This perturbed a bunch of tests (!), so I also added a new rule to the set used to choose which method “should” have the selector. It’s a bigger diff than I want, but I’m much more confident that it will work correctly in cases we don’t directly test.

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