Repository navigation
Add INDIRECT function (HF-27) - #1843
Open
Tobiadefami wants to merge 17 commits into
Open
Tobiadefami wants to merge 17 commits into
Tobiadefami wants to merge 17 commits into
Conversation
INDIRECT resolves its text at evaluation time and records the cell it reads as a runtime dependency in the graph, so it is not volatile. When the target is not current yet in the running pass, the evaluation is deferred: the sort computes the target first, with an explicit stack, and then retries the formula. Covers A1 references to a single cell, on the same or another sheet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
INDIRECT now accepts an A1 range, a named expression and R1C1 text (absolute, relative, ranges, sheet-qualified). A range is read lazily: its cells become a runtime dependency of the formula, through the range vertex, the first time the range's values or address are used, so ROWS and COLUMNS read only its size. Changes to named expressions mark INDIRECT formulas for recalculation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…evaluation - Moving a cell that an INDIRECT formula read marks that formula dirty: the address in its text does not move with the cell, so it reads the address again. - A formula whose result is an INDIRECT range records the range as its dependency while it is evaluated, like a literal range; a cell that later reads the stored range no longer reads cells that are not computed yet. - Range and empty cell vertices that lose their last runtime dependent are removed after the evaluation, not during it, while the sort may still hold them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
hyperformula-docs | ff9828f | Commit Preview URL Branch Preview URL |
Nov 28 2026, 01:06 PM |
Performance comparison of head (ff9828f) vs base (ce5e52f) |
INDIRECT strips a trailing run of spaces and line feeds from ref_text before parsing it, in A1 and R1C1 notation and for names. Other whitespace still makes the text invalid: a trailing tab, carriage return or no-break space, and any leading or inner space give #REF!. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…f references
- INDIRECT reads whole columns and rows, in A1 notation ("B:B", "B:D", "2:3",
"Sheet2!A:A") and in R1C1 notation ("C2", "C[-1]:C2", "R2"), with the
corners in any order. Past maxRows or maxColumns, or with a row or column
number too large to be a number, it returns #REF!.
- ROW, COLUMN, ROWS and COLUMNS use the position or the size of a reference
returned by INDIRECT without reading its cells or recording them as
dependencies, so a formula inside the range it measures is no cycle. A named
range, a named whole column or row, and a range returned by ARRAYFORMULA now
give the same result as the literal range, e.g., ROW of a named range gives
its top row instead of #VALUE!.
- FunctionPlugin.runFunctionWithReferenceArgument takes an optional
referenceExpected argument. Only ROW and COLUMN set it, so a custom function
that takes a reference still reads an INDIRECT range's cells and records
them as dependencies.
- A range returned by INDIRECT checks its cells for values not computed yet
once per evaluation pass, not on every read.
- Trailing spaces and line feeds are removed with a loop instead of a regular
expression, which took quadratic time on a long run of spaces followed by
another character.
- The catalogue entry for INDIRECT describes ranges, whole columns and rows,
named expressions and R1C1 notation.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Names from Microsoft's function pages and the lookup and reference function list for each language. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Known limitations: what INDIRECT can't do (R1C1 letters, spill and external references, ranges that don't spill, own-range cycles). - List of differences: INDIRECT's dependencies are collected at evaluation. - Volatile functions: INDIRECT depends on the sheet structure, which now includes adding or renaming a sheet and changing named expressions. - Developer docs: runtime dependencies in the dependency graph, the referenceExpected argument, and why plugins must not catch EvaluationDeferred. - Changelog: INDIRECT, and ROW, COLUMN, ROWS and COLUMNS of named ranges. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The edge is removed during evaluation; unused vertices are removed later, by removeUnusedRuntimeVertices. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tion caught the signal A custom function that wrapped its work in a try/catch could catch EvaluationDeferred and return a value, which the cell then kept until a rebuild. The evaluator now discards the value of an evaluation that requested a cell, and retries the formula once that cell is computed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It was in the ungrouped list, so only fun:all or fun:INDIRECT granted it. It now comes with fun:lookup.c, like ADDRESS and INDEX. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # CHANGELOG.md # hyperformula/src/interpreter/plugin/InformationPlugin.ts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # CHANGELOG.md # hyperformula/src/interpreter/plugin/InformationPlugin.ts
Marking a volatile array formula as volatile when the sheet is built is a separate engine fix, not part of INDIRECT. The structure-change flag stays: INDIRECT needs it for array formulas. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Don't revisit the cells of a range vertex the graph already has when a formula reads the range again. - Keep the recorded addresses of runtime dependencies current through row, column, cell and sheet-merge changes, and forget a formula once it leaves the graph, so an empty cell vertex that loses its last reader is removed. - Point runtime dependencies to the range vertex that a removed range is merged into. - SHEET, SHEETS, FORMULATEXT and ISFORMULA take INDIRECT's reference like a reference typed into the formula. Only INDIRECT's result counts as a reference; a range returned by ARRAYFORMULA is a value, as in Google Sheets. ROW and COLUMN read a named cell or range from the name's formula (namedReference.ts, shared with INDIRECT). - Docs: the license-key placeholder in the INDIRECT snippets; DEPENDENCY-GRAPH.md and INTERPRETER.md updated; changelog. - Remove runtimeEdgesAdded, TopSortResult.deferred and the TOP_SORT stat, which nothing used, and move two JSDoc blocks back to their declarations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tobiadefami
marked this pull request as ready for review
November 28, 2026 13:45
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #1843 +/- ##
===========================================
+ Coverage 97.76% 97.78% +0.02%
===========================================
Files 212 216 +4
Lines 19159 19728 +569
Branches 4540 4658 +118
===========================================
+ Hits 18730 19292 +562
Misses 429 429
- Partials 0 7 +7
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Warning
High risk: Rewrites the core recalculation engine (TopSort, Evaluator, DependencyGraph) to support runtime dependencies, so any defect affects every formula recalculation, cycle handling, and structural-change propagation across the whole library.
Full review: no issues found.
Want a deeper review? Comment /review improve on its own line: a full review of the latest commit with an extra fix-oriented pass (about 2x the cost).
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
The PR adds the INDIRECT function, without making it volatile.
Why: INDIRECT reads an address known only at evaluation time. The parser cannot add that dependency to the graph.
Approach: each formula keeps the cells and ranges INDIRECT read in its last evaluation as dependencies in the graph, so an edit re-runs only the formulas that read what changed. If a target isn't computed yet in the current pass, the formula stops, the sort computes the target first, then runs the formula again from the start. I built and measured two alternatives and dropped them:
What changed:
IndirectPlugin.ts: resolves A1 and R1C1 text on any sheet:"B:B","2:3","C2"and"R2"in R1C1), and named expressions;#REF!, including a row or column number too large to be a number;DependencyGraph.ts,FormulaVertex.ts,Graph.ts: store each cell or range that INDIRECT read as a runtime dependency of the formula. Reading a range again doesn't revisit its cells.DependencyGraph.ts,dependencyTransformers/: row, column, cell and sheet-merge changes move the recorded addresses with the cells, so an empty cell that loses its last reader is removed.TopSort.ts,Evaluator.ts,EvaluationPass.ts,EvaluationDeferred.ts:try/catch.SimpleRangeValue.ts: an INDIRECT range records its dependency on first use of its values or address.InformationPlugin.ts,FormulaTextPlugin.ts,Interpreter.ts,FunctionPlugin.ts: ROW, COLUMN, ROWS, COLUMNS, SHEET, SHEETS, FORMULATEXT and ISFORMULA take a reference returned by INDIRECT like the same reference typed into the formula, without reading its cells or recording them as dependencies, so a formula inside the range it measures is no cycle. Other functions return values: a range returned by ARRAYFORMULA is not a reference, as in Google Sheets.namedReference.ts: resolves a named cell or range from the name's formula, for INDIRECT and for ROW and COLUMN.Operations.ts,GraphBuilder.ts: sheet, name and structure changes mark INDIRECT formulas dirty.lookup-and-reference.ts: the catalogue entry for INDIRECT.functionCapabilities.ts: INDIRECT in thefun:lookup.clicense group, with the other lookup and reference functions.i18n/languages/: the name of INDIRECT in every language pack, from Microsoft's function pages for each language.DEPENDENCY-GRAPH.md;referenceExpectedand the structure flag inINTERPRETER.md.Result:
=INDIRECT("B"&A1)recalculates when A1 or the target changes, and not on unrelated edits.Side effect on existing functions: ROW and COLUMN of a named cell or range, and ROWS and COLUMNS of a named whole column or row or of a whole column or row returned by ARRAYFORMULA, now give the same result as the literal reference:
myRange=Sheet1!$B$2:$C$3,myCell=Sheet1!$B$5,myCol=Sheet1!$A:$A)=ROW(myRange)#VALUE!=ROW(myCell)#N/A=ROWS(myCol)maxRowsmaxRows=ROWS(ARRAYFORMULA(A:A))maxRowsmaxRowsHow did you test your changes?
Paired branch in
hyperformula-tests:feature/hf-27-phase2(handsontable/hyperformula-tests#104).npx jeston the INDIRECT specs:function-indirect.spec.ts,function-indirect-whole-columns-rows.spec.ts,indirect-dependency-graph.spec.ts,graph.spec.ts,address-representation-converters.spec.ts;npm run test:browser): 17,199 of 17,248 run in Chrome and in Firefox, none failed (49 skipped).npm run lint(no errors),npm run verify:typings,npm run docs:generate-function-docs(INDIRECT listed),git diff --check.AI assistance
Claude Code wrote the implementation, docs and tests, and ran the Excel and Google Sheets checks.
Compatibility with Excel and Google Sheets
Excel: Microsoft Excel Online. Google Sheets: checked only for ranges returned by ARRAYFORMULA (below the table).
Data on the formula's sheet: B1 = 5, C1 = 11, B2 = 7, C2 = 13, B8 = 1.333, and nothing else in column C or row 1. Sheet2!A1 = 42, 'My Sheet'!A1 = 7. Names:
Georgerefers to B8,Konstto=5.=INDIRECT("B1")=INDIRECT(F21), where F21 holds the textB1=INDIRECT("'My Sheet'!A1")=SUM(INDIRECT("B1:C2"))=SUM(INDIRECT("C2:B1"))=INDIRECT("George")=INDIRECT("Konst")#REF!#REF!=SUM(INDIRECT("C:C"))=SUM(INDIRECT("1:1"))=ROWS(INDIRECT("C:C"))=SUM(INDIRECT("R1C2:R2C3", FALSE()))=INDIRECT("B1 ")=INDIRECT("B0")#REF!#REF!=INDIRECT(1/0)#DIV/0!#DIV/0!=SUM(INDIRECT("A:A")), entered in column A#CYCLE!W1K2:W2K3. HyperFormula reads R and C in every language (see the known limitations).ROWS: HyperFormula's sheet has 40,000 rows by default (maxRows).Functions that take a reference, with A1 =
=1+1, A2 =xand a sheet named Sheet2:=SHEET(INDIRECT("Sheet2!A1"))=SHEETS(INDIRECT("A1"))=FORMULATEXT(INDIRECT("A1"))=1+1=1+1=FORMULATEXT(INDIRECT("A2"))#N/A#N/A=ISFORMULA(INDIRECT("A1"))=ISFORMULA(INDIRECT("A0"))#REF!#REF!=FORMULATEXT(INDIRECT("A1")), entered in A1Google Sheets treats a range returned by ARRAYFORMULA as a value: ROW, SHEET, SHEETS, FORMULATEXT and ISFORMULA of
ARRAYFORMULA(range)return an error there and in HyperFormula, and ROWS and COLUMNS ofARRAYFORMULA(A:A)andARRAYFORMULA(1:1)count the whole sheet in both.Public API changes
FunctionPlugin.runFunctionWithReferenceArgumenttakes an optional last argument,referenceExpected, defaultfalse. ROW, COLUMN, SHEET, SHEETS, FORMULATEXT and ISFORMULA set it. A custom function that takes a reference keeps reading an INDIRECT range's cells and recording them as dependencies.Out of scope and follow-ups
"D1#").Types of changes
Related issues
Checklist
dev-docs/pages this change affects – or none needed it.🤖 Generated with Claude Code