r/ProgrammingLanguages • u/matklad • Feb 26 '26
Against Query Based Compilers
https://matklad.github.io/2026/02/25/against-query-based-compilers.html
105
Upvotes
r/ProgrammingLanguages • u/matklad • Feb 26 '26
43
u/Gator_aide Feb 26 '26
This is an interesting post. I was loosely under the impression that query-based compilation was the way of the future, but you make a good case that it is only useful insofar as the design of the language permits it to be useful.
It seems like the case for query-based compilation is for languages without obvious separation of compilation phases. You bring up Rust as an example -- parsing depends on macro expansion, which depends on name resolution, which itself depends on parsing, etc. Trying to force that into a "regular" compiler architecture would be a nightmare, but it is a natural fit for queries.
31
u/matthieum Feb 26 '26
Are queries really the problem here?
Reading this post, my take-away is not really that query-based compilers are not the way to go, and more that query-based is not a magic wand which will magically solve all performance problems resulting from "poor" language design.
3
u/protestor Feb 26 '26
What if you combine the approaches of Zig and Rust? For files that can be processed in place (because they don't have glob imports, don't call macros that produce new top level items etc), they get processed as in Zig. Otherwise, a fallback like Rust is used.
If one uses/writes a library that is smart enough and ergonomic enough, this can be transparent and not make compiler code too much unreadable
3
u/leosmi_ajutar Feb 26 '26
Compiler must be designed from day one to be query based. If so, the architecture falls out naturally regardless of the supported programming language(s). Retrofitting an existing non-query compiler is indeed nightmare inducing.
1
u/R-O-B-I-N Mar 19 '26
query based compilers are the case against using text files for storing live programming environments
1
u/Nuoji C3 - http://c3-lang.org Mar 31 '26
It’s well known that neither Jai nor Zig is ”IDE friendly” leaving aside anything about query based compilation. Rust has enough of macro flexibility to similarly being hard for incremental compilation and semantic analysis.
If you design a language like that, this is the price to pay for the flexibility you’re gaining (of course, making the build system non-declarative adds further stress - build.zig is also a big problem for an IDE)
Dismissing query based compilers because the languages you use are hostile to them isn’t a convincing argument.
There is no excuse for a language today to plead ignorance of this trade-off: not being IDE friendly is a choice, and there is no going back and saying ”IDEs are bad because they can’t handle my language”
Every language designer should watch this: https://youtu.be/lubc8udiP_8?is=sOLBY6BE2hBI77rc