Environment variables and tools
PSYNC_GRAPH
| Value | Effect |
|---|---|
off | every #[psync::graph] function in the build compiles as written |
| unset or anything else | normal rewriting |
The variable is read when the macro expands. Cargo does not track it, so touch the annotated
files, or use a separate CARGO_TARGET_DIR, whenever you change it. See
Comparing builds.
cargo psync
cargo psync check [--deny] [--notes] [--facts] [CARGO CHECK ARGS...]
cargo psync build [--deny] [--notes] [CARGO BUILD ARGS...]
cargo psync fix [CARGO CHECK ARGS...]
cargo psync summaries [CRATE] [--all]
cargo psync pdg [FUNCTION] [--entries] [--from HANDLER]
pdg prints the dependence graphs the last check built; --entries lists the entry points
(main, axum and actix-web handlers with their routes) and --from HANDLER the graphs of what
one request runs (Entry points).
Checks #[psync::graph] rewrites against the compiled bodies of callees. Built from psync-check/
with a pinned nightly (cd psync-check && cargo install --path .). See
Checking rewrites.
| Variable | Set by cargo psync | Meaning |
|---|---|---|
PSYNC_SUMMARY_DIR | target/psync/summaries | where the driver writes and reads per-crate effect summaries |
PSYNC_FINDINGS_DIR | target/psync/findings | where the driver writes per-crate findings (JSON) |
PSYNC_CHECK_DENY | --deny | 1: findings are errors |
PSYNC_CHECK_NOTES | --notes | 1: also report output order and interior mutability |
PSYNC_LINKED | target/psync/linked.json | the driver reads the link step’s resolution of dyn calls |
PSYNC_LINKED_STAMP | hash of linked.json | tracked by the driver, so workspace crates are re-checked when it changes |
PSYNC_FACTS | target/psync/facts.tsv (build, check --facts) | the macro schedules with these facts (Scheduling with compiler facts) |
PSYNC_FACTS_STAMP | hash of facts.tsv | read through option_env! in generated code, so cargo rebuilds when facts change |
psync-expand
cargo run -p psync-graph --features cli --bin psync-expand -- FILE LINE [BOUND]
Applies #[psync::graph] to the innermost function containing LINE of FILE and prints JSON:
function, start_line, end_line, bound, changed, explain, report and expanded. The
cli feature enables span locations, so line numbers appear in reports. See
Reading the report, and the report’s fields below.
psync-scan
cargo build --release -p psync-graph --features cli --bin psync-scan
target/release/psync-scan [--sync | --async] FILE...
Applies #[psync::graph] with default options to every function of every file, as if each were
annotated, without changing the files. It prints one tab-separated line per region where two
waiting statements (awaits, or blocking calls) share a level in different chains:
| Column | Meaning |
|---|---|
| 1 | file |
| 2 | the function’s first line |
| 3 | the function’s name |
| 4 | blocking (synchronous code, Phase II) or async |
| 5 | the region’s number of statements |
| 6 | the number of levels in which two or more chains wait |
| 7 | the first four waiting statements, separated by | |
A summary line (files, functions, functions with a concurrent region, regions) goes to stderr.
--sync scans only synchronous functions, --async only async ones; const fns are skipped.
A panic in the analysis prints PANIC in column 4 and the scan continues: report it, it is a
psync bug. The scan measures what psync finds without hints, so helpers that hide a request
are not seen. See The audit.
psync-cert
cargo run -q -p psync-graph --features cli --bin psync-cert -- FILE... > verify/Certs.lean
Writes a Lean module with a certificate for every concurrent region of every #[psync::graph]
function in the files (and every example! of graph_suite), each with a theorem
check cert = true proved by decide. scripts/certify.sh regenerates the repository’s own
certificates and checks them with Lean; CI fails if verify/Certs.lean is out of date. See
Certified schedules.
psync-predict
cargo run -p psync-graph --features cli --bin psync-predict -- FILE LINE TRACE [BOUND]
Predicts the time of one measured run under psync’s schedule. TRACE has one LINE COST pair per
line, for each call of the function as written. Prints the measured and predicted time, and the
chain that sets each level. A trace of several runs separated by --- lines is grouped by path
(the lines each run ran): each path gets its share of the runs, its mean measured and predicted
time, and the critical path of its slowest run. See Predicting the
speedup.
graph_suite
cargo run --example graph_suite --no-default-features [-- --brief] [-- FILTER]
Times 16 real-world functions before and after the rewrite, and checks that the results match. A third, profiled run of each predicts the rewrite’s time (Predicting the speedup). See Sixteen real-world shapes.
Scripts
| Script | What it does |
|---|---|
scripts/certify.sh | regenerate verify/Certs.lean with psync-cert, then lake build it |
scripts/check-book-examples.py | run psync-expand on every book example that is followed by a report, and fail with a diff if psync now prints something else |
scripts/spec-check/check_logs.py | check Kubernetes audit logs (--kube) or S3 server logs (--s3) against the commutativity specifications (What psync guarantees) |
scripts/spec-check/selftest.sh | the log checker on logs with planted violations |
scripts/charon/ | Rust → Charon → the MIR fragment of verify/Footprint.lean (its README.md) |
scripts/audit/ | the Phase II audit’s harnesses for rustic and tauri (The audit) |
scripts/build-site.sh | this book, every crate’s Rustdoc under /api/ and the Lean docs under /api/lean/ |
scripts/test-rp2350.sh | host tests and the RP2350 firmware build (--flash to flash a board) |
The JSON report
psync-expand prints one object. Its report is the Report struct of psync-graph
(psync-graph/src/lib.rs), serialized field by field; indices are 0-based, lines 1-based, and a
line is 0 when the tokens carry no location (only the cli feature turns locations on).
| Field | Type | Meaning |
|---|---|---|
function, start_line, end_line | string, number | the function chosen and its lines |
bound | number | the loop prefetch bound used |
changed | bool | some region runs two chains together, or some loop is prefetched |
explain | string | the text #[psync::graph(explain)] prints |
expanded | string | the generated function, pretty-printed |
report.regions[] | object | one per analyzed region (two or more waits), below |
report.loops[] | object | one per for loop considered for prefetching, below |
report.barriers[] | string | waiting statements kept in place, each with the reason |
report.unclassified_writes | bool | unclassified calls were taken as writes (strict, or calls = write..) |
A region:
| Field | Type | Meaning |
|---|---|---|
nodes[] | object | its statements, in program order, below |
edges[] | [from, to, reason] | to waits for from; reason is the text of the explain line (for example, reads user) |
chains[] | array of node indices | statements fused into one chain, in program order |
levels[] | array of chain indices | the chains that run together, level by level |
changed | bool | some level has two or more chains |
unclassified[] | [line, call] | awaited calls whose effect psync could not tell from the name |
cert[] | {reads, writes} | per node, the places it may read and write, each a list of path segments: the certificate psync-cert turns into Lean |
runtime_checks | number | chain pairs that run together because their computed file paths differ, and are ordered at run time if they turn out to overlap |
A node:
| Field | Type | Meaning |
|---|---|---|
label | string | the statement’s source, shortened |
line, end_line | number | its first and last line |
awaits | bool | it contains an .await |
blocks | bool | synchronous code that blocks (Phase II), run on another thread |
effect | bool | an ordinary statement with an effect: effects keep their order with each other |
effects[] | string | its effects on files, the network, services, processes and the environment, as explain describes them |
exits | bool | it may leave the function (?, return, break, a panic with facts) |
speculate | bool | its writes may run ahead of earlier exits (#[psync::speculate]) |
A loop:
| Field | Type | Meaning |
|---|---|---|
label | string | the loop header |
line, end_line | number | its first and last line |
prefetched[], prefetched_lines[] | strings, [first, last] | the statements run ahead for each item, and their lines |
bound | number | how many items may be in flight |
changed | bool | it was prefetched |
reason | string | why it was left alone (empty when prefetched) |
check | string | for items that name their own files: checked at run time, or why they could not be and distinct items are assumed |
cargo psync check writes one more JSON file per crate, target/psync/findings/<crate>.json
(CrateFindings in psync-check/src/lib.rs): crate_name; checked_levels and
checked_loops, the counts it checked; functions, a map from each rewritten function to
[concurrent levels, prefetched loops]; and findings[], each with severity (Warning or
Note), kind (conflict, speculative-write, loop-speculative-write,
interior-mutability, output-order or cancellation), message, location
(file:line:column), function, and fix, either null or the #[psync::seq] insertion
cargo psync fix applies ({file, offset, insert}). The summaries’ format is in
From MIR to summaries.
Tests
cargo test --no-default-features --test graph # macro behaviour
cargo test --no-default-features --test scheduling # executor
cargo test -p psync-graph # analysis unit tests
./scripts/test-rp2350.sh [--flash] # host tests and RP2350 firmware build
Cargo features
| Crate | Feature | Effect |
|---|---|---|
psync | rp235x (default) | RP2350 heap (init_heap), WFE/SEV parking and HAL dependencies, on thumbv8m.main-none-eabihf only |
psync-graph | cli | the psync-expand, psync-scan, psync-cert and psync-predict binaries, line numbers, JSON reports |