diff --git a/.github/bdd-parts.json b/.github/bdd-parts.json index f385106a69..15c2d9cf60 100644 --- a/.github/bdd-parts.json +++ b/.github/bdd-parts.json @@ -153,6 +153,7 @@ "MD-10", "MD-11", "MD-12", + "MD-13", "PX-01", "PX-02", "PX-03", @@ -277,6 +278,31 @@ ], "bootstrap-manifest-text": [ "BS-34" + ], + "stdlib": [ + "EX-09", + "SL-01", + "SL-02", + "SL-03", + "SL-04", + "SL-05", + "SL-09", + "SL-10", + "SL-11", + "SL-13", + "SL-14" + ], + "language-models": [ + "LM-01", + "LM-02", + "LM-03", + "LM-04", + "LM-05", + "LM-06", + "LM-07", + "LM-08", + "LM-09", + "LM-13" ] }, "targets": { diff --git a/.github/intel-host-lanes.json b/.github/intel-host-lanes.json index 6a7f0aa94a..792dc5ddaf 100644 --- a/.github/intel-host-lanes.json +++ b/.github/intel-host-lanes.json @@ -4,6 +4,6 @@ "lower": ["bootstrap-lower", "bootstrap-lexicon-lse", "bootstrap-lexicon-lre", "bootstrap-surface-module", "bootstrap-diagnostics", "bootstrap-cli-output"], "print": ["bootstrap-print", "bootstrap-bodies", "bootstrap-succeed", "bootstrap-loops", "bootstrap-assemble", "bootstrap-package", "bootstrap-check", "bootstrap-gnaf", "bootstrap-runtime", "bootstrap-terms", "bootstrap-tooling-latex", "bootstrap-structural-grammar", "bootstrap-surface-lex", "bootstrap-surface-doc", "bootstrap-surface-generic", "bootstrap-surface-tooling", "bootstrap-lock-text", "bootstrap-content-id", "bootstrap-project-text", "bootstrap-manifest-text"], "validate": ["bootstrap-validate", "compiler", "preservation", "preservation-lists", "preservation-runtime", "preservation-support", "preservation-prims", "preservation-std", "production"], - "moves": ["bootstrap-moves", "verification", "rest"] + "moves": ["bootstrap-moves", "verification", "rest", "stdlib", "language-models"] } } diff --git a/.github/vv-rows.json b/.github/vv-rows.json index 7223ecaf22..4af9b69890 100644 --- a/.github/vv-rows.json +++ b/.github/vv-rows.json @@ -11,7 +11,7 @@ { "part": "examples", "recipes": "examples", - "examples_part": "without:uor-atlas", + "examples_part": "without:uor-atlas,bootstrap", "bdd_part": "", "width": "2", "memory_kib": "12582912", @@ -358,5 +358,23 @@ "width": "", "memory_kib": "", "hints": "" + }, + { + "part": "bdd-stdlib", + "recipes": "bdd", + "examples_part": "", + "bdd_part": "stdlib", + "width": "", + "memory_kib": "", + "hints": "" + }, + { + "part": "bdd-language-models", + "recipes": "bdd", + "examples_part": "", + "bdd_part": "language-models", + "width": "", + "memory_kib": "", + "hints": "" } ] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c0eea6a00b..9dc1f15191 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,8 @@ # the exact pinned toolchains and no build cache: §9.4 says "from a clean # checkout", and a restored target directory is not one. CI runs its twelve # recipes as the legs of `.github/vv-rows.json` at once, each its own clean -# checkout: `examples`, which here verifies every example but UOR Atlas, and +# checkout: `examples`, which here verifies every example but UOR Atlas and +# the bootstrap project (the `bootstrap export` job verifies it), and # `honesty`, format/model/spec-links and the BDD meta target first, then # `rest`, the remaining recipes in order, with the `bdd` rows below. # Together they run every recipe of `vv` exactly once, so the gate is the same @@ -199,7 +200,12 @@ jobs: # its cases first needs it, and the harness checks the record against the # leg's own run and checkout and replays the bundle before the case reads # it. The legs start when honesty passes, as before, and wait only at that - # point; the artifact is read by this run alone. + # point; the artifact is read by this run alone. The export verifies the + # bootstrap project through the same `verify` the `examples` recipe runs, + # so this job is also that project's part of the recipe: it formats, locks, + # checks, and builds a clean copy first, and holds the export's verified + # directory to the recipe's checks after, and the `examples` leg does not + # verify the project again. bootstrap-export: name: bootstrap export needs: [plan, honesty] @@ -250,6 +256,15 @@ jobs: sample_pid=$! trap 'kill "$sample_pid" 2>/dev/null || true; wait "$sample_pid" 2>/dev/null || true' EXIT cargo xtask export-bootstrap --output "$RUNNER_TEMP/bootstrap-export" 2>&1 | tee ci-evidence/vv.txt + # The bootstrap project's part of the `examples` recipe (§9.4), made + # visible as the Atlas join makes Atlas's: the leg names it in its part + # and does not verify it. + - name: Assert the export verified the bootstrap example + shell: bash + run: | + set -euo pipefail + grep -F "verify-examples: bootstrap verified (attestation " ci-evidence/vv.txt + grep -E "^verify-examples: bootstrap: [0-9]+ normalized verification records equal expected/verify " ci-evidence/vv.txt - name: Summarize the run's timing and memory if: ${{ !cancelled() }} run: cargo xtask ci-summary --evidence ci-evidence @@ -390,8 +405,10 @@ jobs: # These assertions make its complete proof run visible as first-class CI # evidence without running the expensive verifier a second time. # The leg that runs `examples` is chosen by the matrix, not by the log, - # so a leg that should have verified Atlas and did not fails here. - - name: Assert the leg verified every example but Atlas + # so a leg that should have verified the examples and did not fails + # here, as does one that verified Atlas or the bootstrap project, which + # their own jobs verify. + - name: Assert the leg verified every example but Atlas and bootstrap shell: bash run: | set -euo pipefail @@ -402,6 +419,10 @@ jobs: echo "::error::the examples leg verified Atlas, which the Atlas jobs verify as parts (SPEC.md §9.4)" exit 1 fi + if grep -F "verify-examples: bootstrap" ci-evidence/vv.txt; then + echo "::error::the examples leg verified the bootstrap project, which the bootstrap export verifies (SPEC.md §9.4)" + exit 1 + fi ;; esac - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 @@ -1251,7 +1272,7 @@ jobs: intel-join: name: build and non-Lean tests (x86_64-apple-darwin) needs: [plan, intel-construction, intel-part] - if: ${{ always() && needs.plan.outputs.intel == 'true' }} + if: ${{ !cancelled() && needs.plan.outputs.intel == 'true' }} runs-on: ubuntu-24.04 timeout-minutes: 15 steps: @@ -1333,7 +1354,7 @@ jobs: windows-join: name: build and non-Lean tests (x86_64-pc-windows-msvc) needs: [plan, windows-part] - if: ${{ always() && needs.plan.outputs.full == 'true' }} + if: ${{ !cancelled() && needs.plan.outputs.full == 'true' }} runs-on: ubuntu-24.04 timeout-minutes: 15 steps: diff --git a/CHANGELOG.md b/CHANGELOG.md index 0357ca8fc0..13f4d27fb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -92,6 +92,19 @@ workspace carried at those versions without a tag. person merges a cut. `tag.yml` still tags a person's merge of a cut, and accepts the run that verified a merged head's tree without waiting for the merge's own. +- The whole gate verifies the bootstrap project once (SPEC.md §9.4). The + `bootstrap export` job, whose export already verified it whole through the + `examples` recipe's own `verify`, is now that project's part of the recipe: + `export-bootstrap` formats, locks, checks and builds a clean copy first and + then holds the export's verified directory to the recipe's checks (no + telemetry, records equal to `bootstrap/expected/verify`). The `examples` leg + runs `without:uor-atlas,bootstrap` and no longer spends about 53 minutes + verifying the project a second time; `LEXLEAN_EXAMPLES_PART=without:` takes + a comma-separated list. `RP-14` pins the job's assertion and the leg's. +- The Intel and Windows aggregates no longer run in a run that was cancelled + (a newer push to the pull request), so a superseded head no longer reports + a failed host context; they still run after a failed or cancelled lane of a + run that goes on (SPEC.md §8.3, `RP-14`). - Decision regions (SPEC.md §17.12, `PF-24`, UOR-Foundation/PrismPM#605; no new diagnostic code; changes the language-1.2 identity). The runtime gains a sixth native module, `LexLeanRuntime.Regions`: a checker of local box diff --git a/SPEC.md b/SPEC.md index ed98afddce..b083eb5f88 100644 --- a/SPEC.md +++ b/SPEC.md @@ -565,7 +565,7 @@ On macOS x86-64, one construction job and one conformance execution job per comm All conformance execution jobs MUST run the same constructed `repo-conformance` conformance executable, without rebuilding it. `.github/intel-host-lanes.json` defines a nonempty set of lanes, grouping complete existing parts of `.github/bdd-parts.json`; no fixture-sharing part is split. The conformance executable's actual harness inventory and its filtered inventories MUST prove that each test belongs to exactly one lane and that their union is the complete executable's inventory. Unknown, empty, duplicate or overlapping assignments MUST fail. The remainder owns future conformance tests until assigned, rather than a copied fixed test-name list omitting them. The constructed artifact MUST bind the repository, source commit and tree, workflow run and attempt, checkout path, actual Rust version and pin, native target, profile, features, lockfile, both plans, executable bytes and mode, and exact inventories and filters. Only the executable, its actual runtime dynamic-library closure, and dependency data required by its tests may be transferred; no target build cache, proof result or artifact from another run or attempt is accepted. Consumers MUST verify this custody and inventory before executing their filters, record the subprocess outcome and complete harness results, and bind their receipts and logs to the construction identity. -The aggregate MUST require the construction result and exactly one successful receipt for each committed lane, reject missing, duplicate, foreign, changed, failed or incomplete evidence, and run even when a prerequisite failed or was cancelled so absence cannot become success. Its check context MUST remain exactly `build and non-Lean tests (x86_64-apple-darwin)`. The other auxiliary contexts remain exactly `build and non-Lean tests (aarch64-unknown-linux-gnu)`, `build and non-Lean tests (aarch64-apple-darwin)` and `build and non-Lean tests (x86_64-pc-windows-msvc)`. Previous-run and release evidence MUST require each of these four exact contexts once and passed, a skipped Intel context being absent evidence, not infer complete coverage from the number of matrix rows or accept a partition context in place of a host. The partition changes scheduling and custody only: it reduces no test, changes no assertion or corpus, and raises no host timeout. +The aggregate MUST require the construction result and exactly one successful receipt for each committed lane, reject missing, duplicate, foreign, changed, failed or incomplete evidence, and run even when a prerequisite failed or a lane was cancelled so absence cannot become success; only the cancellation of the whole run, which a newer push to the same pull request makes and which leaves no evidence, skips it. Its check context MUST remain exactly `build and non-Lean tests (x86_64-apple-darwin)`. The other auxiliary contexts remain exactly `build and non-Lean tests (aarch64-unknown-linux-gnu)`, `build and non-Lean tests (aarch64-apple-darwin)` and `build and non-Lean tests (x86_64-pc-windows-msvc)`. Previous-run and release evidence MUST require each of these four exact contexts once and passed, a skipped Intel context being absent evidence, not infer complete coverage from the number of matrix rows or accept a partition context in place of a host. The partition changes scheduling and custody only: it reduces no test, changes no assertion or corpus, and raises no host timeout. On Windows x86-64 that same complete workspace test workload runs as lanes of one run (`.github/scripts/host_lanes.py`): the conformance lanes of `.github/intel-host-lanes.json`, each running the conformance harness with that lane's filters, and a `producer` lane running every other test target of the workspace, the `repo-conformance` library, `bdd` meta target and other integration targets among them, and every doctest. Each lane is a job of its own clean checkout that builds with the pinned toolchain, locked dependencies, all features and the default test profile, checks its host triple, and records the commit, tree, run and attempt, the harness's listing, the producer's listing of the whole workspace, and every test it executed. The aggregate, whose check context remains exactly `build and non-Lean tests (x86_64-pc-windows-msvc)`, runs even when a lane failed or was cancelled, and passes only with exactly one passing receipt for each lane of the run and commit, lanes that listed the same harness, and executed tests whose union is the whole listing with each test once. It reduces no test, changes no assertion, and raises no host timeout. @@ -699,7 +699,7 @@ Its image MUST install the pinned Rust and Lean toolchains at build, so that not **The release's evidence.** `release.yml` runs no recipe of the gate. The CI evidence a release attaches (§30.3) is a run of `ci.yml` that was the whole gate and passed every job, on the tagged commit or, while the commit is a merge whose tree is the tree of its second parent, on that parent, at most four merges down (the walk the plan makes); `.github/release-gate.sh` finds it under the rule `plan` applies to a push, and refuses, naming the commits it looked at, when no such run exists. The evidence names the run, every job of it with its conclusion, and the transcript of every leg the run still retains. The gate run whole on one hosted runner exceeds the six-hour job limit (the `bdd` recipe alone takes over four hours there, and Atlas follows it), so a release gate that re-ran it would never conclude, and the run of the line has already verified the tree. -In a run that is the whole gate, the jobs run the recipes as the rows of `.github/vv-rows.json`, each from its own clean checkout: `examples`, which verifies every example but UOR Atlas; `honesty`, which runs `fmt-check model spec-links bdd` before any expensive root; `rest`, the other recipes in the order of `vv`; and one `bdd-` row for each named part of the `bdd` plan below, which runs `bdd` alone. Each leg runs `just` with its recipes, which stops at the first that fails, as `vv` does. The part of `examples` a job runs is named by its matrix row through `LEXLEAN_EXAMPLES_PART` and by nothing else: `without:uor-atlas` on the leg, `shard:uor-atlas:` and `join:uor-atlas` on the Atlas jobs below; unset or empty, which is what `just vv` runs, the recipe verifies every example whole. After honesty succeeds, the remaining rows run as one matrix and the supported-host matrix, Intel construction, the bootstrap export and Atlas prefix may start; a failed or skipped honesty part starts none of these expensive roots. Together the legs and the Atlas jobs run every recipe of `vv`, every example, and every test of `bdd` exactly once, and the run passes only when every job passes, so it proves what one run of `just vv` proves; no recipe depends on another having run, and every recipe owns the files it builds. Its wall time is the longest path through the jobs rather than the sum. `just vv` remains the acceptance recipe of §9.2 for every other run, and release acceptance requires the complete same-tree run. +In a run that is the whole gate, the jobs run the recipes as the rows of `.github/vv-rows.json`, each from its own clean checkout: `examples`, which verifies every example but UOR Atlas and the bootstrap project; `honesty`, which runs `fmt-check model spec-links bdd` before any expensive root; `rest`, the other recipes in the order of `vv`; and one `bdd-` row for each named part of the `bdd` plan below, which runs `bdd` alone. Each leg runs `just` with its recipes, which stops at the first that fails, as `vv` does. The part of `examples` a job runs is named by its matrix row through `LEXLEAN_EXAMPLES_PART` and by nothing else: `without:uor-atlas,bootstrap` on the leg, `shard:uor-atlas:` and `join:uor-atlas` on the Atlas jobs below; unset or empty, which is what `just vv` runs, the recipe verifies every example whole. After honesty succeeds, the remaining rows run as one matrix and the supported-host matrix, Intel construction, the bootstrap export and Atlas prefix may start; a failed or skipped honesty part starts none of these expensive roots. Together the legs, the bootstrap export and the Atlas jobs run every recipe of `vv`, every example, and every test of `bdd` exactly once, and the run passes only when every job passes, so it proves what one run of `just vv` proves; no recipe depends on another having run, and every recipe owns the files it builds. Its wall time is the longest path through the jobs rather than the sum. `just vv` remains the acceptance recipe of §9.2 for every other run, and release acceptance requires the complete same-tree run. UOR Atlas is verified as the parts of one run. `.github/verify-shards.json` partitions its verification into shards, each naming the shards it needs, the modules it elaborates, and the modules it replays and audits, one of them named `join`; `cargo xtask ci-shards` checks, as the verifier would when a part ran, that every module is elaborated by exactly one shard and replayed by exactly one, that every import of a module a shard elaborates or replays is elaborated by that shard or by one it needs, directly or through another, and that `join` needs every other shard. Each shard is a job of its own clean checkout that runs the verifier's prelude whole (certificate generation, the preflights, staging, the generated-source audit, the probe), then elaborates, replays, and audits only the modules of its plan, reading the `.olean` files of the modules it imports from the output the jobs of the shards it needs uploaded in the same run, and uploads its own `.olean` files and process records as its output. The join runs the modules of its plan, reads every shard's records, requires each to name the executable the join itself hashed for the tool that produced it (`lean` for an elaboration or an audit member, `leanchecker` for a replay), requires every shard's output to name the join's own toolchain addresses (§22.11), judges each as the stage that produced it judges its own, and continues through policy, the attestation over every record in the canonical order of §22.11, publication, and the comparison of every normalized record with `expected/verify` (§29.5): what it publishes is what the whole verification publishes, record for record and attestation identity included (`VR-23`). A module without a record from any part, a record of a process no module owns, a record whose `executable_sha256` is not the join's digest of its tool (`LLI9001`, naming the record and both digests), a shard whose output names no toolchain addresses or another address of any tool (`LLI9001`, naming the part, the tool, and both addresses), or a shard whose plan leaves a module without the `.olean` it imports fails the run. Every process of the verification runs exactly once per run. The executable the Atlas jobs run is the one the `prefix` job built from its clean checkout, carried to the other jobs of the run as an artifact beside the shards' output; it, the output, and the records cross no run, and a job reads the artifacts of its own run only. The Atlas jobs run after the jobs of the shards they need, at the profile of the `examples` leg, and only in a run that is the whole gate. @@ -707,7 +707,7 @@ The `bdd` recipe runs as the parts of one run as well. `.github/bdd-parts.json` Every normative gate job runs on the standard GitHub-hosted runner, `ubuntu-24.04`; no larger runner is part of the gate. The supported-host execution jobs run on their named hosts (§8.3); the Intel and Windows aggregates run on `ubuntu-24.04` and execute no host test. The verification resource profile (§22.11) of a job is named by its matrix row, or on an Atlas job by the job itself, and by nothing else, no repository or workflow variable and no input: the `examples` leg and every Atlas job verify at width 2, with the scheduling hints committed in `.github/verify-hints.json` (derived from a run's telemetry by `cargo xtask ci-hints`) and a memory budget of 12 GiB (12582912 KiB) for the summed expected peaks of the proof processes running at once; the other legs name no profile and run at the default. A profile is a schedule and never a verdict: every elaboration, replay, and audit member still runs on the pinned toolchain, the directory each project publishes is byte for byte the one of width 1 without hints or a budget (§22.11), and the leg and the join still require every example's normalized verification records to equal `expected/verify` (§29.5), so a profile that changed a byte would fail the gate rather than pass a different one. A stale hint reorders processes and never skips one. Local `just vv` verifies UOR Atlas whole at width 1 with no profile. The budget is below the runner's 16 GB, with the 4 GiB swap file of the job as overflow, so two processes run together only when their expected peaks fit, and a process whose expected peak alone passes the budget runs alone. The gate has no path filter, no cache of a build directory, object, verification tree, attestation, or proof result, and no condition that skips a recipe of `just vv` but the plan's, which decides only what a run is, as above; the artifacts the jobs of one run exchange are read by that run alone, and every job starts from a clean checkout with the exact pinned toolchains. Each proof or fan-out job writes its performance telemetry (§22.12) to `ci-evidence/` and uploads that directory as the artifact named after it, `acceptance-gate-evidence-` or `acceptance-gate-evidence-atlas-`: the gate log (`just --timestamp` stamps each recipe's first command on a leg, which is how a recipe is timed without changing it; an Atlas job's log is the recipe's own output), the host's memory and swap sampled every five seconds, the verifier's telemetry, and a summary of the wall time of each recipe and verification stage, the slowest modules and audit members, and the peak resident set and swap of the proof processes. The summary step also prints that summary to the job log and appends it to the step summary, and runs when the job failed, because an uploaded artifact cannot be read from the log; each table lists only its slowest rows and the part appended to the step summary is cut at 512 KiB, half of what GitHub accepts. The initial honesty job retains its recipe timing and summary in the same evidence format, without Lean processes or proof-resource samples. None of it is an input of any recipe, and a timing is never a claim about a semantic property. -The bootstrap production export (§24.7) is made once per run. Every bootstrap case compares the packages of the bootstrap project's export with the committed packages, and a test process that needs the export exports the project, which verifies it whole; each part that ran a bootstrap case ran that verification. In a run that is the whole gate, the job `bootstrap-export` runs `cargo xtask export-bootstrap` from its clean checkout after honesty, at the profile of the `examples` leg, requires every exported package to equal the committed package, and uploads the bundle as the artifact `bootstrap-export` with a custody record (`lexlean/ci-bootstrap-export/2`) that names the repository, the run and its attempt, the commit and its tree, the SHA-256 of `rust-toolchain.toml`, `lean-toolchain` and `Cargo.lock`, what `rustc -vV` and `lean --version` report, the SHA-256 of the pinned toolchain's `lake`, `lean` and `leanchecker` executables and the address of the `rustc` that compiled the job's own binary (§22.11), the bundle's project-relative path, and the digest of its files. The legs do not wait for that job to start: each leg of such a run starts `.github/scripts/take-bootstrap-export.sh`, which asks nothing until a case of the leg needs the export, then downloads that artifact of its own run, or records that the export job ended without it, and the case fails with that reason. The harness names the directory it waits in through `LEXLEAN_BOOTSTRAP_EXPORT`; before any case reads the bundle it requires the record to name the leg's own repository, run, commit, tree, pins, toolchains and executable addresses, an attempt at most the leg's (a rerun of failed jobs keeps the export that passed, on the same commit), the digest of the files it received, and a path below the project, and it replays the bundle (§24.7). A record that differs in any of these fails the case. Unset or empty, as in `just vv` and in a run that is not the whole gate, each process that needs the export runs it itself. The export crosses no run, as the Atlas parts do not; `RP-14` checks the job, the legs' fetcher, and the record against planted changes. +The bootstrap production export (§24.7) is made once per run. Every bootstrap case compares the packages of the bootstrap project's export with the committed packages, and a test process that needs the export exports the project, which verifies it whole; each part that ran a bootstrap case ran that verification. In a run that is the whole gate, the job `bootstrap-export` runs `cargo xtask export-bootstrap` from its clean checkout after honesty, at the profile of the `examples` leg, requires every exported package to equal the committed package, and uploads the bundle as the artifact `bootstrap-export` with a custody record (`lexlean/ci-bootstrap-export/2`) that names the repository, the run and its attempt, the commit and its tree, the SHA-256 of `rust-toolchain.toml`, `lean-toolchain` and `Cargo.lock`, what `rustc -vV` and `lean --version` report, the SHA-256 of the pinned toolchain's `lake`, `lean` and `leanchecker` executables and the address of the `rustc` that compiled the job's own binary (§22.11), the bundle's project-relative path, and the digest of its files. The legs do not wait for that job to start: each leg of such a run starts `.github/scripts/take-bootstrap-export.sh`, which asks nothing until a case of the leg needs the export, then downloads that artifact of its own run, or records that the export job ended without it, and the case fails with that reason. The harness names the directory it waits in through `LEXLEAN_BOOTSTRAP_EXPORT`; before any case reads the bundle it requires the record to name the leg's own repository, run, commit, tree, pins, toolchains and executable addresses, an attempt at most the leg's (a rerun of failed jobs keeps the export that passed, on the same commit), the digest of the files it received, and a path below the project, and it replays the bundle (§24.7). A record that differs in any of these fails the case. Unset or empty, as in `just vv` and in a run that is not the whole gate, each process that needs the export runs it itself. The export crosses no run, as the Atlas parts do not; `RP-14` checks the job, the legs' fetcher, and the record against planted changes. The export verifies the bootstrap project whole through the same `verify`, over the same selection and at the same profile, that the `examples` recipe runs, so the job is also the bootstrap project's part of that recipe and the `examples` leg does not verify it a second time: before exporting, `export-bootstrap` formats, locks, checks and builds a clean copy of the project as the recipe does (`fmt --check`, `lock --check`, `check`, `build`), and after it requires the export's verified directory to hold no performance telemetry (§22.12) and its normalized verification records to equal `bootstrap/expected/verify` (§29.5), printing the recipe's lines, which the job asserts. The Intel host factory is separate from the normative BDD and Atlas partitions above: it transfers only the same-run host test construction and dependency data of §8.3. Construction requires successful honesty and the plan's `intel`; consumers require construction; the aggregate requires all of them and cannot skip an incomplete result. A run whose plan does not set `intel` skips all three, and its Intel context is skipped, never passed, so that run is not evidence of the Intel host for the plan or the release. The factory's behavioral tests run in the initial honesty job, before the expensive roots, and exercise inventory completeness, custody and fail-closed result joins without needing an Intel runner. These tests do not substitute for execution of the complete workload on Intel macOS. diff --git a/VERIFICATION.md b/VERIFICATION.md index 597977606f..06c76734c1 100644 --- a/VERIFICATION.md +++ b/VERIFICATION.md @@ -14586,3 +14586,44 @@ test result: FAILED. 0 passed; 2 failed `RP-19` failed at the first language-1.2 lock, whose `compiler_semantics` line carried the planted digit while the default build's carried the tree's. With each plant removed, `conformance_rp_10` and `conformance_rp_19` pass. + +## The `bdd` legs' evaluator and the remainder's parts (2026-11-13) + +On green run 43433085919 the gate took 205 minutes and 1,738 runner-minutes; +the `bdd` legs were 688 of them. Two causes are addressed here, neither of +which changes what a case asserts. + +**The reference interpreter copied every value it touched.** +`calculus::interp` cloned the whole environment, deep, at every `let` and +call, deep-copied a value at every variable read and field, and copied a +list's tail at every `Cons` match. Its values now share their parts +(`Rc`), the environment is a list whose extension shares the scope it +extends, and a list's tail shares its items. Lookup still walks the +bindings innermost first and charges the same depth, and every step and +weight is charged as before, so every outcome is the one the step-for-step +transcription of `TargetSemantics.eval` gave. Measured locally on a loaded +4-CPU host in the debug profile the gate builds, `BS-15`'s evaluator phase +(2,531 header and 241 render runs) took 239 s against about 800 s before; the +evaluator, not rustc, was most of `BS-15`'s 3,880 s on that run, and every +bootstrap, stdlib, preservation and calculus differential runs on it. + +**The remainder held a fixture's waiters and a duplicate fixture.** On that +run the `rest` leg's `bdd` took 59.7 of its 76.7 minutes. Four `SL` cases +spent about 15 minutes each blocked on one `OnceLock` (the `stdlib` export), +holding three of the four test threads, and `MD-13` verified `models` again +although `verified_models` is the fixture of the `MD` cases in `production` +(it reached the remainder by default when it was registered). Two parts are +added and `MD-13` joins its fixture's part: + +| Part | Cases | Case seconds on that run | +| --- | --- | ---: | +| `stdlib` | `SL-*` (the `stdlib` export) and `EX-09` (the `helpdesk` export), whose exports run side by side | 4,595 | +| `language-models` | `LM-*`, each verifying its own copy of `models` | 3,043 | +| `production` | gains `MD-13`, which now reads the fixture the part already builds | (765 in `rest`) | + +The remainder keeps about 5,800 case seconds, so its `bdd` falls from +about 60 to about 24 minutes and the leg from 77 to about 42; the new legs +are about 20 minutes each. Both new parts run in the Intel and Windows +`moves` lane, which held them as part of `rest`, so no host lane's work +changes. `check-test-inventory` reports the 545 tests of `bdd` as the 41 +parts, disjoint and complete (RP-13). diff --git a/crates/conformance/src/cases/authoring.rs b/crates/conformance/src/cases/authoring.rs index 1395f6e7dd..a56dee79c1 100644 --- a/crates/conformance/src/cases/authoring.rs +++ b/crates/conformance/src/cases/authoring.rs @@ -44,6 +44,9 @@ pub fn run(id: &str) { }); } +/// The most reader threads AU-08 runs at once (about 1 GiB each at peak). +const READERS: usize = 4; + fn check(id: &str) { match id { "AU-01" => round_trip(), @@ -1288,7 +1291,11 @@ fn authoring_api() { }; let root = repo_root(); - let (mut semantic, mut tooling, mut core) = (0usize, 0usize, 0usize); + // Every committed source, then the API on each. A source is independent + // of every other, so they are taken on as many threads as the host has: + // one after another, the round trips of the corpus were the longest case + // of a supported-host lane (55 minutes on Intel). + let mut paths = Vec::new(); for entry in walkdir::WalkDir::new(root.as_std_path()) .into_iter() .filter_entry(|entry| { @@ -1300,23 +1307,30 @@ fn authoring_api() { }) .flatten() { - let path = entry.path(); - if !path.to_string_lossy().ends_with(".lex.tex") { - continue; + if entry.path().to_string_lossy().ends_with(".lex.tex") { + paths.push(entry.into_path()); } + } + let counts = [ + std::sync::atomic::AtomicUsize::new(0), + std::sync::atomic::AtomicUsize::new(0), + std::sync::atomic::AtomicUsize::new(0), + ]; + let source = |path: &std::path::PathBuf| -> Option { + let path = path.as_path(); let Ok(text) = std::fs::read_to_string(path) else { - continue; + return None; }; // Reading a module of tens of megabytes as a value takes minutes in a // debug build. The functions are the same code that runs on every // other module, and AU-09 reads these through the typed notation. if text.len() > LARGEST_READ_AS_VALUE { - continue; + return None; } let Some(kind) = module_kind(&text) else { // Not a module of these kinds: the API says so, and reads nothing. assert!(read_module(&text).is_err(), "{}", path.display()); - continue; + return None; }; // A refused fixture may not be a module; the rest are. let Ok(data) = read_module(&text) else { @@ -1327,7 +1341,7 @@ fn authoring_api() { "{}: a committed module the API cannot read", path.display() ); - continue; + return None; }; let shown = path.display(); // A module under a tag the notation does not name (language 1.1) has @@ -1342,7 +1356,7 @@ fn authoring_api() { data, "{shown}" ); - continue; + return None; } // The module is what the notation module reads to, in either form, and // the conversions are the identity on a canonical source. @@ -1392,11 +1406,6 @@ fn authoring_api() { "{shown}" ); assert_eq!(declaration_spans(&as_data).expect("spans"), None, "{shown}"); - match kind { - ModuleKind::Semantic => semantic += 1, - ModuleKind::Tooling => tooling += 1, - ModuleKind::Core => core += 1, - } // Assembled from its header and data, a source of the standard shape is // the canonical source: the header is what the source already says. let lines: Vec<&str> = notation.lines().collect(); @@ -1448,7 +1457,45 @@ fn authoring_api() { ); } } - } + Some(kind) + }; + // Each thread reads on the stack every authoring case reads on. + let next = std::sync::atomic::AtomicUsize::new(0); + let work = || { + while let Some(path) = paths.get(next.fetch_add(1, std::sync::atomic::Ordering::Relaxed)) { + if let Some(kind) = source(path) { + let at = match kind { + ModuleKind::Semantic => 0, + ModuleKind::Tooling => 1, + ModuleKind::Core => 2, + }; + counts[at].fetch_add(1, std::sync::atomic::Ordering::Relaxed); + } + } + }; + // At most `READERS` threads: each holds up to one module on its reader + // stack, about 1 GiB at peak, so the case stays near 4 GiB beside the + // other cases of its leg on a 16 GB runner. + let width = std::thread::available_parallelism() + .map_or(1, std::num::NonZeroUsize::get) + .min(READERS); + std::thread::scope(|scope| { + let threads: Vec<_> = (0..width) + .map(|_| { + std::thread::Builder::new() + .stack_size(lexlean::READER_STACK) + .spawn_scoped(scope, work) + .expect("a reader thread") + }) + .collect(); + for thread in threads { + thread + .join() + .unwrap_or_else(|panic| std::panic::resume_unwind(panic)); + } + }); + let [semantic, tooling, core] = + counts.map(|count| count.load(std::sync::atomic::Ordering::Relaxed)); assert!( semantic >= 250 && tooling >= 4 && core >= 20, "{semantic} semantic, {tooling} tooling and {core} core sources: the API was not exercised on the product" diff --git a/crates/conformance/src/cases/repository.rs b/crates/conformance/src/cases/repository.rs index 5c208be925..034322931f 100644 --- a/crates/conformance/src/cases/repository.rs +++ b/crates/conformance/src/cases/repository.rs @@ -2127,7 +2127,8 @@ pub(crate) fn run(id: &str) { assert!(legs.len() >= 2, "the gate runs in legs: {legs:?}"); // The leg that runs `examples` verifies at width 2 with the // committed hints and a 12 GiB budget, and every example but the - // one the Atlas jobs verify as parts; every other leg names no + // one the Atlas jobs verify as parts and the bootstrap project, + // which the bootstrap export verifies; every other leg names no // profile and no part (§9.4, §22.11). The values are the // verifier's to accept: a width it refuses, or hints it cannot // read, would fail the gate as `LLV7017` before any stage ran, so @@ -2143,7 +2144,7 @@ pub(crate) fn run(id: &str) { "2", "12582912", ".github/verify-hints.json", - "without:uor-atlas" + "without:uor-atlas,bootstrap" ] .map(str::to_owned), "§9.4: the examples leg's profile and part" @@ -2536,7 +2537,7 @@ pub(crate) fn run(id: &str) { ("lane: [producer, lower, print, validate, moves]", "lane: [producer, lower, print, validate]"), (" needs: [plan, windows-part]", " needs: [plan]"), ( - " if: ${{ always() && needs.plan.outputs.full == 'true' }}\n runs-on: ubuntu-24.04\n timeout-minutes: 15\n steps:\n - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1\n - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2\n with:\n pattern: host-x86_64", + " if: ${{ !cancelled() && needs.plan.outputs.full == 'true' }}\n runs-on: ubuntu-24.04\n timeout-minutes: 15\n steps:\n - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1\n - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2\n with:\n pattern: host-x86_64", " if: ${{ needs.plan.outputs.full == 'true' }}\n runs-on: ubuntu-24.04\n timeout-minutes: 15\n steps:\n - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1\n - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2\n with:\n pattern: host-x86_64", ), ("host_lanes.py join --target", "host_lanes.py execute --target"), @@ -2567,7 +2568,7 @@ pub(crate) fn run(id: &str) { "needs: [plan, intel-construction]", ), ( - "if: ${{ always() && needs.plan.outputs.intel == 'true' }}", + "if: ${{ !cancelled() && needs.plan.outputs.intel == 'true' }}", "if: ${{ needs.plan.outputs.intel == 'true' }}", ), ( @@ -2620,6 +2621,14 @@ pub(crate) fn run(id: &str) { " name: bootstrap-bundle\n", ), (" name: bootstrap export\n", " name: export\n"), + ( + "grep -F \"verify-examples: bootstrap verified (attestation \" ci-evidence/vv.txt\n", + "true\n", + ), + ( + "grep -E \"^verify-examples: bootstrap: [0-9]+ normalized verification records equal expected/verify \" ci-evidence/vv.txt\n", + "true\n", + ), ] { assert!( export_job.contains(from), @@ -2644,6 +2653,10 @@ pub(crate) fn run(id: &str) { " export LEXLEAN_BOOTSTRAP_EXPORT=\"$RUNNER_TEMP/bootstrap-export\"\n", " export LEXLEAN_BOOTSTRAP_EXPORT=\"$RUNNER_TEMP/elsewhere\"\n", ), + ( + " if grep -F \"verify-examples: bootstrap\" ci-evidence/vv.txt; then\n", + " if false; then\n", + ), ] { assert!(ci.contains(from), "the plant must change the workflow: {from}"); assert!( @@ -3970,7 +3983,7 @@ fn intel_host_workflow(ci: &str) -> Result<(), String> { "intel-join", &join, "needs: [plan, intel-construction, intel-part]", - "if: ${{ always() && needs.plan.outputs.intel == 'true' }}", + "if: ${{ !cancelled() && needs.plan.outputs.intel == 'true' }}", ), ] { require(body, dependencies, key)?; @@ -4090,7 +4103,9 @@ const TAKE_EXPORT: &str = ".github/scripts/take-bootstrap-export.sh"; /// one name the fetcher reads; a leg reads the artifacts of its own run only, /// takes the export only in a run that is the whole gate, and only into the /// directory its harness waits in; the fetcher names this run and the export -/// job, and asks nothing before a case wants the export. +/// job, and asks nothing before a case wants the export. The job asserts +/// that it verified the bootstrap example for the `examples` recipe, and the +/// `examples` leg fails when it verifies that project again. fn bootstrap_export_workflow(ci: &str, take: &str) -> Result<(), String> { let job = workflow_job(ci, "bootstrap-export")?; let legs = workflow_job(ci, "vv")?; @@ -4130,6 +4145,14 @@ fn bootstrap_export_workflow(ci: &str, take: &str) -> Result<(), String> { "name: acceptance-gate-evidence-bootstrap-export\n", "the job's evidence", ), + ( + "grep -F \"verify-examples: bootstrap verified (attestation \" ci-evidence/vv.txt\n", + "the export verified the bootstrap example", + ), + ( + "grep -E \"^verify-examples: bootstrap: [0-9]+ normalized verification records equal expected/verify \" ci-evidence/vv.txt\n", + "the export's records equal the bootstrap example's expected/verify", + ), ] { require(&job, text, rule)?; } @@ -4143,6 +4166,10 @@ fn bootstrap_export_workflow(ci: &str, take: &str) -> Result<(), String> { " if [ \"$FULL_GATE\" = true ]; then\n export LEXLEAN_BOOTSTRAP_EXPORT=\"$RUNNER_TEMP/bootstrap-export\"\n .github/scripts/take-bootstrap-export.sh \"$LEXLEAN_BOOTSTRAP_EXPORT\"", "the fetcher fills the directory the harness waits in", ), + ( + " if grep -F \"verify-examples: bootstrap\" ci-evidence/vv.txt; then\n", + "the examples leg does not verify the project the export verifies", + ), ] { require(&legs, text, rule)?; } @@ -4382,8 +4409,8 @@ fn windows_host_workflow(ci: &str) -> Result<(), String> { (&join, " needs: [plan, windows-part]\n", "the aggregate follows the lanes"), ( &join, - " if: ${{ always() && needs.plan.outputs.full == 'true' }}\n", - "the aggregate runs after a failed or cancelled lane", + " if: ${{ !cancelled() && needs.plan.outputs.full == 'true' }}\n", + "the aggregate runs after a failed or cancelled lane, not after the run is cancelled", ), ( &join, diff --git a/crates/conformance/src/export_custody.rs b/crates/conformance/src/export_custody.rs index a1bc4d5101..a729483f70 100644 --- a/crates/conformance/src/export_custody.rs +++ b/crates/conformance/src/export_custody.rs @@ -328,13 +328,14 @@ fn copy_files(from: &Utf8Path, to: &Utf8Path) -> Result<(), String> { /// Export the bootstrap project once for the run, require its packages to /// equal the committed packages, and write the bundle and its custody record -/// to `output`. Returns the record. +/// to `output`. Returns the record, and the export, whose verified directory +/// the `examples` recipe then holds to its records (§9.4). /// /// # Errors /// /// When the run or checkout cannot be named, the export fails, a package /// differs from the committed one, or `output` cannot be written. -pub fn publish(output: &Utf8Path) -> Result { +pub fn publish(output: &Utf8Path) -> Result<(Custody, Exported), String> { let root = support::repo_root(); let before = identity(&root)?; let exported = harness::export(BOOTSTRAP)?; @@ -372,7 +373,7 @@ pub fn publish(output: &Utf8Path) -> Result { harness::canonical(&custody), ) .map_err(|error| format!("{output}/{CUSTODY_FILE}: {error}"))?; - Ok(custody) + Ok((custody, exported)) } /// Wait in `directory` for the run's export, check its custody record diff --git a/crates/conformance/src/production_export.rs b/crates/conformance/src/production_export.rs index 3daaa00d16..3480774f32 100644 --- a/crates/conformance/src/production_export.rs +++ b/crates/conformance/src/production_export.rs @@ -225,7 +225,7 @@ impl Exported { /// The verified directory retained beside the export's production area. #[must_use] - pub(crate) fn verified_root(&self) -> Utf8PathBuf { + pub fn verified_root(&self) -> Utf8PathBuf { self.bundle() .parent() .and_then(Utf8Path::parent) diff --git a/crates/lexlean/src/calculus/interp.rs b/crates/lexlean/src/calculus/interp.rs index 7329da1340..5d09e7a799 100644 --- a/crates/lexlean/src/calculus/interp.rs +++ b/crates/lexlean/src/calculus/interp.rs @@ -5,10 +5,14 @@ //! the LexLean evaluator, so any divergence fails verification. use std::cmp::Ordering; +use std::ops::Deref; +use std::rc::Rc; use super::{Arm, Expr, IntKind, OrderingValue, Outcome, Prim, Program, Shape, Ty, Value}; -/// A runtime value. +/// A runtime value. Its parts are shared, so a copy (a variable read, a +/// binding, a field) costs a reference count and not the size of the value; +/// what a value is, and every step charged for it, is unchanged. #[derive(Debug, Clone, PartialEq, Eq)] pub enum Rv { Unit, @@ -16,19 +20,69 @@ pub enum Rv { Nat(u64), Int(i64), Fixed(IntKind, i128), - Str(String), - Bytes(Vec), + Str(Rc), + Bytes(Rc<[u8]>), Ord(Ordering), None, - Some(Box), - Ok(Box), - Err(Box), - List(Vec), - Pair(Box, Box), - Adt(u64, Vec), - Closure(u64, Vec), + Some(Rc), + Ok(Rc), + Err(Rc), + List(Seq), + Pair(Rc, Rc), + Adt(u64, Rc<[Rv]>), + Closure(u64, Rc<[Rv]>), } +/// The items of a list from `start` on: the tail of a list shares its +/// items, so taking it (`Cons`) does not copy them. +#[derive(Debug, Clone)] +pub struct Seq { + items: Rc<[Rv]>, + start: usize, +} + +impl Seq { + fn tail(&self) -> Self { + Self { + items: Rc::clone(&self.items), + start: self.start + 1, + } + } +} + +impl Deref for Seq { + type Target = [Rv]; + fn deref(&self) -> &[Rv] { + &self.items[self.start..] + } +} + +impl From> for Seq { + fn from(items: Vec) -> Self { + Self { + items: items.into(), + start: 0, + } + } +} + +impl FromIterator for Seq { + fn from_iter>(items: I) -> Self { + Self { + items: items.into_iter().collect(), + start: 0, + } + } +} + +impl PartialEq for Seq { + fn eq(&self, other: &Self) -> bool { + **self == **other + } +} + +impl Eq for Seq {} + /// A runtime outcome; steps are charged exactly as the denotation charges /// them. #[derive(Debug, Clone, PartialEq, Eq)] @@ -61,7 +115,8 @@ fn weight(value: &Rv) -> u64 { Rv::Str(text) => 1 + text.chars().count() as u64, Rv::Bytes(octets) => 1 + octets.len() as u64, Rv::Some(inner) | Rv::Ok(inner) | Rv::Err(inner) => 1 + weight(inner), - Rv::List(items) | Rv::Adt(_, items) | Rv::Closure(_, items) => 1 + weights(items), + Rv::List(items) => 1 + weights(items), + Rv::Adt(_, items) | Rv::Closure(_, items) => 1 + weights(items), Rv::Pair(left, right) => 1 + weight(left) + weight(right), Rv::Unit | Rv::Bool(_) @@ -106,7 +161,7 @@ fn fixed_value(kind: IntKind, number: i128) -> Option { } fn option(value: Option) -> Out { - Out::Value(value.map_or(Rv::None, |value| Rv::Some(Box::new(value))), 0) + Out::Value(value.map_or(Rv::None, |value| Rv::Some(Rc::new(value))), 0) } /// Wrap a mathematical result into `kind` by two's complement truncation. @@ -212,10 +267,10 @@ fn primitive(operation: &Prim, values: &[Rv]) -> Out { (Prim::BoolAnd, [Bool(a), Bool(b)]) => Out::Value(Bool(*a && *b), 0), (Prim::BoolOr, [Bool(a), Bool(b)]) => Out::Value(Bool(*a || *b), 0), (Prim::Append, [List(a), List(b)]) => { - Out::Value(List(a.iter().chain(b).cloned().collect()), 0) + Out::Value(List(a.iter().chain(b.iter()).cloned().collect()), 0) } (Prim::Append, [Bytes(a), Bytes(b)]) => { - Out::Value(Bytes(a.iter().chain(b).copied().collect()), 0) + Out::Value(Bytes(a.iter().chain(b.iter()).copied().collect()), 0) } (Prim::Length, [List(a)]) => nat_result(a.len() as u128), (Prim::Length, [Bytes(a)]) => nat_result(a.len() as u128), @@ -230,18 +285,20 @@ fn primitive(operation: &Prim, values: &[Rv]) -> Out { .map(|byte| Fixed(IntKind::U8, i128::from(*byte))), ), (Prim::Slice, [List(a), Nat(start), Nat(count)]) => { - option(slice(a, *start, *count).map(|part| List(part.to_vec()))) + option(slice(a, *start, *count).map(|part| List(part.iter().cloned().collect()))) } (Prim::Slice, [Bytes(a), Nat(start), Nat(count)]) => { - option(slice(a, *start, *count).map(|part| Bytes(part.to_vec()))) + option(slice(a, *start, *count).map(|part| Bytes(part.into()))) + } + (Prim::Utf8Encode, [Str(a)]) => Out::Value(Bytes(a.as_bytes().into()), 0), + (Prim::Utf8Decode, [Bytes(a)]) => { + option(std::str::from_utf8(a).ok().map(|text| Str(text.into()))) } - (Prim::Utf8Encode, [Str(a)]) => Out::Value(Bytes(a.as_bytes().to_vec()), 0), - (Prim::Utf8Decode, [Bytes(a)]) => option(String::from_utf8(a.clone()).ok().map(Str)), (Prim::CompareBytes, [Bytes(a), Bytes(b)]) => Out::Value(Rv::Ord(a.cmp(b)), 0), (Prim::SplitExact, [Str(text), Str(delimiter), Fixed(IntKind::U32, maximum)]) => { - let fields: Vec = text - .split(delimiter.as_str()) - .map(|field| Str(field.to_owned())) + let fields: Seq = text + .split(&**delimiter) + .map(|field| Str(field.into())) .collect(); option( (!delimiter.is_empty() && fields.len() as i128 <= *maximum).then_some(List(fields)), @@ -249,14 +306,14 @@ fn primitive(operation: &Prim, values: &[Rv]) -> Out { } (Prim::Join, [List(items), Str(delimiter)]) => { let mut texts = Vec::new(); - for item in items { + for item in items.iter() { let Str(text) = item else { return Out::Stuck }; - texts.push(text.as_str()); + texts.push(&**text); } - Out::Value(Str(texts.join(delimiter)), 0) + Out::Value(Str(texts.join(delimiter).into()), 0) } - (Prim::FormatDecimal, [Int(a)]) => Out::Value(Str(a.to_string()), 0), - (Prim::FormatDecimal, [Fixed(_, a)]) => Out::Value(Str(a.to_string()), 0), + (Prim::FormatDecimal, [Int(a)]) => Out::Value(Str(a.to_string().into()), 0), + (Prim::FormatDecimal, [Fixed(_, a)]) => Out::Value(Str(a.to_string().into()), 0), (Prim::Convert { target }, [Int(a)]) => option(fixed_value(*target, i128::from(*a))), (Prim::Convert { target }, [Fixed(_, a)]) => option(fixed_value(*target, *a)), (Prim::Compare, [left, right]) => { @@ -265,7 +322,7 @@ fn primitive(operation: &Prim, values: &[Rv]) -> Out { (Prim::ParseDecimal { target: Ty::Int }, [Str(text)]) => match parse_decimal(text) { None => Out::Value(Rv::None, 0), Some(Ok(number)) => i64::try_from(number).map_or(Out::Overflow(0), |number| { - Out::Value(Rv::Some(Box::new(Int(number))), 0) + Out::Value(Rv::Some(Rc::new(Int(number))), 0) }), Some(Err(())) => Out::Overflow(0), }, @@ -297,7 +354,7 @@ fn compare(left: &Rv, right: &Rv) -> Option { decided => Some(decided), }, (Rv::List(left), Rv::List(right)) => { - for (a, b) in left.iter().zip(right) { + for (a, b) in left.iter().zip(right.iter()) { match compare(a, b)? { Ordering::Equal => {} decided => return Some(decided), @@ -324,23 +381,21 @@ fn destruct(shape: Shape, value: &Rv) -> Option> { (Shape::None, Rv::None) | (Shape::Unit, Rv::Unit) => Some(Vec::new()), (Shape::Some, Rv::Some(inner)) | (Shape::Ok, Rv::Ok(inner)) - | (Shape::Error, Rv::Err(inner)) => Some(vec![inner.as_ref().clone()]), + | (Shape::Error, Rv::Err(inner)) => Some(vec![Rv::clone(inner)]), (Shape::Nil, Rv::List(items)) if items.is_empty() => Some(Vec::new()), (Shape::Cons, Rv::List(items)) if !items.is_empty() => { - Some(vec![items[0].clone(), Rv::List(items[1..].to_vec())]) + Some(vec![items[0].clone(), Rv::List(items.tail())]) } (Shape::Zero, Rv::Nat(0)) => Some(Vec::new()), (Shape::Succ, Rv::Nat(number)) if *number > 0 => Some(vec![Rv::Nat(number - 1)]), - (Shape::Pair, Rv::Pair(left, right)) => { - Some(vec![left.as_ref().clone(), right.as_ref().clone()]) - } + (Shape::Pair, Rv::Pair(left, right)) => Some(vec![Rv::clone(left), Rv::clone(right)]), (Shape::True, Rv::Bool(true)) | (Shape::False, Rv::Bool(false)) | (Shape::Lt, Rv::Ord(Ordering::Less)) | (Shape::Eq, Rv::Ord(Ordering::Equal)) | (Shape::Gt, Rv::Ord(Ordering::Greater)) => Some(Vec::new()), (Shape::Adt { constructor }, Rv::Adt(tag, fields)) if *tag == constructor => { - Some(fields.clone()) + Some(fields.to_vec()) } _ => None, } @@ -350,15 +405,19 @@ fn construct(shape: Shape, values: Vec) -> Out { let mut values = values; match (shape, values.len()) { (Shape::None, 0) => Out::Value(Rv::None, 0), - (Shape::Some, 1) => Out::Value(Rv::Some(Box::new(values.remove(0))), 0), - (Shape::Ok, 1) => Out::Value(Rv::Ok(Box::new(values.remove(0))), 0), - (Shape::Error, 1) => Out::Value(Rv::Err(Box::new(values.remove(0))), 0), - (Shape::Nil, 0) => Out::Value(Rv::List(Vec::new()), 0), + (Shape::Some, 1) => Out::Value(Rv::Some(Rc::new(values.remove(0))), 0), + (Shape::Ok, 1) => Out::Value(Rv::Ok(Rc::new(values.remove(0))), 0), + (Shape::Error, 1) => Out::Value(Rv::Err(Rc::new(values.remove(0))), 0), + (Shape::Nil, 0) => Out::Value(Rv::List(Seq::from(Vec::new())), 0), (Shape::Cons, 2) => match values.remove(1) { - Rv::List(mut items) => { - items.insert(0, values.remove(0)); - Out::Value(Rv::List(items), 0) - } + Rv::List(items) => Out::Value( + Rv::List( + std::iter::once(values.remove(0)) + .chain(items.iter().cloned()) + .collect(), + ), + 0, + ), _ => Out::Stuck, }, (Shape::Zero, 0) => Out::Value(Rv::Nat(0), 0), @@ -368,7 +427,7 @@ fn construct(shape: Shape, values: Vec) -> Out { }, (Shape::Pair, 2) => { let right = values.remove(1); - Out::Value(Rv::Pair(Box::new(values.remove(0)), Box::new(right)), 0) + Out::Value(Rv::Pair(Rc::new(values.remove(0)), Rc::new(right)), 0) } (Shape::True, 0) => Out::Value(Rv::Bool(true), 0), (Shape::False, 0) => Out::Value(Rv::Bool(false), 0), @@ -376,29 +435,51 @@ fn construct(shape: Shape, values: Vec) -> Out { (Shape::Lt, 0) => Out::Value(Rv::Ord(Ordering::Less), 0), (Shape::Eq, 0) => Out::Value(Rv::Ord(Ordering::Equal), 0), (Shape::Gt, 0) => Out::Value(Rv::Ord(Ordering::Greater), 0), - (Shape::Adt { constructor }, _) => Out::Value(Rv::Adt(constructor, values), 0), + (Shape::Adt { constructor }, _) => Out::Value(Rv::Adt(constructor, values.into()), 0), _ => Out::Stuck, } } -type Env = Vec<(u64, Rv)>; +/// The bindings in scope, innermost first. A binding is pushed in front of +/// the bindings it extends, which it shares, so extending a scope costs one +/// binding and not a copy of the scope. +type Env = Option>; + +struct Binding { + name: u64, + value: Rv, + outer: Env, +} /// The innermost binding of `name` and the number of bindings examined /// before it (`depth`). fn lookup(env: &Env, name: u64) -> Option<(Rv, u64)> { - env.iter() - .rev() - .enumerate() - .find(|(_, (bound, _))| *bound == name) - .map(|(depth, (_, value))| (value.clone(), depth as u64)) + let mut depth = 0; + let mut at = env.as_deref(); + while let Some(binding) = at { + if binding.name == name { + return Some((binding.value.clone(), depth)); + } + depth += 1; + at = binding.outer.as_deref(); + } + None } +/// `env` extended by `names` bound to `values` in order, so the last name is +/// the innermost binding. fn bind_all(names: &[u64], values: Vec, env: &Env) -> Option { if names.len() != values.len() { return None; } let mut out = env.clone(); - out.extend(names.iter().copied().zip(values)); + for (name, value) in names.iter().copied().zip(values) { + out = Some(Rc::new(Binding { + name, + value, + outer: out, + })); + } Some(out) } @@ -414,7 +495,7 @@ impl Interp<'_> { else { return Out::Stuck; }; - let Some(env) = bind_all(&callee.parameters, values, &Vec::new()) else { + let Some(env) = bind_all(&callee.parameters, values, &None) else { return Out::Stuck; }; add_steps(self.eval(remaining, &env, &callee.body), steps) @@ -451,8 +532,11 @@ impl Interp<'_> { Expr::Let { name, bound, body, .. } => Self::propagate(self.eval(remaining, env, bound), |value, steps| { - let mut extended = env.clone(); - extended.push((*name, value)); + let extended = Some(Rc::new(Binding { + name: *name, + value, + outer: env.clone(), + })); add_steps(self.eval(remaining, &extended, body), steps + 1) }), Expr::Cond { @@ -486,7 +570,7 @@ impl Interp<'_> { } Expr::Closure { function, captures } => { Self::propagate_list(self.eval_list(remaining, env, captures), |values, steps| { - Out::Value(Rv::Closure(*function, values), steps + 1) + Out::Value(Rv::Closure(*function, values.into()), steps + 1) }) } Expr::Apply { target, operands } => { @@ -498,7 +582,7 @@ impl Interp<'_> { self.eval_list(remaining, env, operands), |values, steps| { let passed = captured.len() as u64; - let mut all = captured; + let mut all = captured.to_vec(); all.extend(values); self.call(remaining, function, all, target_steps + steps + 1 + passed) }, @@ -514,14 +598,14 @@ impl Interp<'_> { Expr::First { value } => Self::propagate( self.eval(remaining, env, value), |value, steps| match value { - Rv::Pair(left, _) => Out::Value(*left, steps + 1), + Rv::Pair(left, _) => Out::Value(Rv::clone(&left), steps + 1), _ => Out::Stuck, }, ), Expr::Second { value } => Self::propagate( self.eval(remaining, env, value), |value, steps| match value { - Rv::Pair(_, right) => Out::Value(*right, steps + 1), + Rv::Pair(_, right) => Out::Value(Rv::clone(&right), steps + 1), _ => Out::Stuck, }, ), @@ -597,12 +681,12 @@ pub fn to_runtime(value: &Value) -> Option { Value::I16 { value } => fixed_value(IntKind::I16, number(value)?)?, Value::I32 { value } => fixed_value(IntKind::I32, number(value)?)?, Value::I64 { value } => fixed_value(IntKind::I64, number(value)?)?, - Value::String { value } => Rv::Str(value.clone()), + Value::String { value } => Rv::Str(value.as_str().into()), Value::Bytes { hex } => Rv::Bytes( (0..hex.len()) .step_by(2) .map(|at| u8::from_str_radix(hex.get(at..at + 2)?, 16).ok()) - .collect::>>()?, + .collect::>>()?, ), Value::Ordering { value } => Rv::Ord(match value { OrderingValue::Lt => Ordering::Less, @@ -610,12 +694,14 @@ pub fn to_runtime(value: &Value) -> Option { OrderingValue::Gt => Ordering::Greater, }), Value::None => Rv::None, - Value::Some { value } => Rv::Some(Box::new(to_runtime(value)?)), - Value::Ok { value } => Rv::Ok(Box::new(to_runtime(value)?)), - Value::Error { value } => Rv::Err(Box::new(to_runtime(value)?)), - Value::List { items } => Rv::List(items.iter().map(to_runtime).collect::>()?), + Value::Some { value } => Rv::Some(Rc::new(to_runtime(value)?)), + Value::Ok { value } => Rv::Ok(Rc::new(to_runtime(value)?)), + Value::Error { value } => Rv::Err(Rc::new(to_runtime(value)?)), + Value::List { items } => Rv::List(Seq::from( + items.iter().map(to_runtime).collect::>>()?, + )), Value::Pair { left, right } => { - Rv::Pair(Box::new(to_runtime(left)?), Box::new(to_runtime(right)?)) + Rv::Pair(Rc::new(to_runtime(left)?), Rc::new(to_runtime(right)?)) } Value::Adt { constructor, @@ -657,7 +743,7 @@ pub fn from_runtime(value: &Rv) -> Value { } } Rv::Str(value) => Value::String { - value: value.clone(), + value: value.to_string(), }, Rv::Bytes(bytes) => Value::Bytes { hex: bytes.iter().map(|byte| format!("{byte:02x}")).collect(), @@ -714,7 +800,7 @@ pub fn run(program: &Program, fuel: u64, entry: u64, arguments: &[Value]) -> Out else { return Outcome::Stuck; }; - let Some(env) = bind_all(&function.parameters, values, &Vec::new()) else { + let Some(env) = bind_all(&function.parameters, values, &None) else { return Outcome::Stuck; }; match interp.eval(fuel, &env, &function.body) { diff --git a/crates/lexlean/src/calculus/realization.rs b/crates/lexlean/src/calculus/realization.rs index 7920e1769f..3a21b5422e 100644 --- a/crates/lexlean/src/calculus/realization.rs +++ b/crates/lexlean/src/calculus/realization.rs @@ -280,15 +280,230 @@ pub const TABLE: &[(&str, &[&str])] = &[ ]; /// The serialized `kind` tag of a closed calculus value. +/// +/// The calculus types are internally tagged, so the tag is the first field +/// their serialization writes. [`tag::Kind`] reads that field and stops, so +/// the cost is that of the tag and not of the whole node: serializing the +/// node to JSON to read one field made a walk that asks for the tag of every +/// node quadratic in the depth of the term. The answer is the field of the +/// JSON form, which `kind_is_the_json_tag` checks on every sample. pub(crate) fn kind(value: &T) -> String { - serde_json::to_value(value) - .ok() - .and_then(|json| { - json.get("kind") - .and_then(|kind| kind.as_str()) - .map(str::to_owned) - }) - .unwrap_or_default() + match value.serialize(tag::Kind) { + Err(tag::Stop::Found(kind)) => kind, + Ok(()) | Err(tag::Stop::Absent) => String::new(), + } +} + +/// A serializer that reads the `kind` field of a struct or map and nothing +/// else: it stops with the field's text as soon as it has it, and with +/// [`Stop::Absent`] at anything that is not such a field. +mod tag { + use serde::ser::{self, Impossible, Serialize}; + + #[derive(Debug)] + pub(super) enum Stop { + Found(String), + Absent, + } + + impl std::fmt::Display for Stop { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str("the tag is read") + } + } + + impl std::error::Error for Stop {} + + impl ser::Error for Stop { + fn custom(_: T) -> Self { + Stop::Absent + } + } + + /// The top level: a struct or a map, whose `kind` field is wanted. + pub(super) struct Kind; + /// A field's value: wanted only as text. + struct Text; + /// A map's fields: the key of the entry whose value comes next. + pub(super) struct Fields(bool); + + macro_rules! absent { + ($($name:ident: $ty:ty),* $(,)?) => { + $(fn $name(self, _: $ty) -> Result { Err(Stop::Absent) })* + }; + } + + macro_rules! scalars { + () => { + absent!( + serialize_bool: bool, serialize_i8: i8, serialize_i16: i16, serialize_i32: i32, + serialize_i64: i64, serialize_u8: u8, serialize_u16: u16, serialize_u32: u32, + serialize_u64: u64, serialize_f32: f32, serialize_f64: f64, serialize_char: char, + serialize_bytes: &[u8], + ); + fn serialize_none(self) -> Result { + Err(Stop::Absent) + } + fn serialize_some(self, _: &T) -> Result { + Err(Stop::Absent) + } + fn serialize_unit(self) -> Result { + Err(Stop::Absent) + } + fn serialize_unit_struct(self, _: &'static str) -> Result { + Err(Stop::Absent) + } + fn serialize_unit_variant( + self, + _: &'static str, + _: u32, + _: &'static str, + ) -> Result { + Err(Stop::Absent) + } + fn serialize_newtype_struct( + self, + _: &'static str, + _: &T, + ) -> Result { + Err(Stop::Absent) + } + fn serialize_newtype_variant( + self, + _: &'static str, + _: u32, + _: &'static str, + _: &T, + ) -> Result { + Err(Stop::Absent) + } + fn serialize_seq(self, _: Option) -> Result { + Err(Stop::Absent) + } + fn serialize_tuple(self, _: usize) -> Result { + Err(Stop::Absent) + } + fn serialize_tuple_struct( + self, + _: &'static str, + _: usize, + ) -> Result { + Err(Stop::Absent) + } + fn serialize_tuple_variant( + self, + _: &'static str, + _: u32, + _: &'static str, + _: usize, + ) -> Result { + Err(Stop::Absent) + } + fn serialize_struct_variant( + self, + _: &'static str, + _: u32, + _: &'static str, + _: usize, + ) -> Result { + Err(Stop::Absent) + } + }; + } + + impl ser::Serializer for Kind { + type Ok = (); + type Error = Stop; + type SerializeSeq = Impossible<(), Stop>; + type SerializeTuple = Impossible<(), Stop>; + type SerializeTupleStruct = Impossible<(), Stop>; + type SerializeTupleVariant = Impossible<(), Stop>; + type SerializeMap = Fields; + type SerializeStruct = Fields; + type SerializeStructVariant = Impossible<(), Stop>; + + scalars!(); + + fn serialize_str(self, _: &str) -> Result<(), Stop> { + Err(Stop::Absent) + } + fn serialize_map(self, _: Option) -> Result { + Ok(Fields(false)) + } + fn serialize_struct(self, _: &'static str, _: usize) -> Result { + Ok(Fields(false)) + } + } + + impl ser::Serializer for Text { + type Ok = String; + type Error = Stop; + type SerializeSeq = Impossible; + type SerializeTuple = Impossible; + type SerializeTupleStruct = Impossible; + type SerializeTupleVariant = Impossible; + type SerializeMap = Impossible; + type SerializeStruct = Impossible; + type SerializeStructVariant = Impossible; + + scalars!(); + + fn serialize_str(self, text: &str) -> Result { + Ok(text.to_owned()) + } + fn serialize_map(self, _: Option) -> Result { + Err(Stop::Absent) + } + fn serialize_struct( + self, + _: &'static str, + _: usize, + ) -> Result { + Err(Stop::Absent) + } + } + + /// The `kind` field is the answer; any other field before it is skipped + /// unread (serde writes the tag first, so none is). + fn field(key: &str, value: &T) -> Result<(), Stop> { + if key == "kind" { + return Err(value.serialize(Text).map_or(Stop::Absent, Stop::Found)); + } + Ok(()) + } + + impl ser::SerializeStruct for Fields { + type Ok = (); + type Error = Stop; + fn serialize_field( + &mut self, + key: &'static str, + value: &T, + ) -> Result<(), Stop> { + field(key, value) + } + fn end(self) -> Result<(), Stop> { + Err(Stop::Absent) + } + } + + impl ser::SerializeMap for Fields { + type Ok = (); + type Error = Stop; + fn serialize_key(&mut self, key: &T) -> Result<(), Stop> { + self.0 = key.serialize(Text).is_ok_and(|key| key == "kind"); + Ok(()) + } + fn serialize_value(&mut self, value: &T) -> Result<(), Stop> { + if self.0 { + return field("kind", value); + } + Ok(()) + } + fn end(self) -> Result<(), Stop> { + Err(Stop::Absent) + } + } } /// One sample of every type kind; [`ty_index`] proves the list complete. @@ -1464,3 +1679,46 @@ pub fn check_table(runtime: &BTreeSet) -> Result<(), String> { } Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + /// The tag [`kind`] reads is the `kind` field of the node's JSON form, + /// on a sample of every kind of every calculus syntax class. + #[test] + fn kind_is_the_json_tag() { + fn json(value: &T) -> String { + serde_json::to_value(value).expect("JSON")["kind"] + .as_str() + .expect("a tag") + .to_owned() + } + let mut checked = 0; + for ty in ty_samples() { + assert_eq!(kind(&ty), json(&ty)); + checked += 1; + } + for value in value_samples() { + assert_eq!(kind(&value), json(&value)); + checked += 1; + } + for expr in expr_samples() { + assert_eq!(kind(&expr), json(&expr)); + checked += 1; + } + for shape in shape_samples() { + assert_eq!(kind(&shape), json(&shape)); + checked += 1; + } + for prim in prim_samples() { + assert_eq!(kind(&prim), json(&prim)); + checked += 1; + } + assert!(checked > 100, "{checked} samples"); + // A node that is not a tagged struct has no tag, as before. + assert_eq!(kind(&3u8), ""); + assert_eq!(kind(&"kind"), ""); + assert_eq!(kind(&vec![Ty::Unit]), ""); + } +} diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 56612dca01..c6cd40d6b8 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -153,21 +153,54 @@ fn check_freshness(root: &Path) -> Result<(), Fail> { /// §9.4: the bootstrap production export, run once for a CI run by the /// `bootstrap-export` job, which uploads what this writes for the run's other -/// jobs (`repo_conformance::export_custody`). +/// jobs (`repo_conformance::export_custody`). The export verifies the +/// bootstrap project whole, through the same `verify` over the same selection +/// that `verify-examples` runs, so this job is also the bootstrap project's +/// part of the `examples` recipe: before the export it formats, locks, +/// checks, and builds a clean copy of the project as the recipe does, and +/// after it it holds the export's verified directory to every check the +/// recipe makes of a verification (§22.12, §29.5). The `examples` leg of the +/// same run then verifies every example but this one and UOR Atlas. fn export_bootstrap(arguments: &[String]) -> Result<(), Fail> { let output = arguments .iter() .position(|argument| argument == "--output") .and_then(|index| arguments.get(index + 1)) .ok_or("export-bootstrap --output DIR")?; - let custody = repo_conformance::export_custody::publish(camino::Utf8Path::new(output))?; + let root = repo_model::repo_root(); + let dir = root.join(BOOTSTRAP_EXAMPLE); + let name = BOOTSTRAP_EXAMPLE; + let started = std::time::Instant::now(); + let (_scratch, _engine, mut steps) = example_before_verify(&root, &dir, name)?; + let clock = std::time::Instant::now(); + let (custody, exported) = + repo_conformance::export_custody::publish(camino::Utf8Path::new(output))?; + steps.insert( + "verify_ms".to_owned(), + serde_json::json!(u64::try_from(clock.elapsed().as_millis()).unwrap_or(u64::MAX)), + ); println!( "export-bootstrap: the bootstrap project exported once for run {} attempt {} (commit {}); its packages equal the committed packages (§24.7); bundle sha256 {} ({} files) in {output}", custody.run_id, custody.run_attempt, custody.commit, custody.bundle_sha256, custody.bundle_files ); - Ok(()) + println!( + "verify-examples: {name} took {} s", + started.elapsed().as_secs() + ); + append_example_telemetry(name, started, &steps, None); + example_after_verify( + &dir, + name, + exported.verified_root().as_std_path(), + &exported.output.result.verification.attestation_id.to_hex(), + false, + ) } +/// The example directory the `bootstrap-export` job verifies for the +/// `examples` recipe (§9.4). +const BOOTSTRAP_EXAMPLE: &str = "bootstrap"; + fn example_dirs(root: &Path) -> Result, Fail> { let mut dirs = Vec::new(); for entry in std::fs::read_dir(root.join("examples"))? { @@ -252,32 +285,7 @@ fn verify_examples(root: &Path, write: bool) -> Result<(), Fail> { .unwrap_or_default() .to_string_lossy() .to_string(); - // Every example runs from a clean copy (§28.6): no build directory - // from an earlier compiler can be reused or refused, and the - // repository tree stays free of generated output. - let scratch = tempfile::Builder::new() - .prefix("lexlean-example-") - .tempdir()?; - // Preserve the example's two-component repository-relative position, - // so any declared local path requirement resolves exactly as it does - // in the checkout while the example itself remains a clean copy. - let staged = stage_project( - root, - &dir, - scratch.path(), - &scratch.path().join("examples").join(&name), - )?; - for required in example_path_requirements(&dir, root)? { - let destination = scratch.path().join(&required); - std::fs::create_dir_all(&destination)?; - copy_example(&root.join(&required), &destination)?; - } - let engine = engine_for(&staged)?; - // The time of each step is kept for the CI evidence: what the - // verifier's own clock does not cover (reading, linking, and rendering - // the project, which `check`, `build`, and `verify` each do) is the - // difference between a step and the verification it contains. - let mut steps = serde_json::Map::new(); + let (_scratch, engine, mut steps) = example_before_verify(root, &dir, &name)?; let mut clock = std::time::Instant::now(); let mut lap = |label: &str| { steps.insert( @@ -286,32 +294,6 @@ fn verify_examples(root: &Path, write: bool) -> Result<(), Fail> { ); clock = std::time::Instant::now(); }; - engine - .format(lexlean::FormatRequest { - selection: lexlean::Selection::Entrypoints, - check_only: true, - }) - .map_err(|error| format!("{name}: fmt --check: {error}"))?; - lap("fmt"); - engine - .lock(lexlean::LockRequest { - check_only: true, - allow_network: false, - }) - .map_err(|error| format!("{name}: lock --check: {error}"))?; - lap("lock"); - engine - .check(lexlean::CheckRequest { - selection: lexlean::Selection::Entrypoints, - }) - .map_err(|error| format!("{name}: check: {error}"))?; - lap("check"); - engine - .build(lexlean::BuildRequest { - selection: lexlean::Selection::Entrypoints, - }) - .map_err(|error| format!("{name}: build: {error}"))?; - lap("build"); // The part of the gate this job is (§9.4): a shard of one example's // verification runs the processes its plan names and leaves; the join // publishes and is compared like a whole verification. @@ -397,59 +379,155 @@ fn verify_examples(root: &Path, write: bool) -> Result<(), Fail> { "verify-examples: {name} took {} s", started.elapsed().as_secs() ); - println!( - "verify-examples: {name} verified (attestation {})", - verified.attestation_id.to_hex() - ); - // §22.12: a measurement is never part of a verified artifact. The - // whole published directory is read for the closed vocabulary of - // measurement keys, and its digest is printed so that two runs (of - // two widths, or two runners) can be compared byte for byte. - let leaked = repo_conformance::evidence::telemetry_in(verified.root.as_std_path())?; - if !leaked.is_empty() { - return Err(format!( - "VR-22: {name}: performance telemetry is in a verified artifact (§22.12): {}", - leaked.join("; ") - ) - .into()); - } - println!( - "verify-examples: {name} verified-digest {}", - ci::tree_digest(verified.root.as_std_path())? - ); append_example_telemetry(&name, started, &steps, None); + example_after_verify( + &dir, + &name, + verified.root.as_std_path(), + &verified.attestation_id.to_hex(), + write, + )?; + } + Ok(()) +} - let records = normalized_verify_records(verified.root.as_std_path())?; - let expected_root = dir.join("expected").join("verify"); - if write { - if expected_root.exists() { - std::fs::remove_dir_all(&expected_root)?; - } - for (relative, bytes) in &records { - let destination = expected_root.join(relative); - if let Some(parent) = destination.parent() { - std::fs::create_dir_all(parent)?; - } - std::fs::write(destination, bytes)?; - } - println!( - "verify-examples: wrote {} normalized verification records for {name}", - records.len() - ); - continue; +/// The steps of the `examples` recipe before an example verifies (§28.6): +/// a clean copy of the example, then `fmt --check`, `lock --check`, `check`, +/// and `build`. Returns the copy, whose directory lives as long as it does, +/// the example's engine, and the time of each step. +fn example_before_verify( + root: &Path, + dir: &Path, + name: &str, +) -> Result< + ( + tempfile::TempDir, + lexlean::Engine, + serde_json::Map, + ), + Fail, +> { + // Every example runs from a clean copy (§28.6): no build directory + // from an earlier compiler can be reused or refused, and the + // repository tree stays free of generated output. + let scratch = tempfile::Builder::new() + .prefix("lexlean-example-") + .tempdir()?; + // Preserve the example's two-component repository-relative position, + // so any declared local path requirement resolves exactly as it does + // in the checkout while the example itself remains a clean copy. + let staged = stage_project( + root, + dir, + scratch.path(), + &scratch.path().join("examples").join(name), + )?; + for required in example_path_requirements(dir, root)? { + let destination = scratch.path().join(&required); + std::fs::create_dir_all(&destination)?; + copy_example(&root.join(&required), &destination)?; + } + let engine = engine_for(&staged)?; + // The time of each step is kept for the CI evidence: what the + // verifier's own clock does not cover (reading, linking, and rendering + // the project, which `check`, `build`, and `verify` each do) is the + // difference between a step and the verification it contains. + let mut steps = serde_json::Map::new(); + let mut clock = std::time::Instant::now(); + let mut lap = |label: &str| { + steps.insert( + format!("{label}_ms"), + serde_json::json!(u64::try_from(clock.elapsed().as_millis()).unwrap_or(u64::MAX)), + ); + clock = std::time::Instant::now(); + }; + engine + .format(lexlean::FormatRequest { + selection: lexlean::Selection::Entrypoints, + check_only: true, + }) + .map_err(|error| format!("{name}: fmt --check: {error}"))?; + lap("fmt"); + engine + .lock(lexlean::LockRequest { + check_only: true, + allow_network: false, + }) + .map_err(|error| format!("{name}: lock --check: {error}"))?; + lap("lock"); + engine + .check(lexlean::CheckRequest { + selection: lexlean::Selection::Entrypoints, + }) + .map_err(|error| format!("{name}: check: {error}"))?; + lap("check"); + engine + .build(lexlean::BuildRequest { + selection: lexlean::Selection::Entrypoints, + }) + .map_err(|error| format!("{name}: build: {error}"))?; + lap("build"); + Ok((scratch, engine, steps)) +} + +/// What the `examples` recipe requires of an example's verified directory +/// (§22.12, §29.5): no performance telemetry in it, and its normalized +/// verification records equal to the committed `expected/verify`, or, with +/// `write`, written there. +fn example_after_verify( + dir: &Path, + name: &str, + verified: &Path, + attestation: &str, + write: bool, +) -> Result<(), Fail> { + println!("verify-examples: {name} verified (attestation {attestation})"); + // §22.12: a measurement is never part of a verified artifact. The + // whole published directory is read for the closed vocabulary of + // measurement keys, and its digest is printed so that two runs (of + // two widths, or two runners) can be compared byte for byte. + let leaked = repo_conformance::evidence::telemetry_in(verified)?; + if !leaked.is_empty() { + return Err(format!( + "VR-22: {name}: performance telemetry is in a verified artifact (§22.12): {}", + leaked.join("; ") + ) + .into()); + } + println!( + "verify-examples: {name} verified-digest {}", + ci::tree_digest(verified)? + ); + let records = normalized_verify_records(verified)?; + let expected_root = dir.join("expected").join("verify"); + if write { + if expected_root.exists() { + std::fs::remove_dir_all(&expected_root)?; } - if !expected_root.is_dir() { - return Err(format!( - "R9: {name} commits no expected/verify; every example carries its normalized verification records (§29.5) — run `cargo xtask verify-examples --write` and review the diff" - ) - .into()); + for (relative, bytes) in &records { + let destination = expected_root.join(relative); + if let Some(parent) = destination.parent() { + std::fs::create_dir_all(parent)?; + } + std::fs::write(destination, bytes)?; } - compare_tree(&name, "expected/verify", &expected_root, &records)?; println!( - "verify-examples: {name}: {} normalized verification records equal expected/verify (§29.5)", + "verify-examples: wrote {} normalized verification records for {name}", records.len() ); + return Ok(()); } + if !expected_root.is_dir() { + return Err(format!( + "R9: {name} commits no expected/verify; every example carries its normalized verification records (§29.5) — run `cargo xtask verify-examples --write` and review the diff" + ) + .into()); + } + compare_tree(name, "expected/verify", &expected_root, &records)?; + println!( + "verify-examples: {name}: {} normalized verification records equal expected/verify (§29.5)", + records.len() + ); Ok(()) } @@ -467,8 +545,8 @@ pub const EXAMPLES_PARTS_VARIABLE: &str = "LEXLEAN_EXAMPLES_PARTS"; enum ExamplesPart { /// Every example, whole. All, - /// Every example but one, whole. - Without(String), + /// Every example but the named ones, whole. + Without(Vec), /// One shard of one example's verification. Shard { example: String, @@ -480,7 +558,7 @@ enum ExamplesPart { } impl ExamplesPart { - /// Read the part from the environment: `without:`, + /// Read the part from the environment: `without:[,…]`, /// `shard::`, or `join:`; unset or empty is /// every example whole. fn from_environment() -> Result { @@ -502,7 +580,7 @@ impl ExamplesPart { let fields: Vec<&str> = text.split(':').collect(); let malformed = || -> Fail { format!( - "{EXAMPLES_PART_VARIABLE}: `{text}` is not a part: expected empty, `without:`, `shard::`, or `join:`" + "{EXAMPLES_PART_VARIABLE}: `{text}` is not a part: expected empty, `without:[,…]`, `shard::`, or `join:`" ) .into() }; @@ -514,7 +592,17 @@ impl ExamplesPart { }; match fields.as_slice() { [""] => Ok(Self::All), - ["without", example] => Ok(Self::Without(named(example)?)), + ["without", examples] => { + let mut names = Vec::new(); + for example in examples.split(',') { + let example = named(example)?; + if names.contains(&example) { + return Err(malformed()); + } + names.push(example); + } + Ok(Self::Without(names)) + } ["shard", example, shard] => Ok(Self::Shard { example: named(example)?, shard: named(shard)?, @@ -532,7 +620,7 @@ impl ExamplesPart { fn includes(&self, name: &str) -> bool { match self { Self::All => true, - Self::Without(example) => example != name, + Self::Without(examples) => !examples.iter().any(|example| example == name), Self::Shard { example, .. } | Self::Join { example, .. } => example == name, } } @@ -540,7 +628,7 @@ impl ExamplesPart { fn describe(&self) -> String { match self { Self::All => "all".to_owned(), - Self::Without(example) => format!("without:{example}"), + Self::Without(examples) => format!("without:{}", examples.join(",")), Self::Shard { example, shard, .. } => format!("shard:{example}:{shard}"), Self::Join { example, .. } => format!("join:{example}"), } @@ -1357,8 +1445,17 @@ mod examples_part_tests { ); assert_eq!( ExamplesPart::parse("without:uor-atlas", parts).expect("without"), - ExamplesPart::Without("uor-atlas".to_owned()) + ExamplesPart::Without(vec!["uor-atlas".to_owned()]) + ); + let both = ExamplesPart::parse("without:uor-atlas,bootstrap", parts).expect("without two"); + assert_eq!( + both, + ExamplesPart::Without(vec!["uor-atlas".to_owned(), "bootstrap".to_owned()]) + ); + assert!( + !both.includes("uor-atlas") && !both.includes("bootstrap") && both.includes("stdlib") ); + assert_eq!(both.describe(), "without:uor-atlas,bootstrap"); assert_eq!( ExamplesPart::parse("shard:uor-atlas:pairs-a", parts).expect("shard"), ExamplesPart::Shard { @@ -1379,6 +1476,8 @@ mod examples_part_tests { "shard:uor-atlas", "join:", "without:../x", + "without:uor-atlas,", + "without:uor-atlas,uor-atlas", "shard:a:b:c", ] { assert!( @@ -1391,7 +1490,7 @@ mod examples_part_tests { assert!(ExamplesPart::parse("without:uor-atlas", no_parts).is_ok()); let shard = ExamplesPart::parse("shard:uor-atlas:prefix", parts).expect("shard"); assert!(shard.includes("uor-atlas") && !shard.includes("compiler")); - assert!(ExamplesPart::Without("uor-atlas".to_owned()).includes("compiler")); + assert!(ExamplesPart::Without(vec!["uor-atlas".to_owned()]).includes("compiler")); assert_eq!(shard.describe(), "shard:uor-atlas:prefix"); } }