update docs for compile chain

This commit is contained in:
2026-02-20 14:35:48 -06:00
parent 285395807b
commit 2f41f58521
10 changed files with 205 additions and 5 deletions

View File

@@ -69,6 +69,7 @@ Optimizes the Mcode IR through a series of independent passes. Operates per-func
6. **Move elimination**: Removes self-moves (`move a, a`).
7. **Unreachable elimination**: Nops dead code after `return` until the next label.
8. **Dead jump elimination**: Removes jumps to the immediately following label.
9. **Compile-time diagnostics** (optional): When `_warn` is set on the mcode input, emits errors for provably wrong operations (storing named property on array, invoking null, etc.) and warnings for suspicious patterns (named property access on array/text). The engine aborts compilation if any error-severity diagnostics are emitted.
See [Streamline Optimizer](streamline.md) for detailed pass descriptions.
@@ -134,6 +135,7 @@ Seeds are used during cold start (empty cache) to compile the pipeline modules f
| `mcode.ce --pretty` | Print raw Mcode IR before streamlining |
| `streamline.ce --types` | Print streamlined IR with type annotations |
| `streamline.ce --stats` | Print IR after streamlining with before/after stats |
| `streamline.ce --diagnose` | Print compile-time diagnostics (type errors and warnings) |
## Test Files
@@ -146,3 +148,4 @@ Seeds are used during cold start (empty cache) to compile the pipeline modules f
| `qbe_test.ce` | End-to-end QBE IL generation |
| `test_intrinsics.cm` | Inlined intrinsic opcodes (is_array, length, push, etc.) |
| `test_backward.cm` | Backward type propagation for parameters |
| `tests/compile.cm` | Compile-time diagnostics (type errors and warnings) |

View File

@@ -178,6 +178,36 @@ Removes `jump L` instructions where `L` is the immediately following label (skip
**Nop prefix:** `_nop_dj_`
### 9. diagnose_function (compile-time diagnostics)
Optional pass that runs when `_warn` is set on the mcode input. Performs a forward type-tracking scan and emits diagnostics for provably wrong operations. Diagnostics are collected in `ir._diagnostics` as `{severity, file, line, col, message}` records.
This pass does not modify instructions — it only emits diagnostics.
**Errors** (compilation is aborted):
| Pattern | Message |
|---------|---------|
| `store_field` on T_ARRAY | storing named property on array |
| `store_index` on T_RECORD | storing numeric index on record |
| `store_field` / `store_index` on T_TEXT | storing property/index on text |
| `push` on T_TEXT / T_RECORD | push on text/record |
| `invoke` on T_NULL / T_INT / T_FLOAT / T_NUM / T_TEXT / T_BOOL / T_ARRAY | invoking null/number/text/bool/array |
| arity mismatch (module imports only) | function expects N arguments, got M |
**Warnings** (compilation continues):
| Pattern | Message |
|---------|---------|
| `load_field` on T_ARRAY | named property access on array |
| `load_field` on T_TEXT | named property access on text |
| `load_dynamic` with T_TEXT key on T_RECORD | text key on record |
| `load_dynamic` with T_RECORD / T_ARRAY / T_BOOL / T_NULL key on T_RECORD | record/array/bool/null key on record |
The engine (`internal/engine.cm`) prints all diagnostics and aborts compilation if any have severity `"error"`. Warnings are printed but do not block compilation.
**Nop prefix:** none (diagnostics only, does not modify instructions)
## Pass Composition
All passes run in sequence in `optimize_function`:
@@ -191,6 +221,7 @@ simplify_booleans
eliminate_moves
eliminate_unreachable
eliminate_dead_jumps
diagnose_function → optional, when _warn is set
```
Each pass is independent and can be commented out for testing or benchmarking.