mirror of
https://github.com/Z3Prover/z3
synced 2026-04-07 05:02:48 +00:00
fstar: add extract.sh script and fstar-extract.yml GHA workflow for Meta-F* extraction
Agent-Logs-Url: https://github.com/Z3Prover/z3/sessions/680146e3-e241-487e-a0d7-a7e23b5f1634 Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
This commit is contained in:
parent
da40b270a1
commit
e5acaf0c28
3 changed files with 159 additions and 6 deletions
93
.github/workflows/fstar-extract.yml
vendored
Normal file
93
.github/workflows/fstar-extract.yml
vendored
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
name: "F* Meta Extraction"
|
||||
|
||||
# Run the Meta-F* reflection-based extraction that generates C++ rewrite rules
|
||||
# from the F* lemmas in fstar/FPARewriterRules.fst.
|
||||
#
|
||||
# The extraction is performed by fstar/RewriteCodeGen.fst which uses
|
||||
# FStar.Tactics.V2 and FStar.Reflection.V2 to inspect the lemma types
|
||||
# and emit C++ if-blocks that implement the corresponding rewrite rules.
|
||||
#
|
||||
# The generated C++ is printed to the job log and uploaded as an artifact.
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- "fstar/**.fst"
|
||||
- "fstar/extract.sh"
|
||||
- ".github/workflows/fstar-extract.yml"
|
||||
pull_request:
|
||||
paths:
|
||||
- "fstar/**.fst"
|
||||
- "fstar/extract.sh"
|
||||
- ".github/workflows/fstar-extract.yml"
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
fstar-extract:
|
||||
name: "Meta-F* rewrite rule extraction"
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v6.0.2
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
# Install F*
|
||||
#
|
||||
# We download the pre-built Linux binary from the F* GitHub releases.
|
||||
# The version is pinned to match what the README recommends.
|
||||
# If the pinned release is unavailable the step fails clearly.
|
||||
# -----------------------------------------------------------------------
|
||||
- name: Install F*
|
||||
env:
|
||||
FSTAR_VERSION: "2024.09.05"
|
||||
run: |
|
||||
ARCHIVE="fstar_v${FSTAR_VERSION}_Linux_x86_64.tar.gz"
|
||||
URL="https://github.com/FStarLang/FStar/releases/download/v${FSTAR_VERSION}/${ARCHIVE}"
|
||||
echo "Downloading F* ${FSTAR_VERSION} from ${URL}" >&2
|
||||
curl -fsSL -o "/tmp/${ARCHIVE}" "${URL}"
|
||||
mkdir -p "$HOME/fstar"
|
||||
tar -xzf "/tmp/${ARCHIVE}" -C "$HOME/fstar" --strip-components=1
|
||||
echo "$HOME/fstar/bin" >> "$GITHUB_PATH"
|
||||
|
||||
- name: Verify F* installation
|
||||
run: fstar.exe --version
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
# Run the Meta-F* extraction
|
||||
#
|
||||
# RewriteCodeGen.fst contains run_tactic calls that print generated C++
|
||||
# to stdout during typechecking. We capture that output, show it in the
|
||||
# log, and upload it as an artifact for inspection.
|
||||
# -----------------------------------------------------------------------
|
||||
- name: Extract C++ rewrite rules via Meta-F*
|
||||
working-directory: fstar
|
||||
run: |
|
||||
chmod +x extract.sh
|
||||
echo "--- generated C++ rules ---"
|
||||
./extract.sh | tee extracted_rules.txt
|
||||
echo "--- end of generated rules ---"
|
||||
|
||||
- name: Show extracted rules
|
||||
working-directory: fstar
|
||||
run: |
|
||||
echo "Lines of generated C++ output:"
|
||||
wc -l extracted_rules.txt
|
||||
echo ""
|
||||
echo "Full content:"
|
||||
cat extracted_rules.txt
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
# Upload the extracted rules as a build artifact so reviewers can
|
||||
# inspect the generated C++ without re-running the workflow.
|
||||
# -----------------------------------------------------------------------
|
||||
- name: Upload extracted rules artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: fstar-extracted-cpp-rules
|
||||
path: fstar/extracted_rules.txt
|
||||
if-no-files-found: error
|
||||
|
|
@ -211,8 +211,14 @@ fstar.exe --include . IEEE754.fst FPARewriterRules.fst
|
|||
|
||||
### Running the Meta-F* extraction
|
||||
|
||||
To run the reflection-based C++ code extraction and print the generated
|
||||
rewrite rules to stdout:
|
||||
The convenience script `extract.sh` runs the extraction and prints the
|
||||
generated C++ rules to stdout:
|
||||
|
||||
```sh
|
||||
cd fstar && ./extract.sh
|
||||
```
|
||||
|
||||
Or invoke F* directly:
|
||||
|
||||
```sh
|
||||
fstar.exe --include . IEEE754.fst FPARewriterRules.fst RewriteCodeGen.fst
|
||||
|
|
@ -220,14 +226,21 @@ fstar.exe --include . IEEE754.fst FPARewriterRules.fst RewriteCodeGen.fst
|
|||
|
||||
This type-checks all three files and executes the `run_tactic` calls in
|
||||
`RewriteCodeGen.fst`, printing the generated C++ for each ite-pushthrough
|
||||
lemma. Redirect stdout to a file to capture the output:
|
||||
lemma. To capture the output to a file:
|
||||
|
||||
```sh
|
||||
fstar.exe --include . IEEE754.fst FPARewriterRules.fst RewriteCodeGen.fst \
|
||||
2>/dev/null
|
||||
./extract.sh > extracted_rules.txt
|
||||
```
|
||||
|
||||
F\* 2024.09.05 or later is recommended. The files have no external
|
||||
### Continuous integration
|
||||
|
||||
The GitHub Actions workflow `.github/workflows/fstar-extract.yml` runs
|
||||
the extraction automatically on every push or pull request that touches
|
||||
the `fstar/` directory. It installs the F* binary, runs `extract.sh`,
|
||||
and uploads the generated C++ as a downloadable artifact
|
||||
`fstar-extracted-cpp-rules` for inspection.
|
||||
|
||||
F\* 2024.09.05 or later is required. The files have no external
|
||||
dependencies beyond the F\* standard library prelude.
|
||||
|
||||
Because all IEEE 754 semantics are encoded as `assume val` axioms, the
|
||||
|
|
|
|||
47
fstar/extract.sh
Executable file
47
fstar/extract.sh
Executable file
|
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/env bash
|
||||
# extract.sh
|
||||
#
|
||||
# Run the Meta-F* reflection-based extraction to generate C++ rewrite rules
|
||||
# from the F* lemmas in this directory.
|
||||
#
|
||||
# Usage (from the fstar/ directory):
|
||||
# ./extract.sh
|
||||
#
|
||||
# Usage (from the repo root):
|
||||
# fstar/extract.sh
|
||||
#
|
||||
# Output:
|
||||
# Prints the generated C++ rules to stdout.
|
||||
# Exits non-zero if F* typechecking or tactic execution fails.
|
||||
#
|
||||
# Requirements:
|
||||
# fstar.exe on PATH (F* 2024.09.05 or later recommended).
|
||||
# The three source files must be present:
|
||||
# IEEE754.fst, FPARewriterRules.fst, RewriteCodeGen.fst
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
if ! command -v fstar.exe &>/dev/null; then
|
||||
echo "ERROR: fstar.exe not found on PATH." >&2
|
||||
echo "Install F* 2024.09.05+ from https://github.com/FStarLang/FStar/releases" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "=== F* version ===" >&2
|
||||
fstar.exe --version >&2
|
||||
|
||||
echo "" >&2
|
||||
echo "=== Running Meta-F* extraction ===" >&2
|
||||
|
||||
# F* writes tactic print() output to stdout.
|
||||
# Verification progress and errors go to stderr.
|
||||
fstar.exe --include . \
|
||||
IEEE754.fst \
|
||||
FPARewriterRules.fst \
|
||||
RewriteCodeGen.fst
|
||||
|
||||
echo "" >&2
|
||||
echo "=== Extraction complete ===" >&2
|
||||
Loading…
Add table
Add a link
Reference in a new issue