cycle dependencies

Neia Neutuladh neia at ikeran.org
Fri Jun 1 00:49:03 UTC 2018


On Thursday, 31 May 2018 at 23:17:20 UTC, Steven Schveighoffer 
wrote:
> Hm... I just had a crazy idea: what if D had a switch that 
> allowed it to store a dependency graph of constructors into a 
> json file, and then when you link, there is a wrapper which 
> consumes all these files, runs the cycle detection and sort, 
> and then compiles a perfectly sorted moduleinfo section to be 
> included in the binary (obviously, written in D and compiled by 
> the compiler).

This is how languages get custom object formats and custom 
linkers.

A fly in the ointment is .di files. This works today and does the 
right thing:

// bar.d
import modulewithstaticctor;
shared static this() {}
string something = modulewithstaticctor.someValue;

// bar.di
// no static ctor, no imports
string something;

// foo.d
import bar, std.stdiod;
void main()
{
   writefln(something);
}

So mixing that dependency graph with .di files is "here be 
dragons" territory.

If the dependency data were inserted into the object files 
instead (which it should be? that's what ModuleInfo is), then the 
compiler could potentially read this out before linking, and we 
could be sure that the resulting order is correct. Like, insert a 
weak symbol into each normal object file saying there's no 
dependency graph, and then the compiler can run on a set of 
object files to produce a new object file with the complete 
dependency graph as a strong symbol.

But that's more work.


More information about the Digitalmars-d mailing list