Reading the report
psync can show you its graph in two forms. explain prints text at compile time. psync-expand
prints JSON, together with the generated code. Both come from the same Report.
explain
#[psync::graph(explain)]
async fn profile_page(api: &Api, user_id: u64) -> Result<Page, Error> { /* ... */ }
The report is printed to stderr while the crate compiles. With Cargo, you see it when the annotated crate is rebuilt:
psync::graph `profile_page`:
region 0:
n0: user = user()? [await]
n1: posts = posts()? [await]
n2: avatar = avatar()? [await]
n3: friends = friends()? [await]
n0 -> n2 (reads `user`)
level 0: n0->n2 || n1 || n3
Line by line:
region Nis one run of nodes between barriers. Only regions with two or more awaits are analyzed and listed.(unchanged)means nothing overlapped, so the region is emitted as written.nK: labelis one node. A binding showsnames = callee(). A computed value shows its first characters.?marks a node that can exit early, and[await]marks one that awaits.nA -> nB (reason):nBwaits fornA. The reasons are listed in Basic concepts.level L: chain || chainlists chains (n0->n2) that run concurrently in levelL.loopfor x in xs: prefetch [labels], N at a timenames a rewritten loop. A loop that was left alone shows the reason instead.barrier: line L:stmt: reasonis an await-containing statement kept in place. Line numbers are only known underpsync-expand. Inside the proc macro they show as0.
Hoisted values appear under generated names: __psync_hN for an operand, __psync_sN for a
scrutinee, __psync_gN for a guarded branch, __psync_tN for a block’s tail.
psync-expand
psync-expand runs the same transformation on any function in any file, without changing the
file:
cargo run -p psync-graph --features cli --bin psync-expand -- src/discovery.rs 115 8
The arguments are the file, a line inside the function, and an optional bound (default 16). It picks
the innermost function containing the line. Free functions, impl methods and trait methods with
default bodies all work. The output is one JSON object:
{
"function": "profile_page",
"start_line": 1,
"end_line": 7,
"bound": 16,
"changed": true,
"explain": " region 0:\n n0: user = user()? [await]\n ...",
"report": {
"regions": [
{
"nodes": [
{ "label": "user = user()?", "awaits": true, "effect": false, "exits": true, "line": 2 },
...
],
"edges": [[0, 2, "reads `user`"]],
"chains": [[0, 2], [1], [3]],
"levels": [[0, 1, 2]],
"changed": true
}
],
"loops": [],
"barriers": []
},
"expanded": "async fn profile_page(api: &Api, user_id: u64) -> Result<Page, Error> { ... }"
}
levelsholds indices intochains, andchainsholds indices intonodes.effect: truemarks an ordinary statement. Effects keep their order with each other.loops[]entries havelabel,prefetched(labels of the prefix nodes),bound,changed,reason,lineandend_line.expandedis the pretty-printed generated function.
Pipe it through jq to get one part out:
psync-expand file.rs 42 | jq -r .explain
psync-expand file.rs 42 | jq -r .expanded
psync-expand was how the 90 audit findings were checked. It ran on each finding’s function at the
pinned commit, and the script confirmed that the concurrent region or prefetched loop fell inside the
finding’s source lines.