I have been working on a potential feature for the zig language which I call the “annotation system”. The Pitch:
- Any KNOWLEDGE that can be derived from ‘looking at the code’, will be derivable through the annotation system (ideally).
- Such knowledge will be provided at comptime, and can be use to add arbitrary CONSTRAINT to the code.
- Each constraint is effectively either a PROOF or a compile error.
- An ANNOTATION on an expression represent a constraint application, these are like “comments that runs”; They work cooperatively to make STATEMENTs about the code.
- The statements are effectively TAGs, not available for regular comptime evaluation, but can be themself be used by the annotation system and query by ‘external tools’ (build system, source gen…)
(…)
This would allow, in it’s primal form, doing thing like custom control flow analysis, resource lifetime tracing, distinct types, anytype refinement, enforce architecture code… all in user code. It’s like an add-on over the type system.
To do so, I’m working on a from scratch implementation of zig language using zig. The code should be public in a few weeks from now. It will mostly be an interpreter.
Why?
- Simpler codebase
- Simpler AST representation + api
- More easily work on the main compiler (debug execution flow)
- Try out, to see how it can be improved
How
- Using zig
- Heavily
abuse comptime - Focus is on “front end”: parsing, semantic analysis, RLS… (some “low level” related behavior might be off in first releases…)
- Priority is more on agility than on performance
What: to expect on the long run
- Interpret zig code (comptime and runtime).
- REPL: to enable interactive dev env
- Code intelligence via the “annotation system”, like
grepbut better suited for a language like zig - Provide a simple way for external tools (like LSP) to understand zig’s (comptime) code evaluation
- Integrate with zig at specific compilation phases (ZIR and AIR)
- Other features under a
--experimentalflag?