-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx Interop] Disambiguate methods within the same class with same name but differing "constness" #41308
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is fantastic. Thank you, Ehud!
@swift-ci please smoke test. |
@swift-ci please smoke test. |
|
||
// No input with output | ||
int numberOfMutableMethodsCalled() { return ++mutableMethodsCalledCount; } | ||
int numberOfMutableMethodsCalled() const { return mutableMethodsCalledCount; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like your test cases are in a pattern of:
- mutating method
- const method
Could you also add another method pair in reverse order, i.e.
- const method
- mutating method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea!
LG with one suggestion. However, I believe we need a discussion if adding 'Mutating' at the end of the method is the right approach with respect to the naming convention. A 'mutating...' prefix might be ergonomic. Could you write up a short pitch for this on the Swift forums where we can have a discussion about the naming? |
@swift-ci please smoke test. |
@swift-ci please smoke test macOS. |
When importing CXX methods into Swift the compiler had issues with classes (Records) that contained 2+ methods that differed in "constness" but had the same name
Example:
This PR appends "Mutating" to the end of the mutable function to disambiguate when importing into swift.
the result of the above would then be:
Determining when 2 methods conflict is a seemingly hard problem. Name alone is not enough to get it right 100% of the time since you could have a class with:
That said, such patterns seem less common and so this PR uses name alone to disambiguate, recognizing that it may result in some confusing outputs in more uncommon circumstances
The above example would result in:
even though the 2 methods do NOT conflict.