Skip to content

New REFERENCES edge type#217

Merged
tirth8205 merged 3 commits intotirth8205:mainfrom
geeknik:main
Apr 11, 2026
Merged

New REFERENCES edge type#217
tirth8205 merged 3 commits intotirth8205:mainfrom
geeknik:main

Conversation

@geeknik
Copy link
Copy Markdown
Contributor

@geeknik geeknik commented Apr 11, 2026

Helps mitigate #160 with new REFERENCES edge type.

The parser now detects function-as-value references — identifiers in value positions that refer to functions without directly calling them. This covers the most common static patterns that cause false positives in dead code detection.

Patterns detected (JS/TS and Python):

  ┌───────────────────────┬───────────────────┐
  │        Pattern        │      Example      │
  ├───────────────────────┼───────────────────┤
  │ Object literal values │ { handler: myFn } │
  ├───────────────────────┼───────────────────┤
  │ Shorthand properties  │ { myFn }          │
  ├───────────────────────┼───────────────────┤
  │ Property assignments  │ map['key'] = myFn │
  ├───────────────────────┼───────────────────┤
  │ Array/list elements   │ [fn1, fn2, fn3]   │
  ├───────────────────────┼───────────────────┤
  │ Callback arguments    │ register(myFn)    │
  ├───────────────────────┼───────────────────┤
  │ Python dict values    │ {'key': my_fn}    │
  └───────────────────────┴───────────────────┘

Files modified:

  • code_review_graph/parser.py — Added _extract_value_references method with 5 sub-extractors (_ref_from_pair, _ref_from_assignment, _ref_from_array, _ref_from_arguments, _emit_reference_if_known). Updated _resolve_call_targets to resolve REFERENCES edges. Integrated into _extract_from_tree.
  • code_review_graph/refactor.py — find_dead_code now checks for REFERENCES edges. Updated docstring with dynamic dispatch caveats.
  • code_review_graph/graph.py — Updated edge kind documentation.
  • tests/test_parser.py — 12 new tests in TestValueReferences class.
  • tests/test_refactor.py — 4 new tests in TestFindDeadCodeWithReferences class.
  • tests/fixtures/sample_map_dispatch.ts — New TS fixture with dispatch patterns.
  • tests/fixtures/sample_map_dispatch.py — New Python fixture with dispatch patterns.

Safety constraints:

  • Only emits REFERENCES for identifiers that are known (in defined_names or import_map)
  • Filters out constants (all-uppercase), single-char names, and language keywords
  • Works at both module scope and function scope

Known remaining limitations (documented in docstring):

  • Fully dynamic keys (map[computedKey()] = fn) — requires abstract interpretation
  • Reflect.apply / Function.prototype.call indirection
  • Runtime require() / dynamic import()

geeknik added 2 commits April 11, 2026 08:00
The parser now detects function-as-value references — identifiers in value positions that refer to functions without directly calling them. This covers the most common static patterns that cause false positives in dead code detection.

Patterns detected (JS/TS and Python):

  ┌───────────────────────┬───────────────────┐
  │        Pattern        │      Example      │
  ├───────────────────────┼───────────────────┤
  │ Object literal values │ { handler: myFn } │
  ├───────────────────────┼───────────────────┤
  │ Shorthand properties  │ { myFn }          │
  ├───────────────────────┼───────────────────┤
  │ Property assignments  │ map['key'] = myFn │
  ├───────────────────────┼───────────────────┤
  │ Array/list elements   │ [fn1, fn2, fn3]   │
  ├───────────────────────┼───────────────────┤
  │ Callback arguments    │ register(myFn)    │
  ├───────────────────────┼───────────────────┤
  │ Python dict values    │ {'key': my_fn}    │
  └───────────────────────┴───────────────────┘

