Reducing the inter-dependencies (in Phobos and at large)
Dmitry Olshansky
dmitry.olsh at gmail.com
Sat Apr 27 02:21:16 PDT 2013
27-Apr-2013 00:26, Dmitry Olshansky пишет:
> Have you read the description? I gave the exact cases where regardless
> of templates or no templates you do pull in the module. This is a
> problem that defeat the whole goodness of generating only the code you
> use (via templates). In fact I'll post about more specific problem
> separately (need to gather the solid data).
Here is the example of the primary catch. Let's say you have 3 modules
a, b and the main app module m. b depends on a's constraint.
module b;
extern(C) void printf(const(char)* fmt, ...);
template canCheckIn(T)
{
enum canCheckIn = is(T : int);
}
static this()
{
printf("START b\n");
}
static ~this()
{
printf("END b\n");
}
module a;
import b;
extern(C) void printf(const(char)* fmt, ...);
void foo(T)(T value)
if(canCheckIn!T)
{
printf("FOO\n");
}
void bar()
{
printf("BAR\n!");
}
module m;
import a;
void main()
{
bar();
}
main will happily print:
START b
BAR
END b
Even though foo is not even instantiated(!) and it's the only thing in
which a depends on b (and m doesn't ever touch it).
Now multiply this be the kind of cross-import happy graph we have in
Phobos and indeed most programs are going to pull in the whole ball of mud.
--
Dmitry Olshansky
More information about the Digitalmars-d
mailing list