From e65a817efad0815a93f50e723b4d67217f74f365 Mon Sep 17 00:00:00 2001 From: tignear Date: Tue, 27 Oct 2026 01:06:55 +0900 Subject: [PATCH] feat(aplite): extract an independently versioned finite solver Make lydite's existing finite solver usable as the standalone aplite crate, starting at 0.1.0 in the same Cargo workspace. Move the Boolean/bit-vector/array solver and expression IR without algorithm changes; keep lydite's public paths through re-exports and leave proof construction, structural proof rules and the external Z3 route with lydite. Preserve source provenance collection and the direct Rust memory-rule checker after the move. Give Aplite independent release-please configuration, component tags, changelog and version checks. Exclude its own paths from the Celox release and retain the existing Celox publisher's package set. Run Aplite tests directly in the Lydite CI lane, including changes to its doctests and private tests. Publish Aplite independently through crates.io Trusted Publishing after its reviewed release PR merges. Dispatch the dedicated workflow at the component release tag, validate release identity and standalone packaging, and skip already published versions on retries. The initial 0.0.0 registry bootstrap is separate from the first implementation release. Validation: 73 Aplite unit tests and its public README doctest; lydite IR/solver suites; 25 verifier unit tests; seven pipeline and search-hint consumer tests, including finite-only proofs and deliberately broken models. The direct memory-rule checker passed 6,291,456 read and 524,288 write comparisons. Release/CI script tests (including tag, release identity, registry failure and component dispatch regressions), version checks, release-please JSON schema and workflow YAML validation, affected all-target clippy, formatting, package include checks and standalone cargo package verification passed. A normalized source comparison confirms that solver algorithms and term representation are unchanged. The full pinned RV32I acceptance campaign and Lean proofs were not rerun locally; runner plumbing tests are not claimed as proof evidence. No local release build was performed. Change-Id: I912d358354ee7adcdb5f99991d1b6c552e02b53b --- .github/workflows/lydite-checks.yml | 5 +- .github/workflows/publish-aplite.yml | 60 ++++++ .github/workflows/release-aplite.yml | 70 ++++++ .release-please-aplite-manifest.json | 1 + Cargo.lock | 9 + Cargo.toml | 3 + crates/aplite/CHANGELOG.md | 5 + crates/aplite/Cargo.toml | 17 ++ crates/aplite/LICENSE-APACHE | 199 ++++++++++++++++++ crates/aplite/LICENSE-MIT | 21 ++ crates/aplite/README.md | 43 ++++ crates/aplite/RELEASING.md | 37 ++++ crates/aplite/clippy.toml | 14 ++ .../{lydite-solver => aplite}/src/finite.rs | 15 +- .../src/finite/control.rs | 10 +- .../src/finite/guarded_tests.rs | 2 +- .../src/finite/lookup.rs | 12 +- .../src/finite/readonly.rs | 7 +- crates/aplite/src/lib.rs | 12 ++ crates/{lydite-ir => aplite}/src/term.rs | 0 crates/lydite-ir/Cargo.toml | 1 + crates/lydite-ir/src/lib.rs | 3 +- crates/lydite-ir/src/lower.rs | 2 +- crates/lydite-solver/Cargo.toml | 1 + crates/lydite-solver/src/lib.rs | 2 +- lydite/README.md | 4 + lydite/audit/veryl_scaling/profile_solver.py | 4 +- .../audit/veryl_scaling/rv32i_selected_ci.py | 2 +- lydite/conformance/veryl-symbolic/run_ci.sh | 6 +- lydite/proof/README.md | 4 +- lydite/proof/check_rust_rules.rs | 2 +- lydite/proof/recheck.py | 6 +- release-please-aplite-config.json | 21 ++ release-please-config.json | 9 + scripts/check-aplite-release.mjs | 30 +++ scripts/check-aplite-release.test.mjs | 45 ++++ scripts/ci-changes.mjs | 5 +- scripts/ci-changes.test.mjs | 1 + scripts/ci-lydite-changes.mjs | 5 +- scripts/ci-lydite-changes.test.mjs | 11 + scripts/publish-aplite.mjs | 48 +++++ scripts/publish-aplite.test.mjs | 63 ++++++ scripts/publish-crates.test.mjs | 2 +- 43 files changed, 773 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/publish-aplite.yml create mode 100644 .github/workflows/release-aplite.yml create mode 100644 .release-please-aplite-manifest.json create mode 100644 crates/aplite/CHANGELOG.md create mode 100644 crates/aplite/Cargo.toml create mode 100644 crates/aplite/LICENSE-APACHE create mode 100644 crates/aplite/LICENSE-MIT create mode 100644 crates/aplite/README.md create mode 100644 crates/aplite/RELEASING.md create mode 100644 crates/aplite/clippy.toml rename crates/{lydite-solver => aplite}/src/finite.rs (99%) rename crates/{lydite-solver => aplite}/src/finite/control.rs (99%) rename crates/{lydite-solver => aplite}/src/finite/guarded_tests.rs (99%) rename crates/{lydite-solver => aplite}/src/finite/lookup.rs (99%) rename crates/{lydite-solver => aplite}/src/finite/readonly.rs (99%) create mode 100644 crates/aplite/src/lib.rs rename crates/{lydite-ir => aplite}/src/term.rs (100%) create mode 100644 release-please-aplite-config.json create mode 100644 scripts/check-aplite-release.mjs create mode 100644 scripts/check-aplite-release.test.mjs create mode 100644 scripts/publish-aplite.mjs create mode 100644 scripts/publish-aplite.test.mjs diff --git a/.github/workflows/lydite-checks.yml b/.github/workflows/lydite-checks.yml index 1176b2834bc..acce10e9aff 100644 --- a/.github/workflows/lydite-checks.yml +++ b/.github/workflows/lydite-checks.yml @@ -69,11 +69,14 @@ jobs: python-version: "3.12" - name: Install recorded solver version run: python -m pip install z3-solver==5.1.0 + - name: Check independent Aplite version + working-directory: . + run: node scripts/check-aplite-release.mjs - name: Test affected Lydite packages and documentation run: | Z3_BIN="$(command -v z3)" export Z3_BIN - cargo test --locked -p lydite -p lydite-ir -p lydite-solver -p lydite-syntax -p lydite-verify + cargo test --locked -p lydite -p lydite-ir -p lydite-solver -p lydite-syntax -p lydite-verify -p aplite documentation: needs: changes diff --git a/.github/workflows/publish-aplite.yml b/.github/workflows/publish-aplite.yml new file mode 100644 index 00000000000..bd20e7ea3ee --- /dev/null +++ b/.github/workflows/publish-aplite.yml @@ -0,0 +1,60 @@ +name: Publish Aplite + +on: + workflow_dispatch: + +concurrency: + group: aplite-publish-${{ github.ref }} + cancel-in-progress: false + +permissions: + contents: read + +env: + RELEASE_TAG: ${{ github.ref_name }} + +jobs: + validate: + name: Validate and test Aplite release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + with: + ref: ${{ github.sha }} + - uses: actions/setup-node@v6 + with: + node-version: '24' + - name: Check release identity + env: + GH_TOKEN: ${{ github.token }} + run: node scripts/publish-aplite.mjs validate + - uses: ./.github/actions/setup-rust + - name: Test and verify standalone package + run: | + cargo test --locked -p aplite + cargo package --locked -p aplite + + publish: + name: Publish Aplite to crates.io + needs: validate + runs-on: ubuntu-latest + environment: crates-io + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v7 + with: + ref: ${{ github.sha }} + - uses: actions/setup-node@v6 + with: + node-version: '24' + - uses: ./.github/actions/setup-rust + - name: Authenticate to crates.io + id: crates_io_auth + uses: rust-lang/crates-io-auth-action@v1 + - name: Publish independent package + env: + GH_TOKEN: ${{ github.token }} + CARGO_REGISTRY_TOKEN: ${{ steps.crates_io_auth.outputs.token }} + run: node scripts/publish-aplite.mjs publish diff --git a/.github/workflows/release-aplite.yml b/.github/workflows/release-aplite.yml new file mode 100644 index 00000000000..59b1cb2152e --- /dev/null +++ b/.github/workflows/release-aplite.yml @@ -0,0 +1,70 @@ +name: Aplite Release Management + +on: + push: + branches: [master] + paths: + - 'crates/aplite/**' + - '.release-please-aplite-manifest.json' + - 'release-please-aplite-config.json' + - '.github/workflows/release-aplite.yml' + workflow_dispatch: + +concurrency: + group: release-management-aplite + cancel-in-progress: false + +permissions: {} + +jobs: + release-please: + name: Update Aplite release pull request + runs-on: ubuntu-latest + steps: + - name: Create release app token + id: release-token + uses: actions/create-github-app-token@v3 + with: + app-id: ${{ vars.RELEASE_APP_ID }} + private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} + permission-actions: write + permission-contents: write + permission-issues: write + permission-pull-requests: write + permission-workflows: write + + - name: Check whether the release pull request is frozen + id: release-pr + env: + GH_TOKEN: ${{ steps.release-token.outputs.token }} + shell: bash + run: | + pull_requests="$(gh pr list \ + --repo "$GITHUB_REPOSITORY" \ + --state open --base master \ + --head release-please--branches--master--components--aplite \ + --json isCrossRepository,labels)" + frozen="$(jq -r 'any(.[]; .isCrossRepository == false and any(.labels[]; .name == "merge-ready" or .name == "queued"))' <<< "$pull_requests")" + echo "frozen=$frozen" >> "$GITHUB_OUTPUT" + + - name: Create release or update release pull request + id: release + uses: googleapis/release-please-action@v5 + with: + token: ${{ steps.release-token.outputs.token }} + config-file: release-please-aplite-config.json + manifest-file: .release-please-aplite-manifest.json + skip-github-pull-request: ${{ steps.release-pr.outputs.frozen == 'true' }} + + - name: Queue Aplite publication + if: steps.release.outputs['crates/aplite--release_created'] == 'true' + env: + GH_TOKEN: ${{ steps.release-token.outputs.token }} + RELEASE_TAG: ${{ steps.release.outputs['crates/aplite--tag_name'] }} + shell: bash + run: | + if [[ ! "$RELEASE_TAG" =~ ^aplite-v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Expected an Aplite stable release tag." >&2 + exit 1 + fi + gh workflow run publish-aplite.yml --repo "$GITHUB_REPOSITORY" --ref "$RELEASE_TAG" diff --git a/.release-please-aplite-manifest.json b/.release-please-aplite-manifest.json new file mode 100644 index 00000000000..0967ef424bc --- /dev/null +++ b/.release-please-aplite-manifest.json @@ -0,0 +1 @@ +{} diff --git a/Cargo.lock b/Cargo.lock index 03444e468bf..a33a7e74520 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -127,6 +127,13 @@ version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a4385e2e34eb35d6b3efe798b9eb88096925d87726c0798709bf56d9ed84af3" +[[package]] +name = "aplite" +version = "0.1.0" +dependencies = [ + "serde_json", +] + [[package]] name = "approx" version = "0.5.1" @@ -2772,6 +2779,7 @@ dependencies = [ name = "lydite-ir" version = "0.11.0" dependencies = [ + "aplite", "serde_json", ] @@ -2779,6 +2787,7 @@ dependencies = [ name = "lydite-solver" version = "0.11.0" dependencies = [ + "aplite", "lydite-ir", "serde_json", ] diff --git a/Cargo.toml b/Cargo.toml index 03951a942f3..90e67df41c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ # Keep optional backend and comparison crates out of ordinary local builds. default-members = ["crates/celox", "crates/celox-napi", "crates/celox-vpi"] members = [ + "crates/aplite", "crates/celox", "crates/celox-analysis", "crates/celox-backend-cranelift", @@ -56,6 +57,8 @@ description = "Celox HDL Simulator" rust-version = "1.99.1" [workspace.dependencies] +# Aplite has its own release version; these consumers are unpublished. +aplite = { path = "crates/aplite" } celox = { version = "=0.11.0", path = "crates/celox", default-features = false } # x-release-please-version celox-analysis = { version = "=0.11.0", path = "crates/celox-analysis" } # x-release-please-version celox-backend-arm64 = { version = "=0.11.0", path = "crates/celox-backend-arm64" } # x-release-please-version diff --git a/crates/aplite/CHANGELOG.md b/crates/aplite/CHANGELOG.md new file mode 100644 index 00000000000..1c2930991b4 --- /dev/null +++ b/crates/aplite/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +## Unreleased + +- Extract the existing finite solver and expression IR from lydite without changing its algorithms. diff --git a/crates/aplite/Cargo.toml b/crates/aplite/Cargo.toml new file mode 100644 index 00000000000..83d091712d4 --- /dev/null +++ b/crates/aplite/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "aplite" +version = "0.1.0" +edition = "2024" +license = "MIT OR Apache-2.0" +description = "Bounded in-process Boolean, bit-vector and array constraint solver" +repository = "https://github.com/celox-sim/celox" +readme = "README.md" +keywords = ["solver", "sat", "bitvector", "constraints"] +categories = ["algorithms"] +include = ["src/**", "README.md", "RELEASING.md", "CHANGELOG.md", "Cargo.toml", "clippy.toml", "LICENSE-*"] + +[dependencies] +serde_json = "1.0" + +[lints] +workspace = true diff --git a/crates/aplite/LICENSE-APACHE b/crates/aplite/LICENSE-APACHE new file mode 100644 index 00000000000..baef3fc1692 --- /dev/null +++ b/crates/aplite/LICENSE-APACHE @@ -0,0 +1,199 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to the Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by the Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding any notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. Please also get an OpenPGP + key ID of the copyright holder. + + Copyright 2025 tignear + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/crates/aplite/LICENSE-MIT b/crates/aplite/LICENSE-MIT new file mode 100644 index 00000000000..5172f04cc24 --- /dev/null +++ b/crates/aplite/LICENSE-MIT @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 tignear + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/crates/aplite/README.md b/crates/aplite/README.md new file mode 100644 index 00000000000..f57e41496bb --- /dev/null +++ b/crates/aplite/README.md @@ -0,0 +1,43 @@ +# Aplite + +A bounded, in-process constraint solver for quantifier-free Boolean, bit-vector +and finite-observation array expressions. Aplite is extracted from lydite's +finite solver, including its existing bit blasting, CDCL search, decomposition, +model replay and memory-expression normalization. + +```rust +use aplite::{Env, Limits, SearchHint, Sort, Verdict, bv, eq, solve_with_hint, var}; + +let x = var("x".into(), Sort::Bv(8)); +let formula = eq(x.clone(), bv(8, 7)); +let context = Env::from([("x".to_owned(), x)]); +let result = solve_with_hint(&formula, &context, Limits::default(), SearchHint::Sat); +assert_eq!(result.verdict, Verdict::Sat); +assert!(result.original_formula_validated); +assert_eq!(result.assignments["x"], aplite::Scalar::Bv { width: 8, value: 7 }); +``` + +`SearchHint` chooses search order; it is not an assumption. Unsupported terms, +invalid inputs detected by the solver, and exhausted budgets yield `Unknown`, +which must not be treated as `Unsat`. SAT assignments are evaluated against the +original query and requested context. UNSAT trusts the Rust implementation; +there is no independently checked UNSAT certificate. The expression constructors +are a low-level IR, not a SystemVerilog parser or a complete typed input validator. +The scalar backend uses words up to 64 bits; callers may encode wider values in +chunks. The solver does not sample models randomly or promise uniform sampling. + +The crate has no dependency on Celox, lydite, Z3, or an external executable. +Lydite retains its proof-obligation generation, proof orchestration, structural +kernel, external-Z3 route and frontend integration. Existing RV32I proof campaigns +exercise that complete pipeline; extracting its finite backend does not turn +those proofs into a standalone Aplite frontend feature. + +## Development and releases + +Aplite is a member of the Celox Cargo workspace, sharing the lockfile, build +cache and lint configuration. Its explicit package version, changelog and +`aplite-vX.Y.Z` tags are independent of Celox's versions. + +Run `cargo test --locked -p aplite` and the lydite consumer tests after changes. +The Lydite CI lane also tests Aplite directly. See [RELEASING.md](RELEASING.md) +for its independent release process. diff --git a/crates/aplite/RELEASING.md b/crates/aplite/RELEASING.md new file mode 100644 index 00000000000..deb590262be --- /dev/null +++ b/crates/aplite/RELEASING.md @@ -0,0 +1,37 @@ +# Releasing Aplite + +Aplite has its own package version and release-please configuration: +`release-please-aplite-config.json` and `.release-please-aplite-manifest.json` +at the repository root. Its version is not inherited from `workspace.package`. +The initially empty manifest lets the Rust release strategy start at 0.1.0. + +The Aplite Release Management workflow opens a separate release PR, updates +this crate's manifest and changelog plus only Aplite's entry in the shared +Cargo.lock, and creates `aplite-vX.Y.Z` tags and GitHub Releases after that PR +merges. Release PRs are reviewed and queued explicitly. Creating an Aplite +release dispatches `publish-aplite.yml` at that exact tag. The workflow checks +the version and published GitHub Release, runs Aplite tests and verifies its +standalone package, then publishes with a short-lived crates.io OIDC token. +The Celox publisher does not publish Aplite. Changes to both consumers and +Aplite can require both releases. + +Trusted Publishing requires an existing crate. The empty `aplite 0.0.0` +bootstrap reserves the name; the first implementation release remains 0.1.0. +Configure the crates.io Trusted Publisher for owner `celox-sim`, repository +`celox`, workflow `publish-aplite.yml`, and environment `crates-io`. That GitHub +environment must allow `aplite-v*` tags. No persistent registry token is needed. + +To retry a failed publication, dispatch the workflow at the reviewed release tag: + +```sh +gh workflow run publish-aplite.yml --repo celox-sim/celox --ref aplite-v0.1.0 +``` + +An already published version is skipped. Branch refs, mismatched versions, +draft releases and prereleases are rejected. Keep Aplite's release cadence +independent of Celox. + +The shared workspace remains the development environment. Changes to the solver +also run the lydite consumer tests and proof gates. The full RV32I acceptance +campaign requires the pinned frontend and release checker documented under +`lydite/docs/rv32i.md`; unit tests are not a replacement for that campaign. diff --git a/crates/aplite/clippy.toml b/crates/aplite/clippy.toml new file mode 100644 index 00000000000..6cb3d06a5d2 --- /dev/null +++ b/crates/aplite/clippy.toml @@ -0,0 +1,14 @@ +# Preserve the finite solver's existing randomized standard hash maps. +# Aplite accepts caller-owned expressions and does not inherit Celox's +# trusted-compiler-input FxHash policy. Library I/O and ownership rules remain. +disallowed-macros = [ + { path = "std::thread_local", reason = "production state must be owned and passed explicitly; only test-local instrumentation may opt out" }, + { path = "std::eprintln", reason = "library diagnostics must use tracing or a caller-provided writer" }, +] + +disallowed-methods = [ + { path = "std::env::var", reason = "read CELOX diagnostics through DiagnosticsOptions::from_env at the application boundary" }, + { path = "std::env::var_os", reason = "read CELOX diagnostics through DiagnosticsOptions::from_env at the application boundary" }, + { path = "std::env::vars", reason = "read CELOX diagnostics through DiagnosticsOptions::from_env at the application boundary" }, + { path = "std::env::vars_os", reason = "read CELOX diagnostics through DiagnosticsOptions::from_env at the application boundary" }, +] diff --git a/crates/lydite-solver/src/finite.rs b/crates/aplite/src/finite.rs similarity index 99% rename from crates/lydite-solver/src/finite.rs rename to crates/aplite/src/finite.rs index a9f4ca1c0f8..64cbdb72dfd 100644 --- a/crates/lydite-solver/src/finite.rs +++ b/crates/aplite/src/finite.rs @@ -5,7 +5,7 @@ //! requested context terms. Readonly arrays use exact finite-observation reduction //! and total sparse-array model replay. Unsupported terms or exhausted budgets yield Unknown. //! Diagnostics are not proof certificates: UNSAT trusts this Rust implementation. -use lydite_ir::{Env, Res, Sort, Term}; +use crate::{Env, Res, Sort, Term}; use serde_json::{Value, json}; use std::{ collections::{BTreeMap, HashMap, HashSet}, @@ -859,7 +859,7 @@ impl Blast { t.clone() } else { self.charge_guarded(b)?; - lydite_ir::node(t.0.sort.clone(), t.0.op.clone(), args) + crate::node(t.0.sort.clone(), t.0.op.clone(), args) }; memo.insert(t.clone(), value.clone()); Ok(value) @@ -928,7 +928,7 @@ impl Blast { } self.charge_guarded(b)?; self.guarded_rewrites += 1; - Ok(Some(lydite_ir::ite( + Ok(Some(crate::ite( t.0.args[0].clone(), yes, t.0.args[2].clone(), @@ -1685,14 +1685,13 @@ fn split_choices(formula: &Term, blast: &Blast, b: &mut Budget) -> Res> Ok(best) } -/// Compatibility entry point: use proof-oriented search, as in 0.11.2. -/// SAT is still returned and validated normally, even though the hint is UNSAT. /// Validate the entire original formula AND diagnostic context before any /// compositional projection can discard derived-context expressions. -pub(crate) fn validate_original_context(formula: &Term, context: &Env) -> Res<(usize, u64)> { +pub fn validate_original_context(formula: &Term, context: &Env) -> Res<(usize, u64)> { validate_original_context_with_limits(formula, context, Limits::default()) } -pub(crate) fn validate_original_context_with_limits( +/// Validate the complete input under an explicit budget; returns term and work counts. +pub fn validate_original_context_with_limits( formula: &Term, context: &Env, limits: Limits, @@ -2106,7 +2105,7 @@ fn solve_plain(formula: &Term, context: &Env, limits: Limits, search_hint: Searc #[cfg(test)] mod tests { use super::*; - use lydite_ir::{and, boolv, bv, eq, ite, node, not, var}; + use crate::{and, boolv, bv, eq, ite, node, not, var}; fn check(t: Term) -> Outcome { let proof = solve(&t, &Env::new(), Limits::default()); let witness = solve_with_hint(&t, &Env::new(), Limits::default(), SearchHint::Sat); diff --git a/crates/lydite-solver/src/finite/control.rs b/crates/aplite/src/finite/control.rs similarity index 99% rename from crates/lydite-solver/src/finite/control.rs rename to crates/aplite/src/finite/control.rs index 3b6b0703efd..cd969f07ac5 100644 --- a/crates/lydite-solver/src/finite/control.rs +++ b/crates/aplite/src/finite/control.rs @@ -2,7 +2,7 @@ //! A selected subset may be fixed; all remaining variables stay symbolic. //! All cases share the original limits; SAT is replayed on the ORIGINAL query. use super::*; -use lydite_ir::{boolv, bv, node, not}; +use crate::{boolv, bv, node, not}; pub(super) fn empty(hint: SearchHint) -> Outcome { Outcome { @@ -243,15 +243,15 @@ fn asserted_polarity(t: &Term, negative: bool, b: &mut Budget, depth: usize) -> let args = &t.0.args; let result = match operation(t)? { Op::Not => visit(&args[0], !negative, b, depth + 1, memo)?, - Op::And if !negative => lydite_ir::and( + Op::And if !negative => crate::and( visit(&args[0], false, b, depth + 1, memo)?, visit(&args[1], false, b, depth + 1, memo)?, ), - Op::Or if negative => lydite_ir::and( + Op::Or if negative => crate::and( visit(&args[0], true, b, depth + 1, memo)?, visit(&args[1], true, b, depth + 1, memo)?, ), - Op::Implies if negative => lydite_ir::and( + Op::Implies if negative => crate::and( visit(&args[0], false, b, depth + 1, memo)?, visit(&args[1], true, b, depth + 1, memo)?, ), @@ -649,7 +649,7 @@ pub(super) fn route( #[cfg(test)] mod tests { use super::*; - use lydite_ir::{and, eq, ite, var}; + use crate::{and, eq, ite, var}; fn or(x: Term, y: Term) -> Term { node(Sort::Bool, "or", vec![x, y]) } diff --git a/crates/lydite-solver/src/finite/guarded_tests.rs b/crates/aplite/src/finite/guarded_tests.rs similarity index 99% rename from crates/lydite-solver/src/finite/guarded_tests.rs rename to crates/aplite/src/finite/guarded_tests.rs index b90ffe6d597..6450d76f994 100644 --- a/crates/lydite-solver/src/finite/guarded_tests.rs +++ b/crates/aplite/src/finite/guarded_tests.rs @@ -1,5 +1,5 @@ use super::*; -use lydite_ir::{and, boolv, bv, eq, ite, node, not, var}; +use crate::{and, boolv, bv, eq, ite, node, not, var}; fn imp(a: Term, b: Term) -> Term { node(Sort::Bool, "=>", vec![a, b]) } diff --git a/crates/lydite-solver/src/finite/lookup.rs b/crates/aplite/src/finite/lookup.rs similarity index 99% rename from crates/lydite-solver/src/finite/lookup.rs rename to crates/aplite/src/finite/lookup.rs index da6ada0074f..e558dbe8af9 100644 --- a/crates/lydite-solver/src/finite/lookup.rs +++ b/crates/aplite/src/finite/lookup.rs @@ -1,6 +1,6 @@ //! Bounded exact distribution of constant-index word lookups over ITE addresses. use super::*; -use lydite_ir::{and, boolv, bv, eq, ite}; +use crate::{and, boolv, bv, eq, ite}; const MAX_ROWS: usize = 64; const MAX_CREATED_NODES: usize = 4096; @@ -79,7 +79,7 @@ impl Rewrite { t.clone() } else if self.room(1, b) { self.charge(1, b)?; - lydite_ir::node(t.0.sort.clone(), t.0.op.clone(), args) + crate::node(t.0.sort.clone(), t.0.op.clone(), args) } else { t.clone() }; @@ -114,7 +114,7 @@ impl Rewrite { self.word_rewrites += 1; n = ite( and( - lydite_ir::not(n.0.args[0].clone()), + crate::not(n.0.args[0].clone()), n.0.args[2].0.args[0].clone(), ), n.0.args[2].0.args[1].clone(), @@ -360,7 +360,7 @@ impl Rewrite { for key in &unchanged { enable = and( enable, - lydite_ir::not(eq(write_address.clone(), bv(width, *key))), + crate::not(eq(write_address.clone(), bv(width, *key))), ); } let result = ite( @@ -453,7 +453,7 @@ impl Rewrite { #[cfg(test)] mod tests { use super::*; - use lydite_ir::{and, boolv, bv, node, not, var}; + use crate::{and, boolv, bv, node, not, var}; fn budget() -> Budget { Budget { @@ -741,7 +741,7 @@ mod tests { #[cfg(test)] mod word_normalization_tests { use super::*; - use lydite_ir::{node, not, var}; + use crate::{node, not, var}; fn b() -> Budget { Budget { limits: Limits::default(), diff --git a/crates/lydite-solver/src/finite/readonly.rs b/crates/aplite/src/finite/readonly.rs similarity index 99% rename from crates/lydite-solver/src/finite/readonly.rs rename to crates/aplite/src/finite/readonly.rs index baf1db82b7c..74276376c11 100644 --- a/crates/lydite-solver/src/finite/readonly.rs +++ b/crates/aplite/src/finite/readonly.rs @@ -8,7 +8,7 @@ //! default then extends every positive equality and preserves every negative equality. This is not a //! certificate; both reduction and independent original-array replay are trusted. use super::*; -use lydite_ir::{and, boolv, eq, ite, node, not, var}; +use crate::{and, boolv, eq, ite, node, not, var}; #[derive(Clone, Debug, PartialEq, Eq)] pub struct ArrayModel { @@ -435,8 +435,7 @@ pub(super) fn solve(formula: &Term, context: &Env, limits: Limits, hint: SearchH if x == y { r.charge(&mut b)?; r.charge(&mut b)?; - r.equality - .insert(t.clone(), (boolv(true), lydite_ir::bv(1, 0))); + r.equality.insert(t.clone(), (boolv(true), crate::bv(1, 0))); continue; } active_equalities.push(t.clone()); @@ -750,7 +749,7 @@ pub(super) fn strengthen(formula: &Term, b: &mut Budget) -> Res { #[cfg(test)] mod tests { use super::*; - use lydite_ir::bv; + use crate::bv; fn mem(n: &str) -> Term { var(n.into(), Sort::Mem(1, 1)) } diff --git a/crates/aplite/src/lib.rs b/crates/aplite/src/lib.rs new file mode 100644 index 00000000000..96c058485f9 --- /dev/null +++ b/crates/aplite/src/lib.rs @@ -0,0 +1,12 @@ +#![doc = include_str!("../README.md")] +//! Aplite: bounded finite Boolean, bit-vector and array constraint solving. +//! +//! The solver runs in process, without an external SMT executable. Unsupported +//! expressions and exhausted resource budgets return [`Verdict::Unknown`]. +//! SAT models are replayed against the original formula; UNSAT trusts the solver. +//! This crate does not provide random sampling of satisfying assignments. +pub mod term; +pub use term::*; +pub type Env = std::collections::BTreeMap; +pub mod finite; +pub use finite::{Limits, Outcome, Scalar, SearchHint, Verdict, solve, solve_with_hint}; diff --git a/crates/lydite-ir/src/term.rs b/crates/aplite/src/term.rs similarity index 100% rename from crates/lydite-ir/src/term.rs rename to crates/aplite/src/term.rs diff --git a/crates/lydite-ir/Cargo.toml b/crates/lydite-ir/Cargo.toml index 20a5cf035a1..bd76c657b60 100644 --- a/crates/lydite-ir/Cargo.toml +++ b/crates/lydite-ir/Cargo.toml @@ -6,6 +6,7 @@ license.workspace = true publish = false [dependencies] +aplite.workspace = true serde_json.workspace = true [lints] diff --git a/crates/lydite-ir/src/lib.rs b/crates/lydite-ir/src/lib.rs index b18a8b1f1c5..eaf6a5aad5a 100644 --- a/crates/lydite-ir/src/lib.rs +++ b/crates/lydite-ir/src/lib.rs @@ -5,10 +5,9 @@ mod specification; pub use scoped_specification::*; pub use specification::*; pub mod lower; -mod term; +pub use aplite::term::*; pub use design::*; pub use lower::*; -pub use term::*; #[cfg(test)] mod validation_tests; diff --git a/crates/lydite-ir/src/lower.rs b/crates/lydite-ir/src/lower.rs index b431b9ae254..25ee2406f37 100644 --- a/crates/lydite-ir/src/lower.rs +++ b/crates/lydite-ir/src/lower.rs @@ -54,7 +54,7 @@ pub fn named(v: &Value) -> Res<&serde_json::Map> { } Ok(o) } -pub type Env = BTreeMap; +pub use aplite::Env; #[derive(Default)] pub struct Lower { pub rules: BTreeMap, diff --git a/crates/lydite-solver/Cargo.toml b/crates/lydite-solver/Cargo.toml index b32c57b549c..3a1023c6914 100644 --- a/crates/lydite-solver/Cargo.toml +++ b/crates/lydite-solver/Cargo.toml @@ -6,6 +6,7 @@ license.workspace = true publish = false [dependencies] +aplite.workspace = true serde_json.workspace = true lydite-ir.workspace = true diff --git a/crates/lydite-solver/src/lib.rs b/crates/lydite-solver/src/lib.rs index 29137d25a75..97471bf5001 100644 --- a/crates/lydite-solver/src/lib.rs +++ b/crates/lydite-solver/src/lib.rs @@ -1,5 +1,5 @@ //! Structural UNSAT, partition planning and SMT/Z3. No parser dependency. -pub mod finite; +pub use aplite::finite; pub mod kernel; pub mod partition; mod z3; diff --git a/lydite/README.md b/lydite/README.md index 21b8fd45ac6..947db1225f4 100644 --- a/lydite/README.md +++ b/lydite/README.md @@ -43,3 +43,7 @@ LYDITE_SOLVER=finite ../target/release/lydite audit/lemma_candidates/counter.lyd The Rust translation, obligation generation, kernel and selected solver are trusted; see the [trust boundary](docs/trust.md). Current results come from [CI](../.github/workflows/lydite-checks.yml), not archived reports. + +The in-process finite backend is [Aplite](../crates/aplite/README.md), a separately +versioned workspace crate. Lydite retains proof construction and orchestration; +its existing `lydite_solver::finite` API re-exports the Aplite implementation. diff --git a/lydite/audit/veryl_scaling/profile_solver.py b/lydite/audit/veryl_scaling/profile_solver.py index 30bc7fff980..c25db89b95c 100644 --- a/lydite/audit/veryl_scaling/profile_solver.py +++ b/lydite/audit/veryl_scaling/profile_solver.py @@ -12,7 +12,7 @@ else: for name in ('Cargo.toml','Cargo.lock','clippy.toml'):shutil.copy2(REPO/name,a.out/name) for name in WORKSPACE:shutil.copytree(REPO/name,a.out/name,ignore=shutil.ignore_patterns('node_modules','target')) -f=a.out/'crates/lydite-solver/src/finite.rs';s=f.read_text() +f=a.out/'crates/aplite/src/finite.rs';s=f.read_text() s=s.replace('pub struct Stats {','pub struct Stats {\n pub encoding_seconds: f64,\n pub search_seconds: f64,\n pub validation_seconds: f64,\n pub encoding_work: u64,') s=s.replace('"solver_result":self.verdict.as_str(),','"encoding_seconds":self.stats.encoding_seconds,"search_seconds":self.stats.search_seconds,"validation_seconds":self.stats.validation_seconds,"encoding_work":self.stats.encoding_work,"timing_scope":"encoding=aliases+bitblast+context; search=split planning+CNF copies+CDCL; validation=SAT witness checks", "solver_result":self.verdict.as_str(),') s=s.replace(' let compile = (|| -> Res<()> {',' let encoding_started = Instant::now();\n let compile = (|| -> Res<()> {') @@ -22,6 +22,6 @@ s=s.replace(' // Validate every original CNF clause', ' validation_started = Some(Instant::now());\n // Validate every original CNF clause') s=s.replace(' outcome.stats.clauses = cumulative_clauses;', ' if !search_finished { outcome.stats.search_seconds = search_started.elapsed().as_secs_f64(); }\n if let Some(started) = validation_started { outcome.stats.validation_seconds = started.elapsed().as_secs_f64(); }\n outcome.stats.clauses = cumulative_clauses;') f.write_text(s) -(a.out/'instrumentation.patch').write_text(subprocess.run(['diff','-u',str(REPO/'crates/lydite-solver/src/finite.rs'),str(f)],capture_output=True,text=True).stdout) +(a.out/'instrumentation.patch').write_text(subprocess.run(['diff','-u',str(REPO/'crates/aplite/src/finite.rs'),str(f)],capture_output=True,text=True).stdout) subprocess.run(['cargo','build','--release','--locked','-p','lydite','--manifest-path',str(a.out/'Cargo.toml')],check=True) print(a.out/'../target/release/lydite') diff --git a/lydite/audit/veryl_scaling/rv32i_selected_ci.py b/lydite/audit/veryl_scaling/rv32i_selected_ci.py index 34e6e8fae86..8d6477155d4 100644 --- a/lydite/audit/veryl_scaling/rv32i_selected_ci.py +++ b/lydite/audit/veryl_scaling/rv32i_selected_ci.py @@ -25,7 +25,7 @@ def write(path, value): def capture_provenance(out, checker): root = selected.ROOT - scope = ['../Cargo.toml', '../Cargo.lock', '../crates/lydite-ir', '../crates/lydite', '../crates/lydite-celox', '../crates/lydite-solver', '../crates/lydite-syntax', '../crates/lydite-verify', + scope = ['../Cargo.toml', '../Cargo.lock', '../crates/aplite', '../crates/lydite-ir', '../crates/lydite', '../crates/lydite-celox', '../crates/lydite-solver', '../crates/lydite-syntax', '../crates/lydite-verify', 'audit/veryl_scaling', 'audit/lemma_candidates', 'conformance/veryl-symbolic', '../.github/workflows/lydite-checks.yml', 'examples/build_pipeline.py', 'examples/build_branch_pipeline.py', diff --git a/lydite/conformance/veryl-symbolic/run_ci.sh b/lydite/conformance/veryl-symbolic/run_ci.sh index 3d99023f445..b9826332c6c 100755 --- a/lydite/conformance/veryl-symbolic/run_ci.sh +++ b/lydite/conformance/veryl-symbolic/run_ci.sh @@ -23,7 +23,7 @@ FRONTEND="$REPO/../target/debug/lydite-celox-export" test -x "$FRONTEND" cp conformance/veryl-proof/work/provenance.json "$OUT/frontend-provenance.json" cargo build --release --locked -p lydite -p lydite-celox -cargo fmt --check -p lydite-ir -p lydite -p lydite-celox -p lydite-solver -p lydite-syntax -p lydite-verify +cargo fmt --check -p aplite -p lydite-ir -p lydite -p lydite-celox -p lydite-solver -p lydite-syntax -p lydite-verify python3 - "$OUT" "$REPO" "$FRONTEND" <<'PYHASH' import hashlib, json, pathlib, subprocess, sys out, root, frontend = map(pathlib.Path, sys.argv[1:]) @@ -31,7 +31,7 @@ out, root, frontend = map(pathlib.Path, sys.argv[1:]) repo = root.parent files = [repo/'Cargo.toml', repo/'Cargo.lock', frontend, root/'../target/release/lydite', root/'../target/release/lydite-celox-lift'] -for directory in ('crates/lydite-ir', 'crates/lydite-solver', 'crates/lydite-verify', 'crates/lydite-syntax', +for directory in ('crates/aplite', 'crates/lydite-ir', 'crates/lydite-solver', 'crates/lydite-verify', 'crates/lydite-syntax', 'crates/lydite', 'crates/lydite-celox', 'lydite/conformance/veryl-symbolic'): files.extend(p for p in (repo/directory).rglob('*') if p.is_file() and '__pycache__' not in p.parts and p.suffix != '.pyc') @@ -46,7 +46,7 @@ cp conformance/veryl-proof/tools/z3-tripwire.sh "$OUT/tripwire-bin/z3" export PATH="$OUT/tripwire-bin:$PATH" export Z3_BIN="$OUT/tripwire-bin/z3" export LYDITE_SOLVER=finite -cargo test --release --locked -p lydite-celox -p lydite-solver +cargo test --release --locked -p lydite-celox -p lydite-solver -p aplite python3 -m unittest discover -s "$HERE/tests" -v python3 "$HERE/run.py" --out "$OUT/cases" --frontend "$FRONTEND" --lifter "$REPO/../target/release/lydite-celox-lift" python3 "$REPO/audit/veryl_scaling/measure.py" --out "$OUT/scaling-regression" --sizes 16 32 64 --require-success diff --git a/lydite/proof/README.md b/lydite/proof/README.md index b106f31f4cd..2c1627026df 100644 --- a/lydite/proof/README.md +++ b/lydite/proof/README.md @@ -1,6 +1,6 @@ # Correctness of memory simplification -The target is `memory_read` / `memory_write` in `crates/lydite-ir/src/term.rs`. Only Lean 4.34.1 + Std are used. +The target is `memory_read` / `memory_write` in `crates/aplite/src/term.rs`. Only Lean 4.34.1 + Std are used. ## What is proved @@ -32,7 +32,7 @@ Rust has string ops, Vec arguments and runtime Sorts. That inputs are well-forme ## Cross-checking the implementation and negative examples -`check_rust_rules.rs` directly imports the real `../../crates/lydite-ir/src/term.rs` and compares it against an independent evaluator that does not use Z3. +`check_rust_rules.rs` directly imports the real `../../crates/aplite/src/term.rs` and compares it against an independent evaluator that does not use Z3. - All 256 memories with 2-bit addresses and 2-bit words - All 64 assignments of 3 address variables, including actual-address collisions under identical and different syntax diff --git a/lydite/proof/check_rust_rules.rs b/lydite/proof/check_rust_rules.rs index 4ff7f692f02..d87dd5b9737 100644 --- a/lydite/proof/check_rust_rules.rs +++ b/lydite/proof/check_rust_rules.rs @@ -1,6 +1,6 @@ //! Differential check against independent concrete semantics, using actual ir.rs. #![allow(dead_code)] -#[path = "../../crates/lydite-ir/src/term.rs"] +#[path = "../../crates/aplite/src/term.rs"] mod ir; use ir::*; use std::collections::BTreeMap; diff --git a/lydite/proof/recheck.py b/lydite/proof/recheck.py index 988568af8e5..90751aa33a5 100644 --- a/lydite/proof/recheck.py +++ b/lydite/proof/recheck.py @@ -30,7 +30,7 @@ def run(name, command, expected=0): return p lean_source = (HERE / 'MemoryRules.lean').read_text() -TERM_RS = ROOT.parent / 'crates/lydite-ir/src/term.rs' +TERM_RS = ROOT.parent / 'crates/aplite/src/term.rs' rust_source = TERM_RS.read_text() with tempfile.TemporaryDirectory(prefix='lydite-memory-proof-') as td: td = Path(td) @@ -48,7 +48,7 @@ def run(name, command, expected=0): p = run('reject_lean_' + label, [args.lean, str(f)], expected=1) assert 'unsolved goals' in p.stdout or 'error:' in p.stdout # Mirror the repository layout so check_rust_rules.rs's #[path] resolves. - (td / 'crates/lydite-ir/src').mkdir(parents=True) + (td / 'crates/aplite/src').mkdir(parents=True) (td / 'lydite/proof').mkdir(parents=True) shutil.copyfile(HERE / 'check_rust_rules.rs', td / 'lydite/proof/check_rust_rules.rs') for label, source in [ @@ -58,7 +58,7 @@ def run(name, command, expected=0): ]: if label != 'actual': assert source != rust_source, 'Rust shape changed: update mutation deliberately' - (td / 'crates/lydite-ir/src/term.rs').write_text(source) + (td / 'crates/aplite/src/term.rs').write_text(source) binary = td / ('check_' + label) run('compile_rust_' + label, [args.rustc, '--edition=2021', '-O', str(td / 'lydite/proof/check_rust_rules.rs'), '-o', str(binary)]) p = run('rust_' + label, [str(binary)], expected=0 if label == 'actual' else 1) diff --git a/release-please-aplite-config.json b/release-please-aplite-config.json new file mode 100644 index 00000000000..4f39cfc67dd --- /dev/null +++ b/release-please-aplite-config.json @@ -0,0 +1,21 @@ +{ + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", + "bootstrap-sha": "08af331166889f70f738a651810f99df619054eb", + "separate-pull-requests": true, + "packages": { + "crates/aplite": { + "release-type": "rust", + "component": "aplite", + "package-name": "aplite", + "include-component-in-tag": true, + "bump-minor-pre-major": true, + "extra-files": [ + { + "type": "toml", + "path": "Cargo.lock", + "jsonpath": "$.package[?(@.name.value == \"aplite\")].version" + } + ] + } + } +} diff --git a/release-please-config.json b/release-please-config.json index 6ce1a1774b4..9f3ce4ac321 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -36,6 +36,15 @@ "path": "crates/celox-napi/package.json", "jsonpath": "$.version" } + ], + "exclude-paths": [ + "crates/aplite", + ".release-please-aplite-manifest.json", + "release-please-aplite-config.json", + ".github/workflows/release-aplite.yml", + ".github/workflows/publish-aplite.yml", + "scripts/publish-aplite.mjs", + "scripts/publish-aplite.test.mjs" ] } } diff --git a/scripts/check-aplite-release.mjs b/scripts/check-aplite-release.mjs new file mode 100644 index 00000000000..6665d546372 --- /dev/null +++ b/scripts/check-aplite-release.mjs @@ -0,0 +1,30 @@ +import { readFileSync } from "node:fs"; +import { resolve } from "node:path"; +import { pathToFileURL } from "node:url"; + +export function checkApliteRelease(root = ".") { + const read = (path) => readFileSync(resolve(root, path), "utf8"); + const manifest = read("crates/aplite/Cargo.toml"); + const version = /^version = "([^"]+)"$/m.exec(manifest)?.[1]; + if (!/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(version ?? "")) { + throw new Error("Aplite must have an explicit stable SemVer version"); + } + const releases = JSON.parse(read(".release-please-aplite-manifest.json")); + if (Object.keys(releases).some((key) => key !== "crates/aplite")) { + throw new Error("Aplite release manifest contains another component"); + } + // An empty manifest bootstraps the first Rust release at 0.1.0. + if ((releases["crates/aplite"] ?? "0.1.0") !== version) { + throw new Error("Aplite release manifest and package version disagree"); + } + const entries = read("Cargo.lock").split("[[package]]").slice(1); + const locked = entries.filter((entry) => /^name = "aplite"$/m.test(entry)); + if (locked.length !== 1 || /^version = "([^"]+)"$/m.exec(locked[0])?.[1] !== version) { + throw new Error("Cargo.lock must contain exactly the current Aplite version"); + } + return version; +} + +if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) { + console.log(`Validated independent Aplite version ${checkApliteRelease()}`); +} diff --git a/scripts/check-aplite-release.test.mjs b/scripts/check-aplite-release.test.mjs new file mode 100644 index 00000000000..5dd4cdccaa0 --- /dev/null +++ b/scripts/check-aplite-release.test.mjs @@ -0,0 +1,45 @@ +import assert from "node:assert/strict"; +import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import test from "node:test"; +import { checkApliteRelease } from "./check-aplite-release.mjs"; + +function fixture(t, { version = "0.1.0", recorded = {}, locked = version } = {}) { + const root = mkdtempSync(join(tmpdir(), "aplite-version-")); + t.after(() => rmSync(root, { recursive: true, force: true })); + mkdirSync(join(root, "crates/aplite"), { recursive: true }); + writeFileSync(join(root, "crates/aplite/Cargo.toml"), `[package]\nname = "aplite"\nversion = "${version}"\n`); + writeFileSync(join(root, ".release-please-aplite-manifest.json"), JSON.stringify(recorded)); + writeFileSync(join(root, "Cargo.lock"), `[[package]]\nname = "aplite"\nversion = "${locked}"\n\n[[package]]\nname = "celox"\nversion = "99.8.7"\n`); + return root; +} + +test("Aplite bootstrap is independent of the Celox version", (t) => { + assert.equal(checkApliteRelease(fixture(t)), "0.1.0"); +}); +test("Aplite releases follow their own version and manifest", (t) => { + assert.equal(checkApliteRelease(fixture(t, { version: "0.2.0", recorded: { "crates/aplite": "0.2.0" } })), "0.2.0"); +}); +test("reject stale lockfile and release manifest versions", (t) => { + assert.throws(() => checkApliteRelease(fixture(t, { locked: "0.0.9" })), /Cargo.lock/); + assert.throws(() => checkApliteRelease(fixture(t, { recorded: { "crates/aplite": "0.2.0" } })), /disagree/); + assert.throws(() => checkApliteRelease(fixture(t, { recorded: { ".": "0.1.0" } })), /another component/); +}); +test("release configurations separate tags, paths and lockfile updates", () => { + const read = (path) => readFileSync(new URL(`../${path}`, import.meta.url), "utf8"); + const aplite = JSON.parse(read("release-please-aplite-config.json")); + const celox = JSON.parse(read("release-please-config.json")); + assert.deepEqual(Object.keys(aplite.packages), ["crates/aplite"]); + const pkg = aplite.packages["crates/aplite"]; + assert.equal(pkg.component, "aplite"); + assert.equal(pkg["release-type"], "rust"); + assert.equal(pkg["include-component-in-tag"], true); + assert.deepEqual(pkg["extra-files"], [{ type: "toml", path: "Cargo.lock", jsonpath: '$.package[?(@.name.value == "aplite")].version' }]); + assert.ok(celox.packages["."]["exclude-paths"].includes("crates/aplite")); + const workflow = read(".github/workflows/release-aplite.yml"); + assert.match(workflow, /manifest-file: \.release-please-aplite-manifest.json/); + assert.match(workflow, /config-file: release-please-aplite-config.json/); + assert.match(workflow, /release-please--branches--master--components--aplite/); + assert.doesNotMatch(workflow, /cargo publish|publish-crates.yml|napi-release/); +}); diff --git a/scripts/ci-changes.mjs b/scripts/ci-changes.mjs index a97b9d17302..3e343ee2a67 100644 --- a/scripts/ci-changes.mjs +++ b/scripts/ci-changes.mjs @@ -42,6 +42,7 @@ const RELEASE_PLEASE_FILES = new Set([ // dependencies of celox-napi. ci-changes.test.mjs checks the workspace graph // so adding a dependency cannot silently make this exclusion unsafe. const RUST_ONLY_CRATES = new Set([ + "aplite", "celox-test-suite", "celox-bench", "celox-bench-sv", @@ -308,8 +309,8 @@ if ( // Lydite core tests run independently; bridge CI is disabled. export function celoxRustTestScope(files, packages) { return rustTestScope( - files.filter((path) => !/^(?:\.\/)?(?:lydite\/|crates\/lydite(?:-|\/))/.test(path)), - packages.filter((pkg) => !/^lydite(?:-|$)/.test(pkg.name)), + files.filter((path) => !/^(?:\.\/)?(?:lydite\/|crates\/(?:lydite(?:-|\/)|aplite\/))/.test(path)), + packages.filter((pkg) => !/^(?:lydite(?:-|$)|aplite$)/.test(pkg.name)), ); } diff --git a/scripts/ci-changes.test.mjs b/scripts/ci-changes.test.mjs index 7d2b80e76b2..42b42f7e884 100644 --- a/scripts/ci-changes.test.mjs +++ b/scripts/ci-changes.test.mjs @@ -56,6 +56,7 @@ test("Rust test infrastructure skips bindings while retaining Rust checks", () = "crates/celox-bench-sv/src/main.rs", "crates/celox-vpi/src/lib.rs", "crates/celox-wasm/src/lib.rs", + "crates/aplite/src/lib.rs", "crates/lydite/src/lib.rs", "crates/lydite-ir/src/lib.rs", "crates/lydite-solver/src/lib.rs", diff --git a/scripts/ci-lydite-changes.mjs b/scripts/ci-lydite-changes.mjs index bc870e24ac2..ac65960fb12 100644 --- a/scripts/ci-lydite-changes.mjs +++ b/scripts/ci-lydite-changes.mjs @@ -58,7 +58,7 @@ export function lyditeScope(files, packages, lock = null) { return seen; }; const coreRoots = packages - .filter((p) => isLydite(p.name) && p.name !== "lydite-celox") + .filter((p) => p.name === "aplite" || (isLydite(p.name) && p.name !== "lydite-celox")) .map((p) => p.name); const core = closure(coreRoots); const result = { core: false }; @@ -94,6 +94,7 @@ export function lyditeScope(files, packages, lock = null) { ".cargo/", ".github/actions/setup-rust/", "scripts/ci-lydite-changes.", + "scripts/check-aplite-release.", "scripts/ci-rust-scope.", "scripts/ci-changes.", ].some((prefix) => path.startsWith(prefix)) @@ -104,7 +105,7 @@ export function lyditeScope(files, packages, lock = null) { const inner = path.slice(owner.dir.length + 1); // Consumer tests do not depend on an upstream crate's private tests/docs. if ( - !isLydite(owner.name) && + owner.name !== "aplite" && !isLydite(owner.name) && (/^(tests|benches|examples)\//.test(inner) || inner.endsWith(".md")) ) continue; diff --git a/scripts/ci-lydite-changes.test.mjs b/scripts/ci-lydite-changes.test.mjs index fac8fdc01e6..2a31c7d37f1 100644 --- a/scripts/ci-lydite-changes.test.mjs +++ b/scripts/ci-lydite-changes.test.mjs @@ -21,6 +21,10 @@ test("Lydite core changes and shared configuration run core checks", () => { for (const path of [ "crates/lydite/src/main.rs", "crates/lydite-ir/src/lib.rs", + "crates/aplite/src/finite.rs", + "crates/aplite/README.md", + "crates/aplite/tests/model.rs", + "scripts/check-aplite-release.mjs", "lydite/editor/server.py", "Cargo.lock", "Cargo.toml", @@ -307,3 +311,10 @@ test("normal CI and standalone core conformance never build the bridge", () => { assert.doesNotMatch(coreGate, /lydite-celox/); assert.match(coreGate, /-p lydite-ir -p lydite -p lydite-solver -p lydite-syntax -p lydite-verify/); }); + +// The extracted solver is tested directly as well as through its proof consumers. +test("Aplite runs its own tests in the Lydite lane", () => { + const workflow = readFileSync(new URL("../.github/workflows/lydite-checks.yml", import.meta.url), "utf8"); + assert.match(workflow, /cargo test --locked .* -p aplite/); + assert.deepEqual(celoxRustTestScope(["crates/aplite/src/finite.rs"], packages).packages ?? [], []); +}); diff --git a/scripts/publish-aplite.mjs b/scripts/publish-aplite.mjs new file mode 100644 index 00000000000..1f797a94979 --- /dev/null +++ b/scripts/publish-aplite.mjs @@ -0,0 +1,48 @@ +import { execFileSync } from "node:child_process"; +import { resolve } from "node:path"; +import { pathToFileURL } from "node:url"; +import { checkApliteRelease } from "./check-aplite-release.mjs"; + +export function validateRelease(version, env, release) { + const tag = `aplite-v${version}`; + if (env.GITHUB_REF_TYPE !== "tag" || env.RELEASE_TAG !== tag) { + throw new Error(`Run from the matching stable release tag ${tag}`); + } + if (release.tagName !== tag || release.isDraft !== false || release.isPrerelease !== false) { + throw new Error(`Published stable GitHub Release ${tag} was not found`); + } +} + +export async function registryExists(path, request = fetch) { + const response = await request(`https://crates.io/api/v1/crates/${path}`, { + headers: { "User-Agent": "aplite-release (https://github.com/celox-sim/celox)" }, + signal: AbortSignal.timeout(30000), + }); + if (response.status === 200) return true; + if (response.status === 404) return false; + throw new Error(`crates.io lookup failed (HTTP ${response.status})`); +} + +async function main() { + const mode = process.argv[2]; + if (!["validate", "publish"].includes(mode)) throw new Error("Usage: publish-aplite.mjs validate|publish"); + const version = checkApliteRelease(); + const env = process.env; + // Reject branch executions before querying GitHub or requesting publication. + validateRelease(version, env, { tagName: `aplite-v${version}`, isDraft: false, isPrerelease: false }); + const release = JSON.parse(execFileSync("gh", ["release", "view", env.RELEASE_TAG, + "--repo", env.GITHUB_REPOSITORY, "--json", "tagName,isDraft,isPrerelease"], { encoding: "utf8" })); + validateRelease(version, env, release); + if (!await registryExists("aplite")) throw new Error("Bootstrap aplite on crates.io before Trusted Publishing"); + if (mode === "validate") return; + if (await registryExists(`aplite/${version}`)) { + console.log(`aplite@${version} already published; skipping`); + return; + } + if (!env.CARGO_REGISTRY_TOKEN) throw new Error("Missing crates.io OIDC token"); + execFileSync("cargo", ["publish", "--locked", "-p", "aplite"], { stdio: "inherit" }); +} + +if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) { + main().catch((error) => { console.error(error.message); process.exitCode = 1; }); +} diff --git a/scripts/publish-aplite.test.mjs b/scripts/publish-aplite.test.mjs new file mode 100644 index 00000000000..e6918cc9071 --- /dev/null +++ b/scripts/publish-aplite.test.mjs @@ -0,0 +1,63 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { registryExists, validateRelease } from "./publish-aplite.mjs"; + +const env = { GITHUB_REF_TYPE: "tag", RELEASE_TAG: "aplite-v0.1.0" }; +const release = { tagName: "aplite-v0.1.0", isDraft: false, isPrerelease: false }; + +test("accepts the matching independent stable release", () => { + assert.doesNotThrow(() => validateRelease("0.1.0", env, release)); +}); + +test("rejects branches, Celox tags, wrong versions and prerelease tags", () => { + for (const invalid of [ + { ...env, GITHUB_REF_TYPE: "branch" }, + { ...env, RELEASE_TAG: "v0.1.0" }, + { ...env, RELEASE_TAG: "aplite-v0.2.0" }, + { ...env, RELEASE_TAG: "aplite-v0.1.0-rc.1" }, + ]) assert.throws(() => validateRelease("0.1.0", invalid, release)); +}); + +test("rejects missing, mismatched, draft and prerelease GitHub releases", () => { + for (const invalid of [{}, { ...release, tagName: "v0.1.0" }, + { ...release, isDraft: true }, { ...release, isPrerelease: true }]) { + assert.throws(() => validateRelease("0.1.0", env, invalid)); + } +}); + +test("only HTTP 404 means an absent registry version", async () => { + assert.equal(await registryExists("aplite/0.1.0", async () => ({ status: 200 })), true); + assert.equal(await registryExists("aplite/0.1.0", async () => ({ status: 404 })), false); + for (const status of [401, 403, 429, 500, 503]) { + await assert.rejects(registryExists("aplite/0.1.0", async () => ({ status })), /lookup failed/); + } + await assert.rejects(registryExists("aplite", async () => { throw new Error("network"); }), /network/); +}); + +test("release dispatch uses the Aplite component output and exact tag", async (t) => { + const { readFileSync, mkdtempSync, writeFileSync, rmSync } = await import("node:fs"); + const { tmpdir } = await import("node:os"); + const { join } = await import("node:path"); + const { spawnSync } = await import("node:child_process"); + const workflow = readFileSync(new URL("../.github/workflows/release-aplite.yml", import.meta.url), "utf8"); + const step = workflow.split(" - name: Queue Aplite publication\n")[1]; + assert.match(step, /if: steps.release.outputs\['crates\/aplite--release_created'\] == 'true'/); + assert.match(step, /RELEASE_TAG: \$\{\{ steps.release.outputs\['crates\/aplite--tag_name'\] \}\}/); + const script = step.split(" run: |\n")[1].replace(/^ /gm, ""); + const dir = mkdtempSync(join(tmpdir(), "aplite-dispatch-")); + t.after(() => rmSync(dir, { recursive: true, force: true })); + writeFileSync(join(dir, "gh"), '#!/bin/sh\nprintf "%s\\n" "$@"\n', { mode: 0o755 }); + for (const tag of ["aplite-v0.1.0", "v0.1.0", "master", "aplite-v0.1.0-rc.1", ""]) { + const result = spawnSync("bash", ["-e", "-o", "pipefail", "-c", script], { + encoding: "utf8", env: { ...process.env, PATH: `${dir}:${process.env.PATH}`, + RELEASE_TAG: tag, GITHUB_REPOSITORY: "celox-sim/celox" }, + }); + if (tag === "aplite-v0.1.0") { + assert.equal(result.status, 0, result.stderr); + assert.equal(result.stdout, "workflow\nrun\npublish-aplite.yml\n--repo\ncelox-sim/celox\n--ref\naplite-v0.1.0\n"); + } else { + assert.notEqual(result.status, 0); + assert.equal(result.stdout, ""); + } + } +}); diff --git a/scripts/publish-crates.test.mjs b/scripts/publish-crates.test.mjs index 6fc87b97d81..9e8025385eb 100644 --- a/scripts/publish-crates.test.mjs +++ b/scripts/publish-crates.test.mjs @@ -116,7 +116,7 @@ test("publication order includes every public crate after its workspace dependen const publicPackages = metadata.packages.filter( (pkg) => pkg.publish === null || pkg.publish.includes("crates-io"), ); - assert.deepEqual([...order].sort(), publicPackages.map((pkg) => pkg.name).sort()); + assert.deepEqual([...order, "aplite"].sort(), publicPackages.map((pkg) => pkg.name).sort()); for (const [index, name] of order.entries()) { for (const dependency of packages.get(name).dependencies) { if (!dependency.path) continue;