Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

WalterBright
Copy link
Member

… not mangle as const

If it doesn't break anything in the test suite, I'll need to add tests.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @WalterBright!

Bugzilla references

Auto-close Bugzilla Severity Description
19785 minor top level const types in function parameters should not mangle as const

Testing this PR locally

If 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"

@thewilsonator thewilsonator added the Review:Needs Changelog A changelog entry needs to be added to /changelog label Apr 4, 2019
@thewilsonator
Copy link
Contributor

This is quite a serious change and needs a changelog.

@jacob-carlborg
Copy link
Contributor

Not sure how serious this is. We don't offer any ABI compatibility. Anyone that expects that is going to be disappointed.

@WalterBright WalterBright force-pushed the fix19785 branch 2 times, most recently from 9d2708b to b8216e5 Compare April 4, 2019 08:59
@WalterBright
Copy link
Member Author

BTW, C++ does this, and so does D with extern (C++) functions.

@WalterBright WalterBright force-pushed the fix19785 branch 2 times, most recently from a5d6aa1 to dae9f87 Compare April 4, 2019 09:19
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`
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't mention immutable.

then the converted type is mangled instead. This means
these functions mangle to the same string:

```
Copy link
Contributor

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.

Copy link
Contributor

@jacob-carlborg jacob-carlborg left a 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.

@WalterBright WalterBright force-pushed the fix19785 branch 3 times, most recently from 83992a6 to 52829f3 Compare April 4, 2019 09:51
Copy link
Member

@Geod24 Geod24 left a 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
Copy link
Member

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.
Copy link
Member

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

@kinke
Copy link
Contributor

kinke commented Apr 4, 2019

BTW, C++ does this, and so does D with extern (C++) functions.

MSVC (stupidly) doesn't: https://godbolt.org/z/5P4vLv

@WalterBright WalterBright removed the Review:Needs Changelog A changelog entry needs to be added to /changelog label Apr 4, 2019
@WalterBright
Copy link
Member Author

Although this is a better design, it turns out to require changing the implicit conversion rules for function overload matching, as shown in the test/runnable/template9.d(860) failure. I think the best way to approach this is to (internally) have two types for a function parameter - one visible to callers, with const stripped from the head, and another visible to the internals of the function, with the const intact.

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 extern(C++), which also strips the head const off, it's just that nobody has noticed/reported an issue with it.

@WalterBright WalterBright added the Review:Phantom Zone Has value/information for future work, but closed for now label Apr 4, 2019
void foo(const(int)* p);
---

Note that C++ compilers typically do this as well.
Copy link
Member

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.

Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Review:Phantom Zone Has value/information for future work, but closed for now Severity:Bug Fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants