|
| 1 | +-- SPDX-License-Identifier: PMPL-1.0-or-later |
| 2 | +-- Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk> |
| 3 | + |
| 4 | +||| VCL-total Interface — Cross-language Wire Conformance (P5b step 2) |
| 5 | +||| |
| 6 | +||| Machine-checked proof that the certified Idris decoder |
| 7 | +||| (`VclTotal.Interface.WireDecode.fromWire`) agrees, byte-for-byte, |
| 8 | +||| with the trusted Rust encoder (`src/interface/parse/src/wire.rs` |
| 9 | +||| `to_wire`) on shared golden fixtures. |
| 10 | +||| |
| 11 | +||| Each `goldenN` is the EXACT `to_wire` image emitted by the Rust |
| 12 | +||| regeneration oracle `src/interface/parse/tests/conformance_emit.rs` |
| 13 | +||| (run that test with `--nocapture` to re-derive these literals; the |
| 14 | +||| literals below are injected verbatim from its output, never |
| 15 | +||| hand-transcribed). The corresponding |
| 16 | +||| `conformN : fromWire goldenN = Right expectedN` is proved by `Refl`: |
| 17 | +||| the corpus build only succeeds if the total decoder, evaluated at |
| 18 | +||| compile time on the Rust bytes, reduces to exactly the expected |
| 19 | +||| certified `Statement`. This is WIRE-FORMAT.adoc's conformance |
| 20 | +||| contract discharged as a proof, not a runtime test — no |
| 21 | +||| proof-escape, %default total. |
| 22 | +||| |
| 23 | +||| Fixtures: F1 minimal; F2 exercises strings / ints / bools / agents / |
| 24 | +||| options / lists / a nested comparison expression and every extension |
| 25 | +||| clause; F3 the float path with the exactly-representable `2.5` |
| 26 | +||| (arbitrary-`f64` bit-exactness — incl. the NaN payload, which the |
| 27 | +||| Idris `Double` boundary does NOT preserve, by disclosure — is the |
| 28 | +||| Rust proptest's job: `wire.rs::golden_bit_exact_floats`). |
| 29 | + |
| 30 | +module VclTotal.Interface.WireConformance |
| 31 | + |
| 32 | +import VclTotal.ABI.Types |
| 33 | +import VclTotal.Core.Grammar |
| 34 | +import VclTotal.Interface.WireDecode |
| 35 | + |
| 36 | +%default total |
| 37 | + |
| 38 | +-- ── F1: minimal — SELECT * FROM STORE "main", level SchemaBound ────── |
| 39 | + |
| 40 | +golden1 : List Bits8 |
| 41 | +golden1 = [86,67,76,87,1,0,1,0,0,0,3,2,4,0,0,0,109,97,105,110,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1] |
| 42 | + |
| 43 | +expected1 : Statement |
| 44 | +expected1 = |
| 45 | + MkStatement [SelStar] (SrcStore "main") |
| 46 | + Nothing [] Nothing [] Nothing Nothing |
| 47 | + Nothing Nothing Nothing Nothing Nothing |
| 48 | + SchemaBound |
| 49 | + |
| 50 | +conform1 : fromWire WireConformance.golden1 = Right WireConformance.expected1 |
| 51 | +conform1 = Refl |
| 52 | + |
| 53 | +-- ── F2: strings/ints/bools/agents/options/lists/nested expr + every |
| 54 | +-- extension clause; level EpistemicSafe ───────────────────────── |
| 55 | + |
| 56 | +golden2 : List Bits8 |
| 57 | +golden2 = [86,67,76,87,1,0,2,0,0,0,0,0,2,0,0,0,105,100,3,0,6,0,0,0,117,117,105,100,45,49,1,2,0,0,1,1,0,0,0,120,1,1,7,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,5,1,0,0,0,116,1,1,10,0,0,0,0,0,0,0,0,1,1,1,0,0,0,119,1,2,1,1,3,0,0,0,0,0,0,0,1,1,1,2,0,0,0,0,1,5,0,0,0,108,101,97,110,52,1,0,0,0,0,0,1,3,1,10] |
| 58 | + |
| 59 | +expected2 : Statement |
| 60 | +expected2 = |
| 61 | + MkStatement |
| 62 | + [SelField (MkFieldRef Graph "id"), SelStar] |
| 63 | + (SrcOctad "uuid-1") |
| 64 | + (Just (ECompare Eq |
| 65 | + (EField (MkFieldRef Vector "x") TAny) |
| 66 | + (ELiteral (LitInt 7) TAny) |
| 67 | + TAny)) |
| 68 | + [] |
| 69 | + Nothing |
| 70 | + [(MkFieldRef Temporal "t", True)] |
| 71 | + (Just 10) |
| 72 | + Nothing |
| 73 | + (Just (ProofWitness "w")) |
| 74 | + (Just EffReadWrite) |
| 75 | + (Just (VerAtLeast 3)) |
| 76 | + (Just LinUseOnce) |
| 77 | + (Just (EpClause |
| 78 | + [AgEngine, AgProver "lean4"] |
| 79 | + [EpReqKnows AgEngine (ELiteral (LitBool True) TAny)])) |
| 80 | + EpistemicSafe |
| 81 | + |
| 82 | +conform2 : fromWire WireConformance.golden2 = Right WireConformance.expected2 |
| 83 | +conform2 = Refl |
| 84 | + |
| 85 | +-- ── F3: float path — WHERE 2.5 (exactly representable), level |
| 86 | +-- ParseSafe. Witnesses the IEEE-754 reconstruction reduces to |
| 87 | +-- the identical primitive `Double` under the evaluator. ───────── |
| 88 | + |
| 89 | +golden3 : List Bits8 |
| 90 | +golden3 = [86,67,76,87,1,0,1,0,0,0,3,2,1,0,0,0,115,1,1,2,0,0,0,0,0,0,4,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] |
| 91 | + |
| 92 | +expected3 : Statement |
| 93 | +expected3 = |
| 94 | + MkStatement [SelStar] (SrcStore "s") |
| 95 | + (Just (ELiteral (LitFloat 2.5) TAny)) |
| 96 | + [] Nothing [] Nothing Nothing |
| 97 | + Nothing Nothing Nothing Nothing Nothing |
| 98 | + ParseSafe |
| 99 | + |
| 100 | +conform3 : fromWire WireConformance.golden3 = Right WireConformance.expected3 |
| 101 | +conform3 = Refl |
0 commit comments