Thread overview
Error: Global variable type does not match previous declaration with same mangled name:
Nov 22, 2020
Adam D. Ruppe
Nov 22, 2020
kinke
Nov 23, 2020
Johan Engelen
November 22, 2020
So I'm trying to do this:

pragma(mangle, "_D" ~ T.mangleof[1..$] ~ "6__initZ")
// llvm says it is supposed to be { [2 x i8*]*, i8* }       __gshared extern immutable idk initializer;


to do `emplace` in -betterC.


On dmd, I use `ubyte[__traits(classInstanceSize, T)]` as idk, but it doesn't check so it is all fine.

In ldc, I can't find anything that works. The closest I get is

        static struct idk { ubyte*[1]* a; }

But it still shows a different type. Since `T` is a class, and a D class is a reference if I use T as idk, it comes across as T* in the llvm type... and D can't express T itself.

This appears to the the code that generates the error:

https://github.com/ldc-developers/ldc/blob/c5b9f8a9048e46322301575546ed60fa79d5f2c9/gen/llvmhelpers.cpp#L1677

and I don't see an escape hatch....

I've tried using `void*`, `void[0]` and various things but I can't get ldc to accept it. I just want to get at the raw bytes defined by that symbol and I don't think the D language can actually express that.

Could ldc perhaps just relax the type checking with a pragma or something too? I don't see one in existing in the wiki but it might be useful at some point later to consider adding.
November 22, 2020
On Sunday, 22 November 2020 at 17:46:16 UTC, Adam D. Ruppe wrote:
> pragma(mangle, "_D" ~ T.mangleof[1..$] ~ "6__initZ")
> // llvm says it is supposed to be { [2 x i8*]*, i8* }       __gshared extern immutable idk initializer;

Yeah, this trick only works for (non-zero-initialized) structs.

> I just want to get at the raw bytes defined by that symbol and I don't think the D language can actually express that.

Yeah, I think the proper way would be the addition of a new trait for aggregates, e.g., `__traits(initializer, T)`, with semantics equivalent to current `TypeInfo.initializer()` - returning a `const(void)[]`, and ptr being null for zero-initialized structs.

That wouldn't just be useful for a TypeInfo-free emplace(), but also for moving TypeInfo generation from the compiler to druntime templates.
November 23, 2020
On Sunday, 22 November 2020 at 19:53:51 UTC, kinke wrote:
> On Sunday, 22 November 2020 at 17:46:16 UTC, Adam D. Ruppe wrote:
>> pragma(mangle, "_D" ~ T.mangleof[1..$] ~ "6__initZ")
>> // llvm says it is supposed to be { [2 x i8*]*, i8* }       __gshared extern immutable idk initializer;
>
> Yeah, this trick only works for (non-zero-initialized) structs.

Hi Adam,
  Keep us posted about your progress. I've also worked on this a few months ago, to fix the druntime implementation of emplace that stack allocates large structs.
Current fix in production: https://github.com/weka-io/druntime/blob/134bdb9a02ffec5370c5788b61fe692ae441d9c5/src/core/internal/lifetime.d#L113-L146

Here is my attempt at avoiding the duplication of the symbol:
https://github.com/weka-io/druntime/blob/185ef32d69eb0024eec5a698e03cbbeade2e2ca7/src/core/internal/lifetime.d#L92-L140
For classes, I have no solution either...

-Johan