Repository navigation
Commit 9334faa
committed
feat: P-022 step 3 — port own-cfg (AST → CFG lowering) with exact CFG-JSON parity
Third strangler-fig step of the P-022 Rust core migration. `own-cfg` lowers the
`own-syntax` AST to a control-flow graph and projects the canonical CFG-JSON
seam, mirroring `ownlang/{cfg,cfg_json,buffers}.py` line-for-line. Python stays
authoritative; this port introduces no behaviour change.
Crate (rust/crates/own-cfg, depends on own-syntax only, per the P-022 DAG — no
analysis/diagnostics edge):
* ir.rs — Kind/Symbol/Instr/Block/Cfg/Signature; symbol identity is a
newtype arena index (replacing Python's id(sym)), blocks are
threaded by BlockId so lowering never aliases a &mut.
* buffers.rs — buffers.py resolve/validate_policies/BufferInfo, value-for-value.
* builder.rs — the _Builder scope resolver + AST→CFG lowering + collect_*.
* json.rs — cfg_json.py projection plus a serializer that reproduces
json.dumps(indent=2, sort_keys=True, ensure_ascii=True)
byte-for-byte (the property the seam rests on).
Parity gate (mirrors the step-2 syntax fixtures):
* tests/test_cfg_fixtures.py (Python-authoritative) sweeps corpus/, examples/,
tests/fixtures/ plus curated cases, and freezes each input's canonical CFG
JSON + (line, code) diagnostics into tests/fixtures/cfg_parity.json; the
Python suite fails if it is stale.
* rust/crates/own-cfg/tests/parity.rs replays every case and asserts the
byte-identical CFG JSON, the identical diagnostics, and — for rejected
sources — the identical parser error text. 66 cases (60 corpus + 6 curated)
green; the Rust output also matches `python -m ownlang cfg --format json`
end-to-end.
Diagnostics carry code + line only at this step: the CFG-JSON seam does not
carry diagnostic message text (a verdict-layer contract pinned later by the
SARIF oracle), so the human message is deferred to the analysis/diagnostics
step, keeping this step's surface fully covered by its own oracle.
Closes #197
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cg6DVXahkyY68Ruu7f76rG1 parent f30176f commit 9334faa
11 files changed
Lines changed: 2783 additions & 1 deletion
File tree
- rust
- crates/own-cfg
- src
- tests
- tests
- fixtures
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
0 commit comments