From 8f1af48139c996cda9a36ae50e2cc4a95e6fb867 Mon Sep 17 00:00:00 2001 From: humuhumu33 Date: Tue, 10 Nov 2026 14:49:29 +0000 Subject: [PATCH 1/2] BS-34: the register row, scenario, and case of the build manifest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A slice of the build driver as source (#274), on release/v0.4 with BS-21: the row (register 479 -> 480, the §31 table, the RP-07 check and its case), the scenario, the §17.23 prose, the CHANGELOG entry, the README's claim, the CI part and its Intel lane, and the case, conformance_bs_34, which holds ManifestText.buildManifest to the file bytes of BuildManifest::to_json on hand-built manifests, on the 26 committed build manifests, each the oracle's text of its own fields, and on seeded ones, with 10 planted defects each named by its vector. VERIFICATION.md records the first run: the evaluator agrees on 236 runs, rustc on 1,036, and every plant is detected. Co-Authored-By: Claude Opus 5.5 --- .github/bdd-parts.json | 3 + .github/intel-host-lanes.json | 2 +- .github/vv-rows.json | 9 + CHANGELOG.md | 5 + CONFORMANCE.md | 1 + README.md | 4 +- SPEC.md | 16 +- VERIFICATION.md | 41 ++ crates/conformance/src/cases/bootstrap.rs | 2 + .../src/cases/bootstrap/manifest_text.rs | 635 ++++++++++++++++++ crates/conformance/src/cases/repository.rs | 2 +- crates/conformance/tests/conformance.rs | 5 + features/suites/bootstrap.feature | 7 + model/ids.toml | 6 + xtask/src/spec_links.rs | 4 +- 15 files changed, 735 insertions(+), 7 deletions(-) create mode 100644 crates/conformance/src/cases/bootstrap/manifest_text.rs diff --git a/.github/bdd-parts.json b/.github/bdd-parts.json index 4d6dae137a..6d46ceec51 100644 --- a/.github/bdd-parts.json +++ b/.github/bdd-parts.json @@ -40,6 +40,9 @@ "bootstrap-terms": [ "BS-10" ], + "bootstrap-manifest-text": [ + "BS-34" + ], "bootstrap-tooling-latex": [ "BS-20" ], diff --git a/.github/intel-host-lanes.json b/.github/intel-host-lanes.json index 5e4002048e..606fad9e43 100644 --- a/.github/intel-host-lanes.json +++ b/.github/intel-host-lanes.json @@ -2,7 +2,7 @@ "producer": ["honesty"], "lanes": { "lower": ["bootstrap-lower"], - "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"], + "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-manifest-text"], "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 11170d61b5..f6981c7698 100644 --- a/.github/vv-rows.json +++ b/.github/vv-rows.json @@ -62,6 +62,15 @@ "memory_kib": "", "hints": "" }, + { + "part": "bdd-bootstrap-manifest-text", + "recipes": "bdd", + "examples_part": "", + "bdd_part": "bootstrap-manifest-text", + "width": "", + "memory_kib": "", + "hints": "" + }, { "part": "bdd-bootstrap-tooling-latex", "recipes": "bdd", diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e9f352fb4..83b6f8d9e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,11 @@ workspace carried at those versions without a tag. ## Unreleased +- The build manifest as language-1.2 source (SPEC.md §17.23, §21.6, `BS-34`, + #274; no new diagnostic code, no change to the language-1.2 identity). + `buildManifest` of `ManifestText` returns the file bytes of + `BuildManifest::to_json` through the standard library's `Json` writer, and + admits `recursion` through it. The register is 480 IDs. - The structural grammar as language-1.2 source, first slice of the front end (SPEC.md §17.23, §15.1, §15.2, `BS-21`, #269; no new diagnostic code, no change to the language-1.2 identity). `parseModule` of `StructuralGrammar` reads the diff --git a/CONFORMANCE.md b/CONFORMANCE.md index cb85cdcdd3..69d46cf7b8 100644 --- a/CONFORMANCE.md +++ b/CONFORMANCE.md @@ -78,6 +78,7 @@ the error registry does not sanction (R5, `ERRORS.md`). | `BS-16` | `build` | The GNAF request validation of SPEC.md §17.15 (`gnaf::validate`, with `universe_size`) is language-1.2 source in the `bootstrap/` project: `validateRequest` of `GnafValidate` is a production root eligible for `rust-std` with exactly its declared effects, over the projection of a request that validation reads (the length of the domain, the machine, the carrier's kind with each plan's preparations and the thresholds, the completeness evidence, the objective, the claim's class, and the scope) as first-order data, and returns the first violated rule in the model's order as the oracle's `serde_json` bytes, or nothing; on every host, its rendered `rust-std` package under the pinned rustc agrees with the Rust oracle `gnaf::validate` on the acceptance and on the rejection, to the byte, on the committed requests of `compiler/gnaf/`, the requests the committed certificate fixtures name, hand-built requests that reach each rejection, and seeded mutants of the committed requests; on the normative host, the root's lowered program under the calculus evaluator agrees with the oracle on the same corpus, each planted defect in the source is detected, and the certified package the production export publishes for the project is the committed one; loading a request (`gnaf::load`), the universe identity, the answer, and certification are outside the claim. | | `BS-20` | `build` | The canonical LaTeX of a tooling module of SPEC.md §17.20 (`backend::tooling::render_latex`: the fixed document frame and, for each declaration in order, its title, its kind, and the lines the Lean printer of the same file spells for its types, signatures, and terms, every line escaped by `tex_escape`) is language-1.2 source in the `bootstrap/` project: `renderToolingLatex` of `ToolingLatex`, over the tooling module as first-order data with each list carried as a chain of its own `Nil` and `Cons` constructors and with the typings the checker infers as an argument, writing through the standard library's `Buffer` with an explicit capacity, is a production root eligible for `rust-std` with exactly its declared effects; its rendered `rust-std` package under the pinned rustc and its lowered program under the calculus evaluator agree with the Rust oracle on the text, to the byte, and on the refusal of a write past the capacity, on the committed tooling modules (whose committed `.tex` is equal to the text), on hand-built modules that reach every declaration, type, signature, and term form and every byte class of the escaper, and on seeded mutants, every planted defect is detected, and the certified package the production export publishes for the project is the committed one; the checker, the decoder of the module, and the source map of the emitted pieces stay in the host. | | `BS-21` | `build` | The fixed structural grammar of SPEC.md §15.1 and §15.2 (`grammar::structural::parse_module`: the module header, the blocks and declarations, the axiom policies, the sentences, the structured proof environments, and the closed data forms, with the coverage rows of every structural atom it consumes) is language-1.2 source in the `bootstrap/` project: `parseModule` of `StructuralGrammar`, for the atoms `scanSource` of `BS-03` returns, the path, the name the path gives the module, and `max_scope_depth`, is a production root eligible for `rust-std` with exactly its declared effects, none of them `recursion`, and has no part of its certificate beyond 3,145,728 bytes; it returns the module with its rows, or the refusal's code, message, and span, and on 267 hand-built vectors, 146 of them refused, which reach every refusal of `parse_module`, and on the committed modules, whole or by the atoms of both their ends, its lowered program under the calculus evaluator on the normative host and its rendered package under the pinned rustc on every host agree with the oracle to the byte; on the normative host both also agree on 2,000 seeded edits of those texts, each of 44 planted defects in the source is detected by the one vector it names, and the certified package the production export publishes for the project is the committed one; the grammars of mathematical islands, propositions, and proof sentences, which read the lexicon's closure, and the interpretation of the module this root returns are outside the claim. | +| `BS-34` | `build` | The build manifest of SPEC.md §21.6 in the canonical JSON of §21.7 (`artifact::manifest::BuildManifest::to_json` written as a file: the specification, the compiler version and semantics ID, the language, the project, the source, semantic, and build IDs, the pinned Lean toolchain, the selection and the module rows in their order, a module's origin only when it has one, and the input and output rows sorted by kind, path, length, and digest, each digest in lower-case hex) is language-1.2 source in the `bootstrap/` project, as the production root `buildManifest` of `ManifestText` over the standard library's `Json` writer, 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 hand-built manifests, which reach every key of the row order, lengths across a byte, a module's origin, and escapes, on every committed build manifest, each of which is the oracle's text of its own fields, and on seeded manifests; each planted defect in the source is detected by the one vector it names, and the certified packages the production export publishes for the project are the committed ones; gathering the rows of a build and hashing its files are outside the claim. | ## calculus diff --git a/README.md b/README.md index 46578d3f5c..be6597e2c6 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 479 registered conformance IDs have their named tests; `just vv` checks them with the pinned toolchain installed. +All 480 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, and the structural grammar, 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-21` | `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, 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-34` | `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 3ce36752c0..333f2ea977 100644 --- a/SPEC.md +++ b/SPEC.md @@ -8753,6 +8753,19 @@ the public marker and the visibility line, and the trimming of a line) are each pinned Lean the production export (§24.7) certifies the root beside the others and its package is the committed one. +The build manifest (§21.6) is a component of the build driver as source (`BS-34`, issue 274), +the module `ManifestText`, with one production root for `rust-std` over the standard library's +canonical JSON writer: + +| Root | Takes | Returns | Oracle | +| --- | --- | --- | --- | +| `LexLeanBoot.ManifestText.buildManifest` | a build manifest | its canonical JSON file bytes | `artifact::manifest::BuildManifest::to_json` | + +`buildManifest` builds the manifest's JSON value and writes it with `Json`'s `writeJsonFile`, which +orders the keys. The input and output rows are sorted with the stable merge sort of `Order` by an +order-preserving key of their kind, path, big-endian length, and digest. The root admits `recursion` +through the JSON writer. Gathering the rows of a build and hashing its files stay in the host. + ## 18. Lean backend ### 18.1 Output contract @@ -11675,6 +11688,7 @@ Every row below is normative, has honesty level `build`, and MUST be copied byte | `BS-16` | `bootstrap` | The GNAF request validation of SPEC.md §17.15 (`gnaf::validate`, with `universe_size`) is language-1.2 source in the `bootstrap/` project: `validateRequest` of `GnafValidate` is a production root eligible for `rust-std` with exactly its declared effects, over the projection of a request that validation reads (the length of the domain, the machine, the carrier's kind with each plan's preparations and the thresholds, the completeness evidence, the objective, the claim's class, and the scope) as first-order data, and returns the first violated rule in the model's order as the oracle's `serde_json` bytes, or nothing; on every host, its rendered `rust-std` package under the pinned rustc agrees with the Rust oracle `gnaf::validate` on the acceptance and on the rejection, to the byte, on the committed requests of `compiler/gnaf/`, the requests the committed certificate fixtures name, hand-built requests that reach each rejection, and seeded mutants of the committed requests; on the normative host, the root's lowered program under the calculus evaluator agrees with the oracle on the same corpus, each planted defect in the source is detected, and the certified package the production export publishes for the project is the committed one; loading a request (`gnaf::load`), the universe identity, the answer, and certification are outside the claim. | §17.15, §17.23 | | `BS-20` | `bootstrap` | The canonical LaTeX of a tooling module of SPEC.md §17.20 (`backend::tooling::render_latex`: the fixed document frame and, for each declaration in order, its title, its kind, and the lines the Lean printer of the same file spells for its types, signatures, and terms, every line escaped by `tex_escape`) is language-1.2 source in the `bootstrap/` project: `renderToolingLatex` of `ToolingLatex`, over the tooling module as first-order data with each list carried as a chain of its own `Nil` and `Cons` constructors and with the typings the checker infers as an argument, writing through the standard library's `Buffer` with an explicit capacity, is a production root eligible for `rust-std` with exactly its declared effects; its rendered `rust-std` package under the pinned rustc and its lowered program under the calculus evaluator agree with the Rust oracle on the text, to the byte, and on the refusal of a write past the capacity, on the committed tooling modules (whose committed `.tex` is equal to the text), on hand-built modules that reach every declaration, type, signature, and term form and every byte class of the escaper, and on seeded mutants, every planted defect is detected, and the certified package the production export publishes for the project is the committed one; the checker, the decoder of the module, and the source map of the emitted pieces stay in the host. | §17.20, §17.23 | | `BS-21` | `bootstrap` | The fixed structural grammar of SPEC.md §15.1 and §15.2 (`grammar::structural::parse_module`: the module header, the blocks and declarations, the axiom policies, the sentences, the structured proof environments, and the closed data forms, with the coverage rows of every structural atom it consumes) is language-1.2 source in the `bootstrap/` project: `parseModule` of `StructuralGrammar`, for the atoms `scanSource` of `BS-03` returns, the path, the name the path gives the module, and `max_scope_depth`, is a production root eligible for `rust-std` with exactly its declared effects, none of them `recursion`, and has no part of its certificate beyond 3,145,728 bytes; it returns the module with its rows, or the refusal's code, message, and span, and on 267 hand-built vectors, 146 of them refused, which reach every refusal of `parse_module`, and on the committed modules, whole or by the atoms of both their ends, its lowered program under the calculus evaluator on the normative host and its rendered package under the pinned rustc on every host agree with the oracle to the byte; on the normative host both also agree on 2,000 seeded edits of those texts, each of 44 planted defects in the source is detected by the one vector it names, and the certified package the production export publishes for the project is the committed one; the grammars of mathematical islands, propositions, and proof sentences, which read the lexicon's closure, and the interpretation of the module this root returns are outside the claim. | §17.23, §15.1, §15.2 | +| `BS-34` | `bootstrap` | The build manifest of SPEC.md §21.6 in the canonical JSON of §21.7 (`artifact::manifest::BuildManifest::to_json` written as a file: the specification, the compiler version and semantics ID, the language, the project, the source, semantic, and build IDs, the pinned Lean toolchain, the selection and the module rows in their order, a module's origin only when it has one, and the input and output rows sorted by kind, path, length, and digest, each digest in lower-case hex) is language-1.2 source in the `bootstrap/` project, as the production root `buildManifest` of `ManifestText` over the standard library's `Json` writer, 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 hand-built manifests, which reach every key of the row order, lengths across a byte, a module's origin, and escapes, on every committed build manifest, each of which is the oracle's text of its own fields, and on seeded manifests; each planted defect in the source is detected by the one vector it names, and the certified packages the production export publishes for the project are the committed ones; gathering the rows of a build and hashing its files are outside the claim. | §17.23, §21.6, §21.7 | | `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 | @@ -11691,7 +11705,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:** 479. +**Total required capability IDs:** 480. 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 7c3c34cf2c..33ee4f4d5b 100644 --- a/VERIFICATION.md +++ b/VERIFICATION.md @@ -11089,6 +11089,47 @@ writes them); `cargo clippy -p repo-conformance -p xtask --all-targets --all-features -D warnings`, `validate-model` (461 ids), `validate-spec-links` (461 rows), `check-test-inventory`, and the five `bdd` meta-gate tests pass. +### the build manifest is source (BS-34) + +`BS-34` holds the production root `buildManifest` of `LexLeanBoot.ManifestText` +(`bootstrap/src/ManifestText.lex.tex`) to the file bytes of +`artifact::manifest::BuildManifest::to_json`: the specification, the compiler +version and semantics ID, the language, the project, the source, semantic, and +build IDs, the pinned Lean toolchain, the selection and the module rows in their +order, a module's origin only when it has one, and the input and output rows +sorted by kind, path, length, and digest. The root builds the manifest's JSON +value and writes it with the standard library's `writeJsonFile`, which orders +the keys; the rows are sorted with the stable merge sort of `Order` by a key of +the kind and the path, each with its NUL bytes escaped and a two-byte end, the +big-endian length, and the digest. The root admits exactly `allocation`, +`overflow`, and `recursion`, the last through the JSON writer. The oracle is the +existing public code of `manifest.rs`; no Rust outside the case changes. The +case holds the root to the oracle on hand-built manifests that reach every key +of the row order, lengths across a byte, a kind that is a prefix of another, a +module's origin, and escapes; on every committed `expected/build/manifest.json`, +each of which the case asserts is the oracle's text of its own fields; and on +seeded manifests. Each planted defect names the one vector that catches it, and +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, on a copy of the project whose +only entrypoint is `ManifestText`: `lexlean check`, `lexlean build`, and +`lexlean verify` pass, and the eligibility report gives the root exactly +`allocation`, `overflow`, and `recursion`. The register agrees with the §31 +table on 480 IDs, by the same parse `validate-spec-links` makes. + +The case was first compiled and run on the normative host over +`release/v0.4` at `c66f83d05` (`cargo test -p repo-conformance --test +conformance -- conformance_bs_34`, 102 s). Its corpus is 10 named vectors, the +26 committed build manifests, and 200 and 1,000 seeded runs. The evaluator +agrees with the oracle on 236 manifests, the rendered package under the pinned +rustc on 1,036 runs, and each of the 10 planted defects is detected by its own +vector. The first runs found no fault of the writer: Lean asked for exactly the +axioms the module now declares. The case then stops at the stack-bound step, +`bootstrap/build_manifest is no package of the committed exports`, as each +bootstrap member did before its regeneration, which produces the package and +measures the root's stack bound. + ## 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/crates/conformance/src/cases/bootstrap.rs b/crates/conformance/src/cases/bootstrap.rs index b3520a1d91..6314a198b9 100644 --- a/crates/conformance/src/cases/bootstrap.rs +++ b/crates/conformance/src/cases/bootstrap.rs @@ -22,6 +22,7 @@ use crate::rust_packages; use crate::support::{self, P}; mod gnaf_validate; +mod manifest_text; mod runtime_validate; mod rust_assemble; mod rust_bodies; @@ -2459,6 +2460,7 @@ fn case(id: &str) { // §17.23, §17.20: the canonical LaTeX of a tooling module. "BS-20" => tooling_latex::case(), "BS-21" => structural_grammar::case(), + "BS-34" => manifest_text::case(), other => panic!("no bootstrap case is wired for {other}"), } } diff --git a/crates/conformance/src/cases/bootstrap/manifest_text.rs b/crates/conformance/src/cases/bootstrap/manifest_text.rs new file mode 100644 index 0000000000..3a7bbcc2ee --- /dev/null +++ b/crates/conformance/src/cases/bootstrap/manifest_text.rs @@ -0,0 +1,635 @@ +//! `BS-34` (SPEC.md §17.23, §21.6, §21.7): the build manifest as +//! language-1.2 source, `LexLeanBoot.ManifestText`, held to the byte to +//! `lexlean::artifact::manifest::BuildManifest::to_json` written as a file. +//! +//! `buildManifest` writes a manifest through the standard library's canonical +//! JSON writer: the specification, the compiler, the language, the project, +//! the three IDs, the pinned Lean toolchain, the selection and the modules in +//! their order, and the input and output rows sorted by kind, path, length, +//! and digest. Every committed `expected/build/manifest.json` is a run, and +//! each is the oracle's text of its own fields. +//! +//! Each planted defect names the one vector that catches it. + +use std::collections::{BTreeMap, BTreeSet}; + +use lexlean::artifact::manifest::{BuildManifest, FileRow, ModuleRow}; +use lexlean::calculus::Value; +use lexlean::Sha256Digest; +use serde_json::Value as Json2; + +use super::rust_validate::{eligibility_of, rustc_differential}; +use super::{bytes, list, option, text, texts, Run, Seeded}; +use crate::production_export as harness; +use crate::support::{self, repo_root}; + +const MODULE: &str = "LexLeanBoot.ManifestText"; +const ROOTS: [(&str, &[&str]); 1] = [("buildManifest", &["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; +/// Seeded runs of the root under the evaluator, and under rustc. +const EVALUATOR_SEEDED: usize = 200; +const RUSTC_SEEDED: usize = 1_000; + +// ------------------------------------------------------------- the encoders + +fn adt(fields: Vec) -> Value { + Value::Adt { + constructor: 0, + fields, + } +} + +fn nat(value: usize) -> Value { + Value::Nat { + value: value.to_string(), + } +} + +fn enc_row(row: &FileRow) -> Value { + adt(vec![ + text(&row.kind), + text(&row.path), + nat(row.byte_length), + bytes(&row.sha256.0), + ]) +} + +fn enc_module(row: &ModuleRow) -> Value { + adt(vec![ + text(&row.module), + text(&row.lean_module), + text(&row.source_path), + option(row.origin.as_deref().map(text)), + ]) +} + +fn enc(manifest: &BuildManifest) -> Value { + adt(vec![ + text(&manifest.language), + text(&manifest.compiler_version), + bytes(&manifest.semantics_id.0), + text(&manifest.project), + bytes(&manifest.source_id.0), + bytes(&manifest.semantic_id.0), + bytes(&manifest.build_id.0), + texts(&manifest.selection), + list(manifest.modules.iter().map(enc_module).collect()), + list(manifest.inputs.iter().map(enc_row).collect()), + list(manifest.outputs.iter().map(enc_row).collect()), + ]) +} + +fn manifest_run(manifest: &BuildManifest) -> Run { + ( + vec![enc(manifest)], + serde_json::to_value(bytes(&manifest.to_json().to_file_bytes())).expect("a value is JSON"), + ) +} + +// ------------------------------------------------------------------ corpora + +fn digest(json: &Json2) -> Sha256Digest { + Sha256Digest::from_hex(json.as_str().expect("a digest")).expect("a digest") +} + +fn string(json: &Json2) -> String { + json.as_str().expect("a string").to_owned() +} + +fn rows_of(json: &Json2) -> Vec { + json.as_array() + .expect("rows") + .iter() + .map(|row| FileRow { + kind: string(&row["kind"]), + path: string(&row["path"]), + byte_length: usize::try_from(row["byte_length"].as_u64().expect("a length")) + .expect("usize"), + sha256: digest(&row["sha256"]), + }) + .collect() +} + +fn manifest_of(json: &Json2) -> BuildManifest { + BuildManifest { + language: string(&json["language"]), + compiler_version: string(&json["compiler"]["version"]), + semantics_id: digest(&json["compiler"]["semantics_id"]), + project: string(&json["project"]), + source_id: digest(&json["source_id"]), + semantic_id: digest(&json["semantic_id"]), + build_id: digest(&json["build_id"]), + selection: json["selection"] + .as_array() + .expect("a selection") + .iter() + .map(string) + .collect(), + modules: json["modules"] + .as_array() + .expect("modules") + .iter() + .map(|row| ModuleRow { + module: string(&row["module"]), + lean_module: string(&row["lean_module"]), + source_path: string(&row["source_path"]), + origin: row.get("origin").map(string), + }) + .collect(), + inputs: rows_of(&json["inputs"]), + outputs: rows_of(&json["outputs"]), + } +} + +fn manifests_under(dir: &std::path::Path, out: &mut Vec) { + let Ok(entries) = std::fs::read_dir(dir) else { + return; + }; + let mut entries: Vec<_> = entries.flatten().collect(); + entries.sort_by_key(std::fs::DirEntry::file_name); + for entry in entries { + let name = entry.file_name().to_string_lossy().into_owned(); + let path = entry.path(); + if path.is_dir() { + if !matches!( + name.as_str(), + ".git" | "target" | ".lexlean" | "node_modules" + ) { + manifests_under(&path, out); + } + } else if name == "manifest.json" && path.ends_with("expected/build/manifest.json") { + out.push(path); + } + } +} + +/// Every committed build manifest, each checked to be the oracle's text of +/// its own fields. +fn committed() -> Vec { + let mut paths = Vec::new(); + manifests_under(repo_root().as_std_path(), &mut paths); + paths + .iter() + .map(|path| { + let committed_bytes = std::fs::read(path).expect("a committed manifest"); + let json: Json2 = serde_json::from_slice(&committed_bytes).expect("manifest JSON"); + let manifest = manifest_of(&json); + assert_eq!( + manifest.to_json().to_file_bytes(), + committed_bytes, + "{}: the committed manifest is the oracle's text of its own fields", + path.display() + ); + manifest + }) + .collect() +} + +// ------------------------------------------------------------------ vectors + +fn sha(byte: u8) -> Sha256Digest { + let mut out = [0u8; 32]; + for (index, slot) in out.iter_mut().enumerate() { + *slot = byte.wrapping_add(u8::try_from(index).expect("a byte")); + } + Sha256Digest(out) +} + +fn row(kind: &str, path: &str, byte_length: usize, digest_byte: u8) -> FileRow { + FileRow { + kind: kind.to_owned(), + path: path.to_owned(), + byte_length, + sha256: sha(digest_byte), + } +} + +fn module(name: &str, origin: Option<&str>) -> ModuleRow { + ModuleRow { + module: name.to_owned(), + lean_module: format!("Demo.{name}"), + source_path: format!("src/{name}.lex.tex"), + origin: origin.map(str::to_owned), + } +} + +fn empty() -> BuildManifest { + BuildManifest { + language: "1.2".to_owned(), + compiler_version: "0.4.0".to_owned(), + semantics_id: sha(0x10), + project: "demo".to_owned(), + source_id: sha(0x20), + semantic_id: sha(0x30), + build_id: sha(0x40), + selection: Vec::new(), + modules: Vec::new(), + inputs: Vec::new(), + outputs: Vec::new(), + } +} + +struct Vector { + label: &'static str, + run: Run, +} + +fn named() -> Vec { + let mut out = Vec::new(); + let mut add = |label: &'static str, manifest: BuildManifest| { + out.push(Vector { + label, + run: manifest_run(&manifest), + }); + }; + add("an empty manifest", empty()); + add( + "inputs out of order", + BuildManifest { + inputs: vec![ + row("source", "src/B.lex.tex", 10, 1), + row("lock", "lexlean.lock", 20, 2), + row("source", "src/A.lex.tex", 30, 3), + ], + ..empty() + }, + ); + add( + "outputs out of order", + BuildManifest { + outputs: vec![row("tex", "b.tex", 1, 1), row("map", "a.map.json", 2, 2)], + ..empty() + }, + ); + add( + "rows of one kind and path", + BuildManifest { + inputs: vec![row("source", "f", 10, 1), row("source", "f", 9, 2)], + ..empty() + }, + ); + add( + "lengths across a byte", + BuildManifest { + inputs: vec![row("source", "f", 256, 1), row("source", "f", 255, 2)], + ..empty() + }, + ); + add( + "rows equal but the digest", + BuildManifest { + inputs: vec![row("source", "f", 1, 0x90), row("source", "f", 1, 0x10)], + ..empty() + }, + ); + add( + "a kind that is a prefix", + BuildManifest { + inputs: vec![row("a-b", "a", 1, 1), row("a", "z", 1, 2)], + ..empty() + }, + ); + add( + "a module from a source package", + BuildManifest { + modules: vec![module("Std", Some("lexlean.stdlib"))], + ..empty() + }, + ); + add( + "modules in their order", + BuildManifest { + modules: vec![module("Zeta", None), module("Alpha", None)], + selection: vec!["Zeta".to_owned(), "Alpha".to_owned()], + ..empty() + }, + ); + add( + "escapes in a path", + BuildManifest { + outputs: vec![row("tex", "a \"b\"\\c\n\u{1}", 3, 3)], + ..empty() + }, + ); + out +} + +// ------------------------------------------------------------------- seeded + +const KINDS: &[&str] = &["source", "lock", "lean", "tex", "map", "a", "a-b", ""]; +const PIECES: &[&str] = &["a", "z", "/", ".", "-", "\"", "\\", "\n", "\u{e9}"]; + +fn drawn_text(seeded: &mut Seeded) -> String { + let count = seeded.below(6); + (0..count).map(|_| *seeded.pick(PIECES)).collect() +} + +fn drawn_sha(seeded: &mut Seeded) -> Sha256Digest { + let mut out = [0u8; 32]; + for slot in &mut out { + *slot = u8::try_from(seeded.below(256)).expect("a byte"); + } + Sha256Digest(out) +} + +fn drawn_rows(seeded: &mut Seeded) -> Vec { + (0..seeded.below(5)) + .map(|_| FileRow { + kind: (*seeded.pick(KINDS)).to_owned(), + path: drawn_text(seeded), + byte_length: *seeded.pick(&[0, 1, 255, 256, 65_536, 4_194_304]), + sha256: drawn_sha(seeded), + }) + .collect() +} + +fn drawn_manifest(seeded: &mut Seeded) -> BuildManifest { + BuildManifest { + language: (*seeded.pick(&["1.1", "1.2"])).to_owned(), + compiler_version: drawn_text(seeded), + semantics_id: drawn_sha(seeded), + project: drawn_text(seeded), + source_id: drawn_sha(seeded), + semantic_id: drawn_sha(seeded), + build_id: drawn_sha(seeded), + selection: (0..seeded.below(3)).map(|_| drawn_text(seeded)).collect(), + modules: (0..seeded.below(3)) + .map(|_| ModuleRow { + module: drawn_text(seeded), + lean_module: drawn_text(seeded), + source_path: drawn_text(seeded), + origin: if seeded.chance(30) { + Some(drawn_text(seeded)) + } else { + None + }, + }) + .collect(), + inputs: drawn_rows(seeded), + outputs: drawn_rows(seeded), + } +} + +fn seeded_runs(count: usize, seed: u64) -> Vec { + let mut seeded = Seeded(seed); + (0..count) + .map(|_| manifest_run(&drawn_manifest(&mut seeded))) + .collect() +} + +// ------------------------------------------------------------------- plants + +struct Plant { + label: &'static str, + site: &'static str, + replacement: &'static str, + vector: &'static str, +} + +const PLANTS: &[Plant] = &[ + Plant { + label: "the rows are not sorted", + site: "(LexLeanStd.Order::reverseList [FileRow] (rowsSorted rows))", + replacement: "(LexLeanStd.Order::reverseList [FileRow] rows)", + vector: "inputs out of order", + }, + Plant { + label: "the length is not in the key", + site: "(bigEndian (project row byteLength) 8)", + replacement: "0x", + vector: "rows of one kind and path", + }, + Plant { + label: "the length key is little-endian", + site: "(cat (LexLeanStd.Numeral::pick (LexLeanStd.Numeral::byteValues) (prim remainder (first state) 256 0 : Nat)) (second state))", + replacement: "(cat (second state) (LexLeanStd.Numeral::pick (LexLeanStd.Numeral::byteValues) (prim remainder (first state) 256 0 : Nat)))", + vector: "lengths across a byte", + }, + Plant { + label: "the digest is not in the key", + site: "(bigEndian (project row byteLength) 8)) (project row digest))", + replacement: "(bigEndian (project row byteLength) 8)) 0x)", + vector: "rows equal but the digest", + }, + Plant { + label: "the kind key has no end", + site: "0x0001) 0x0000)", + replacement: "0x0001) 0x)", + vector: "a kind that is a prefix", + }, + Plant { + label: "the origin is never written", + site: "| Option.some named => (member \"origin\" (jsonText named) (ctor LexLeanStd.Json::Json.JNil))", + replacement: "| Option.some named => (ctor LexLeanStd.Json::Json.JNil)", + vector: "a module from a source package", + }, + Plant { + label: "the modules are written last first", + site: "(LexLeanStd.Order::reverseList [ModuleRow] rows)", + replacement: "rows", + vector: "modules in their order", + }, + Plant { + label: "the toolchain is another", + site: "(lit \"leanprover/lean4:v4.32.1\")", + replacement: "(lit \"leanprover/lean4:v4.32.0\")", + vector: "an empty manifest", + }, + Plant { + label: "the semantics ID is the source ID", + site: "(jsonDigest (project manifest semanticsId))", + replacement: "(jsonDigest (project manifest sourceId))", + vector: "an empty manifest", + }, + Plant { + label: "a byte length is negative", + site: "(ctor LexLeanStd.Json::Json.JInt false (project row byteLength))", + replacement: "(ctor LexLeanStd.Json::Json.JInt true (project row byteLength))", + vector: "outputs out of order", + }, +]; + +fn plants(vectors: &[Vector]) { + let mut missed = Vec::new(); + for plant in PLANTS { + let vector = vectors + .iter() + .find(|vector| vector.label == plant.vector) + .unwrap_or_else(|| panic!("{}: no vector `{}`", plant.label, plant.vector)); + let planted = support::P::bootstrap(); + let source = planted.read_raw("src/ManifestText.lex.tex"); + assert_eq!( + source.matches(plant.site).count(), + 1, + "{}: the plant site occurs once", + plant.label + ); + planted.write( + "src/ManifestText.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, std::slice::from_ref(&vector.run), 1).first() { + Some(first) => eprintln!( + "BS-34: plant detected: {}: {}", + plant.label, + first.chars().take(160).collect::() + ), + None => missed.push(plant.label), + } + } + assert!( + missed.is_empty(), + "planted defects their own vector does not detect: {missed:?}" + ); +} + +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-34: {}: 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("ManifestText"), + "ManifestText is a linked module of the project" + ); + eligibility_of(&project, "ManifestText", MODULE, &ROOTS); + + let vectors = named(); + let labels: BTreeSet<&str> = vectors.iter().map(|vector| vector.label).collect(); + assert_eq!(labels.len(), vectors.len(), "each vector has its own label"); + let runs: Vec = vectors.iter().map(|vector| vector.run.clone()).collect(); + + // Every committed build manifest, each the oracle's text of its fields. + let manifests = committed(); + assert!( + manifests + .iter() + .any(|manifest| manifest.modules.iter().any(|row| row.origin.is_some())), + "a committed manifest has a module from a source package" + ); + let corpus: Vec = manifests.iter().map(manifest_run).collect(); + let normative = support::normative_host(); + let (evaluator_seeded, rustc_seeded) = if normative { + ( + seeded_runs(EVALUATOR_SEEDED, 0x0B55_0034), + seeded_runs(RUSTC_SEEDED, 0x0B55_1034), + ) + } else { + (Vec::new(), Vec::new()) + }; + eprintln!( + "BS-34: {} vectors, {} committed manifests, {} and {} seeded runs ({:?})", + vectors.len(), + manifests.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 all_runs = runs.clone(); + all_runs.extend(corpus.iter().cloned()); + all_runs.extend(evaluator_seeded.iter().cloned()); + let disagreements = super::evaluate(&lowered[root], &all_runs, 5); + assert!( + disagreements.is_empty(), + "{root} and the Rust oracle disagree: {disagreements:?}" + ); + eprintln!( + "BS-34: {root}: the evaluator agrees on {} runs ({:?})", + all_runs.len(), + started.elapsed() + ); + plants(&vectors); + } else { + eprintln!("BS-34: platform-bound host: the evaluator, the seeded runs, and the planted defects run on the normative host"); + } + + let mut compiled = runs; + compiled.extend(corpus); + compiled.extend(rustc_seeded); + let total = rustc_differential( + "BS-34", + &[(root, &lowered[root], compiled.as_slice())], + "oracle", + ); + eprintln!("BS-34: {total} rustc runs agree ({:?})", started.elapsed()); + + if !support::lean_backed("BS-34") { + return; + } + export(&lowered); + eprintln!("BS-34: passed in {:?}", started.elapsed()); +} diff --git a/crates/conformance/src/cases/repository.rs b/crates/conformance/src/cases/repository.rs index 10772fbae2..7719d0aea2 100644 --- a/crates/conformance/src/cases/repository.rs +++ b/crates/conformance/src/cases/repository.rs @@ -898,7 +898,7 @@ pub(crate) fn run(id: &str) { let model = repo_model::Model::load(&root.join("model").into_std_path_buf()) .expect("the model loads"); let table = spec_table(); - assert_eq!(table.len(), 479, "§31 has 479 rows"); + assert_eq!(table.len(), 480, "§31 has 480 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 2845785382..f6fb49ae1d 100644 --- a/crates/conformance/tests/conformance.rs +++ b/crates/conformance/tests/conformance.rs @@ -2325,6 +2325,11 @@ fn conformance_bs_21() { repo_conformance::cases::run("BS-21"); } +#[test] +fn conformance_bs_34() { + repo_conformance::cases::run("BS-34"); +} + #[test] fn conformance_pk_01() { repo_conformance::cases::run("PK-01"); diff --git a/features/suites/bootstrap.feature b/features/suites/bootstrap.feature index ce21fe9ac6..beaa7e97d6 100644 --- a/features/suites/bootstrap.feature +++ b/features/suites/bootstrap.feature @@ -126,3 +126,10 @@ Feature: bootstrap When the project is checked and built, and the lowered program of the root and its rendered package are run on the atoms the oracle's scanner returns 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 `parse_module` on every run, every refusal of which a vector reaches And every planted defect is detected by its own vector, and the exported packages are byte-identical to the committed packages and realize the program the differential ran + + @BS-34 @build + Scenario: The build manifest of SPEC.md §21.6 in the canonical JSON of §21.7 (`artifact::manifest::BuildManifest::to_json` written as a file: the specification, the compiler version and semantics ID, the language, the project, the source, semantic, and build IDs, the pinned Lean toolchain, the selection and the module rows in their order, a module's origin only when it has one, and the input and output rows sorted by kind, path, length, and digest, each digest in lower-case hex) is language-1.2 source in the `bootstrap/` project, as the production root `buildManifest` of `ManifestText` over the standard library's `Json` writer, 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 hand-built manifests, which reach every key of the row order, lengths across a byte, a module's origin, and escapes, on every committed build manifest, each of which is the oracle's text of its own fields, and on seeded manifests; each planted defect in the source is detected by the one vector it names, and the certified packages the production export publishes for the project are the committed ones; gathering the rows of a build and hashing its files are outside the claim. + Given the committed `bootstrap` project, hand-built manifests, every committed build manifest, and seeded manifests + When the project is checked and built, and the lowered program and the rendered package of the root are run on those manifests + Then the root is eligible for rust-std with exactly its declared effects, no certificate part is beyond 3,145,728 bytes, the root equals the file bytes of `BuildManifest::to_json` on every run, and each committed manifest is the oracle's text of its own fields + 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 diff --git a/model/ids.toml b/model/ids.toml index 18123556aa..ce28f96776 100644 --- a/model/ids.toml +++ b/model/ids.toml @@ -2792,6 +2792,12 @@ level = "build" suite = "bootstrap" statement = "The fixed structural grammar of SPEC.md §15.1 and §15.2 (`grammar::structural::parse_module`: the module header, the blocks and declarations, the axiom policies, the sentences, the structured proof environments, and the closed data forms, with the coverage rows of every structural atom it consumes) is language-1.2 source in the `bootstrap/` project: `parseModule` of `StructuralGrammar`, for the atoms `scanSource` of `BS-03` returns, the path, the name the path gives the module, and `max_scope_depth`, is a production root eligible for `rust-std` with exactly its declared effects, none of them `recursion`, and has no part of its certificate beyond 3,145,728 bytes; it returns the module with its rows, or the refusal's code, message, and span, and on 267 hand-built vectors, 146 of them refused, which reach every refusal of `parse_module`, and on the committed modules, whole or by the atoms of both their ends, its lowered program under the calculus evaluator on the normative host and its rendered package under the pinned rustc on every host agree with the oracle to the byte; on the normative host both also agree on 2,000 seeded edits of those texts, each of 44 planted defects in the source is detected by the one vector it names, and the certified package the production export publishes for the project is the committed one; the grammars of mathematical islands, propositions, and proof sentences, which read the lexicon's closure, and the interpretation of the module this root returns are outside the claim." +[[id]] +id = "BS-34" +level = "build" +suite = "bootstrap" +statement = "The build manifest of SPEC.md §21.6 in the canonical JSON of §21.7 (`artifact::manifest::BuildManifest::to_json` written as a file: the specification, the compiler version and semantics ID, the language, the project, the source, semantic, and build IDs, the pinned Lean toolchain, the selection and the module rows in their order, a module's origin only when it has one, and the input and output rows sorted by kind, path, length, and digest, each digest in lower-case hex) is language-1.2 source in the `bootstrap/` project, as the production root `buildManifest` of `ManifestText` over the standard library's `Json` writer, 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 hand-built manifests, which reach every key of the row order, lengths across a byte, a module's origin, and escapes, on every committed build manifest, each of which is the oracle's text of its own fields, and on seeded manifests; each planted defect in the source is detected by the one vector it names, and the certified packages the production export publishes for the project are the committed ones; gathering the rows of a build and hashing its files are outside the claim." + [[id]] id = "PK-01" level = "build" diff --git a/xtask/src/spec_links.rs b/xtask/src/spec_links.rs index 962afcafd8..ec77840783 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() != 479 { - return Err(format!("RP-07: the §31 table has {} rows, not 479", rows.len()).into()); + if rows.len() != 480 { + return Err(format!("RP-07: the §31 table has {} rows, not 480", rows.len()).into()); } // The prose total under the table is part of the contract a reader // relies on; a row added without it would leave §31 contradicting itself. From 3747eea55094bc47331e5558fa03d8f6400867c2 Mon Sep 17 00:00:00 2001 From: humuhumu33 Date: Tue, 10 Nov 2026 14:49:29 +0000 Subject: [PATCH 2/2] BS-34: the build manifest, ManifestText bootstrap/src/ManifestText.lex.tex over the standard library's Json writer: buildManifest writes a build manifest's canonical JSON file, its rows sorted by kind, path, length, and digest. Lean verifies the module and the root is eligible with exactly allocation, overflow, and recursion. The entrypoint, the lock, the export root, and the project README follow. Co-Authored-By: Claude Opus 5.5 --- bootstrap/README.md | 3 + bootstrap/lexlean.lock | 2 +- bootstrap/lexlean.toml | 2 +- bootstrap/src/ManifestText.lex.tex | 189 +++++++++++++++++++ tests/production-export/bootstrap/roots.json | 8 + 5 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 bootstrap/src/ManifestText.lex.tex diff --git a/bootstrap/README.md b/bootstrap/README.md index da9b5275f8..7375dae4aa 100644 --- a/bootstrap/README.md +++ b/bootstrap/README.md @@ -21,3 +21,6 @@ writes the rejection of a GNAF request through it. `src/StructuralGrammar.lex.tex` imports `PrimitiveScan` for the atoms it reads and the refusal it returns, and `Buffer` and `Numeral` from the standard library. + +`src/ManifestText.lex.tex` (SPEC.md §17.23, `BS-34`) imports the standard library's `Json`, +`Numeral`, `Order`, and `Text`, and writes the build manifest of SPEC.md §21.6. diff --git a/bootstrap/lexlean.lock b/bootstrap/lexlean.lock index 42a36fda63..8e7c5eedd2 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 = "7cf9cfbf5cfbb7241a5b7dcb321e7ed97206e0cf2399c657407b9b5ec88e426c" +project_config_sha256 = "f3afee50ab84dd49447d37a15260aaab9b2501c2dd3fc9071a2e652ff3b0da4f" lean_toolchain = "leanprover/lean4:v4.32.1" [[workspace_file]] diff --git a/bootstrap/lexlean.toml b/bootstrap/lexlean.toml index c217373037..6802c10a26 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/GnafValidate.lex.tex", "src/PrimitiveScan.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/StructuralGrammar.lex.tex", "src/TokenAudit.lex.tex", "src/ToolingAst.lex.tex", "src/ToolingLatex.lex.tex"] +entrypoints = ["src/AxiomOutput.lex.tex", "src/CalculusCheck.lex.tex", "src/GnafValidate.lex.tex", "src/ManifestText.lex.tex", "src/PrimitiveScan.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/StructuralGrammar.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/ManifestText.lex.tex b/bootstrap/src/ManifestText.lex.tex new file mode 100644 index 0000000000..1923ff2abc --- /dev/null +++ b/bootstrap/src/ManifestText.lex.tex @@ -0,0 +1,189 @@ +\begin{lexlean}{ManifestText} +\useglossary{lexlean.std.nat@1.2.0} +\importmodule{LexLeanStd.Json} +\importmodule{LexLeanStd.Numeral} +\importmodule{LexLeanStd.Order} +\importmodule{LexLeanStd.Text} +\title{Natural number addition} +\begin{semanticmodule} +structure{ + name: FileRow, + type_parameters: [], + parameters: [], + fields: [ + {name: kind, type: Bytes}, + {name: location, type: Bytes}, + {name: byteLength, type: Nat}, + {name: digest, type: Bytes} + ] +} + +structure{ + name: ModuleRow, + type_parameters: [], + parameters: [], + fields: [ + {name: moduleName, type: Bytes}, + {name: leanModule, type: Bytes}, + {name: sourcePath, type: Bytes}, + {name: origin, type: (Option Bytes)} + ] +} + +structure{ + name: BuildManifest, + type_parameters: [], + parameters: [], + fields: [ + {name: language, type: Bytes}, + {name: compilerVersion, type: Bytes}, + {name: semanticsId, type: Bytes}, + {name: projectName, type: Bytes}, + {name: sourceId, type: Bytes}, + {name: semanticId, type: Bytes}, + {name: buildId, type: Bytes}, + {name: selection, type: (List Bytes)}, + {name: modules, type: (List ModuleRow)}, + {name: inputs, type: (List FileRow)}, + {name: outputs, type: (List FileRow)} + ] +} + +definition{ + name: lit, + parameters: [literal : String], + result: Bytes, + body: (prim utf8_encode literal : Bytes), + executable: true +} + +definition{ + name: cat, + parameters: [left : Bytes, right : Bytes], + result: Bytes, + body: (prim append left right : Bytes), + executable: true +} + +definition{ + name: jsonText, + parameters: [value : Bytes], + result: LexLeanStd.Json::Json, + body: (ctor LexLeanStd.Json::Json.JStr value), + executable: true +} + +definition{ + name: jsonDigest, + parameters: [digest : Bytes], + result: LexLeanStd.Json::Json, + body: (jsonText (LexLeanStd.Numeral::hex digest)), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: member, + parameters: [key : String, value : LexLeanStd.Json::Json, rest : LexLeanStd.Json::Json], + result: LexLeanStd.Json::Json, + body: (ctor LexLeanStd.Json::Json.JMember (lit key) value rest), + executable: true +} + +definition{ + name: textArray, + parameters: [values : (List Bytes)], + result: LexLeanStd.Json::Json, + body: (ctor LexLeanStd.Json::Json.JArr (prim list_fold (fun (acc : LexLeanStd.Json::Json) (item : Bytes) => (ctor LexLeanStd.Json::Json.JItem (jsonText item) acc)) (ctor LexLeanStd.Json::Json.JNil) (LexLeanStd.Order::reverseList [Bytes] values) : LexLeanStd.Json::Json)), + executable: true +} + +definition{ + name: bigEndian, + parameters: [value : Nat, width : Nat], + result: Bytes, + body: (second (prim iterate (fun (state : (Nat * Bytes)) => ((prim quotient (first state) 256 0 : Nat), (cat (LexLeanStd.Numeral::pick (LexLeanStd.Numeral::byteValues) (prim remainder (first state) 256 0 : Nat)) (second state)))) width (value, 0x) : (Nat * Bytes))), + executable: true +} + +definition{ + name: escapedKey, + parameters: [text : Bytes], + result: Bytes, + body: (cat (LexLeanStd.Text::joinWith (LexLeanStd.Text::splitOn text (0 : UInt8)) 0x0001) 0x0000), + executable: true +} + +definition{ + name: rowKey, + parameters: [row : FileRow], + result: Bytes, + body: (cat (cat (cat (escapedKey (project row kind)) (escapedKey (project row location))) (bigEndian (project row byteLength) 8)) (project row digest)), + executable: true +} + +definition{ + name: rowsSorted, + parameters: [rows : (List FileRow)], + result: (List FileRow), + body: (prim list_fold (fun (acc : (List FileRow)) (entry : (Bytes * FileRow)) => (cons (second entry) acc)) (nil FileRow) (LexLeanStd.Order::reverseList [(Bytes * FileRow)] (LexLeanStd.Order::sortByKey [FileRow] (LexLeanStd.Order::reverseList [(Bytes * FileRow)] (prim list_fold (fun (acc : (List (Bytes * FileRow))) (row : FileRow) => (cons ((rowKey row), row) acc)) (nil (Bytes * FileRow)) rows : (List (Bytes * FileRow)))))) : (List FileRow)), + axioms: [propext], + executable: true +} + +definition{ + name: rowJson, + parameters: [row : FileRow], + result: LexLeanStd.Json::Json, + body: (ctor LexLeanStd.Json::Json.JObj (member "kind" (jsonText (project row kind)) (member "path" (jsonText (project row location)) (member "byte_length" (ctor LexLeanStd.Json::Json.JInt false (project row byteLength)) (member "sha256" (jsonDigest (project row digest)) (ctor LexLeanStd.Json::Json.JNil)))))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: rowsJson, + parameters: [rows : (List FileRow)], + result: LexLeanStd.Json::Json, + body: (ctor LexLeanStd.Json::Json.JArr (prim list_fold (fun (acc : LexLeanStd.Json::Json) (row : FileRow) => (ctor LexLeanStd.Json::Json.JItem (rowJson row) acc)) (ctor LexLeanStd.Json::Json.JNil) (LexLeanStd.Order::reverseList [FileRow] (rowsSorted rows)) : LexLeanStd.Json::Json)), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: moduleJson, + parameters: [entry : ModuleRow], + result: LexLeanStd.Json::Json, + body: (let tail : LexLeanStd.Json::Json := (match (project entry origin) + | Option.some named => (member "origin" (jsonText named) (ctor LexLeanStd.Json::Json.JNil)) + | Option.none => (ctor LexLeanStd.Json::Json.JNil)); (ctor LexLeanStd.Json::Json.JObj (member "module" (jsonText (project entry moduleName)) (member "lean_module" (jsonText (project entry leanModule)) (member "source_path" (jsonText (project entry sourcePath)) tail))))), + executable: true +} + +definition{ + name: modulesJson, + parameters: [rows : (List ModuleRow)], + result: LexLeanStd.Json::Json, + body: (ctor LexLeanStd.Json::Json.JArr (prim list_fold (fun (acc : LexLeanStd.Json::Json) (entry : ModuleRow) => (ctor LexLeanStd.Json::Json.JItem (moduleJson entry) acc)) (ctor LexLeanStd.Json::Json.JNil) (LexLeanStd.Order::reverseList [ModuleRow] rows) : LexLeanStd.Json::Json)), + executable: true +} + +definition{ + name: manifestJson, + parameters: [manifest : BuildManifest], + result: LexLeanStd.Json::Json, + body: (ctor LexLeanStd.Json::Json.JObj (member "spec" (jsonText (lit "lexlean/build-manifest/1")) (member "compiler" (ctor LexLeanStd.Json::Json.JObj (member "version" (jsonText (project manifest compilerVersion)) (member "semantics_id" (jsonDigest (project manifest semanticsId)) (ctor LexLeanStd.Json::Json.JNil)))) (member "language" (jsonText (project manifest language)) (member "project" (jsonText (project manifest projectName)) (member "source_id" (jsonDigest (project manifest sourceId)) (member "semantic_id" (jsonDigest (project manifest semanticId)) (member "build_id" (jsonDigest (project manifest buildId)) (member "lean_toolchain" (jsonText (lit "leanprover/lean4:v4.32.1")) (member "selection" (textArray (project manifest selection)) (member "modules" (modulesJson (project manifest modules)) (member "inputs" (rowsJson (project manifest inputs)) (member "outputs" (rowsJson (project manifest outputs)) (ctor LexLeanStd.Json::Json.JNil)))))))))))))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: buildManifest, + parameters: [manifest : BuildManifest], + result: Bytes, + body: (LexLeanStd.Json::writeJsonFile (manifestJson manifest)), + axioms: [Quot.sound, propext], + executable: true, + production: {effects: [allocation, overflow, recursion], targets: [rust-std]} +} +\end{semanticmodule} +\end{lexlean} diff --git a/tests/production-export/bootstrap/roots.json b/tests/production-export/bootstrap/roots.json index c1c5b90ebf..f743938c50 100644 --- a/tests/production-export/bootstrap/roots.json +++ b/tests/production-export/bootstrap/roots.json @@ -24,6 +24,14 @@ ], "version": "1.0.0" }, + { + "name": "build_manifest", + "root": "LexLeanBoot.ManifestText.buildManifest", + "targets": [ + "rust-std" + ], + "version": "1.0.0" + }, { "name": "check_arguments", "root": "LexLeanBoot.CalculusCheck.checkArguments",