r/Compilers • • Jul 28 '26

Inside Zig's Incremental Compilation | mlugg

https://mlugg.co.uk/posts/incremental-compilation-internals/
47 Upvotes

16 comments sorted by

View all comments

Show parent comment

2

u/matthieum Jul 29 '26

Thanks for the link, though it did not quite answer my question.

In general, you add another pass to make easier to do the next.

Agreed, though there's always a potential cost trade-off too, so the benefits must be worth the cost.

At the moment, it's just not clear to me what the benefits are. I see some checks occur as part of AstGen, but those checks could just as easily be executed on the AST itself without generating anything as far as I can tell.

For now, the one potential reason I could is that there's a desugaring/normalization step which occurs, which requires mutating/rewriting the AST anyway, and at that point targeting AST or a different format as an output is more or less the same processing cost. If on top some desugaring/normalization cannot easily be represented in the AST for any reason, then a different model becomes more attractive.

0

u/mamcx Jul 29 '26

What you see in the article is the reason, the thing is that ""AST", in the pedantic way, is the "abstract" program, the one that is the true execution and semantic truth.

If the lang is simple enough you don't care about the distinctions, but the more complexity the more being "abstract" goes against your goals.

So, to be clear: The AST should not have macros at all, that is something that was solved in and early pass.

In general, there is a step of "desugaring" where the special cases and shortcut are normalized into canonical forms (for example all iterator magic is removed away), and in some langs, that is also removed away to be even more "abstract" where is not possible anymore to cleanly map back to the source code.

So all of this is purely in terms of necessity, where you get Source code -> ? * N steps -> AST -> ? * N steps -> Final output OR execution

(If you look at "nano pass" is argued that have dozen, thousands of step is cool)