@@ -39,11 +39,19 @@ match-based smartcasting are all supported. The transformer lowers sum type
3939match branches to ` is_expr ` nodes, enabling smartcast field access through union
4040variants in both ` if ` and ` match ` blocks.
4141
42- Type checking runs as a shared pipeline phase before backend selection :
42+ Type checking runs before transform, matching V1 and V2 :
4343` TypeChecker.collect() ` walks the flat AST to extract function signatures,
4444struct fields, enum names, type aliases, sum types, and C function declarations,
45- then registers runtime method signatures. Both the C backend and future backends
46- receive the pre-populated ` TypeChecker ` .
45+ then registers runtime method signatures. ` check_semantics() ` validates the
46+ unlowered source program before the transformer rewrites it. Both the C backend
47+ and future backends receive the pre-populated ` TypeChecker ` .
48+
49+ After transform, v3 runs ` annotate_types() ` . This is not a second semantic
50+ checker pass and should not report source diagnostics. It repopulates
51+ expression-type metadata for the post-transform flat AST, including new node IDs
52+ created by lowering. V1 and V2 do not need a separate step because their checker
53+ updates the typed AST/table that later stages keep using directly; v3's flat AST
54+ keeps those per-node caches outside the nodes.
4755
4856Imports are resolved recursively: after parsing the input file, the driver
4957collects ` import_decl ` nodes, resolves module paths, parses module files, and
@@ -53,9 +61,9 @@ repeats until no new imports are found.
5361
5462```
5563source + vlib/builtin -> scanner -> flat parser -> flat AST -> imports
56- -> transform -> check -> markused -> gen C -> cc
57- \-> SSA build -> ARM64 gen -> link
58- \-> optimize -> MIR -> insel (-prod)
64+ -> check -> transform -> annotate types -> markused -> gen C -> cc
65+ \-> SSA build -> ARM64 gen -> link
66+ \-> optimize -> MIR -> insel (-prod)
5967```
6068
6169The parser directly emits a flat AST. There is no recursive AST intermediate and
@@ -93,7 +101,8 @@ lowers to C type strings only at final emission. Lexical scopes store
93101generation. Function bodies from builtins are skipped during C code generation;
94102only type and declaration information is used.
95103
96- The transformer lowers match statements to if/else chains and collects struct/global type info.
104+ The transformer lowers match statements to if/else chains and collects
105+ struct/global type info for its own type-dependent rewrites.
97106
98107The markused pass performs reachability analysis from ` main ` , building a call
99108graph and BFS-walking to find all used functions. Method calls are resolved to
@@ -172,36 +181,37 @@ function pointers.
172181| cc | 79 ms | 17,312 KB |
173182| ** total** | ** ~ 259 ms** | ** 17,312 KB** |
174183
175- All v3 steps (parse + transform + check + markused + gen + write) complete in
176- ~ 8 ms for hello world, including 38 builtin files, and ~ 157 ms for ` test.v `
177- with the C backend.
184+ All v3 steps (parse + check + transform + annotate types + markused + gen +
185+ write) complete in ~ 8 ms for hello world, including 38 builtin files, and
186+ ~ 157 ms for ` test.v ` with the C backend.
178187
179188Peak RSS: 9-17 MB.
180189
181- Compiling ` v3.v ` itself with a ` v3 ` seed binary built by V :
190+ Compiling ` v3.v ` itself in the C self-host chain :
182191
183192Commands:
184193
185- - ` ./vnew -o /tmp/v3_perf_seed vlib/v3 `
186- - ` /tmp/v3_perf_seed vlib/v3/v3.v -o /tmp/v3_self_c_perf_warm `
187- - ` /tmp/v3_perf_seed vlib/v3/v3.v -b arm64 -o /tmp/v3_self_arm_perf_warm `
188-
189- Both backend rows compile the target without ` -prod ` . The C backend uses
190- bundled TCC for the final ` cc ` step; the ARM64 backend emits and links a
191- Mach-O binary directly.
192-
193- | Phase | C backend | ARM64 backend |
194- | -------------| ----------:| --------------:|
195- | parse | 69 ms | 71 ms |
196- | transform | 489 ms | 486 ms |
197- | check | 176 ms | 171 ms |
198- | markused | 356 ms | 354 ms |
199- | gen C/write | 345 ms | - |
200- | ssa build | - | 3,931 ms |
201- | arm64 gen | - | 1,414 ms |
202- | cc/link | 56 ms | 226 ms |
203- | ** total** | ** 1,509 ms** | ** 6,677 ms** |
204- | Peak RSS | 171 MB | 399 MB |
194+ ``` sh
195+ v -gc none -prod -o v3 v3.v
196+ ./v3 -parallel -o v4 v3.v
197+ ./v4 -o v5 v3.v
198+ ./v5 -o v6 v3.v
199+ ```
200+
201+ The table uses the first v3-generated C stage, ` ./v3 -parallel -o v4 v3.v ` .
202+ Bundled TCC currently rejects the atomic helper shims on macOS and the driver
203+ falls back to ` cc ` .
204+
205+ | Phase | Time | Peak RSS |
206+ | ----------------| ----------:| ---------:|
207+ | parse | 47.33 ms | 73 MB |
208+ | check | 43.92 ms | 131 MB |
209+ | transform | 94.83 ms | 274 MB |
210+ | annotate types | 30.46 ms | 307 MB |
211+ | markused | 48.53 ms | 354 MB |
212+ | gen C/write | 94.67 ms | 455 MB |
213+ | cc | 707.84 ms | 455 MB |
214+ | ** total** | ** 1,092.92 ms** | ** 455 MB** |
205215
206216## Comparison with V1
207217
0 commit comments