www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Bug in dmd?

reply Andrey Zherikov <andrey.zherikov gmail.com> writes:
I have [pretty simple code in my 
library](https://github.com/andrey-zherikov/argparse/blob/bug/source/argparse/help.d#L27-L47):
```d
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](https://github.com/andrey-zherikov/argparse/runs/6880350900?check_suite_f
cus=true#step:5:12) `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?
Jun 14 2022
next sibling parent reply Dukc <ajieskola gmail.com> writes:
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-zherikov/argparse/blob/bug/source/argparse/help.d#L27-L47):
 ```d
 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](https://github.com/andrey-zherikov/argparse/runs/6880350900?check_suite_f
cus=true#step:5:12) `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).
Jun 14 2022
parent reply Andrey Zherikov <andrey.zherikov gmail.com> writes:
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](https://github.com/andrey-zherikov/argparse/blob/bug/source/argpa se/internal.d#L786) and DMD doesn't catch this.
Jun 14 2022
next sibling parent reply JG <someone somewhere.com> writes:
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](https://github.com/andrey-zherikov/argparse/blob/bug/source/argpa se/internal.d#L786) 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): ```d 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); } ```
Jun 15 2022
parent Andrey Zherikov <andrey.zherikov gmail.com> writes:
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.
Jun 15 2022
prev sibling parent reply Dukc <ajieskola gmail.com> writes:
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](https://github.com/andrey-zherikov/argparse/blob/bug/source/argpa se/internal.d#L786) 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.
Jun 15 2022
parent reply Andrey Zherikov <andrey.zherikov gmail.com> writes:
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.
Jun 15 2022
parent reply mw <mingwu gmail.com> writes:
Create a simple test case, file bug at:

https://issues.dlang.org/
Jun 15 2022
parent Andrey Zherikov <andrey.zherikov gmail.com> writes:
On Wednesday, 15 June 2022 at 16:53:13 UTC, mw wrote:
 Create a simple test case, file bug at:

 https://issues.dlang.org/
I tried. No luck.
Jun 16 2022
prev sibling parent reply user1234 <user1234 12.de> writes:
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](https://github.com/andrey-zherikov/argparse/runs/6880350900?check_suite_f
cus=true#step:5:12) `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`.
Jun 15 2022
parent Andrey Zherikov <andrey.zherikov gmail.com> writes:
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](https://github.com/andrey-zherikov/argparse/runs/6880350900?check_suite_f
cus=true#step:5:12) `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`: ```bash $ nm .../liball_argparse.a|egrep 'argparse.+dtor' $ nm .../all_getting_started-basic.o|egrep 'argparse.+dtor' U _D3std7sumtype__T7SumTypeTS8argparse4help2AATSQtQm2BBZQBl6__dtorMFNaNbNiNfZv ```
Jun 15 2022