diff --git a/.github/bdd-parts.json b/.github/bdd-parts.json index fe7db0138d..b85fb355ce 100644 --- a/.github/bdd-parts.json +++ b/.github/bdd-parts.json @@ -25,6 +25,9 @@ "bootstrap-lower": [ "BS-07" ], + "bootstrap-surface-module": [ + "BS-28" + ], "bootstrap-moves": [ "BS-08" ], diff --git a/.github/vv-rows.json b/.github/vv-rows.json index a0695b8575..4adba89e7e 100644 --- a/.github/vv-rows.json +++ b/.github/vv-rows.json @@ -62,6 +62,15 @@ "memory_kib": "", "hints": "" }, + { + "part": "bdd-bootstrap-surface-module", + "recipes": "bdd", + "examples_part": "", + "bdd_part": "bootstrap-surface-module", + "width": "", + "memory_kib": "", + "hints": "" + }, { "part": "bdd-bootstrap-tooling-latex", "recipes": "bdd", diff --git a/CHANGELOG.md b/CHANGELOG.md index 68f6a6eb5e..a48c33e34b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,11 @@ workspace carried at those versions without a tag. ## Unreleased +- Where the module of a source is, as language-1.2 source (SPEC.md §17.23, + §17.21, `BS-28`, #269; no new diagnostic code, no change to the language-1.2 + identity). `locateModule` of `SurfaceModule` returns what + `surface::module::locate` returns and admits no `recursion`. The register is + 479 IDs. - Canonical JSON reading in the standard library, the fourth member the self-hosted compiler needs, #276 (SPEC.md §17.22, `SL-13`). The module `LexLeanStd.JsonRead` holds the production roots `readJson` and diff --git a/CONFORMANCE.md b/CONFORMANCE.md index c9b4937578..68f0225661 100644 --- a/CONFORMANCE.md +++ b/CONFORMANCE.md @@ -77,6 +77,7 @@ the error registry does not sanction (R5, `ERRORS.md`). | `BS-15` | `build` | The package renderer of SPEC.md §17.16 (the checks `package::lower` makes of a manifest's own fields before it reads the program: the spec, the crate name against the Rust keywords and the reserved crates, the version, the profile, the form and the order of the sources, and the effects against the registry, with `allocation` refused on `rust-core`; the Cargo manifest over the scaffold record; and the provenance in canonical JSON with the digests of the runtime, the Cargo manifest, and the library) is language-1.2 source in the `bootstrap/` project, as two production roots of `RustPackage` that the host composes around the roots of `BS-04` to `BS-14`: `checkManifest`, which for the fields of a manifest and the registered effects returns whether the profile is `rust-std`, or the refusal of `package::lower` to the byte, and `renderPackage`, which for the scaffold record, the manifest's name, version, profile, sources, effects and exports, the program's identity, the compiler-semantics identity, the two runtime texts, and the library returns the `Cargo.toml` and the `provenance.json` of `package::package` to the byte; each is eligible for `rust-std` with exactly its declared effects and has no part of its certificate beyond 3,145,728 bytes; the oracle of `checkManifest` is `package::lower` on the manifest with its program and exports replaced by a pair every later check accepts, which agrees with each committed negative manifest's refusal, and the oracle of `renderPackage` is `package::package` on the 299 committed manifests it accepts and, on 137 hand-built inputs (names, exports, sources and effects that reach the escaper, and scaffold records that differ from the committed one) and 299 seeded mutants, `cargo_toml_of` and the canonical JSON of §21.7 by the recipe `package::package` is held to; on the normative host the lowered programs under the calculus evaluator agree with the oracle on the 318 committed manifests, 182 rule manifests and 2,000 seeded mutants, and on the 241 renders whose library is at most 16,384 bytes; the rendered packages agree with the oracle under the pinned rustc on all 3,190 runs; 21 planted defects in the source are each detected; and the certified packages the production export publishes for the project are the committed ones; the checks of the program, the exports and the crate, and the bytes of the library, which are the rows `BS-04` to `BS-14`, are outside the claim. | | `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-28` | `build` | Where the module of a source is, as SPEC.md §17.21 places it (`surface::module::locate`: in a text, the first environment of a kind with a notation, searched in the order semantic, tooling, core, to the last closing marker of that kind, or none when the text holds no such environment or holds the first one found without a closing marker after its opening; the byte range of its body; and, when the body is the control of the data form of that kind and braces with white space as Rust's `char::is_whitespace` defines it around them, the byte range of what the braces hold) is language-1.2 source in the `bootstrap/` project, as the production root `locateModule` of `SurfaceModule`, eligible for `rust-std` with exactly its declared effects, none of them `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 the hand-built texts, which reach no module, a module in the notation, and a module in the data form of each kind, on every committed `.lex.tex` source, and on seeded texts and seeded edits of the sources; 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; the readers and printers of each kind's notation are outside the claim. | ## calculus diff --git a/README.md b/README.md index 0f5db6830c..6c53c71fed 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 478 registered conformance IDs have their named tests; `just vv` checks them with the pinned toolchain installed. +All 479 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, and the LaTeX of a tooling module, 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-20` | `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 where the module of a source is, 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-28` | `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 93b9b32971..0de0a62966 100644 --- a/SPEC.md +++ b/SPEC.md @@ -8725,6 +8725,23 @@ 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. +Where the module of a source is (§17.21) is a component of the front end as source (`BS-28`, +issue 269), the module `SurfaceModule`, with one production root for `rust-std`: + +| Root | Takes | Returns | Oracle | +| --- | --- | --- | --- | +| `LexLeanBoot.SurfaceModule.locateModule` | a text | the kind of its module, the byte range of the body, and the byte range of its data, or none | `surface::module::locate` | + +`locateModule` searches the text for the opening marker of each kind in the oracle's order +(semantic, tooling, core) and stops at the first kind found: the body runs from the end of the +first opening marker to the last closing marker of that kind, and a kind whose closing marker is +missing, or found only before its opening, ends the search with none, as the oracle's `?` does. The +data form is the control of the kind (`\semanticdata`, `\toolingdata`, `\coredata`) after white +space at the start of the body, then white space and an opening brace, and the body's end after +white space is a closing brace; what lies between the braces is the data. White space is what +Rust's `char::is_whitespace` admits, scanned forward and backward by the scanners of `AxiomOutput`. +The root admits no `recursion`. The readers and printers of each kind's notation stay in the host. + ## 18. Lean backend ### 18.1 Output contract @@ -11646,6 +11663,7 @@ Every row below is normative, has honesty level `build`, and MUST be copied byte | `BS-15` | `bootstrap` | The package renderer of SPEC.md §17.16 (the checks `package::lower` makes of a manifest's own fields before it reads the program: the spec, the crate name against the Rust keywords and the reserved crates, the version, the profile, the form and the order of the sources, and the effects against the registry, with `allocation` refused on `rust-core`; the Cargo manifest over the scaffold record; and the provenance in canonical JSON with the digests of the runtime, the Cargo manifest, and the library) is language-1.2 source in the `bootstrap/` project, as two production roots of `RustPackage` that the host composes around the roots of `BS-04` to `BS-14`: `checkManifest`, which for the fields of a manifest and the registered effects returns whether the profile is `rust-std`, or the refusal of `package::lower` to the byte, and `renderPackage`, which for the scaffold record, the manifest's name, version, profile, sources, effects and exports, the program's identity, the compiler-semantics identity, the two runtime texts, and the library returns the `Cargo.toml` and the `provenance.json` of `package::package` to the byte; each is eligible for `rust-std` with exactly its declared effects and has no part of its certificate beyond 3,145,728 bytes; the oracle of `checkManifest` is `package::lower` on the manifest with its program and exports replaced by a pair every later check accepts, which agrees with each committed negative manifest's refusal, and the oracle of `renderPackage` is `package::package` on the 299 committed manifests it accepts and, on 137 hand-built inputs (names, exports, sources and effects that reach the escaper, and scaffold records that differ from the committed one) and 299 seeded mutants, `cargo_toml_of` and the canonical JSON of §21.7 by the recipe `package::package` is held to; on the normative host the lowered programs under the calculus evaluator agree with the oracle on the 318 committed manifests, 182 rule manifests and 2,000 seeded mutants, and on the 241 renders whose library is at most 16,384 bytes; the rendered packages agree with the oracle under the pinned rustc on all 3,190 runs; 21 planted defects in the source are each detected; and the certified packages the production export publishes for the project are the committed ones; the checks of the program, the exports and the crate, and the bytes of the library, which are the rows `BS-04` to `BS-14`, are outside the claim. | §17.16, §17.23 | | `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-28` | `bootstrap` | Where the module of a source is, as SPEC.md §17.21 places it (`surface::module::locate`: in a text, the first environment of a kind with a notation, searched in the order semantic, tooling, core, to the last closing marker of that kind, or none when the text holds no such environment or holds the first one found without a closing marker after its opening; the byte range of its body; and, when the body is the control of the data form of that kind and braces with white space as Rust's `char::is_whitespace` defines it around them, the byte range of what the braces hold) is language-1.2 source in the `bootstrap/` project, as the production root `locateModule` of `SurfaceModule`, eligible for `rust-std` with exactly its declared effects, none of them `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 the hand-built texts, which reach no module, a module in the notation, and a module in the data form of each kind, on every committed `.lex.tex` source, and on seeded texts and seeded edits of the sources; 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; the readers and printers of each kind's notation are outside the claim. | §17.23, §17.21 | | `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 | @@ -11662,7 +11680,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:** 478. +**Total required capability IDs:** 479. 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 0992f2e61e..e57a5a18dc 100644 --- a/VERIFICATION.md +++ b/VERIFICATION.md @@ -10999,6 +10999,44 @@ 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. +### where the module of a source is, as source (BS-28) + +`BS-28` holds the production root `LexLeanBoot.SurfaceModule.locateModule` +(`bootstrap/src/SurfaceModule.lex.tex`) to `surface::module::locate`: the kind +of a source's module, the byte range of its body, and the byte range of its data +when it is written in the data form. The module imports `AxiomOutput`, whose +scanners of white space (`skipWhite`, `dropWhiteEnd`, and `lastStep`) trim and +search as Rust's `char::is_whitespace` and `rfind` do, and the standard +library's `Text`; it admits no `recursion`. The case holds the root to the +oracle on hand-built texts that reach no module, a module of each kind in each +form, the order of the search, a kind whose closing marker is missing or found +only before its opening, and every shape of the data form with white space of +one, two, and three bytes; on every committed `.lex.tex` source; and on seeded +texts and seeded edits of the sources. 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 `SurfaceModule`: `lexlean check`, `lexlean build`, and +`lexlean verify` pass, and the eligibility report gives the root exactly +`allocation` and `overflow`. The register agrees with the §31 table on 479 IDs, +by the same parse `validate-spec-links` makes. + +The case was first compiled and run on the normative host on `release/v0.4` at +`4318b17b8` (`cargo test -p repo-conformance --test conformance -- +conformance_bs_28`, 223 s). Its corpus is 38 named vectors, the 1,045 committed +sources (342 of at most 4,000 bytes under the evaluator, 895 of at most 200,000 +bytes under rustc), and 300 and 1,500 seeded texts. The evaluator agrees with the +oracle on 680 runs and the rendered package under the pinned rustc on 2,433, and +each of the 14 planted defects is detected by its own vector. The first run found +no fault of the module and one plant its vector did not reach: `an end before the +begin is taken` was tried on a text whose last closing marker follows the +opening, so the test of the order never decided it (now `the end before the +begin`). The case then stops at the stack-bound step, `bootstrap/locate_module +is no package of the committed exports`, as each bootstrap member did before its +regeneration, which produces the `bootstrap/locate_module` package. The branch is +based on `release/v0.4` and stacks on nothing. + ## 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 a9f234eb1a..47359e0ec4 100644 --- a/bootstrap/README.md +++ b/bootstrap/README.md @@ -18,3 +18,6 @@ payloads a printer reads); `src/RustPrint.lex.tex` also imports the standard library's `Buffer` (`stdlib/src/Buffer.lex.tex`), which it writes through. `src/GnafValidate.lex.tex` (SPEC.md §17.15, `BS-16`) imports `Buffer` alone and writes the rejection of a GNAF request through it. + +`src/SurfaceModule.lex.tex` (SPEC.md §17.23, `BS-28`) imports `AxiomOutput`, whose scanners of +white space it trims with, and the standard library's `Text`. diff --git a/bootstrap/lexlean.lock b/bootstrap/lexlean.lock index dec1db451b..539ff11488 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 = "b2bd695c7fad3f83d9a41fdabb6f9f5eee0538452d59609e5170eff53d78f14f" +project_config_sha256 = "584d4141448245a467a9bc085880decb668865846df1f2b3f5277d28285195e0" lean_toolchain = "leanprover/lean4:v4.32.1" [[workspace_file]] diff --git a/bootstrap/lexlean.toml b/bootstrap/lexlean.toml index f57986a7e8..d9997ed1bb 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/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/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/SurfaceModule.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/SurfaceModule.lex.tex b/bootstrap/src/SurfaceModule.lex.tex new file mode 100644 index 0000000000..b430056916 --- /dev/null +++ b/bootstrap/src/SurfaceModule.lex.tex @@ -0,0 +1,116 @@ +\begin{lexlean}{SurfaceModule} +\useglossary{lexlean.std.nat@1.2.0} +\importmodule{AxiomOutput} +\importmodule{LexLeanStd.Text} +\title{Natural number addition} +\begin{semanticmodule} +structure{ + name: Located, + type_parameters: [], + parameters: [], + fields: [ + {name: kind, type: Nat}, + {name: bodyStart, type: Nat}, + {name: bodyStop, type: Nat}, + {name: data, type: (Option (Nat * Nat))} + ] +} + +definition{ + name: lit, + parameters: [literal : String], + result: Bytes, + body: (prim utf8_encode literal : Bytes), + executable: true +} + +definition{ + name: environment, + parameters: [kind : Nat], + result: Bytes, + body: (if (kind =? 0) then (lit "semanticmodule") else (if (kind =? 1) then (lit "toolingmodule") else (lit "coremodule"))), + executable: true +} + +definition{ + name: control, + parameters: [kind : Nat], + result: Bytes, + body: (if (kind =? 0) then (lit "\\semanticdata") else (if (kind =? 1) then (lit "\\toolingdata") else (lit "\\coredata"))), + executable: true +} + +definition{ + name: beginMarker, + parameters: [kind : Nat], + result: Bytes, + body: (prim append (prim append (lit "\\begin{") (environment kind) : Bytes) (lit "}") : Bytes), + executable: true +} + +definition{ + name: endMarker, + parameters: [kind : Nat], + result: Bytes, + body: (prim append (prim append (lit "\\end{") (environment kind) : Bytes) (lit "}") : Bytes), + executable: true +} + +definition{ + name: lastAt, + parameters: [subject : Bytes, needle : Bytes], + result: (Option Nat), + body: (let total : Nat := (prim length subject : Nat); (let size : Nat := (prim length needle : Nat); (if (total (AxiomOutput::lastStep subject needle position)) (total + 1) (prim subtract total size : Nat) : (Nat * Bool))); (if (LexLeanStd.Text::matchAt subject needle position) then (ctor Option.some [Nat] position) else (ctor Option.none [Nat])))))), + executable: true +} + +definition{ + name: tail, + parameters: [subject : Bytes, offset : Nat], + result: Bytes, + body: (LexLeanStd.Text::sliceOr subject offset (prim subtract (prim length subject : Nat) offset : Nat)), + executable: true +} + +definition{ + name: dataRange, + parameters: [text : Bytes, kind : Nat, start : Nat, stop : Nat], + result: (Option (Nat * Nat)), + body: (let region : Bytes := (LexLeanStd.Text::sliceOr text start (prim subtract stop start : Nat)); (let lead : Nat := (AxiomOutput::skipWhite region); (let tag : Bytes := (control kind); (if (LexLeanStd.Text::startsWith (tail region lead) tag) then (let afterTag : Nat := (lead + (prim length tag : Nat)); (let brace : Nat := (afterTag + (AxiomOutput::skipWhite (tail region afterTag))); (if (LexLeanStd.Text::startsWith (tail region brace) (lit "{")) then (let inside : Bytes := (tail region (brace + 1)); (let trimmedStop : Nat := (AxiomOutput::dropWhiteEnd inside 0); (if (if (0 (0, (ctor Option.none [Located])) + | Option.some found => (let start : Nat := (found + (prim length marker : Nat)); (match (lastAt text (endMarker kind)) + | Option.none => (1, (ctor Option.none [Located])) + | Option.some stop => (if (stop gnaf_validate::case(), // §17.23, §17.20: the canonical LaTeX of a tooling module. "BS-20" => tooling_latex::case(), + "BS-28" => surface_module::case(), other => panic!("no bootstrap case is wired for {other}"), } } diff --git a/crates/conformance/src/cases/bootstrap/surface_module.rs b/crates/conformance/src/cases/bootstrap/surface_module.rs new file mode 100644 index 0000000000..423f2e10e8 --- /dev/null +++ b/crates/conformance/src/cases/bootstrap/surface_module.rs @@ -0,0 +1,597 @@ +//! `BS-28` (SPEC.md §17.23, §17.21): where the module of a source is, as +//! language-1.2 source, `LexLeanBoot.SurfaceModule`, held to the byte to +//! `lexlean::surface::module::locate`. +//! +//! `locateModule` searches a text for the first environment of a kind with a +//! notation (semantic, tooling, core, in that order), takes the body to the last +//! closing marker of that kind, and, when the body is the control of the data +//! form followed by braces, the byte range of what the braces hold; it trims +//! white space as Rust's `char::is_whitespace` defines it, with the scanners of +//! `AxiomOutput`. +//! +//! Each planted defect names the one vector that catches it. + +use std::collections::{BTreeMap, BTreeSet}; + +use lexlean::calculus::Value; +use lexlean::surface::module::locate; +use serde_json::Value as Json2; + +use super::rust_validate::{eligibility_of, rustc_differential}; +use super::{nat_val, option, pair, text, Run, Seeded}; +use crate::production_export as harness; +use crate::support::{self, repo_root}; + +const MODULE: &str = "LexLeanBoot.SurfaceModule"; +const ROOTS: [(&str, &[&str]); 1] = [("locateModule", &["allocation", "overflow"])]; + +/// The most a part of a certificate of a root may be, as the row states. +const CERTIFICATE_BUDGET: u64 = 3_145_728; +/// Committed sources run under the evaluator: those of at most this many bytes. +const EVALUATOR_BYTES: usize = 4_000; +/// Committed sources run under rustc: those of at most this many bytes. +const RUSTC_BYTES: usize = 200_000; +/// Seeded texts under the evaluator, and under rustc. +const EVALUATOR_SEEDED: usize = 300; +const RUSTC_SEEDED: usize = 1_500; + +const KINDS: [&str; 3] = ["semanticmodule", "toolingmodule", "coremodule"]; + +/// What `locate` says of a text, as the module's `Option Located`. +fn located(source: &str) -> Value { + option(locate(source).map(|found| { + let kind = KINDS + .iter() + .position(|environment| *environment == found.kind.environment) + .expect("a kind of the table"); + Value::Adt { + constructor: 0, + fields: vec![ + nat_val(kind), + nat_val(found.body.0), + nat_val(found.body.1), + option( + found + .data + .map(|(start, end)| pair(nat_val(start), nat_val(end))), + ), + ], + } + })) +} + +fn run(source: &str) -> Run { + ( + vec![text(source)], + serde_json::to_value(located(source)).expect("a value is JSON"), + ) +} + +// ------------------------------------------------------------------ vectors + +const B: &str = "\\begin{semanticmodule}"; +const E: &str = "\\end{semanticmodule}"; + +fn wrapped(inner: &str) -> String { + format!("\\begin{{lexlean}}{{M}}\n{inner}\\end{{lexlean}}\n") +} + +#[allow(clippy::too_many_lines)] +fn named() -> Vec<(String, String)> { + let mut out: Vec<(String, String)> = Vec::new(); + let mut add = |label: &str, source: String| out.push((label.to_owned(), source)); + add( + "the oracle's data form", + wrapped("\\begin{semanticmodule}\n\\semanticdata{{\"a\":1}}\n\\end{semanticmodule}\n"), + ); + add( + "the oracle's notation form", + wrapped("\\begin{toolingmodule}\n{declarations: []}\n\\end{toolingmodule}\n"), + ); + add("no module", wrapped("")); + add("a begin marker alone", B.to_owned()); + add("an end marker alone", E.to_owned()); + add("an empty text", String::new()); + add("an empty body", format!("{B}{E}")); + add("the end before the begin", format!("{E}{B}")); + add("the end before and after the begin", format!("{E}{B}x{E}")); + add("the last end marker", format!("{B}a{E}b{E}")); + add("the first begin marker", format!("x{B}a{B}b{E}")); + add( + "a core module", + "\\begin{coremodule}\n\\coredata{}\n\\end{coremodule}".to_owned(), + ); + add( + "a core module in notation", + "\\begin{coremodule}\nimports []\n\\end{coremodule}".to_owned(), + ); + add( + "a tooling module in data form", + "\\begin{toolingmodule}\\toolingdata{x}\\end{toolingmodule}".to_owned(), + ); + add( + "semantic is searched before tooling", + "\\begin{toolingmodule}a\\end{toolingmodule}\\begin{semanticmodule}b\\end{semanticmodule}" + .to_owned(), + ); + add( + "tooling is searched before core", + "\\begin{coremodule}a\\end{coremodule}\\begin{toolingmodule}b\\end{toolingmodule}" + .to_owned(), + ); + add( + "a semantic module without its end stops the search", + "\\begin{semanticmodule}a\\begin{toolingmodule}b\\end{toolingmodule}".to_owned(), + ); + add( + "a semantic module ended before it begins stops the search", + "\\end{semanticmodule}\\begin{semanticmodule}\\begin{toolingmodule}b\\end{toolingmodule}" + .to_owned(), + ); + add( + "the end of another kind is no end", + "\\begin{semanticmodule}a\\end{toolingmodule}".to_owned(), + ); + add( + "the data form without white space", + format!("{B}\\semanticdata{{x}}{E}"), + ); + add( + "the data form with white space everywhere", + format!("{B} \n\t\\semanticdata \n{{x}} \n\t{E}"), + ); + add( + "the data form with a no-break space", + format!("{B}\u{a0}\\semanticdata\u{a0}{{x}}\u{a0}{E}"), + ); + add( + "the data form with a line separator", + format!("{B}\u{2028}\\semanticdata{{x}}\u{3000}{E}"), + ); + add("empty data", format!("{B}\\semanticdata{{}}{E}")); + add( + "data of only white space", + format!("{B}\\semanticdata{{ }}{E}"), + ); + add( + "data with braces inside", + format!("{B}\\semanticdata{{{{a}}{{b}}}}{E}"), + ); + add("data without its close", format!("{B}\\semanticdata{{x{E}")); + add("data without its open", format!("{B}\\semanticdata x}}{E}")); + add( + "data with text after the close", + format!("{B}\\semanticdata{{x}} y{E}"), + ); + add( + "the control of another kind", + format!("{B}\\toolingdata{{x}}{E}"), + ); + add( + "a control with more letters", + format!("{B}\\semanticdatax{{x}}{E}"), + ); + add( + "text before the control", + format!("{B}x \\semanticdata{{x}}{E}"), + ); + add( + "a brace that is only a close", + format!("{B}\\semanticdata}}{E}"), + ); + add("a lone open brace", format!("{B}\\semanticdata{{{E}")); + add( + "a control and nothing else", + format!("{B}\\semanticdata{E}"), + ); + add( + "a scalar beyond ASCII in the body", + format!("{B}\u{e9}\\semanticdata{{\u{e9}}}{E}"), + ); + add( + "a no-break space is white but a zero-width space is not", + format!("{B}\u{200b}\\semanticdata{{x}}{E}"), + ); + add( + "white space of three bytes before the close", + format!("{B}\\semanticdata{{x}}\u{3000}\u{2029}{E}"), + ); + out +} + +// ------------------------------------------------------------------- seeded + +const PIECES: &[&str] = &[ + "\\begin{semanticmodule}", + "\\end{semanticmodule}", + "\\begin{toolingmodule}", + "\\end{toolingmodule}", + "\\begin{coremodule}", + "\\end{coremodule}", + "\\semanticdata", + "\\toolingdata", + "\\coredata", + "{", + "}", + " ", + "\n", + "\u{a0}", + "\u{3000}", + "x", +]; + +fn edited(seeded: &mut Seeded, source: &str) -> String { + let mut scalars: Vec = source.chars().collect(); + for _ in 0..=seeded.below(3) { + let at = seeded.below(scalars.len() + 1); + let piece: Vec = seeded.pick(PIECES).chars().collect(); + match seeded.below(3) { + 0 if at < scalars.len() => { + scalars.remove(at); + } + 1 => { + drop(scalars.splice(at..at, piece)); + } + _ if at < scalars.len() => { + drop(scalars.splice(at..=at, piece)); + } + _ => scalars.extend(piece), + } + } + scalars.into_iter().collect() +} + +fn drawn(seeded: &mut Seeded) -> String { + let count = 1 + seeded.below(8); + (0..count).map(|_| *seeded.pick(PIECES)).collect() +} + +fn seeded_runs(count: usize, bases: &[String], seed: u64) -> Vec { + let mut seeded = Seeded(seed); + let mut out = Vec::with_capacity(count); + while out.len() < count { + let source = if seeded.chance(50) && !bases.is_empty() { + let base = seeded.pick(bases).clone(); + edited(&mut seeded, &base) + } else { + drawn(&mut seeded) + }; + out.push(run(&source)); + } + out +} + +/// Every committed `.lex.tex` source, with its path. +fn sources() -> Vec<(String, String)> { + let root = repo_root(); + let walker = walkdir::WalkDir::new(root.as_std_path()) + .sort_by_file_name() + .into_iter() + .filter_entry(|entry| { + let name = entry.file_name().to_string_lossy(); + !(entry.file_type().is_dir() + && (matches!(name.as_ref(), "target" | ".git" | ".lexlean") + || support::holds_cache_tag(entry))) + }); + let mut out = Vec::new(); + for entry in walker.flatten() { + let path = entry.path(); + if !entry.file_type().is_file() || !path.to_string_lossy().ends_with(".lex.tex") { + continue; + } + let Ok(content) = std::fs::read_to_string(path) else { + continue; + }; + let relative = path + .strip_prefix(root.as_std_path()) + .expect("under the root") + .to_string_lossy() + .replace('\\', "/"); + out.push((relative, content)); + } + out +} + +// ------------------------------------------------------------------- plants + +struct Plant { + label: &'static str, + site: &'static str, + replacement: &'static str, + vector: &'static str, +} + +const PLANTS: &[Plant] = &[ + Plant { + label: "the first end marker is taken", + site: "(match (lastAt text (endMarker kind))", + replacement: "(match (LexLeanStd.Text::find text (endMarker kind))", + vector: "the last end marker", + }, + Plant { + label: "an end before the begin is taken", + site: "(if (stop (1, (ctor Option.none [Located]))", + replacement: " | Option.none => (0, (ctor Option.none [Located]))", + vector: "a semantic module without its end stops the search", + }, + Plant { + label: "tooling is searched before semantic", + site: "(let semantic : (Nat * (Option Located)) := (tryKind text 0);", + replacement: "(let semantic : (Nat * (Option Located)) := (tryKind text 1);", + vector: "semantic is searched before tooling", + }, + Plant { + label: "core is not searched", + site: "(locateFrom text 2)", + replacement: "(ctor Option.none [Located])", + vector: "a core module", + }, + Plant { + label: "the body begins at the begin marker", + site: "(let start : Nat := (found + (prim length marker : Nat));", + replacement: "(let start : Nat := found;", + vector: "an empty body", + }, + Plant { + label: "the core control is the semantic one", + site: "(lit \"\\\\coredata\")", + replacement: "(lit \"\\\\semanticdata\")", + vector: "a core module", + }, + Plant { + label: "no white space before the control", + site: "(let lead : Nat := (AxiomOutput::skipWhite region);", + replacement: "(let lead : Nat := 0;", + vector: "the data form with white space everywhere", + }, + Plant { + label: "no white space before the open brace", + site: "(let brace : Nat := (afterTag + (AxiomOutput::skipWhite (tail region afterTag)));", + replacement: "(let brace : Nat := afterTag;", + vector: "the data form with white space everywhere", + }, + Plant { + label: "white space before the close is kept", + site: "(let trimmedStop : Nat := (AxiomOutput::dropWhiteEnd inside 0);", + replacement: "(let trimmedStop : Nat := (prim length inside : Nat);", + vector: "white space of three bytes before the close", + }, + Plant { + label: "the data range ends at the close brace", + site: "(((start + brace) + 1) + (prim subtract trimmedStop 1 : Nat))", + replacement: "(((start + brace) + 1) + trimmedStop)", + vector: "the oracle's data form", + }, + Plant { + label: "the data range begins at the open brace", + site: "(ctor Option.some [(Nat * Nat)] (((start + brace) + 1),", + replacement: "(ctor Option.some [(Nat * Nat)] ((start + brace),", + vector: "data with braces inside", + }, + Plant { + label: "data need not close", + site: "(if (if (0 eprintln!( + "BS-28: 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-28: {}: 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" + ); + } +} + +#[allow(clippy::too_many_lines)] +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("SurfaceModule"), + "SurfaceModule is a linked module of the project" + ); + eligibility_of(&project, "SurfaceModule", MODULE, &ROOTS); + + let vectors = named(); + let labels: BTreeSet<&str> = vectors.iter().map(|(label, _)| label.as_str()).collect(); + assert_eq!(labels.len(), vectors.len(), "each vector has its own label"); + let outcomes: Vec> = vectors + .iter() + .map(|(_, source)| locate(source).map(|found| found.data.is_some())) + .collect(); + for (what, wanted) in [ + ("no module", None), + ("a module in notation", Some(false)), + ("a module in data form", Some(true)), + ] { + assert!( + outcomes.contains(&wanted), + "no vector reaches the outcome `{what}`" + ); + } + let mut named_runs: Vec = vectors.iter().map(|(_, source)| run(source)).collect(); + + let texts = sources(); + assert!( + texts.len() >= 100, + "the committed sources are {}", + texts.len() + ); + let mut evaluator_runs: Vec = Vec::new(); + let mut rustc_runs: Vec = Vec::new(); + let mut bases: Vec = Vec::new(); + for (_, content) in &texts { + if content.len() <= EVALUATOR_BYTES { + evaluator_runs.push(run(content)); + bases.push(content.clone()); + } + if content.len() <= RUSTC_BYTES { + rustc_runs.push(run(content)); + } + } + let normative = support::normative_host(); + let (evaluator_seeded, rustc_seeded) = if normative { + ( + seeded_runs(EVALUATOR_SEEDED, &bases, 0x0B55_0028), + seeded_runs(RUSTC_SEEDED, &bases, 0x0B55_1028), + ) + } else { + (Vec::new(), Vec::new()) + }; + eprintln!( + "BS-28: {} vectors, {} committed sources ({} under the evaluator, {} under rustc), {} and {} seeded texts ({:?})", + vectors.len(), + texts.len(), + evaluator_runs.len(), + rustc_runs.len(), + evaluator_seeded.len(), + rustc_seeded.len(), + 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(); + if normative { + let mut corpus: Vec = named_runs.clone(); + corpus.extend(evaluator_runs); + corpus.extend(evaluator_seeded); + let disagreements = super::evaluate(&lowered[ROOTS[0].0], &corpus, 5); + assert!( + disagreements.is_empty(), + "locateModule and the Rust oracle disagree: {disagreements:?}" + ); + eprintln!( + "BS-28: locateModule: the evaluator agrees on {} runs ({:?})", + corpus.len(), + started.elapsed() + ); + plants(&vectors); + } else { + eprintln!("BS-28: platform-bound host: the evaluator, the seeded runs, and the planted defects run on the normative host"); + } + + named_runs.extend(rustc_runs); + named_runs.extend(rustc_seeded); + let total = rustc_differential( + "BS-28", + &[(ROOTS[0].0, &lowered[ROOTS[0].0], named_runs.as_slice())], + "oracle", + ); + eprintln!("BS-28: {total} rustc runs agree ({:?})", started.elapsed()); + + if !support::lean_backed("BS-28") { + return; + } + export(&lowered); + eprintln!("BS-28: passed in {:?}", started.elapsed()); +} diff --git a/crates/conformance/src/cases/repository.rs b/crates/conformance/src/cases/repository.rs index 7df18c8c4a..aaab4a220b 100644 --- a/crates/conformance/src/cases/repository.rs +++ b/crates/conformance/src/cases/repository.rs @@ -873,7 +873,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(), 478, "§31 has 478 rows"); + assert_eq!(table.len(), 479, "§31 has 479 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 992ea8a7b3..efb2198ed4 100644 --- a/crates/conformance/tests/conformance.rs +++ b/crates/conformance/tests/conformance.rs @@ -2320,6 +2320,11 @@ fn conformance_bs_20() { repo_conformance::cases::run("BS-20"); } +#[test] +fn conformance_bs_28() { + repo_conformance::cases::run("BS-28"); +} + #[test] fn conformance_pk_01() { repo_conformance::cases::run("PK-01"); diff --git a/features/suites/bootstrap.feature b/features/suites/bootstrap.feature index 31570df912..a48449e652 100644 --- a/features/suites/bootstrap.feature +++ b/features/suites/bootstrap.feature @@ -119,3 +119,10 @@ Feature: bootstrap When the project is checked and built, the lowered program of the root is run by the evaluator on those modules and the mutants, and its rendered rust-std package is run by the pinned rustc on the modules, each with the capacity that fits and capacities that do not Then the root is eligible for rust-std with exactly its declared effects and no run disagrees with the oracle text, to the byte, or with its refusal And every planted defect is detected, and the exported package is byte-identical to its committed package and realizes the lowered program + + @BS-28 @build + Scenario: Where the module of a source is, as SPEC.md §17.21 places it (`surface::module::locate`: in a text, the first environment of a kind with a notation, searched in the order semantic, tooling, core, to the last closing marker of that kind, or none when the text holds no such environment or holds the first one found without a closing marker after its opening; the byte range of its body; and, when the body is the control of the data form of that kind and braces with white space as Rust's `char::is_whitespace` defines it around them, the byte range of what the braces hold) is language-1.2 source in the `bootstrap/` project, as the production root `locateModule` of `SurfaceModule`, eligible for `rust-std` with exactly its declared effects, none of them `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 the hand-built texts, which reach no module, a module in the notation, and a module in the data form of each kind, on every committed `.lex.tex` source, and on seeded texts and seeded edits of the sources; 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; the readers and printers of each kind's notation are outside the claim. + Given the committed `bootstrap` project, hand-built texts that reach no module and a module of each kind in each form, every committed `.lex.tex` source, and seeded texts and edits + When the project is checked and built, and the lowered program and the rendered package of the root are run on those texts + Then the root is eligible for rust-std with exactly its declared effects, no certificate part is beyond 3,145,728 bytes, and `locateModule` equals `locate` on every run + And every planted defect is detected by its own vector, and the exported package is byte-identical to the committed package and realizes the program the differential ran diff --git a/model/ids.toml b/model/ids.toml index 69eb399d8a..5cda4e559a 100644 --- a/model/ids.toml +++ b/model/ids.toml @@ -2786,6 +2786,12 @@ level = "build" suite = "bootstrap" statement = "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." +[[id]] +id = "BS-28" +level = "build" +suite = "bootstrap" +statement = "Where the module of a source is, as SPEC.md §17.21 places it (`surface::module::locate`: in a text, the first environment of a kind with a notation, searched in the order semantic, tooling, core, to the last closing marker of that kind, or none when the text holds no such environment or holds the first one found without a closing marker after its opening; the byte range of its body; and, when the body is the control of the data form of that kind and braces with white space as Rust's `char::is_whitespace` defines it around them, the byte range of what the braces hold) is language-1.2 source in the `bootstrap/` project, as the production root `locateModule` of `SurfaceModule`, eligible for `rust-std` with exactly its declared effects, none of them `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 the hand-built texts, which reach no module, a module in the notation, and a module in the data form of each kind, on every committed `.lex.tex` source, and on seeded texts and seeded edits of the sources; 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; the readers and printers of each kind's notation are 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 4f911a0892..3e1fb689c0 100644 --- a/tests/production-export/bootstrap/roots.json +++ b/tests/production-export/bootstrap/roots.json @@ -104,6 +104,14 @@ ], "version": "1.0.0" }, + { + "name": "locate_module", + "root": "LexLeanBoot.SurfaceModule.locateModule", + "targets": [ + "rust-std" + ], + "version": "1.0.0" + }, { "name": "loop_function", "root": "LexLeanBoot.RustLoops.loopFunction", diff --git a/xtask/src/spec_links.rs b/xtask/src/spec_links.rs index d3b755a3d4..962afcafd8 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() != 478 { - return Err(format!("RP-07: the §31 table has {} rows, not 478", rows.len()).into()); + if rows.len() != 479 { + return Err(format!("RP-07: the §31 table has {} rows, not 479", 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.