-
-
Notifications
You must be signed in to change notification settings - Fork 656
Fix issue 18095 - Add support for pragma(mangle) on alias declarations #7458
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
|
Thanks for your pull request, @jacob-carlborg! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Some tips to help speed things up:
Bear in mind that large or tricky changes may require multiple rounds of review and revision. Please see CONTRIBUTING.md for more information. Bugzilla references
|
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.
How is the change in the backend related to this PR?
Later edit: Oh, I see, nevermind.
46bdb91 to
e15d801
Compare
test/runnable/mangle.d
Outdated
| @("basic type") | ||
| { | ||
| @("override mangling") | ||
| { |
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.
What is the purpose of all of these @("some string") UDAs?
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 adds a description to each test indicating what is tested. If you don't like it I can remove it. I think it adds value.
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.
I don't see where those descriptions are being used anywhere. How is this different from just adding a comment?
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.
They could be used in the future and they allow me to add a form of scope for the description.
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.
I think until we have something in our infrastructure that makes use of these descriptions, they're a bit of a distraction.
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.
Fine 😞. I'll remove or move them to comments.
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.
Done.
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.
I think that now it's much more difficult to see which code belongs to which test and which description belongs to which test. In any other D project I would have used a separate unit test block for each test, but the DMD tests are not using unit test blocks.
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.
You can easily resolve that with some kind of comment header...
/*******************************************************
* Section 1
*******************************************************/
// Section 1.1
// Section 1.2
/*******************************************************
* Section 2
*******************************************************/
// Section 2.1
// Section 2.2... or something along those lines
FWIW, I see the value in what you were proposing, but I don't think this PR is the right place to introduce such idioms into the code base unless it solves a specific problem that we're currently facing and/or has broader support/adoption.
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.
I think it solves specific problem we have but nobody else seems to agree with me.
|
I like the idea and also tried to implement it when Walter introduced those special structs that don't work well without implicit conversions. I suspect it's not so easy, though. Doesn't this reintroduce some kind of "typedef", i.e. types are compared according to their mangling so the type with mangle overwrite is no longer the same as the aliased type? Could you also add a test case where the mangle override is at some intermediate step? |
e15d801 to
9704601
Compare
|
@rainers Done. |
|
I need to add a test for C++ mangling as well. |
|
Do we have any tests for the mangling in the actual binary? |
9704601 to
56db4b0
Compare
|
Added tests for C++ mangling as well. |
2fe5fe0 to
41f6e94
Compare
@rainers I added a new field to the |
|
Can we move forward with this? |
I noticed, but Type.merge() uses the mangling to fold multiple types into one. I'm not sure this isn't used somewhere else. It even makes the definition of what actually is an identical type non-obvious: Can a function with a different mangling have the same type?
I guess it needs approval by @WalterBright or @andralex . A good example to show the merits would be to implement c_long et al. with this. |
I'm not sure I understand. I added a new field so I know it's not used anywhere else.
I don't understand this question either. It's already possible today to manually set the mangling of a function. |
Check the implementation of Example: Does this still work? Are the function still compatible although the mangling of the type is different? It might be ok because checks for implicit conversions are satisfied.
Yes, but not the mangling of its type. |
@rainers the above works, but the following fails: static assert(is(void function(int) == void function(foo)))I'll have a look to see if I can figure something out. |
This allows to override the mangling of a type in an alias declaration as follows: ```d pragma(mangle, "foo") alias foo = int; static assert(foo.mangleof == "foo"); static assert(int.mangleof == "i"); ``` Overriding the mangling of a type in an alias allows for more generic solution to get the correct mangling of `c_long/c_ulong` for C++ functions. With the current solution the compiler is looking for a struct with the name `__c_long/__c_ulong` and special cases the mangling for that particular struct. Since D doesn't have implicit conversions to structs one are also forced cast/explicitly construct a `__c_long` struct when calling a function which uses the `__c_long` type as a parameter. With an alias that's not necessary anymore.
41f6e94 to
68d36fe
Compare
|
status? |
|
@andralex the status is that it wasn't so easy to implement as I thought it would be. Currently I'm not working on this. The issue is, as Rainer pointed out, that the mangling is used for type comparison as well. An alias with |
|
I suggest this be closed if it's not being actively pursued. Any objections? |
|
FWIW this would have been really helpful for #7893 (comment) where we can't do |
Yes, but I haven't come up with a way to solve the type comparison problem that Rainer mentioned. |
This allows to override the mangling of a type in an alias declaration as follows:
Overriding the mangling of a type in an alias allows for more generic solution to get the correct mangling of
c_long/c_ulongfor C++ functions. With the current solution the compiler is looking for a struct with the name__c_long/__c_ulongand special cases the mangling for that particular struct. Since D doesn't have implicit conversions to structs one are also forced cast/explicitly construct a__c_longstruct when calling a function which uses the__c_longtype as a parameter. With an alias that's not necessary anymore.