Review of Andrei's std.benchmark

Jonathan M Davis jmdavisProg at gmx.com
Sat Sep 22 09:44:49 PDT 2012


On Saturday, September 22, 2012 09:04:09 Andrei Alexandrescu wrote:
> On 9/22/12 8:28 AM, "Øivind" wrote:
> > Is there a way to solve the dependency issue without forbidding static
> > constructors in modules with cyclic dependencies?
> 
> I think an idea just occurred to me. The rules for static ctors and
> dtors were invented before "import" was allowed inside a scope. We could
> have taken advantage of that.
> 
> Say we restrict symbol visibility inside static cdtors to ONLY symbols
> within the current module. If some static cdtor needs a symbol from a
> different module, it must import it explicitly (even if the current
> module already imports it).
> 
> In this setup it should be possible to compute, in a fine-grained
> manner, the dependencies of static cdtors.
> 
> Unfortunately that would be a breaking change.

It's a nice thought, but it wouldn't work. If nothing else .di files completely 
ruin it.

1. I don't think that it's actually required that static constructors be in a 
.di file. So, the compiler couldn't know for sure whether the modules being 
imported had static constructors.

2. Even if all static constructors had to be in a .di file, local imports ruin 
it, because the function bodies (which can definitely be elided from .di files) 
could contain local imports to modules which have static constructors and 
cause circular dependencies.

- Jonathan M Davis


More information about the Digitalmars-d mailing list