Files modified:

  - code_review_graph/parser.py — Added _extract_value_references method with 5 sub-extractors (_ref_from_pair, _ref_from_assignment, _ref_from_array, _ref_from_arguments, _emit_reference_if_known). Updated _resolve_call_targets to resolve REFERENCES edges. Integrated into _extract_from_tree.
  - code_review_graph/refactor.py — find_dead_code now checks for REFERENCES edges. Updated docstring with dynamic dispatch caveats.
  - code_review_graph/graph.py — Updated edge kind documentation.
  - tests/test_parser.py — 12 new tests in TestValueReferences class.
  - tests/test_refactor.py — 4 new tests in TestFindDeadCodeWithReferences class.
  - tests/fixtures/sample_map_dispatch.ts — New TS fixture with dispatch patterns.
  - tests/fixtures/sample_map_dispatch.py — New Python fixture with dispatch patterns.

Safety constraints:

  - Only emits REFERENCES for identifiers that are known (in defined_names or import_map)
  - Filters out constants (all-uppercase), single-char names, and language keywords
  - Works at both module scope and function scope

Known remaining limitations (documented in docstring):

  - Fully dynamic keys (map[computedKey()] = fn) — requires abstract interpretation
  - Reflect.apply / Function.prototype.call indirection
  - Runtime require() / dynamic import()
New Python fixture with dispatch patterns.
@geeknik
Copy link
Copy Markdown
Contributor Author

geeknik commented Apr 11, 2026

On a small repo I'm working on...
Before: Full build: 32 files, 213 nodes, 1561 edges (postprocess=full)
After: Full build: 37 files, 296 nodes, 2680 edges (postprocess=full)

@tirth8205 tirth8205 merged commit 1c6cef6 into tirth8205:main Apr 11, 2026
9 checks passed
tirth8205 added a commit that referenced this pull request Apr 11, 2026
Unreleased fixes since v2.2.2 that users are complaining about:
- #208 Claude Code hook schema (fixes #97, #138, #163, #168, #172, #182,
  #188, #191, #201) — v2.2.2 generates an invalid hooks schema and
  timeouts in ms instead of seconds; PreCommit is also not a real event.
- #205 SQLite transaction nesting (fixes #110, #135, #181) — implicit
  transactions from the legacy sqlite3 default caused "cannot start a
  transaction within a transaction" on update.
- #166 Go method receivers resolved from field_identifier.
- #170 UTF-8 decode errors in detect_changes (fixes #169).
- #142 --platform target filters (fixes #133).
- #213 / #183 large-repo community detection hangs.
- #220 CI lint + tomllib on Python 3.10.
- #159 missing pytest-cov dev dep.
- #154 JSX component CALLS edges.

Plus features: #177 Codex, #165 Luau (#153), #217 REFERENCES edge,
#215 recurse_submodules, #185 gitignore default (#175), #171 gitignore
docs (#157).

Verified locally on Python 3.11: ruff clean, mypy clean, bandit clean,
691 tests pass, coverage 73.72%.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tirth8205 tirth8205 mentioned this pull request Apr 11, 2026
5 tasks
tirth8205 added a commit that referenced this pull request Apr 11, 2026
Unreleased fixes since v2.2.2 that users are complaining about:
- #208 Claude Code hook schema (fixes #97, #138, #163, #168, #172, #182,
  #188, #191, #201) — v2.2.2 generates an invalid hooks schema and
  timeouts in ms instead of seconds; PreCommit is also not a real event.
- #205 SQLite transaction nesting (fixes #110, #135, #181) — implicit
  transactions from the legacy sqlite3 default caused "cannot start a
  transaction within a transaction" on update.
- #166 Go method receivers resolved from field_identifier.
- #170 UTF-8 decode errors in detect_changes (fixes #169).
- #142 --platform target filters (fixes #133).
- #213 / #183 large-repo community detection hangs.
- #220 CI lint + tomllib on Python 3.10.
- #159 missing pytest-cov dev dep.
- #154 JSX component CALLS edges.

Plus features: #177 Codex, #165 Luau (#153), #217 REFERENCES edge,
#215 recurse_submodules, #185 gitignore default (#175), #171 gitignore
docs (#157).

Verified locally on Python 3.11: ruff clean, mypy clean, bandit clean,
691 tests pass, coverage 73.72%.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants