Skip to content

[anneal][mir] Model char, Cmp, *WithOverflow, and CastKind.intToInt - #4005

Draft
joshlf wants to merge 1 commit into
joshlf-anneal-mir-completeness-03-memory-modelfrom
joshlf-anneal-mir-completeness-04-unop-binop-casts
Draft

joshlf wants to merge 1 commit into
joshlf-anneal-mir-completeness-03-memory-modelfrom
joshlf-anneal-mir-completeness-04-unop-binop-casts

Conversation

@joshlf

@joshlf joshlf commented Nov 20, 2026

Copy link
Copy Markdown
Member

Authored by an AI agent acting on joshlf's behalf.

Human review surface

  • Pass 1 Lean TCB (anneal/trusted/lean/):
    • anneal/trusted/lean/Trusted/MirAst.lean, MirAst/Types.lean, MirAst/Rvalues.lean: Added MirTy.char, MirTy.ordering (for core::cmp::Ordering, #[repr(i8)] Less = -1, Equal = 0, Greater = 1 with verbatim library/core/src/cmp.rs rust-lang/rust@8144389c quote), BinOp.cmp, BinOp.isOverflowing (the three BinOp.*WithOverflow variants already existed in Rvalues.lean; added AddWithOverflow quote from syntax.rs@8144389c), CastKind (intToInt | unsupported), and Rvalue.cast; extended MirTy.beq and AST module docs.
    • anneal/trusted/lean/Trusted/MirModel.lean: Added self-contained OrderingVal (less | equal | greater, avoiding Init.Data.Ord.Basic), Val.char (c : Char), and Val.ordering (ord : OrderingVal).
    • anneal/trusted/lean/Trusted/MirSemantics/Layout.lean: Added overflowPairLayout for .tuple [.int w s, .bool] (natural scalar-pair size 2 * (intLayout w).size and natural alignment (intLayout w).alignLog2 — i.e., w.byteSize, including 16 for i128, with w.byteSize - 1 padding bytes matching LayoutData::scalar_pair in simple.rs@8144389c for a=T, b=bool), and admitted .char (⟨4, 2⟩), .ordering (⟨1, 0⟩), and overflow pairs in layoutOfTy. (By existing convention, M_ref layouts use Align.ONE, a difference unobservable in profile v1.)
    • anneal/trusted/lean/Trusted/MirSemantics/Enum.lean: Added isUnicodeScalar (with verbatim rust-lang/reference@a286e1ec quote), orderingTagBits/orderingOfTagBits (255/0/1), isOverflowPairTy, and isIntLikeTy; updated Val.ty?, checkVal, isSupportedScalarOrUnitTy (admitting .char, .ordering, and .tuple [.int w s, .bool]), and isPrimitiveReadableTy (admitting .char and .tuple [.int w s, .bool], while rejecting .ordering and enums whose M_ref tag scalar is .Union).
    • anneal/trusted/lean/Trusted/MirSemantics/Bytes.lean: Extended evalConstLit, encodeVal, and decodeVal for .char, .ordering, and overflow pairs .tuple [.int w s, .bool] (encoding integer + bool + w.byteSize - 1 .uninit padding bytes with verbatim rustc place.rs@8144389c quote; decoding integer and bool slices and ignoring padding bytes).
    • anneal/trusted/lean/Trusted/MirSemantics/Ops.lean: Added cmpOrderingOfInt, intLikeBits, and evalIntToIntCast (with verbatim cast.rs@8144389c quotes); extended evalArithOp (BinOp.{add,sub,mul}WithOverflow returning .tuple [.scalar wrapped, .bool (hostOverflow || lossy)]), evalBinOp (Cmp on same-typed ints -> OrderingVal; Eq..Ge and Cmp on char -> comparing Unicode scalar values; .unsupported on bool.cmp), and evalUnOp docs (rejecting unary ops on char).
    • anneal/trusted/lean/Trusted/MirSemantics/{State,Step,Boundary,CanaryFixtures}.lean and Trusted/MirSemantics.lean: Added static castTypesValid (enforcing dstTy == castTy on unprojected .assign dst (.cast .intToInt _ castTy), enforced in both initState and public BodyStaticAdmitted in Boundary.lean:217 matching rustc well-formed MIR invariant) and .ordering case in discriminantTypesValid; added evalOrderingDiscriminantOfVal, .cast .intToInt in evalRvalue (source-type check -> uninit check -> target check -> u8 -> char check), and evalCharSwitchBranches (plus empty-branches-only switchInt jump to otherwise for overflow pairs, matching rustc's interpreter in step.rs:555-577 even though rustc MIR validation rejects that form) in evalTerminator; added 5 locked Pass 1 canaries (20 -> 25, Canary*AnnealClaim).
  • Pass 2 Correspondence TCB (anneal/trusted/correspondence/):
    • anneal/trusted/correspondence/Trusted/Correspondence/{Codec,Config,Simulation,State}.lean and Trusted/Correspondence.lean: Extended RefRvalue/codec with .cast (and collectTy/interning for .char/.ordering); activated previously fail-closed M_ref leaves (refCastLeaves.typeInfo admitting int/bool/char, refScalarLeaves orderingLayout/overflowLayout and .char typeKind, refValidityHooks.typeKind .char/.ordering/overflow pairs, refProjectFieldLayout field 1 for overflow pairs and field 0 for .ordering, refProjectVariantLayout and refDiscriminantLeaves for .ordering, toMiriRvalue mapping .cast .intToInt to .Cast .IntToInt and .cast .unsupported to .CopyForDeref); updated checkRefVal, evalRefConstLit, valToMiriImmediate, BackendRepr.ScalarPair layout for .tuple [.int w s, .bool], and refReadReturnVal; replaced PR 03's constant-false refHasPadding with the place.rs:971-992 rule (false for Scalar, |a| + |b| != size for ScalarPair — so false for i8/u8 pairs and true for wider overflow pairs — and true for Memory reprs such as .unit, .never, and ZST enums, routing any indirect copy of those through memoryCopy, which tightens Day-1 behavior consistently with M_anneal); added refCastTypesValid and castTypesValid body = true to FrameSimInv; added 3 locked Pass 2 claims D14–D16 (34 -> 37).
  • Auditor & negative tests (anneal/trusted/audit/{TrustedBoundary.lean,src/lib.rs,tests/boundary_audit.rs}):
    • Locked the 5 new Pass 1 canary claims (20 -> 25), 3 new Pass 2 claims (D14–D16, 34 -> 37), and 5 new required live ExecutionMachine Miri primitives in verifyRefEvaluatorIndependence (34 -> 39: IntegerOps.binaryChar, Cast.cast, IntegerCast.cast, ScalarInt.{toChar,ofChar}, all also purity-checked via closureCorr); fixed stale 38,718 -> 38,728 vendor declaration count in doc comment; added matching positive and negative tests in boundary_audit.rs. No auditor allowlists or boundary checks relaxed.
  • Governing & design docs (anneal/docs/{trust-model,mir-correspondence-design}.md):
    • Updated Pass 1/Pass 2 locked counts (20 -> 25, 34 -> 37, 34 -> 39), and updated mir-correspondence-design.md (§1, §3.1, §4.1, §4.4, §4.5, §5.2, §5.4) for char, Ordering, *WithOverflow, CastKind.intToInt, and castTypesValid. (Cumulative stack also relies on PR 03's SimulationInv pinning s.mem = entryMemory and forceAllocation / allocateStack remaining canary-reached only.)
  • Intentional policy relaxations: none.

Summary

Stacks on #3977 (joshlf-anneal-mir-completeness-03-memory-model) to add char values/operations, BinOp.cmp (core::cmp::Ordering), checked-overflow arithmetic (BinOp.{add,sub,mul}WithOverflow producing (T, bool) overflow pairs with natural alignment and padding), and CastKind.intToInt integer/bool/char casts across Trusted.MirAst, Trusted.MirSemantics, Trusted.Correspondence, Anneal.PureLift, Anneal.MirWp, and Anneal.MirCorrespondenceProof.

All 25 Pass 1 MirWp claims, all 37 Pass 2 claims, and all 39 required live ExecutionMachine primitives build, replay, and pass anneal-audit --require-correspondence and cargo test -p anneal-audit with zero sorry.

Extend the executable MIR model, M_ref, PureLift, and the kernel-checked
correspondence proof to cover Unicode scalar char values, three-way
BinOp.cmp comparisons (via core::cmp::Ordering), checked-overflow
arithmetic (BinOp.{add,sub,mul}WithOverflow), and CastKind.intToInt
casts (paths below are relative to anneal/):

- trusted/lean/Trusted/{MirAst.lean,MirAst/{Types,Rvalues}.lean,
  MirModel.lean}: add MirTy.char and MirTy.ordering (for
  core::cmp::Ordering, #[repr(i8)] with Less = -1, Equal = 0,
  Greater = 1), OrderingVal and Val.{char,ordering}, BinOp.cmp,
  BinOp.isOverflowing, CastKind (.intToInt | .unsupported), and
  Rvalue.cast (the three *WithOverflow BinOp variants already existed).
- trusted/lean/Trusted/{MirSemantics.lean,MirSemantics/{Ops,Enum,Layout,
  Bytes,State,Step,Boundary,CanaryFixtures}.lean}: add char layout
  (<4, 2>), ABI valid scalar-value checks (<= 0x10ffff excluding
  surrogates), ordering discriminant reads (i8 dst) and rejection of raw
  primitive reads on Ordering, overflow arithmetic (*WithOverflow in
  Ops.lean), natural-alignment overflow-pair layout (intLayout align; 16
  for i128) and codec for .tuple [.int w s, .bool] with uninit padding
  bytes ignored on decodeVal, evalCharSwitchBranches, CastKind.intToInt
  casts across integers, bool, and char (u8-only integer-to-char),
  castTypesValid enforcement in initState and BodyStaticAdmitted, and
  five Pass 1 canaries (20 -> 25).
- trusted/correspondence/Trusted/{Correspondence.lean,Correspondence/
  {Codec,State,Config,Simulation}.lean}: wire M_ref through
  Miri.Interpreter.ExecutionMachine.step using ScalarOps,
  IntegerOps.binaryChar, ScalarInt.{toChar,ofChar}, Cast.cast, and
  IntegerCast.cast (activating refCastLeaves.typeInfo, refScalarLeaves,
  refValidityHooks, refProjectFieldLayout field 1, and Ordering enum
  hooks), with BackendRepr.ScalarPair layouts, refHasPadding (true for
  Memory reprs and padded ScalarPairs), refCastTypesValid, FrameSimInv
  updated for castTypesValid, and three Pass 2 claims D14-D16
  (34 -> 37).
- theory/Anneal/{MirWp.lean,MirWp/{Canaries,Execution,Reflection}.lean,
  PureLift/MirBridge.lean} and correspondence/Anneal/
  {MirCorrespondenceProof.lean,MirCorrespondence/*.lean}: discharge all
  five new Pass 1 canary theorems, extend PureLift computable mirrors,
  and prove lockstep correspondence (zero sorry, zero Trusted-namespace
  leaks in non-Trusted modules).
- trusted/audit/{TrustedBoundary.lean,src/lib.rs,
  tests/boundary_audit.rs} and
  docs/{trust-model,mir-correspondence-design}.md: lock the 25 Pass 1
  and 37 Pass 2 claims and all 39 required live ExecutionMachine Miri
  primitives with positive and negative tests, fix the stale 38,718 ->
  38,728 vendor declaration count in a TrustedBoundary.lean doc comment,
  and update design docs.

No trust-boundary checks or auditor allowlists are relaxed.

Agent-authored-by: AI agent acting on joshlf's behalf
@joshlf
joshlf added this pull request to stack #3973 November 20, 2026 23:30
@joshlf

joshlf commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Authored by an AI agent acting on joshlf's behalf.

Review Receipt (Gate 1)

  • Reviewed range: target_base (ec75fb464cda7b18581faa83a6a82d0dfdf422d9, origin/main), parent = c52834c383acff50182240b3423f7b636d33632a ([anneal][mir] Add byte-level memory and indirect locals #3977), cumulative from stack_base (1962a9c0e3eda8a3a58387f61c70ddd2c396b118), head = 597288c976f9fefb7da109f00d9e3a76c05cc40b (joshlf-anneal-mir-completeness-04-unop-binop-casts, tree 8fda69226fe60fca6a515e80eaa651618ab8ca24, 38 paths under anneal/; git merge-tree --write-tree ec75fb464c 597288c976 -> a2c0fc1d, origin/main 9e45f0d86c -> 1f71dd07, 0 conflicts).
  • Passes & reviewers: Two rounds of independent read-only Pass 1, Pass 2 (trust-review, including verbatim quote checks against rust-lang/rust@8144389c / rust-lang/reference@a286e1ec / vendor/lean-miri@c92d1d9754c9, 36-root/correspondence cone checks, and empirical rustc tuple layout measurement for (u8,bool)..(u128,bool)), and general change-review across two distinct model families (inspecting read-only via git from clean base, never entering candidate worktrees).
  • Findings & resolution:
    • Round 1 found 0 code, soundness, upstream-fidelity, or auditor defects across all 38 paths, and requested fixes to the planned Human review surface block (natural alignment formula for overflowPairLayout, refHasPadding returning true for .Memory reprs, BodyStaticAdmitted omission, existing *WithOverflow attribution, and newly active M_ref leaves) plus stale design-doc sections (§3.1, §4.1, §4.4, §4.5 in docs/mir-correspondence-design.md) and a minor commit-body phrasing fix.
    • Round 2 updated anneal/docs/mir-correspondence-design.md (07e9974b52..597288c976 touches only that file; all trusted/, theory/, correspondence/, ci/, and vendor/ blobs remain byte-identical to 07e9974b52), amended the commit message (53 lines, 0 >72 cols), and corrected the Human review surface block (including Round 2 section-list and w.byteSize - 1 fixes). Verdict: Unanimous APPROVE (0 open trust questions).
  • Deterministic checks:
    • Verified directly on 07e9974b52 (exact same .lean/.rs/config tree as 597288c976; TrustedBoundary.lean sha256 29e902214f2f599b19e753b44849e78900d455dbd76eb4869a1c74e898497fb3):
      • scan_pass2_leaks.py: Compiled 53 updated modules (total 53). NONE! ZERO LEAKS!
      • cargo fmt -- --config-path /dev/null --check (clean) and cargo clippy --locked -p anneal-audit --all-targets -- -D warnings (0 warnings).
      • cargo test --locked -p anneal-audit: 61/61 passed (19 lib unit, 38 boundary_audit including all new PR 04 canary and primitive negative tests, 4 cli_environment; 0 skipped/filtered).
      • Mechanical Pass 1 TCB reachability closure over pr04_audit.json: 749/1651 declarations reached from locked Pass 1 roots + Trusted.Crate/UnitTheorem/*AtChoices (0 unreached user-written declarations; only Lean-generated recursor/field projections outside closure).
      • git grep '\bsorry\b\|\badmit\b' and theory/ noncomputable check: 0 occurrences in proof code.
    • Supplied author verification on byte-identical Lean/Rust tree (b42280ed40):
      • build.py (53/53 [ok]), anneal-audit --require-correspondence --miri-cache-dir <cache> --json (exit 0, replay: true 5425/6307, axioms: ['propext'], miriReplay: true 38728 across 160 modules, correspondenceReplay: true 2673/2673, checkedAlternateProofs: 0), and 1-guard-disabled probe on TrustedBoundary.lean (failed enforces_correspondence_non_backsliding exit 101, restored byte-identically).
    • Verified post-amend on 597288c976 (clean tree):
      • ./anneal/ci/check_todo.sh (root and anneal/), sha256sum --check --strict trusted/root-manifest.sha256, ./ci/check_actions.sh, ./ci/check_job_dependencies.sh, ./ci/check_non_stable_version.sh, python3 -B -m unittest discover -s ci -p 'test_*.py' (67/67 passed), 80-col doc check, and git merge-tree.
  • Checks not executed locally (gated on GitHub CI): nix build .#omnibus-archive, cargo test --workspace, installed_smoke, and re-running anneal-audit after the docs-only amend.
  • Remaining gates: Gate 2 (Codex review), Gate 3 (GitHub CI), Gate 5 (human review & merge).

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T23:32:58.981820Z 597288c Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 597288c976

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.99%. Comparing base (c52834c) to head (597288c).

Additional details and impacted files
@@                               Coverage Diff                               @@
##           joshlf-anneal-mir-completeness-03-memory-model    #4005   +/-   ##
===============================================================================
  Coverage                                           92.99%   92.99%           
===============================================================================
  Files                                                  16       16           
  Lines                                                2469     2469           
===============================================================================
  Hits                                                 2296     2296           
  Misses                                                173      173           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

2 participants