-
-
Notifications
You must be signed in to change notification settings - Fork 610
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
fix Issue 19785 - top level const types in function parameters should… #9556
Conversation
|
Thanks for your pull request, @WalterBright! Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + dmd#9556" |
|
This is quite a serious change and needs a changelog. |
|
Not sure how serious this is. We don't offer any ABI compatibility. Anyone that expects that is going to be disappointed. |
9d2708b to
b8216e5
Compare
|
BTW, C++ does this, and so does D with |
a5d6aa1 to
dae9f87
Compare
changelog/fix19785.dd
Outdated
| Function Parameter Name Mangling Changes | ||
|
|
||
| If the parameter type can be implicitly converted to a type | ||
| that at the top level does not have `const` or `shared` or `inout` |
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.
Doesn't mention immutable.
changelog/fix19785.dd
Outdated
| then the converted type is mangled instead. This means | ||
| these functions mangle to the same string: | ||
|
|
||
| ``` |
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.
Please use ---. The markdown features are not enabled, as far as I know.
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 is more serious than I thought, a lot more. I didn't understand the implications until I read the now present changelog. This is a silent breaking change, the worst kind. It needs to go though the deprecation process.
83992a6 to
52829f3
Compare
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.
The change itself makes sense but the silent breakage is a no go from me. Such functions overload should be deprecated first.
| This will break binary compatibility with existing code, | ||
| it will need to be recompiled. | ||
|
|
||
| It will also break code that relies on them being distinct |
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.
Silently break code
| assert(foo60(k) == 3); | ||
| } | ||
| --- | ||
| Although arguably such code never made sense anyway. |
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.
Not a sound justification either
MSVC (stupidly) doesn't: https://godbolt.org/z/5P4vLv |
… not mangle as const
|
Although this is a better design, it turns out to require changing the implicit conversion rules for function overload matching, as shown in the This would be some significant work, and is a low priority, so I'm going to defer this for now. Note that the template9 failure would also likely exhibit if the functions were |
| void foo(const(int)* p); | ||
| --- | ||
|
|
||
| Note that C++ compilers typically do this as well. |
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.
Not on Windows, e.g. void foo(const int* const ptr) is mangled as ?foo@@YAXQBH@Z by both cl and dmc. This translates back to void __cdecl foo(int const * const).
The change in this PR might help interfacing with void foo(const Class* ptr), though.
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.
DMC++ tries to duplicate what VC++ does for mangling. Where it would show up in semantics is how the two functions overload against each other. Obviously, if they mangle the same they have to be semantically regarded has having the same function ABI and cannot overload against each other.
… not mangle as const
If it doesn't break anything in the test suite, I'll need to add tests.