Jump to page: 1 2
Thread overview
Bug in dmd?
Jun 14, 2022
Andrey Zherikov
Jun 14, 2022
Dukc
Jun 14, 2022
Andrey Zherikov
Jun 15, 2022
JG
Jun 15, 2022
Andrey Zherikov
Jun 15, 2022
Dukc
Jun 15, 2022
Andrey Zherikov
Jun 15, 2022
mw
Jun 16, 2022
Andrey Zherikov
Jun 15, 2022
user1234
Jun 15, 2022
Andrey Zherikov
June 14, 2022

I have pretty simple code in my library:

alias CC = SumType!(AA,BB);
struct AA {}
struct BB
{
    CC[] c;
}

private void ppp(T, Output)(auto ref Output output, in CommandArguments!T cmd, in Config config)
{
    auto cc = CC(AA());  // (1)
}
private void printHelp(T, Output)(auto ref Output output, in CommandArguments!T cmd, in Config config)
{
    auto cc = CC(AA());  // (2)
}

void printHelp(T, Output)(auto ref Output output, in Config config)
{
    ppp(output, CommandArguments!T(config), config);
    printHelp(output, CommandArguments!T(config), config);
}

Line (2) produces undefined reference to '_D3std7sumtype__T7SumTypeTS8argparse4help2AATSQtQm2BBZQBl6__dtorMFNaNbNiNfZv' (it demangles to pure nothrow @nogc @safe void std.sumtype.SumType!(argparse.help.AA, argparse.help.BB).SumType.__dtor())

If I comment line (2) then everything is good (no link errors). Note that there is the same code at (1) which doesn't produce any error. Any idea what's going on?

June 14, 2022

On Tuesday, 14 June 2022 at 13:39:12 UTC, Andrey Zherikov wrote:

>

I have pretty simple code in my library:

alias CC = SumType!(AA,BB);
struct AA {}
struct BB
{
    CC[] c;
}

private void ppp(T, Output)(auto ref Output output, in CommandArguments!T cmd, in Config config)
{
    auto cc = CC(AA());  // (1)
}
private void printHelp(T, Output)(auto ref Output output, in CommandArguments!T cmd, in Config config)
{
    auto cc = CC(AA());  // (2)
}

void printHelp(T, Output)(auto ref Output output, in Config config)
{
    ppp(output, CommandArguments!T(config), config);
    printHelp(output, CommandArguments!T(config), config);
}

Line (2) produces undefined reference to '_D3std7sumtype__T7SumTypeTS8argparse4help2AATSQtQm2BBZQBl6__dtorMFNaNbNiNfZv' (it demangles to pure nothrow @nogc @safe void std.sumtype.SumType!(argparse.help.AA, argparse.help.BB).SumType.__dtor())

If I comment line (2) then everything is good (no link errors). Note that there is the same code at (1) which doesn't produce any error. Any idea what's going on?

No idea. The functions seems indeed to be exactly the same, so I assume this is a DMD bug. It cannot be a bug in std.sumtype, since that would trigger in both of the templates.

BTW, thanks for taking the effort to write your question this well (demagling, link to your library and all).

June 14, 2022

On Tuesday, 14 June 2022 at 21:44:48 UTC, Dukc wrote:

>

No idea. The functions seems indeed to be exactly the same, so I assume this is a DMD bug. It cannot be a bug in std.sumtype, since that would trigger in both of the templates.

This definitely triggers some bug in DMD because this private void printHelp ... function is not really private as it's called from another module and DMD doesn't catch this.

June 15, 2022

On Tuesday, 14 June 2022 at 23:56:58 UTC, Andrey Zherikov wrote:

>

On Tuesday, 14 June 2022 at 21:44:48 UTC, Dukc wrote:

>

No idea. The functions seems indeed to be exactly the same, so I assume this is a DMD bug. It cannot be a bug in std.sumtype, since that would trigger in both of the templates.

This definitely triggers some bug in DMD because this private void printHelp ... function is not really private as it's called from another module and DMD doesn't catch this.

I tried to reproduce it but wasn't able (I guess it is some interplay with the rest of your code):

import std.sumtype;



alias CC = SumType!(AA,BB);
struct AA {}
struct BB
{
    CC[] c;
}

