Skip to content

feat(history): add a symbolic history evaluator with Verus proofs - #985

Draft
Lef Ioannidis (elefthei) wants to merge 4 commits into
microsoft:mainfrom
elefthei:upstream/history-3-symbolic
Draft

Lef Ioannidis (elefthei) wants to merge 4 commits into
microsoft:mainfrom
elefthei:upstream/history-3-symbolic

Conversation

@elefthei

@elefthei Lef Ioannidis (elefthei) commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

The 4,096-node rule graph in tests/history_table.rs round-trips in #984, but the reference evaluator returns GraphBudget when it unfolds that graph into a tree. It caps each expansion or derivative at depth 256 and 65,536 nodes. HistoryStep now evaluates the same rule on a graph that preserves shared subexpressions. The Rego syntax, v7 program format and native HistoryStore/RegoVM API stay the same.

The new src/history-semantics crate normalizes rules, computes symbolic derivatives on hash-consed graphs and advances a RuleRuntime cursor one batch at a time. It starts at the declared root even if that isn't the last node, without unfolding unused nodes. The crate is publishable and exposes CompiledRule, Validator and TracePolicy for typed callers. src/junco-core adds bits and the numeric kernel; its unverified reference evaluator from #984 now builds only under test-util.

rvm::vm::history_tables drives RuleRuntime. VMs attached to the same HistoryStore wrapper share bounded caches, keyed by program, for compiled rule graphs and retained per-history prefixes. An active continuation pins its graph. If a batch fails, its cursor stays where the batch began. If a lazily built graph exceeds its 100 KiB payload budget, the rule gets one retry per decision on a fresh graph.

Store and dependencies

src/history-store adds graph, cache and keyed modules and typed Store<E> and History<E> views. Its graph arenas use hashconsius 0.1.4 and bumpus 0.1.2 from crates.io. Both crates are MIT-licensed and verified with Verus. hashconsius also pins bumpus =0.1.2, so Cargo resolves one copy. Locking uses parking_lot with std and spin without it.

The root history feature enables the store and semantics runtimes; cache forwards history-semantics?/cache. The history crates also use lru and smallvec. The smallvec pin (=1.16.2) takes the workspace lockfile back from 1.16.4. history-syntax uses frunk_core for event coproducts. The binding lockfiles include the new path crates.

What Verus checks

When evaluation succeeds, the Boolean agrees with the source rule on the pinned history prefix. The proofs cover lowering owned rules, encoding their constants, the numeric compiler and evaluator, agreement between typed and numeric histories, and reuse of cached decisions. src/verify/history_host.rs checks Regorus's construct, resume and advance calls under host limits. It assumes the specifications for ExecutionTimer, monotonic_now and the memory-limit checks. Regorus's Rego-to-rule lowering and native byte interner are outside that proof.

The root crate and all four history crates set [package.metadata.verus] verify = true. About 22,000 of the history crates' 74,000 lines are in junco-core/src/{spec,verify} and history-semantics/src/{spec,verify}; runtime modules also contain inline verus! contracts and proofs. None of the history proofs use src/verify/value_{assumptions,numeric,specs}.rs or the matching Value, Array, Object and Set view annotations from the source branch, so those changes aren't in this PR.

.github/workflows/verus.yml uses Verus 0.2026.10.04.426d8b0. The root and all four history crates pin vstd to =0.0.0-2026-10-04-0306. The Verus release selects Rust 1.98.1 for the proof job; normal builds stay on 1.95.0. The job runs cargo verus verify --locked with defaults, with --features history and with --no-default-features --features history,arc,std. In lib.rs, #![cfg_attr(verus_keep_ghost, feature(allocator_api))] enables the allocator API during verification. RegoVM derives Debug only outside Verus builds because the history records have no ghost Debug model.

Tests

For every generated word, tests/history_table.rs compares the split-word regex oracle, junco_core::reference on the lowered FlatPair<u64>, and the RVM. It runs the RVM in both modes at batch sizes 1, 2, 64, 256 and 1024. typed_semantics_and_rego_history_rules_agree compares the typed Store/CompiledRule API with compiled Rego in both modes, including requests that don't match a constant in the head. staging_requires_attachment_and_each_domain_membership checks that the byte-domain facade rejects IDs issued only by a typed Store<E>.

CI runs cargo test -p history-syntax -p junco-core -p history-store -p history-semantics --features history-semantics/test-util,history-store/test-util. This covers the history-semantics tests, graph, cache and typed-store tests in history-store, the history-syntax DSL tests and the reference evaluator's unit tests.

Stacked on #984, after #982 and #983. Review the last commit.

Step mode suspends after every Continue. handle_instruction_suspend advanced
the top frame's pc whenever frame.pc <= self.pc, so after CallRule pushed a
callee laid out before its caller, the callee frame's entry pc was bumped past
RuleInit and the rule body ran from the wrong instruction.

Only an explicit InstructionOutcome::Suspend now advances the frame pc; the
Continue arm already did, and a pushed callee frame owns its pc.

- tests/rvm/vm/suites/call_rule.yaml: call_rule_callee_laid_out_before_caller
…n unimplemented)

- Added the history-syntax and junco-core crates (rule syntax, portable flat sources, flattening, validation); LimitError moved into junco-core and is re-exported at its old path.
- With feature `history`, the RVM compiler lowers history.require/forbid to one row of Program::history_tables[0] plus one HistoryStep; executing it fails with the fatal HistoryUnimplemented (HistoryFeatureDisabled without the feature).
- Program format version 7 is additive: HistoryStep is the last Instruction variant and history data lives in a trailing binary section, so version-6 blobs still decode completely.
- CI runs the history tests and the std,arc,history feature subset; docs cover the syntax, HistoryStep and the v7 layout.
…ator

- Add the history-store crate: interned identities and committed histories with revisions.
- Add junco-core lower_flat and the runtime reference evaluator (depth 256, 65536 nodes).
- RegoVM::attach_history/set_history_input; HistoryStep pins a revision at its first
  dispatch, folds at most batch_size events per dispatch and repeats at the same PC.
- Replace HistoryUnimplemented with typed fatal history errors; recheck the revision on
  resume and completion.
- load_program always cancels a suspended execution.
- Port the history_table suite; CI tests history-store.
- Add history-semantics (normalization, symbolic derivatives, cursor-batched RuleRuntime) and run it from HistoryStep.
- history-store gains hash-consed graphs (hashconsius 0.1.4, bumpus 0.1.2), bounded caches and the typed Store<E>/History<E> views.
- Restore the Verus specs and proofs; verus.yml verifies the default, history and no-default history,arc,std configurations.
- Keep the reference evaluator as a test-util oracle; the exhaustive word test checks it against the regex oracle and the RVM.
- Balance generated alternations in history_tables tests under the parser's expression depth limit.
@elefthei Lef Ioannidis (elefthei) changed the title feat(history): symbolic derivative runtime, graph store and Verus proofs feat(history): add a symbolic history evaluator with Verus proofs Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant