code wiki / _hdl_build / nx_eqsat_constfold_test.nx

nx_eqsat_constfold_test.nx

buildroot/runtime/_hdl_build/nx_eqsat_constfold_test.nx

11395 B193 linesdepth 9pulls 13 transitivereach 0 importersview sourcekind gate/prooftopic eqsat
docsdependenciesstructsconstsfunctions

about

nx_eqsat_constfold_test.nx -- the CONST-FOLD GATE: proves the egg-style e-class ANALYSIS (constant folding / propagation) newly integrated into nx_eqsat.nx is (a) SOUND BY EVALUATION (folds via the PROVEN nx_gsim_eval_cell oracle), (b) CERTIFIED through membership-as-proof (cites NX_EQSAT_RULE_CONSTFOLD, admitted to the proven-sound allow-list + lockstep), and (c) LOAD-BEARING (a wrong fold / unmapped op / unproven rule is REFUSED). FAIL LOUD known-answer; exit 0 iff every check holds. STEPS (each self-asserts; mismatch => sys_exit(nonzero)): STEP 0 LOCKSTEP: MP_RULE_CONSTFOLD == NX_EQSAT_RULE_CONSTFOLD (and the whole id table agrees), so the live log the engine writes is never mislabeled. Also: MP_RULE_CONSTFOLD must be in the proven-sound allow-list. STEP 1 POSITIVE (add 2 3)->5, LIVE + CERTIFIED: enable prov + constfold, run the REAL saturator, assert find(add23)==find(5), the log contains RULE_CONSTFOLD, and mp_certify_live CERTIFIES (member && sound). STEP 2 MORE OPS: (mul 6 7)->42 and (shl 1 4)->16 fold + certify (same engine path). STEP 3 NEGATIVE -- WRONG FOLD REFUSED: (a) an unmapped op (DIV) never folds even with const children (nx_eqsat_op_to_gate_kind(DIV) < 0) -- find stays distinct from any const; (b) an UNPROVEN rule id (BOGUS) is NOT in the allow-list so mp_log_all_sound would refuse it -- a back-door wrong fold cannot certify; (c) folding is OFF by default (no enable => no fold => no CONSTFOLD in the log) so the feature is opt-in by construction. Known answer (FAIL LOUD): prints "5 42 16 1 1 1 " == folded(add 2 3), folded(mul 6 7), folded(shl 1 4), cert_add, cert_mul, cert_shl. exit 0 iff all steps hold.

dependencies 1 imports · 0 importers

nx_eqsat_membership_proof.nx nx_eqsat_constfold_test.nx

imports: nx_eqsat_membership_proof.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main mp_rule_ids_lockstep mp_is_sound_rule _fold_binop nx_eqsat_init nx_eqsat_enable_prov nx_eqsat_enable_constfold sys_mmap nx_eqsat_add_const nx_eqsat_add nx_eqsat_op_is_valid nx_eqsat_arity_for nx_cf_intern_const nx_eqsat_add_const ↻ nx_eqsat_mix nx_cf_make_const_node nx_eqsat_new_class nx_eqsat_find nx_eqsat_find ↻ nx_eqsat_fold_value nx_eqsat_op_to_gate_kind nx_gsim_kind_supported nx_eqsat_arity_for ↻ nx_eqsat_find ↻ nx_gsim_eval_cell nx_eqsat_op_cost nx_eqsat_new_class ↻ nx_eqsat_union_cited nx_eqsat_find ↻ nx_eqsat_log_rule nx_eqsat_push_dirty nx_eqsat_fingerprint nx_eqsat_mix ↻ nx_hmap_has nx_hmap_probe_find nx_hmap_hash nx_hmap_entry_at nx_hmap_get nx_hmap_probe_find ↻ nx_hmap_entry_at ↻

structs

none

consts

none

functions

30func _emit_num(v: i64) -> i64
called by 1: main
38func _nl() -> i64 { let z: *u8 = sys_mmap(2); z[0] = 10; sys_write(1, z, 1); return 0 }
called by 1: main
41func _log_has(g: *NxEGraph, want: i64) -> i64
called by 2: _fold_binopmain
53func _fold_binop(op: i64, a: i64, b: i64, cert_out: *i64) -> i64
86func main() -> i64