Bug 21203 – Accept pragma(mangle) on aggregate types
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-08-27T23:05:58Z
Last change time
2021-03-24T23:50:41Z
Keywords
pull
Assigned to
No Owner
Creator
Manu
Comments
Comment #0 by turkeyman — 2020-08-27T23:05:58Z
pragma(mangle) is only accepted on hard functions and variables.
Adding support to AggregateDecl will allow the user to customise the mangling for type names, and that mangle override should be used when composing mangled names for functions/templates.
This is the key to allowing comprehensive C++ class interop.
For instance, this becomes possible:
struct ScopeClass(C)
if (is(C == class)
{
static if (__traits(getLinkage, C) == "C++")
{
extern(C++, class)
pragma(mangle, C.mangleof) // <- here's the magic!
struct ScopeClass
{
char[__traits(classInstanceSize, C)] buffer;
//... all the things ...
}
}
}
And then consider these functions:
void fun(MyClass); // mangles MyClass*
void fun(const MyClass); // mangles const MyClass* const
void fun(ScopedClass!MyClass); // mangles MyClass
void fun(const ScopedClass!MyClass); // mangles const MyClass
void fun(ref ScopedClass!MyClass); // mangles MyClass&
void fun(ref const ScopedClass!MyClass); // mangles const MyClass&
By allowing pragma(mangle) to apply to AggregateDecl, we can override the mangling for the type names, and with this, we can write in-language tooling that can handle classes in ALL the ways that C++ can express.
Comment #1 by turkeyman — 2020-08-27T23:25:57Z
Sorry, that should read:
template ScopeClass(C)
{
...
}
!!
Comment #2 by turkeyman — 2020-08-27T23:27:24Z
And I missed the most important one:
void fun(const(ScopedClass!MyClass)*); // mangles const MyClass*
That's the money shot!
(I wish you could edit in bugzilla!!!)
Comment #3 by andrej.mitrovich — 2020-09-29T03:54:03Z
+1
Also we currently cannot add a binding to std::function. Because function is a keyword. And pragma(mangle) doesn't work on structs.
Comment #4 by turkeyman — 2020-09-29T04:52:03Z
I think this is a really big deal! It'll enable in-language solutions for a whole heap of our biggest extern(C++) problems...
I'm surprised it's not receiving more attention.
Comment #5 by iamthewilsonator — 2020-10-05T10:17:36Z