DIP10005: Dependency-Carrying Declarations is now available for community feedback
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Mon Dec 19 18:34:49 PST 2016
Added this note about module constructors:
## Future Possibilities and Directions
Inline and scoped imports offer the option of better handling of static
module constructors. Currently, modules that mutually `import` one
another (either directly or through a longer chain) cannot
simultaneously define `shared static this()` constructors. The reason is
that, again, dependencies are computed at module level.
If instead modules have no top-level dependencies, then the compiler is
able to compute the narrow set of dependencies needed for executing the
static module constructor. The static constructor may be (a) a part of a
`with` declaration, (b) use local imports within, and (c) call other
functions within the module that have their own dependencies. For example:
```d
// assume no top-level import
with (module_a) void fun(T)()
{
import module_b;
return gun();
}
with (module_c)
static shared this()
{
import module_d;
fun!int;
}
```
In this case, the module constructor depends (only) on `module_a`,
`module_b`, `module_c`, and `module_d`. The full information is confined
within the current module so it is inferrable during separate compilation.
Andrei
More information about the Digitalmars-d
mailing list