digitalmars.D.internals - Best way to pass template parameters information to the mangler
- Mathias Lang (25/25) Jun 26 2018 Hi everyone,
- Walter Bright (4/5) Jun 28 2018 Yes, I know about this problem. I'm pretty sure there's a bugzilla entry...
Hi everyone, I'm currently looking at expanding the C++ interop to work for what I thought was a very limited used case. While C++ interop works great for non-templated code, any non-trivial code involving templates is broken on POSIX, because template parameters are not substituted. Take for example: ``` extern(C++) T* foo (T) (); pragma(msg, foo!(int).mangleof); ``` This should mangle to `_Z3fooIiEPT_v` but DMD mangles it to `_Z3fooIiEPiv`. I crafted a bunch of more advanced test cases (https://github.com/Geod24/dmd/commit/9928cb28ba099676caaa8d0defdc8e48c5f3de6d) but that's the gist of it. It's reported as https://issues.dlang.org/show_bug.cgi?id=16479 I've done a bit of digging and saw that the frontend "installs" an alias to the actual type in the scope (https://github.com/dlang/dmd/blob/fb22391c75e91ffe27c78e3daf02f44ef70c7c17/src/dmd/dtemp ate.d#L2003-L2006), and AFAICT that alias is later peeled off (via `toAlias`), meaning when we reach the mangling phase there's no way to tell if the type was a template parameter or not. In order to fix the previously mentioned issue, I need to keep the information that the type is a template parameter. I am considering keeping the `AliasDeclaration` around and adding a `dependent` field, but I suspect that would require extensive changes to not peel it off. The least invasive solution so far would be to add yet another field to keep this information, but it sounds hacky and brittle. If anyone has any suggestion, it is very welcome!
Jun 26 2018
On 6/26/2018 9:50 PM, Mathias Lang wrote:If anyone has any suggestion, it is very welcome!Yes, I know about this problem. I'm pretty sure there's a bugzilla entry for it. I don't have a solution, but I didn't spend a lot of time on it. Your idea sounds worth exploring.
Jun 28 2018