ABI Layer 4: prove the FFI result-code seam is injective + faithful#38
Merged
Conversation
Add Nimiser.ABI.Semantics, a machine-checked semantic proof that the Nim->C code generator preserves source signatures: same name, same arity, and every argument/return type lowered by the canonical injective nimToC mapping. An arity or type mismatch is unrepresentable as a SigPreserved witness. Contents: - Faithful model: NimT / CT type universes, NimSig / CSig signatures, total nimToC lowering, genBinding code generator. - Headline property SigPreserved with no constructor for any mismatch. - genBindingPreserves: the generator ALWAYS preserves (soundness). - nimToCInjective: the lowering is injective (non-vacuity engine). - decSigPreserved: sound + complete Dec decision procedure. - certifyBinding + certifyBindingSound tied to the project Result type; generatedAlwaysCertifies corollary. - Positive control samplePreserved (explicit witness) and three negative controls (wrong return type, wrong arity, wrong arg type), all machine-checked. Build: idris2 --build nimiser-abi.ipkg exits 0, zero warnings. Adversarial false proof (claiming a type-mismatched binding is preserved) is rejected by the type-checker, confirming non-vacuity. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6PSzJWpRxtzGDjUCEh7Mx
Adds Nimiser.ABI.Invariants over the existing Semantics codegen model (NimT/CT/nimToC/NimSig/CSig/genBinding/ArgsLower), proving two facts deeper than and distinct from the Layer-2 signature-preservation theorem: 1. Composition/distributivity: lowering is a homomorphism over argument- list concatenation (lowerAppendDistrib), lifted relationally (argsLowerAppend) and to signature extension (genBindingExtendComposes, extendedArgsLower) — codegen of a grown proc is the grown codegen. 2. Whole-signature injectivity: genBindingInjective shows distinct Nim signatures lower to distinct C bindings (no symbol/ABI aliasing), strictly stronger than the Layer-2 per-type nimToCInjective lemma. Includes a sound+complete DecEq NimSig, a positive control (composed ArgsLower witness on concrete data) and negative/non-vacuity controls (distinctSigsDistinctBindings, extensionChangesBinding, decEqDistinctIsNo). Builds clean (exit 0, zero warnings); adversarial false-equality proof via genBindingInjective is rejected. No believe_me/postulate/assert_total/etc. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6PSzJWpRxtzGDjUCEh7Mx
Seals the ABI<->FFI seam on the proof side: proves the Result result-code encoding is sound, complementing the structural abi-ffi-gate.py check. - intToResult: total Bits32 -> Maybe Result decoder - resultRoundTrip: faithful/lossless encoding (decode . encode = Just) - resultToIntInjective: distinct outcomes never collide on the wire, derived from the round-trip via justInjective . cong - positive controls (decode 0/7/8) and a non-vacuity negative control (Not (resultToInt Ok = resultToInt Error)), all machine-checked No ProofStatus/statusToInt or other FFI enum encoder exists in this ABI, so Result is the sole seam. Genuine total proof: no believe_me, postulate, assert_total, idris_crash, or %hint hacks. Builds clean with zero warnings. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A6PSzJWpRxtzGDjUCEh7Mx
Signed-off-by: Jonathan D.A. Jewell <6759885+hyperpolymath@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Layer 4 (seal the ABI↔FFI seam): proves the FFI result-code encoding (
resultToInt) is a sound, lossless wire encoding — decoderintToResultwithresultRoundTrip, from whichresultToIntInjectiveis derived. Distinct ABI outcomes never collide on the C wire. Complements the structuralabi-ffi-gate.py.New module
*.ABI.FfiSeam(importsTypes). Positive + non-vacuity controls.Testing
Idris2 0.7.0
--build→ exit 0, zero warnings. Adversarial rejection confirmed.build/removed. Nobelieve_me/postulate/sorry.🤖 Generated with Claude Code
https://claude.ai/code/session_01A6PSzJWpRxtzGDjUCEh7Mx
Generated by Claude Code