[Issue 11284] New: add -allinst compiler switch

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Oct 16 16:36:38 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=11284

           Summary: add -allinst compiler switch
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bugzilla at digitalmars.com


--- Comment #0 from Walter Bright <bugzilla at digitalmars.com> 2013-10-16 16:36:37 PDT ---
Given these two files:

  ----- a.d ------
  int foo(T)(T i) { return i;)
  enum x = foo(3);
  enum f = foo(2.3);
  ---- test.d ----
  import a;
  int y = foo(4);
  ----------------

Compiling with 2.063 or earlier with:

    dmd test -c

would generate an instance of foo!int and foo!double into test.obj. In fact,
every file that imported a.d would have those instantiations inserted into its
resulting object file. This didn't affect the executable, as the linker would
remove duplicates (the magic of COMDAT segments).

However, template heavy imports can and did result in inordinately massive .obj
files, for example, try importing std.stdio.

Starting with 2.064, the compiler notices that foo!double is instantiated only
by import a, and so the code generated for foo!double would presumably be in
the object file a.obj, and so the compiler does not have to insert it into
test.obj. This can potentially result in large compiler speed increases, which
are a big feature of D.

If the foo!double is not in a.obj, then the user sees "undefined symbol
foo!double" coming from the linker in code that worked with 2.063, and files a
bug report. This circumstance can appear when:

1. a.obj is never linked in, i.e. a.d is regarded as a "header only" file.

2. a.d was modified but a.obj was never recompiled with the newer a.d.

3. a.d's template instantiations are behind VersionDeclaration's and the
versions in effect when a.d is compiled are different than the versions when
test.d is compiled.

4. Other forms of conditional compilation analogous to case (3).

I regard these as user build system irregularities, not bugs. However, user
confusion over this, and frustration over "it worked in 2.063 and now I get
this error message, what's wrong" is very real. Hence, I propose the -allinst
switch which will generate code for all instantiated templates, like 2.063
does.

This way, the user can throw the switch and continue working as before, or if
he wants to track down the source of the undefined symbol at least the switch
provides a starting point in diagnosing if it is one of cases 1..4 or something
else.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list