diff --git a/.github/bdd-parts.json b/.github/bdd-parts.json index fe7db0138d..08bc809e24 100644 --- a/.github/bdd-parts.json +++ b/.github/bdd-parts.json @@ -25,6 +25,9 @@ "bootstrap-lower": [ "BS-07" ], + "bootstrap-diagnostics": [ + "BS-29" + ], "bootstrap-moves": [ "BS-08" ], diff --git a/.github/vv-rows.json b/.github/vv-rows.json index a0695b8575..8894ded0be 100644 --- a/.github/vv-rows.json +++ b/.github/vv-rows.json @@ -62,6 +62,15 @@ "memory_kib": "", "hints": "" }, + { + "part": "bdd-bootstrap-diagnostics", + "recipes": "bdd", + "examples_part": "", + "bdd_part": "bootstrap-diagnostics", + "width": "", + "memory_kib": "", + "hints": "" + }, { "part": "bdd-bootstrap-tooling-latex", "recipes": "bdd", diff --git a/CHANGELOG.md b/CHANGELOG.md index 68f6a6eb5e..de529de076 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,12 @@ workspace carried at those versions without a tag. ## Unreleased +- The canonical diagnostic and the failure it makes as language-1.2 source + (SPEC.md §17.23, §20.1, §24.5, `BS-29`, #274; no new diagnostic code, no change + to the language-1.2 identity). `diagnosticText`, `sortDiagnostics`, and + `reportDiagnostics` of `Diagnostics` return what `Diagnostic::to_json`, + `sort_canonical`, and `LexLeanError::from_diagnostics(..).bounded(..)` return; + none admits `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..7b2335db78 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-29` | `build` | The canonical diagnostic of SPEC.md §20.1 and the failure it makes under §24.5 (`Diagnostic::to_json`, written as `to_canonical_string` writes it: the code, the message, the primary span, the labels, the notes, the help and the causes, with the constant severity and spec, in canonical JSON; `diagnostic::sort_canonical`: diagnostics in the order of their path, byte start, code, and message, stable; and `LexLeanError::from_diagnostics` with `bounded`: the failure class of a set of diagnostics as its exit code, the most severe of their codes' classes, and the diagnostics the failure reports under `limits.max_diagnostics`, the first of them in canonical order and the `LLS8002` diagnostic that names the cap) is language-1.2 source in the `bootstrap/` project, as three production roots of `Diagnostics`: `diagnosticText`, `sortDiagnostics`, and `reportDiagnostics`, each eligible for `rust-std` with exactly its declared effects, none of them `recursion`, and each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator, agree with the oracle to the byte on the hand-built diagnostics, which reach every class of failure and both sides of the cap, on every committed expected diagnostic of the negative fixtures, written, sorted, and reported under four caps, and on seeded sets of diagnostics; 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 rendering of a diagnostic for a terminal and the producer-set details of §24.5 are outside the claim. | ## calculus diff --git a/README.md b/README.md index 0f5db6830c..62b5622fc4 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 the canonical diagnostic, 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-29` | `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..35586e6b86 100644 --- a/SPEC.md +++ b/SPEC.md @@ -8725,6 +8725,26 @@ 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 canonical diagnostic (§20.1) and the failure it makes (§24.5) are a component of the +driver as source (`BS-29`, issue 274), the module `Diagnostics`, with three production roots for +`rust-std`: + +| Root | Takes | Returns | Oracle | +| --- | --- | --- | --- | +| `LexLeanBoot.Diagnostics.diagnosticText` | a diagnostic | its canonical JSON text | `Diagnostic::to_json`, `to_canonical_string` | +| `LexLeanBoot.Diagnostics.sortDiagnostics` | diagnostics | them in canonical order | `diagnostic::sort_canonical` | +| `LexLeanBoot.Diagnostics.reportDiagnostics` | diagnostics, the cap, the phase | the exit code and the diagnostics reported | `LexLeanError::from_diagnostics`, `bounded` | + +`diagnosticText` writes the object's members in the order of their keys, each string by the +standard library's `escapeString` and each count in decimal, so the text is the canonical JSON of +§21.7. `sortDiagnostics` sorts by a byte key whose order is the order of the oracle's tuple: the +path with each nul byte doubled and the path ended by two nul bytes, the byte start as eight bytes +big-endian, the code, which is seven bytes, and the message, with the standard library's stable +`sortByKey`. `reportDiagnostics` sorts, takes the most severe class of the codes as its exit code +(the codes of the environment table, then the letter of the range), and, past the cap, keeps the +first diagnostics up to the cap and appends the `LLS8002` diagnostic, whose class then counts. +None of the three admits `recursion`. Rendering a diagnostic for a terminal stays in the host. + ## 18. Lean backend ### 18.1 Output contract @@ -11646,6 +11666,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-29` | `bootstrap` | The canonical diagnostic of SPEC.md §20.1 and the failure it makes under §24.5 (`Diagnostic::to_json`, written as `to_canonical_string` writes it: the code, the message, the primary span, the labels, the notes, the help and the causes, with the constant severity and spec, in canonical JSON; `diagnostic::sort_canonical`: diagnostics in the order of their path, byte start, code, and message, stable; and `LexLeanError::from_diagnostics` with `bounded`: the failure class of a set of diagnostics as its exit code, the most severe of their codes' classes, and the diagnostics the failure reports under `limits.max_diagnostics`, the first of them in canonical order and the `LLS8002` diagnostic that names the cap) is language-1.2 source in the `bootstrap/` project, as three production roots of `Diagnostics`: `diagnosticText`, `sortDiagnostics`, and `reportDiagnostics`, each eligible for `rust-std` with exactly its declared effects, none of them `recursion`, and each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator, agree with the oracle to the byte on the hand-built diagnostics, which reach every class of failure and both sides of the cap, on every committed expected diagnostic of the negative fixtures, written, sorted, and reported under four caps, and on seeded sets of diagnostics; 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 rendering of a diagnostic for a terminal and the producer-set details of §24.5 are outside the claim. | §17.23, §20.1, §24.5 | | `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 +11683,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..2e79a6069f 100644 --- a/VERIFICATION.md +++ b/VERIFICATION.md @@ -10999,6 +10999,55 @@ 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 canonical diagnostic is source (BS-29) + +`BS-29` holds the three production roots of `LexLeanBoot.Diagnostics` +(`bootstrap/src/Diagnostics.lex.tex`) to the oracle of the driver's diagnostics: +`diagnosticText` to `Diagnostic::to_json` written as `to_canonical_string` +writes it, `sortDiagnostics` to `diagnostic::sort_canonical`, and +`reportDiagnostics` to `LexLeanError::from_diagnostics` followed by `bounded`, +which gives the exit code of the failure and the diagnostics it reports under +`limits.max_diagnostics`. It is the first slice of the driver (#274) as source +and imports only the standard library's `Json`, `Numeral`, `Order`, and `Text`. +`diagnosticText` writes the members of the object in the order of their keys; +`sortDiagnostics` sorts by a byte key whose order is the order of the oracle's +tuple (the path with each nul byte doubled and ended by two nul bytes, the byte +start in eight bytes big-endian, the seven bytes of the code, the message) with +the stable `sortByKey`; `reportDiagnostics` takes the most severe class of the +codes and, past the cap, keeps the first diagnostics and appends `LLS8002`. None +of the three admits `recursion`. The case holds the roots to the oracle on +hand-built diagnostics that reach every class of failure, both sides of the cap, +equal keys, and paths that are prefixes of each other or hold a nul byte; on the +306 committed expected diagnostics of the 303 negative fixtures, each first +checked to be what the oracle writes, written one by one, each fixture's set +sorted and reported under four caps, and all of them sorted together; and on +seeded sets. 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 `Diagnostics`: `lexlean check`, `lexlean build`, and +`lexlean verify` pass, and the eligibility report gives each 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_29`, 209 s). Its corpus is 29 named vectors (11 written, 9 +sorted, 9 reported), the 306 committed diagnostics, and 200 and 1,000 seeded +sets. The evaluator agrees with the oracle on 472 texts, 513 sorts, and 1,422 +reports, the rendered packages under the pinned rustc on 4,641 runs, and each of +the 23 planted defects is detected by its own vector. The first run found one +fault of the module: the keyed list was built in reverse before the stable +sort, so diagnostics with equal keys came out in the reverse of their order (the +vector `equal keys keep their order` and four sets of the committed corpus); the +list is now in the input order, and the plant `equal keys are reversed` holds +it. Lean's audit corrected the axiom policy of 17 definitions. The case then +stops at the stack-bound step, `bootstrap/diagnostic_text is no package of the +committed exports`, as each bootstrap member did before its regeneration, which +produces the three packages. 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..ee8e88778d 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/Diagnostics.lex.tex` (SPEC.md §17.23, `BS-29`) imports the standard library's `Json`, +`Numeral`, `Order`, and `Text`: it writes, sorts, and caps the canonical diagnostic. diff --git a/bootstrap/lexlean.lock b/bootstrap/lexlean.lock index dec1db451b..594cd1a20e 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 = "5276014c3c1a79b31474efbe4b25238cf5f9acfc9a4792505f584610c2ba7607" lean_toolchain = "leanprover/lean4:v4.32.1" [[workspace_file]] diff --git a/bootstrap/lexlean.toml b/bootstrap/lexlean.toml index f57986a7e8..7bcaa26128 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/Diagnostics.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"] build_root = ".lexlean" lockfile = "lexlean.lock" lean_workspace = "." diff --git a/bootstrap/src/Diagnostics.lex.tex b/bootstrap/src/Diagnostics.lex.tex new file mode 100644 index 0000000000..da2a4f7681 --- /dev/null +++ b/bootstrap/src/Diagnostics.lex.tex @@ -0,0 +1,319 @@ +\begin{lexlean}{Diagnostics} +\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: Span, + type_parameters: [], + parameters: [], + fields: [ + {name: path, type: Bytes}, + {name: byteStart, type: Nat}, + {name: byteEnd, type: Nat}, + {name: lineStart, type: Nat}, + {name: columnStart, type: Nat}, + {name: lineEnd, type: Nat}, + {name: columnEnd, type: Nat} + ] +} + +structure{ + name: Label, + type_parameters: [], + parameters: [], + fields: [{name: message, type: Bytes}, {name: span, type: Span}] +} + +structure{ + name: Note, + type_parameters: [], + parameters: [], + fields: [{name: message, type: Bytes}, {name: span, type: (Option Span)}] +} + +structure{ + name: Diagnostic, + type_parameters: [], + parameters: [], + fields: [ + {name: code, type: Bytes}, + {name: message, type: Bytes}, + {name: primary, type: (Option Span)}, + {name: labels, type: (List Label)}, + {name: notes, type: (List Note)}, + {name: help, type: (List Bytes)}, + {name: causes, type: (List Bytes)} + ] +} + +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: jsonString, + parameters: [text : Bytes], + result: Bytes, + body: (LexLeanStd.Json::escapeString text), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: num, + parameters: [value : Nat], + result: Bytes, + body: (LexLeanStd.Numeral::decimal value), + executable: true +} + +definition{ + name: field, + parameters: [key : Bytes, shown : Bytes], + result: Bytes, + body: (cat (cat (jsonString key) (lit ":")) shown), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: objectOf, + parameters: [fields : (List Bytes)], + result: Bytes, + body: (cat (cat (lit "{") (LexLeanStd.Text::joinWith fields (lit ","))) (lit "}")), + executable: true +} + +definition{ + name: arrayOf, + parameters: [items : (List Bytes)], + result: Bytes, + body: (cat (cat (lit "[") (LexLeanStd.Text::joinWith items (lit ","))) (lit "]")), + executable: true +} + +definition{ + name: spanText, + parameters: [span : Span], + result: Bytes, + body: (objectOf (cons (field (lit "byte_end") (num (project span byteEnd))) (cons (field (lit "byte_start") (num (project span byteStart))) (cons (field (lit "column_end") (num (project span columnEnd))) (cons (field (lit "column_start") (num (project span columnStart))) (cons (field (lit "line_end") (num (project span lineEnd))) (cons (field (lit "line_start") (num (project span lineStart))) (cons (field (lit "path") (jsonString (project span path))) (nil Bytes))))))))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: labelText, + parameters: [label : Label], + result: Bytes, + body: (objectOf (cons (field (lit "message") (jsonString (project label message))) (cons (field (lit "span") (spanText (project label span))) (nil Bytes)))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: noteText, + parameters: [note : Note], + result: Bytes, + body: (match (project note span) + | Option.some span => (objectOf (cons (field (lit "message") (jsonString (project note message))) (cons (field (lit "span") (spanText span)) (nil Bytes)))) + | Option.none => (objectOf (cons (field (lit "message") (jsonString (project note message))) (nil Bytes)))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: strings, + parameters: [items : (List Bytes)], + result: Bytes, + body: (arrayOf (prim list_fold (fun (acc : (List Bytes)) (item : Bytes) => (cons (jsonString item) acc)) (nil Bytes) (LexLeanStd.Order::reverseList [Bytes] items) : (List Bytes))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: labelsText, + parameters: [items : (List Label)], + result: Bytes, + body: (arrayOf (prim list_fold (fun (acc : (List Bytes)) (item : Label) => (cons (labelText item) acc)) (nil Bytes) (LexLeanStd.Order::reverseList [Label] items) : (List Bytes))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: notesText, + parameters: [items : (List Note)], + result: Bytes, + body: (arrayOf (prim list_fold (fun (acc : (List Bytes)) (item : Note) => (cons (noteText item) acc)) (nil Bytes) (LexLeanStd.Order::reverseList [Note] items) : (List Bytes))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: diagnosticText, + parameters: [given : Diagnostic], + result: Bytes, + body: (let tail : (List Bytes) := (cons (field (lit "severity") (jsonString (lit "error"))) (cons (field (lit "spec") (jsonString (lit "lexlean/diagnostic/1"))) (nil Bytes))); (let located : (List Bytes) := (match (project given primary) + | Option.some span => (cons (field (lit "primary") (spanText span)) tail) + | Option.none => tail); (objectOf (cons (field (lit "causes") (strings (project given causes))) (cons (field (lit "code") (jsonString (project given code))) (cons (field (lit "help") (strings (project given help))) (cons (field (lit "labels") (labelsText (project given labels))) (cons (field (lit "message") (jsonString (project given message))) (cons (field (lit "notes") (notesText (project given notes))) located))))))))), + axioms: [Quot.sound, propext], + executable: true, + production: {effects: [allocation, overflow], targets: [rust-std]} +} + +definition{ + name: byteText, + parameters: [value : Nat], + result: Bytes, + body: (LexLeanStd.Numeral::pick (LexLeanStd.Numeral::byteValues) value), + executable: true +} + +definition{ + name: beStep, + parameters: [state : (Nat * (Nat * Bytes))], + result: (Option (Nat * (Nat * Bytes))), + body: (if ((first state) =? 0) then (ctor Option.none [(Nat * (Nat * Bytes))]) else (ctor Option.some [(Nat * (Nat * Bytes))] ((prim subtract (first state) 1 : Nat), ((prim quotient (first (second state)) 256 0 : Nat), (cat (byteText (prim remainder (first (second state)) 256 0 : Nat)) (second (second state))))))), + executable: true +} + +definition{ + name: bigEndian, + parameters: [value : Nat], + result: Bytes, + body: (second (second (first (prim iterate_until (fun (state : (Nat * (Nat * Bytes))) => (beStep state)) 9 (8, (value, 0x)) : ((Nat * (Nat * Bytes)) * Bool))))), + executable: true +} + +definition{ + name: orderStep, + parameters: [path : Bytes, n : Nat, state : (Nat * Bytes)], + result: (Option (Nat * Bytes)), + body: (let position : Nat := (first state); (if (position (if (prim equal byte (0 : UInt8) : Bool) then (ctor Option.some [(Nat * Bytes)] ((position + 1), (cat (second state) 0x0001))) else (ctor Option.some [(Nat * Bytes)] ((position + 1), (cat (second state) (byteText (prim to_nat byte : Nat)))))) + | Option.none => (ctor Option.none [(Nat * Bytes)])) else (ctor Option.none [(Nat * Bytes)]))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: orderedPath, + parameters: [path : Bytes], + result: Bytes, + body: (let n : Nat := (prim length path : Nat); (cat (second (first (prim iterate_until (fun [n, path] (state : (Nat * Bytes)) => (orderStep path n state)) (n + 1) (0, 0x) : ((Nat * Bytes) * Bool)))) 0x0000)), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: sortKey, + parameters: [given : Diagnostic], + result: Bytes, + body: (let place : (Bytes * Nat) := (match (project given primary) + | Option.some span => ((project span path), (project span byteStart)) + | Option.none => (0x, 0)); (cat (cat (cat (orderedPath (first place)) (bigEndian (second place))) (project given code)) (project given message))), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: keyed, + parameters: [given : Diagnostic], + result: (Bytes * Diagnostic), + body: ((sortKey given), given), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: sortDiagnostics, + parameters: [items : (List Diagnostic)], + result: (List Diagnostic), + body: (prim list_fold (fun (acc : (List Diagnostic)) (entry : (Bytes * Diagnostic)) => (cons (second entry) acc)) (nil Diagnostic) (LexLeanStd.Order::reverseList [(Bytes * Diagnostic)] (LexLeanStd.Order::sortByKey [Diagnostic] (LexLeanStd.Order::reverseList [(Bytes * Diagnostic)] (prim list_fold (fun (acc : (List (Bytes * Diagnostic))) (item : Diagnostic) => (cons (keyed item) acc)) (nil (Bytes * Diagnostic)) items : (List (Bytes * Diagnostic)))))) : (List Diagnostic)), + axioms: [Quot.sound, propext], + executable: true, + production: {effects: [allocation, overflow], targets: [rust-std]} +} + +definition{ + name: isEnvironmentCode, + parameters: [code : Bytes], + result: Bool, + body: (prim list_fold (fun [code] (found : Bool) (listed : Bytes) => (if found then true else (prim equal code listed : Bool))) false (cons (lit "LLB6004") (cons (lit "LLV7001") (cons (lit "LLV7007") (cons (lit "LLV7008") (cons (lit "LLV7009") (cons (lit "LLV7010") (cons (lit "LLV7012") (cons (lit "LLV7014") (cons (lit "LLV7017") (cons (lit "LLV7018") (nil Bytes))))))))))) : Bool), + executable: true +} + +definition{ + name: codeExit, + parameters: [code : Bytes], + result: Nat, + body: (if (isEnvironmentCode code) then 3 else (match (LexLeanStd.Text::byteAt code 2) + | Option.some letter => (let value : Nat := (prim to_nat letter : Nat); (if (value =? 67) then 2 else (if (value =? 83) then 4 else (if (value =? 73) then 70 else 1)))) + | Option.none => 1)), + axioms: [Quot.sound, propext], + executable: true +} + +definition{ + name: worstExit, + parameters: [items : (List Diagnostic), empty : Nat], + result: Nat, + body: (match items + | List.nil => empty + | List.cons head rest => (prim list_fold (fun (worst : Nat) (item : Diagnostic) => (let rank : Nat := (codeExit (project item code)); (if (worst (ctor Option.none [(Nat * ((List Diagnostic) * (List Diagnostic)))]) + | List.cons head rest => (ctor Option.some [(Nat * ((List Diagnostic) * (List Diagnostic)))] ((prim subtract (first state) 1 : Nat), (rest, (cons head (second (second state)))))))), + executable: true +} + +definition{ + name: firstOf, + parameters: [items : (List Diagnostic), count : Nat], + result: (List Diagnostic), + body: (LexLeanStd.Order::reverseList [Diagnostic] (second (second (first (prim iterate_until (fun (state : (Nat * ((List Diagnostic) * (List Diagnostic)))) => (takeStep state)) (count + 1) (count, (items, (nil Diagnostic))) : ((Nat * ((List Diagnostic) * (List Diagnostic))) * Bool)))))), + executable: true +} + +definition{ + name: exceeded, + parameters: [phase : Bytes, limit : Nat, observed : Nat], + result: Diagnostic, + body: (record Diagnostic {code := (lit "LLS8002"), message := (cat (cat (cat (cat (cat (cat (cat (cat (lit "max_diagnostics exceeded in phase ") phase) (lit ": configured ")) (num limit)) (lit ", observed ")) (num observed)) (lit "; the first ")) (num limit)) (lit " diagnostics are reported")), primary := (ctor Option.none [Span]), labels := (nil Label), notes := (nil Note), help := (nil Bytes), causes := (nil Bytes)}), + executable: true +} + +definition{ + name: reportDiagnostics, + parameters: [items : (List Diagnostic), limit : Nat, phase : Bytes], + result: (Nat * (List Diagnostic)), + body: (let sorted : (List Diagnostic) := (sortDiagnostics items); (let observed : Nat := (prim length items : Nat); (if (observed <=? limit) then ((worstExit sorted 70), sorted) else (let kept : (List Diagnostic) := (LexLeanStd.Order::reverseList [Diagnostic] (cons (exceeded phase limit observed) (LexLeanStd.Order::reverseList [Diagnostic] (firstOf sorted limit)))); ((worstExit kept 70), kept))))), + axioms: [Quot.sound, propext], + executable: true, + production: {effects: [allocation, overflow], targets: [rust-std]} +} +\end{semanticmodule} +\end{lexlean} diff --git a/crates/conformance/src/cases/bootstrap.rs b/crates/conformance/src/cases/bootstrap.rs index 49c5bbf14c..c731a5873c 100644 --- a/crates/conformance/src/cases/bootstrap.rs +++ b/crates/conformance/src/cases/bootstrap.rs @@ -21,6 +21,7 @@ use crate::rust_harness::{self, Calls}; use crate::rust_packages; use crate::support::{self, P}; +mod diagnostics; mod gnaf_validate; mod runtime_validate; mod rust_assemble; @@ -2457,6 +2458,7 @@ fn case(id: &str) { "BS-16" => gnaf_validate::case(), // §17.23, §17.20: the canonical LaTeX of a tooling module. "BS-20" => tooling_latex::case(), + "BS-29" => diagnostics::case(), other => panic!("no bootstrap case is wired for {other}"), } } diff --git a/crates/conformance/src/cases/bootstrap/diagnostics.rs b/crates/conformance/src/cases/bootstrap/diagnostics.rs new file mode 100644 index 0000000000..444f9312f1 --- /dev/null +++ b/crates/conformance/src/cases/bootstrap/diagnostics.rs @@ -0,0 +1,993 @@ +//! `BS-29` (SPEC.md §17.23, §20.1, §24.5): the canonical diagnostic as +//! language-1.2 source, `LexLeanBoot.Diagnostics`, held to the byte to +//! `lexlean::diagnostic::{Diagnostic::to_json, sort_canonical}` and to +//! `LexLeanError::from_diagnostics(..).bounded(..)`. +//! +//! `diagnosticText` writes the canonical JSON text of one diagnostic (the +//! object of `to_json`, written as `to_canonical_string` writes it); +//! `sortDiagnostics` orders diagnostics as `sort_canonical` does, by a byte +//! key that preserves the order of the oracle's tuple (path, byte start, code, +//! message); `reportDiagnostics` gives the failure class of a set of +//! diagnostics as its exit code and the diagnostics a failure reports under the +//! configured `max_diagnostics`, with the `LLS8002` diagnostic the cap appends. +//! +//! Each planted defect names the one vector that catches it. + +use std::collections::{BTreeMap, BTreeSet}; + +use lexlean::calculus::Value; +use lexlean::diagnostic::{sort_canonical, Diagnostic, DiagnosticCode, Label, Note, Span}; +use lexlean::LexLeanError; +use serde_json::Value as Json2; + +use super::rust_validate::{eligibility_of, rustc_differential}; +use super::{list, nat_val, option, pair, text, Run, Seeded}; +use crate::production_export as harness; +use crate::support::{self, repo_root}; + +const MODULE: &str = "LexLeanBoot.Diagnostics"; +const ROOTS: [(&str, &[&str]); 3] = [ + ("diagnosticText", &["allocation", "overflow"]), + ("sortDiagnostics", &["allocation", "overflow"]), + ("reportDiagnostics", &["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; +/// The caps the committed diagnostics of each fixture are reported under. +const CAPS: [u64; 4] = [0, 1, 2, 256]; +/// Seeded diagnostic sets under the evaluator, and under rustc. +const EVALUATOR_SEEDED: usize = 200; +const RUSTC_SEEDED: usize = 1_000; + +// ------------------------------------------------------------- the encoders + +fn code(text: &str) -> DiagnosticCode { + let leaked: &'static str = Box::leak(text.to_owned().into_boxed_str()); + DiagnosticCode::from_validated(DiagnosticCode::validate(leaked)) +} + +fn enc_span(span: &Span) -> Value { + Value::Adt { + constructor: 0, + fields: vec![ + text(&span.path), + nat_val(span.byte_start), + nat_val(span.byte_end), + nat_val(span.line_start), + nat_val(span.column_start), + nat_val(span.line_end), + nat_val(span.column_end), + ], + } +} + +fn enc(diagnostic: &Diagnostic) -> Value { + Value::Adt { + constructor: 0, + fields: vec![ + text(diagnostic.code.as_str()), + text(&diagnostic.message), + option(diagnostic.primary.as_ref().map(enc_span)), + list( + diagnostic + .labels + .iter() + .map(|label| Value::Adt { + constructor: 0, + fields: vec![text(&label.message), enc_span(&label.span)], + }) + .collect(), + ), + list( + diagnostic + .notes + .iter() + .map(|note| Value::Adt { + constructor: 0, + fields: vec![ + text(¬e.message), + option(note.span.as_ref().map(enc_span)), + ], + }) + .collect(), + ), + list(diagnostic.help.iter().map(|item| text(item)).collect()), + list(diagnostic.causes.iter().map(|item| text(item)).collect()), + ], + } +} + +fn encs(diagnostics: &[Diagnostic]) -> Value { + list(diagnostics.iter().map(enc).collect()) +} + +fn text_run(diagnostic: &Diagnostic) -> Run { + ( + vec![enc(diagnostic)], + serde_json::to_value(text(&diagnostic.to_json().to_canonical_string())) + .expect("a value is JSON"), + ) +} + +fn sort_run(diagnostics: &[Diagnostic]) -> Run { + let mut sorted = diagnostics.to_vec(); + sort_canonical(&mut sorted); + ( + vec![encs(diagnostics)], + serde_json::to_value(encs(&sorted)).expect("a value is JSON"), + ) +} + +/// The exit code and the reported diagnostics of a failure, as the oracle +/// makes them. +fn reported(diagnostics: &[Diagnostic], cap: u64, phase: &str) -> (i32, Vec) { + let error = LexLeanError::from_diagnostics(diagnostics.to_vec()).bounded(cap, phase); + (error.class.exit_code(), error.diagnostics) +} + +fn report_run(diagnostics: &[Diagnostic], cap: u64, phase: &str) -> Run { + let (exit, kept) = reported(diagnostics, cap, phase); + ( + vec![ + encs(diagnostics), + Value::Nat { + value: cap.to_string(), + }, + text(phase), + ], + serde_json::to_value(pair( + nat_val(usize::try_from(exit).expect("an exit code")), + encs(&kept), + )) + .expect("a value is JSON"), + ) +} + +// ------------------------------------------------------- reading the corpus + +fn span_of(json: &Json2) -> Span { + let n = |key: &str| usize::try_from(json[key].as_u64().expect("a count")).expect("usize"); + Span { + path: json["path"].as_str().expect("a path").to_owned(), + byte_start: n("byte_start"), + byte_end: n("byte_end"), + line_start: n("line_start"), + column_start: n("column_start"), + line_end: n("line_end"), + column_end: n("column_end"), + } +} + +fn strings_of(json: &Json2) -> Vec { + json.as_array() + .expect("an array") + .iter() + .map(|item| item.as_str().expect("a string").to_owned()) + .collect() +} + +fn diagnostic_of(json: &Json2) -> Diagnostic { + let mut diagnostic = Diagnostic::new( + code(json["code"].as_str().expect("a code")), + json["message"].as_str().expect("a message"), + ); + if let Some(primary) = json.get("primary") { + diagnostic.primary = Some(span_of(primary)); + } + for label in json["labels"].as_array().expect("labels") { + diagnostic.labels.push(Label { + message: label["message"].as_str().expect("a message").to_owned(), + span: span_of(&label["span"]), + }); + } + for note in json["notes"].as_array().expect("notes") { + diagnostic.notes.push(Note { + message: note["message"].as_str().expect("a message").to_owned(), + span: note.get("span").map(span_of), + }); + } + diagnostic.help = strings_of(&json["help"]); + diagnostic.causes = strings_of(&json["causes"]); + diagnostic +} + +/// The committed expected diagnostics of every negative fixture, each file's +/// set with its path; each is first checked to be what the oracle writes. +fn committed() -> Vec<(String, Vec)> { + let root = repo_root().join("tests/negative"); + let mut names: Vec = std::fs::read_dir(root.as_std_path()) + .expect("the negative fixtures") + .flatten() + .map(|entry| entry.file_name().to_string_lossy().into_owned()) + .collect(); + names.sort(); + let mut out = Vec::new(); + for name in names { + let path = root.join(&name).join("expected/diagnostics.json"); + let Ok(bytes) = std::fs::read(path.as_std_path()) else { + continue; + }; + let json: Json2 = serde_json::from_slice(&bytes).expect("diagnostics JSON"); + let diagnostics: Vec = json + .as_array() + .expect("an array of diagnostics") + .iter() + .map(diagnostic_of) + .collect(); + let written = format!( + "[{}]", + diagnostics + .iter() + .map(|diagnostic| diagnostic.to_json().to_canonical_string()) + .collect::>() + .join(",") + ); + assert_eq!( + written.as_bytes(), + String::from_utf8_lossy(&bytes).trim_end().as_bytes(), + "{name}: the committed diagnostics are what the oracle writes" + ); + out.push((name, diagnostics)); + } + out +} + +// ------------------------------------------------------------------ vectors + +fn at(path: &str, start: usize) -> Span { + Span { + path: path.to_owned(), + byte_start: start, + byte_end: start + 3, + line_start: 2, + column_start: 5, + line_end: 4, + column_end: 7, + } +} + +fn d(code_text: &str, message: &str) -> Diagnostic { + Diagnostic::new(code(code_text), message) +} + +fn located(code_text: &str, message: &str, path: &str, start: usize) -> Diagnostic { + d(code_text, message).with_span(at(path, start)) +} + +enum Subject { + Text(Box), + Sort(Vec), + Report(Vec, u64, String), +} + +struct Vector { + label: String, + subject: Subject, +} + +impl Vector { + fn root(&self) -> usize { + match self.subject { + Subject::Text(_) => 0, + Subject::Sort(_) => 1, + Subject::Report(..) => 2, + } + } + + fn run(&self) -> Run { + match &self.subject { + Subject::Text(diagnostic) => text_run(diagnostic), + Subject::Sort(items) => sort_run(items), + Subject::Report(items, cap, phase) => report_run(items, *cap, phase), + } + } +} + +#[allow(clippy::too_many_lines)] +fn named() -> Vec { + let mut out: Vec = Vec::new(); + let mut add = |label: &str, subject: Subject| { + out.push(Vector { + label: label.to_owned(), + subject, + }); + }; + // The text of one diagnostic. + add( + "a minimal diagnostic", + Subject::Text(Box::new(d("LLT4001", "m"))), + ); + add( + "a located diagnostic", + Subject::Text(Box::new(located( + "LLT4001", + "phase link: m", + "src/Main.lex.tex", + 113, + ))), + ); + add( + "a span of distinct coordinates", + Subject::Text(Box::new(d("LLL1001", "m").with_span(Span { + path: "a".to_owned(), + byte_start: 1, + byte_end: 2, + line_start: 3, + column_start: 4, + line_end: 5, + column_end: 6, + }))), + ); + add( + "a note without a span", + Subject::Text(Box::new(d("LLV7005", "m").with_note("unlocated"))), + ); + add( + "a note with a span", + Subject::Text(Box::new( + d("LLV7005", "m").with_located_note("located", at("b", 9)), + )), + ); + add( + "two labels", + Subject::Text(Box::new( + d("LLP2001", "m") + .with_label("first", at("x", 1)) + .with_label("second", at("y", 2)), + )), + ); + add( + "help with a quote", + Subject::Text(Box::new( + d("LLC0102", "m").with_help("run `lexlean lock` \"now\""), + )), + ); + add( + "causes in order", + Subject::Text(Box::new( + d("LLI9001", "m") + .with_cause("inner") + .with_cause("innermost"), + )), + ); + add( + "a message with a newline", + Subject::Text(Box::new(d( + "LLT4001", + "line one\nline two\ttab \\ slash \u{1} \u{e9}", + ))), + ); + add( + "every part at once", + Subject::Text(Box::new( + located("LLB6004", "m", "p/q.lex.tex", 7) + .with_label("l", at("r", 1)) + .with_note("n") + .with_located_note("o", at("s", 2)) + .with_help("h") + .with_cause("c"), + )), + ); + add( + "a path beyond ASCII", + Subject::Text(Box::new(located( + "LLL1001", + "m", + "src/\u{e9}t\u{e9}.lex.tex", + 0, + ))), + ); + // Sorting. + add( + "two files", + Subject::Sort(vec![ + located("LLT4001", "m", "src/B.lex.tex", 1), + located("LLT4001", "m", "src/A.lex.tex", 9), + ]), + ); + add( + "a path and its extension", + Subject::Sort(vec![ + located("LLT4001", "m", "ab", 0), + located("LLT4001", "m", "a", 18_446_744_073_709_551_000), + ]), + ); + add( + "one file, two offsets", + Subject::Sort(vec![ + located("LLT4001", "m", "f", 256), + located("LLT4001", "m", "f", 1), + ]), + ); + add( + "same place, two codes", + Subject::Sort(vec![ + located("LLT4002", "a", "f", 5), + located("LLT4001", "z", "f", 5), + ]), + ); + add( + "same place and code, two messages", + Subject::Sort(vec![ + located("LLT4001", "b", "f", 5), + located("LLT4001", "a", "f", 5), + ]), + ); + add( + "unlocated first", + Subject::Sort(vec![located("LLT4001", "m", "a", 0), d("LLC0102", "m")]), + ); + add( + "a path with a nul", + Subject::Sort(vec![ + located("LLT4001", "m", "a\u{0}", 0), + located("LLT4001", "m", "a", 9), + located("LLT4001", "m", "a\u{1}", 0), + ]), + ); + add( + "equal keys keep their order", + Subject::Sort(vec![ + d("LLT4001", "m").with_note("first"), + d("LLT4001", "m").with_note("second"), + ]), + ); + add("no diagnostics to sort", Subject::Sort(Vec::new())); + // Reporting. + let phase = || "check".to_owned(); + add("no diagnostics", Subject::Report(Vec::new(), 256, phase())); + add( + "a language failure", + Subject::Report(vec![d("LLT4001", "m")], 256, phase()), + ); + add( + "a configuration failure", + Subject::Report(vec![d("LLC0102", "m")], 256, phase()), + ); + add( + "an environment failure", + Subject::Report(vec![d("LLV7001", "m"), d("LLT4001", "m")], 256, phase()), + ); + add( + "an internal and a limit failure", + Subject::Report(vec![d("LLS8001", "m"), d("LLI9001", "m")], 256, phase()), + ); + add( + "three diagnostics capped at two", + Subject::Report( + vec![ + located("LLT4001", "c", "f", 3), + located("LLT4001", "a", "f", 1), + located("LLT4001", "b", "f", 2), + ], + 2, + "link".to_owned(), + ), + ); + add( + "three language failures capped at one", + Subject::Report( + vec![d("LLT4001", "a"), d("LLT4002", "b"), d("LLT4003", "c")], + 1, + phase(), + ), + ); + add( + "capped at zero", + Subject::Report(vec![d("LLT4001", "a"), d("LLT4002", "b")], 0, phase()), + ); + add( + "exactly at the cap", + Subject::Report(vec![d("LLT4001", "a"), d("LLT4002", "b")], 2, phase()), + ); + out +} + +// ------------------------------------------------------------------- seeded + +const PATHS: &[&str] = &[ + "", + "a", + "ab", + "src/Main.lex.tex", + "src/\u{e9}.lex.tex", + "a\u{0}b", +]; +const MESSAGES: &[&str] = &[ + "", + "m", + "phase link: expected `x`", + "quote \" and slash \\", + "line\nbreak", + "control \u{1f} and \u{7f}", + "\u{1f600} emoji", +]; + +fn drawn_span(seeded: &mut Seeded) -> Span { + let start = *seeded.pick(&[0usize, 1, 9, 255, 256, 65_536, 4_294_967_296]); + Span { + path: (*seeded.pick(PATHS)).to_owned(), + byte_start: start, + byte_end: start + seeded.below(5), + line_start: 1 + seeded.below(9), + column_start: 1 + seeded.below(9), + line_end: 1 + seeded.below(9), + column_end: 1 + seeded.below(9), + } +} + +fn drawn(seeded: &mut Seeded, codes: &[String]) -> Diagnostic { + let mut diagnostic = d(seeded.pick(codes), seeded.pick(MESSAGES)); + if seeded.chance(70) { + diagnostic.primary = Some(drawn_span(seeded)); + } + for _ in 0..seeded.below(3) { + let span = drawn_span(seeded); + diagnostic = diagnostic.with_label(*seeded.pick(MESSAGES), span); + } + for _ in 0..seeded.below(3) { + if seeded.chance(50) { + let span = drawn_span(seeded); + diagnostic = diagnostic.with_located_note(*seeded.pick(MESSAGES), span); + } else { + diagnostic = diagnostic.with_note(*seeded.pick(MESSAGES)); + } + } + for _ in 0..seeded.below(2) { + diagnostic = diagnostic.with_help(*seeded.pick(MESSAGES)); + } + for _ in 0..seeded.below(2) { + diagnostic = diagnostic.with_cause(*seeded.pick(MESSAGES)); + } + diagnostic +} + +/// `count` seeded sets: the text of each diagnostic, the sort of each set, +/// and the report of each set under a drawn cap. +fn seeded_runs(count: usize, codes: &[String], seed: u64) -> [Vec; 3] { + let mut seeded = Seeded(seed); + let mut out: [Vec; 3] = [Vec::new(), Vec::new(), Vec::new()]; + for _ in 0..count { + let size = seeded.below(5); + let set: Vec = (0..size).map(|_| drawn(&mut seeded, codes)).collect(); + if let Some(first) = set.first() { + out[0].push(text_run(first)); + } + out[1].push(sort_run(&set)); + let cap = u64::try_from(seeded.below(5)).expect("a cap"); + out[2].push(report_run( + &set, + cap, + seeded.pick(&["check", "link", "build"]), + )); + } + out +} + +// ------------------------------------------------------------------- plants + +struct Plant { + label: &'static str, + root: usize, + site: &'static str, + replacement: &'static str, + vector: &'static str, +} + +const PLANTS: &[Plant] = &[ + Plant { + label: "the severity is a warning", + root: 0, + site: "(jsonString (lit \"error\"))", + replacement: "(jsonString (lit \"warning\"))", + vector: "a minimal diagnostic", + }, + Plant { + label: "the primary span is left out", + root: 0, + site: "| Option.some span => (cons (field (lit \"primary\") (spanText span)) tail)", + replacement: "| Option.some span => tail", + vector: "a located diagnostic", + }, + Plant { + label: "the byte end is the byte start", + root: 0, + site: "(field (lit \"byte_end\") (num (project span byteEnd)))", + replacement: "(field (lit \"byte_end\") (num (project span byteStart)))", + vector: "a located diagnostic", + }, + Plant { + label: "the start column is the start line", + root: 0, + site: "(field (lit \"column_start\") (num (project span columnStart)))", + replacement: "(field (lit \"column_start\") (num (project span lineStart)))", + vector: "a span of distinct coordinates", + }, + Plant { + label: "a note without a span writes a null span", + root: 0, + site: "| Option.none => (objectOf (cons (field (lit \"message\") (jsonString (project note message))) (nil Bytes)))", + replacement: "| Option.none => (objectOf (cons (field (lit \"message\") (jsonString (project note message))) (cons (field (lit \"span\") (lit \"null\")) (nil Bytes))))", + vector: "a note without a span", + }, + Plant { + label: "labels are written last first", + root: 0, + site: "(nil Bytes) (LexLeanStd.Order::reverseList [Label] items) : (List Bytes)", + replacement: "(nil Bytes) items : (List Bytes)", + vector: "two labels", + }, + Plant { + label: "help and causes are not escaped", + root: 0, + site: "(cons (jsonString item) acc)", + replacement: "(cons (cat (cat (lit \"\\\"\") item) (lit \"\\\"\")) acc)", + vector: "help with a quote", + }, + Plant { + label: "the message is not escaped", + root: 0, + site: "(field (lit \"message\") (jsonString (project given message)))", + replacement: "(field (lit \"message\") (cat (cat (lit \"\\\"\") (project given message)) (lit \"\\\"\")))", + vector: "a message with a newline", + }, + Plant { + label: "the path does not order", + root: 1, + site: "(cat (cat (cat (orderedPath (first place)) (bigEndian (second place))) (project given code)) (project given message))", + replacement: "(cat (cat (bigEndian (second place)) (project given code)) (project given message))", + vector: "two files", + }, + Plant { + label: "a shorter path is not ended", + root: 1, + site: "0x0000))", + replacement: "0x))", + vector: "a path and its extension", + }, + Plant { + label: "the byte start is little-endian", + root: 1, + site: "(cat (byteText (prim remainder (first (second state)) 256 0 : Nat)) (second (second state)))", + replacement: "(cat (second (second state)) (byteText (prim remainder (first (second state)) 256 0 : Nat)))", + vector: "one file, two offsets", + }, + Plant { + label: "the code does not order", + root: 1, + site: "(bigEndian (second place))) (project given code))", + replacement: "(bigEndian (second place))) 0x)", + vector: "same place, two codes", + }, + Plant { + label: "the sort is descending", + root: 1, + site: "(LexLeanStd.Order::reverseList [(Bytes * Diagnostic)] (LexLeanStd.Order::sortByKey [Diagnostic]", + replacement: "(LexLeanStd.Order::sortByKey [Diagnostic] (LexLeanStd.Order::sortByKey [Diagnostic]", + vector: "two files", + }, + Plant { + label: "equal keys are reversed", + root: 1, + site: "(LexLeanStd.Order::sortByKey [Diagnostic] (LexLeanStd.Order::reverseList [(Bytes * Diagnostic)] (prim list_fold", + replacement: "(LexLeanStd.Order::sortByKey [Diagnostic] (LexLeanStd.Order::sortByKey [Diagnostic] (prim list_fold", + vector: "equal keys keep their order", + }, + Plant { + label: "a nul in a path is no byte", + root: 1, + site: "(cat (second state) 0x0001)", + replacement: "(second state)", + vector: "a path with a nul", + }, + Plant { + label: "the cap admits one more", + root: 2, + site: "(if (observed <=? limit) then", + replacement: "(if (observed <=? (limit + 1)) then", + vector: "three diagnostics capped at two", + }, + Plant { + label: "an environment code is a language failure", + root: 2, + site: "(if (isEnvironmentCode code) then 3 else", + replacement: "(if false then 3 else", + vector: "an environment failure", + }, + Plant { + label: "an internal code is a language failure", + root: 2, + site: "(if (value =? 73) then 70 else 1)", + replacement: "(if (value =? 73) then 1 else 1)", + vector: "an internal and a limit failure", + }, + Plant { + label: "no diagnostics is a language failure", + root: 2, + site: "| List.nil => empty", + replacement: "| List.nil => 1", + vector: "no diagnostics", + }, + Plant { + label: "the cap reports the observed count as kept", + root: 2, + site: "(lit \"; the first \")) (num limit))", + replacement: "(lit \"; the first \")) (num observed))", + vector: "three diagnostics capped at two", + }, + Plant { + label: "the cap's diagnostic comes first", + root: 2, + site: "(LexLeanStd.Order::reverseList [Diagnostic] (cons (exceeded phase limit observed) (LexLeanStd.Order::reverseList [Diagnostic] (firstOf sorted limit))))", + replacement: "(cons (exceeded phase limit observed) (firstOf sorted limit))", + vector: "three diagnostics capped at two", + }, + Plant { + label: "the class leaves out the cap's diagnostic", + root: 2, + site: "((worstExit kept 70), kept)", + replacement: "((worstExit (firstOf sorted limit) 70), kept)", + vector: "three language failures capped at one", + }, + Plant { + label: "a cap of zero keeps everything", + root: 2, + site: "(if ((first state) =? 0) then (ctor Option.none [(Nat * ((List Diagnostic) * (List Diagnostic)))])", + replacement: "(if false then (ctor Option.none [(Nat * ((List Diagnostic) * (List Diagnostic)))])", + vector: "capped at zero", + }, +]; + +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)); + assert_eq!( + vector.root(), + plant.root, + "{}: the vector is a run of the root planted", + plant.label + ); + let planted = support::P::bootstrap(); + let source = planted.read_raw("src/Diagnostics.lex.tex"); + assert_eq!( + source.matches(plant.site).count(), + 1, + "{}: the plant site occurs once", + plant.label + ); + planted.write( + "src/Diagnostics.lex.tex", + &source.replacen(plant.site, plant.replacement, 1), + ); + let checked = support::checked_project(&planted); + let low = super::lower(&checked, &planted, MODULE, ROOTS[plant.root].0); + match super::evaluate(&low, &[vector.run()], 1).first() { + Some(first) => eprintln!( + "BS-29: 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-29: {}: 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("Diagnostics"), + "Diagnostics is a linked module of the project" + ); + eligibility_of(&project, "Diagnostics", MODULE, &ROOTS); + + let vectors = named(); + let labels: BTreeSet<&str> = vectors.iter().map(|vector| vector.label.as_str()).collect(); + assert_eq!(labels.len(), vectors.len(), "each vector has its own label"); + // Every class of failure and both sides of the cap are reached. + let mut exits = BTreeSet::new(); + let mut capped = false; + let mut uncapped = false; + for vector in &vectors { + if let Subject::Report(items, cap, phase) = &vector.subject { + let (exit, kept) = reported(items, *cap, phase); + exits.insert(exit); + if kept.iter().any(|item| item.code.as_str() == "LLS8002") { + capped = true; + } else { + uncapped = true; + } + } + } + assert_eq!( + exits.into_iter().collect::>(), + vec![1, 2, 3, 4, 70], + "the vectors reach every class of failure" + ); + assert!( + capped && uncapped, + "the vectors reach both sides of the cap" + ); + let mut runs: [Vec; 3] = [Vec::new(), Vec::new(), Vec::new()]; + for vector in &vectors { + runs[vector.root()].push(vector.run()); + } + + // The committed diagnostics: each written, each fixture's set sorted and + // reported under each cap, and all of them sorted together. + let fixtures = committed(); + let mut all: Vec = Vec::new(); + let mut corpus: [Vec; 3] = [Vec::new(), Vec::new(), Vec::new()]; + for (_, set) in &fixtures { + for diagnostic in set { + corpus[0].push(text_run(diagnostic)); + } + corpus[1].push(sort_run(set)); + for cap in CAPS { + corpus[2].push(report_run(set, cap, "check")); + } + all.extend(set.iter().cloned()); + } + corpus[1].push(sort_run(&all)); + corpus[2].push(report_run(&all, 256, "check")); + let codes: Vec = { + let mut seen: BTreeSet = all + .iter() + .map(|item| item.code.as_str().to_owned()) + .collect(); + for extra in [ + "LLC0102", "LLS8002", "LLI9001", "LLV7001", "LLB6004", "LLF5001", "LLR3004", + ] { + seen.insert(extra.to_owned()); + } + seen.into_iter().collect() + }; + let normative = support::normative_host(); + let (evaluator_seeded, rustc_seeded) = if normative { + ( + seeded_runs(EVALUATOR_SEEDED, &codes, 0x0B55_0029), + seeded_runs(RUSTC_SEEDED, &codes, 0x0B55_1029), + ) + } else { + ( + [Vec::new(), Vec::new(), Vec::new()], + [Vec::new(), Vec::new(), Vec::new()], + ) + }; + eprintln!( + "BS-29: {} vectors ({} written, {} sorted, {} reported), {} committed diagnostics in {} fixtures, {} codes, {} and {} seeded sets ({:?})", + vectors.len(), + runs[0].len(), + runs[1].len(), + runs[2].len(), + all.len(), + fixtures.len(), + codes.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(); + if normative { + for (index, (root, _)) in ROOTS.iter().enumerate() { + let mut all_runs: Vec = runs[index].clone(); + all_runs.extend(corpus[index].iter().cloned()); + all_runs.extend(evaluator_seeded[index].iter().cloned()); + let disagreements = super::evaluate(&lowered[root], &all_runs, 5); + assert!( + disagreements.is_empty(), + "{root} and the Rust oracle disagree: {disagreements:?}" + ); + eprintln!( + "BS-29: {root}: the evaluator agrees on {} runs ({:?})", + all_runs.len(), + started.elapsed() + ); + } + plants(&vectors); + } else { + eprintln!("BS-29: platform-bound host: the evaluator, the seeded runs, and the planted defects run on the normative host"); + } + + let mut compiled: [Vec; 3] = [Vec::new(), Vec::new(), Vec::new()]; + for index in 0..3 { + compiled[index].extend(runs[index].iter().cloned()); + compiled[index].extend(corpus[index].iter().cloned()); + compiled[index].extend(rustc_seeded[index].iter().cloned()); + } + let total = rustc_differential( + "BS-29", + &[ + (ROOTS[0].0, &lowered[ROOTS[0].0], compiled[0].as_slice()), + (ROOTS[1].0, &lowered[ROOTS[1].0], compiled[1].as_slice()), + (ROOTS[2].0, &lowered[ROOTS[2].0], compiled[2].as_slice()), + ], + "oracle", + ); + eprintln!("BS-29: {total} rustc runs agree ({:?})", started.elapsed()); + + if !support::lean_backed("BS-29") { + return; + } + export(&lowered); + eprintln!("BS-29: 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..c82d99b5eb 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_29() { + repo_conformance::cases::run("BS-29"); +} + #[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..ea2c5b7356 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-29 @build + Scenario: The canonical diagnostic of SPEC.md §20.1 and the failure it makes under §24.5 (`Diagnostic::to_json`, written as `to_canonical_string` writes it: the code, the message, the primary span, the labels, the notes, the help and the causes, with the constant severity and spec, in canonical JSON; `diagnostic::sort_canonical`: diagnostics in the order of their path, byte start, code, and message, stable; and `LexLeanError::from_diagnostics` with `bounded`: the failure class of a set of diagnostics as its exit code, the most severe of their codes' classes, and the diagnostics the failure reports under `limits.max_diagnostics`, the first of them in canonical order and the `LLS8002` diagnostic that names the cap) is language-1.2 source in the `bootstrap/` project, as three production roots of `Diagnostics`: `diagnosticText`, `sortDiagnostics`, and `reportDiagnostics`, each eligible for `rust-std` with exactly its declared effects, none of them `recursion`, and each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator, agree with the oracle to the byte on the hand-built diagnostics, which reach every class of failure and both sides of the cap, on every committed expected diagnostic of the negative fixtures, written, sorted, and reported under four caps, and on seeded sets of diagnostics; 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 rendering of a diagnostic for a terminal and the producer-set details of §24.5 are outside the claim. + Given the committed `bootstrap` project, hand-built diagnostics that reach every class of failure and both sides of the cap, every committed expected diagnostic of the negative fixtures, and seeded sets of diagnostics + When the project is checked and built, and the lowered program and the rendered package of each root are run on those diagnostics + Then each root is eligible for rust-std with exactly its declared effects, no certificate part is beyond 3,145,728 bytes, and the three roots equal `to_json`, `sort_canonical`, and `bounded` on every run + And every planted defect is detected by its own vector, and the exported packages are byte-identical to the committed packages and realize the programs the differential ran diff --git a/model/ids.toml b/model/ids.toml index 69eb399d8a..a8a138c480 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-29" +level = "build" +suite = "bootstrap" +statement = "The canonical diagnostic of SPEC.md §20.1 and the failure it makes under §24.5 (`Diagnostic::to_json`, written as `to_canonical_string` writes it: the code, the message, the primary span, the labels, the notes, the help and the causes, with the constant severity and spec, in canonical JSON; `diagnostic::sort_canonical`: diagnostics in the order of their path, byte start, code, and message, stable; and `LexLeanError::from_diagnostics` with `bounded`: the failure class of a set of diagnostics as its exit code, the most severe of their codes' classes, and the diagnostics the failure reports under `limits.max_diagnostics`, the first of them in canonical order and the `LLS8002` diagnostic that names the cap) is language-1.2 source in the `bootstrap/` project, as three production roots of `Diagnostics`: `diagnosticText`, `sortDiagnostics`, and `reportDiagnostics`, each eligible for `rust-std` with exactly its declared effects, none of them `recursion`, and each with no part of its certificate beyond 3,145,728 bytes; their rendered `rust-std` packages under the pinned rustc, and on the normative host their lowered programs under the calculus evaluator, agree with the oracle to the byte on the hand-built diagnostics, which reach every class of failure and both sides of the cap, on every committed expected diagnostic of the negative fixtures, written, sorted, and reported under four caps, and on seeded sets of diagnostics; 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 rendering of a diagnostic for a terminal and the producer-set details of §24.5 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..3211e9c799 100644 --- a/tests/production-export/bootstrap/roots.json +++ b/tests/production-export/bootstrap/roots.json @@ -64,6 +64,14 @@ ], "version": "1.0.0" }, + { + "name": "diagnostic_text", + "root": "LexLeanBoot.Diagnostics.diagnosticText", + "targets": [ + "rust-std" + ], + "version": "1.0.0" + }, { "name": "fallible_functions", "root": "LexLeanBoot.RustLower.fallibleFunctions", @@ -192,6 +200,14 @@ ], "version": "1.0.0" }, + { + "name": "report_diagnostics", + "root": "LexLeanBoot.Diagnostics.reportDiagnostics", + "targets": [ + "rust-std" + ], + "version": "1.0.0" + }, { "name": "scan_source", "root": "LexLeanBoot.PrimitiveScan.scanSource", @@ -208,6 +224,14 @@ ], "version": "1.0.0" }, + { + "name": "sort_diagnostics", + "root": "LexLeanBoot.Diagnostics.sortDiagnostics", + "targets": [ + "rust-std" + ], + "version": "1.0.0" + }, { "name": "succeed_bodies", "root": "LexLeanBoot.RustSucceed.succeedBodies", 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.