A tour of the repository
This part is for people who want to change psync. It assumes the Foundations part, or the same background. It shows where everything lives, how a change travels through the code, how to set up a development environment, and how to check a change before you send it.
The crates
| Path | What it is | Built with |
|---|---|---|
psync-macros/ | the proc-macro crate: #[graph] and the hint attributes, all thin wrappers | stable |
psync-graph/ | the analysis and code generation behind #[graph], as an ordinary library; the psync-expand tool; the Foundations examples | stable |
src/ (crate psync) | what users depend on: re-exports the macros, the runtime the generated code calls (graph_rt.rs, as psync::__private), and the executors | stable, no_std |
psync-check/ | cargo psync and psync-driver, the compiler-level checks and facts | the pinned nightly |
verify/ | the Lean proofs and the Lean tutorial | Lean 4.22 |
tests/ | behaviour tests of the macro and the executors | stable |
examples/graph_suite/ | sixteen real-world shapes, each run sequentially and with psync | stable |
book/ | this book (mdBook) | mdbook |
psync-check is outside the Cargo workspace (exclude in the root Cargo.toml), because it
links rustc’s internal crates and needs its own toolchain.
The life of an annotated function
Follow one #[psync::graph] async fn through the code, in the order things happen.
psync-macros/src/lib.rsgraph(attr, item)converts the token streams and callspsync_graph::expand.psync-graph/src/lib.rsexpandparses the options (Options::parse), honoursoffandPSYNC_GRAPH=off, and callstransform_fn. That builds theScope(which bindings aremut,&muthandles or#[psync::fresh]), loads the compiler facts ifPSYNC_FACTSis set (facts.rs), runs theRewriter, strips the hints, and adds the__PSYNC_GRAPHmarker.rewrite.rsRewriteris aVisitMut. For each block of async code, innermost first, it sendsforandwhileloops toloops.rs, then calls the hoisting and scheduling steps.hoist.rssplits statements so each hidden await becomes its own binding.classify.rsdecides for each statement: node or barrier, and for a node, what it binds, whether it awaits, may exit or may panic, and its effects (fromeffects.rs) and accesses (fromaccess.rs).schedule.rsplandraws the edges (depends), fuses chains and assigns levels.emitgenerates each level’s join, withexits.rsproviding the code that records exits and replays them.src/graph_rt.rsis what the generated code calls at run time:maybe_done_at(a chain),over_atandjoin_all_bounded(a prefetched loop), andBranchandRethrow(the?plumbing).
#[graph(explain)] prints the report that steps 5 and 6 build (Report in lib.rs), and
psync-expand prints it as JSON with the generated code.
The life of cargo psync build
psync-check/src/bin/cargo-psync.rsrunscargo checkintarget/psync, withRUSTC_WRAPPERset topsync-driverand the environment variables inpsync_check::env.src/bin/psync-driver.rsis rustc with a callback. After analysis it runs theCheckerand theAnalyzerfromsrc/driver/analysis.rs.analysis.rs:Analyzer::summarizecomputes summaries from MIR. Each body’s own effects come fromlocalandcall, and summaries are fixed points over call-graph components (component).call_factswrites a fact for every call site in annotated functions, andwrite_summarieswrites the crate’s summary file.Checker::runfinds the macro’s markers (markers) and checks each level and loop prefix.src/lib.rs(psync_check, no compiler dependency) holds the shared model:Effect,conflict, the summary and findings file formats, andlink, which resolves deferreddyncalls over the whole build.facts_textwritesfacts.tsv.- Back in
cargo-psync.rs,check_and_linkre-runs the check when linking resolved new calls.buildthen runs one more check pass withPSYNC_FACTSpointing atfacts.tsv. In it, the macro (step 2 above) schedules with the facts, and the driver checks the schedule that results. Last, it runs a plaincargo build(no driver, the normal target directory) with the samePSYNC_FACTS, so the binary gets the schedule that was just checked.
Setting up
git clone <the repository> && cd psync
cargo test --no-default-features # the macro and the single-core executor
The default feature rp235x builds the embedded executor for the RP2350. On a host,
--no-default-features (and --features std for MultiExecutor) is what you want.
For psync-check you need rustup, which reads psync-check/rust-toolchain.toml and installs the
pinned nightly with rustc-dev on first use:
cd psync-check
cargo test # builds the driver and runs it on the fixture
cargo install --path . --locked # puts cargo-psync and psync-driver on your PATH
rust-analyzer needs rustc_private support to understand the driver. psync-check/Cargo.toml
sets [package.metadata.rust-analyzer] rustc_private = true. Open psync-check/ as its own
project so the pinned toolchain is used.
Lean: install elan. lean verify/Schedule.lean fetches nothing, because the proofs use only
Lean’s core library.
The book: cd book && mdbook build, then open book/book/index.html.
Before you send a change
Run all of these. Each takes from seconds to a couple of minutes.
cargo test --no-default-features # graph + scheduling tests
cargo test --no-default-features --features std --test multi # MultiExecutor
cargo test -p psync-graph # analysis unit tests, Foundations examples
cargo run --example graph_suite --no-default-features -- --brief # speedups: geometric mean ~3.8x
(cd psync-check && cargo test) # driver: check, --facts, fix
lean verify/Schedule.lean && lean verify/Tutorial.lean # proofs
(cd book && mdbook build) # the book
If your change alters what psync does, it changes the book too. Update the chapter that describes the behaviour, and the report output it shows. The rest of this part gives the recipes for the most common changes:
- Adding an effect rule: teach the macro or the driver what a call does.
- Adding a check: a new warning in
cargo psync check. - Adding a test: which suite, and how.
Writing for the book
-
Reports you show after a Rust example (a
textblock starting withregion, or with thepsync::graphheader) are checked against what psync prints, byscripts/check-book-examples.py. Paste real output. -
Quizzes are plain fenced blocks, turned into widgets by
book/theme/quiz.js. No preprocessor is needed, and the block reads well as text:```quiz ? The question. `code` works. + A right answer (several `+` make it "pick all that apply"). - A wrong answer. > Why, shown after the reader answers. ``` -
Benchmark figures are SVG drawn by
scripts/figures.pyintobook/src/figures/and included with{{#include ../figures/NAME.svg}}. The numbers live in the script, next to the name of the chapter that measured them: change both together, then run the script.