-
Notifications
You must be signed in to change notification settings - Fork 10.5k
C++ Interop: import const methods as non-mutating #38618
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
This change makes ClangImporter import some C++ member functions as non-mutating, given that they satisfy two requirements: * the function itself is marked as `const` * the parent struct doesn't contain any `mutable` members `get` accessors of subscript operators are now also imported as non-mutating if the C++ `operator[]` satisfies the requirements above. Fixes SR-12795.
@swift-ci please smoke test |
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 would be cool to see some performance improvements here. Unfortunately, we don't have enough C++ interop performance tests yet.
Anyway, thanks for the patch, as always!
@swift-ci please smoke test macOS |
Yeah, looks like the C++ interop performance tests currently verify object instantiation, but not method calls. |
Hey @egorzhdan :) |
To unblock CI, I created a PR to disable the test and filed a issue: |
Sorry for breaking the test! |
Thank you for the fix :) |
Also, for the future, if you're changing code in the ClangImporter, IRGen or the runtime, it is better to err on the side of caution and run full testing instead of smoke testing as there are often platform differences which aren't caught by smoke testing. |
Yes, that's reasonable, thanks! |
This change makes ClangImporter import some C++ member functions as non-mutating, given that they satisfy two requirements:
const
mutable
membersget
accessors of subscript operators are now also imported as non-mutating if the C++operator[]
satisfies the requirements above.In the future we should allow annotating a C++ method as
mutating
explicitly, to make it possible to preserve the correct behavior for methods that are declaredconst
, but mutate the object anyway, for example viaconst_cast
.Fixes SR-12795.