Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Environment variables and tools

PSYNC_GRAPH

ValueEffect
offevery #[psync::graph] function in the build compiles as written
unset or anything elsenormal 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.

VariableSet by cargo psyncMeaning
PSYNC_SUMMARY_DIRtarget/psync/summarieswhere the driver writes and reads per-crate effect summaries
PSYNC_FINDINGS_DIRtarget/psync/findingswhere the driver writes per-crate findings (JSON)
PSYNC_CHECK_DENY--deny1: findings are errors
PSYNC_CHECK_NOTES--notes1: also report output order and interior mutability
PSYNC_LINKEDtarget/psync/linked.jsonthe driver reads the link step’s resolution of dyn calls
PSYNC_LINKED_STAMPhash of linked.jsontracked by the driver, so workspace crates are re-checked when it changes
PSYNC_FACTStarget/psync/facts.tsv (build, check --facts)the macro schedules with these facts (Scheduling with compiler facts)
PSYNC_FACTS_STAMPhash of facts.tsvread 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:

ColumnMeaning
1file
2the function’s first line
3the function’s name
4blocking (synchronous code, Phase II) or async
5the region’s number of statements
6the number of levels in which two or more chains wait
7the 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

ScriptWhat it does
scripts/certify.shregenerate verify/Certs.lean with psync-cert, then lake build it
scripts/check-book-examples.pyrun 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.pycheck Kubernetes audit logs (--kube) or S3 server logs (--s3) against the commutativity specifications (What psync guarantees)
scripts/spec-check/selftest.shthe 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.shthis book, every crate’s Rustdoc under /api/ and the Lean docs under /api/lean/
scripts/test-rp2350.shhost 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).

FieldTypeMeaning
function, start_line, end_linestring, numberthe function chosen and its lines
boundnumberthe loop prefetch bound used
changedboolsome region runs two chains together, or some loop is prefetched
explainstringthe text #[psync::graph(explain)] prints
expandedstringthe generated function, pretty-printed
report.regions[]objectone per analyzed region (two or more waits), below
report.loops[]objectone per for loop considered for prefetching, below
report.barriers[]stringwaiting statements kept in place, each with the reason
report.unclassified_writesboolunclassified calls were taken as writes (strict, or calls = write..)

A region:

FieldTypeMeaning
nodes[]objectits 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 indicesstatements fused into one chain, in program order
levels[]array of chain indicesthe chains that run together, level by level
changedboolsome 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_checksnumberchain pairs that run together because their computed file paths differ, and are ordered at run time if they turn out to overlap

A node:

FieldTypeMeaning
labelstringthe statement’s source, shortened
line, end_linenumberits first and last line
awaitsboolit contains an .await
blocksboolsynchronous code that blocks (Phase II), run on another thread
effectboolan ordinary statement with an effect: effects keep their order with each other
effects[]stringits effects on files, the network, services, processes and the environment, as explain describes them
exitsboolit may leave the function (?, return, break, a panic with facts)
speculateboolits writes may run ahead of earlier exits (#[psync::speculate])

A loop:

FieldTypeMeaning
labelstringthe loop header
line, end_linenumberits first and last line
prefetched[], prefetched_lines[]strings, [first, last]the statements run ahead for each item, and their lines
boundnumberhow many items may be in flight
changedboolit was prefetched
reasonstringwhy it was left alone (empty when prefetched)
checkstringfor 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

CrateFeatureEffect
psyncrp235x (default)RP2350 heap (init_heap), WFE/SEV parking and HAL dependencies, on thumbv8m.main-none-eabihf only
psync-graphclithe psync-expand, psync-scan, psync-cert and psync-predict binaries, line numbers, JSON reports