Bug 15985 – [REG2.068/2.069] Code doesn't link unless compiled with -debug
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-05-02T16:54:19Z
Last change time
2023-02-08T00:26:30Z
Keywords
link-failure, pull
Assigned to
No Owner
Creator
Vladimir Panteleev
Comments
Comment #0 by dlang-bugzilla — 2016-05-02T16:54:19Z
/////////////////////// test.d ///////////////////////
struct S()
{
void delegate() d;
}
S!() f_Ds(U=D*)()
{
static if (is(U == struct))
return S!()
(
{
foreach (i, field; U.init.tupleof)
f_Ds!(typeof(field))();
}
);
static if (is(U V : V*))
return f_Ds!V();
}
void f_E()()
{
auto f = S!()
(
{
enum x = is(typeof(f_Ds!(D*)()));
f_Ds!(D*)();
}
);
}
struct A
{
D* d;
}
struct B
{
}
struct C
{
A a;
B b;
}
struct D
{
C c;
}
void main()
{
f_E();
f_Ds!D();
}
//////////////////////////////////////////////////////
Linux , DMD 2.068.0, with -debug: OK
Linux , DMD 2.068.0, without -debug: OK
Linux , DMD 2.069.0, with -debug: OK
Linux , DMD 2.069.0, without -debug: Link error
Windows, DMD 2.067.0, with -debug: OK
Windows, DMD 2.067.0, without -debug: OK
Windows, DMD 2.068.0, with -debug: OK
Windows, DMD 2.068.0, without -debug: Link error
Bisection attempts point towards master/stable branch merges (i.e. nothing useful).
It is probably a latent heisenbug triggered by other changes.
Downstream issue: https://github.com/CyberShadow/Digger/issues/36
Comment #1 by jiki — 2016-05-02T22:07:56Z
I confirmed this with dmd 2.068 and -m64 mode in Windows.
So -allinst option works.
Comment #2 by dlang-bugzilla — 2017-02-12T03:59:27Z
(In reply to Vladimir Panteleev from comment #0)
> Bisection attempts point towards master/stable branch merges (i.e. nothing
> useful).
>
> It is probably a latent heisenbug triggered by other changes.
Sorry, that was wrong. (Digger could not bisect changes in the stable branch properly)
Introduced in https://github.com/D-Programming-Language/dmd/pull/4944.
Comment #3 by bugzilla — 2017-10-08T04:52:24Z
Reduced it a bit to:
struct S()
{
void delegate() d;
}
S!() f_Ds(U)()
{
static if (is(U == struct))
return S!()
(
{
foreach (i, field; U.init.tupleof)
f_Ds!(typeof(field))();
}
);
else
return f_Ds!(D)();
}
void f_E()
{
auto f = S!()
(
{
enum x = is(typeof(f_Ds!(D*)()));
f_Ds!(D*)();
}
);
}
struct A
{
D* d;
}
struct D
{
A a;
int b;
}
void main()
{
f_E();
f_Ds!(D*)();
}
Comment #4 by ag0aep6g — 2017-10-08T09:56:57Z
Reduced further:
----
void f()() { h!()(); }
void g()() { f!()(); }
void h()() { g!()(); }
enum x = is(typeof(g!()()));
alias my_h = h!();
void main() {}
----
And here's a variant that fails both with and without -debug:
----
void f()()
{
g!()();
h!()();
}
void g()() { f!()(); }
void h()() { f!()(); }
enum x = is(typeof(f!()()));
alias my_g = g!();
void main() {}
----
(In reply to ag0aep6g from comment #4)
> void f()()
> {
> g!()();
> h!()();
> }
>
> void g()() { f!()(); }
> void h()() { f!()(); }
>
> enum x = is(typeof(f!()()));
> alias my_g = g!();
>
> void main() {}
Here's what I suspect is going on with this. Let's follow the semantic analsysis:
1. x is the first to get semantically analyzed. The typeof instantiates f!()
2. f!() instantiates g!() and h!()
3. my_g instantiates g!() directly
h!() is only instantiated indirectly, and since that instantiation happens during a typeof, it never gets marked as needing code to be generated for it.
Comment #7 by ibuclaw — 2023-01-29T19:41:34Z
(In reply to Walter Bright from comment #6)
>
> Here's what I suspect is going on with this. Let's follow the semantic
> analsysis:
>
DMD's default behaviour is to eagerly prune templates it expects to be instantiated elsewhere. Undefined references are expected as a default behaviour.
If undefined errors still persist with -allinst, then that's a bug that needs fixing.
Comment #8 by dlang-bot — 2023-01-31T02:14:15Z
@WalterBright created dlang/dmd pull request #14855 "fix Issue 15985 - [REG2.068/2.069] Code doesn't link unless compiled …" fixing this issue:
- fix Issue 15985 - [REG2.068/2.069] Code doesn't link unless compiled with -debug
https://github.com/dlang/dmd/pull/14855
Comment #9 by dlang-bot — 2023-02-08T00:26:30Z
dlang/dmd pull request #14855 "fix Issue 15985 - [REG2.068/2.069] Code doesn't link unless compiled …" was merged into master:
- a476bc101e5c3172b8f18479fbf4557ba35a5a8a by Walter Bright:
fix Issue 15985 - [REG2.068/2.069] Code doesn't link unless compiled with -debug
https://github.com/dlang/dmd/pull/14855