Proposal: remove spans from test snapshots
Changing anything within the std.prql module almost always results in churn of dozens of snapshots where the only changes are in the span: 0:1234-1238 lines. This makes code review substantially harder since you end up with a bunch of junk you have to skip, and a true substantial change to a snapshot is difficult to spot.
Instead, it probably makes sense to simply drop the span: lines from the snapshots. Spans are of course always relative to the total PRQL input and they don't really have any underlying meaning behind them. I'm having a hard time thinking of a case where a code reviewer would want to know that a span changed, or where we would want a test to fail because a span changed.
Reproduced the mechanism, but the measurements point somewhere slightly different: spans are a real source of churn, just a very small one compared to expression-ID renumbering.
Span churn is small and precisely bounded. Inserting a single comment line at the top of std.prql (zero semantic change, pure byte-offset shift) churns exactly 14 lines across 4 snapshots, all span: lines:
prqlc__semantic__resolver__test__functions_pipeline.snap/-2.snapprqlc__semantic__resolver__transforms__tests__aggregate_positional_arg-2.snapintegration__queries__debug_lineage__set_ops_remove.snap
That's the whole footprint — those 14 lines are every source_id: 0 span in the prqlc crate's snapshots. The other ~2,090 spans in prqlc's snapshots are 1: (query-relative) and don't move when std.prql changes.
The "dozens of snapshots" churn is node IDs, not spans. For a normal std.prql change — adding or removing a declaration — I categorized the actual snapshot diffs:
| commit | .snap files |
span lines | expression-ID lines |
|---|---|---|---|
#5721 date.now |
38 | 8 | 5,886 |
#5729 date.trunc |
37 | 8 | 5,886 |
#5806 remove std.prql_version |
36 | 0 | 5,924 |
#6046 append by:name |
46 | 14 | 6,206 |
The resolver assigns every expr an id from a single monotonic counter that numbers std.prql's exprs before the query's, so adding a declaration shifts every downstream id:, parent:, target_id:, input_id:, child-ID list entry, and _literal_N name. That lands almost entirely in the 31 debug_lineage snapshots. Dropping spans wouldn't have changed #5806's diff at all.
Suggest doing it at the snapshot layer, not by dropping the field. span is documented output of prqlc debug lineage (cli/mod.rs:206), and #4662 enabled span serialization specifically because the debug HTML renderer reconstructs AST nodes from JSON — it uses the presence of a "span" key as its node detector (render_html.rs:383).
An insta filter gets the same review benefit without touching serialization. Filtering only source_id: 0 spans, scoped to prqlc's tests, removes the churn while keeping the query-relative spans that are stable and readable:
with_settings!({
input_file => prql_path,
filters => vec![(r"\b0:\d+-\d+", "[std]")],
}, {
assert_snapshot!(test_name, &lineage, &prql)
});
I verified this on the debug_lineage test: the 9 std spans in …set_ops_remove.snap render as [std], the 39 1: spans are untouched, and re-running with a shifted std.prql produces no diff. Broadening the regex to \b\d+:\d+-\d+ drops spans wholesale if you'd rather go that way — worth noting the scoping matters, because in prqlc-parser source 0 is the test's own input, and those ~809 span assertions are arguably what the parser tests are checking.
Happy to open a PR for the span filter, for the ID churn, or both — the ID side is the one that would actually shrink those 40-file diffs, so it's probably worth deciding on first.
Method
Repo state: 7bd749933dbf6c827a53ecd59b443006e4858b0d.
Span-churn experiment — prepend one comment line to prqlc/prqlc/src/semantic/std.prql, then:
INSTA_UPDATE=always cargo test -p prqlc --quiet
git diff --stat -- '*.snap'
Yields 4 files / 14 lines, all matching span.
Historical categorization — for each commit touching std.prql:
git show --format="" -U0 <sha> -- '*.snap' | grep -E '^[+-]' | grep -vE '^(\+\+\+|---)' | awk '
/span/ {s++; next}
/(id|input_id|target_id|parent): [0-9]+$/ {i++; next}
/^[+-][[:space:]]*- [0-9]+$/ {i++; next}
/_literal_[0-9]+/ {i++; next}
{o++}
END {print "span:", s+0, " id-churn:", i+0, " other:", o+0}'
other is 41 lines for #5729 and 2 for #5806 (SQL output of new tests plus insta headers).
Span footprint by crate:
grep -rhoE 'span: "?[0-9]+:' --include=*.snap prqlc/prqlc # 12 × "0:", 2091 × "1:"
grep -rhoE 'span: "?[0-9]+:' --include=*.snap --include=*.rs prqlc/prqlc-parser # 809 × "0:"
(The prqlc count above misses the two - - 0:…-… frame keys in set_ops_remove.snap, which is why the experiment shows 14 lines rather than 12.)
Filter verification — applied the filters block to queries.rs:151, accepted snapshots, then re-ran with the perturbed std.prql: git diff --stat was identical before and after, and the snapshot contains 0 occurrences of 0:, 9 of [std], 39 of 1:. All changes reverted; working tree is clean.