DIP10005: Dependency-Carrying Declarations is now available for community feedback

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Fri Dec 23 20:41:46 PST 2016


On 12/23/16 9:23 PM, Chris Wright wrote:
> The comparison to mach.d is a strawman.

The mach.d is given as an example of the approach of breaking code into 
fine-grained module. No comparison is made or implied.

> Then I looked at the code.
>
> Phobos has 26 templates that would use this special syntax, referencing
> 14 distinct templates and CTFE functions in three modules.

Could you please give more detail about the method you used? What 
special syntax are you referring to - would that be the "with (import 
...)" syntax? If that's the case there's a bunch of stuff missing. 
Consider e.g.:

int cmp(alias pred = "a < b", R1, R2)(R1 r1, R2 r2)
if (isInputRange!R1 && isInputRange!R2 && !(isSomeString!R1 && 
isSomeString!R2));

int cmp(alias pred = "a < b", R1, R2)(R1 r1, R2 r2)
if (isSomeString!R1 && isSomeString!R2);

These and many like them would use the "with import" construct, wouldn't 
they? They are missing from your list.

> The templates that have to be parsed are std.traits, std.meta, and
> std.range.primitives.

That's where most introspection primitives for the standard library are 
situated indeed.

> I wrote a test program that imported them without
> using them. It compiled in too little time to accurately measure --
> `time` reports 0.01s wall time.
>
> You want to add new language syntax to save me ten milliseconds during
> compilation.

DIP1005 enumerates several benefits of the proposed feature. Speed is 
not the most important and is not presented as such, but it takes most 
space because the others are more difficult to experiment with without 
an experimental implementation.

> You hope that template constraints become more common.

Well, to the extent that is the way correct code is written, that's more 
than just hope.

> If they do, this
> change relies on:
>
> * projects defining their own constraints (not just using std.traits)
> * those constraints being defined in modules other than where they're used
> * those constraints being defined in very large modules
> * my code not depending on anything in those constraint-defining modules
> * my code depending on something in a file with a template with one of
> those constraints
> * this whole situation being common enough to give me a death by a
> thousand papercuts

It's not only constraints, it's everything in declarations that relies 
on entities (e.g. types) defined in other modules. And again the 
feature's benefits go well beyond making general projects faster to build.

A simple way to look at things is - local imports are The Right Thing, 
for many reasons beyond compilation speed. There needs to be a way to do 
the right thing for the declaration part as well.

(I'm glad we're getting to the point of diminished returns - I recall an 
argument made a while ago was that, on the contrary, our compilation 
model cannot possibly scale for large projects.)

> Appendix A: templates that would receive 'with(import foo)' in Phobos.

Could you please provide more detail on how you measured this and what 
assumptions you made? Most templates in Phobos would receive a with 
clause, so there's a disconnect somewhere.


Andrei



More information about the Digitalmars-d mailing list