Registry Mirror
Skip to content

codegraph exports: dynamic-dispatch via registry object literal (LANGUAGE_REGISTRY) not credited as consumer #1779

Closed

Description

@carlos-alm

Context

Discovered during Titan audit (phase: gauntlet, date: 2026-07-02).

Description

codegraph exports <file> -T --json reports every per-language extractor entry function (e.g. extractRSymbols, extractDartSymbols) as a zero-consumer dead export. These functions are in fact referenced — via LANGUAGE_REGISTRY in src/domain/parser.ts, where each is assigned to an extractor property in an object literal and invoked later through dynamic property dispatch (registry[lang].extractor(...)), not a direct static call. The exports/dead-role analysis does not attribute a consumer edge for this registry-object-literal + dynamic-dispatch pattern, so it false-positives on every one of the 34 language extractors' top-level entry function.

Verified manually via grep in parser.ts for extractRSymbols/extractDartSymbols — both are demonstrably wired up and invoked.

Additional Context

Repro:

codegraph exports src/extractors/r.ts -T --json
codegraph exports src/extractors/dart.ts -T --json

Both report the top-level extractor function as a zero-consumer dead export despite being referenced via LANGUAGE_REGISTRY[lang].extractor(...).

This is a distinct root cause from #1724 (type-only imports not credited) and #1730 (renamed imports not credited) — here the consumer edge is missing because the reference is an object-literal-property assignment followed by dynamic dispatch through a computed property access, not any form of static import.

Source

  • Titan phase: gauntlet
  • Severity: limitation
  • Category: codegraph

Activity

  1. added
    titan-audit
    on Jul 4, 2026
  2. carlos-alm commented on Jul 6, 2026

    @carlos-alm
    ContributorAuthor

    Already fixed — by #1771's value-ref reference-edge mechanism, which landed earlier in this same batch (commit 6515186, "fix: emit reference edges for function identifiers used as object-literal values"). No code change needed here.

    Root cause overlap

    #1771 fixed exactly this pattern: a bare function identifier used as an object-literal property value ({ resolve: someFunction } / shorthand { someFunction }), which previously produced no edge at all. The fix (collectObjectLiteralValueRefCall in src/extractors/javascript.ts, mirrored in crates/codegraph-core/src/extractors/javascript.rs) fires unconditionally on every pair AST node in any parsed JS/TS/TSX file, emitting a calls edge with dynamic=1, dynamicKind='value-ref' whenever the property value is a bare identifier resolving to a function/method.

    LANGUAGE_REGISTRY's entries ({ id: 'r', extensions: [...], grammarFile: '...', extractor: extractRSymbols, required: false }) are structurally identical to that pattern — extractor: extractRSymbols is a pair node whose value is a bare identifier. src/domain/analysis/exports.ts's consumer query (kind IN ('calls', 'imports-type'), unchanged since #1724) already credits calls edges regardless of the dynamic/dynamicKind flags, so this flows through with zero additional changes — exactly the "reuse the existing calls kind" design #1771 called out.

    Verification

    Built this repo's own graph fresh from the current branch tip (native engine, then rebuilt with --engine wasm — both produce identical results) and ran the exact repro:

    $ codegraph exports src/extractors/r.ts -T --json
    "extractRSymbols": consumerCount: 2, role: "core"
    consumers: [
      { name: "LANGUAGE_REGISTRY", file: "src/domain/parser.ts", line: 768 },
      { name: "LANGUAGE_REGISTRY", file: "src/domain/wasm-worker-entry.ts", line: 149 }
    ]
    
    $ codegraph exports src/extractors/dart.ts -T --json
    "extractDartSymbols": consumerCount: 2, role: "core"  (same two consumers)
    

    (The second consumer is a deliberate local duplicate of LANGUAGE_REGISTRY inside wasm-worker-entry.ts, for worker-thread cache isolation — same object-literal shape, also correctly credited.)

    codegraph fn-impact confirms real transitive dependents for both:

    $ codegraph fn-impact extractRSymbols -T
    Level 1 (2 functions): LANGUAGE_REGISTRY (parser.ts:768), LANGUAGE_REGISTRY (wasm-worker-entry.ts:149)
    
    $ codegraph fn-impact extractDartSymbols -T
    Level 1 (2 functions): LANGUAGE_REGISTRY (parser.ts:768), LANGUAGE_REGISTRY (wasm-worker-entry.ts:149)
    

    Spot-checked every other extractor entry in src/extractors/*.ts (bash, c, clojure, cpp, csharp, cuda, elixir, erlang, fsharp, gleam, go, groovy, haskell, hcl, java, javascript's extractSymbols, julia, kotlin, lua, objc, ocaml, php, python, ruby, rust, scala, solidity, swift, verilog, zig) — all 34 languages show consumerCount: 2 with a non-dead role (core or utility), on both engines.

    Repo-wide sweep confirms no false positives remain: codegraph roles --role dead -T --json reports 641 dead symbols, none named extract*Symbols.

    Full verification gate: npm run lint clean (829 files), npm test full suite green (220 test files, 3589 passed, 30 skipped, 2 todo, 0 failed).

    No commit needed — closing as already resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    titan-audit

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions