Proposed improvements to the separate compilation model

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Jul 23 15:50:22 PDT 2011


On 7/23/11 5:39 PM, bearophile wrote:
> Andrei:
>
> I am not expert on this, but it doesn't look like esoteric stuff.
>
>> Consider:
>
> Thank you for explaining better, with more examples. This usually
> helps the discussion.
>
>
>> Say the team working on A wants to "freeze" a.di without precluding
>> work on A.fun().
>
> Currently in D there is no explicit&  enforced way to state this
> desire to the compiler?

It is as I described in the example. It works today. Fragility is the 
problem there.

>> The problem with this setup is that it's extremely fragile, in ways
>> that are undetectable during compilation or runtime.
>
> Is it possible to invent ways to make this less fragile?
>
>
>> For example, just swapping a and b in the implementation file makes
>> the program print "08.96566e-31344". Similar issues occur if fields
>> or methods are added or removed from one file but not the other.
>
> I have suggested some fine-grained hashing. Compute a hash from a
> class definition, and later quickly compare this value with a value
> stored elsewhere (like automatically written in the .di file).

I discussed four options with Walter, and this was one of them. It has 
issues. The proposal as in this thread is the simplest and most 
effective I could find.

>> Ultimately the programmers figure there's no way to keep files
>> separate without establishing a build mechanism that e.g. generates
>> a.di from a.d, compares it against the existing a.di, and complains
>> if the two aren't identical.
>
> Comparing .di files looks tricky. DMD generates them
> deterministically, so in theory it works, but it doesn't sound like a
> good thing to do.

It's commonplace with code generation tools.

>> They must define one class with everything in one place, and
>> there's no way out of that.
>
> I think C# uses partial classes to solve this. It doesn't use header
> files.
> http://msdn.microsoft.com/en-us/library/wa80x488%28v=vs.80%29.aspx

C#'s partial classes serve a different purpose, but yah, they can be 
used like that.


Andrei


More information about the Digitalmars-d mailing list