Repository navigation
Recalc: an anchor's new formula no longer reads its old spill area - #1427
Conversation
…l area sees it empty When a dynamic array's anchor gets a new formula, the formula is evaluated while the old array is still laid out, so it can read the old spilled values. The anchor was then never evaluated again: it is left out of its own spill area's dependents, so as not to read its own array. - `A1` was `=SEQUENCE(3)` and becomes `=SUM(A2:A3)+1`: it showed 6 (2 + 3 + 1) with A2:A3 empty; recalculating from scratch gives 1. - `A1` was `=SEQUENCE(3)` and becomes `=SEQUENCE(1,A2+1)`: it read A2 as 2 and spilled over A1:C1 instead of showing 1. The anchor is now evaluated again when its old array is gone or partly freed. It is still left out when its new array covers the old one, where it would read its own array. Regression test in calc (`an_anchor_given_a_formula_that_reads_its_old_spill_area_sees_it_empty`: the new formula stops spilling, spills elsewhere, or spills over part of the old area); it fails without the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Not a maintainer, but I have a PR touching the same function so I built this branch and ran your three examples against Your first example reproduces and is fixed: The other two already give 1 on I would rather assume my reproduction is the problem than your report. I drove it through the For what it is worth I checked whether On overlapping with the other two spill PRs (I mention it because all three of us edit |
What happened
When a dynamic array's anchor gets a new formula that reads the cells its old array spilled into, the new formula keeps the old values:
=SEQUENCE(3), then A1=SUM(A2:A3)+1: A2:A3 are empty now, but A1 shows 6 (2 + 3 + 1) instead of 1.=SEQUENCE(3), then A1=SEQUENCE(1,A2+1): it reads A2 as 2 and spills over A1:C1 instead of showing 1.=SEQUENCE(3), then A1=SEQUENCE(MAX(1,A3-1)): it reads A3 as 3 and spills 1, 2 over A1:A2 instead of showing 1.Recalculating from scratch (Calculate Now) gives the right values.
Why
The new formula is evaluated while the old array is still laid out, because spills are only cleared and laid out again at write-back. So it reads the old spilled values. Write-back then sends the dependents of the changed spill area to another round, but it leaves the anchor itself out so that an array never reads its own array. Once the old array was gone, nothing evaluated the anchor again.
Fix
At write-back, the anchor goes to the next round with the other dependents of its spill area when its old array is gone or only partly covered by the new one. It is still left out when the new array covers the old one, because there reading the area would mean reading its own array.
Tests
calc:an_anchor_given_a_formula_that_reads_its_old_spill_area_sees_it_emptycovers the three cases above (the anchor stops spilling, spills somewhere else, or spills over part of the old area). It fails without the fix.cargo xtask cipasses on Linux (fmt, clippy -D warnings, test, assets, layers, wasm, parity, keytips).GRIDCRAFT_FUZZ_SEED0–399, 200 steps each) gives the same results as on main. The 21 seeds that fail on main fail with the same first invariant, and no seed fails that didn't before.