diff --git a/.github/workflows/verify-proofs.yml b/.github/workflows/verify-proofs.yml index 029cf2c4..2a108cb9 100644 --- a/.github/workflows/verify-proofs.yml +++ b/.github/workflows/verify-proofs.yml @@ -191,7 +191,7 @@ jobs: failed=0 for f in *.idr; do echo "── $f ─────────────────────────────────────────────" - if idris2 --check "$f"; then + if idris2 --check --total "$f"; then echo "✓ $f" bash "$GITHUB_WORKSPACE/scripts/proof-ledger.sh" receipt idris2 pass "verification/proofs/idris2/$f" else diff --git a/verification/README.adoc b/verification/README.adoc index fcaec960..9a12fc12 100644 --- a/verification/README.adoc +++ b/verification/README.adoc @@ -18,12 +18,14 @@ Idris2, Lean 4, TLA+ and Agda proof sources for Hypatia's type-level guarantees. == Building Proofs The `proofs/` tree is not an Idris2 package; each file is type-checked -independently, exactly as `.github/workflows/verify-proofs.yml` does it: +independently, exactly as `.github/workflows/verify-proofs.yml` does it. +`--total` makes Idris refuse a partial definition even in a file that has +lost its `%default total`: [source,bash] ---- cd verification/proofs/idris2 -for f in *.idr; do idris2 --check "$f"; done +for f in *.idr; do idris2 --check --total "$f"; done ---- The Agda artefact is checked under the estate strict profile (capital diff --git a/verification/proofs/idris2/ParserTotality.idr b/verification/proofs/idris2/ParserTotality.idr index ae5e59ee..f4522bbe 100644 --- a/verification/proofs/idris2/ParserTotality.idr +++ b/verification/proofs/idris2/ParserTotality.idr @@ -69,10 +69,37 @@ parseFrom _ = Err ExpectedFromClaus -- Section 3: totality as a structural property ------------------------------------------------------------------------ -||| Property 1: parseFrom is a function: equal inputs give equal results. +||| The FROM-clause grammar as a relation, written apart from parseFrom: one +||| constructor per production. `Parses ts s rest` says the grammar reads +||| source s from the front of ts and leaves rest. +public export +data Parses : List Token -> Source -> List Token -> Type where + PStore : Parses (KwFrom :: KwStore :: Ident v :: rest) (Store v) rest + PStoreQuoted : Parses (KwFrom :: KwStore :: Quoted v :: rest) (Store v) rest + PFed : Parses (KwFrom :: KwFederation :: Ident v :: rest) (Federation v) rest + PFedQuoted : Parses (KwFrom :: KwFederation :: Quoted v :: rest) (Federation v) rest + PHexad : Parses (KwFrom :: KwHexad :: Ident v :: rest) (Hexad v) rest + +||| Every parse the grammar allows is the one parseFrom returns. If two +||| productions could read the same tokens differently, parseFrom could +||| return only one of them, and this would not check. +export +parsesComplete : Parses ts s rest -> parseFrom ts = Ok s rest +parsesComplete PStore = Refl +parsesComplete PStoreQuoted = Refl +parsesComplete PFed = Refl +parsesComplete PFedQuoted = Refl +parsesComplete PHexad = Refl + +||| Property 1: the grammar is deterministic. Two parses of the same tokens +||| give the same source and leave the same tokens. Derived from +||| parsesComplete: both parses are the one parseFrom returns. export -parseFromDeterministic : (ts : List Token) -> parseFrom ts = parseFrom ts -parseFromDeterministic _ = Refl +parseFromDeterministic : Parses ts s rest -> Parses ts s' rest' -> (s = s', rest = rest') +parseFromDeterministic p q = okInjective (trans (sym (parsesComplete p)) (parsesComplete q)) + where + okInjective : Ok a r = Ok a' r' -> (a = a', r = r') + okInjective Refl = (Refl, Refl) ||| Property 2: empty input gives the empty-input error. export