private void ppp(T, Output)(auto ref Output output, in CommandArguments!T cmd, in Config config)
{
    auto cc = CC(AA());  // (1)
}
private void printHelp(T, Output)(auto ref Output output, in CommandArguments!T cmd, in Config config)
{
    auto cc = CC(AA());  // (2)
}

void printHelp(T, Output)(auto ref Output output, in Config config)
{
    ppp(output, CommandArguments!T(config), config);
    printHelp(output, CommandArguments!T(config), config);
}

struct CommandArguments(T) {
    T x;
}
struct Config {}

void main() {
    string test;
    Config config;
    CommandArguments!int commandArguments;
    printHelp!(int,string)(test,commandArguments,config);
}
June 15, 2022

On Tuesday, 14 June 2022 at 13:39:12 UTC, Andrey Zherikov wrote:

>

I have [pretty simple code in my library](https://github.com/andrey-
Line (2) produces undefined reference to '_D3std7sumtype__T7SumTypeTS8argparse4help2AATSQtQm2BBZQBl6__dtorMFNaNbNiNfZv' (it demangles to pure nothrow @nogc @safe void std.sumtype.SumType!(argparse.help.AA, argparse.help.BB).SumType.__dtor())

If I comment line (2) then everything is good (no link errors). Note that there is the same code at (1) which doesn't produce any error. Any idea what's going on?

That can be a template instance that's emitted somewhere else, i.e the thing is there but the mangle is different. maybe try to find if the dtor is there with mn -S on each object.

Another thing to try in these situations is to see if that works with -allinst.

June 15, 2022

On Tuesday, 14 June 2022 at 23:56:58 UTC, Andrey Zherikov wrote:

>

On Tuesday, 14 June 2022 at 21:44:48 UTC, Dukc wrote:

>

No idea. The functions seems indeed to be exactly the same, so I assume this is a DMD bug. It cannot be a bug in std.sumtype, since that would trigger in both of the templates.

This definitely triggers some bug in DMD because this private void printHelp ... function is not really private as it's called from another module and DMD doesn't catch this.

Now when I think of it, perhaps the fact that private printHelp has the same name as the public printHelp is somehow confusing dmd. If you try to rename the private printHelp and it's call in the public one to something else, you might get some insight on what triggers this behaviour.

June 15, 2022

On Wednesday, 15 June 2022 at 07:38:36 UTC, JG wrote:

>

I tried to reproduce it but wasn't able (I guess it is some interplay with the rest of your code):

I tried this first but got the same result as you. I think my small library overheats DMD's template engine.

June 15, 2022

On Wednesday, 15 June 2022 at 09:21:28 UTC, user1234 wrote:

>

On Tuesday, 14 June 2022 at 13:39:12 UTC, Andrey Zherikov wrote:

>

I have [pretty simple code in my library](https://github.com/andrey-
Line (2) produces undefined reference to '_D3std7sumtype__T7SumTypeTS8argparse4help2AATSQtQm2BBZQBl6__dtorMFNaNbNiNfZv' (it demangles to pure nothrow @nogc @safe void std.sumtype.SumType!(argparse.help.AA, argparse.help.BB).SumType.__dtor())

If I comment line (2) then everything is good (no link errors). Note that there is the same code at (1) which doesn't produce any error. Any idea what's going on?

That can be a template instance that's emitted somewhere else, i.e the thing is there but the mangle is different. maybe try to find if the dtor is there with mn -S on each object.

Another thing to try in these situations is to see if that works with -allinst.

I tried to call dmd the same way as dub does with -allinst added to all calls. Got the same linker issue.

nm shows that app.d refers to dtor which is not defined in .a:

$ nm .../liball_argparse.a|egrep 'argparse.+dtor'
$ nm .../all_getting_started-basic.o|egrep 'argparse.+dtor'
                 U _D3std7sumtype__T7SumTypeTS8argparse4help2AATSQtQm2BBZQBl6__dtorMFNaNbNiNfZv
June 15, 2022

On Wednesday, 15 June 2022 at 09:24:35 UTC, Dukc wrote:

>

Now when I think of it, perhaps the fact that private printHelp has the same name as the public printHelp is somehow confusing dmd. If you try to rename the private printHelp and it's call in the public one to something else, you might get some insight on what triggers this behaviour.

I tried private void printHelp -> package void printHelp1. It didn't help.

June 15, 2022

Create a simple test case, file bug at:

https://issues.dlang.org/

« First   ‹ Prev
1 2