www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17541] New: nogc template deduction problem (codegen

https://issues.dlang.org/show_bug.cgi?id=17541

          Issue ID: 17541
           Summary:  nogc template deduction problem (codegen different
                    from .mangleof)
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: johanengelen weka.io

I unfortunately only have a complex testcase for this issue (after long
dustmiting sessions and manual reduction), involving three files (one.d, two.d,
three.d).

When only `one.d` is compiled, function `three.TT!(int).insertabcdefg(int)` is
deduced to be ` nogc`. But the deduction happens late, and printing `.mangleof`
does not show it. The symbol in the object file does show ` nogc` in the
mangling.

When `one.d` and `two.d` are compiled simultaneously (with or without
`three.d`), the function is no longer deduced to be ` nogc`.

(The bug was found in Weka's codebase where everything-at-once compilation is
impossible, and where per-package compilation is done. The testcase is heavily
simplified.)

Details:

Only compiling one.d gives:
 dmd one.d -c -of=tmp1.o
_D5three9__T2TTTiZ2TT13insertabcdefgMFiZv
 nm tmp1.o | grep "insertabcdefg"
0000000000000358 S _D5three9__T2TTTiZ2TT13insertabcdefgMFNiiZv Compiling all three at once gives:
 dmd one.d two.d three.d -c -of=tmp2.o
_D5three9__T2TTTiZ2TT13insertabcdefgMFiZv
 nm tmp2.o | grep "insertabcdefg"
0000000000000460 S _D5three9__T2TTTiZ2TT13insertabcdefgMFiZv File one.d ``````````````````````````` module one; import two; import three; struct BB { enum MAX_NUM_FIBERS = 4096; TWOR!1 t; TT!(int) tt; auto foo() { tt.insertabcdefg(1); } } BB bb; ``````````````````````````` File two.d ``````````````````````````` module two; import one; struct ET(bool a) { enum e = BB.MAX_NUM_FIBERS; } alias Event = ET!false; struct TWOR(size_t M) { Event e; void open() { bb.foo(); } } ``````````````````````````` File three.d ``````````````````````````` module three; void aaa() nogc { } struct TT(T) { void insertabcdefg(T) // nogc <-- deduction problem { pragma(msg, insertabcdefg.mangleof); aaa(); } } ``````````````````````````` --
Jun 23 2017