mirror of
https://github.com/storytold/gridcraft.git
synced 2026-10-27 12:16:54 -06:00
A formula that reads one later in row-major order (further down, or on a later sheet) is calculated on demand, inside the formula that reads it. Each level costs stack, so real models with chains of about 1,000 such formulas overflowed the 1 MB main-thread stack on Windows and crashed on open. Past 2,000 levels the chain gave #CIRC! instead. On-demand evaluation now goes at most 64 formulas deep. A formula needed deeper suspends the evaluations in progress: it is calculated from the top, then the suspended ones again, reading the results kept so far. Chains of any length calculate, with the same results. A suspended formula read again is a circular reference, as a formula in progress is, so loops are found at the same cell as before. Regression tests build the chains in code: 20,000 formulas each reading the row below, the same hopping between two sheets, a 5,000-formula loop, and a loop closing into the middle of a deep chain. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>