Reggae [was Building C++ modules]

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Aug 14 17:24:38 UTC 2019


On Wed, Aug 14, 2019 at 12:32:11PM +0200, Jacob Carlborg via Digitalmars-d wrote:
> On 2019-08-13 20:33, H. S. Teoh wrote:
> 
> > I suppose in C++, with its overcomplex lexing/parsing, this could
> > potentially be significant savings.  But based on what Walter has
> > said about storing binary forms of the source code (which is
> > basically what you'll end up doing if you really want to implement
> > incremental compilation in the above sense), it's not much more
> > efficient than (re)lexing and (re)parsing the entire file.
> 
> I'm guessing the compiler would run as a daemon in the background
> storing everything in memory.
[...]

In theory, I suppose it could work.  But again, it comes back to this
point of whether it's worth the trouble to maintain the necessary data
structures that allows you to reliably map sections of a modified source
file to the AST.  Some parts of the AST aren't 100% context-free. Think,
for example, of static ifs or static foreach that generate parts of the
AST based on some CTFE computation taking as input some enums defined
elsewhere in the file, or in another module.  You'll need some pretty
complex data structures to keep track of which part(s) of the AST
depends on which other part(s), and you'll need some clever algorithms
to update everything consistently when you detect that one of the parts
of the source file corresponding to these AST subtrees is modified.

I suspect the complexity required to maintain consistency and update the
AST will be not much better than the cost of a straightforward re-parse
of the entire source file and rebuild of the AST from scratch.  It
probably only starts to be superior when your source file becomes
unreasonably large, in which case you should be splitting it up into
more manageable modules anyway.

But then again, this is all in the hypothetical.  Somebody should run a
proof-of-concept experiment and profile it to compare the actual
performance characteristics of such a scheme.


T

-- 
If you want to solve a problem, you need to address its root cause, not just its symptoms. Otherwise it's like treating cancer with Tylenol...


More information about the Digitalmars-d mailing list