Thread overview
[Issue 13394] invariant fail to link since 2.066 when using separate compilation
Aug 29, 2014
Kenji Hara
Aug 29, 2014
deadalnix
Aug 29, 2014
Kenji Hara
Aug 29, 2014
Kenji Hara
August 29, 2014
https://issues.dlang.org/show_bug.cgi?id=13394

Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |link-failure
           Hardware|x86                         |All
                 OS|Mac OS X                    |All

--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> ---
Introduced in: https://github.com/D-Programming-Language/dmd/pull/3775

====

When a.d is compiled, compiler instantiates Btpl!A and outputs its invariant objcode to a.obj.

Next b.d is compiled, the `new B` expression instantiates the Btpl!A template constructor. It implicitly calls the invariant in post-condition, bug Btpl!A is explicitly instantiated in the non-root module (== a module which not directly compiled from command line) a. So compiler assumes that the Btpl!A.invariant objcode will be provided in linking phase and skips its codegen.

However, currently dmd always adds the inferred function attributes into the
symbol name of instantiated functions. Therefore, dmd a.d will emit the objcode
of Btpl!A.invariant with the symbol name:
  _D1a15__T4BtplTC1a1AZ4Btpl11__invariantMxFNaNbNiNfZv

But dmd b.d does not invoke semantic3 of Btpl!A.invariant. Then b.obj refer the
invariant by using the symbol name:
  _D1a15__T4BtplTC1a1AZ4Btpl11__invariantMxFZv
  <-- does not contain the inferred attributes NaNbNiNf

Then link-failure happens.

--
August 29, 2014
https://issues.dlang.org/show_bug.cgi?id=13394

--- Comment #2 from deadalnix <deadalnix@gmail.com> ---
(In reply to Kenji Hara from comment #1)
> Introduced in: https://github.com/D-Programming-Language/dmd/pull/3775
> 
> ====
> 
> When a.d is compiled, compiler instantiates Btpl!A and outputs its invariant objcode to a.obj.
> 
> Next b.d is compiled, the `new B` expression instantiates the Btpl!A template constructor. It implicitly calls the invariant in post-condition, bug Btpl!A is explicitly instantiated in the non-root module (== a module which not directly compiled from command line) a. So compiler assumes that the Btpl!A.invariant objcode will be provided in linking phase and skips its codegen.
> 
> However, currently dmd always adds the inferred function attributes into the
> symbol name of instantiated functions. Therefore, dmd a.d will emit the
> objcode of Btpl!A.invariant with the symbol name:
>   _D1a15__T4BtplTC1a1AZ4Btpl11__invariantMxFNaNbNiNfZv
> 
> But dmd b.d does not invoke semantic3 of Btpl!A.invariant. Then b.obj refer
> the invariant by using the symbol name:
>   _D1a15__T4BtplTC1a1AZ4Btpl11__invariantMxFZv
>   <-- does not contain the inferred attributes NaNbNiNf
> 
> Then link-failure happens.

That is interesting. Do you know why the import alter the behavior of DMD ?

--
August 29, 2014
https://issues.dlang.org/show_bug.cgi?id=13394

--- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> ---
(In reply to deadalnix from comment #2)
> That is interesting. Do you know why the import alter the behavior of DMD ?

In my Windows environment, importing std.utf in a.d was unnecessary to reproduce the link-failure.

--
August 29, 2014
https://issues.dlang.org/show_bug.cgi?id=13394

Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #4 from Kenji Hara <k.hara.pg@gmail.com> ---
https://github.com/D-Programming-Language/dmd/pull/3918

--
August 31, 2014
https://issues.dlang.org/show_bug.cgi?id=13394

--- Comment #5 from github-bugzilla@puremagic.com ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/7683136e580c73fa6aa150c4c3ea4b54ed6f9b32
fix Issue 13394 - invariant fail to link since 2.066 when using separate
compilation

https://github.com/D-Programming-Language/dmd/commit/f6c130e66791ba9eb047334dec0645d06e74cc89 Merge pull request #3918 from 9rnsr/fix13394

[REG2.066] Issue 13394 - invariant fail to link since 2.066 when using separate compilation

--
August 31, 2014
https://issues.dlang.org/show_bug.cgi?id=13394

github-bugzilla@puremagic.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--
September 02, 2014
https://issues.dlang.org/show_bug.cgi?id=13394

--- Comment #6 from github-bugzilla@puremagic.com ---
Commit pushed to 2.066 at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/6bfc3341a04ff6b4bc431703473646c35bbd0c87 Merge pull request #3918 from 9rnsr/fix13394

[REG2.066] Issue 13394 - invariant fail to link since 2.066 when using separate compilation

--