Skip to content

Commit 9334faa

Browse files
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_01Cg6DVXahkyY68Ruu7f76rG
1 parent f30176f commit 9334faa

11 files changed

Lines changed: 2783 additions & 1 deletion

File tree

‎rust/Cargo.lock‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rust/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
[workspace]
1010
resolver = "2"
11-
members = ["crates/own-ir", "crates/own-syntax"]
11+
members = ["crates/own-ir", "crates/own-syntax", "crates/own-cfg"]
1212

1313
[workspace.package]
1414
edition = "2021"

‎rust/crates/own-cfg/Cargo.toml‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "own-cfg"
3+
description = "OwnLang AST -> CFG lowering, an exact port of ownlang/{cfg,cfg_json,buffers}.py gated by the CFG-JSON differential oracle"
4+
edition.workspace = true
5+
rust-version.workspace = true
6+
license.workspace = true
7+
publish.workspace = true
8+
version = "0.1.0"
9+
10+
[dependencies]
11+
own-syntax = { path = "../own-syntax" }
12+
# The canonical CFG JSON seam is built as a serde_json value tree and dumped
13+
# through a Python-`json.dumps(indent=2, sort_keys=True)`-compatible printer, so
14+
# the oracle can byte-compare it against `python -m ownlang cfg --format json`.
15+
serde_json = { workspace = true }
16+
17+
[dev-dependencies]
18+
19+
[lints]
20+
workspace = true

0 commit comments

Comments
 (0)