From f2694a39127928c28969148c959386c6e43aea3e Mon Sep 17 00:00:00 2001 From: humuhumu33 Date: Thu, 12 Nov 2026 15:14:26 +0000 Subject: [PATCH 1/6] BS-71: the model declarations as source (SemanticModels) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The artifact, contract, realization, evidence and model declarations of the semantic module language (SPEC.md §17.12) with the twenty types they hold, as language-1.2 source in bootstrap/, seventh slice of the typed IR (#269): modelDeclarationText of SemanticModels, held to the canonical JSON of their serde form. The module and the case encoders and examples are generated from one description of the oracle types (scratch schemagen.py / gen71.py); 35 planted defects. Register row (500), SPEC §31 row and §17.23 prose, scenario, bdd part and lane, README count and range, CHANGELOG, VERIFICATION record, roots, the register-count mirrors. Co-Authored-By: Claude Opus 5.5 --- .github/bdd-parts.json | 3 + .github/intel-host-lanes.json | 2 +- .github/vv-rows.json | 9 + CHANGELOG.md | 6 + README.md | 4 +- SPEC.md | 15 +- VERIFICATION.md | 33 + bootstrap/README.md | 3 + bootstrap/lexlean.lock | 2 +- bootstrap/lexlean.toml | 2 +- bootstrap/src/SemanticModels.lex.tex | 591 +++++++ crates/conformance/src/cases/bootstrap.rs | 2 + .../src/cases/bootstrap/semantic_models.rs | 1414 +++++++++++++++++ crates/conformance/src/cases/repository.rs | 2 +- crates/conformance/tests/conformance.rs | 5 + features/suites/bootstrap.feature | 6 + model/ids.toml | 6 + tests/production-export/bootstrap/roots.json | 8 + xtask/src/spec_links.rs | 4 +- 19 files changed, 2108 insertions(+), 9 deletions(-) create mode 100755 bootstrap/src/SemanticModels.lex.tex create mode 100755 crates/conformance/src/cases/bootstrap/semantic_models.rs diff --git a/.github/bdd-parts.json b/.github/bdd-parts.json index 091db20a31..b360492e62 100644 --- a/.github/bdd-parts.json +++ b/.github/bdd-parts.json @@ -295,6 +295,9 @@ ], "bootstrap-semantic-decls": [ "BS-70" + ], + "bootstrap-semantic-models": [ + "BS-71" ] }, "targets": { diff --git a/.github/intel-host-lanes.json b/.github/intel-host-lanes.json index a377206058..fe339fa80b 100644 --- a/.github/intel-host-lanes.json +++ b/.github/intel-host-lanes.json @@ -2,7 +2,7 @@ "producer": ["honesty"], "lanes": { "lower": ["bootstrap-lower", "bootstrap-lexicon-lse", "bootstrap-lexicon-lre", "bootstrap-surface-module", "bootstrap-diagnostics", "bootstrap-cli-output"], - "print": ["bootstrap-print", "bootstrap-bodies", "bootstrap-succeed", "bootstrap-loops", "bootstrap-assemble", "bootstrap-package", "bootstrap-check", "bootstrap-gnaf", "bootstrap-runtime", "bootstrap-terms", "bootstrap-tooling-latex", "bootstrap-structural-grammar", "bootstrap-surface-lex", "bootstrap-surface-doc", "bootstrap-surface-generic", "bootstrap-surface-tooling", "bootstrap-lock-text", "bootstrap-content-id", "bootstrap-project-text", "bootstrap-manifest-text", "bootstrap-ir-term", "bootstrap-ir-proof", "bootstrap-ir-document", "bootstrap-semantic-types", "bootstrap-semantic-terms", "bootstrap-semantic-decls"], + "print": ["bootstrap-print", "bootstrap-bodies", "bootstrap-succeed", "bootstrap-loops", "bootstrap-assemble", "bootstrap-package", "bootstrap-check", "bootstrap-gnaf", "bootstrap-runtime", "bootstrap-terms", "bootstrap-tooling-latex", "bootstrap-structural-grammar", "bootstrap-surface-lex", "bootstrap-surface-doc", "bootstrap-surface-generic", "bootstrap-surface-tooling", "bootstrap-lock-text", "bootstrap-content-id", "bootstrap-project-text", "bootstrap-manifest-text", "bootstrap-ir-term", "bootstrap-ir-proof", "bootstrap-ir-document", "bootstrap-semantic-types", "bootstrap-semantic-terms", "bootstrap-semantic-decls", "bootstrap-semantic-models"], "validate": ["bootstrap-validate", "compiler", "preservation", "preservation-lists", "preservation-runtime", "preservation-support", "preservation-prims", "preservation-std", "production"], "moves": ["bootstrap-moves", "verification", "rest"] } diff --git a/.github/vv-rows.json b/.github/vv-rows.json index 605669197e..7085cc98b2 100644 --- a/.github/vv-rows.json +++ b/.github/vv-rows.json @@ -412,5 +412,14 @@ "width": "", "memory_kib": "", "hints": "" + }, + { + "part": "bdd-bootstrap-semantic-models", + "recipes": "bdd", + "examples_part": "", + "bdd_part": "bootstrap-semantic-models", + "width": "", + "memory_kib": "", + "hints": "" } ] diff --git a/CHANGELOG.md b/CHANGELOG.md index b99a1e553f..79eb13bc26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,12 @@ workspace carried at those versions without a tag. ## Unreleased +- The declarations of artifacts, contracts, realizations, evidence, and models as + language-1.2 source, seventh slice of the typed IR (SPEC.md §17.23, §17.12, `BS-71`, + #269; no new diagnostic code, no change to the language-1.2 identity). + `modelDeclarationText` of `SemanticModels` returns the canonical JSON of the serde + form of those declarations; the module and its case's encoders and examples are + generated from one description of the oracle's types. The register is 500 IDs. - The ordinary declarations of the semantic module language and its modules as language-1.2 source, sixth slice of the typed IR (SPEC.md §17.23, §17.11, §17.12, `BS-70`, #269; no new diagnostic code, no change to the language-1.2 identity). diff --git a/README.md b/README.md index cd21b0d072..d8a6cdee2d 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ just vv # the complete normative acceptance gate (SPEC.md §9.2) just release # vv, then the §30 release criterion; refused until 1.0.0 ``` -All 499 registered conformance IDs have their named tests; `just vv` checks them with the pinned toolchain installed. +All 500 registered conformance IDs have their named tests; `just vv` checks them with the pinned toolchain installed. The differential against the independent generator `lean4-prod` (SPEC.md §17.19, `OR-01`..`OR-08`) acquires it at its pinned commit: from the checkout `LEXLEAN_ORACLE_DIR` names, or by fetching the commit with `git` into the Cargo target directory (`LEXLEAN_ORACLE_CACHE` overrides), and builds it with the pinned Lean and Rust toolchains. It is validation evidence only and no input to any identity. An oracle that cannot be acquired, is not the pinned files, or fails is unavailable: that fails the gate on Linux x86-64 and is printed as `NOT VALIDATED` elsewhere, and is never reported as agreement. @@ -197,7 +197,7 @@ Every row is validated by `just vv`; the IDs link the claim to its register row, | The language-1.2 authoring notation: a readable `.lex.tex` text for a semantic module, in bijection with its canonical JSON, whose every position and variant is read from the schema, with readable forms for types and terms and a generic form for every other value, formatted canonically by `fmt` failing closed, the only form in which a language-1.2 source of the product is written (the data form is refused under language 1.2, and `lexlean::sdk` is the explicit conversion), the same for the compiler-tooling modules in the generic notation, with no compiler-semantics ID that depends on which form an embedded module is written in, with no product source owned by a generator but five named records, read and written by programs only through the authoring API (`lexlean::sdk`), and, for a native core module, a readable program over the shared table of kernel terms whose numbering is the order of its text | `AU-01`..`AU-13` | `build` | | The runtime of generated Lean as native modules: the portable, collection, model, and reasoning runtimes of language 1.2 are LexLean source that every generated module imports, migrated losslessly and audited against their exact axioms, the released runtime text of languages 1.0 and 1.1 is frozen data equal to their released output, and no other Lean runtime text remains in the compiler but the decoder of core module 2 | `RT-01`..`RT-04` | `build` | | The standard library: language-1.2 source beside the compiler whose members are certified production roots, each validated against its oracle by a seeded differential of its evaluator and rustc realizations; bytes and text over `Bytes`, an output buffer of a given capacity written in order; decimal and hexadecimal; the byte order and stable sorts over it; canonical JSON reading and writing; maps and sets over byte keys; SHA-256 against FIPS 180-4, the NIST CAVP vectors, and the `sha2` crate; and the `std-models` and `std-reasoning` source packages, generic over types, whose laws are kernel-checked theorems and whose application is the `helpdesk` example | `SL-01`, `SL-02`, `SL-03`, `SL-04`, `SL-05`, `SL-09`, `SL-10`, `SL-11`, `SL-13`, `SL-14` | `build` | -| The bootstrap project: the compiler's own components as language-1.2 source compiled by LexLean's production pipeline to certified Rust packages, the exact axiom-output parser and its closed Lean-name check, the primitive scanner of §12.2, the preservation lexer and token audit, the target calculus's checker, the Rust crate validator, the Rust printer, the runtime syntax validator, the failure typing and the types of the Rust lowering, its last-use moves, its literal values and its terms, the package renderer, the GNAF request validation, the LaTeX of a tooling module, the structural grammar, the lexer of the authoring notation, its layout algebra, its generic notation, the notation of a tooling module, the reader and printer of LexLean Semantic Expressions, the reader of LexLean Rendering Expressions, where the module of a source is, the canonical diagnostic and its terminal output, the canonical text of the lock file and of the project manifest, the hash recipes of content identity, the build manifest, the linked term IR in its canonical JSON, the proof and declaration IR in theirs with the axiom policy check, the document IR, the linked project, and the semantic ID, the closed types of the semantic module language, its terms and proofs, and its ordinary declarations and modules, each held to the Rust it replaces (the stage-0 oracle) by the committed vectors and a seeded differential of its evaluator and rustc realizations, with planted defects detected and the production export committed | `BS-01`..`BS-70` | `build` | +| The bootstrap project: the compiler's own components as language-1.2 source compiled by LexLean's production pipeline to certified Rust packages, the exact axiom-output parser and its closed Lean-name check, the primitive scanner of §12.2, the preservation lexer and token audit, the target calculus's checker, the Rust crate validator, the Rust printer, the runtime syntax validator, the failure typing and the types of the Rust lowering, its last-use moves, its literal values and its terms, the package renderer, the GNAF request validation, the LaTeX of a tooling module, the structural grammar, the lexer of the authoring notation, its layout algebra, its generic notation, the notation of a tooling module, the reader and printer of LexLean Semantic Expressions, the reader of LexLean Rendering Expressions, where the module of a source is, the canonical diagnostic and its terminal output, the canonical text of the lock file and of the project manifest, the hash recipes of content identity, the build manifest, the linked term IR in its canonical JSON, the proof and declaration IR in theirs with the axiom policy check, the document IR, the linked project, and the semantic ID, the closed types of the semantic module language, its terms and proofs, its ordinary declarations and modules, and its model declarations, each held to the Rust it replaces (the stage-0 oracle) by the committed vectors and a seeded differential of its evaluator and rustc realizations, with planted defects detected and the production export committed | `BS-01`..`BS-71` | `build` | | Source packages: a language-1.2 project imports the modules of a locked, content-addressed package of its workspace: `[[source_package]]` and `lexlean-workspace.toml`, the pins in `lexlean.lock` recomputed by every command, imports closed at link, no re-export of a package's production roots, and the package's modules replayed by the importer's `verify` with their origin in the records | `PK-01`..`PK-05` | `build` | | The literal `nat-add-zero` example, the Lean-verified feature examples, and the complete negative fixture suite | `EX-01`..`EX-09` | `build` | | Language-1.2 text components: tokenizers and their round-trip laws, with the laws carried as one native core module the generated modules import rather than authored Lean text | `LM-01`, `LM-02`, `LM-03`, `LM-13` | `build` | diff --git a/SPEC.md b/SPEC.md index 1b889d4085..be04d6f389 100644 --- a/SPEC.md +++ b/SPEC.md @@ -9113,6 +9113,18 @@ Every module of the `bootstrap/` project and of the standard library declares on so `moduleText` writes the semantic modules of LexLean's own sources. Both roots admit `recursion`. The declarations of models, reasoning, and text components, and reading declarations from JSON, stay in the host. +The declarations of artifacts, contracts, realizations, evidence, and models (§17.12) are the +seventh component of the typed IR as source (`BS-71`, issue 269), the module `SemanticModels` +over `SemanticTerms` and `SemanticTypes`, with one production root for `rust-std`: + +| Root | Takes | Returns | Oracle | +| --- | --- | --- | --- | +| `LexLeanBoot.SemanticModels.modelDeclarationText` | an artifact, contract, realization, evidence, or model declaration | its canonical JSON as the linked IR embeds it | the serde form of those variants of `ir::semantic::SemanticDeclaration` | + +None of the twenty types these declarations hold refers to itself, so each is one inductive and +one writer, and a list of them is a list. The module, the case's encoders, and the case's +examples are generated from one description of the oracle's types. The root admits +`recursion` through the term and JSON writers. Reading declarations from JSON stays in the host. The authoring notation of a tooling module (§17.20, §17.21) is the fifth component of the front end (`BS-27`, issue 269), the module `SurfaceTooling` over the generic notation of @@ -12167,6 +12179,7 @@ Every row below is normative, has honesty level `build`, and MUST be copied byte | `BS-68` | `bootstrap` | The closed types of the semantic module language of SPEC.md §17.11 and §17.12, its primitives, and its integer families (`ir::semantic::SemanticType` in the serde form the linked IR embeds, written as canonical JSON: each type tagged by its `kind`, a named type's module only when it has one, and the fixed-width names `int8` to `uint64`; its `Display`, the spelling diagnostics use; and of `SemanticPrimitive` and `SemanticInteger`, the serialized name, whether a primitive is language 1.2's, whether linking widens it away, and the position of its function argument) is language-1.2 source in the `bootstrap/` project, as four production roots of `SemanticTypes`: `primitiveFacts` and `integerName`, each eligible for `rust-std` with exactly `allocation`, `typeText`, with exactly `allocation`, `overflow`, and `recursion`, and `typeSpelling`, with exactly `allocation` and `recursion`, each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator, agree with the oracle to the byte on hand-built types, which reach every constructor and every unit type, on every primitive and every integer family the module names, each read back through the oracle's serialized name, on every distinct type of every committed semantic module that links, and on seeded types; each planted defect in the source is detected by the root and the one vector it names, and the certified packages the production export publishes for the project are the committed ones; reading types from JSON is outside the claim. | §17.11, §17.12, §17.23 | | `BS-69` | `bootstrap` | The closed terms and proofs of the semantic module language of SPEC.md §17.11 and §17.12 (`ir::semantic::SemanticTerm` and `SemanticProof` in the serde form the linked IR embeds, written as canonical JSON: each term and proof tagged by its `kind`, its member references, assignments, branches, binders, map entries, graph edges, model checks, and reflections in their fields, a list of type arguments, definitions, generalized names, or premises left out when it is empty where the oracle skips it, and its types through `SemanticTypes`) is language-1.2 source in the `bootstrap/` project, as two production roots of `SemanticTerms`: `termText` and `proofText`, each eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator, agree with the oracle to the byte on hand-built terms and proofs, which reach every constructor and every optional list both empty and not, on every distinct term and proof of every committed semantic module that links, and on seeded terms and proofs; each planted defect in the source is detected by the root and the one vector it names, and the certified packages the production export publishes for the project are the committed ones; reading terms and proofs from JSON is outside the claim. | §17.11, §17.12, §17.23 | | `BS-70` | `bootstrap` | The ordinary declarations of the semantic module language of SPEC.md §17.11 and §17.12 and the module that holds them (`ir::semantic::SemanticDeclaration` for structures, classes, instances, inductives, definitions, and theorems, and `SemanticModule`, in the serde form the linked IR embeds, written as canonical JSON: each declaration tagged by its `kind`, its parameters, fields, constructors, and assignments in order, and a definition's or a theorem's type parameters, recursive argument, axioms, executable flag, mutual group, termination, and production, and an inductive's mutual group, left out exactly where the oracle's serde attributes skip them; and a module's specification and declarations in order) is language-1.2 source in the `bootstrap/` project, as two production roots of `SemanticDecls` over `SemanticTerms` and `SemanticTypes`: `declarationText` and `moduleText`, each eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator on the shorter modules, agree with the oracle to the byte on hand-built declarations, which reach every kind and every optional member both present and absent, on every distinct ordinary declaration of every committed semantic module that links and on every such module whose declarations are all ordinary, among them every module of the `bootstrap/` project and the standard library, and on seeded declarations; each planted defect in the source is detected by the root and the one vector it names, and the certified packages the production export publishes for the project are the committed ones; the declarations of models, reasoning, and text components, and reading declarations from JSON, are outside the claim. | §17.11, §17.12, §17.23 | +| `BS-71` | `bootstrap` | The declarations of artifacts, contracts, realizations, evidence, and models of the semantic module language of SPEC.md §17.12 (those variants of `ir::semantic::SemanticDeclaration`, with the artifact roles and schemas, binders, states, validators, uses, rules, the deterministic, rule, statistical, neural, and composite realization descriptors with their layers, decoders, forms, and junctions, and the evidence claims they hold, in the serde form the linked IR embeds, written as canonical JSON: each tagged variant by its `kind`, each closed name as the oracle serializes it, and each optional member left out exactly where the oracle's serde attributes skip it) is language-1.2 source in the `bootstrap/` project, as the production root `modelDeclarationText` of `SemanticModels` over `SemanticTerms` and `SemanticTypes`, generated with the case's encoders and examples from one description of the oracle's types, eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and with no part of its certificate beyond 3,145,728 bytes; its rendered `rust-std` package under the pinned rustc, and on the normative host its lowered program under the calculus evaluator, agree with the oracle to the byte on examples that reach every variant, every optional member present and absent, and every list empty and not, on every distinct such declaration of every committed semantic module that links, and on seeded examples; each planted defect, a misspelled kind or name, is detected by the first example that holds it, and the certified packages the production export publishes for the project are the committed ones; reading declarations from JSON is outside the claim. | §17.12, §17.23 | | `PK-01` | `packages` | A language-1.2 project that declares a source package by its identifier, version, kind `path`, and the member directory a `lexlean-workspace.toml` lists locks it by the tree digest of its manifest and source files, its manifest digest, its version, its module prefix, and its own packages, and the configuration and the lock read back to the bytes written; a project without a source package keeps its bytes, and a package of another kind, a source package in another language, a changed byte or version (LLC0105), an undeclared package (LLC0106), a module prefix claimed twice (LLC0107), a project or a package outside the workspace (LLC0108), a path that escapes it, and a symlink (LLS8001) are each refused with the named code. | §10.5, §11.1, §25.1 | | `PK-02` | `packages` | A module of a project imports only modules of its own project and modules of the packages the project declares, and a module of a package only modules of itself and of the packages its own manifest declares: a package module is a module of the importing project under its own module prefix, a module of a package the project does not declare fails with LLR3009, and an import cycle through a package fails with LLR3003. | §10.5, §15.1 | | `PK-03` | `packages` | An importing project builds and verifies under the pinned Lean offline, and its package modules are generated, elaborated, replayed with `leanchecker`, and audited for their exact axioms under the package's module prefix with the package as their origin in the records; the source ID of the project changes with the pins, and no file of the package is written by `fmt`, `build`, or `verify`. | §10.5, §21.3, §22 | @@ -12183,7 +12196,7 @@ Every row below is normative, has honesty level `build`, and MUST be copied byte | `LM-09` | `language-models` | No prompt is code: no member of the closed language maps `string` or `bytes` to a function, a term, or source — every operation of the primitive registry that takes a `string` or `bytes` operand is classified by the audit with a data result, the registry's schema enumeration and the production registry's primitive rows equal one another and equal that classified set, and the text declarations of `lexlean/semantic-module/2` state no `string`-typed member, so a prompt reaches a model only as the tokens `encodeText` makes of it; a planted operation or text member of that shape is caught by the audit with its name. | §17.12 | | `LM-13` | `language-models` | The text laws a tokenizer elaborates through are LexLean source and not authored text: the module that states them is one language-1.2 native core module of the embedded `language/text-1.2` project, the project holds no file of Lean source, no independently authored Lean file anywhere in the release tree declares the `LexLeanText` namespace or lies under its module root, and the one-time migration input is absent; the registry lists only that module, the declarations and their exact axiom policies are read from its native data, which the compiler embeds and hashes into the language-1.2 semantics, and a module that declares a text component imports the generated module rather than splicing any Lean text. | §17.10, §17.12 | -**Total required capability IDs:** 499. +**Total required capability IDs:** 500. No row may be downgraded to `some-true` or `open`. Upstream Lean facts are ledger/authority rows, not substitutions for these build behaviors. diff --git a/VERIFICATION.md b/VERIFICATION.md index 4bfc998e8c..48bd61c29b 100644 --- a/VERIFICATION.md +++ b/VERIFICATION.md @@ -11916,6 +11916,39 @@ check` and `lexlean build` of the `bootstrap/` project pass, with each of the tw roots eligible for `rust-std` with exactly its declared effects, and `lexlean fmt --check` passes. +### the model declarations are source (BS-71) + +`BS-71` holds the production root `modelDeclarationText` of +`LexLeanBoot.SemanticModels` (`bootstrap/src/SemanticModels.lex.tex`) to the +canonical JSON of the serde form of the artifact, contract, realization, +evidence, and model variants of `lexlean::ir::semantic::SemanticDeclaration`, as +`DocumentModule::to_json` embeds a semantic module. The module declares the +twenty types those declarations hold (artifact roles and schemas, tensor +elements, binders, states, predicates, validators, uses, rules, the statistical +scheme and neural architecture, layers, decoders, junctions, composite forms, +realization descriptors, and evidence claims) and the declarations themselves, +each as one inductive with one writer, over the terms of `SemanticTerms` +(`BS-69`) and the types of `SemanticTypes` (`BS-68`). No such type refers to +itself, so a list of them is a list. An object is written from its entries, an +optional member entering exactly where the oracle's serde attributes keep it. +The module, the case's encoders, and the case's example builders are generated +from one description of the oracle's types, so that a type the description and +the oracle disagree on fails to encode or to compare. The root admits exactly +`allocation`, `overflow`, and `recursion`. The oracle is the existing public code +of `semantic.rs` and its serde derivations; no Rust outside the case changes. + +The case holds the root to the oracle on 150 examples whose step's digits choose +every variant at every depth, each optional member present and absent and each +list empty and not; on every distinct such declaration of every committed +semantic module that links; and on seeded examples. Each planted defect +misspells one serialized kind or closed name, and the first example that holds +it detects it; the case asserts that the site of each plant occurs once. The +row's statement carries no counts. + +Measured with the compiler binary of this tree's compiler sources: `lexlean +check` of the `bootstrap/` project passes, with the root eligible for `rust-std` +with exactly its declared effects, and `lexlean fmt --check` passes. + ## The `bdd` recipe as the parts of one run (Issue #131) With UOR Atlas verified as the parts of one run, the `rest` leg became the diff --git a/bootstrap/README.md b/bootstrap/README.md index 590e2c8728..43072559df 100644 --- a/bootstrap/README.md +++ b/bootstrap/README.md @@ -73,3 +73,6 @@ the linked IR embeds them. `src/SemanticDecls.lex.tex` (SPEC.md §17.23, `BS-70`) imports `SemanticTerms` (`BS-69`), `SemanticTypes` (`BS-68`), and the standard library's `Json` and `Order`, and writes the ordinary declarations of the semantic module language and its modules as the linked IR embeds them. +`src/SemanticModels.lex.tex` (SPEC.md §17.23, `BS-71`) imports `SemanticTerms`, `SemanticTypes`, and the +standard library's `Json` and `Order`, and writes the declarations of artifacts, contracts, +realizations, evidence, and models as the linked IR embeds them. diff --git a/bootstrap/lexlean.lock b/bootstrap/lexlean.lock index 7879dd8e2d..5acde89bb2 100644 --- a/bootstrap/lexlean.lock +++ b/bootstrap/lexlean.lock @@ -1,7 +1,7 @@ spec = "lexlean/lock/2" language = "1.2" compiler_semantics = "635a25acb886587f8777525e778092e9599d1f2df26da59403ee39e9e299151a" -project_config_sha256 = "b48ffa32d3a34197ff1ad80ee19edbf6ee5bdecaebbb47c9f8231d13d7dfc675" +project_config_sha256 = "df6d82ce9eab8856a204ffcc661add576602655ec005140c2e9f9fab0045ad01" lean_toolchain = "leanprover/lean4:v4.32.1" [[workspace_file]] diff --git a/bootstrap/lexlean.toml b/bootstrap/lexlean.toml index b033d495c8..792918d13a 100644 --- a/bootstrap/lexlean.toml +++ b/bootstrap/lexlean.toml @@ -3,7 +3,7 @@ name = "bootstrap" language = "1.2" module_prefix = "LexLeanBoot" source_roots = ["src"] -entrypoints = ["src/AxiomOutput.lex.tex", "src/CalculusCheck.lex.tex", "src/CliOutput.lex.tex", "src/ContentId.lex.tex", "src/Diagnostics.lex.tex", "src/GnafValidate.lex.tex", "src/IrDocument.lex.tex", "src/IrProof.lex.tex", "src/IrTerm.lex.tex", "src/LexiconLre.lex.tex", "src/LexiconLse.lex.tex", "src/LockText.lex.tex", "src/ManifestText.lex.tex", "src/PrimitiveScan.lex.tex", "src/ProjectText.lex.tex", "src/RuntimeValidate.lex.tex", "src/RustAssemble.lex.tex", "src/RustAst.lex.tex", "src/RustBodies.lex.tex", "src/RustLoops.lex.tex", "src/RustLower.lex.tex", "src/RustMoves.lex.tex", "src/RustPackage.lex.tex", "src/RustPrint.lex.tex", "src/RustSucceed.lex.tex", "src/RustTerms.lex.tex", "src/RustValidate.lex.tex", "src/SemanticDecls.lex.tex", "src/SemanticTerms.lex.tex", "src/SemanticTypes.lex.tex", "src/StructuralGrammar.lex.tex", "src/SurfaceDoc.lex.tex", "src/SurfaceGeneric.lex.tex", "src/SurfaceLex.lex.tex", "src/SurfaceModule.lex.tex", "src/SurfaceTooling.lex.tex", "src/TokenAudit.lex.tex", "src/ToolingAst.lex.tex", "src/ToolingLatex.lex.tex"] +entrypoints = ["src/AxiomOutput.lex.tex", "src/CalculusCheck.lex.tex", "src/CliOutput.lex.tex", "src/ContentId.lex.tex", "src/Diagnostics.lex.tex", "src/GnafValidate.lex.tex", "src/IrDocument.lex.tex", "src/IrProof.lex.tex", "src/IrTerm.lex.tex", "src/LexiconLre.lex.tex", "src/LexiconLse.lex.tex", "src/LockText.lex.tex", "src/ManifestText.lex.tex", "src/PrimitiveScan.lex.tex", "src/ProjectText.lex.tex", "src/RuntimeValidate.lex.tex", "src/RustAssemble.lex.tex", "src/RustAst.lex.tex", "src/RustBodies.lex.tex", "src/RustLoops.lex.tex", "src/RustLower.lex.tex", "src/RustMoves.lex.tex", "src/RustPackage.lex.tex", "src/RustPrint.lex.tex", "src/RustSucceed.lex.tex", "src/RustTerms.lex.tex", "src/RustValidate.lex.tex", "src/SemanticDecls.lex.tex", "src/SemanticModels.lex.tex", "src/SemanticTerms.lex.tex", "src/SemanticTypes.lex.tex", "src/StructuralGrammar.lex.tex", "src/SurfaceDoc.lex.tex", "src/SurfaceGeneric.lex.tex", "src/SurfaceLex.lex.tex", "src/SurfaceModule.lex.tex", "src/SurfaceTooling.lex.tex", "src/TokenAudit.lex.tex", "src/ToolingAst.lex.tex", "src/ToolingLatex.lex.tex"] build_root = ".lexlean" lockfile = "lexlean.lock" lean_workspace = "." diff --git a/bootstrap/src/SemanticModels.lex.tex b/bootstrap/src/SemanticModels.lex.tex new file mode 100755 index 0000000000..302938eb9d --- /dev/null +++ b/bootstrap/src/SemanticModels.lex.tex @@ -0,0 +1,591 @@ +\begin{lexlean}{SemanticModels} +\useglossary{lexlean.std.nat@1.2.0} +\importmodule{SemanticTerms} +\importmodule{SemanticTypes} +\importmodule{LexLeanStd.Json} +\importmodule{LexLeanStd.Order} +\title{Natural number addition} +\begin{semanticmodule} +inductive{ + name: ArtifactRole, + type_parameters: [], + parameters: [], + constructors: [ + {name: ArtifactRoleParameters, fields: []}, + {name: ArtifactRoleVocabulary, fields: []}, + {name: ArtifactRoleDataset, fields: []}, + {name: ArtifactRoleTable, fields: []}, + {name: ArtifactRoleBinary, fields: []} + ] +} + +inductive{ + name: TensorElement, + type_parameters: [], + parameters: [], + constructors: [ + {name: TensorElementInt8, fields: []}, + {name: TensorElementInt16, fields: []}, + {name: TensorElementInt32, fields: []}, + {name: TensorElementInt64, fields: []}, + {name: TensorElementUInt8, fields: []}, + {name: TensorElementUInt16, fields: []}, + {name: TensorElementUInt32, fields: []}, + {name: TensorElementUInt64, fields: []} + ] +} + +inductive{ + name: ArtifactSchema, + type_parameters: [], + parameters: [], + constructors: [ + {name: ArtifactSchemaBytes, fields: []}, + {name: ArtifactSchemaIntTensor, fields: [TensorElement, (List Nat)]}, + {name: ArtifactSchemaUtf8Lines, fields: []} + ] +} + +inductive{ + name: ModelBinder, + type_parameters: [], + parameters: [], + constructors: [{name: ModelBinderOf, fields: [Bytes, SemanticTypes::SemanticType]}] +} + +inductive{ + name: ContractState, + type_parameters: [], + parameters: [], + constructors: [{name: ContractStateOf, fields: [Bytes, Bytes, SemanticTypes::SemanticType]}] +} + +inductive{ + name: ContractPredicate, + type_parameters: [], + parameters: [], + constructors: [ + {name: ContractPredicateInvariant, fields: []}, + {name: ContractPredicatePostcondition, fields: []}, + {name: ContractPredicatePrecondition, fields: []} + ] +} + +inductive{ + name: ContractValidator, + type_parameters: [], + parameters: [], + constructors: [ + { + name: ContractValidatorOf, + fields: [ + ContractPredicate, + ((Option Bytes) * Bytes), + ((Option Bytes) * Bytes), + (Option ((Option Bytes) * Bytes)) + ] + } + ] +} + +inductive{ + name: ModelUse, + type_parameters: [], + parameters: [], + constructors: [ + {name: ModelUseOf, fields: [((Option Bytes) * Bytes), (List SemanticTypes::SemanticType)]} + ] +} + +inductive{ + name: RealizationState, + type_parameters: [], + parameters: [], + constructors: [ + {name: RealizationStateOf, fields: [Bytes, SemanticTypes::SemanticType, SemanticTerms::STerm]} + ] +} + +inductive{ + name: RealizationRule, + type_parameters: [], + parameters: [], + constructors: [ + {name: RealizationRuleOf, fields: [Bytes, SemanticTerms::STerm, SemanticTerms::STerm]} + ] +} + +inductive{ + name: StatisticalScheme, + type_parameters: [], + parameters: [], + constructors: [{name: StatisticalSchemeLinearScoring, fields: []}] +} + +inductive{ + name: NeuralArchitecture, + type_parameters: [], + parameters: [], + constructors: [{name: NeuralArchitectureIntegerFeedforward, fields: []}] +} + +inductive{ + name: NeuralLayer, + type_parameters: [], + parameters: [], + constructors: [ + { + name: NeuralLayerDense, + fields: [Nat, Nat, ((Option Bytes) * Bytes), ((Option Bytes) * Bytes)] + }, + {name: NeuralLayerRelu, fields: []}, + {name: NeuralLayerRequantize, fields: [Nat, Bytes, Bytes]} + ] +} + +inductive{ + name: NeuralDecoder, + type_parameters: [], + parameters: [], + constructors: [ + {name: NeuralDecoderArgmax, fields: [(List SemanticTerms::STerm)]}, + {name: NeuralDecoderFunction, fields: [Bytes, SemanticTerms::STerm]} + ] +} + +inductive{ + name: CompositeJunction, + type_parameters: [], + parameters: [], + constructors: [ + {name: CompositeJunctionUnconditional, fields: []}, + {name: CompositeJunctionProved, fields: [((Option Bytes) * Bytes)]}, + {name: CompositeJunctionChecked, fields: []} + ] +} + +inductive{ + name: CompositeForm, + type_parameters: [], + parameters: [], + constructors: [ + {name: CompositeFormSequence, fields: [(List ModelUse), (List CompositeJunction)]}, + {name: CompositeFormFanout, fields: [ModelUse, ModelUse]}, + {name: CompositeFormProduct, fields: [ModelUse, ModelUse]}, + {name: CompositeFormBranch, fields: [SemanticTerms::STerm, ModelUse, ModelUse]}, + {name: CompositeFormScan, fields: [ModelUse, CompositeJunction]} + ] +} + +inductive{ + name: RealizationDescriptor, + type_parameters: [], + parameters: [], + constructors: [ + {name: RealizationDescriptorDeterministic, fields: [SemanticTerms::STerm]}, + {name: RealizationDescriptorRule, fields: [(List RealizationRule), SemanticTerms::STerm]}, + { + name: RealizationDescriptorStatistical, + fields: [ + StatisticalScheme, + SemanticTerms::STerm, + Nat, + ((Option Bytes) * Bytes), + ((Option Bytes) * Bytes), + ((Option Bytes) * Bytes), + (List SemanticTerms::STerm) + ] + }, + { + name: RealizationDescriptorNeural, + fields: [ + NeuralArchitecture, + SemanticTerms::STerm, + Nat, + ((Option Bytes) * Bytes), + (List NeuralLayer), + NeuralDecoder + ] + }, + {name: RealizationDescriptorComposite, fields: [CompositeForm]} + ] +} + +inductive{ + name: EvidenceClaim, + type_parameters: [], + parameters: [], + constructors: [ + { + name: EvidenceClaimDatasetAgreement, + fields: [ + ((Option Bytes) * Bytes), + ((Option Bytes) * Bytes), + ((Option Bytes) * Bytes), + Nat, + Nat, + ((Option Bytes) * Bytes) + ] + }, + {name: EvidenceClaimEquivalentTo, fields: [ModelUse, ((Option Bytes) * Bytes)]}, + {name: EvidenceClaimInitialInvariant, fields: [((Option Bytes) * Bytes)]}, + {name: EvidenceClaimPreservesInvariant, fields: [((Option Bytes) * Bytes)]}, + {name: EvidenceClaimSatisfiesContract, fields: [((Option Bytes) * Bytes)]} + ] +} + +inductive{ + name: ModelDeclaration, + type_parameters: [], + parameters: [], + constructors: [ + { + name: ModelDeclarationArtifact, + fields: [ + Bytes, + ArtifactRole, + Bytes, + Nat, + ArtifactSchema, + SemanticTypes::SemanticType, + (List Bytes) + ] + }, + { + name: ModelDeclarationContract, + fields: [ + Bytes, + (List Bytes), + ModelBinder, + ModelBinder, + (Option ContractState), + (Option ((Option Bytes) * Bytes)), + (Option ((Option Bytes) * Bytes)), + (Option ((Option Bytes) * Bytes)), + (List ContractValidator), + (List Bytes) + ] + }, + { + name: ModelDeclarationRealization, + fields: [ + Bytes, + (List Bytes), + ModelBinder, + SemanticTypes::SemanticType, + (Option RealizationState), + RealizationDescriptor, + Bool, + (List Bytes) + ] + }, + { + name: ModelDeclarationEvidence, + fields: [Bytes, (List Bytes), ModelUse, ModelUse, (List EvidenceClaim), (List Bytes)] + }, + { + name: ModelDeclarationModel, + fields: [ + Bytes, + (List Bytes), + ModelUse, + ModelUse, + (List ModelUse), + (List ((Option Bytes) * Bytes)), + (List Bytes) + ] + } + ] +} + +definition{ + name: lit, + parameters: [literal : String], + result: Bytes, + body: (prim utf8_encode literal : Bytes), + executable: true +} + +definition{ + name: objectOf, + parameters: [entries : (List (Bytes * LexLeanStd.Json::Json))], + result: LexLeanStd.Json::Json, + body: (ctor LexLeanStd.Json::Json.JObj (prim list_fold (fun (rest : LexLeanStd.Json::Json) (entry : (Bytes * LexLeanStd.Json::Json)) => (ctor LexLeanStd.Json::Json.JMember (first entry) (second entry) rest)) (ctor LexLeanStd.Json::Json.JNil) entries : LexLeanStd.Json::Json)), + executable: true +} + +definition{ + name: artifactRoleJson, + parameters: [value : ArtifactRole], + result: LexLeanStd.Json::Json, + body: (match value + | ArtifactRole.ArtifactRoleParameters => (ctor LexLeanStd.Json::Json.JStr (lit "parameters")) + | ArtifactRole.ArtifactRoleVocabulary => (ctor LexLeanStd.Json::Json.JStr (lit "vocabulary")) + | ArtifactRole.ArtifactRoleDataset => (ctor LexLeanStd.Json::Json.JStr (lit "dataset")) + | ArtifactRole.ArtifactRoleTable => (ctor LexLeanStd.Json::Json.JStr (lit "table")) + | ArtifactRole.ArtifactRoleBinary => (ctor LexLeanStd.Json::Json.JStr (lit "binary"))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: tensorElementJson, + parameters: [value : TensorElement], + result: LexLeanStd.Json::Json, + body: (match value + | TensorElement.TensorElementInt8 => (ctor LexLeanStd.Json::Json.JStr (lit "int8")) + | TensorElement.TensorElementInt16 => (ctor LexLeanStd.Json::Json.JStr (lit "int16")) + | TensorElement.TensorElementInt32 => (ctor LexLeanStd.Json::Json.JStr (lit "int32")) + | TensorElement.TensorElementInt64 => (ctor LexLeanStd.Json::Json.JStr (lit "int64")) + | TensorElement.TensorElementUInt8 => (ctor LexLeanStd.Json::Json.JStr (lit "uint8")) + | TensorElement.TensorElementUInt16 => (ctor LexLeanStd.Json::Json.JStr (lit "uint16")) + | TensorElement.TensorElementUInt32 => (ctor LexLeanStd.Json::Json.JStr (lit "uint32")) + | TensorElement.TensorElementUInt64 => (ctor LexLeanStd.Json::Json.JStr (lit "uint64"))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: artifactSchemaJson, + parameters: [value : ArtifactSchema], + result: LexLeanStd.Json::Json, + body: (match value + | ArtifactSchema.ArtifactSchemaBytes => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "bytes"))) (nil (Bytes * LexLeanStd.Json::Json))); (objectOf entries1)) + | ArtifactSchema.ArtifactSchemaIntTensor part0 part1 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "int_tensor"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "element"), (tensorElementJson part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "shape"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : Nat) => (cons (ctor LexLeanStd.Json::Json.JInt false item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [Nat] part1) : (List LexLeanStd.Json::Json))))) entries2); (objectOf entries3)))) + | ArtifactSchema.ArtifactSchemaUtf8Lines => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "utf8_lines"))) (nil (Bytes * LexLeanStd.Json::Json))); (objectOf entries1))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: modelBinderJson, + parameters: [value : ModelBinder], + result: LexLeanStd.Json::Json, + body: (match value + | ModelBinder.ModelBinderOf part0 part1 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "name"), (ctor LexLeanStd.Json::Json.JStr part0)) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "type"), (SemanticTypes::typeJson part1)) entries1); (objectOf entries2)))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: contractStateJson, + parameters: [value : ContractState], + result: LexLeanStd.Json::Json, + body: (match value + | ContractState.ContractStateOf part0 part1 part2 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "name"), (ctor LexLeanStd.Json::Json.JStr part0)) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "next"), (ctor LexLeanStd.Json::Json.JStr part1)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "type"), (SemanticTypes::typeJson part2)) entries2); (objectOf entries3))))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: contractPredicateJson, + parameters: [value : ContractPredicate], + result: LexLeanStd.Json::Json, + body: (match value + | ContractPredicate.ContractPredicateInvariant => (ctor LexLeanStd.Json::Json.JStr (lit "invariant")) + | ContractPredicate.ContractPredicatePostcondition => (ctor LexLeanStd.Json::Json.JStr (lit "postcondition")) + | ContractPredicate.ContractPredicatePrecondition => (ctor LexLeanStd.Json::Json.JStr (lit "precondition"))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: contractValidatorJson, + parameters: [value : ContractValidator], + result: LexLeanStd.Json::Json, + body: (match value + | ContractValidator.ContractValidatorOf part0 part1 part2 part3 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "predicate"), (contractPredicateJson part0)) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "validator"), (SemanticTerms::memberJson (first part1) (second part1))) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "sound"), (SemanticTerms::memberJson (first part2) (second part2))) entries2); (let entries4 : (List (Bytes * LexLeanStd.Json::Json)) := (match part3 + | Option.some present => (cons ((lit "complete"), (SemanticTerms::memberJson (first present) (second present))) entries3) + | Option.none => entries3); (objectOf entries4)))))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: modelUseJson, + parameters: [value : ModelUse], + result: LexLeanStd.Json::Json, + body: (match value + | ModelUse.ModelUseOf part0 part1 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "member"), (SemanticTerms::memberJson (first part0) (second part0))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (match part1 + | List.nil => entries1 + | List.cons head tail => (cons ((lit "type_arguments"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : SemanticTypes::SemanticType) => (cons (SemanticTypes::typeJson item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [SemanticTypes::SemanticType] part1) : (List LexLeanStd.Json::Json))))) entries1)); (objectOf entries2)))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: realizationStateJson, + parameters: [value : RealizationState], + result: LexLeanStd.Json::Json, + body: (match value + | RealizationState.RealizationStateOf part0 part1 part2 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "name"), (ctor LexLeanStd.Json::Json.JStr part0)) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "type"), (SemanticTypes::typeJson part1)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "initial"), (SemanticTerms::termJson part2)) entries2); (objectOf entries3))))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: realizationRuleJson, + parameters: [value : RealizationRule], + result: LexLeanStd.Json::Json, + body: (match value + | RealizationRule.RealizationRuleOf part0 part1 part2 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "name"), (ctor LexLeanStd.Json::Json.JStr part0)) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "guard"), (SemanticTerms::termJson part1)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "action"), (SemanticTerms::termJson part2)) entries2); (objectOf entries3))))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: statisticalSchemeJson, + parameters: [value : StatisticalScheme], + result: LexLeanStd.Json::Json, + body: (match value + | StatisticalScheme.StatisticalSchemeLinearScoring => (ctor LexLeanStd.Json::Json.JStr (lit "linear_scoring"))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: neuralArchitectureJson, + parameters: [value : NeuralArchitecture], + result: LexLeanStd.Json::Json, + body: (match value + | NeuralArchitecture.NeuralArchitectureIntegerFeedforward => (ctor LexLeanStd.Json::Json.JStr (lit "integer_feedforward"))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: neuralLayerJson, + parameters: [value : NeuralLayer], + result: LexLeanStd.Json::Json, + body: (match value + | NeuralLayer.NeuralLayerDense part0 part1 part2 part3 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "dense"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "inputs"), (ctor LexLeanStd.Json::Json.JInt false part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "outputs"), (ctor LexLeanStd.Json::Json.JInt false part1)) entries2); (let entries4 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "weights"), (SemanticTerms::memberJson (first part2) (second part2))) entries3); (let entries5 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "bias"), (SemanticTerms::memberJson (first part3) (second part3))) entries4); (objectOf entries5)))))) + | NeuralLayer.NeuralLayerRelu => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "relu"))) (nil (Bytes * LexLeanStd.Json::Json))); (objectOf entries1)) + | NeuralLayer.NeuralLayerRequantize part0 part1 part2 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "requantize"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "shift"), (ctor LexLeanStd.Json::Json.JInt false part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "minimum"), (ctor LexLeanStd.Json::Json.JStr part1)) entries2); (let entries4 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "maximum"), (ctor LexLeanStd.Json::Json.JStr part2)) entries3); (objectOf entries4)))))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: neuralDecoderJson, + parameters: [value : NeuralDecoder], + result: LexLeanStd.Json::Json, + body: (match value + | NeuralDecoder.NeuralDecoderArgmax part0 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "argmax"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "labels"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : SemanticTerms::STerm) => (cons (SemanticTerms::termJson item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [SemanticTerms::STerm] part0) : (List LexLeanStd.Json::Json))))) entries1); (objectOf entries2))) + | NeuralDecoder.NeuralDecoderFunction part0 part1 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "function"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "binder"), (ctor LexLeanStd.Json::Json.JStr part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "body"), (SemanticTerms::termJson part1)) entries2); (objectOf entries3))))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: compositeJunctionJson, + parameters: [value : CompositeJunction], + result: LexLeanStd.Json::Json, + body: (match value + | CompositeJunction.CompositeJunctionUnconditional => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "unconditional"))) (nil (Bytes * LexLeanStd.Json::Json))); (objectOf entries1)) + | CompositeJunction.CompositeJunctionProved part0 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "proved"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "evidence"), (SemanticTerms::memberJson (first part0) (second part0))) entries1); (objectOf entries2))) + | CompositeJunction.CompositeJunctionChecked => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "checked"))) (nil (Bytes * LexLeanStd.Json::Json))); (objectOf entries1))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: compositeFormJson, + parameters: [value : CompositeForm], + result: LexLeanStd.Json::Json, + body: (match value + | CompositeForm.CompositeFormSequence part0 part1 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "sequence"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "stages"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : ModelUse) => (cons (modelUseJson item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [ModelUse] part0) : (List LexLeanStd.Json::Json))))) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "junctions"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : CompositeJunction) => (cons (compositeJunctionJson item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [CompositeJunction] part1) : (List LexLeanStd.Json::Json))))) entries2); (objectOf entries3)))) + | CompositeForm.CompositeFormFanout part0 part1 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "fanout"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "left"), (modelUseJson part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "right"), (modelUseJson part1)) entries2); (objectOf entries3)))) + | CompositeForm.CompositeFormProduct part0 part1 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "product"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "left"), (modelUseJson part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "right"), (modelUseJson part1)) entries2); (objectOf entries3)))) + | CompositeForm.CompositeFormBranch part0 part1 part2 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "branch"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "guard"), (SemanticTerms::termJson part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "then"), (modelUseJson part1)) entries2); (let entries4 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "else"), (modelUseJson part2)) entries3); (objectOf entries4))))) + | CompositeForm.CompositeFormScan part0 part1 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "scan"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "stage"), (modelUseJson part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "junction"), (compositeJunctionJson part1)) entries2); (objectOf entries3))))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: realizationDescriptorJson, + parameters: [value : RealizationDescriptor], + result: LexLeanStd.Json::Json, + body: (match value + | RealizationDescriptor.RealizationDescriptorDeterministic part0 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "deterministic"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "body"), (SemanticTerms::termJson part0)) entries1); (objectOf entries2))) + | RealizationDescriptor.RealizationDescriptorRule part0 part1 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "rule"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "rules"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : RealizationRule) => (cons (realizationRuleJson item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [RealizationRule] part0) : (List LexLeanStd.Json::Json))))) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "default"), (SemanticTerms::termJson part1)) entries2); (objectOf entries3)))) + | RealizationDescriptor.RealizationDescriptorStatistical part0 part1 part2 part3 part4 part5 part6 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "statistical"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "scheme"), (statisticalSchemeJson part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "features"), (SemanticTerms::termJson part1)) entries2); (let entries4 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "width"), (ctor LexLeanStd.Json::Json.JInt false part2)) entries3); (let entries5 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "width_evidence"), (SemanticTerms::memberJson (first part3) (second part3))) entries4); (let entries6 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "weights"), (SemanticTerms::memberJson (first part4) (second part4))) entries5); (let entries7 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "bias"), (SemanticTerms::memberJson (first part5) (second part5))) entries6); (let entries8 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "labels"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : SemanticTerms::STerm) => (cons (SemanticTerms::termJson item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [SemanticTerms::STerm] part6) : (List LexLeanStd.Json::Json))))) entries7); (objectOf entries8))))))))) + | RealizationDescriptor.RealizationDescriptorNeural part0 part1 part2 part3 part4 part5 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "neural"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "architecture"), (neuralArchitectureJson part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "encoder"), (SemanticTerms::termJson part1)) entries2); (let entries4 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "width"), (ctor LexLeanStd.Json::Json.JInt false part2)) entries3); (let entries5 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "width_evidence"), (SemanticTerms::memberJson (first part3) (second part3))) entries4); (let entries6 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "layers"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : NeuralLayer) => (cons (neuralLayerJson item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [NeuralLayer] part4) : (List LexLeanStd.Json::Json))))) entries5); (let entries7 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "decoder"), (neuralDecoderJson part5)) entries6); (objectOf entries7)))))))) + | RealizationDescriptor.RealizationDescriptorComposite part0 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "composite"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "form"), (compositeFormJson part0)) entries1); (objectOf entries2)))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: evidenceClaimJson, + parameters: [value : EvidenceClaim], + result: LexLeanStd.Json::Json, + body: (match value + | EvidenceClaim.EvidenceClaimDatasetAgreement part0 part1 part2 part3 part4 part5 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "dataset_agreement"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "dataset"), (SemanticTerms::memberJson (first part0) (second part0))) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "comparison"), (SemanticTerms::memberJson (first part1) (second part1))) entries2); (let entries4 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "comparison_sound"), (SemanticTerms::memberJson (first part2) (second part2))) entries3); (let entries5 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "examples"), (ctor LexLeanStd.Json::Json.JInt false part3)) entries4); (let entries6 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "agreements"), (ctor LexLeanStd.Json::Json.JInt false part4)) entries5); (let entries7 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "theorem"), (SemanticTerms::memberJson (first part5) (second part5))) entries6); (objectOf entries7)))))))) + | EvidenceClaim.EvidenceClaimEquivalentTo part0 part1 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "equivalent_to"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "reference"), (modelUseJson part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "theorem"), (SemanticTerms::memberJson (first part1) (second part1))) entries2); (objectOf entries3)))) + | EvidenceClaim.EvidenceClaimInitialInvariant part0 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "initial_invariant"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "theorem"), (SemanticTerms::memberJson (first part0) (second part0))) entries1); (objectOf entries2))) + | EvidenceClaim.EvidenceClaimPreservesInvariant part0 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "preserves_invariant"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "theorem"), (SemanticTerms::memberJson (first part0) (second part0))) entries1); (objectOf entries2))) + | EvidenceClaim.EvidenceClaimSatisfiesContract part0 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "satisfies_contract"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "theorem"), (SemanticTerms::memberJson (first part0) (second part0))) entries1); (objectOf entries2)))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: modelDeclarationJson, + parameters: [value : ModelDeclaration], + result: LexLeanStd.Json::Json, + body: (match value + | ModelDeclaration.ModelDeclarationArtifact part0 part1 part2 part3 part4 part5 part6 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "artifact"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "name"), (ctor LexLeanStd.Json::Json.JStr part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "role"), (artifactRoleJson part1)) entries2); (let entries4 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "sha256"), (ctor LexLeanStd.Json::Json.JStr part2)) entries3); (let entries5 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "length"), (ctor LexLeanStd.Json::Json.JInt false part3)) entries4); (let entries6 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "schema"), (artifactSchemaJson part4)) entries5); (let entries7 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "type"), (SemanticTypes::typeJson part5)) entries6); (let entries8 : (List (Bytes * LexLeanStd.Json::Json)) := (match part6 + | List.nil => entries7 + | List.cons head tail => (cons ((lit "axioms"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : Bytes) => (cons (ctor LexLeanStd.Json::Json.JStr item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [Bytes] part6) : (List LexLeanStd.Json::Json))))) entries7)); (objectOf entries8))))))))) + | ModelDeclaration.ModelDeclarationContract part0 part1 part2 part3 part4 part5 part6 part7 part8 part9 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "contract"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "name"), (ctor LexLeanStd.Json::Json.JStr part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (match part1 + | List.nil => entries2 + | List.cons head tail => (cons ((lit "type_parameters"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : Bytes) => (cons (ctor LexLeanStd.Json::Json.JStr item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [Bytes] part1) : (List LexLeanStd.Json::Json))))) entries2)); (let entries4 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "input"), (modelBinderJson part2)) entries3); (let entries5 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "output"), (modelBinderJson part3)) entries4); (let entries6 : (List (Bytes * LexLeanStd.Json::Json)) := (match part4 + | Option.some present => (cons ((lit "state"), (contractStateJson present)) entries5) + | Option.none => entries5); (let entries7 : (List (Bytes * LexLeanStd.Json::Json)) := (match part5 + | Option.some present => (cons ((lit "precondition"), (SemanticTerms::memberJson (first present) (second present))) entries6) + | Option.none => entries6); (let entries8 : (List (Bytes * LexLeanStd.Json::Json)) := (match part6 + | Option.some present => (cons ((lit "postcondition"), (SemanticTerms::memberJson (first present) (second present))) entries7) + | Option.none => entries7); (let entries9 : (List (Bytes * LexLeanStd.Json::Json)) := (match part7 + | Option.some present => (cons ((lit "invariant"), (SemanticTerms::memberJson (first present) (second present))) entries8) + | Option.none => entries8); (let entries10 : (List (Bytes * LexLeanStd.Json::Json)) := (match part8 + | List.nil => entries9 + | List.cons head tail => (cons ((lit "validators"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : ContractValidator) => (cons (contractValidatorJson item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [ContractValidator] part8) : (List LexLeanStd.Json::Json))))) entries9)); (let entries11 : (List (Bytes * LexLeanStd.Json::Json)) := (match part9 + | List.nil => entries10 + | List.cons head tail => (cons ((lit "axioms"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : Bytes) => (cons (ctor LexLeanStd.Json::Json.JStr item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [Bytes] part9) : (List LexLeanStd.Json::Json))))) entries10)); (objectOf entries11)))))))))))) + | ModelDeclaration.ModelDeclarationRealization part0 part1 part2 part3 part4 part5 part6 part7 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "realization"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "name"), (ctor LexLeanStd.Json::Json.JStr part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (match part1 + | List.nil => entries2 + | List.cons head tail => (cons ((lit "type_parameters"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : Bytes) => (cons (ctor LexLeanStd.Json::Json.JStr item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [Bytes] part1) : (List LexLeanStd.Json::Json))))) entries2)); (let entries4 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "input"), (modelBinderJson part2)) entries3); (let entries5 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "output"), (SemanticTypes::typeJson part3)) entries4); (let entries6 : (List (Bytes * LexLeanStd.Json::Json)) := (match part4 + | Option.some present => (cons ((lit "state"), (realizationStateJson present)) entries5) + | Option.none => entries5); (let entries7 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "descriptor"), (realizationDescriptorJson part5)) entries6); (let entries8 : (List (Bytes * LexLeanStd.Json::Json)) := (if part6 then (cons ((lit "executable"), (ctor LexLeanStd.Json::Json.JBool true)) entries7) else entries7); (let entries9 : (List (Bytes * LexLeanStd.Json::Json)) := (match part7 + | List.nil => entries8 + | List.cons head tail => (cons ((lit "axioms"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : Bytes) => (cons (ctor LexLeanStd.Json::Json.JStr item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [Bytes] part7) : (List LexLeanStd.Json::Json))))) entries8)); (objectOf entries9)))))))))) + | ModelDeclaration.ModelDeclarationEvidence part0 part1 part2 part3 part4 part5 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "evidence"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "name"), (ctor LexLeanStd.Json::Json.JStr part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (match part1 + | List.nil => entries2 + | List.cons head tail => (cons ((lit "type_parameters"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : Bytes) => (cons (ctor LexLeanStd.Json::Json.JStr item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [Bytes] part1) : (List LexLeanStd.Json::Json))))) entries2)); (let entries4 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "contract"), (modelUseJson part2)) entries3); (let entries5 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "realization"), (modelUseJson part3)) entries4); (let entries6 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "claims"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : EvidenceClaim) => (cons (evidenceClaimJson item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [EvidenceClaim] part4) : (List LexLeanStd.Json::Json))))) entries5); (let entries7 : (List (Bytes * LexLeanStd.Json::Json)) := (match part5 + | List.nil => entries6 + | List.cons head tail => (cons ((lit "axioms"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : Bytes) => (cons (ctor LexLeanStd.Json::Json.JStr item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [Bytes] part5) : (List LexLeanStd.Json::Json))))) entries6)); (objectOf entries7)))))))) + | ModelDeclaration.ModelDeclarationModel part0 part1 part2 part3 part4 part5 part6 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "model"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "name"), (ctor LexLeanStd.Json::Json.JStr part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (match part1 + | List.nil => entries2 + | List.cons head tail => (cons ((lit "type_parameters"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : Bytes) => (cons (ctor LexLeanStd.Json::Json.JStr item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [Bytes] part1) : (List LexLeanStd.Json::Json))))) entries2)); (let entries4 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "contract"), (modelUseJson part2)) entries3); (let entries5 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "realization"), (modelUseJson part3)) entries4); (let entries6 : (List (Bytes * LexLeanStd.Json::Json)) := (match part4 + | List.nil => entries5 + | List.cons head tail => (cons ((lit "evidence"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : ModelUse) => (cons (modelUseJson item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [ModelUse] part4) : (List LexLeanStd.Json::Json))))) entries5)); (let entries7 : (List (Bytes * LexLeanStd.Json::Json)) := (match part5 + | List.nil => entries6 + | List.cons head tail => (cons ((lit "entry"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : ((Option Bytes) * Bytes)) => (cons (SemanticTerms::memberJson (first item) (second item)) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [((Option Bytes) * Bytes)] part5) : (List LexLeanStd.Json::Json))))) entries6)); (let entries8 : (List (Bytes * LexLeanStd.Json::Json)) := (match part6 + | List.nil => entries7 + | List.cons head tail => (cons ((lit "axioms"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : Bytes) => (cons (ctor LexLeanStd.Json::Json.JStr item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [Bytes] part6) : (List LexLeanStd.Json::Json))))) entries7)); (objectOf entries8)))))))))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: modelDeclarationText, + parameters: [value : ModelDeclaration], + result: Bytes, + body: (LexLeanStd.Json::writeJson (modelDeclarationJson value)), + axioms: [Quot.sound, propext], + executable: true, + production: {effects: [allocation, overflow, recursion], targets: [rust-std]} +} +\end{semanticmodule} +\end{lexlean} diff --git a/crates/conformance/src/cases/bootstrap.rs b/crates/conformance/src/cases/bootstrap.rs index 57c1a85c23..70f735bfbe 100644 --- a/crates/conformance/src/cases/bootstrap.rs +++ b/crates/conformance/src/cases/bootstrap.rs @@ -46,6 +46,7 @@ mod rust_terms; mod rust_validate; mod scan; mod semantic_decls; +mod semantic_models; mod semantic_terms; mod semantic_types; mod structural_grammar; @@ -2586,6 +2587,7 @@ fn case(id: &str) { "BS-68" => semantic_types::case(), "BS-69" => semantic_terms::case(), "BS-70" => semantic_decls::case(), + "BS-71" => semantic_models::case(), other => panic!("no bootstrap case is wired for {other}"), } } diff --git a/crates/conformance/src/cases/bootstrap/semantic_models.rs b/crates/conformance/src/cases/bootstrap/semantic_models.rs new file mode 100755 index 0000000000..8961e2eda9 --- /dev/null +++ b/crates/conformance/src/cases/bootstrap/semantic_models.rs @@ -0,0 +1,1414 @@ +//! `BS-71` (SPEC.md §17.23, §17.12): the declarations of models, contracts, +//! realizations, evidence, and artifacts of the semantic module language as +//! language-1.2 source, `LexLeanBoot.SemanticModels`, held to the byte to the +//! serde form of those variants of `lexlean::ir::semantic::SemanticDeclaration` +//! in canonical JSON, as the linked IR embeds them. +//! +//! `modelDeclarationText` writes an artifact, contract, realization, evidence, +//! or model declaration with every datatype it holds: artifact roles and +//! schemas, binders, states, validators, uses, rules, the statistical, neural, +//! and composite realization descriptors with their layers, decoders, forms, +//! and junctions, and evidence claims, each optional member left out exactly +//! where the oracle's serde attributes skip it. The module, its encoders here, +//! and the example builders here are generated from one description of the +//! oracle's types. Every such declaration of every committed semantic module +//! that links is a run, and so are examples that reach every variant, every +//! optional member present and absent, and every list empty and not. +//! +//! Each planted defect renames one serialized kind or name and is detected by +//! the first example that holds it. + +use std::collections::{BTreeMap, BTreeSet}; +use std::sync::OnceLock; + +use lexlean::calculus::Value; +use lexlean::ir::semantic::{ + ArtifactRole, ArtifactSchema, CompositeForm, CompositeJunction, ContractPredicate, + ContractState, ContractValidator, EvidenceClaim, MemberRef, ModelBinder, ModelUse, + NeuralArchitecture, NeuralDecoder, NeuralLayer, RealizationDescriptor, RealizationRule, + RealizationState, SemanticDeclaration, SemanticTerm, SemanticType, StatisticalScheme, + TensorElement, +}; +use serde_json::Value as Json2; + +use super::ir_document::linked_projects; +use super::rust_validate::{eligibility_of, rustc_differential}; +use super::semantic_terms::enc_term; +use super::semantic_types::{canonical, enc_type}; +use super::{list, option, pair, text, Run, Seeded}; +use crate::production_export as harness; +use crate::support::{self, repo_root}; + +const MODULE: &str = "LexLeanBoot.SemanticModels"; +const SOURCE: &str = "bootstrap/src/SemanticModels.lex.tex"; +const ROOTS: [(&str, &[&str]); 1] = [( + "modelDeclarationText", + &["allocation", "overflow", "recursion"], +)]; + +/// The most a part of a certificate of a root may be, as the row states. +const CERTIFICATE_BUDGET: u64 = 3_145_728; +/// The examples: one per step, the step's digits choosing every variant. +const EXAMPLES: usize = 150; +/// Seeded examples under the evaluator, and under rustc. +const EVALUATOR_SEEDED: usize = 100; +const RUSTC_SEEDED: usize = 500; + +// ---------------------------------------------------------------- the sorts + +fn constructors(sort: &str) -> &'static Vec { + static TABLES: OnceLock>> = OnceLock::new(); + let tables = TABLES.get_or_init(|| { + let source = std::fs::read_to_string(repo_root().join(SOURCE).as_std_path()) + .expect("the module's source"); + let mut out = BTreeMap::new(); + for block in source.split("inductive{").skip(1) { + let block = block.split("\n}\n").next().expect("a block"); + let name = block + .split("name: ") + .nth(1) + .and_then(|rest| rest.split(',').next()) + .expect("the inductive's name") + .trim() + .to_owned(); + let names: Vec = block + .split("constructors:") + .nth(1) + .expect("the constructors") + .split("name: ") + .skip(1) + .map(|rest| { + rest.split([',', '\n']) + .next() + .expect("a constructor") + .trim() + .to_owned() + }) + .collect(); + out.insert(name, names); + } + out + }); + tables + .get(sort) + .unwrap_or_else(|| panic!("the module has no inductive `{sort}`")) +} + +fn adt(sort: &str, constructor: &str, fields: Vec) -> Value { + let found = constructors(sort) + .iter() + .position(|name| name == constructor) + .unwrap_or_else(|| panic!("`{sort}` has no constructor `{constructor}`")); + Value::Adt { + constructor: u64::try_from(found).expect("an index"), + fields, + } +} + +fn nat(value: u64) -> Value { + Value::Nat { + value: value.to_string(), + } +} + +fn enc_member(member: &MemberRef) -> Value { + pair( + option(member.module.as_deref().map(text)), + text(&member.name), + ) +} + +// ------------------------------------------- generated from the type schema + +fn enc_artifact_role(value: &ArtifactRole) -> Value { + adt( + "ArtifactRole", + &format!("ArtifactRole{value:?}"), + Vec::new(), + ) +} + +const ALL_ARTIFACT_ROLE: &[ArtifactRole] = &[ + ArtifactRole::Parameters, + ArtifactRole::Vocabulary, + ArtifactRole::Dataset, + ArtifactRole::Table, + ArtifactRole::Binary, +]; + +fn example_artifact_role(step: usize) -> ArtifactRole { + ALL_ARTIFACT_ROLE[step % ALL_ARTIFACT_ROLE.len()] +} + +fn enc_tensor_element(value: &TensorElement) -> Value { + adt( + "TensorElement", + &format!("TensorElement{value:?}"), + Vec::new(), + ) +} + +const ALL_TENSOR_ELEMENT: &[TensorElement] = &[ + TensorElement::Int8, + TensorElement::Int16, + TensorElement::Int32, + TensorElement::Int64, + TensorElement::UInt8, + TensorElement::UInt16, + TensorElement::UInt32, + TensorElement::UInt64, +]; + +fn example_tensor_element(step: usize) -> TensorElement { + ALL_TENSOR_ELEMENT[step % ALL_TENSOR_ELEMENT.len()] +} + +fn enc_artifact_schema(value: &ArtifactSchema) -> Value { + match value { + ArtifactSchema::Bytes => adt("ArtifactSchema", "ArtifactSchemaBytes", vec![]), + ArtifactSchema::IntTensor { element, shape } => adt( + "ArtifactSchema", + "ArtifactSchemaIntTensor", + vec![ + enc_tensor_element(element), + list(shape.iter().map(|item| nat(*item)).collect()), + ], + ), + ArtifactSchema::Utf8Lines => adt("ArtifactSchema", "ArtifactSchemaUtf8Lines", vec![]), + } +} + +#[allow(clippy::too_many_lines)] +fn example_artifact_schema(step: usize) -> ArtifactSchema { + let rest = step / 3; + match step % 3 { + 0 => ArtifactSchema::Bytes, + 1 => ArtifactSchema::IntTensor { + element: example_tensor_element(rest), + shape: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2) + .map(|next| u64::try_from(next).expect("a rest") + 1) + .collect() + }, + }, + _ => ArtifactSchema::Utf8Lines, + } +} + +fn enc_model_binder(value: &ModelBinder) -> Value { + adt( + "ModelBinder", + "ModelBinderOf", + vec![text(&value.name), enc_type(&value.r#type)], + ) +} + +fn example_model_binder(step: usize) -> ModelBinder { + ModelBinder { + name: format!("s{step}"), + r#type: if step % 2 == 0 { + SemanticType::Nat + } else { + SemanticType::Bytes + }, + } +} + +fn enc_contract_state(value: &ContractState) -> Value { + adt( + "ContractState", + "ContractStateOf", + vec![ + text(&value.name), + text(&value.next), + enc_type(&value.r#type), + ], + ) +} + +fn example_contract_state(step: usize) -> ContractState { + ContractState { + name: format!("s{step}"), + next: format!("s{step}"), + r#type: if step % 2 == 0 { + SemanticType::Nat + } else { + SemanticType::Bytes + }, + } +} + +fn enc_contract_predicate(value: &ContractPredicate) -> Value { + adt( + "ContractPredicate", + &format!("ContractPredicate{value:?}"), + Vec::new(), + ) +} + +const ALL_CONTRACT_PREDICATE: &[ContractPredicate] = &[ + ContractPredicate::Invariant, + ContractPredicate::Postcondition, + ContractPredicate::Precondition, +]; + +fn example_contract_predicate(step: usize) -> ContractPredicate { + ALL_CONTRACT_PREDICATE[step % ALL_CONTRACT_PREDICATE.len()] +} + +fn enc_contract_validator(value: &ContractValidator) -> Value { + adt( + "ContractValidator", + "ContractValidatorOf", + vec![ + enc_contract_predicate(&value.predicate), + enc_member(&value.validator), + enc_member(&value.sound), + option(&value.complete.as_ref().map(|item| enc_member(item))), + ], + ) +} + +fn example_contract_validator(step: usize) -> ContractValidator { + ContractValidator { + predicate: example_contract_predicate(step), + validator: MemberRef { + module: (step % 2 == 0).then(|| "M".to_owned()), + name: format!("m{step}"), + }, + sound: MemberRef { + module: (step % 2 == 0).then(|| "M".to_owned()), + name: format!("m{step}"), + }, + complete: (step % 3 != 2).then(|| MemberRef { + module: (step % 2 == 0).then(|| "M".to_owned()), + name: format!("m{step}"), + }), + } +} + +fn enc_model_use(value: &ModelUse) -> Value { + adt( + "ModelUse", + "ModelUseOf", + vec![ + enc_member(&value.member), + list( + &value + .type_arguments + .iter() + .map(|item| enc_type(item)) + .collect(), + ), + ], + ) +} + +fn example_model_use(step: usize) -> ModelUse { + ModelUse { + member: MemberRef { + module: (step % 2 == 0).then(|| "M".to_owned()), + name: format!("m{step}"), + }, + type_arguments: if step % 3 == 2 { + Vec::new() + } else { + (step..step + 2) + .map(|next| { + if step % 2 == 0 { + SemanticType::Nat + } else { + SemanticType::Bytes + } + }) + .collect() + }, + } +} + +fn enc_realization_state(value: &RealizationState) -> Value { + adt( + "RealizationState", + "RealizationStateOf", + vec![ + text(&value.name), + enc_type(&value.r#type), + enc_term(&value.initial), + ], + ) +} + +fn example_realization_state(step: usize) -> RealizationState { + RealizationState { + name: format!("s{step}"), + r#type: if step % 2 == 0 { + SemanticType::Nat + } else { + SemanticType::Bytes + }, + initial: SemanticTerm::Nat { + value: step.to_string(), + }, + } +} + +fn enc_realization_rule(value: &RealizationRule) -> Value { + adt( + "RealizationRule", + "RealizationRuleOf", + vec![ + text(&value.name), + enc_term(&value.guard), + enc_term(&value.action), + ], + ) +} + +fn example_realization_rule(step: usize) -> RealizationRule { + RealizationRule { + name: format!("s{step}"), + guard: SemanticTerm::Nat { + value: step.to_string(), + }, + action: SemanticTerm::Nat { + value: step.to_string(), + }, + } +} + +fn enc_statistical_scheme(value: &StatisticalScheme) -> Value { + adt( + "StatisticalScheme", + &format!("StatisticalScheme{value:?}"), + Vec::new(), + ) +} + +const ALL_STATISTICAL_SCHEME: &[StatisticalScheme] = &[StatisticalScheme::LinearScoring]; + +fn example_statistical_scheme(step: usize) -> StatisticalScheme { + ALL_STATISTICAL_SCHEME[step % ALL_STATISTICAL_SCHEME.len()] +} + +fn enc_neural_architecture(value: &NeuralArchitecture) -> Value { + adt( + "NeuralArchitecture", + &format!("NeuralArchitecture{value:?}"), + Vec::new(), + ) +} + +const ALL_NEURAL_ARCHITECTURE: &[NeuralArchitecture] = &[NeuralArchitecture::IntegerFeedforward]; + +fn example_neural_architecture(step: usize) -> NeuralArchitecture { + ALL_NEURAL_ARCHITECTURE[step % ALL_NEURAL_ARCHITECTURE.len()] +} + +fn enc_neural_layer(value: &NeuralLayer) -> Value { + match value { + NeuralLayer::Dense { + inputs, + outputs, + weights, + bias, + } => adt( + "NeuralLayer", + "NeuralLayerDense", + vec![ + nat(*inputs), + nat(*outputs), + enc_member(weights), + enc_member(bias), + ], + ), + NeuralLayer::Relu => adt("NeuralLayer", "NeuralLayerRelu", vec![]), + NeuralLayer::Requantize { + shift, + minimum, + maximum, + } => adt( + "NeuralLayer", + "NeuralLayerRequantize", + vec![nat(*shift), text(minimum), text(maximum)], + ), + } +} + +#[allow(clippy::too_many_lines)] +fn example_neural_layer(step: usize) -> NeuralLayer { + let rest = step / 3; + match step % 3 { + 0 => NeuralLayer::Dense { + inputs: u64::try_from(rest).expect("a rest") + 1, + outputs: u64::try_from(rest).expect("a rest") + 1, + weights: MemberRef { + module: (rest % 2 == 0).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + bias: MemberRef { + module: (rest % 2 == 0).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + }, + 1 => NeuralLayer::Relu, + _ => NeuralLayer::Requantize { + shift: u64::try_from(rest).expect("a rest") + 1, + minimum: format!("s{rest}"), + maximum: format!("s{rest}"), + }, + } +} + +fn enc_neural_decoder(value: &NeuralDecoder) -> Value { + match value { + NeuralDecoder::Argmax { labels } => adt( + "NeuralDecoder", + "NeuralDecoderArgmax", + vec![list(labels.iter().map(|item| enc_term(item)).collect())], + ), + NeuralDecoder::Function { binder, body } => adt( + "NeuralDecoder", + "NeuralDecoderFunction", + vec![text(binder), enc_term(body)], + ), + } +} + +#[allow(clippy::too_many_lines)] +fn example_neural_decoder(step: usize) -> NeuralDecoder { + let rest = step / 2; + match step % 2 { + 0 => NeuralDecoder::Argmax { + labels: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2) + .map(|next| SemanticTerm::Nat { + value: rest.to_string(), + }) + .collect() + }, + }, + _ => NeuralDecoder::Function { + binder: format!("s{rest}"), + body: SemanticTerm::Nat { + value: rest.to_string(), + }, + }, + } +} + +fn enc_composite_junction(value: &CompositeJunction) -> Value { + match value { + CompositeJunction::Unconditional => adt( + "CompositeJunction", + "CompositeJunctionUnconditional", + vec![], + ), + CompositeJunction::Proved { evidence } => adt( + "CompositeJunction", + "CompositeJunctionProved", + vec![enc_member(evidence)], + ), + CompositeJunction::Checked => adt("CompositeJunction", "CompositeJunctionChecked", vec![]), + } +} + +#[allow(clippy::too_many_lines)] +fn example_composite_junction(step: usize) -> CompositeJunction { + let rest = step / 3; + match step % 3 { + 0 => CompositeJunction::Unconditional, + 1 => CompositeJunction::Proved { + evidence: MemberRef { + module: (rest % 2 == 0).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + }, + _ => CompositeJunction::Checked, + } +} + +fn enc_composite_form(value: &CompositeForm) -> Value { + match value { + CompositeForm::Sequence { stages, junctions } => adt( + "CompositeForm", + "CompositeFormSequence", + vec![ + list(stages.iter().map(|item| enc_model_use(item)).collect()), + list( + junctions + .iter() + .map(|item| enc_composite_junction(item)) + .collect(), + ), + ], + ), + CompositeForm::Fanout { left, right } => adt( + "CompositeForm", + "CompositeFormFanout", + vec![enc_model_use(left), enc_model_use(right)], + ), + CompositeForm::Product { left, right } => adt( + "CompositeForm", + "CompositeFormProduct", + vec![enc_model_use(left), enc_model_use(right)], + ), + CompositeForm::Branch { + guard, + then, + r#else, + } => adt( + "CompositeForm", + "CompositeFormBranch", + vec![enc_term(guard), enc_model_use(then), enc_model_use(r#else)], + ), + CompositeForm::Scan { stage, junction } => adt( + "CompositeForm", + "CompositeFormScan", + vec![enc_model_use(stage), enc_composite_junction(junction)], + ), + } +} + +#[allow(clippy::too_many_lines)] +fn example_composite_form(step: usize) -> CompositeForm { + let rest = step / 5; + match step % 5 { + 0 => CompositeForm::Sequence { + stages: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2) + .map(|next| example_model_use(next)) + .collect() + }, + junctions: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2) + .map(|next| example_composite_junction(next)) + .collect() + }, + }, + 1 => CompositeForm::Fanout { + left: example_model_use(rest), + right: example_model_use(rest), + }, + 2 => CompositeForm::Product { + left: example_model_use(rest), + right: example_model_use(rest), + }, + 3 => CompositeForm::Branch { + guard: SemanticTerm::Nat { + value: rest.to_string(), + }, + then: example_model_use(rest), + r#else: example_model_use(rest), + }, + _ => CompositeForm::Scan { + stage: example_model_use(rest), + junction: example_composite_junction(rest), + }, + } +} + +fn enc_realization_descriptor(value: &RealizationDescriptor) -> Value { + match value { + RealizationDescriptor::Deterministic { body } => adt( + "RealizationDescriptor", + "RealizationDescriptorDeterministic", + vec![enc_term(body)], + ), + RealizationDescriptor::Rule { rules, default } => adt( + "RealizationDescriptor", + "RealizationDescriptorRule", + vec![ + list( + rules + .iter() + .map(|item| enc_realization_rule(item)) + .collect(), + ), + enc_term(default), + ], + ), + RealizationDescriptor::Statistical { + scheme, + features, + width, + width_evidence, + weights, + bias, + labels, + } => adt( + "RealizationDescriptor", + "RealizationDescriptorStatistical", + vec![ + enc_statistical_scheme(scheme), + enc_term(features), + nat(*width), + enc_member(width_evidence), + enc_member(weights), + enc_member(bias), + list(labels.iter().map(|item| enc_term(item)).collect()), + ], + ), + RealizationDescriptor::Neural { + architecture, + encoder, + width, + width_evidence, + layers, + decoder, + } => adt( + "RealizationDescriptor", + "RealizationDescriptorNeural", + vec![ + enc_neural_architecture(architecture), + enc_term(encoder), + nat(*width), + enc_member(width_evidence), + list(layers.iter().map(|item| enc_neural_layer(item)).collect()), + enc_neural_decoder(decoder), + ], + ), + RealizationDescriptor::Composite { form } => adt( + "RealizationDescriptor", + "RealizationDescriptorComposite", + vec![enc_composite_form(form)], + ), + } +} + +#[allow(clippy::too_many_lines)] +fn example_realization_descriptor(step: usize) -> RealizationDescriptor { + let rest = step / 5; + match step % 5 { + 0 => RealizationDescriptor::Deterministic { + body: SemanticTerm::Nat { + value: rest.to_string(), + }, + }, + 1 => RealizationDescriptor::Rule { + rules: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2) + .map(|next| example_realization_rule(next)) + .collect() + }, + default: SemanticTerm::Nat { + value: rest.to_string(), + }, + }, + 2 => RealizationDescriptor::Statistical { + scheme: example_statistical_scheme(rest), + features: SemanticTerm::Nat { + value: rest.to_string(), + }, + width: u64::try_from(rest).expect("a rest") + 1, + width_evidence: MemberRef { + module: (rest % 2 == 0).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + weights: MemberRef { + module: (rest % 2 == 0).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + bias: MemberRef { + module: (rest % 2 == 0).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + labels: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2) + .map(|next| SemanticTerm::Nat { + value: rest.to_string(), + }) + .collect() + }, + }, + 3 => RealizationDescriptor::Neural { + architecture: example_neural_architecture(rest), + encoder: SemanticTerm::Nat { + value: rest.to_string(), + }, + width: u64::try_from(rest).expect("a rest") + 1, + width_evidence: MemberRef { + module: (rest % 2 == 0).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + layers: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2) + .map(|next| example_neural_layer(next)) + .collect() + }, + decoder: example_neural_decoder(rest), + }, + _ => RealizationDescriptor::Composite { + form: example_composite_form(rest), + }, + } +} + +fn enc_evidence_claim(value: &EvidenceClaim) -> Value { + match value { + EvidenceClaim::DatasetAgreement { + dataset, + comparison, + comparison_sound, + examples, + agreements, + theorem, + } => adt( + "EvidenceClaim", + "EvidenceClaimDatasetAgreement", + vec![ + enc_member(dataset), + enc_member(comparison), + enc_member(comparison_sound), + nat(*examples), + nat(*agreements), + enc_member(theorem), + ], + ), + EvidenceClaim::EquivalentTo { reference, theorem } => adt( + "EvidenceClaim", + "EvidenceClaimEquivalentTo", + vec![enc_model_use(reference), enc_member(theorem)], + ), + EvidenceClaim::InitialInvariant { theorem } => adt( + "EvidenceClaim", + "EvidenceClaimInitialInvariant", + vec![enc_member(theorem)], + ), + EvidenceClaim::PreservesInvariant { theorem } => adt( + "EvidenceClaim", + "EvidenceClaimPreservesInvariant", + vec![enc_member(theorem)], + ), + EvidenceClaim::SatisfiesContract { theorem } => adt( + "EvidenceClaim", + "EvidenceClaimSatisfiesContract", + vec![enc_member(theorem)], + ), + } +} + +#[allow(clippy::too_many_lines)] +fn example_evidence_claim(step: usize) -> EvidenceClaim { + let rest = step / 5; + match step % 5 { + 0 => EvidenceClaim::DatasetAgreement { + dataset: MemberRef { + module: (rest % 2 == 0).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + comparison: MemberRef { + module: (rest % 2 == 0).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + comparison_sound: MemberRef { + module: (rest % 2 == 0).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + examples: u64::try_from(rest).expect("a rest") + 1, + agreements: u64::try_from(rest).expect("a rest") + 1, + theorem: MemberRef { + module: (rest % 2 == 0).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + }, + 1 => EvidenceClaim::EquivalentTo { + reference: example_model_use(rest), + theorem: MemberRef { + module: (rest % 2 == 0).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + }, + 2 => EvidenceClaim::InitialInvariant { + theorem: MemberRef { + module: (rest % 2 == 0).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + }, + 3 => EvidenceClaim::PreservesInvariant { + theorem: MemberRef { + module: (rest % 2 == 0).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + }, + _ => EvidenceClaim::SatisfiesContract { + theorem: MemberRef { + module: (rest % 2 == 0).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + }, + } +} + +fn enc_model_declaration(value: &SemanticDeclaration) -> Value { + match value { + SemanticDeclaration::Artifact { + name, + role, + sha256, + length, + schema, + r#type, + axioms, + } => adt( + "ModelDeclaration", + "ModelDeclarationArtifact", + vec![ + text(name), + enc_artifact_role(role), + text(sha256), + nat(*length), + enc_artifact_schema(schema), + enc_type(r#type), + list(axioms.iter().map(|item| text(item)).collect()), + ], + ), + SemanticDeclaration::Contract { + name, + type_parameters, + input, + output, + state, + precondition, + postcondition, + invariant, + validators, + axioms, + } => adt( + "ModelDeclaration", + "ModelDeclarationContract", + vec![ + text(name), + list(type_parameters.iter().map(|item| text(item)).collect()), + enc_model_binder(input), + enc_model_binder(output), + option(state.as_ref().map(|item| enc_contract_state(item))), + option(precondition.as_ref().map(|item| enc_member(item))), + option(postcondition.as_ref().map(|item| enc_member(item))), + option(invariant.as_ref().map(|item| enc_member(item))), + list( + validators + .iter() + .map(|item| enc_contract_validator(item)) + .collect(), + ), + list(axioms.iter().map(|item| text(item)).collect()), + ], + ), + SemanticDeclaration::Realization { + name, + type_parameters, + input, + output, + state, + descriptor, + executable, + axioms, + } => adt( + "ModelDeclaration", + "ModelDeclarationRealization", + vec![ + text(name), + list(type_parameters.iter().map(|item| text(item)).collect()), + enc_model_binder(input), + enc_type(output), + option(state.as_ref().map(|item| enc_realization_state(item))), + enc_realization_descriptor(descriptor), + Value::Bool { value: *executable }, + list(axioms.iter().map(|item| text(item)).collect()), + ], + ), + SemanticDeclaration::Evidence { + name, + type_parameters, + contract, + realization, + claims, + axioms, + } => adt( + "ModelDeclaration", + "ModelDeclarationEvidence", + vec![ + text(name), + list(type_parameters.iter().map(|item| text(item)).collect()), + enc_model_use(contract), + enc_model_use(realization), + list(claims.iter().map(|item| enc_evidence_claim(item)).collect()), + list(axioms.iter().map(|item| text(item)).collect()), + ], + ), + SemanticDeclaration::Model { + name, + type_parameters, + contract, + realization, + evidence, + entry, + axioms, + } => adt( + "ModelDeclaration", + "ModelDeclarationModel", + vec![ + text(name), + list(type_parameters.iter().map(|item| text(item)).collect()), + enc_model_use(contract), + enc_model_use(realization), + list(evidence.iter().map(|item| enc_model_use(item)).collect()), + list(entry.iter().map(|item| enc_member(item)).collect()), + list(axioms.iter().map(|item| text(item)).collect()), + ], + ), + other => panic!("not a declaration of this module: {other:?}"), + } +} + +#[allow(clippy::too_many_lines)] +fn example_model_declaration(step: usize) -> SemanticDeclaration { + let rest = step / 5; + match step % 5 { + 0 => SemanticDeclaration::Artifact { + name: format!("s{rest}"), + role: example_artifact_role(rest), + sha256: format!("s{rest}"), + length: u64::try_from(rest).expect("a rest") + 1, + schema: example_artifact_schema(rest), + r#type: if rest % 2 == 0 { + SemanticType::Nat + } else { + SemanticType::Bytes + }, + axioms: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(|next| format!("s{rest}")).collect() + }, + }, + 1 => SemanticDeclaration::Contract { + name: format!("s{rest}"), + type_parameters: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(|next| format!("s{rest}")).collect() + }, + input: example_model_binder(rest), + output: example_model_binder(rest), + state: (rest % 3 != 2).then(|| example_contract_state(rest)), + precondition: (rest % 3 != 2).then(|| MemberRef { + module: (rest % 2 == 0).then(|| "M".to_owned()), + name: format!("m{rest}"), + }), + postcondition: (rest % 3 != 2).then(|| MemberRef { + module: (rest % 2 == 0).then(|| "M".to_owned()), + name: format!("m{rest}"), + }), + invariant: (rest % 3 != 2).then(|| MemberRef { + module: (rest % 2 == 0).then(|| "M".to_owned()), + name: format!("m{rest}"), + }), + validators: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2) + .map(|next| example_contract_validator(next)) + .collect() + }, + axioms: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(|next| format!("s{rest}")).collect() + }, + }, + 2 => SemanticDeclaration::Realization { + name: format!("s{rest}"), + type_parameters: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(|next| format!("s{rest}")).collect() + }, + input: example_model_binder(rest), + output: if rest % 2 == 0 { + SemanticType::Nat + } else { + SemanticType::Bytes + }, + state: (rest % 3 != 2).then(|| example_realization_state(rest)), + descriptor: example_realization_descriptor(rest), + executable: rest % 2 == 0, + axioms: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(|next| format!("s{rest}")).collect() + }, + }, + 3 => SemanticDeclaration::Evidence { + name: format!("s{rest}"), + type_parameters: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(|next| format!("s{rest}")).collect() + }, + contract: example_model_use(rest), + realization: example_model_use(rest), + claims: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2) + .map(|next| example_evidence_claim(next)) + .collect() + }, + axioms: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(|next| format!("s{rest}")).collect() + }, + }, + _ => SemanticDeclaration::Model { + name: format!("s{rest}"), + type_parameters: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(|next| format!("s{rest}")).collect() + }, + contract: example_model_use(rest), + realization: example_model_use(rest), + evidence: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2) + .map(|next| example_model_use(next)) + .collect() + }, + entry: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2) + .map(|next| MemberRef { + module: (rest % 2 == 0).then(|| "M".to_owned()), + name: format!("m{rest}"), + }) + .collect() + }, + axioms: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(|next| format!("s{rest}")).collect() + }, + }, + } +} + +/// Every serialized kind of a tagged variant. +const KINDS: &[&str] = &[ + "bytes", + "int_tensor", + "utf8_lines", + "dense", + "relu", + "requantize", + "argmax", + "function", + "unconditional", + "proved", + "checked", + "sequence", + "fanout", + "product", + "branch", + "scan", + "deterministic", + "rule", + "statistical", + "neural", + "composite", + "dataset_agreement", + "equivalent_to", + "initial_invariant", + "preserves_invariant", + "satisfies_contract", + "artifact", + "contract", + "realization", + "evidence", + "model", +]; + +// ------------------------------------------------------------- the inputs + +fn is_model(declaration: &SemanticDeclaration) -> bool { + matches!( + declaration, + SemanticDeclaration::Artifact { .. } + | SemanticDeclaration::Contract { .. } + | SemanticDeclaration::Realization { .. } + | SemanticDeclaration::Evidence { .. } + | SemanticDeclaration::Model { .. } + ) +} + +fn run(declaration: &SemanticDeclaration) -> Run { + ( + vec![enc_model_declaration(declaration)], + serde_json::to_value(text(&canonical(declaration))).expect("a value is JSON"), + ) +} + +/// Every distinct model-family declaration of every committed semantic +/// module that links. +fn committed() -> Vec { + let mut out = BTreeMap::new(); + for project in linked_projects() { + for module in project.modules.values() { + if let Some(semantic) = &module.semantic { + for declaration in semantic.declarations.iter().filter(|item| is_model(item)) { + out.insert(canonical(declaration), declaration.clone()); + } + } + } + } + out.into_values().collect() +} + +fn seeded_examples(count: usize, seed: u64) -> Vec { + let mut seeded = Seeded(seed); + (0..count) + .map(|_| example_model_declaration(seeded.below(1_000_000))) + .collect() +} + +// ------------------------------------------------------------------- plants + +/// The serialized names a plant renames besides the kinds, each with the +/// member that holds it. +const NAMES: &[(&str, &str)] = &[ + ("uint8", "element"), + ("linear_scoring", "scheme"), + ("precondition", "predicate"), + ("integer_feedforward", "architecture"), +]; + +struct Plant { + label: String, + site: String, + replacement: String, + needle: String, +} + +/// One plant per serialized kind and per name of `NAMES`, each with the +/// JSON fragment its vector must hold. +fn plant_list() -> Vec { + let mut out: Vec = KINDS + .iter() + .map(|kind| Plant { + label: format!("the kind `{kind}` is misspelled"), + site: format!("(lit \"kind\"), (ctor LexLeanStd.Json::Json.JStr (lit \"{kind}\"))"), + replacement: format!( + "(lit \"kind\"), (ctor LexLeanStd.Json::Json.JStr (lit \"{kind}x\"))" + ), + needle: format!("\"kind\":\"{kind}\""), + }) + .collect(); + out.extend(NAMES.iter().map(|(name, holder)| Plant { + label: format!("the name `{name}` is misspelled"), + site: format!("(ctor LexLeanStd.Json::Json.JStr (lit \"{name}\"))"), + replacement: format!("(ctor LexLeanStd.Json::Json.JStr (lit \"{name}x\"))"), + needle: format!("\"{holder}\":\"{name}\""), + })); + out +} + +fn plants(examples: &[SemanticDeclaration]) -> usize { + let mut missed = Vec::new(); + let list = plant_list(); + for plant in &list { + let vector = examples + .iter() + .find(|example| canonical(*example).contains(&plant.needle)) + .unwrap_or_else(|| panic!("{}: no example holds {}", plant.label, plant.needle)); + let planted = support::P::bootstrap(); + let source = planted.read_raw("src/SemanticModels.lex.tex"); + assert_eq!( + source.matches(&plant.site).count(), + 1, + "{}: the plant site occurs once", + plant.label + ); + planted.write( + "src/SemanticModels.lex.tex", + &source.replacen(&plant.site, &plant.replacement, 1), + ); + let checked = support::checked_project(&planted); + let low = super::lower(&checked, &planted, MODULE, ROOTS[0].0); + match super::evaluate(&low, &[run(vector)], 1).first() { + Some(first) => eprintln!( + "BS-71: plant detected: {}: {}", + plant.label, + first.chars().take(120).collect::() + ), + None => missed.push(plant.label.clone()), + } + } + assert!( + missed.is_empty(), + "planted defects their own vector does not detect: {missed:?}" + ); + list.len() +} + +fn export(lowered: &BTreeMap<&str, super::Lowered>) { + let exported = harness::exported("bootstrap"); + let bundle = exported.bundle(); + let mut realized = 0usize; + for exported_root in &exported.output.result.roots { + let Some((member, low)) = exported_root + .root + .strip_prefix(&format!("{MODULE}.")) + .and_then(|member| lowered.get(member).map(|low| (member, low))) + else { + continue; + }; + let largest = exported_root + .outputs + .iter() + .flat_map(|output| &output.certification.certificates) + .map(|certificate| certificate.file.byte_length) + .max() + .expect("a certificate"); + eprintln!( + "BS-71: {}: largest certificate part {largest} bytes", + exported_root.root + ); + assert!( + largest <= CERTIFICATE_BUDGET, + "{}: a certificate part of {largest} bytes is beyond {CERTIFICATE_BUDGET}", + exported_root.root + ); + for output in &exported_root.outputs { + let package: Json2 = serde_json::from_slice( + &std::fs::read( + bundle + .join(&output.package.directory) + .join("package.json") + .as_std_path(), + ) + .expect("package.json"), + ) + .expect("package JSON"); + assert_eq!( + package["program"], + serde_json::to_value(&low.program).expect("a program is JSON"), + "{member}: the exported package realizes the program the differential ran" + ); + realized += 1; + } + } + assert_eq!(realized, ROOTS.len(), "one certified package per root"); + let packages = harness::tree(&bundle.join("packages")); + let committed_packages = harness::tree(&harness::fixture_dir("bootstrap").join("packages")); + assert_eq!( + packages.keys().collect::>(), + committed_packages.keys().collect::>(), + "the exported package files are the committed ones" + ); + for (relative, content) in &packages { + assert!( + committed_packages.get(relative) == Some(content), + "packages/{relative} differs from the committed package" + ); + } +} + +pub(super) fn case() { + let started = std::time::Instant::now(); + let project = support::P::bootstrap(); + let checked_units = project.check_ok(); + assert!( + checked_units.units.contains_key("SemanticModels"), + "SemanticModels is a linked module of the project" + ); + eligibility_of(&project, "SemanticModels", MODULE, &ROOTS); + + let examples: Vec = (0..EXAMPLES).map(example_model_declaration).collect(); + let distinct: BTreeSet = examples.iter().map(canonical).collect(); + let corpus = committed(); + assert!( + corpus.len() >= 20, + "the committed semantic modules carry {} distinct model-family declarations", + corpus.len() + ); + let normative = support::normative_host(); + let (evaluator_seeded, rustc_seeded) = if normative { + ( + seeded_examples(EVALUATOR_SEEDED, 0x0B55_0071), + seeded_examples(RUSTC_SEEDED, 0x0B55_1071), + ) + } else { + (Vec::new(), Vec::new()) + }; + eprintln!( + "BS-71: {} examples ({} distinct), {} committed declarations, {} and {} seeded examples ({:?})", + examples.len(), + distinct.len(), + corpus.len(), + EVALUATOR_SEEDED, + RUSTC_SEEDED, + started.elapsed() + ); + + let checked = support::checked_project(&project); + let lowered: BTreeMap<&str, super::Lowered> = ROOTS + .iter() + .map(|(root, _)| (*root, super::lower(&checked, &project, MODULE, root))) + .collect(); + let root = ROOTS[0].0; + if normative { + let mut runs: Vec = examples.iter().map(run).collect(); + runs.extend(corpus.iter().map(run)); + runs.extend(evaluator_seeded.iter().map(run)); + let disagreements = super::evaluate(&lowered[root], &runs, 5); + assert!( + disagreements.is_empty(), + "{root} and the Rust oracle disagree: {disagreements:?}" + ); + eprintln!( + "BS-71: {root}: the evaluator agrees on {} runs ({:?})", + runs.len(), + started.elapsed() + ); + let planted = plants(&examples); + eprintln!( + "BS-71: {planted} planted defects detected ({:?})", + started.elapsed() + ); + } else { + eprintln!("BS-71: platform-bound host: the evaluator, the seeded runs, and the planted defects run on the normative host"); + } + + let mut compiled: Vec = examples.iter().map(run).collect(); + compiled.extend(corpus.iter().map(run)); + compiled.extend(rustc_seeded.iter().map(run)); + let total = rustc_differential( + "BS-71", + &[(root, &lowered[root], compiled.as_slice())], + "oracle", + ); + eprintln!("BS-71: {total} rustc runs agree ({:?})", started.elapsed()); + + if !support::lean_backed("BS-71") { + return; + } + export(&lowered); + eprintln!("BS-71: passed in {:?}", started.elapsed()); +} diff --git a/crates/conformance/src/cases/repository.rs b/crates/conformance/src/cases/repository.rs index 2558dcb523..584bca732e 100644 --- a/crates/conformance/src/cases/repository.rs +++ b/crates/conformance/src/cases/repository.rs @@ -898,7 +898,7 @@ pub(crate) fn run(id: &str) { let model = repo_model::Model::load(&root.join("model").into_std_path_buf()) .expect("the model loads"); let table = spec_table(); - assert_eq!(table.len(), 499, "§31 has 499 rows"); + assert_eq!(table.len(), 500, "§31 has 500 rows"); assert_eq!(model.ids.id.len(), table.len(), "register row count"); for ((spec_id, spec_suite, spec_statement), row) in table.iter().zip(model.ids.id.iter()) diff --git a/crates/conformance/tests/conformance.rs b/crates/conformance/tests/conformance.rs index dae74592b5..f9080559c5 100644 --- a/crates/conformance/tests/conformance.rs +++ b/crates/conformance/tests/conformance.rs @@ -2425,6 +2425,11 @@ fn conformance_bs_70() { repo_conformance::cases::run("BS-70"); } +#[test] +fn conformance_bs_71() { + repo_conformance::cases::run("BS-71"); +} + #[test] fn conformance_pk_01() { repo_conformance::cases::run("PK-01"); diff --git a/features/suites/bootstrap.feature b/features/suites/bootstrap.feature index 0366dae2f3..f3e0006be9 100644 --- a/features/suites/bootstrap.feature +++ b/features/suites/bootstrap.feature @@ -244,3 +244,9 @@ Feature: bootstrap When the project is checked and built, and the lowered program and the rendered package of each root are run on those inputs Then each root is eligible for rust-std with exactly its declared effects, no certificate part is beyond 3,145,728 bytes, and the two roots equal the canonical JSON of the serde form of `SemanticDeclaration` and `SemanticModule` on every run And every planted defect is detected by its own vector, and the exported packages are byte-identical to the committed packages and realize the programs the differential ran + @BS-71 @build + Scenario: The declarations of artifacts, contracts, realizations, evidence, and models of the semantic module language of SPEC.md §17.12 (those variants of `ir::semantic::SemanticDeclaration`, with the artifact roles and schemas, binders, states, validators, uses, rules, the deterministic, rule, statistical, neural, and composite realization descriptors with their layers, decoders, forms, and junctions, and the evidence claims they hold, in the serde form the linked IR embeds, written as canonical JSON: each tagged variant by its `kind`, each closed name as the oracle serializes it, and each optional member left out exactly where the oracle's serde attributes skip it) is language-1.2 source in the `bootstrap/` project, as the production root `modelDeclarationText` of `SemanticModels` over `SemanticTerms` and `SemanticTypes`, generated with the case's encoders and examples from one description of the oracle's types, eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and with no part of its certificate beyond 3,145,728 bytes; its rendered `rust-std` package under the pinned rustc, and on the normative host its lowered program under the calculus evaluator, agree with the oracle to the byte on examples that reach every variant, every optional member present and absent, and every list empty and not, on every distinct such declaration of every committed semantic module that links, and on seeded examples; each planted defect, a misspelled kind or name, is detected by the first example that holds it, and the certified packages the production export publishes for the project are the committed ones; reading declarations from JSON is outside the claim. + Given the committed `bootstrap` project, examples that reach every variant and every optional member, every model-family declaration of the committed semantic modules that link, and seeded examples + When the project is checked and built, and the lowered program and the rendered package of the root are run on those declarations + Then the root is eligible for rust-std with exactly its declared effects, no certificate part is beyond 3,145,728 bytes, and the root equals the canonical JSON of the serde form of the declaration on every run + And every planted defect is detected by the first example that holds it, and the exported packages are byte-identical to the committed packages and realize the programs the differential ran diff --git a/model/ids.toml b/model/ids.toml index c34499db90..69730e3a23 100644 --- a/model/ids.toml +++ b/model/ids.toml @@ -2912,6 +2912,12 @@ level = "build" suite = "bootstrap" statement = "The ordinary declarations of the semantic module language of SPEC.md §17.11 and §17.12 and the module that holds them (`ir::semantic::SemanticDeclaration` for structures, classes, instances, inductives, definitions, and theorems, and `SemanticModule`, in the serde form the linked IR embeds, written as canonical JSON: each declaration tagged by its `kind`, its parameters, fields, constructors, and assignments in order, and a definition's or a theorem's type parameters, recursive argument, axioms, executable flag, mutual group, termination, and production, and an inductive's mutual group, left out exactly where the oracle's serde attributes skip them; and a module's specification and declarations in order) is language-1.2 source in the `bootstrap/` project, as two production roots of `SemanticDecls` over `SemanticTerms` and `SemanticTypes`: `declarationText` and `moduleText`, each eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator on the shorter modules, agree with the oracle to the byte on hand-built declarations, which reach every kind and every optional member both present and absent, on every distinct ordinary declaration of every committed semantic module that links and on every such module whose declarations are all ordinary, among them every module of the `bootstrap/` project and the standard library, and on seeded declarations; each planted defect in the source is detected by the root and the one vector it names, and the certified packages the production export publishes for the project are the committed ones; the declarations of models, reasoning, and text components, and reading declarations from JSON, are outside the claim." +[[id]] +id = "BS-71" +level = "build" +suite = "bootstrap" +statement = "The declarations of artifacts, contracts, realizations, evidence, and models of the semantic module language of SPEC.md §17.12 (those variants of `ir::semantic::SemanticDeclaration`, with the artifact roles and schemas, binders, states, validators, uses, rules, the deterministic, rule, statistical, neural, and composite realization descriptors with their layers, decoders, forms, and junctions, and the evidence claims they hold, in the serde form the linked IR embeds, written as canonical JSON: each tagged variant by its `kind`, each closed name as the oracle serializes it, and each optional member left out exactly where the oracle's serde attributes skip it) is language-1.2 source in the `bootstrap/` project, as the production root `modelDeclarationText` of `SemanticModels` over `SemanticTerms` and `SemanticTypes`, generated with the case's encoders and examples from one description of the oracle's types, eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and with no part of its certificate beyond 3,145,728 bytes; its rendered `rust-std` package under the pinned rustc, and on the normative host its lowered program under the calculus evaluator, agree with the oracle to the byte on examples that reach every variant, every optional member present and absent, and every list empty and not, on every distinct such declaration of every committed semantic module that links, and on seeded examples; each planted defect, a misspelled kind or name, is detected by the first example that holds it, and the certified packages the production export publishes for the project are the committed ones; reading declarations from JSON is outside the claim." + [[id]] id = "PK-01" level = "build" diff --git a/tests/production-export/bootstrap/roots.json b/tests/production-export/bootstrap/roots.json index 4e15b36638..4689a2d9bb 100644 --- a/tests/production-export/bootstrap/roots.json +++ b/tests/production-export/bootstrap/roots.json @@ -647,6 +647,14 @@ "rust-std" ], "version": "1.0.0" + }, + { + "name": "model_declaration_text", + "root": "LexLeanBoot.SemanticModels.modelDeclarationText", + "targets": [ + "rust-std" + ], + "version": "1.0.0" } ] } diff --git a/xtask/src/spec_links.rs b/xtask/src/spec_links.rs index 01b9b3a3e5..40df6926ea 100644 --- a/xtask/src/spec_links.rs +++ b/xtask/src/spec_links.rs @@ -61,8 +61,8 @@ fn parse_table(spec: &str) -> Result, Fail> { pub fn validate(root: &Path) -> Result<(), Fail> { let spec = std::fs::read_to_string(root.join("SPEC.md"))?; let rows = parse_table(&spec)?; - if rows.len() != 499 { - return Err(format!("RP-07: the §31 table has {} rows, not 499", rows.len()).into()); + if rows.len() != 500 { + return Err(format!("RP-07: the §31 table has {} rows, not 500", rows.len()).into()); } // The prose total under the table is part of the contract a reader // relies on; a row added without it would leave §31 contradicting itself. From f143d674311da73d3bbb77ef444cc2a419da8162 Mon Sep 17 00:00:00 2001 From: humuhumu33 Date: Thu, 12 Nov 2026 15:22:57 +0000 Subject: [PATCH 2/6] BS-71: the generated encoders and examples compile Co-Authored-By: Claude Opus 5.5 --- .../src/cases/bootstrap/semantic_models.rs | 168 +++++++++--------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/crates/conformance/src/cases/bootstrap/semantic_models.rs b/crates/conformance/src/cases/bootstrap/semantic_models.rs index 8961e2eda9..caec33e168 100755 --- a/crates/conformance/src/cases/bootstrap/semantic_models.rs +++ b/crates/conformance/src/cases/bootstrap/semantic_models.rs @@ -120,7 +120,7 @@ fn enc_member(member: &MemberRef) -> Value { // ------------------------------------------- generated from the type schema -fn enc_artifact_role(value: &ArtifactRole) -> Value { +pub(super) fn enc_artifact_role(value: &ArtifactRole) -> Value { adt( "ArtifactRole", &format!("ArtifactRole{value:?}"), @@ -128,7 +128,7 @@ fn enc_artifact_role(value: &ArtifactRole) -> Value { ) } -const ALL_ARTIFACT_ROLE: &[ArtifactRole] = &[ +pub(super) const ALL_ARTIFACT_ROLE: &[ArtifactRole] = &[ ArtifactRole::Parameters, ArtifactRole::Vocabulary, ArtifactRole::Dataset, @@ -136,11 +136,11 @@ const ALL_ARTIFACT_ROLE: &[ArtifactRole] = &[ ArtifactRole::Binary, ]; -fn example_artifact_role(step: usize) -> ArtifactRole { +pub(super) fn example_artifact_role(step: usize) -> ArtifactRole { ALL_ARTIFACT_ROLE[step % ALL_ARTIFACT_ROLE.len()] } -fn enc_tensor_element(value: &TensorElement) -> Value { +pub(super) fn enc_tensor_element(value: &TensorElement) -> Value { adt( "TensorElement", &format!("TensorElement{value:?}"), @@ -148,7 +148,7 @@ fn enc_tensor_element(value: &TensorElement) -> Value { ) } -const ALL_TENSOR_ELEMENT: &[TensorElement] = &[ +pub(super) const ALL_TENSOR_ELEMENT: &[TensorElement] = &[ TensorElement::Int8, TensorElement::Int16, TensorElement::Int32, @@ -159,11 +159,11 @@ const ALL_TENSOR_ELEMENT: &[TensorElement] = &[ TensorElement::UInt64, ]; -fn example_tensor_element(step: usize) -> TensorElement { +pub(super) fn example_tensor_element(step: usize) -> TensorElement { ALL_TENSOR_ELEMENT[step % ALL_TENSOR_ELEMENT.len()] } -fn enc_artifact_schema(value: &ArtifactSchema) -> Value { +pub(super) fn enc_artifact_schema(value: &ArtifactSchema) -> Value { match value { ArtifactSchema::Bytes => adt("ArtifactSchema", "ArtifactSchemaBytes", vec![]), ArtifactSchema::IntTensor { element, shape } => adt( @@ -179,7 +179,7 @@ fn enc_artifact_schema(value: &ArtifactSchema) -> Value { } #[allow(clippy::too_many_lines)] -fn example_artifact_schema(step: usize) -> ArtifactSchema { +pub(super) fn example_artifact_schema(step: usize) -> ArtifactSchema { let rest = step / 3; match step % 3 { 0 => ArtifactSchema::Bytes, @@ -189,7 +189,7 @@ fn example_artifact_schema(step: usize) -> ArtifactSchema { Vec::new() } else { (rest..rest + 2) - .map(|next| u64::try_from(next).expect("a rest") + 1) + .map(|next| u64::try_from(next).expect("a step") + 1) .collect() }, }, @@ -197,15 +197,15 @@ fn example_artifact_schema(step: usize) -> ArtifactSchema { } } -fn enc_model_binder(value: &ModelBinder) -> Value { +pub(super) fn enc_model_binder(value: &ModelBinder) -> Value { adt( "ModelBinder", "ModelBinderOf", - vec![text(&value.name), enc_type(&value.r#type)], + vec![text((&value.name)), enc_type((&value.r#type))], ) } -fn example_model_binder(step: usize) -> ModelBinder { +pub(super) fn example_model_binder(step: usize) -> ModelBinder { ModelBinder { name: format!("s{step}"), r#type: if step % 2 == 0 { @@ -216,19 +216,19 @@ fn example_model_binder(step: usize) -> ModelBinder { } } -fn enc_contract_state(value: &ContractState) -> Value { +pub(super) fn enc_contract_state(value: &ContractState) -> Value { adt( "ContractState", "ContractStateOf", vec![ - text(&value.name), - text(&value.next), - enc_type(&value.r#type), + text((&value.name)), + text((&value.next)), + enc_type((&value.r#type)), ], ) } -fn example_contract_state(step: usize) -> ContractState { +pub(super) fn example_contract_state(step: usize) -> ContractState { ContractState { name: format!("s{step}"), next: format!("s{step}"), @@ -240,7 +240,7 @@ fn example_contract_state(step: usize) -> ContractState { } } -fn enc_contract_predicate(value: &ContractPredicate) -> Value { +pub(super) fn enc_contract_predicate(value: &ContractPredicate) -> Value { adt( "ContractPredicate", &format!("ContractPredicate{value:?}"), @@ -248,30 +248,30 @@ fn enc_contract_predicate(value: &ContractPredicate) -> Value { ) } -const ALL_CONTRACT_PREDICATE: &[ContractPredicate] = &[ +pub(super) const ALL_CONTRACT_PREDICATE: &[ContractPredicate] = &[ ContractPredicate::Invariant, ContractPredicate::Postcondition, ContractPredicate::Precondition, ]; -fn example_contract_predicate(step: usize) -> ContractPredicate { +pub(super) fn example_contract_predicate(step: usize) -> ContractPredicate { ALL_CONTRACT_PREDICATE[step % ALL_CONTRACT_PREDICATE.len()] } -fn enc_contract_validator(value: &ContractValidator) -> Value { +pub(super) fn enc_contract_validator(value: &ContractValidator) -> Value { adt( "ContractValidator", "ContractValidatorOf", vec![ - enc_contract_predicate(&value.predicate), - enc_member(&value.validator), - enc_member(&value.sound), - option(&value.complete.as_ref().map(|item| enc_member(item))), + enc_contract_predicate((&value.predicate)), + enc_member((&value.validator)), + enc_member((&value.sound)), + option((&value.complete).as_ref().map(|item| enc_member(item))), ], ) } -fn example_contract_validator(step: usize) -> ContractValidator { +pub(super) fn example_contract_validator(step: usize) -> ContractValidator { ContractValidator { predicate: example_contract_predicate(step), validator: MemberRef { @@ -289,15 +289,14 @@ fn example_contract_validator(step: usize) -> ContractValidator { } } -fn enc_model_use(value: &ModelUse) -> Value { +pub(super) fn enc_model_use(value: &ModelUse) -> Value { adt( "ModelUse", "ModelUseOf", vec![ - enc_member(&value.member), + enc_member((&value.member)), list( - &value - .type_arguments + (&value.type_arguments) .iter() .map(|item| enc_type(item)) .collect(), @@ -306,7 +305,7 @@ fn enc_model_use(value: &ModelUse) -> Value { ) } -fn example_model_use(step: usize) -> ModelUse { +pub(super) fn example_model_use(step: usize) -> ModelUse { ModelUse { member: MemberRef { module: (step % 2 == 0).then(|| "M".to_owned()), @@ -317,7 +316,7 @@ fn example_model_use(step: usize) -> ModelUse { } else { (step..step + 2) .map(|next| { - if step % 2 == 0 { + if next % 2 == 0 { SemanticType::Nat } else { SemanticType::Bytes @@ -328,19 +327,19 @@ fn example_model_use(step: usize) -> ModelUse { } } -fn enc_realization_state(value: &RealizationState) -> Value { +pub(super) fn enc_realization_state(value: &RealizationState) -> Value { adt( "RealizationState", "RealizationStateOf", vec![ - text(&value.name), - enc_type(&value.r#type), - enc_term(&value.initial), + text((&value.name)), + enc_type((&value.r#type)), + enc_term((&value.initial)), ], ) } -fn example_realization_state(step: usize) -> RealizationState { +pub(super) fn example_realization_state(step: usize) -> RealizationState { RealizationState { name: format!("s{step}"), r#type: if step % 2 == 0 { @@ -354,19 +353,19 @@ fn example_realization_state(step: usize) -> RealizationState { } } -fn enc_realization_rule(value: &RealizationRule) -> Value { +pub(super) fn enc_realization_rule(value: &RealizationRule) -> Value { adt( "RealizationRule", "RealizationRuleOf", vec![ - text(&value.name), - enc_term(&value.guard), - enc_term(&value.action), + text((&value.name)), + enc_term((&value.guard)), + enc_term((&value.action)), ], ) } -fn example_realization_rule(step: usize) -> RealizationRule { +pub(super) fn example_realization_rule(step: usize) -> RealizationRule { RealizationRule { name: format!("s{step}"), guard: SemanticTerm::Nat { @@ -378,7 +377,7 @@ fn example_realization_rule(step: usize) -> RealizationRule { } } -fn enc_statistical_scheme(value: &StatisticalScheme) -> Value { +pub(super) fn enc_statistical_scheme(value: &StatisticalScheme) -> Value { adt( "StatisticalScheme", &format!("StatisticalScheme{value:?}"), @@ -386,13 +385,13 @@ fn enc_statistical_scheme(value: &StatisticalScheme) -> Value { ) } -const ALL_STATISTICAL_SCHEME: &[StatisticalScheme] = &[StatisticalScheme::LinearScoring]; +pub(super) const ALL_STATISTICAL_SCHEME: &[StatisticalScheme] = &[StatisticalScheme::LinearScoring]; -fn example_statistical_scheme(step: usize) -> StatisticalScheme { +pub(super) fn example_statistical_scheme(step: usize) -> StatisticalScheme { ALL_STATISTICAL_SCHEME[step % ALL_STATISTICAL_SCHEME.len()] } -fn enc_neural_architecture(value: &NeuralArchitecture) -> Value { +pub(super) fn enc_neural_architecture(value: &NeuralArchitecture) -> Value { adt( "NeuralArchitecture", &format!("NeuralArchitecture{value:?}"), @@ -400,13 +399,14 @@ fn enc_neural_architecture(value: &NeuralArchitecture) -> Value { ) } -const ALL_NEURAL_ARCHITECTURE: &[NeuralArchitecture] = &[NeuralArchitecture::IntegerFeedforward]; +pub(super) const ALL_NEURAL_ARCHITECTURE: &[NeuralArchitecture] = + &[NeuralArchitecture::IntegerFeedforward]; -fn example_neural_architecture(step: usize) -> NeuralArchitecture { +pub(super) fn example_neural_architecture(step: usize) -> NeuralArchitecture { ALL_NEURAL_ARCHITECTURE[step % ALL_NEURAL_ARCHITECTURE.len()] } -fn enc_neural_layer(value: &NeuralLayer) -> Value { +pub(super) fn enc_neural_layer(value: &NeuralLayer) -> Value { match value { NeuralLayer::Dense { inputs, @@ -437,12 +437,12 @@ fn enc_neural_layer(value: &NeuralLayer) -> Value { } #[allow(clippy::too_many_lines)] -fn example_neural_layer(step: usize) -> NeuralLayer { +pub(super) fn example_neural_layer(step: usize) -> NeuralLayer { let rest = step / 3; match step % 3 { 0 => NeuralLayer::Dense { - inputs: u64::try_from(rest).expect("a rest") + 1, - outputs: u64::try_from(rest).expect("a rest") + 1, + inputs: u64::try_from(rest).expect("a step") + 1, + outputs: u64::try_from(rest).expect("a step") + 1, weights: MemberRef { module: (rest % 2 == 0).then(|| "M".to_owned()), name: format!("m{rest}"), @@ -454,14 +454,14 @@ fn example_neural_layer(step: usize) -> NeuralLayer { }, 1 => NeuralLayer::Relu, _ => NeuralLayer::Requantize { - shift: u64::try_from(rest).expect("a rest") + 1, + shift: u64::try_from(rest).expect("a step") + 1, minimum: format!("s{rest}"), maximum: format!("s{rest}"), }, } } -fn enc_neural_decoder(value: &NeuralDecoder) -> Value { +pub(super) fn enc_neural_decoder(value: &NeuralDecoder) -> Value { match value { NeuralDecoder::Argmax { labels } => adt( "NeuralDecoder", @@ -477,7 +477,7 @@ fn enc_neural_decoder(value: &NeuralDecoder) -> Value { } #[allow(clippy::too_many_lines)] -fn example_neural_decoder(step: usize) -> NeuralDecoder { +pub(super) fn example_neural_decoder(step: usize) -> NeuralDecoder { let rest = step / 2; match step % 2 { 0 => NeuralDecoder::Argmax { @@ -486,7 +486,7 @@ fn example_neural_decoder(step: usize) -> NeuralDecoder { } else { (rest..rest + 2) .map(|next| SemanticTerm::Nat { - value: rest.to_string(), + value: next.to_string(), }) .collect() }, @@ -500,7 +500,7 @@ fn example_neural_decoder(step: usize) -> NeuralDecoder { } } -fn enc_composite_junction(value: &CompositeJunction) -> Value { +pub(super) fn enc_composite_junction(value: &CompositeJunction) -> Value { match value { CompositeJunction::Unconditional => adt( "CompositeJunction", @@ -517,7 +517,7 @@ fn enc_composite_junction(value: &CompositeJunction) -> Value { } #[allow(clippy::too_many_lines)] -fn example_composite_junction(step: usize) -> CompositeJunction { +pub(super) fn example_composite_junction(step: usize) -> CompositeJunction { let rest = step / 3; match step % 3 { 0 => CompositeJunction::Unconditional, @@ -531,7 +531,7 @@ fn example_composite_junction(step: usize) -> CompositeJunction { } } -fn enc_composite_form(value: &CompositeForm) -> Value { +pub(super) fn enc_composite_form(value: &CompositeForm) -> Value { match value { CompositeForm::Sequence { stages, junctions } => adt( "CompositeForm", @@ -574,7 +574,7 @@ fn enc_composite_form(value: &CompositeForm) -> Value { } #[allow(clippy::too_many_lines)] -fn example_composite_form(step: usize) -> CompositeForm { +pub(super) fn example_composite_form(step: usize) -> CompositeForm { let rest = step / 5; match step % 5 { 0 => CompositeForm::Sequence { @@ -615,7 +615,7 @@ fn example_composite_form(step: usize) -> CompositeForm { } } -fn enc_realization_descriptor(value: &RealizationDescriptor) -> Value { +pub(super) fn enc_realization_descriptor(value: &RealizationDescriptor) -> Value { match value { RealizationDescriptor::Deterministic { body } => adt( "RealizationDescriptor", @@ -684,7 +684,7 @@ fn enc_realization_descriptor(value: &RealizationDescriptor) -> Value { } #[allow(clippy::too_many_lines)] -fn example_realization_descriptor(step: usize) -> RealizationDescriptor { +pub(super) fn example_realization_descriptor(step: usize) -> RealizationDescriptor { let rest = step / 5; match step % 5 { 0 => RealizationDescriptor::Deterministic { @@ -709,7 +709,7 @@ fn example_realization_descriptor(step: usize) -> RealizationDescriptor { features: SemanticTerm::Nat { value: rest.to_string(), }, - width: u64::try_from(rest).expect("a rest") + 1, + width: u64::try_from(rest).expect("a step") + 1, width_evidence: MemberRef { module: (rest % 2 == 0).then(|| "M".to_owned()), name: format!("m{rest}"), @@ -727,7 +727,7 @@ fn example_realization_descriptor(step: usize) -> RealizationDescriptor { } else { (rest..rest + 2) .map(|next| SemanticTerm::Nat { - value: rest.to_string(), + value: next.to_string(), }) .collect() }, @@ -737,7 +737,7 @@ fn example_realization_descriptor(step: usize) -> RealizationDescriptor { encoder: SemanticTerm::Nat { value: rest.to_string(), }, - width: u64::try_from(rest).expect("a rest") + 1, + width: u64::try_from(rest).expect("a step") + 1, width_evidence: MemberRef { module: (rest % 2 == 0).then(|| "M".to_owned()), name: format!("m{rest}"), @@ -757,7 +757,7 @@ fn example_realization_descriptor(step: usize) -> RealizationDescriptor { } } -fn enc_evidence_claim(value: &EvidenceClaim) -> Value { +pub(super) fn enc_evidence_claim(value: &EvidenceClaim) -> Value { match value { EvidenceClaim::DatasetAgreement { dataset, @@ -802,7 +802,7 @@ fn enc_evidence_claim(value: &EvidenceClaim) -> Value { } #[allow(clippy::too_many_lines)] -fn example_evidence_claim(step: usize) -> EvidenceClaim { +pub(super) fn example_evidence_claim(step: usize) -> EvidenceClaim { let rest = step / 5; match step % 5 { 0 => EvidenceClaim::DatasetAgreement { @@ -818,8 +818,8 @@ fn example_evidence_claim(step: usize) -> EvidenceClaim { module: (rest % 2 == 0).then(|| "M".to_owned()), name: format!("m{rest}"), }, - examples: u64::try_from(rest).expect("a rest") + 1, - agreements: u64::try_from(rest).expect("a rest") + 1, + examples: u64::try_from(rest).expect("a step") + 1, + agreements: u64::try_from(rest).expect("a step") + 1, theorem: MemberRef { module: (rest % 2 == 0).then(|| "M".to_owned()), name: format!("m{rest}"), @@ -853,7 +853,7 @@ fn example_evidence_claim(step: usize) -> EvidenceClaim { } } -fn enc_model_declaration(value: &SemanticDeclaration) -> Value { +pub(super) fn enc_model_declaration(value: &SemanticDeclaration) -> Value { match value { SemanticDeclaration::Artifact { name, @@ -976,14 +976,14 @@ fn enc_model_declaration(value: &SemanticDeclaration) -> Value { } #[allow(clippy::too_many_lines)] -fn example_model_declaration(step: usize) -> SemanticDeclaration { +pub(super) fn example_model_declaration(step: usize) -> SemanticDeclaration { let rest = step / 5; match step % 5 { 0 => SemanticDeclaration::Artifact { name: format!("s{rest}"), role: example_artifact_role(rest), sha256: format!("s{rest}"), - length: u64::try_from(rest).expect("a rest") + 1, + length: u64::try_from(rest).expect("a step") + 1, schema: example_artifact_schema(rest), r#type: if rest % 2 == 0 { SemanticType::Nat @@ -993,7 +993,7 @@ fn example_model_declaration(step: usize) -> SemanticDeclaration { axioms: if rest % 3 == 2 { Vec::new() } else { - (rest..rest + 2).map(|next| format!("s{rest}")).collect() + (rest..rest + 2).map(|next| format!("s{next}")).collect() }, }, 1 => SemanticDeclaration::Contract { @@ -1001,7 +1001,7 @@ fn example_model_declaration(step: usize) -> SemanticDeclaration { type_parameters: if rest % 3 == 2 { Vec::new() } else { - (rest..rest + 2).map(|next| format!("s{rest}")).collect() + (rest..rest + 2).map(|next| format!("s{next}")).collect() }, input: example_model_binder(rest), output: example_model_binder(rest), @@ -1028,7 +1028,7 @@ fn example_model_declaration(step: usize) -> SemanticDeclaration { axioms: if rest % 3 == 2 { Vec::new() } else { - (rest..rest + 2).map(|next| format!("s{rest}")).collect() + (rest..rest + 2).map(|next| format!("s{next}")).collect() }, }, 2 => SemanticDeclaration::Realization { @@ -1036,7 +1036,7 @@ fn example_model_declaration(step: usize) -> SemanticDeclaration { type_parameters: if rest % 3 == 2 { Vec::new() } else { - (rest..rest + 2).map(|next| format!("s{rest}")).collect() + (rest..rest + 2).map(|next| format!("s{next}")).collect() }, input: example_model_binder(rest), output: if rest % 2 == 0 { @@ -1050,7 +1050,7 @@ fn example_model_declaration(step: usize) -> SemanticDeclaration { axioms: if rest % 3 == 2 { Vec::new() } else { - (rest..rest + 2).map(|next| format!("s{rest}")).collect() + (rest..rest + 2).map(|next| format!("s{next}")).collect() }, }, 3 => SemanticDeclaration::Evidence { @@ -1058,7 +1058,7 @@ fn example_model_declaration(step: usize) -> SemanticDeclaration { type_parameters: if rest % 3 == 2 { Vec::new() } else { - (rest..rest + 2).map(|next| format!("s{rest}")).collect() + (rest..rest + 2).map(|next| format!("s{next}")).collect() }, contract: example_model_use(rest), realization: example_model_use(rest), @@ -1072,7 +1072,7 @@ fn example_model_declaration(step: usize) -> SemanticDeclaration { axioms: if rest % 3 == 2 { Vec::new() } else { - (rest..rest + 2).map(|next| format!("s{rest}")).collect() + (rest..rest + 2).map(|next| format!("s{next}")).collect() }, }, _ => SemanticDeclaration::Model { @@ -1080,7 +1080,7 @@ fn example_model_declaration(step: usize) -> SemanticDeclaration { type_parameters: if rest % 3 == 2 { Vec::new() } else { - (rest..rest + 2).map(|next| format!("s{rest}")).collect() + (rest..rest + 2).map(|next| format!("s{next}")).collect() }, contract: example_model_use(rest), realization: example_model_use(rest), @@ -1096,15 +1096,15 @@ fn example_model_declaration(step: usize) -> SemanticDeclaration { } else { (rest..rest + 2) .map(|next| MemberRef { - module: (rest % 2 == 0).then(|| "M".to_owned()), - name: format!("m{rest}"), + module: (next % 2 == 0).then(|| "M".to_owned()), + name: format!("m{next}"), }) .collect() }, axioms: if rest % 3 == 2 { Vec::new() } else { - (rest..rest + 2).map(|next| format!("s{rest}")).collect() + (rest..rest + 2).map(|next| format!("s{next}")).collect() }, }, } @@ -1147,7 +1147,7 @@ const KINDS: &[&str] = &[ // ------------------------------------------------------------- the inputs -fn is_model(declaration: &SemanticDeclaration) -> bool { +pub(super) fn is_model(declaration: &SemanticDeclaration) -> bool { matches!( declaration, SemanticDeclaration::Artifact { .. } From 0ea3933d62f0cc0f7de25a3a8ee38ea5445833a0 Mon Sep 17 00:00:00 2001 From: humuhumu33 Date: Thu, 12 Nov 2026 15:48:53 +0000 Subject: [PATCH 3/6] BS-71: the generated encoders and examples pass clippy Co-Authored-By: Claude Opus 5.5 --- .../src/cases/bootstrap/semantic_models.rs | 142 ++++++++---------- 1 file changed, 61 insertions(+), 81 deletions(-) diff --git a/crates/conformance/src/cases/bootstrap/semantic_models.rs b/crates/conformance/src/cases/bootstrap/semantic_models.rs index caec33e168..4f627a91f7 100755 --- a/crates/conformance/src/cases/bootstrap/semantic_models.rs +++ b/crates/conformance/src/cases/bootstrap/semantic_models.rs @@ -201,14 +201,14 @@ pub(super) fn enc_model_binder(value: &ModelBinder) -> Value { adt( "ModelBinder", "ModelBinderOf", - vec![text((&value.name)), enc_type((&value.r#type))], + vec![text(&value.name), enc_type(&value.r#type)], ) } pub(super) fn example_model_binder(step: usize) -> ModelBinder { ModelBinder { name: format!("s{step}"), - r#type: if step % 2 == 0 { + r#type: if step.is_multiple_of(2) { SemanticType::Nat } else { SemanticType::Bytes @@ -221,9 +221,9 @@ pub(super) fn enc_contract_state(value: &ContractState) -> Value { "ContractState", "ContractStateOf", vec![ - text((&value.name)), - text((&value.next)), - enc_type((&value.r#type)), + text(&value.name), + text(&value.next), + enc_type(&value.r#type), ], ) } @@ -232,7 +232,7 @@ pub(super) fn example_contract_state(step: usize) -> ContractState { ContractState { name: format!("s{step}"), next: format!("s{step}"), - r#type: if step % 2 == 0 { + r#type: if step.is_multiple_of(2) { SemanticType::Nat } else { SemanticType::Bytes @@ -263,10 +263,10 @@ pub(super) fn enc_contract_validator(value: &ContractValidator) -> Value { "ContractValidator", "ContractValidatorOf", vec![ - enc_contract_predicate((&value.predicate)), - enc_member((&value.validator)), - enc_member((&value.sound)), - option((&value.complete).as_ref().map(|item| enc_member(item))), + enc_contract_predicate(&value.predicate), + enc_member(&value.validator), + enc_member(&value.sound), + option(value.complete.as_ref().map(enc_member)), ], ) } @@ -275,15 +275,15 @@ pub(super) fn example_contract_validator(step: usize) -> ContractValidator { ContractValidator { predicate: example_contract_predicate(step), validator: MemberRef { - module: (step % 2 == 0).then(|| "M".to_owned()), + module: step.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{step}"), }, sound: MemberRef { - module: (step % 2 == 0).then(|| "M".to_owned()), + module: step.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{step}"), }, complete: (step % 3 != 2).then(|| MemberRef { - module: (step % 2 == 0).then(|| "M".to_owned()), + module: step.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{step}"), }), } @@ -294,13 +294,8 @@ pub(super) fn enc_model_use(value: &ModelUse) -> Value { "ModelUse", "ModelUseOf", vec![ - enc_member((&value.member)), - list( - (&value.type_arguments) - .iter() - .map(|item| enc_type(item)) - .collect(), - ), + enc_member(&value.member), + list(value.type_arguments.iter().map(enc_type).collect()), ], ) } @@ -308,7 +303,7 @@ pub(super) fn enc_model_use(value: &ModelUse) -> Value { pub(super) fn example_model_use(step: usize) -> ModelUse { ModelUse { member: MemberRef { - module: (step % 2 == 0).then(|| "M".to_owned()), + module: step.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{step}"), }, type_arguments: if step % 3 == 2 { @@ -316,7 +311,7 @@ pub(super) fn example_model_use(step: usize) -> ModelUse { } else { (step..step + 2) .map(|next| { - if next % 2 == 0 { + if next.is_multiple_of(2) { SemanticType::Nat } else { SemanticType::Bytes @@ -332,9 +327,9 @@ pub(super) fn enc_realization_state(value: &RealizationState) -> Value { "RealizationState", "RealizationStateOf", vec![ - text((&value.name)), - enc_type((&value.r#type)), - enc_term((&value.initial)), + text(&value.name), + enc_type(&value.r#type), + enc_term(&value.initial), ], ) } @@ -342,7 +337,7 @@ pub(super) fn enc_realization_state(value: &RealizationState) -> Value { pub(super) fn example_realization_state(step: usize) -> RealizationState { RealizationState { name: format!("s{step}"), - r#type: if step % 2 == 0 { + r#type: if step.is_multiple_of(2) { SemanticType::Nat } else { SemanticType::Bytes @@ -358,9 +353,9 @@ pub(super) fn enc_realization_rule(value: &RealizationRule) -> Value { "RealizationRule", "RealizationRuleOf", vec![ - text((&value.name)), - enc_term((&value.guard)), - enc_term((&value.action)), + text(&value.name), + enc_term(&value.guard), + enc_term(&value.action), ], ) } @@ -444,11 +439,11 @@ pub(super) fn example_neural_layer(step: usize) -> NeuralLayer { inputs: u64::try_from(rest).expect("a step") + 1, outputs: u64::try_from(rest).expect("a step") + 1, weights: MemberRef { - module: (rest % 2 == 0).then(|| "M".to_owned()), + module: rest.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{rest}"), }, bias: MemberRef { - module: (rest % 2 == 0).then(|| "M".to_owned()), + module: rest.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{rest}"), }, }, @@ -466,7 +461,7 @@ pub(super) fn enc_neural_decoder(value: &NeuralDecoder) -> Value { NeuralDecoder::Argmax { labels } => adt( "NeuralDecoder", "NeuralDecoderArgmax", - vec![list(labels.iter().map(|item| enc_term(item)).collect())], + vec![list(labels.iter().map(enc_term).collect())], ), NeuralDecoder::Function { binder, body } => adt( "NeuralDecoder", @@ -523,7 +518,7 @@ pub(super) fn example_composite_junction(step: usize) -> CompositeJunction { 0 => CompositeJunction::Unconditional, 1 => CompositeJunction::Proved { evidence: MemberRef { - module: (rest % 2 == 0).then(|| "M".to_owned()), + module: rest.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{rest}"), }, }, @@ -537,13 +532,8 @@ pub(super) fn enc_composite_form(value: &CompositeForm) -> Value { "CompositeForm", "CompositeFormSequence", vec![ - list(stages.iter().map(|item| enc_model_use(item)).collect()), - list( - junctions - .iter() - .map(|item| enc_composite_junction(item)) - .collect(), - ), + list(stages.iter().map(enc_model_use).collect()), + list(junctions.iter().map(enc_composite_junction).collect()), ], ), CompositeForm::Fanout { left, right } => adt( @@ -626,12 +616,7 @@ pub(super) fn enc_realization_descriptor(value: &RealizationDescriptor) -> Value "RealizationDescriptor", "RealizationDescriptorRule", vec![ - list( - rules - .iter() - .map(|item| enc_realization_rule(item)) - .collect(), - ), + list(rules.iter().map(enc_realization_rule).collect()), enc_term(default), ], ), @@ -653,7 +638,7 @@ pub(super) fn enc_realization_descriptor(value: &RealizationDescriptor) -> Value enc_member(width_evidence), enc_member(weights), enc_member(bias), - list(labels.iter().map(|item| enc_term(item)).collect()), + list(labels.iter().map(enc_term).collect()), ], ), RealizationDescriptor::Neural { @@ -671,7 +656,7 @@ pub(super) fn enc_realization_descriptor(value: &RealizationDescriptor) -> Value enc_term(encoder), nat(*width), enc_member(width_evidence), - list(layers.iter().map(|item| enc_neural_layer(item)).collect()), + list(layers.iter().map(enc_neural_layer).collect()), enc_neural_decoder(decoder), ], ), @@ -711,15 +696,15 @@ pub(super) fn example_realization_descriptor(step: usize) -> RealizationDescript }, width: u64::try_from(rest).expect("a step") + 1, width_evidence: MemberRef { - module: (rest % 2 == 0).then(|| "M".to_owned()), + module: rest.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{rest}"), }, weights: MemberRef { - module: (rest % 2 == 0).then(|| "M".to_owned()), + module: rest.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{rest}"), }, bias: MemberRef { - module: (rest % 2 == 0).then(|| "M".to_owned()), + module: rest.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{rest}"), }, labels: if rest % 3 == 2 { @@ -739,7 +724,7 @@ pub(super) fn example_realization_descriptor(step: usize) -> RealizationDescript }, width: u64::try_from(rest).expect("a step") + 1, width_evidence: MemberRef { - module: (rest % 2 == 0).then(|| "M".to_owned()), + module: rest.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{rest}"), }, layers: if rest % 3 == 2 { @@ -807,46 +792,46 @@ pub(super) fn example_evidence_claim(step: usize) -> EvidenceClaim { match step % 5 { 0 => EvidenceClaim::DatasetAgreement { dataset: MemberRef { - module: (rest % 2 == 0).then(|| "M".to_owned()), + module: rest.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{rest}"), }, comparison: MemberRef { - module: (rest % 2 == 0).then(|| "M".to_owned()), + module: rest.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{rest}"), }, comparison_sound: MemberRef { - module: (rest % 2 == 0).then(|| "M".to_owned()), + module: rest.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{rest}"), }, examples: u64::try_from(rest).expect("a step") + 1, agreements: u64::try_from(rest).expect("a step") + 1, theorem: MemberRef { - module: (rest % 2 == 0).then(|| "M".to_owned()), + module: rest.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{rest}"), }, }, 1 => EvidenceClaim::EquivalentTo { reference: example_model_use(rest), theorem: MemberRef { - module: (rest % 2 == 0).then(|| "M".to_owned()), + module: rest.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{rest}"), }, }, 2 => EvidenceClaim::InitialInvariant { theorem: MemberRef { - module: (rest % 2 == 0).then(|| "M".to_owned()), + module: rest.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{rest}"), }, }, 3 => EvidenceClaim::PreservesInvariant { theorem: MemberRef { - module: (rest % 2 == 0).then(|| "M".to_owned()), + module: rest.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{rest}"), }, }, _ => EvidenceClaim::SatisfiesContract { theorem: MemberRef { - module: (rest % 2 == 0).then(|| "M".to_owned()), + module: rest.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{rest}"), }, }, @@ -895,16 +880,11 @@ pub(super) fn enc_model_declaration(value: &SemanticDeclaration) -> Value { list(type_parameters.iter().map(|item| text(item)).collect()), enc_model_binder(input), enc_model_binder(output), - option(state.as_ref().map(|item| enc_contract_state(item))), - option(precondition.as_ref().map(|item| enc_member(item))), - option(postcondition.as_ref().map(|item| enc_member(item))), - option(invariant.as_ref().map(|item| enc_member(item))), - list( - validators - .iter() - .map(|item| enc_contract_validator(item)) - .collect(), - ), + option(state.as_ref().map(enc_contract_state)), + option(precondition.as_ref().map(enc_member)), + option(postcondition.as_ref().map(enc_member)), + option(invariant.as_ref().map(enc_member)), + list(validators.iter().map(enc_contract_validator).collect()), list(axioms.iter().map(|item| text(item)).collect()), ], ), @@ -925,7 +905,7 @@ pub(super) fn enc_model_declaration(value: &SemanticDeclaration) -> Value { list(type_parameters.iter().map(|item| text(item)).collect()), enc_model_binder(input), enc_type(output), - option(state.as_ref().map(|item| enc_realization_state(item))), + option(state.as_ref().map(enc_realization_state)), enc_realization_descriptor(descriptor), Value::Bool { value: *executable }, list(axioms.iter().map(|item| text(item)).collect()), @@ -946,7 +926,7 @@ pub(super) fn enc_model_declaration(value: &SemanticDeclaration) -> Value { list(type_parameters.iter().map(|item| text(item)).collect()), enc_model_use(contract), enc_model_use(realization), - list(claims.iter().map(|item| enc_evidence_claim(item)).collect()), + list(claims.iter().map(enc_evidence_claim).collect()), list(axioms.iter().map(|item| text(item)).collect()), ], ), @@ -966,8 +946,8 @@ pub(super) fn enc_model_declaration(value: &SemanticDeclaration) -> Value { list(type_parameters.iter().map(|item| text(item)).collect()), enc_model_use(contract), enc_model_use(realization), - list(evidence.iter().map(|item| enc_model_use(item)).collect()), - list(entry.iter().map(|item| enc_member(item)).collect()), + list(evidence.iter().map(enc_model_use).collect()), + list(entry.iter().map(enc_member).collect()), list(axioms.iter().map(|item| text(item)).collect()), ], ), @@ -985,7 +965,7 @@ pub(super) fn example_model_declaration(step: usize) -> SemanticDeclaration { sha256: format!("s{rest}"), length: u64::try_from(rest).expect("a step") + 1, schema: example_artifact_schema(rest), - r#type: if rest % 2 == 0 { + r#type: if rest.is_multiple_of(2) { SemanticType::Nat } else { SemanticType::Bytes @@ -1007,15 +987,15 @@ pub(super) fn example_model_declaration(step: usize) -> SemanticDeclaration { output: example_model_binder(rest), state: (rest % 3 != 2).then(|| example_contract_state(rest)), precondition: (rest % 3 != 2).then(|| MemberRef { - module: (rest % 2 == 0).then(|| "M".to_owned()), + module: rest.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{rest}"), }), postcondition: (rest % 3 != 2).then(|| MemberRef { - module: (rest % 2 == 0).then(|| "M".to_owned()), + module: rest.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{rest}"), }), invariant: (rest % 3 != 2).then(|| MemberRef { - module: (rest % 2 == 0).then(|| "M".to_owned()), + module: rest.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{rest}"), }), validators: if rest % 3 == 2 { @@ -1039,14 +1019,14 @@ pub(super) fn example_model_declaration(step: usize) -> SemanticDeclaration { (rest..rest + 2).map(|next| format!("s{next}")).collect() }, input: example_model_binder(rest), - output: if rest % 2 == 0 { + output: if rest.is_multiple_of(2) { SemanticType::Nat } else { SemanticType::Bytes }, state: (rest % 3 != 2).then(|| example_realization_state(rest)), descriptor: example_realization_descriptor(rest), - executable: rest % 2 == 0, + executable: rest.is_multiple_of(2), axioms: if rest % 3 == 2 { Vec::new() } else { @@ -1096,7 +1076,7 @@ pub(super) fn example_model_declaration(step: usize) -> SemanticDeclaration { } else { (rest..rest + 2) .map(|next| MemberRef { - module: (next % 2 == 0).then(|| "M".to_owned()), + module: next.is_multiple_of(2).then(|| "M".to_owned()), name: format!("m{next}"), }) .collect() From a58a1d574ee29e50df0c40123987489d465cd760 Mon Sep 17 00:00:00 2001 From: humuhumu33 Date: Thu, 12 Nov 2026 18:55:44 +0000 Subject: [PATCH 4/6] BS-71: the writers declare no axioms; the examples map with their builders Co-Authored-By: Claude Opus 5.5 --- bootstrap/src/SemanticModels.lex.tex | 19 ------------- .../src/cases/bootstrap/semantic_models.rs | 28 +++++-------------- 2 files changed, 7 insertions(+), 40 deletions(-) diff --git a/bootstrap/src/SemanticModels.lex.tex b/bootstrap/src/SemanticModels.lex.tex index 302938eb9d..def295ed5e 100755 --- a/bootstrap/src/SemanticModels.lex.tex +++ b/bootstrap/src/SemanticModels.lex.tex @@ -324,7 +324,6 @@ | ArtifactRole.ArtifactRoleDataset => (ctor LexLeanStd.Json::Json.JStr (lit "dataset")) | ArtifactRole.ArtifactRoleTable => (ctor LexLeanStd.Json::Json.JStr (lit "table")) | ArtifactRole.ArtifactRoleBinary => (ctor LexLeanStd.Json::Json.JStr (lit "binary"))), - axioms: [Quot.sound, propext], executable: true } @@ -341,7 +340,6 @@ | TensorElement.TensorElementUInt16 => (ctor LexLeanStd.Json::Json.JStr (lit "uint16")) | TensorElement.TensorElementUInt32 => (ctor LexLeanStd.Json::Json.JStr (lit "uint32")) | TensorElement.TensorElementUInt64 => (ctor LexLeanStd.Json::Json.JStr (lit "uint64"))), - axioms: [Quot.sound, propext], executable: true } @@ -353,7 +351,6 @@ | ArtifactSchema.ArtifactSchemaBytes => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "bytes"))) (nil (Bytes * LexLeanStd.Json::Json))); (objectOf entries1)) | ArtifactSchema.ArtifactSchemaIntTensor part0 part1 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "int_tensor"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "element"), (tensorElementJson part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "shape"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : Nat) => (cons (ctor LexLeanStd.Json::Json.JInt false item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [Nat] part1) : (List LexLeanStd.Json::Json))))) entries2); (objectOf entries3)))) | ArtifactSchema.ArtifactSchemaUtf8Lines => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "utf8_lines"))) (nil (Bytes * LexLeanStd.Json::Json))); (objectOf entries1))), - axioms: [Quot.sound, propext], executable: true } @@ -363,7 +360,6 @@ result: LexLeanStd.Json::Json, body: (match value | ModelBinder.ModelBinderOf part0 part1 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "name"), (ctor LexLeanStd.Json::Json.JStr part0)) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "type"), (SemanticTypes::typeJson part1)) entries1); (objectOf entries2)))), - axioms: [Quot.sound, propext], executable: true } @@ -373,7 +369,6 @@ result: LexLeanStd.Json::Json, body: (match value | ContractState.ContractStateOf part0 part1 part2 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "name"), (ctor LexLeanStd.Json::Json.JStr part0)) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "next"), (ctor LexLeanStd.Json::Json.JStr part1)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "type"), (SemanticTypes::typeJson part2)) entries2); (objectOf entries3))))), - axioms: [Quot.sound, propext], executable: true } @@ -385,7 +380,6 @@ | ContractPredicate.ContractPredicateInvariant => (ctor LexLeanStd.Json::Json.JStr (lit "invariant")) | ContractPredicate.ContractPredicatePostcondition => (ctor LexLeanStd.Json::Json.JStr (lit "postcondition")) | ContractPredicate.ContractPredicatePrecondition => (ctor LexLeanStd.Json::Json.JStr (lit "precondition"))), - axioms: [Quot.sound, propext], executable: true } @@ -397,7 +391,6 @@ | ContractValidator.ContractValidatorOf part0 part1 part2 part3 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "predicate"), (contractPredicateJson part0)) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "validator"), (SemanticTerms::memberJson (first part1) (second part1))) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "sound"), (SemanticTerms::memberJson (first part2) (second part2))) entries2); (let entries4 : (List (Bytes * LexLeanStd.Json::Json)) := (match part3 | Option.some present => (cons ((lit "complete"), (SemanticTerms::memberJson (first present) (second present))) entries3) | Option.none => entries3); (objectOf entries4)))))), - axioms: [Quot.sound, propext], executable: true } @@ -409,7 +402,6 @@ | ModelUse.ModelUseOf part0 part1 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "member"), (SemanticTerms::memberJson (first part0) (second part0))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (match part1 | List.nil => entries1 | List.cons head tail => (cons ((lit "type_arguments"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : SemanticTypes::SemanticType) => (cons (SemanticTypes::typeJson item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [SemanticTypes::SemanticType] part1) : (List LexLeanStd.Json::Json))))) entries1)); (objectOf entries2)))), - axioms: [Quot.sound, propext], executable: true } @@ -419,7 +411,6 @@ result: LexLeanStd.Json::Json, body: (match value | RealizationState.RealizationStateOf part0 part1 part2 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "name"), (ctor LexLeanStd.Json::Json.JStr part0)) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "type"), (SemanticTypes::typeJson part1)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "initial"), (SemanticTerms::termJson part2)) entries2); (objectOf entries3))))), - axioms: [Quot.sound, propext], executable: true } @@ -429,7 +420,6 @@ result: LexLeanStd.Json::Json, body: (match value | RealizationRule.RealizationRuleOf part0 part1 part2 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "name"), (ctor LexLeanStd.Json::Json.JStr part0)) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "guard"), (SemanticTerms::termJson part1)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "action"), (SemanticTerms::termJson part2)) entries2); (objectOf entries3))))), - axioms: [Quot.sound, propext], executable: true } @@ -439,7 +429,6 @@ result: LexLeanStd.Json::Json, body: (match value | StatisticalScheme.StatisticalSchemeLinearScoring => (ctor LexLeanStd.Json::Json.JStr (lit "linear_scoring"))), - axioms: [Quot.sound, propext], executable: true } @@ -449,7 +438,6 @@ result: LexLeanStd.Json::Json, body: (match value | NeuralArchitecture.NeuralArchitectureIntegerFeedforward => (ctor LexLeanStd.Json::Json.JStr (lit "integer_feedforward"))), - axioms: [Quot.sound, propext], executable: true } @@ -461,7 +449,6 @@ | NeuralLayer.NeuralLayerDense part0 part1 part2 part3 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "dense"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "inputs"), (ctor LexLeanStd.Json::Json.JInt false part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "outputs"), (ctor LexLeanStd.Json::Json.JInt false part1)) entries2); (let entries4 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "weights"), (SemanticTerms::memberJson (first part2) (second part2))) entries3); (let entries5 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "bias"), (SemanticTerms::memberJson (first part3) (second part3))) entries4); (objectOf entries5)))))) | NeuralLayer.NeuralLayerRelu => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "relu"))) (nil (Bytes * LexLeanStd.Json::Json))); (objectOf entries1)) | NeuralLayer.NeuralLayerRequantize part0 part1 part2 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "requantize"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "shift"), (ctor LexLeanStd.Json::Json.JInt false part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "minimum"), (ctor LexLeanStd.Json::Json.JStr part1)) entries2); (let entries4 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "maximum"), (ctor LexLeanStd.Json::Json.JStr part2)) entries3); (objectOf entries4)))))), - axioms: [Quot.sound, propext], executable: true } @@ -472,7 +459,6 @@ body: (match value | NeuralDecoder.NeuralDecoderArgmax part0 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "argmax"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "labels"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : SemanticTerms::STerm) => (cons (SemanticTerms::termJson item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [SemanticTerms::STerm] part0) : (List LexLeanStd.Json::Json))))) entries1); (objectOf entries2))) | NeuralDecoder.NeuralDecoderFunction part0 part1 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "function"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "binder"), (ctor LexLeanStd.Json::Json.JStr part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "body"), (SemanticTerms::termJson part1)) entries2); (objectOf entries3))))), - axioms: [Quot.sound, propext], executable: true } @@ -484,7 +470,6 @@ | CompositeJunction.CompositeJunctionUnconditional => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "unconditional"))) (nil (Bytes * LexLeanStd.Json::Json))); (objectOf entries1)) | CompositeJunction.CompositeJunctionProved part0 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "proved"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "evidence"), (SemanticTerms::memberJson (first part0) (second part0))) entries1); (objectOf entries2))) | CompositeJunction.CompositeJunctionChecked => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "checked"))) (nil (Bytes * LexLeanStd.Json::Json))); (objectOf entries1))), - axioms: [Quot.sound, propext], executable: true } @@ -498,7 +483,6 @@ | CompositeForm.CompositeFormProduct part0 part1 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "product"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "left"), (modelUseJson part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "right"), (modelUseJson part1)) entries2); (objectOf entries3)))) | CompositeForm.CompositeFormBranch part0 part1 part2 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "branch"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "guard"), (SemanticTerms::termJson part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "then"), (modelUseJson part1)) entries2); (let entries4 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "else"), (modelUseJson part2)) entries3); (objectOf entries4))))) | CompositeForm.CompositeFormScan part0 part1 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "scan"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "stage"), (modelUseJson part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "junction"), (compositeJunctionJson part1)) entries2); (objectOf entries3))))), - axioms: [Quot.sound, propext], executable: true } @@ -512,7 +496,6 @@ | RealizationDescriptor.RealizationDescriptorStatistical part0 part1 part2 part3 part4 part5 part6 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "statistical"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "scheme"), (statisticalSchemeJson part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "features"), (SemanticTerms::termJson part1)) entries2); (let entries4 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "width"), (ctor LexLeanStd.Json::Json.JInt false part2)) entries3); (let entries5 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "width_evidence"), (SemanticTerms::memberJson (first part3) (second part3))) entries4); (let entries6 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "weights"), (SemanticTerms::memberJson (first part4) (second part4))) entries5); (let entries7 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "bias"), (SemanticTerms::memberJson (first part5) (second part5))) entries6); (let entries8 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "labels"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : SemanticTerms::STerm) => (cons (SemanticTerms::termJson item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [SemanticTerms::STerm] part6) : (List LexLeanStd.Json::Json))))) entries7); (objectOf entries8))))))))) | RealizationDescriptor.RealizationDescriptorNeural part0 part1 part2 part3 part4 part5 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "neural"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "architecture"), (neuralArchitectureJson part0)) entries1); (let entries3 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "encoder"), (SemanticTerms::termJson part1)) entries2); (let entries4 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "width"), (ctor LexLeanStd.Json::Json.JInt false part2)) entries3); (let entries5 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "width_evidence"), (SemanticTerms::memberJson (first part3) (second part3))) entries4); (let entries6 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "layers"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : NeuralLayer) => (cons (neuralLayerJson item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [NeuralLayer] part4) : (List LexLeanStd.Json::Json))))) entries5); (let entries7 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "decoder"), (neuralDecoderJson part5)) entries6); (objectOf entries7)))))))) | RealizationDescriptor.RealizationDescriptorComposite part0 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "composite"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "form"), (compositeFormJson part0)) entries1); (objectOf entries2)))), - axioms: [Quot.sound, propext], executable: true } @@ -526,7 +509,6 @@ | EvidenceClaim.EvidenceClaimInitialInvariant part0 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "initial_invariant"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "theorem"), (SemanticTerms::memberJson (first part0) (second part0))) entries1); (objectOf entries2))) | EvidenceClaim.EvidenceClaimPreservesInvariant part0 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "preserves_invariant"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "theorem"), (SemanticTerms::memberJson (first part0) (second part0))) entries1); (objectOf entries2))) | EvidenceClaim.EvidenceClaimSatisfiesContract part0 => (let entries1 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "kind"), (ctor LexLeanStd.Json::Json.JStr (lit "satisfies_contract"))) (nil (Bytes * LexLeanStd.Json::Json))); (let entries2 : (List (Bytes * LexLeanStd.Json::Json)) := (cons ((lit "theorem"), (SemanticTerms::memberJson (first part0) (second part0))) entries1); (objectOf entries2)))), - axioms: [Quot.sound, propext], executable: true } @@ -574,7 +556,6 @@ | List.cons head tail => (cons ((lit "entry"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : ((Option Bytes) * Bytes)) => (cons (SemanticTerms::memberJson (first item) (second item)) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [((Option Bytes) * Bytes)] part5) : (List LexLeanStd.Json::Json))))) entries6)); (let entries8 : (List (Bytes * LexLeanStd.Json::Json)) := (match part6 | List.nil => entries7 | List.cons head tail => (cons ((lit "axioms"), (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (item : Bytes) => (cons (ctor LexLeanStd.Json::Json.JStr item) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [Bytes] part6) : (List LexLeanStd.Json::Json))))) entries7)); (objectOf entries8)))))))))), - axioms: [Quot.sound, propext], executable: true } diff --git a/crates/conformance/src/cases/bootstrap/semantic_models.rs b/crates/conformance/src/cases/bootstrap/semantic_models.rs index 4f627a91f7..998cc9027c 100755 --- a/crates/conformance/src/cases/bootstrap/semantic_models.rs +++ b/crates/conformance/src/cases/bootstrap/semantic_models.rs @@ -571,16 +571,12 @@ pub(super) fn example_composite_form(step: usize) -> CompositeForm { stages: if rest % 3 == 2 { Vec::new() } else { - (rest..rest + 2) - .map(|next| example_model_use(next)) - .collect() + (rest..rest + 2).map(example_model_use).collect() }, junctions: if rest % 3 == 2 { Vec::new() } else { - (rest..rest + 2) - .map(|next| example_composite_junction(next)) - .collect() + (rest..rest + 2).map(example_composite_junction).collect() }, }, 1 => CompositeForm::Fanout { @@ -681,9 +677,7 @@ pub(super) fn example_realization_descriptor(step: usize) -> RealizationDescript rules: if rest % 3 == 2 { Vec::new() } else { - (rest..rest + 2) - .map(|next| example_realization_rule(next)) - .collect() + (rest..rest + 2).map(example_realization_rule).collect() }, default: SemanticTerm::Nat { value: rest.to_string(), @@ -730,9 +724,7 @@ pub(super) fn example_realization_descriptor(step: usize) -> RealizationDescript layers: if rest % 3 == 2 { Vec::new() } else { - (rest..rest + 2) - .map(|next| example_neural_layer(next)) - .collect() + (rest..rest + 2).map(example_neural_layer).collect() }, decoder: example_neural_decoder(rest), }, @@ -1001,9 +993,7 @@ pub(super) fn example_model_declaration(step: usize) -> SemanticDeclaration { validators: if rest % 3 == 2 { Vec::new() } else { - (rest..rest + 2) - .map(|next| example_contract_validator(next)) - .collect() + (rest..rest + 2).map(example_contract_validator).collect() }, axioms: if rest % 3 == 2 { Vec::new() @@ -1045,9 +1035,7 @@ pub(super) fn example_model_declaration(step: usize) -> SemanticDeclaration { claims: if rest % 3 == 2 { Vec::new() } else { - (rest..rest + 2) - .map(|next| example_evidence_claim(next)) - .collect() + (rest..rest + 2).map(example_evidence_claim).collect() }, axioms: if rest % 3 == 2 { Vec::new() @@ -1067,9 +1055,7 @@ pub(super) fn example_model_declaration(step: usize) -> SemanticDeclaration { evidence: if rest % 3 == 2 { Vec::new() } else { - (rest..rest + 2) - .map(|next| example_model_use(next)) - .collect() + (rest..rest + 2).map(example_model_use).collect() }, entry: if rest % 3 == 2 { Vec::new() From 63b1568962cad38aa531f9572d982eaff745f593 Mon Sep 17 00:00:00 2001 From: humuhumu33 Date: Thu, 12 Nov 2026 21:18:41 +0000 Subject: [PATCH 5/6] The roots of BS-69, BS-70 and BS-72 are named after their packages The stack-bound step of the regeneration maps a package to its root by name, so a root is the camel case of its package and unique in the project: semanticTermText, semanticProofText, semanticDeclarationText, semanticModuleText, and wholeSemanticModuleText. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 6 +++--- SPEC.md | 14 +++++++------- VERIFICATION.md | 10 +++++----- bootstrap/src/SemanticDecls.lex.tex | 4 ++-- bootstrap/src/SemanticTerms.lex.tex | 4 ++-- .../src/cases/bootstrap/semantic_decls.rs | 10 ++++++++-- .../src/cases/bootstrap/semantic_terms.rs | 7 +++++-- features/suites/bootstrap.feature | 4 ++-- model/ids.toml | 4 ++-- tests/production-export/bootstrap/roots.json | 8 ++++---- 10 files changed, 40 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79eb13bc26..3d6108103f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,14 +26,14 @@ workspace carried at those versions without a tag. - The ordinary declarations of the semantic module language and its modules as language-1.2 source, sixth slice of the typed IR (SPEC.md §17.23, §17.11, §17.12, `BS-70`, #269; no new diagnostic code, no change to the language-1.2 identity). - `declarationText` and `moduleText` of `SemanticDecls` return the canonical JSON of + `semanticDeclarationText` and `semanticModuleText` of `SemanticDecls` return the canonical JSON of the serde form of `SemanticDeclaration` and `SemanticModule`, the latter for every module of the `bootstrap/` project and the standard library, and admit `recursion`. The register is 499 IDs. - The closed terms and proofs of the semantic module language as language-1.2 source, fifth slice of the typed IR (SPEC.md §17.23, §17.11, §17.12, `BS-69`, #269; no new - diagnostic code, no change to the language-1.2 identity). `termText` and - `proofText` of `SemanticTerms` return the canonical JSON of the serde form of + diagnostic code, no change to the language-1.2 identity). `semanticTermText` and + `semanticProofText` of `SemanticTerms` return the canonical JSON of the serde form of `SemanticTerm` and `SemanticProof`, and admit `recursion`. The register is 498 IDs. - The closed types of the semantic module language, its primitives, and its integer families as language-1.2 source, fourth slice of the typed IR (SPEC.md §17.23, §17.11, diff --git a/SPEC.md b/SPEC.md index a3705bef51..66c86f282b 100644 --- a/SPEC.md +++ b/SPEC.md @@ -9092,8 +9092,8 @@ component of the typed IR as source (`BS-69`, issue 269), the module `SemanticTe | Root | Takes | Returns | Oracle | | --- | --- | --- | --- | -| `LexLeanBoot.SemanticTerms.termText` | a term | its canonical JSON as the linked IR embeds it | the serde form of `ir::semantic::SemanticTerm` | -| `LexLeanBoot.SemanticTerms.proofText` | a proof | its canonical JSON as the linked IR embeds it | the serde form of `ir::semantic::SemanticProof` | +| `LexLeanBoot.SemanticTerms.semanticTermText` | a term | its canonical JSON as the linked IR embeds it | the serde form of `ir::semantic::SemanticTerm` | +| `LexLeanBoot.SemanticTerms.semanticProofText` | a proof | its canonical JSON as the linked IR embeds it | the serde form of `ir::semantic::SemanticProof` | Arguments, assignments, branches, map entries, and graph edges are chains of cells of the term itself, and proof branches and nested members chains of cells of the proof, so that each root is @@ -9106,11 +9106,11 @@ holds them are the sixth component of the typed IR as source (`BS-70`, issue 269 | Root | Takes | Returns | Oracle | | --- | --- | --- | --- | -| `LexLeanBoot.SemanticDecls.declarationText` | a structure, class, instance, inductive, definition, or theorem | its canonical JSON as the linked IR embeds it | the serde form of `ir::semantic::SemanticDeclaration` | -| `LexLeanBoot.SemanticDecls.moduleText` | a specification and the declarations of a module | the module's canonical JSON | the serde form of `ir::semantic::SemanticModule` | +| `LexLeanBoot.SemanticDecls.semanticDeclarationText` | a structure, class, instance, inductive, definition, or theorem | its canonical JSON as the linked IR embeds it | the serde form of `ir::semantic::SemanticDeclaration` | +| `LexLeanBoot.SemanticDecls.semanticModuleText` | a specification and the declarations of a module | the module's canonical JSON | the serde form of `ir::semantic::SemanticModule` | Every module of the `bootstrap/` project and of the standard library declares only these kinds, -so `moduleText` writes the semantic modules of LexLean's own sources. Both roots admit +so `semanticModuleText` writes the semantic modules of LexLean's own sources. Both roots admit `recursion`. The declarations of models, reasoning, and text components, and reading declarations from JSON, stay in the host. The declarations of artifacts, contracts, realizations, evidence, and models (§17.12) are the @@ -12177,8 +12177,8 @@ Every row below is normative, has honesty level `build`, and MUST be copied byte | `BS-66` | `bootstrap` | The proof and declaration IR of SPEC.md §17.4 and §17.5 in the canonical JSON of §17.9 (`ir::proof::Proof::to_json` and `ir::declaration::Declaration::to_json` under the hashing renumbering of `BS-65`: each step, rule, case, and calculation step in order, an introduction binding its locals in order, a `have` binding its local after its proposition, a case binding its locals before its proof, a rewrite target resolved as an occurrence, and a declaration's parameters bound before its body, with its kind and its axiom policy; and `AxiomPolicy::permits` of §15.9: no axiom under `none`, a subset under `allow`, and the sorted distinct set equal to the policy's under `exact`) is language-1.2 source in the `bootstrap/` project, as three production roots of `IrProof` over the term JSON of `IrTerm`: `proofText` and `declarationText`, each eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and `permits`, with exactly `allocation` and `overflow`, each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator, agree with the oracle to the byte on hand-built proofs, declarations, and policies, which reach every proof constructor, every declaration kind and body, every policy, rebound and free locals, duplicates, and order, on every declaration and every nested proof of the linked IR of the committed projects that declare document environments, with each policy against its own axioms and against none, and on seeded inputs; each planted defect in the source is detected by the root and the one vector it names, and the certified packages the production export publishes for the project are the committed ones; elaborating proofs and observing axioms are outside the claim. | §15.9, §17.4, §17.5, §17.9, §17.23 | | `BS-67` | `bootstrap` | The document IR and the linked project of SPEC.md §17.5 in the canonical JSON of §17.9, and the semantic ID of §21.4 (`ir::document::DocumentModule::to_json`: the name, the Lean module, the glossary, the imports, the title and the blocks under one hashing renumbering of `BS-65`, each section's heading, parameters, and blocks in order and each declaration through `BS-66`, the origin only when there is one, an import's Lean module only when it is not the one the module's prefix gives, and an embedded closed-core module as its serialized text and a semantic or tooling module as its JSON; `LinkedProject::to_json`: the specification and the modules in name order; and the semantic ID the linker records, the recipe of `BS-32` over that text) is language-1.2 source in the `bootstrap/` project, as three production roots of `IrDocument`: `moduleText`, `linkedText`, and `projectSemanticId`, each eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc on the projects of at most 4,194,304 bytes of linked IR, and on the normative host their lowered programs under the calculus evaluator on the shorter ones, agree with the oracle to the byte on hand-built modules and projects, which reach every phrase item, sections, origins, default and foreign imports, every kind of embedded module, and modules out of order, and on every module, every linked project, and the recorded semantic ID of every committed project outside the negative fixtures and UOR Atlas that links under its committed lock, or under a lock computed from its manifest when it commits none; each planted defect in the source is detected by the root and the one vector it names, and the certified packages the production export publishes for the project are the committed ones; serializing the embedded modules and the lexicon closure is outside the claim. | §17.5, §17.9, §17.23, §21.4 | | `BS-68` | `bootstrap` | The closed types of the semantic module language of SPEC.md §17.11 and §17.12, its primitives, and its integer families (`ir::semantic::SemanticType` in the serde form the linked IR embeds, written as canonical JSON: each type tagged by its `kind`, a named type's module only when it has one, and the fixed-width names `int8` to `uint64`; its `Display`, the spelling diagnostics use; and of `SemanticPrimitive` and `SemanticInteger`, the serialized name, whether a primitive is language 1.2's, whether linking widens it away, and the position of its function argument) is language-1.2 source in the `bootstrap/` project, as four production roots of `SemanticTypes`: `primitiveFacts` and `integerName`, each eligible for `rust-std` with exactly `allocation`, `typeText`, with exactly `allocation`, `overflow`, and `recursion`, and `typeSpelling`, with exactly `allocation` and `recursion`, each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator, agree with the oracle to the byte on hand-built types, which reach every constructor and every unit type, on every primitive and every integer family the module names, each read back through the oracle's serialized name, on every distinct type of every committed semantic module that links, and on seeded types; each planted defect in the source is detected by the root and the one vector it names, and the certified packages the production export publishes for the project are the committed ones; reading types from JSON is outside the claim. | §17.11, §17.12, §17.23 | -| `BS-69` | `bootstrap` | The closed terms and proofs of the semantic module language of SPEC.md §17.11 and §17.12 (`ir::semantic::SemanticTerm` and `SemanticProof` in the serde form the linked IR embeds, written as canonical JSON: each term and proof tagged by its `kind`, its member references, assignments, branches, binders, map entries, graph edges, model checks, and reflections in their fields, a list of type arguments, definitions, generalized names, or premises left out when it is empty where the oracle skips it, and its types through `SemanticTypes`) is language-1.2 source in the `bootstrap/` project, as two production roots of `SemanticTerms`: `termText` and `proofText`, each eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator, agree with the oracle to the byte on hand-built terms and proofs, which reach every constructor and every optional list both empty and not, on every distinct term and proof of every committed semantic module that links, and on seeded terms and proofs; each planted defect in the source is detected by the root and the one vector it names, and the certified packages the production export publishes for the project are the committed ones; reading terms and proofs from JSON is outside the claim. | §17.11, §17.12, §17.23 | -| `BS-70` | `bootstrap` | The ordinary declarations of the semantic module language of SPEC.md §17.11 and §17.12 and the module that holds them (`ir::semantic::SemanticDeclaration` for structures, classes, instances, inductives, definitions, and theorems, and `SemanticModule`, in the serde form the linked IR embeds, written as canonical JSON: each declaration tagged by its `kind`, its parameters, fields, constructors, and assignments in order, and a definition's or a theorem's type parameters, recursive argument, axioms, executable flag, mutual group, termination, and production, and an inductive's mutual group, left out exactly where the oracle's serde attributes skip them; and a module's specification and declarations in order) is language-1.2 source in the `bootstrap/` project, as two production roots of `SemanticDecls` over `SemanticTerms` and `SemanticTypes`: `declarationText` and `moduleText`, each eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator on the shorter modules, agree with the oracle to the byte on hand-built declarations, which reach every kind and every optional member both present and absent, on every distinct ordinary declaration of every committed semantic module that links and on every such module whose declarations are all ordinary, among them every module of the `bootstrap/` project and the standard library, and on seeded declarations; each planted defect in the source is detected by the root and the one vector it names, and the certified packages the production export publishes for the project are the committed ones; the declarations of models, reasoning, and text components, and reading declarations from JSON, are outside the claim. | §17.11, §17.12, §17.23 | +| `BS-69` | `bootstrap` | The closed terms and proofs of the semantic module language of SPEC.md §17.11 and §17.12 (`ir::semantic::SemanticTerm` and `SemanticProof` in the serde form the linked IR embeds, written as canonical JSON: each term and proof tagged by its `kind`, its member references, assignments, branches, binders, map entries, graph edges, model checks, and reflections in their fields, a list of type arguments, definitions, generalized names, or premises left out when it is empty where the oracle skips it, and its types through `SemanticTypes`) is language-1.2 source in the `bootstrap/` project, as two production roots of `SemanticTerms`: `semanticTermText` and `semanticProofText`, each eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator, agree with the oracle to the byte on hand-built terms and proofs, which reach every constructor and every optional list both empty and not, on every distinct term and proof of every committed semantic module that links, and on seeded terms and proofs; each planted defect in the source is detected by the root and the one vector it names, and the certified packages the production export publishes for the project are the committed ones; reading terms and proofs from JSON is outside the claim. | §17.11, §17.12, §17.23 | +| `BS-70` | `bootstrap` | The ordinary declarations of the semantic module language of SPEC.md §17.11 and §17.12 and the module that holds them (`ir::semantic::SemanticDeclaration` for structures, classes, instances, inductives, definitions, and theorems, and `SemanticModule`, in the serde form the linked IR embeds, written as canonical JSON: each declaration tagged by its `kind`, its parameters, fields, constructors, and assignments in order, and a definition's or a theorem's type parameters, recursive argument, axioms, executable flag, mutual group, termination, and production, and an inductive's mutual group, left out exactly where the oracle's serde attributes skip them; and a module's specification and declarations in order) is language-1.2 source in the `bootstrap/` project, as two production roots of `SemanticDecls` over `SemanticTerms` and `SemanticTypes`: `semanticDeclarationText` and `semanticModuleText`, each eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator on the shorter modules, agree with the oracle to the byte on hand-built declarations, which reach every kind and every optional member both present and absent, on every distinct ordinary declaration of every committed semantic module that links and on every such module whose declarations are all ordinary, among them every module of the `bootstrap/` project and the standard library, and on seeded declarations; each planted defect in the source is detected by the root and the one vector it names, and the certified packages the production export publishes for the project are the committed ones; the declarations of models, reasoning, and text components, and reading declarations from JSON, are outside the claim. | §17.11, §17.12, §17.23 | | `BS-71` | `bootstrap` | The declarations of artifacts, contracts, realizations, evidence, and models of the semantic module language of SPEC.md §17.12 (those variants of `ir::semantic::SemanticDeclaration`, with the artifact roles and schemas, binders, states, validators, uses, rules, the deterministic, rule, statistical, neural, and composite realization descriptors with their layers, decoders, forms, and junctions, and the evidence claims they hold, in the serde form the linked IR embeds, written as canonical JSON: each tagged variant by its `kind`, each closed name as the oracle serializes it, and each optional member left out exactly where the oracle's serde attributes skip it) is language-1.2 source in the `bootstrap/` project, as the production root `modelDeclarationText` of `SemanticModels` over `SemanticTerms` and `SemanticTypes`, generated with the case's encoders and examples from one description of the oracle's types, eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and with no part of its certificate beyond 3,145,728 bytes; its rendered `rust-std` package under the pinned rustc, and on the normative host its lowered program under the calculus evaluator, agree with the oracle to the byte on examples that reach every variant, every optional member present and absent, and every list empty and not, on every distinct such declaration of every committed semantic module that links, and on seeded examples; each planted defect, a misspelled kind or name, is detected by the first example that holds it, and the certified packages the production export publishes for the project are the committed ones; reading declarations from JSON is outside the claim. | §17.12, §17.23 | | `PK-01` | `packages` | A language-1.2 project that declares a source package by its identifier, version, kind `path`, and the member directory a `lexlean-workspace.toml` lists locks it by the tree digest of its manifest and source files, its manifest digest, its version, its module prefix, and its own packages, and the configuration and the lock read back to the bytes written; a project without a source package keeps its bytes, and a package of another kind, a source package in another language, a changed byte or version (LLC0105), an undeclared package (LLC0106), a module prefix claimed twice (LLC0107), a project or a package outside the workspace (LLC0108), a path that escapes it, and a symlink (LLS8001) are each refused with the named code. | §10.5, §11.1, §25.1 | | `PK-02` | `packages` | A module of a project imports only modules of its own project and modules of the packages the project declares, and a module of a package only modules of itself and of the packages its own manifest declares: a package module is a module of the importing project under its own module prefix, a module of a package the project does not declare fails with LLR3009, and an import cycle through a package fails with LLR3003. | §10.5, §15.1 | diff --git a/VERIFICATION.md b/VERIFICATION.md index faad8df7aa..45b014fd2e 100644 --- a/VERIFICATION.md +++ b/VERIFICATION.md @@ -11857,8 +11857,8 @@ passes. ### the semantic terms and proofs are source (BS-69) `BS-69` holds the two production roots of `LexLeanBoot.SemanticTerms` -(`bootstrap/src/SemanticTerms.lex.tex`) to `lexlean::ir::semantic`: `termText` -to the canonical JSON of the serde form of `SemanticTerm` and `proofText` to +(`bootstrap/src/SemanticTerms.lex.tex`) to `lexlean::ir::semantic`: `semanticTermText` +to the canonical JSON of the serde form of `SemanticTerm` and `semanticProofText` to that of `SemanticProof`, as `DocumentModule::to_json` embeds a semantic module. The module declares the 42 term forms and the 13 proof forms of SPEC.md §17.11 and §17.12 as inductives over the types of `SemanticTypes` (`BS-68`). Arguments, @@ -11888,9 +11888,9 @@ passes. `BS-70` holds the two production roots of `LexLeanBoot.SemanticDecls` (`bootstrap/src/SemanticDecls.lex.tex`) to `lexlean::ir::semantic`: -`declarationText` to the canonical JSON of the serde form of +`semanticDeclarationText` to the canonical JSON of the serde form of `SemanticDeclaration` for structures, classes, instances, inductives, -definitions, and theorems, and `moduleText` to that of `SemanticModule`, as +definitions, and theorems, and `semanticModuleText` to that of `SemanticModule`, as `DocumentModule::to_json` embeds a semantic module. The module declares the six ordinary declaration kinds of SPEC.md §17.11 and §17.12 as one inductive over the terms and proofs of `SemanticTerms` (`BS-69`) and the types of @@ -11898,7 +11898,7 @@ the terms and proofs of `SemanticTerms` (`BS-69`) and the types of recursive argument, axioms, executable flag, mutual group, termination, and production, and an inductive's mutual group, are left out exactly where the oracle's serde attributes skip them. Every module of the `bootstrap/` project and -of the standard library declares only these kinds, so `moduleText` writes the +of the standard library declares only these kinds, so `semanticModuleText` writes the semantic modules of LexLean's own sources. Both roots admit exactly `allocation`, `overflow`, and `recursion`. The oracle is the existing public code of `semantic.rs` and its serde derivations; no Rust outside the case changes. diff --git a/bootstrap/src/SemanticDecls.lex.tex b/bootstrap/src/SemanticDecls.lex.tex index 090f76c3c0..d0fca84f47 100755 --- a/bootstrap/src/SemanticDecls.lex.tex +++ b/bootstrap/src/SemanticDecls.lex.tex @@ -185,7 +185,7 @@ } definition{ - name: declarationText, + name: semanticDeclarationText, parameters: [declaration : SDecl], result: Bytes, body: (LexLeanStd.Json::writeJson (declarationJson declaration)), @@ -195,7 +195,7 @@ } definition{ - name: moduleText, + name: semanticModuleText, parameters: [spec : Bytes, declarations : (List SDecl)], result: Bytes, body: (LexLeanStd.Json::writeJson (ctor LexLeanStd.Json::Json.JObj (member "spec" (jtext spec) (member "declarations" (ctor LexLeanStd.Json::Json.JArr (SemanticTerms::chainOf (prim list_fold (fun (acc : (List LexLeanStd.Json::Json)) (declaration : SDecl) => (cons (declarationJson declaration) acc)) (nil LexLeanStd.Json::Json) (LexLeanStd.Order::reverseList [SDecl] declarations) : (List LexLeanStd.Json::Json)))) (jnil))))), diff --git a/bootstrap/src/SemanticTerms.lex.tex b/bootstrap/src/SemanticTerms.lex.tex index 590b6c2178..a6b91f3fe9 100755 --- a/bootstrap/src/SemanticTerms.lex.tex +++ b/bootstrap/src/SemanticTerms.lex.tex @@ -323,7 +323,7 @@ } definition{ - name: termText, + name: semanticTermText, parameters: [term : STerm], result: Bytes, body: (LexLeanStd.Json::writeJson (termJson term)), @@ -333,7 +333,7 @@ } definition{ - name: proofText, + name: semanticProofText, parameters: [proof : SProof], result: Bytes, body: (LexLeanStd.Json::writeJson (proofJson proof)), diff --git a/crates/conformance/src/cases/bootstrap/semantic_decls.rs b/crates/conformance/src/cases/bootstrap/semantic_decls.rs index 215d292f82..36cde01087 100755 --- a/crates/conformance/src/cases/bootstrap/semantic_decls.rs +++ b/crates/conformance/src/cases/bootstrap/semantic_decls.rs @@ -36,8 +36,14 @@ use crate::support::{self, repo_root}; const MODULE: &str = "LexLeanBoot.SemanticDecls"; const SOURCE: &str = "bootstrap/src/SemanticDecls.lex.tex"; const ROOTS: [(&str, &[&str]); 2] = [ - ("declarationText", &["allocation", "overflow", "recursion"]), - ("moduleText", &["allocation", "overflow", "recursion"]), + ( + "semanticDeclarationText", + &["allocation", "overflow", "recursion"], + ), + ( + "semanticModuleText", + &["allocation", "overflow", "recursion"], + ), ]; /// The most a part of a certificate of a root may be, as the row states. diff --git a/crates/conformance/src/cases/bootstrap/semantic_terms.rs b/crates/conformance/src/cases/bootstrap/semantic_terms.rs index 7bdfce3696..c8d1db126c 100755 --- a/crates/conformance/src/cases/bootstrap/semantic_terms.rs +++ b/crates/conformance/src/cases/bootstrap/semantic_terms.rs @@ -33,8 +33,11 @@ use crate::support::{self, repo_root}; const MODULE: &str = "LexLeanBoot.SemanticTerms"; const SOURCE: &str = "bootstrap/src/SemanticTerms.lex.tex"; const ROOTS: [(&str, &[&str]); 2] = [ - ("termText", &["allocation", "overflow", "recursion"]), - ("proofText", &["allocation", "overflow", "recursion"]), + ("semanticTermText", &["allocation", "overflow", "recursion"]), + ( + "semanticProofText", + &["allocation", "overflow", "recursion"], + ), ]; /// The most a part of a certificate of a root may be, as the row states. diff --git a/features/suites/bootstrap.feature b/features/suites/bootstrap.feature index 4d38539377..b10a161bf2 100644 --- a/features/suites/bootstrap.feature +++ b/features/suites/bootstrap.feature @@ -233,13 +233,13 @@ Feature: bootstrap Then each root is eligible for rust-std with exactly its declared effects, no certificate part is beyond 3,145,728 bytes, and the four roots equal the facts of `SemanticPrimitive` and `SemanticInteger`, the canonical JSON of the serde form of `SemanticType`, and its `Display` on every run And every planted defect is detected by its own vector, and the exported packages are byte-identical to the committed packages and realize the programs the differential ran @BS-69 @build - Scenario: The closed terms and proofs of the semantic module language of SPEC.md §17.11 and §17.12 (`ir::semantic::SemanticTerm` and `SemanticProof` in the serde form the linked IR embeds, written as canonical JSON: each term and proof tagged by its `kind`, its member references, assignments, branches, binders, map entries, graph edges, model checks, and reflections in their fields, a list of type arguments, definitions, generalized names, or premises left out when it is empty where the oracle skips it, and its types through `SemanticTypes`) is language-1.2 source in the `bootstrap/` project, as two production roots of `SemanticTerms`: `termText` and `proofText`, each eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator, agree with the oracle to the byte on hand-built terms and proofs, which reach every constructor and every optional list both empty and not, on every distinct term and proof of every committed semantic module that links, and on seeded terms and proofs; each planted defect in the source is detected by the root and the one vector it names, and the certified packages the production export publishes for the project are the committed ones; reading terms and proofs from JSON is outside the claim. + Scenario: The closed terms and proofs of the semantic module language of SPEC.md §17.11 and §17.12 (`ir::semantic::SemanticTerm` and `SemanticProof` in the serde form the linked IR embeds, written as canonical JSON: each term and proof tagged by its `kind`, its member references, assignments, branches, binders, map entries, graph edges, model checks, and reflections in their fields, a list of type arguments, definitions, generalized names, or premises left out when it is empty where the oracle skips it, and its types through `SemanticTypes`) is language-1.2 source in the `bootstrap/` project, as two production roots of `SemanticTerms`: `semanticTermText` and `semanticProofText`, each eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator, agree with the oracle to the byte on hand-built terms and proofs, which reach every constructor and every optional list both empty and not, on every distinct term and proof of every committed semantic module that links, and on seeded terms and proofs; each planted defect in the source is detected by the root and the one vector it names, and the certified packages the production export publishes for the project are the committed ones; reading terms and proofs from JSON is outside the claim. Given the committed `bootstrap` project, hand-built terms and proofs, every term and proof of the committed semantic modules that link, and seeded terms and proofs When the project is checked and built, and the lowered program and the rendered package of each root are run on those inputs Then each root is eligible for rust-std with exactly its declared effects, no certificate part is beyond 3,145,728 bytes, and the two roots equal the canonical JSON of the serde form of `SemanticTerm` and `SemanticProof` on every run And every planted defect is detected by its own vector, and the exported packages are byte-identical to the committed packages and realize the programs the differential ran @BS-70 @build - Scenario: The ordinary declarations of the semantic module language of SPEC.md §17.11 and §17.12 and the module that holds them (`ir::semantic::SemanticDeclaration` for structures, classes, instances, inductives, definitions, and theorems, and `SemanticModule`, in the serde form the linked IR embeds, written as canonical JSON: each declaration tagged by its `kind`, its parameters, fields, constructors, and assignments in order, and a definition's or a theorem's type parameters, recursive argument, axioms, executable flag, mutual group, termination, and production, and an inductive's mutual group, left out exactly where the oracle's serde attributes skip them; and a module's specification and declarations in order) is language-1.2 source in the `bootstrap/` project, as two production roots of `SemanticDecls` over `SemanticTerms` and `SemanticTypes`: `declarationText` and `moduleText`, each eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator on the shorter modules, agree with the oracle to the byte on hand-built declarations, which reach every kind and every optional member both present and absent, on every distinct ordinary declaration of every committed semantic module that links and on every such module whose declarations are all ordinary, among them every module of the `bootstrap/` project and the standard library, and on seeded declarations; each planted defect in the source is detected by the root and the one vector it names, and the certified packages the production export publishes for the project are the committed ones; the declarations of models, reasoning, and text components, and reading declarations from JSON, are outside the claim. + Scenario: The ordinary declarations of the semantic module language of SPEC.md §17.11 and §17.12 and the module that holds them (`ir::semantic::SemanticDeclaration` for structures, classes, instances, inductives, definitions, and theorems, and `SemanticModule`, in the serde form the linked IR embeds, written as canonical JSON: each declaration tagged by its `kind`, its parameters, fields, constructors, and assignments in order, and a definition's or a theorem's type parameters, recursive argument, axioms, executable flag, mutual group, termination, and production, and an inductive's mutual group, left out exactly where the oracle's serde attributes skip them; and a module's specification and declarations in order) is language-1.2 source in the `bootstrap/` project, as two production roots of `SemanticDecls` over `SemanticTerms` and `SemanticTypes`: `semanticDeclarationText` and `semanticModuleText`, each eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator on the shorter modules, agree with the oracle to the byte on hand-built declarations, which reach every kind and every optional member both present and absent, on every distinct ordinary declaration of every committed semantic module that links and on every such module whose declarations are all ordinary, among them every module of the `bootstrap/` project and the standard library, and on seeded declarations; each planted defect in the source is detected by the root and the one vector it names, and the certified packages the production export publishes for the project are the committed ones; the declarations of models, reasoning, and text components, and reading declarations from JSON, are outside the claim. Given the committed `bootstrap` project, hand-built declarations and a module, every ordinary declaration of the committed semantic modules that link, every such module of only ordinary declarations, and seeded declarations When the project is checked and built, and the lowered program and the rendered package of each root are run on those inputs Then each root is eligible for rust-std with exactly its declared effects, no certificate part is beyond 3,145,728 bytes, and the two roots equal the canonical JSON of the serde form of `SemanticDeclaration` and `SemanticModule` on every run diff --git a/model/ids.toml b/model/ids.toml index 315341f1d5..1bbb951e14 100644 --- a/model/ids.toml +++ b/model/ids.toml @@ -2904,13 +2904,13 @@ statement = "The closed types of the semantic module language of SPEC.md §17.11 id = "BS-69" level = "build" suite = "bootstrap" -statement = "The closed terms and proofs of the semantic module language of SPEC.md §17.11 and §17.12 (`ir::semantic::SemanticTerm` and `SemanticProof` in the serde form the linked IR embeds, written as canonical JSON: each term and proof tagged by its `kind`, its member references, assignments, branches, binders, map entries, graph edges, model checks, and reflections in their fields, a list of type arguments, definitions, generalized names, or premises left out when it is empty where the oracle skips it, and its types through `SemanticTypes`) is language-1.2 source in the `bootstrap/` project, as two production roots of `SemanticTerms`: `termText` and `proofText`, each eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator, agree with the oracle to the byte on hand-built terms and proofs, which reach every constructor and every optional list both empty and not, on every distinct term and proof of every committed semantic module that links, and on seeded terms and proofs; each planted defect in the source is detected by the root and the one vector it names, and the certified packages the production export publishes for the project are the committed ones; reading terms and proofs from JSON is outside the claim." +statement = "The closed terms and proofs of the semantic module language of SPEC.md §17.11 and §17.12 (`ir::semantic::SemanticTerm` and `SemanticProof` in the serde form the linked IR embeds, written as canonical JSON: each term and proof tagged by its `kind`, its member references, assignments, branches, binders, map entries, graph edges, model checks, and reflections in their fields, a list of type arguments, definitions, generalized names, or premises left out when it is empty where the oracle skips it, and its types through `SemanticTypes`) is language-1.2 source in the `bootstrap/` project, as two production roots of `SemanticTerms`: `semanticTermText` and `semanticProofText`, each eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator, agree with the oracle to the byte on hand-built terms and proofs, which reach every constructor and every optional list both empty and not, on every distinct term and proof of every committed semantic module that links, and on seeded terms and proofs; each planted defect in the source is detected by the root and the one vector it names, and the certified packages the production export publishes for the project are the committed ones; reading terms and proofs from JSON is outside the claim." [[id]] id = "BS-70" level = "build" suite = "bootstrap" -statement = "The ordinary declarations of the semantic module language of SPEC.md §17.11 and §17.12 and the module that holds them (`ir::semantic::SemanticDeclaration` for structures, classes, instances, inductives, definitions, and theorems, and `SemanticModule`, in the serde form the linked IR embeds, written as canonical JSON: each declaration tagged by its `kind`, its parameters, fields, constructors, and assignments in order, and a definition's or a theorem's type parameters, recursive argument, axioms, executable flag, mutual group, termination, and production, and an inductive's mutual group, left out exactly where the oracle's serde attributes skip them; and a module's specification and declarations in order) is language-1.2 source in the `bootstrap/` project, as two production roots of `SemanticDecls` over `SemanticTerms` and `SemanticTypes`: `declarationText` and `moduleText`, each eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator on the shorter modules, agree with the oracle to the byte on hand-built declarations, which reach every kind and every optional member both present and absent, on every distinct ordinary declaration of every committed semantic module that links and on every such module whose declarations are all ordinary, among them every module of the `bootstrap/` project and the standard library, and on seeded declarations; each planted defect in the source is detected by the root and the one vector it names, and the certified packages the production export publishes for the project are the committed ones; the declarations of models, reasoning, and text components, and reading declarations from JSON, are outside the claim." +statement = "The ordinary declarations of the semantic module language of SPEC.md §17.11 and §17.12 and the module that holds them (`ir::semantic::SemanticDeclaration` for structures, classes, instances, inductives, definitions, and theorems, and `SemanticModule`, in the serde form the linked IR embeds, written as canonical JSON: each declaration tagged by its `kind`, its parameters, fields, constructors, and assignments in order, and a definition's or a theorem's type parameters, recursive argument, axioms, executable flag, mutual group, termination, and production, and an inductive's mutual group, left out exactly where the oracle's serde attributes skip them; and a module's specification and declarations in order) is language-1.2 source in the `bootstrap/` project, as two production roots of `SemanticDecls` over `SemanticTerms` and `SemanticTypes`: `semanticDeclarationText` and `semanticModuleText`, each eligible for `rust-std` with exactly its declared effects, `allocation`, `overflow`, and `recursion`, and each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator on the shorter modules, agree with the oracle to the byte on hand-built declarations, which reach every kind and every optional member both present and absent, on every distinct ordinary declaration of every committed semantic module that links and on every such module whose declarations are all ordinary, among them every module of the `bootstrap/` project and the standard library, and on seeded declarations; each planted defect in the source is detected by the root and the one vector it names, and the certified packages the production export publishes for the project are the committed ones; the declarations of models, reasoning, and text components, and reading declarations from JSON, are outside the claim." [[id]] id = "BS-71" diff --git a/tests/production-export/bootstrap/roots.json b/tests/production-export/bootstrap/roots.json index 4689a2d9bb..a9b642a17c 100644 --- a/tests/production-export/bootstrap/roots.json +++ b/tests/production-export/bootstrap/roots.json @@ -618,7 +618,7 @@ }, { "name": "semantic_term_text", - "root": "LexLeanBoot.SemanticTerms.termText", + "root": "LexLeanBoot.SemanticTerms.semanticTermText", "targets": [ "rust-std" ], @@ -626,7 +626,7 @@ }, { "name": "semantic_proof_text", - "root": "LexLeanBoot.SemanticTerms.proofText", + "root": "LexLeanBoot.SemanticTerms.semanticProofText", "targets": [ "rust-std" ], @@ -634,7 +634,7 @@ }, { "name": "semantic_declaration_text", - "root": "LexLeanBoot.SemanticDecls.declarationText", + "root": "LexLeanBoot.SemanticDecls.semanticDeclarationText", "targets": [ "rust-std" ], @@ -642,7 +642,7 @@ }, { "name": "semantic_module_text", - "root": "LexLeanBoot.SemanticDecls.moduleText", + "root": "LexLeanBoot.SemanticDecls.semanticModuleText", "targets": [ "rust-std" ], From d133f67f33453ec24d4387aecf509fcb343e22d2 Mon Sep 17 00:00:00 2001 From: humuhumu33 Date: Fri, 13 Nov 2026 05:25:35 +0000 Subject: [PATCH 6/6] Merge bs70-semantic-decls (release b8b6e86a9) into bs71-semantic-models Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- README.md | 2 +- SPEC.md | 2 +- crates/conformance/src/cases/repository.rs | 2 +- xtask/src/spec_links.rs | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97956cc999..81388ddd47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ workspace carried at those versions without a tag. #269; no new diagnostic code, no change to the language-1.2 identity). `modelDeclarationText` of `SemanticModels` returns the canonical JSON of the serde form of those declarations; the module and its case's encoders and examples are - generated from one description of the oracle's types. The register is 500 IDs. + generated from one description of the oracle's types. The register is 501 IDs. - The ordinary declarations of the semantic module language and its modules as language-1.2 source, sixth slice of the typed IR (SPEC.md §17.23, §17.11, §17.12, `BS-70`, #269; no new diagnostic code, no change to the language-1.2 identity). diff --git a/README.md b/README.md index 06336a35b7..168f315ad5 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ just vv # the complete normative acceptance gate (SPEC.md §9.2) just release # vv, then the §30 release criterion; refused until 1.0.0 ``` -All 500 registered conformance IDs have their named tests; `just vv` checks them with the pinned toolchain installed. +All 501 registered conformance IDs have their named tests; `just vv` checks them with the pinned toolchain installed. The differential against the independent generator `lean4-prod` (SPEC.md §17.19, `OR-01`..`OR-08`) acquires it at its pinned commit: from the checkout `LEXLEAN_ORACLE_DIR` names, or by fetching the commit with `git` into the Cargo target directory (`LEXLEAN_ORACLE_CACHE` overrides), and builds it with the pinned Lean and Rust toolchains. It is validation evidence only and no input to any identity. An oracle that cannot be acquired, is not the pinned files, or fails is unavailable: that fails the gate on Linux x86-64 and is printed as `NOT VALIDATED` elsewhere, and is never reported as agreement. diff --git a/SPEC.md b/SPEC.md index 2b72c635b3..652809ea13 100644 --- a/SPEC.md +++ b/SPEC.md @@ -12214,7 +12214,7 @@ Every row below is normative, has honesty level `build`, and MUST be copied byte | `LM-09` | `language-models` | No prompt is code: no member of the closed language maps `string` or `bytes` to a function, a term, or source — every operation of the primitive registry that takes a `string` or `bytes` operand is classified by the audit with a data result, the registry's schema enumeration and the production registry's primitive rows equal one another and equal that classified set, and the text declarations of `lexlean/semantic-module/2` state no `string`-typed member, so a prompt reaches a model only as the tokens `encodeText` makes of it; a planted operation or text member of that shape is caught by the audit with its name. | §17.12 | | `LM-13` | `language-models` | The text laws a tokenizer elaborates through are LexLean source and not authored text: the module that states them is one language-1.2 native core module of the embedded `language/text-1.2` project, the project holds no file of Lean source, no independently authored Lean file anywhere in the release tree declares the `LexLeanText` namespace or lies under its module root, and the one-time migration input is absent; the registry lists only that module, the declarations and their exact axiom policies are read from its native data, which the compiler embeds and hashes into the language-1.2 semantics, and a module that declares a text component imports the generated module rather than splicing any Lean text. | §17.10, §17.12 | -**Total required capability IDs:** 500. +**Total required capability IDs:** 501. No row may be downgraded to `some-true` or `open`. Upstream Lean facts are ledger/authority rows, not substitutions for these build behaviors. diff --git a/crates/conformance/src/cases/repository.rs b/crates/conformance/src/cases/repository.rs index 584bca732e..8f9110ca76 100644 --- a/crates/conformance/src/cases/repository.rs +++ b/crates/conformance/src/cases/repository.rs @@ -898,7 +898,7 @@ pub(crate) fn run(id: &str) { let model = repo_model::Model::load(&root.join("model").into_std_path_buf()) .expect("the model loads"); let table = spec_table(); - assert_eq!(table.len(), 500, "§31 has 500 rows"); + assert_eq!(table.len(), 501, "§31 has 501 rows"); assert_eq!(model.ids.id.len(), table.len(), "register row count"); for ((spec_id, spec_suite, spec_statement), row) in table.iter().zip(model.ids.id.iter()) diff --git a/xtask/src/spec_links.rs b/xtask/src/spec_links.rs index 40df6926ea..fb3364c264 100644 --- a/xtask/src/spec_links.rs +++ b/xtask/src/spec_links.rs @@ -61,8 +61,8 @@ fn parse_table(spec: &str) -> Result, Fail> { pub fn validate(root: &Path) -> Result<(), Fail> { let spec = std::fs::read_to_string(root.join("SPEC.md"))?; let rows = parse_table(&spec)?; - if rows.len() != 500 { - return Err(format!("RP-07: the §31 table has {} rows, not 500", rows.len()).into()); + if rows.len() != 501 { + return Err(format!("RP-07: the §31 table has {} rows, not 501", rows.len()).into()); } // The prose total under the table is part of the contract a reader // relies on; a row added without it would leave §31 contradicting itself.