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 6b6d83fec7..ce8bde1aac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,12 @@ workspace carried at those versions without a tag. A landing that moves the language-1.2 ID now also updates the constant; `RP-10` names the new value when it is stale. +- 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 503 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 7acaa2b1ca..e944c813e9 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 502 registered conformance IDs have their named tests; `just vv` checks them with the pinned toolchain installed. +All 503 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, and the build manifest, 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, and the build manifest, 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 05497dafc5..f7831f3a89 100644 --- a/SPEC.md +++ b/SPEC.md @@ -9185,6 +9185,18 @@ Every module of the `bootstrap/` project and of the standard library declares on 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 +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 @@ -12250,6 +12262,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`: `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 | | `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 | @@ -12266,7 +12279,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:** 502. +**Total required capability IDs:** 503. 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 3c0486a8a8..8d52f4d218 100644 --- a/VERIFICATION.md +++ b/VERIFICATION.md @@ -11951,6 +11951,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..def295ed5e --- /dev/null +++ b/bootstrap/src/SemanticModels.lex.tex @@ -0,0 +1,572 @@ +\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"))), + 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"))), + 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))), + 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)))), + 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))))), + 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"))), + 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)))))), + 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)))), + 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))))), + 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))))), + 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"))), + 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"))), + 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)))))), + 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))))), + 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))), + 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))))), + 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)))), + 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)))), + 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)))))))))), + 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..998cc9027c --- /dev/null +++ b/crates/conformance/src/cases/bootstrap/semantic_models.rs @@ -0,0 +1,1380 @@ +//! `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 + +pub(super) fn enc_artifact_role(value: &ArtifactRole) -> Value { + adt( + "ArtifactRole", + &format!("ArtifactRole{value:?}"), + Vec::new(), + ) +} + +pub(super) const ALL_ARTIFACT_ROLE: &[ArtifactRole] = &[ + ArtifactRole::Parameters, + ArtifactRole::Vocabulary, + ArtifactRole::Dataset, + ArtifactRole::Table, + ArtifactRole::Binary, +]; + +pub(super) fn example_artifact_role(step: usize) -> ArtifactRole { + ALL_ARTIFACT_ROLE[step % ALL_ARTIFACT_ROLE.len()] +} + +pub(super) fn enc_tensor_element(value: &TensorElement) -> Value { + adt( + "TensorElement", + &format!("TensorElement{value:?}"), + Vec::new(), + ) +} + +pub(super) const ALL_TENSOR_ELEMENT: &[TensorElement] = &[ + TensorElement::Int8, + TensorElement::Int16, + TensorElement::Int32, + TensorElement::Int64, + TensorElement::UInt8, + TensorElement::UInt16, + TensorElement::UInt32, + TensorElement::UInt64, +]; + +pub(super) fn example_tensor_element(step: usize) -> TensorElement { + ALL_TENSOR_ELEMENT[step % ALL_TENSOR_ELEMENT.len()] +} + +pub(super) 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)] +pub(super) 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 step") + 1) + .collect() + }, + }, + _ => ArtifactSchema::Utf8Lines, + } +} + +pub(super) fn enc_model_binder(value: &ModelBinder) -> Value { + adt( + "ModelBinder", + "ModelBinderOf", + 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.is_multiple_of(2) { + SemanticType::Nat + } else { + SemanticType::Bytes + }, + } +} + +pub(super) fn enc_contract_state(value: &ContractState) -> Value { + adt( + "ContractState", + "ContractStateOf", + vec![ + text(&value.name), + text(&value.next), + enc_type(&value.r#type), + ], + ) +} + +pub(super) fn example_contract_state(step: usize) -> ContractState { + ContractState { + name: format!("s{step}"), + next: format!("s{step}"), + r#type: if step.is_multiple_of(2) { + SemanticType::Nat + } else { + SemanticType::Bytes + }, + } +} + +pub(super) fn enc_contract_predicate(value: &ContractPredicate) -> Value { + adt( + "ContractPredicate", + &format!("ContractPredicate{value:?}"), + Vec::new(), + ) +} + +pub(super) const ALL_CONTRACT_PREDICATE: &[ContractPredicate] = &[ + ContractPredicate::Invariant, + ContractPredicate::Postcondition, + ContractPredicate::Precondition, +]; + +pub(super) fn example_contract_predicate(step: usize) -> ContractPredicate { + ALL_CONTRACT_PREDICATE[step % ALL_CONTRACT_PREDICATE.len()] +} + +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(enc_member)), + ], + ) +} + +pub(super) fn example_contract_validator(step: usize) -> ContractValidator { + ContractValidator { + predicate: example_contract_predicate(step), + validator: MemberRef { + module: step.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{step}"), + }, + sound: MemberRef { + module: step.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{step}"), + }, + complete: (step % 3 != 2).then(|| MemberRef { + module: step.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{step}"), + }), + } +} + +pub(super) fn enc_model_use(value: &ModelUse) -> Value { + adt( + "ModelUse", + "ModelUseOf", + vec![ + enc_member(&value.member), + list(value.type_arguments.iter().map(enc_type).collect()), + ], + ) +} + +pub(super) fn example_model_use(step: usize) -> ModelUse { + ModelUse { + member: MemberRef { + module: step.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{step}"), + }, + type_arguments: if step % 3 == 2 { + Vec::new() + } else { + (step..step + 2) + .map(|next| { + if next.is_multiple_of(2) { + SemanticType::Nat + } else { + SemanticType::Bytes + } + }) + .collect() + }, + } +} + +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), + ], + ) +} + +pub(super) fn example_realization_state(step: usize) -> RealizationState { + RealizationState { + name: format!("s{step}"), + r#type: if step.is_multiple_of(2) { + SemanticType::Nat + } else { + SemanticType::Bytes + }, + initial: SemanticTerm::Nat { + value: step.to_string(), + }, + } +} + +pub(super) fn enc_realization_rule(value: &RealizationRule) -> Value { + adt( + "RealizationRule", + "RealizationRuleOf", + vec![ + text(&value.name), + enc_term(&value.guard), + enc_term(&value.action), + ], + ) +} + +pub(super) 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(), + }, + } +} + +pub(super) fn enc_statistical_scheme(value: &StatisticalScheme) -> Value { + adt( + "StatisticalScheme", + &format!("StatisticalScheme{value:?}"), + Vec::new(), + ) +} + +pub(super) const ALL_STATISTICAL_SCHEME: &[StatisticalScheme] = &[StatisticalScheme::LinearScoring]; + +pub(super) fn example_statistical_scheme(step: usize) -> StatisticalScheme { + ALL_STATISTICAL_SCHEME[step % ALL_STATISTICAL_SCHEME.len()] +} + +pub(super) fn enc_neural_architecture(value: &NeuralArchitecture) -> Value { + adt( + "NeuralArchitecture", + &format!("NeuralArchitecture{value:?}"), + Vec::new(), + ) +} + +pub(super) const ALL_NEURAL_ARCHITECTURE: &[NeuralArchitecture] = + &[NeuralArchitecture::IntegerFeedforward]; + +pub(super) fn example_neural_architecture(step: usize) -> NeuralArchitecture { + ALL_NEURAL_ARCHITECTURE[step % ALL_NEURAL_ARCHITECTURE.len()] +} + +pub(super) 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)] +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 step") + 1, + outputs: u64::try_from(rest).expect("a step") + 1, + weights: MemberRef { + module: rest.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + bias: MemberRef { + module: rest.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + }, + 1 => NeuralLayer::Relu, + _ => NeuralLayer::Requantize { + shift: u64::try_from(rest).expect("a step") + 1, + minimum: format!("s{rest}"), + maximum: format!("s{rest}"), + }, + } +} + +pub(super) fn enc_neural_decoder(value: &NeuralDecoder) -> Value { + match value { + NeuralDecoder::Argmax { labels } => adt( + "NeuralDecoder", + "NeuralDecoderArgmax", + vec![list(labels.iter().map(enc_term).collect())], + ), + NeuralDecoder::Function { binder, body } => adt( + "NeuralDecoder", + "NeuralDecoderFunction", + vec![text(binder), enc_term(body)], + ), + } +} + +#[allow(clippy::too_many_lines)] +pub(super) 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: next.to_string(), + }) + .collect() + }, + }, + _ => NeuralDecoder::Function { + binder: format!("s{rest}"), + body: SemanticTerm::Nat { + value: rest.to_string(), + }, + }, + } +} + +pub(super) 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)] +pub(super) fn example_composite_junction(step: usize) -> CompositeJunction { + let rest = step / 3; + match step % 3 { + 0 => CompositeJunction::Unconditional, + 1 => CompositeJunction::Proved { + evidence: MemberRef { + module: rest.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + }, + _ => CompositeJunction::Checked, + } +} + +pub(super) fn enc_composite_form(value: &CompositeForm) -> Value { + match value { + CompositeForm::Sequence { stages, junctions } => adt( + "CompositeForm", + "CompositeFormSequence", + vec![ + list(stages.iter().map(enc_model_use).collect()), + list(junctions.iter().map(enc_composite_junction).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)] +pub(super) 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(example_model_use).collect() + }, + junctions: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(example_composite_junction).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), + }, + } +} + +pub(super) 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(enc_realization_rule).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(enc_term).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(enc_neural_layer).collect()), + enc_neural_decoder(decoder), + ], + ), + RealizationDescriptor::Composite { form } => adt( + "RealizationDescriptor", + "RealizationDescriptorComposite", + vec![enc_composite_form(form)], + ), + } +} + +#[allow(clippy::too_many_lines)] +pub(super) 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(example_realization_rule).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 step") + 1, + width_evidence: MemberRef { + module: rest.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + weights: MemberRef { + module: rest.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + bias: MemberRef { + module: rest.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + labels: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2) + .map(|next| SemanticTerm::Nat { + value: next.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 step") + 1, + width_evidence: MemberRef { + module: rest.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + layers: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(example_neural_layer).collect() + }, + decoder: example_neural_decoder(rest), + }, + _ => RealizationDescriptor::Composite { + form: example_composite_form(rest), + }, + } +} + +pub(super) 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)] +pub(super) fn example_evidence_claim(step: usize) -> EvidenceClaim { + let rest = step / 5; + match step % 5 { + 0 => EvidenceClaim::DatasetAgreement { + dataset: MemberRef { + module: rest.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + comparison: MemberRef { + module: rest.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + comparison_sound: MemberRef { + 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.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + }, + 1 => EvidenceClaim::EquivalentTo { + reference: example_model_use(rest), + theorem: MemberRef { + module: rest.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + }, + 2 => EvidenceClaim::InitialInvariant { + theorem: MemberRef { + module: rest.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + }, + 3 => EvidenceClaim::PreservesInvariant { + theorem: MemberRef { + module: rest.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + }, + _ => EvidenceClaim::SatisfiesContract { + theorem: MemberRef { + module: rest.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{rest}"), + }, + }, + } +} + +pub(super) 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(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()), + ], + ), + 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(enc_realization_state)), + 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(enc_evidence_claim).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(enc_model_use).collect()), + list(entry.iter().map(enc_member).collect()), + list(axioms.iter().map(|item| text(item)).collect()), + ], + ), + other => panic!("not a declaration of this module: {other:?}"), + } +} + +#[allow(clippy::too_many_lines)] +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 step") + 1, + schema: example_artifact_schema(rest), + r#type: if rest.is_multiple_of(2) { + SemanticType::Nat + } else { + SemanticType::Bytes + }, + axioms: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(|next| format!("s{next}")).collect() + }, + }, + 1 => SemanticDeclaration::Contract { + name: format!("s{rest}"), + type_parameters: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(|next| format!("s{next}")).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.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{rest}"), + }), + postcondition: (rest % 3 != 2).then(|| MemberRef { + module: rest.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{rest}"), + }), + invariant: (rest % 3 != 2).then(|| MemberRef { + module: rest.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{rest}"), + }), + validators: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(example_contract_validator).collect() + }, + axioms: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(|next| format!("s{next}")).collect() + }, + }, + 2 => SemanticDeclaration::Realization { + name: format!("s{rest}"), + type_parameters: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(|next| format!("s{next}")).collect() + }, + input: example_model_binder(rest), + 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.is_multiple_of(2), + axioms: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(|next| format!("s{next}")).collect() + }, + }, + 3 => SemanticDeclaration::Evidence { + name: format!("s{rest}"), + type_parameters: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(|next| format!("s{next}")).collect() + }, + contract: example_model_use(rest), + realization: example_model_use(rest), + claims: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(example_evidence_claim).collect() + }, + axioms: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(|next| format!("s{next}")).collect() + }, + }, + _ => SemanticDeclaration::Model { + name: format!("s{rest}"), + type_parameters: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(|next| format!("s{next}")).collect() + }, + contract: example_model_use(rest), + realization: example_model_use(rest), + evidence: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(example_model_use).collect() + }, + entry: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2) + .map(|next| MemberRef { + module: next.is_multiple_of(2).then(|| "M".to_owned()), + name: format!("m{next}"), + }) + .collect() + }, + axioms: if rest % 3 == 2 { + Vec::new() + } else { + (rest..rest + 2).map(|next| format!("s{next}")).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 + +pub(super) 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 584f74624a..087d8568fa 100644 --- a/crates/conformance/src/cases/repository.rs +++ b/crates/conformance/src/cases/repository.rs @@ -1091,7 +1091,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(), 502, "§31 has 502 rows"); + assert_eq!(table.len(), 503, "§31 has 503 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 7fc3ba738e..168b6119dd 100644 --- a/crates/conformance/tests/conformance.rs +++ b/crates/conformance/tests/conformance.rs @@ -2440,6 +2440,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 51f30dd06a..2f72fa7791 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 481d9d631d..e5cdc4d24a 100644 --- a/model/ids.toml +++ b/model/ids.toml @@ -2930,6 +2930,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`: `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" +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 f67b601076..a9b642a17c 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 ebb4eaa4af..11b6089fbd 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() != 502 { - return Err(format!("RP-07: the §31 table has {} rows, not 502", rows.len()).into()); + if rows.len() != 503 { + return Err(format!("RP-07: the §31 table has {} rows, not 503", 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.