@optave/codegraph 3.13.0 → 3.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -34
- package/dist/ast-analysis/engine.d.ts.map +1 -1
- package/dist/ast-analysis/engine.js +38 -40
- package/dist/ast-analysis/engine.js.map +1 -1
- package/dist/ast-analysis/rules/b2.d.ts +7 -0
- package/dist/ast-analysis/rules/b2.d.ts.map +1 -0
- package/dist/ast-analysis/rules/b2.js +240 -0
- package/dist/ast-analysis/rules/b2.js.map +1 -0
- package/dist/ast-analysis/rules/b3.d.ts +6 -0
- package/dist/ast-analysis/rules/b3.d.ts.map +1 -0
- package/dist/ast-analysis/rules/b3.js +105 -0
- package/dist/ast-analysis/rules/b3.js.map +1 -0
- package/dist/ast-analysis/rules/b4.d.ts +9 -0
- package/dist/ast-analysis/rules/b4.d.ts.map +1 -0
- package/dist/ast-analysis/rules/b4.js +361 -0
- package/dist/ast-analysis/rules/b4.js.map +1 -0
- package/dist/ast-analysis/rules/b5.d.ts +4 -0
- package/dist/ast-analysis/rules/b5.d.ts.map +1 -0
- package/dist/ast-analysis/rules/b5.js +52 -0
- package/dist/ast-analysis/rules/b5.js.map +1 -0
- package/dist/ast-analysis/rules/c.d.ts +4 -0
- package/dist/ast-analysis/rules/c.d.ts.map +1 -0
- package/dist/ast-analysis/rules/c.js +143 -0
- package/dist/ast-analysis/rules/c.js.map +1 -0
- package/dist/ast-analysis/rules/index.d.ts.map +1 -1
- package/dist/ast-analysis/rules/index.js +34 -0
- package/dist/ast-analysis/rules/index.js.map +1 -1
- package/dist/ast-analysis/rules/javascript.d.ts.map +1 -1
- package/dist/ast-analysis/rules/javascript.js +3 -0
- package/dist/ast-analysis/rules/javascript.js.map +1 -1
- package/dist/ast-analysis/shared.d.ts.map +1 -1
- package/dist/ast-analysis/shared.js +2 -0
- package/dist/ast-analysis/shared.js.map +1 -1
- package/dist/ast-analysis/visitor-utils.d.ts +1 -0
- package/dist/ast-analysis/visitor-utils.d.ts.map +1 -1
- package/dist/ast-analysis/visitor-utils.js +5 -0
- package/dist/ast-analysis/visitor-utils.js.map +1 -1
- package/dist/ast-analysis/visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitor.js +60 -47
- package/dist/ast-analysis/visitor.js.map +1 -1
- package/dist/ast-analysis/visitors/cfg-visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitors/cfg-visitor.js +126 -76
- package/dist/ast-analysis/visitors/cfg-visitor.js.map +1 -1
- package/dist/ast-analysis/visitors/complexity-visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitors/complexity-visitor.js +27 -15
- package/dist/ast-analysis/visitors/complexity-visitor.js.map +1 -1
- package/dist/ast-analysis/visitors/dataflow-visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitors/dataflow-visitor.js +54 -21
- package/dist/ast-analysis/visitors/dataflow-visitor.js.map +1 -1
- package/dist/cli/commands/config.d.ts.map +1 -1
- package/dist/cli/commands/config.js +137 -134
- package/dist/cli/commands/config.js.map +1 -1
- package/dist/cli/commands/roles.d.ts.map +1 -1
- package/dist/cli/commands/roles.js +6 -1
- package/dist/cli/commands/roles.js.map +1 -1
- package/dist/db/better-sqlite3.d.ts +2 -1
- package/dist/db/better-sqlite3.d.ts.map +1 -1
- package/dist/db/better-sqlite3.js.map +1 -1
- package/dist/db/connection.d.ts +7 -1
- package/dist/db/connection.d.ts.map +1 -1
- package/dist/db/connection.js +20 -5
- package/dist/db/connection.js.map +1 -1
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +1 -1
- package/dist/db/index.js.map +1 -1
- package/dist/db/migrations.d.ts.map +1 -1
- package/dist/db/migrations.js +68 -0
- package/dist/db/migrations.js.map +1 -1
- package/dist/db/repository/build-stmts.d.ts.map +1 -1
- package/dist/db/repository/build-stmts.js +18 -0
- package/dist/db/repository/build-stmts.js.map +1 -1
- package/dist/db/repository/dataflow.d.ts +5 -0
- package/dist/db/repository/dataflow.d.ts.map +1 -1
- package/dist/db/repository/dataflow.js +14 -0
- package/dist/db/repository/dataflow.js.map +1 -1
- package/dist/db/repository/index.d.ts +1 -1
- package/dist/db/repository/index.d.ts.map +1 -1
- package/dist/db/repository/index.js +1 -1
- package/dist/db/repository/index.js.map +1 -1
- package/dist/db/repository/native-repository.d.ts.map +1 -1
- package/dist/db/repository/native-repository.js +47 -34
- package/dist/db/repository/native-repository.js.map +1 -1
- package/dist/domain/analysis/context.d.ts +2 -2
- package/dist/domain/analysis/dependencies.d.ts +2 -2
- package/dist/domain/analysis/diff-impact.d.ts +2 -2
- package/dist/domain/analysis/fn-impact.d.ts +3 -1
- package/dist/domain/analysis/fn-impact.d.ts.map +1 -1
- package/dist/domain/analysis/fn-impact.js +4 -0
- package/dist/domain/analysis/fn-impact.js.map +1 -1
- package/dist/domain/analysis/implementations.d.ts +2 -2
- package/dist/domain/analysis/module-map.d.ts.map +1 -1
- package/dist/domain/analysis/module-map.js +32 -5
- package/dist/domain/analysis/module-map.js.map +1 -1
- package/dist/domain/analysis/roles.d.ts +7 -1
- package/dist/domain/analysis/roles.d.ts.map +1 -1
- package/dist/domain/analysis/roles.js +16 -0
- package/dist/domain/analysis/roles.js.map +1 -1
- package/dist/domain/analysis/symbol-lookup.d.ts +4 -4
- package/dist/domain/graph/builder/call-resolver.d.ts +17 -5
- package/dist/domain/graph/builder/call-resolver.d.ts.map +1 -1
- package/dist/domain/graph/builder/call-resolver.js +85 -220
- package/dist/domain/graph/builder/call-resolver.js.map +1 -1
- package/dist/domain/graph/builder/context.d.ts +1 -0
- package/dist/domain/graph/builder/context.d.ts.map +1 -1
- package/dist/domain/graph/builder/context.js.map +1 -1
- package/dist/domain/graph/builder/helpers.d.ts +16 -1
- package/dist/domain/graph/builder/helpers.d.ts.map +1 -1
- package/dist/domain/graph/builder/helpers.js +162 -72
- package/dist/domain/graph/builder/helpers.js.map +1 -1
- package/dist/domain/graph/builder/incremental.d.ts.map +1 -1
- package/dist/domain/graph/builder/incremental.js +166 -97
- package/dist/domain/graph/builder/incremental.js.map +1 -1
- package/dist/domain/graph/builder/pipeline.d.ts.map +1 -1
- package/dist/domain/graph/builder/pipeline.js +10 -4
- package/dist/domain/graph/builder/pipeline.js.map +1 -1
- package/dist/domain/graph/builder/stages/build-edges.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/build-edges.js +496 -250
- package/dist/domain/graph/builder/stages/build-edges.js.map +1 -1
- package/dist/domain/graph/builder/stages/collect-files.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/collect-files.js +10 -7
- package/dist/domain/graph/builder/stages/collect-files.js.map +1 -1
- package/dist/domain/graph/builder/stages/detect-changes.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/detect-changes.js +2 -1
- package/dist/domain/graph/builder/stages/detect-changes.js.map +1 -1
- package/dist/domain/graph/builder/stages/native-orchestrator.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/native-orchestrator.js +895 -545
- package/dist/domain/graph/builder/stages/native-orchestrator.js.map +1 -1
- package/dist/domain/graph/resolver/points-to.d.ts.map +1 -1
- package/dist/domain/graph/resolver/points-to.js +105 -57
- package/dist/domain/graph/resolver/points-to.js.map +1 -1
- package/dist/domain/graph/resolver/strategy.d.ts +61 -0
- package/dist/domain/graph/resolver/strategy.d.ts.map +1 -0
- package/dist/domain/graph/resolver/strategy.js +222 -0
- package/dist/domain/graph/resolver/strategy.js.map +1 -0
- package/dist/domain/graph/watcher.d.ts.map +1 -1
- package/dist/domain/graph/watcher.js +16 -9
- package/dist/domain/graph/watcher.js.map +1 -1
- package/dist/domain/parser.d.ts +12 -0
- package/dist/domain/parser.d.ts.map +1 -1
- package/dist/domain/parser.js +12 -2
- package/dist/domain/parser.js.map +1 -1
- package/dist/domain/queries.d.ts +1 -1
- package/dist/domain/queries.d.ts.map +1 -1
- package/dist/domain/queries.js +1 -1
- package/dist/domain/queries.js.map +1 -1
- package/dist/domain/wasm-worker-entry.js +3 -0
- package/dist/domain/wasm-worker-entry.js.map +1 -1
- package/dist/domain/wasm-worker-pool.d.ts.map +1 -1
- package/dist/domain/wasm-worker-pool.js +24 -5
- package/dist/domain/wasm-worker-pool.js.map +1 -1
- package/dist/domain/wasm-worker-protocol.d.ts +7 -0
- package/dist/domain/wasm-worker-protocol.d.ts.map +1 -1
- package/dist/extractors/dart.js +48 -3
- package/dist/extractors/dart.js.map +1 -1
- package/dist/extractors/groovy.js +62 -3
- package/dist/extractors/groovy.js.map +1 -1
- package/dist/extractors/helpers.d.ts +4 -2
- package/dist/extractors/helpers.d.ts.map +1 -1
- package/dist/extractors/helpers.js +5 -1
- package/dist/extractors/helpers.js.map +1 -1
- package/dist/extractors/java.js +77 -1
- package/dist/extractors/java.js.map +1 -1
- package/dist/extractors/javascript.d.ts.map +1 -1
- package/dist/extractors/javascript.js +549 -163
- package/dist/extractors/javascript.js.map +1 -1
- package/dist/extractors/kotlin.js +58 -3
- package/dist/extractors/kotlin.js.map +1 -1
- package/dist/extractors/objc.js +25 -2
- package/dist/extractors/objc.js.map +1 -1
- package/dist/extractors/scala.js +62 -2
- package/dist/extractors/scala.js.map +1 -1
- package/dist/extractors/swift.js +52 -3
- package/dist/extractors/swift.js.map +1 -1
- package/dist/features/audit.js +26 -23
- package/dist/features/audit.js.map +1 -1
- package/dist/features/boundaries.d.ts.map +1 -1
- package/dist/features/boundaries.js +12 -9
- package/dist/features/boundaries.js.map +1 -1
- package/dist/features/cfg.d.ts.map +1 -1
- package/dist/features/cfg.js +25 -18
- package/dist/features/cfg.js.map +1 -1
- package/dist/features/check.d.ts.map +1 -1
- package/dist/features/check.js +18 -5
- package/dist/features/check.js.map +1 -1
- package/dist/features/communities.d.ts +4 -2
- package/dist/features/communities.d.ts.map +1 -1
- package/dist/features/communities.js +6 -4
- package/dist/features/communities.js.map +1 -1
- package/dist/features/dataflow.d.ts +60 -0
- package/dist/features/dataflow.d.ts.map +1 -1
- package/dist/features/dataflow.js +530 -6
- package/dist/features/dataflow.js.map +1 -1
- package/dist/features/manifesto.d.ts.map +1 -1
- package/dist/features/manifesto.js +59 -72
- package/dist/features/manifesto.js.map +1 -1
- package/dist/features/sequence.d.ts.map +1 -1
- package/dist/features/sequence.js +27 -22
- package/dist/features/sequence.js.map +1 -1
- package/dist/features/snapshot.d.ts.map +1 -1
- package/dist/features/snapshot.js +36 -28
- package/dist/features/snapshot.js.map +1 -1
- package/dist/features/structure.d.ts.map +1 -1
- package/dist/features/structure.js +150 -62
- package/dist/features/structure.js.map +1 -1
- package/dist/features/triage.d.ts.map +1 -1
- package/dist/features/triage.js +18 -11
- package/dist/features/triage.js.map +1 -1
- package/dist/graph/algorithms/bfs.d.ts +1 -1
- package/dist/graph/algorithms/bfs.d.ts.map +1 -1
- package/dist/graph/algorithms/bfs.js +14 -13
- package/dist/graph/algorithms/bfs.js.map +1 -1
- package/dist/graph/algorithms/tarjan.d.ts.map +1 -1
- package/dist/graph/algorithms/tarjan.js +5 -0
- package/dist/graph/algorithms/tarjan.js.map +1 -1
- package/dist/graph/builders/dependency.js +28 -22
- package/dist/graph/builders/dependency.js.map +1 -1
- package/dist/graph/classifiers/roles.d.ts +10 -1
- package/dist/graph/classifiers/roles.d.ts.map +1 -1
- package/dist/graph/classifiers/roles.js +60 -6
- package/dist/graph/classifiers/roles.js.map +1 -1
- package/dist/infrastructure/config.d.ts +10 -0
- package/dist/infrastructure/config.d.ts.map +1 -1
- package/dist/infrastructure/config.js +31 -3
- package/dist/infrastructure/config.js.map +1 -1
- package/dist/infrastructure/registry.d.ts +0 -7
- package/dist/infrastructure/registry.d.ts.map +1 -1
- package/dist/infrastructure/registry.js +29 -13
- package/dist/infrastructure/registry.js.map +1 -1
- package/dist/infrastructure/update-check.d.ts.map +1 -1
- package/dist/infrastructure/update-check.js +49 -31
- package/dist/infrastructure/update-check.js.map +1 -1
- package/dist/mcp/server.d.ts +2 -10
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools/ast-query.d.ts +1 -1
- package/dist/mcp/tools/ast-query.d.ts.map +1 -1
- package/dist/mcp/tools/audit.d.ts +1 -1
- package/dist/mcp/tools/audit.d.ts.map +1 -1
- package/dist/mcp/tools/batch-query.d.ts +1 -1
- package/dist/mcp/tools/batch-query.d.ts.map +1 -1
- package/dist/mcp/tools/branch-compare.d.ts +1 -1
- package/dist/mcp/tools/branch-compare.d.ts.map +1 -1
- package/dist/mcp/tools/brief.d.ts +1 -1
- package/dist/mcp/tools/brief.d.ts.map +1 -1
- package/dist/mcp/tools/cfg.d.ts +1 -1
- package/dist/mcp/tools/cfg.d.ts.map +1 -1
- package/dist/mcp/tools/check.d.ts +1 -1
- package/dist/mcp/tools/check.d.ts.map +1 -1
- package/dist/mcp/tools/co-changes.d.ts +1 -1
- package/dist/mcp/tools/co-changes.d.ts.map +1 -1
- package/dist/mcp/tools/code-owners.d.ts +1 -1
- package/dist/mcp/tools/code-owners.d.ts.map +1 -1
- package/dist/mcp/tools/communities.d.ts +1 -1
- package/dist/mcp/tools/communities.d.ts.map +1 -1
- package/dist/mcp/tools/complexity.d.ts +1 -1
- package/dist/mcp/tools/complexity.d.ts.map +1 -1
- package/dist/mcp/tools/context.d.ts +1 -1
- package/dist/mcp/tools/context.d.ts.map +1 -1
- package/dist/mcp/tools/dataflow.d.ts +1 -1
- package/dist/mcp/tools/dataflow.d.ts.map +1 -1
- package/dist/mcp/tools/diff-impact.d.ts +1 -1
- package/dist/mcp/tools/diff-impact.d.ts.map +1 -1
- package/dist/mcp/tools/execution-flow.d.ts +1 -1
- package/dist/mcp/tools/execution-flow.d.ts.map +1 -1
- package/dist/mcp/tools/export-graph.d.ts +1 -1
- package/dist/mcp/tools/export-graph.d.ts.map +1 -1
- package/dist/mcp/tools/file-deps.d.ts +1 -1
- package/dist/mcp/tools/file-deps.d.ts.map +1 -1
- package/dist/mcp/tools/file-exports.d.ts +1 -1
- package/dist/mcp/tools/file-exports.d.ts.map +1 -1
- package/dist/mcp/tools/find-cycles.d.ts +1 -1
- package/dist/mcp/tools/find-cycles.d.ts.map +1 -1
- package/dist/mcp/tools/fn-impact.d.ts +1 -1
- package/dist/mcp/tools/fn-impact.d.ts.map +1 -1
- package/dist/mcp/tools/impact-analysis.d.ts +1 -1
- package/dist/mcp/tools/impact-analysis.d.ts.map +1 -1
- package/dist/mcp/tools/implementations.d.ts +1 -1
- package/dist/mcp/tools/implementations.d.ts.map +1 -1
- package/dist/mcp/tools/index.d.ts +2 -5
- package/dist/mcp/tools/index.d.ts.map +1 -1
- package/dist/mcp/tools/index.js.map +1 -1
- package/dist/mcp/tools/interfaces.d.ts +1 -1
- package/dist/mcp/tools/interfaces.d.ts.map +1 -1
- package/dist/mcp/tools/list-functions.d.ts +1 -1
- package/dist/mcp/tools/list-functions.d.ts.map +1 -1
- package/dist/mcp/tools/list-repos.d.ts +1 -1
- package/dist/mcp/tools/list-repos.d.ts.map +1 -1
- package/dist/mcp/tools/module-map.d.ts +1 -1
- package/dist/mcp/tools/module-map.d.ts.map +1 -1
- package/dist/mcp/tools/node-roles.d.ts +1 -1
- package/dist/mcp/tools/node-roles.d.ts.map +1 -1
- package/dist/mcp/tools/path.d.ts +1 -1
- package/dist/mcp/tools/path.d.ts.map +1 -1
- package/dist/mcp/tools/query.d.ts +1 -1
- package/dist/mcp/tools/query.d.ts.map +1 -1
- package/dist/mcp/tools/semantic-search.d.ts +1 -1
- package/dist/mcp/tools/semantic-search.d.ts.map +1 -1
- package/dist/mcp/tools/sequence.d.ts +1 -1
- package/dist/mcp/tools/sequence.d.ts.map +1 -1
- package/dist/mcp/tools/structure.d.ts +1 -1
- package/dist/mcp/tools/structure.d.ts.map +1 -1
- package/dist/mcp/tools/symbol-children.d.ts +1 -1
- package/dist/mcp/tools/symbol-children.d.ts.map +1 -1
- package/dist/mcp/tools/triage.d.ts +1 -1
- package/dist/mcp/tools/triage.d.ts.map +1 -1
- package/dist/mcp/tools/where.d.ts +1 -1
- package/dist/mcp/tools/where.d.ts.map +1 -1
- package/dist/mcp/types.d.ts +19 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +6 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/presentation/queries-cli/index.d.ts +1 -1
- package/dist/presentation/queries-cli/index.d.ts.map +1 -1
- package/dist/presentation/queries-cli/index.js +1 -1
- package/dist/presentation/queries-cli/index.js.map +1 -1
- package/dist/presentation/queries-cli/overview.d.ts +1 -0
- package/dist/presentation/queries-cli/overview.d.ts.map +1 -1
- package/dist/presentation/queries-cli/overview.js +20 -1
- package/dist/presentation/queries-cli/overview.js.map +1 -1
- package/dist/presentation/queries-cli.d.ts +1 -1
- package/dist/presentation/queries-cli.d.ts.map +1 -1
- package/dist/presentation/queries-cli.js +1 -1
- package/dist/presentation/queries-cli.js.map +1 -1
- package/dist/presentation/viewer.d.ts.map +1 -1
- package/dist/presentation/viewer.js +45 -32
- package/dist/presentation/viewer.js.map +1 -1
- package/dist/shared/constants.d.ts +21 -0
- package/dist/shared/constants.d.ts.map +1 -1
- package/dist/shared/constants.js +25 -0
- package/dist/shared/constants.js.map +1 -1
- package/dist/shared/normalize.d.ts.map +1 -1
- package/dist/shared/normalize.js +12 -22
- package/dist/shared/normalize.js.map +1 -1
- package/dist/shared/paginate.d.ts +4 -17
- package/dist/shared/paginate.d.ts.map +1 -1
- package/dist/shared/paginate.js.map +1 -1
- package/dist/types.d.ts +76 -1
- package/dist/types.d.ts.map +1 -1
- package/grammars/tree-sitter-erlang.wasm +0 -0
- package/package.json +7 -7
- package/src/ast-analysis/engine.ts +43 -63
- package/src/ast-analysis/rules/b2.ts +263 -0
- package/src/ast-analysis/rules/b3.ts +127 -0
- package/src/ast-analysis/rules/b4.ts +378 -0
- package/src/ast-analysis/rules/b5.ts +65 -0
- package/src/ast-analysis/rules/c.ts +157 -0
- package/src/ast-analysis/rules/index.ts +34 -0
- package/src/ast-analysis/rules/javascript.ts +3 -0
- package/src/ast-analysis/shared.ts +2 -0
- package/src/ast-analysis/visitor-utils.ts +5 -0
- package/src/ast-analysis/visitor.ts +82 -52
- package/src/ast-analysis/visitors/cfg-visitor.ts +198 -84
- package/src/ast-analysis/visitors/complexity-visitor.ts +44 -16
- package/src/ast-analysis/visitors/dataflow-visitor.ts +68 -29
- package/src/cli/commands/config.ts +184 -184
- package/src/cli/commands/roles.ts +6 -1
- package/src/db/better-sqlite3.ts +5 -4
- package/src/db/connection.ts +23 -5
- package/src/db/index.ts +1 -0
- package/src/db/migrations.ts +68 -0
- package/src/db/repository/build-stmts.ts +30 -0
- package/src/db/repository/dataflow.ts +16 -0
- package/src/db/repository/index.ts +1 -1
- package/src/db/repository/native-repository.ts +56 -40
- package/src/domain/analysis/fn-impact.ts +4 -0
- package/src/domain/analysis/module-map.ts +38 -6
- package/src/domain/analysis/roles.ts +23 -0
- package/src/domain/graph/builder/call-resolver.ts +112 -232
- package/src/domain/graph/builder/context.ts +1 -0
- package/src/domain/graph/builder/helpers.ts +190 -72
- package/src/domain/graph/builder/incremental.ts +249 -120
- package/src/domain/graph/builder/pipeline.ts +11 -5
- package/src/domain/graph/builder/stages/build-edges.ts +696 -296
- package/src/domain/graph/builder/stages/collect-files.ts +12 -6
- package/src/domain/graph/builder/stages/detect-changes.ts +3 -1
- package/src/domain/graph/builder/stages/native-orchestrator.ts +1102 -590
- package/src/domain/graph/resolver/points-to.ts +182 -59
- package/src/domain/graph/resolver/strategy.ts +265 -0
- package/src/domain/graph/watcher.ts +19 -9
- package/src/domain/parser.ts +12 -2
- package/src/domain/queries.ts +1 -1
- package/src/domain/wasm-worker-entry.ts +3 -0
- package/src/domain/wasm-worker-pool.ts +28 -4
- package/src/domain/wasm-worker-protocol.ts +4 -0
- package/src/extractors/dart.ts +48 -3
- package/src/extractors/groovy.ts +62 -2
- package/src/extractors/helpers.ts +5 -2
- package/src/extractors/java.ts +80 -1
- package/src/extractors/javascript.ts +566 -161
- package/src/extractors/kotlin.ts +57 -3
- package/src/extractors/objc.ts +25 -1
- package/src/extractors/scala.ts +63 -1
- package/src/extractors/swift.ts +46 -3
- package/src/features/audit.ts +43 -34
- package/src/features/boundaries.ts +17 -9
- package/src/features/cfg.ts +31 -22
- package/src/features/check.ts +21 -5
- package/src/features/communities.ts +28 -19
- package/src/features/dataflow.ts +755 -6
- package/src/features/manifesto.ts +76 -75
- package/src/features/sequence.ts +29 -23
- package/src/features/snapshot.ts +36 -25
- package/src/features/structure.ts +185 -55
- package/src/features/triage.ts +28 -15
- package/src/graph/algorithms/bfs.ts +13 -12
- package/src/graph/algorithms/tarjan.ts +5 -0
- package/src/graph/builders/dependency.ts +35 -23
- package/src/graph/classifiers/roles.ts +74 -7
- package/src/infrastructure/config.ts +32 -3
- package/src/infrastructure/registry.ts +44 -20
- package/src/infrastructure/update-check.ts +55 -33
- package/src/mcp/server.ts +2 -8
- package/src/mcp/tools/ast-query.ts +1 -1
- package/src/mcp/tools/audit.ts +1 -1
- package/src/mcp/tools/batch-query.ts +1 -1
- package/src/mcp/tools/branch-compare.ts +1 -1
- package/src/mcp/tools/brief.ts +1 -1
- package/src/mcp/tools/cfg.ts +1 -1
- package/src/mcp/tools/check.ts +1 -1
- package/src/mcp/tools/co-changes.ts +1 -1
- package/src/mcp/tools/code-owners.ts +1 -1
- package/src/mcp/tools/communities.ts +1 -1
- package/src/mcp/tools/complexity.ts +1 -1
- package/src/mcp/tools/context.ts +1 -1
- package/src/mcp/tools/dataflow.ts +1 -1
- package/src/mcp/tools/diff-impact.ts +1 -1
- package/src/mcp/tools/execution-flow.ts +1 -1
- package/src/mcp/tools/export-graph.ts +1 -1
- package/src/mcp/tools/file-deps.ts +1 -1
- package/src/mcp/tools/file-exports.ts +1 -1
- package/src/mcp/tools/find-cycles.ts +1 -1
- package/src/mcp/tools/fn-impact.ts +1 -1
- package/src/mcp/tools/impact-analysis.ts +1 -1
- package/src/mcp/tools/implementations.ts +1 -1
- package/src/mcp/tools/index.ts +2 -5
- package/src/mcp/tools/interfaces.ts +1 -1
- package/src/mcp/tools/list-functions.ts +1 -1
- package/src/mcp/tools/list-repos.ts +1 -1
- package/src/mcp/tools/module-map.ts +1 -1
- package/src/mcp/tools/node-roles.ts +1 -1
- package/src/mcp/tools/path.ts +1 -1
- package/src/mcp/tools/query.ts +1 -1
- package/src/mcp/tools/semantic-search.ts +1 -1
- package/src/mcp/tools/sequence.ts +1 -1
- package/src/mcp/tools/structure.ts +1 -1
- package/src/mcp/tools/symbol-children.ts +1 -1
- package/src/mcp/tools/triage.ts +1 -1
- package/src/mcp/tools/where.ts +1 -1
- package/src/mcp/types.ts +21 -0
- package/src/presentation/queries-cli/index.ts +1 -1
- package/src/presentation/queries-cli/overview.ts +35 -1
- package/src/presentation/queries-cli.ts +1 -0
- package/src/presentation/viewer.ts +98 -87
- package/src/shared/constants.ts +26 -0
- package/src/shared/normalize.ts +13 -22
- package/src/shared/paginate.ts +4 -18
- package/src/types.ts +86 -1
|
@@ -11,16 +11,17 @@
|
|
|
11
11
|
* The orchestrator-selection strategy lives here so `pipeline.ts` stays a thin
|
|
12
12
|
* top-level controller: detect changes, try native, fall back to JS stages.
|
|
13
13
|
*/
|
|
14
|
+
import { execFileSync } from 'node:child_process';
|
|
14
15
|
import path from 'node:path';
|
|
15
16
|
import { performance } from 'node:perf_hooks';
|
|
16
17
|
import { acquireAdvisoryLock, closeDbPair, openDb, purgeFilesData, releaseAdvisoryLock, setBuildMeta, } from '../../../../db/index.js';
|
|
17
18
|
import { debug, info, warn } from '../../../../infrastructure/logger.js';
|
|
18
19
|
import { loadNative } from '../../../../infrastructure/native.js';
|
|
19
20
|
import { semverCompare } from '../../../../infrastructure/update-check.js';
|
|
20
|
-
import { normalizePath } from '../../../../shared/constants.js';
|
|
21
|
+
import { normalizePath, TS_NATIVE_CONFIDENCE_FLOOR } from '../../../../shared/constants.js';
|
|
21
22
|
import { toErrorMessage } from '../../../../shared/errors.js';
|
|
22
23
|
import { CODEGRAPH_VERSION } from '../../../../shared/version.js';
|
|
23
|
-
import { classifyNativeDrops, formatDropExtensionSummary, getInstalledWasmExtensions, NATIVE_SUPPORTED_EXTENSIONS, parseFilesWasmForBackfill, } from '../../../parser.js';
|
|
24
|
+
import { classifyNativeDrops, formatDropExtensionSummary, getInstalledWasmExtensions, NATIVE_SUPPORTED_EXTENSIONS, parseFilesWasmForBackfill, patchDataflowResult, } from '../../../parser.js';
|
|
24
25
|
import { computeConfidence } from '../../resolve.js';
|
|
25
26
|
import { resolveThisDispatch } from '../cha.js';
|
|
26
27
|
import { batchInsertEdges, batchInsertNodes, CHA_DISPATCH_PENALTY, CHA_TYPED_DISPATCH_CONFIDENCE, collectFiles as collectFilesUtil, fileHash, fileStat, readFileSafe, } from '../helpers.js';
|
|
@@ -166,6 +167,162 @@ async function runPostNativeStructure(ctx, allFileSymbols, isFullBuild, changedF
|
|
|
166
167
|
}
|
|
167
168
|
return performance.now() - structureStart;
|
|
168
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* P6: Build dataflow_vertices and inter-procedural edges after the Rust
|
|
172
|
+
* orchestrator completes.
|
|
173
|
+
*
|
|
174
|
+
* The Rust pipeline writes flows_to/returns/mutates edges directly to the DB
|
|
175
|
+
* but never writes to dataflow_vertices or dataflow_summary. This pass re-runs
|
|
176
|
+
* the Rust dataflow visitor (via extractDataflowAnalysis — fast, no re-parse)
|
|
177
|
+
* to get the DataflowResult and calls buildDataflowVerticesFromMap.
|
|
178
|
+
*
|
|
179
|
+
* Languages for which Rust has no dataflow rules return null from
|
|
180
|
+
* extractDataflowAnalysis and are silently skipped here. A follow-up issue
|
|
181
|
+
* (#1614 adjacent) will add WASM fallback for those languages.
|
|
182
|
+
*/
|
|
183
|
+
async function runDataflowVertexPass(ctx, changedFiles) {
|
|
184
|
+
if (ctx.opts.dataflow === false)
|
|
185
|
+
return;
|
|
186
|
+
const native = loadNative();
|
|
187
|
+
if (!native?.extractDataflowAnalysis)
|
|
188
|
+
return;
|
|
189
|
+
// Determine which files to process: changed files for incremental, all for full builds.
|
|
190
|
+
let filesToProcess;
|
|
191
|
+
if (changedFiles && changedFiles.length > 0) {
|
|
192
|
+
filesToProcess = changedFiles;
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
// Full build: scope to files that need vertex extraction rather than scanning every
|
|
196
|
+
// file in the project. Two categories:
|
|
197
|
+
// (a) Non-native language files — NATIVE_SUPPORTED_EXTENSIONS doesn't cover them,
|
|
198
|
+
// so extractDataflowAnalysis returns null; the wasmStubs path calls buildDataflowEdges
|
|
199
|
+
// which writes both edges AND vertices for those files.
|
|
200
|
+
// (b) Native-language files with dataflow edges already written by the Rust orchestrator
|
|
201
|
+
// (flows_to/returns/mutates) — those need vertex rows to connect them.
|
|
202
|
+
//
|
|
203
|
+
// Skipping native-language files with no dataflow edges is safe: extractDataflowAnalysis
|
|
204
|
+
// would return argFlows=[], assignments=[], mutations=[] for them, producing zero vertices
|
|
205
|
+
// and zero inter-procedural edges. Excluding them avoids O(n_total_files) re-analysis on
|
|
206
|
+
// every full build (codegraph itself: ~2000 files, ~50-80% with no dataflow edges).
|
|
207
|
+
const filesWithDataflow = new Set(ctx.db
|
|
208
|
+
.prepare(`SELECT DISTINCT n.file
|
|
209
|
+
FROM dataflow d
|
|
210
|
+
JOIN nodes n ON n.id = d.source_id
|
|
211
|
+
WHERE n.file IS NOT NULL`)
|
|
212
|
+
.all().map((r) => r.file));
|
|
213
|
+
filesToProcess = ctx.db
|
|
214
|
+
.prepare(`SELECT DISTINCT file FROM nodes WHERE file IS NOT NULL AND kind != 'directory'`)
|
|
215
|
+
.all()
|
|
216
|
+
.map((r) => r.file)
|
|
217
|
+
.filter((f) => {
|
|
218
|
+
const ext = path.extname(f).toLowerCase();
|
|
219
|
+
// Non-native files: always include (WASM handles them via wasmStubs path).
|
|
220
|
+
if (!NATIVE_SUPPORTED_EXTENSIONS.has(ext))
|
|
221
|
+
return true;
|
|
222
|
+
// Native files: only include when Rust wrote dataflow edges for them.
|
|
223
|
+
return filesWithDataflow.has(f);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
// Split files into two buckets:
|
|
227
|
+
// nativeDataflow — Rust extracted data (vertex-only pass; edges already in DB)
|
|
228
|
+
// wasmStubs — Rust returned null (WASM will handle edges + vertices)
|
|
229
|
+
const nativeDataflow = new Map();
|
|
230
|
+
const wasmStubs = new Map();
|
|
231
|
+
const absPaths = filesToProcess.map((relPath) => path.join(ctx.rootDir, relPath));
|
|
232
|
+
// Batch the per-file dataflow extraction into one NAPI call so the parses run
|
|
233
|
+
// across the rayon thread pool instead of serially on the event loop — this is
|
|
234
|
+
// the dominant cost of a native full build (#perf). Older addons predate the
|
|
235
|
+
// batch export, so fall back to the per-file path when it is unavailable.
|
|
236
|
+
let batchResults = null;
|
|
237
|
+
if (typeof native.extractDataflowAnalysisBatch === 'function') {
|
|
238
|
+
try {
|
|
239
|
+
batchResults = native.extractDataflowAnalysisBatch(absPaths);
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
batchResults = null; // fall through to per-file extraction below
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
for (let i = 0; i < filesToProcess.length; i++) {
|
|
246
|
+
const relPath = filesToProcess[i];
|
|
247
|
+
let result = null;
|
|
248
|
+
if (batchResults) {
|
|
249
|
+
result = batchResults[i] ?? null;
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
let source;
|
|
253
|
+
try {
|
|
254
|
+
source = readFileSafe(absPaths[i]);
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
// Unreadable file — mirror batch-path behaviour and route to WASM.
|
|
258
|
+
wasmStubs.set(relPath, { definitions: [], _langId: null, _tree: null });
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
if (!source) {
|
|
262
|
+
// Empty file — same treatment as batch returning null.
|
|
263
|
+
wasmStubs.set(relPath, { definitions: [], _langId: null, _tree: null });
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
try {
|
|
267
|
+
result = native.extractDataflowAnalysis(source, absPaths[i]);
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
// Language-specific parse failure — fall through to WASM.
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (result) {
|
|
274
|
+
// Normalise the native DataflowResult: Rust emits `bindingType: string | null`
|
|
275
|
+
// (flat) while the TS dataflow layer expects `binding: { type, index? }` (object).
|
|
276
|
+
// patchNativeResult handles this via patchDataflow for the full parse path;
|
|
277
|
+
// extractDataflowAnalysis(Batch) is a vertex-only fast path that bypasses
|
|
278
|
+
// patchNativeResult, so we apply the same normalisation here.
|
|
279
|
+
patchDataflowResult(result);
|
|
280
|
+
nativeDataflow.set(relPath, result);
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
// Rust has no dataflow rules for this language; WASM fallback will handle
|
|
284
|
+
// both edge insertion and vertex extraction. Since Rust inserted 0 dataflow
|
|
285
|
+
// edges for these files, there is no risk of duplicates.
|
|
286
|
+
wasmStubs.set(relPath, { definitions: [], _langId: null, _tree: null });
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const { buildExtToLangMap } = (await import('../../../../ast-analysis/shared.js'));
|
|
290
|
+
const { buildDataflowVerticesFromMap, buildDataflowEdges, collectCallerStitchCandidates, collectFuncIdsForFiles, } = (await import('../../../../features/dataflow.js'));
|
|
291
|
+
// Rust-supported languages: build vertices only (edges already written by Rust orchestrator).
|
|
292
|
+
if (nativeDataflow.size > 0) {
|
|
293
|
+
// P4: On incremental builds, unchanged caller files' arg_in edges were deleted when
|
|
294
|
+
// the changed files' param vertices were purged and recreated. Re-collect stitch
|
|
295
|
+
// candidates from those caller files so buildInterproceduralStitch can reconnect them.
|
|
296
|
+
// Skip on full builds (changedFiles absent/empty) — nativeDataflow covers all files.
|
|
297
|
+
let p4Candidates = [];
|
|
298
|
+
let p4Captures = [];
|
|
299
|
+
if (changedFiles && changedFiles.length > 0) {
|
|
300
|
+
const changedSet = new Set(changedFiles);
|
|
301
|
+
const totalFilesInDb = ctx.db.prepare(`SELECT COUNT(DISTINCT file) AS n FROM nodes`).get().n;
|
|
302
|
+
// Only run P4 when this is a real incremental build (not all files changed).
|
|
303
|
+
if (nativeDataflow.size < totalFilesInDb) {
|
|
304
|
+
const changedFuncIds = collectFuncIdsForFiles(ctx.db, changedSet);
|
|
305
|
+
if (changedFuncIds.length > 0) {
|
|
306
|
+
const extra = await collectCallerStitchCandidates(ctx.db, changedFuncIds, changedSet, ctx.rootDir, buildExtToLangMap(), null, // parsers — lazily loaded inside collectCallerStitchCandidates
|
|
307
|
+
null);
|
|
308
|
+
p4Candidates = extra.candidates;
|
|
309
|
+
p4Captures = extra.captures;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const interCount = buildDataflowVerticesFromMap(ctx.db, nativeDataflow, p4Candidates.length > 0 ? p4Candidates : undefined, p4Captures.length > 0 ? p4Captures : undefined);
|
|
314
|
+
if (interCount > 0) {
|
|
315
|
+
info(`Dataflow (native orchestrator): ${interCount} inter-procedural edges inserted${p4Candidates.length > 0 ? ` (P4: ${p4Candidates.length} re-stitch candidate(s) from unchanged callers)` : ''}`);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
// Rust-unsupported languages: run the full WASM extraction (edges + vertices).
|
|
319
|
+
// wasmStubs entries have no `.dataflow` property, so the native bulk-insert
|
|
320
|
+
// fast path in buildDataflowEdges is always skipped for them — WASM runs
|
|
321
|
+
// both edge insertion and vertex extraction end-to-end.
|
|
322
|
+
if (wasmStubs.size > 0) {
|
|
323
|
+
await buildDataflowEdges(ctx.db, wasmStubs, ctx.rootDir);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
169
326
|
/**
|
|
170
327
|
* JS fallback for AST/complexity/CFG/dataflow analysis after native orchestrator.
|
|
171
328
|
* Used when the Rust addon doesn't include analysis persistence (older addon
|
|
@@ -244,47 +401,9 @@ async function runPostNativeAnalysis(ctx, allFileSymbols, changedFiles) {
|
|
|
244
401
|
}
|
|
245
402
|
return timing;
|
|
246
403
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
* The Rust build pipeline resolves typed receiver calls (e.g. `worker.doWork()`
|
|
251
|
-
* where `worker: IWorker`) to the interface method declaration only. This
|
|
252
|
-
* post-pass reads the class hierarchy (via `implements`/`extends` edges) and
|
|
253
|
-
* instantiated types (via `calls` edges to class nodes) from the DB and expands
|
|
254
|
-
* each call to an interface/abstract method to ALL RTA-filtered concrete
|
|
255
|
-
* implementations.
|
|
256
|
-
*
|
|
257
|
-
* Note: `this`/`super` dispatch is handled separately by `runPostNativeThisDispatch`,
|
|
258
|
-
* which WASM-re-parses JS/TS files to obtain raw call site receiver info.
|
|
259
|
-
*
|
|
260
|
-
* `changedFiles` controls candidate scoping on incremental builds:
|
|
261
|
-
* - null → full build; scan all call→method edges (existing behaviour).
|
|
262
|
-
* - array → incremental; two cheap gate queries decide scope:
|
|
263
|
-
* Gate A: any class/interface/trait/struct/record nodes in changed files?
|
|
264
|
-
* If yes, a new implementor may have appeared — full scan required.
|
|
265
|
-
* Gate B: any `calls` edges from changed-file sources targeting
|
|
266
|
-
* class/constructor/function-kind nodes? If yes, the RTA set may
|
|
267
|
-
* have grown (also covers the older-schema fallback where
|
|
268
|
-
* constructor calls target `constructor`/`function` nodes instead
|
|
269
|
-
* of `class` nodes) — full scan required.
|
|
270
|
-
* If neither gate fires: scope `callToMethods` to `src.file IN changedFiles`
|
|
271
|
-
* (safe because no hierarchy or RTA evidence changed).
|
|
272
|
-
*
|
|
273
|
-
* Returns the count of newly inserted CHA edges plus the set of files containing
|
|
274
|
-
* the new edges' endpoints, so the caller can scope role re-classification to the
|
|
275
|
-
* nodes whose fan-in/out actually changed. A zero count means no edges were added
|
|
276
|
-
* and role re-classification is unnecessary.
|
|
277
|
-
*/
|
|
278
|
-
function runPostNativeCha(db, changedFiles) {
|
|
279
|
-
const affectedFiles = new Set();
|
|
280
|
-
const empty = { newEdgeCount: 0, affectedFiles };
|
|
281
|
-
// Fast guard: no hierarchy edges → no CHA work
|
|
282
|
-
const hasHierarchy = db
|
|
283
|
-
.prepare(`SELECT 1 FROM edges WHERE kind IN ('extends', 'implements') LIMIT 1`)
|
|
284
|
-
.get();
|
|
285
|
-
if (!hasHierarchy)
|
|
286
|
-
return empty;
|
|
287
|
-
// Build implementors map: parent/interface name → [child/implementing class names]
|
|
404
|
+
// ── CHA post-pass helpers ────────────────────────────────────────────────────
|
|
405
|
+
/** Build implementors map: parent/interface name → [child/implementing class names]. */
|
|
406
|
+
function buildChaImplementorsMap(db) {
|
|
288
407
|
const hierarchyRows = db
|
|
289
408
|
.prepare(`
|
|
290
409
|
SELECT src.name AS child_name, tgt.name AS parent_name
|
|
@@ -304,12 +423,18 @@ function runPostNativeCha(db, changedFiles) {
|
|
|
304
423
|
if (!list.includes(row.child_name))
|
|
305
424
|
list.push(row.child_name);
|
|
306
425
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
426
|
+
return implementors;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Build RTA set: class names actually instantiated via `new X()`.
|
|
430
|
+
* Primary query targets `class`-kind nodes (the canonical schema).
|
|
431
|
+
* Fallback also matches `constructor`/`function`-kind nodes because some native
|
|
432
|
+
* engine versions record constructor calls against those kinds instead of `class`.
|
|
433
|
+
* Returns `{ instantiated, noRtaEvidence }` where `noRtaEvidence` means no
|
|
434
|
+
* constructor-call evidence exists — skip RTA filtering so interface dispatch
|
|
435
|
+
* still produces edges.
|
|
436
|
+
*/
|
|
437
|
+
function buildChaRtaSet(db) {
|
|
313
438
|
let rtaRows = db
|
|
314
439
|
.prepare(`
|
|
315
440
|
SELECT DISTINCT tgt.name
|
|
@@ -331,88 +456,80 @@ function runPostNativeCha(db, changedFiles) {
|
|
|
331
456
|
.all();
|
|
332
457
|
}
|
|
333
458
|
const instantiated = new Set(rtaRows.map((r) => r.name));
|
|
334
|
-
// noRtaEvidence: true when no constructor-call evidence exists in the DB (e.g. graph
|
|
335
|
-
// built by an older native engine that doesn't emit constructor call edges at all).
|
|
336
|
-
// In that case we skip RTA filtering so interface dispatch still produces edges —
|
|
337
|
-
// all instantiated implementors are admitted rather than silently dropping everything.
|
|
338
459
|
const noRtaEvidence = instantiated.size === 0;
|
|
339
460
|
if (noRtaEvidence) {
|
|
340
461
|
debug('runPostNativeCha: no constructor-call evidence found — proceeding without RTA filter');
|
|
341
462
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
463
|
+
return { instantiated, noRtaEvidence };
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Determine CHA candidate scope for incremental builds.
|
|
467
|
+
*
|
|
468
|
+
* Gate A: did a changed file add/change a class hierarchy node?
|
|
469
|
+
* A new `extends`/`implements` edge means a previously-untracked implementor
|
|
470
|
+
* is now in the hierarchy — unchanged call sites in OTHER files may gain new
|
|
471
|
+
* valid expansions, so the full scan is required.
|
|
472
|
+
* Note: *removed* class nodes are safe — Rust's `purge_changed_files` runs
|
|
473
|
+
* before this post-pass and deletes stale nodes and their hierarchy edges, so
|
|
474
|
+
* Gate A queries the post-purge DB. A deleted class returns no row here, which
|
|
475
|
+
* is correct: its stale CHA edges were already cleaned up by the Rust purge.
|
|
476
|
+
*
|
|
477
|
+
* Gate B: did a changed file add new RTA evidence (`new ConcreteX()`)?
|
|
478
|
+
* A new `calls` edge to a class/constructor/function-kind target means the
|
|
479
|
+
* instantiated set grew — previously RTA-filtered expansions in unchanged
|
|
480
|
+
* caller files become admissible, so the full scan is required.
|
|
481
|
+
* (`constructor`/`function` cover the older native engine fallback schema.)
|
|
482
|
+
*
|
|
483
|
+
* Returns `true` when the scan should be scoped to changed-file sources only.
|
|
484
|
+
* Returns `false` (full scan) when changedFiles is null, empty, or either gate fires.
|
|
485
|
+
*/
|
|
486
|
+
function computeChaScope(db, changedFiles) {
|
|
487
|
+
if (changedFiles === null || changedFiles.length === 0)
|
|
488
|
+
return false;
|
|
489
|
+
const CHUNK_SIZE = 500;
|
|
490
|
+
let gateAFired = false;
|
|
491
|
+
for (let i = 0; i < changedFiles.length && !gateAFired; i += CHUNK_SIZE) {
|
|
492
|
+
const chunk = changedFiles.slice(i, i + CHUNK_SIZE);
|
|
493
|
+
const ph = chunk.map(() => '?').join(',');
|
|
494
|
+
const row = db
|
|
495
|
+
.prepare(`SELECT 1 FROM nodes
|
|
496
|
+
WHERE file IN (${ph})
|
|
497
|
+
AND kind IN ('class', 'interface', 'trait', 'struct', 'record')
|
|
498
|
+
LIMIT 1`)
|
|
499
|
+
.get(...chunk);
|
|
500
|
+
if (row)
|
|
501
|
+
gateAFired = true;
|
|
502
|
+
}
|
|
503
|
+
let gateBFired = false;
|
|
504
|
+
if (!gateAFired) {
|
|
505
|
+
for (let i = 0; i < changedFiles.length && !gateBFired; i += CHUNK_SIZE) {
|
|
369
506
|
const chunk = changedFiles.slice(i, i + CHUNK_SIZE);
|
|
370
507
|
const ph = chunk.map(() => '?').join(',');
|
|
371
508
|
const row = db
|
|
372
|
-
.prepare(`SELECT 1 FROM
|
|
373
|
-
|
|
374
|
-
|
|
509
|
+
.prepare(`SELECT 1 FROM edges e
|
|
510
|
+
JOIN nodes src ON e.source_id = src.id
|
|
511
|
+
JOIN nodes tgt ON e.target_id = tgt.id
|
|
512
|
+
WHERE e.kind = 'calls'
|
|
513
|
+
AND tgt.kind IN ('class', 'interface', 'trait', 'struct', 'record', 'constructor', 'function')
|
|
514
|
+
AND src.file IN (${ph})
|
|
375
515
|
LIMIT 1`)
|
|
376
516
|
.get(...chunk);
|
|
377
517
|
if (row)
|
|
378
|
-
|
|
379
|
-
}
|
|
380
|
-
// Gate B: calls from changed-file sources to class/instantiable-kind targets
|
|
381
|
-
// (also covers older-schema fallback and future CHA extensions to struct/record).
|
|
382
|
-
// Includes class/interface/trait/struct/record (future CHA extension safety) and
|
|
383
|
-
// constructor/function (older native engine schema fallback).
|
|
384
|
-
let gateBFired = false;
|
|
385
|
-
if (!gateAFired) {
|
|
386
|
-
for (let i = 0; i < changedFiles.length && !gateBFired; i += CHUNK_SIZE) {
|
|
387
|
-
const chunk = changedFiles.slice(i, i + CHUNK_SIZE);
|
|
388
|
-
const ph = chunk.map(() => '?').join(',');
|
|
389
|
-
const row = db
|
|
390
|
-
.prepare(`SELECT 1 FROM edges e
|
|
391
|
-
JOIN nodes src ON e.source_id = src.id
|
|
392
|
-
JOIN nodes tgt ON e.target_id = tgt.id
|
|
393
|
-
WHERE e.kind = 'calls'
|
|
394
|
-
AND tgt.kind IN ('class', 'interface', 'trait', 'struct', 'record', 'constructor', 'function')
|
|
395
|
-
AND src.file IN (${ph})
|
|
396
|
-
LIMIT 1`)
|
|
397
|
-
.get(...chunk);
|
|
398
|
-
if (row)
|
|
399
|
-
gateBFired = true;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
if (!gateAFired && !gateBFired) {
|
|
403
|
-
scopeToChangedFiles = true;
|
|
404
|
-
debug(`runPostNativeCha: neither gate fired — scoping candidate scan to ${changedFiles.length} changed file(s)`);
|
|
405
|
-
}
|
|
406
|
-
else {
|
|
407
|
-
debug(`runPostNativeCha: ${gateAFired ? 'Gate A (hierarchy)' : 'Gate B (RTA)'} fired — running full scan`);
|
|
518
|
+
gateBFired = true;
|
|
408
519
|
}
|
|
409
520
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
521
|
+
if (!gateAFired && !gateBFired) {
|
|
522
|
+
debug(`runPostNativeCha: neither gate fired — scoping candidate scan to ${changedFiles.length} changed file(s)`);
|
|
523
|
+
return true;
|
|
524
|
+
}
|
|
525
|
+
debug(`runPostNativeCha: ${gateAFired ? 'Gate A (hierarchy)' : 'Gate B (RTA)'} fired — running full scan`);
|
|
526
|
+
return false;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Fetch call→method rows that are candidates for CHA expansion.
|
|
530
|
+
* When `scopeToChangedFiles` is true, restricts to source nodes in `changedFiles`.
|
|
531
|
+
*/
|
|
532
|
+
function fetchChaCallToMethods(db, changedFiles, scopeToChangedFiles) {
|
|
416
533
|
if (scopeToChangedFiles && changedFiles && changedFiles.length > 0) {
|
|
417
534
|
const CHUNK_SIZE = 500;
|
|
418
535
|
const rows = [];
|
|
@@ -431,21 +548,26 @@ function runPostNativeCha(db, changedFiles) {
|
|
|
431
548
|
.all(...chunk);
|
|
432
549
|
rows.push(...chunkRows);
|
|
433
550
|
}
|
|
434
|
-
|
|
435
|
-
}
|
|
436
|
-
else {
|
|
437
|
-
callToMethods = db
|
|
438
|
-
.prepare(`
|
|
439
|
-
SELECT e.source_id, src.name AS caller_name, tgt.name AS method_name, src.file AS caller_file
|
|
440
|
-
FROM edges e
|
|
441
|
-
JOIN nodes tgt ON e.target_id = tgt.id
|
|
442
|
-
JOIN nodes src ON e.source_id = src.id
|
|
443
|
-
WHERE e.kind = 'calls' AND tgt.kind = 'method'
|
|
444
|
-
AND INSTR(tgt.name, '.') > 0
|
|
445
|
-
AND (e.technique IS NULL OR e.technique != 'cha-expanded')
|
|
446
|
-
`)
|
|
447
|
-
.all();
|
|
551
|
+
return rows;
|
|
448
552
|
}
|
|
553
|
+
return db
|
|
554
|
+
.prepare(`
|
|
555
|
+
SELECT e.source_id, src.name AS caller_name, tgt.name AS method_name, src.file AS caller_file
|
|
556
|
+
FROM edges e
|
|
557
|
+
JOIN nodes tgt ON e.target_id = tgt.id
|
|
558
|
+
JOIN nodes src ON e.source_id = src.id
|
|
559
|
+
WHERE e.kind = 'calls' AND tgt.kind = 'method'
|
|
560
|
+
AND INSTR(tgt.name, '.') > 0
|
|
561
|
+
AND (e.technique IS NULL OR e.technique != 'cha-expanded')
|
|
562
|
+
`)
|
|
563
|
+
.all();
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* BFS-expand CHA call edges and insert new edges into the DB.
|
|
567
|
+
* Returns `{ newEdgeCount, affectedFiles }` for role re-classification scoping.
|
|
568
|
+
*/
|
|
569
|
+
function expandChaEdges(db, callToMethods, implementors, instantiated, noRtaEvidence) {
|
|
570
|
+
const affectedFiles = new Set();
|
|
449
571
|
// Seed seen-pairs only from the source_ids we'll be expanding — avoids loading every
|
|
450
572
|
// call edge in the DB (which would be O(all edges)) for large codebases.
|
|
451
573
|
const seen = new Set();
|
|
@@ -518,79 +640,91 @@ function runPostNativeCha(db, changedFiles) {
|
|
|
518
640
|
}
|
|
519
641
|
return { newEdgeCount, affectedFiles };
|
|
520
642
|
}
|
|
521
|
-
// Extensions where `this`/`super` dispatch can occur (JS/TS family)
|
|
522
|
-
const THIS_DISPATCH_EXTS = new Set(['.js', '.ts', '.tsx', '.jsx', '.mjs', '.cjs', '.mts', '.cts']);
|
|
523
643
|
/**
|
|
524
|
-
* Phase 8.
|
|
644
|
+
* Phase 8.6: CHA expansion post-pass for the native orchestrator path.
|
|
525
645
|
*
|
|
526
|
-
* The Rust build pipeline resolves typed receiver calls
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
* `
|
|
530
|
-
*
|
|
646
|
+
* The Rust build pipeline resolves typed receiver calls (e.g. `worker.doWork()`
|
|
647
|
+
* where `worker: IWorker`) to the interface method declaration only. This
|
|
648
|
+
* post-pass reads the class hierarchy (via `implements`/`extends` edges) and
|
|
649
|
+
* instantiated types (via `calls` edges to class nodes) from the DB and expands
|
|
650
|
+
* each call to an interface/abstract method to ALL RTA-filtered concrete
|
|
651
|
+
* implementations.
|
|
531
652
|
*
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
* `resolveThisDispatch` resolves them by treating the dot-prefix of the caller name
|
|
535
|
-
* (`f` from `f.h`) as the class and looking up `f.g` directly — no `extends` edge needed.
|
|
653
|
+
* Note: `this`/`super` dispatch is handled separately by `runPostNativeThisDispatch`,
|
|
654
|
+
* which WASM-re-parses JS/TS files to obtain raw call site receiver info.
|
|
536
655
|
*
|
|
537
|
-
*
|
|
538
|
-
*
|
|
656
|
+
* `changedFiles` controls candidate scoping on incremental builds:
|
|
657
|
+
* - null → full build; scan all call→method edges (existing behaviour).
|
|
658
|
+
* - array → incremental; two cheap gate queries decide scope:
|
|
659
|
+
* Gate A: any class/interface/trait/struct/record nodes in changed files?
|
|
660
|
+
* If yes, a new implementor may have appeared — full scan required.
|
|
661
|
+
* Gate B: any `calls` edges from changed-file sources targeting
|
|
662
|
+
* class/constructor/function-kind nodes? If yes, the RTA set may
|
|
663
|
+
* have grown (also covers the older-schema fallback where
|
|
664
|
+
* constructor calls target `constructor`/`function` nodes instead
|
|
665
|
+
* of `class` nodes) — full scan required.
|
|
666
|
+
* If neither gate fires: scope `callToMethods` to `src.file IN changedFiles`
|
|
667
|
+
* (safe because no hierarchy or RTA evidence changed).
|
|
668
|
+
*
|
|
669
|
+
* Returns the count of newly inserted CHA edges plus the set of files containing
|
|
670
|
+
* the new edges' endpoints, so the caller can scope role re-classification to the
|
|
671
|
+
* nodes whose fan-in/out actually changed. A zero count means no edges were added
|
|
672
|
+
* and role re-classification is unnecessary.
|
|
539
673
|
*/
|
|
540
|
-
|
|
541
|
-
const t0 = performance.now();
|
|
542
|
-
const targetIds = new Set();
|
|
543
|
-
// Files containing endpoints of newly inserted edges — lets the caller scope
|
|
544
|
-
// role re-classification to the nodes whose fan-in/out actually changed.
|
|
674
|
+
function runPostNativeCha(db, changedFiles) {
|
|
545
675
|
const affectedFiles = new Set();
|
|
546
|
-
|
|
547
|
-
//
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
const hasFuncPropMethod = db
|
|
551
|
-
.prepare(`SELECT 1 FROM nodes WHERE kind = 'method' AND INSTR(name, '.') > 0 LIMIT 1`)
|
|
676
|
+
const empty = { newEdgeCount: 0, affectedFiles };
|
|
677
|
+
// Fast guard: no hierarchy edges → no CHA work
|
|
678
|
+
const hasHierarchy = db
|
|
679
|
+
.prepare(`SELECT 1 FROM edges WHERE kind IN ('extends', 'implements') LIMIT 1`)
|
|
552
680
|
.get();
|
|
553
|
-
if (!
|
|
554
|
-
return
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
const
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
681
|
+
if (!hasHierarchy)
|
|
682
|
+
return empty;
|
|
683
|
+
const implementors = buildChaImplementorsMap(db);
|
|
684
|
+
if (implementors.size === 0)
|
|
685
|
+
return empty;
|
|
686
|
+
const { instantiated, noRtaEvidence } = buildChaRtaSet(db);
|
|
687
|
+
const scopeToChangedFiles = computeChaScope(db, changedFiles);
|
|
688
|
+
const callToMethods = fetchChaCallToMethods(db, changedFiles, scopeToChangedFiles);
|
|
689
|
+
return expandChaEdges(db, callToMethods, implementors, instantiated, noRtaEvidence);
|
|
690
|
+
}
|
|
691
|
+
// Extensions where `this`/`super` dispatch can occur (JS/TS family)
|
|
692
|
+
const THIS_DISPATCH_EXTS = new Set(['.js', '.ts', '.tsx', '.jsx', '.mjs', '.cjs', '.mts', '.cts']);
|
|
693
|
+
// ── this/super dispatch post-pass helpers ───────────────────────────────────
|
|
694
|
+
/**
|
|
695
|
+
* Build parents map: child class → direct parent class (from `extends` edges).
|
|
696
|
+
* May be empty when only func-prop methods exist (no class inheritance) —
|
|
697
|
+
* resolveThisDispatch handles that case via direct class-prefix lookup.
|
|
698
|
+
*/
|
|
699
|
+
function buildThisDispatchParentsMap(db, hasExtends) {
|
|
569
700
|
const parents = new Map();
|
|
701
|
+
if (!hasExtends)
|
|
702
|
+
return parents;
|
|
703
|
+
const parentRows = db
|
|
704
|
+
.prepare(`
|
|
705
|
+
SELECT src.name AS child_name, tgt.name AS parent_name
|
|
706
|
+
FROM edges e
|
|
707
|
+
JOIN nodes src ON e.source_id = src.id
|
|
708
|
+
JOIN nodes tgt ON e.target_id = tgt.id
|
|
709
|
+
WHERE e.kind = 'extends'
|
|
710
|
+
`)
|
|
711
|
+
.all();
|
|
570
712
|
for (const row of parentRows) {
|
|
571
713
|
if (!parents.has(row.child_name))
|
|
572
714
|
parents.set(row.child_name, row.parent_name);
|
|
573
715
|
}
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
// the entire project on top of the native pass, causing a massive regression
|
|
587
|
-
// (measured: +358% ms/file on codegraph itself). Instead we restrict to files
|
|
588
|
-
// that are part of the class inheritance hierarchy (both subclass files with
|
|
589
|
-
// `super.X()` calls and parent-class files with `this.X()` calls) OR that
|
|
590
|
-
// contain dot-named method nodes (func-prop assignments whose bodies may call
|
|
591
|
-
// `this.sibling()`). Any file not in either set has no class or object context
|
|
592
|
-
// where `this`/`super` dispatch would produce new edges.
|
|
593
|
-
let relFiles;
|
|
716
|
+
return parents;
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* Determine the set of relative file paths to re-parse for this/super dispatch.
|
|
720
|
+
*
|
|
721
|
+
* On a full build we do NOT re-parse every JS/TS file — that would WASM-parse
|
|
722
|
+
* the entire project on top of the native pass, causing a massive regression
|
|
723
|
+
* (measured: +358% ms/file on codegraph itself). Instead we restrict to files
|
|
724
|
+
* that are part of the class inheritance hierarchy OR that contain dot-named
|
|
725
|
+
* method nodes (func-prop assignments whose bodies may call `this.sibling()`).
|
|
726
|
+
*/
|
|
727
|
+
function selectThisDispatchFiles(db, changedFiles, isFullBuild) {
|
|
594
728
|
if (isFullBuild || !changedFiles) {
|
|
595
729
|
const rows = db
|
|
596
730
|
.prepare(`
|
|
@@ -622,95 +756,60 @@ async function runPostNativeThisDispatch(db, rootDir, changedFiles, isFullBuild)
|
|
|
622
756
|
)
|
|
623
757
|
`)
|
|
624
758
|
.all();
|
|
625
|
-
|
|
759
|
+
return rows
|
|
626
760
|
.map((r) => r.file)
|
|
627
761
|
.filter((f) => THIS_DISPATCH_EXTS.has(path.extname(f).toLowerCase()));
|
|
628
762
|
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
// runtime here instead cost ~40–110ms per full build (in-process
|
|
680
|
-
// web-tree-sitter + grammar init dominated) — part of the v3.12.0
|
|
681
|
-
// publish-gate regression. Files the native engine cannot parse (extension
|
|
682
|
-
// outside NATIVE_SUPPORTED_EXTENSIONS, e.g. .mts/.cts) and native parse
|
|
683
|
-
// failures fall back to the WASM backfill path so the sweep stays complete.
|
|
684
|
-
const absFiles = relFiles.map((f) => path.join(rootDir, f));
|
|
685
|
-
const nativeAbs = absFiles.filter((f) => NATIVE_SUPPORTED_EXTENSIONS.has(path.extname(f).toLowerCase()));
|
|
686
|
-
const callsByRel = new Map();
|
|
687
|
-
// Track native-supported files that returned null (per-file parse error) so
|
|
688
|
-
// they can be included in the WASM fallback set below, ensuring no file's
|
|
689
|
-
// this/super call sites are silently discarded.
|
|
690
|
-
const nativeNullFiles = new Set();
|
|
691
|
-
let nativeParsed = false;
|
|
692
|
-
if (nativeAbs.length > 0) {
|
|
693
|
-
const native = loadNative();
|
|
694
|
-
if (native) {
|
|
695
|
-
try {
|
|
696
|
-
const results = native.parseFiles(nativeAbs, rootDir, false, false);
|
|
697
|
-
for (let i = 0; i < results.length; i++) {
|
|
698
|
-
const r = results[i];
|
|
699
|
-
if (!r) {
|
|
700
|
-
// Per-file parse failure — fall back to WASM for this file.
|
|
701
|
-
const abs = nativeAbs[i];
|
|
702
|
-
if (abs)
|
|
703
|
-
nativeNullFiles.add(abs);
|
|
704
|
-
continue;
|
|
705
|
-
}
|
|
706
|
-
callsByRel.set(normalizePath(path.relative(rootDir, r.file)), r.calls ?? []);
|
|
707
|
-
}
|
|
708
|
-
nativeParsed = true;
|
|
709
|
-
}
|
|
710
|
-
catch (e) {
|
|
711
|
-
debug(`this-dispatch native re-parse failed, falling back to WASM: ${toErrorMessage(e)}`);
|
|
712
|
-
}
|
|
713
|
-
}
|
|
763
|
+
// NOTE: Only files explicitly listed in changedFiles are re-parsed.
|
|
764
|
+
// If a parent-class method is replaced (new node ID) but the child file is
|
|
765
|
+
// unchanged, the stale super.method() edge is not refreshed here. A full
|
|
766
|
+
// rebuild (isFullBuild=true) is required to recover in that scenario.
|
|
767
|
+
return changedFiles.filter((f) => THIS_DISPATCH_EXTS.has(path.extname(f).toLowerCase()));
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Re-parse files via native (preferred) + WASM fallback to obtain call sites
|
|
771
|
+
* with receiver info. Returns a map of relPath → calls array.
|
|
772
|
+
*
|
|
773
|
+
* The native engine is preferred: this pass only runs after a native
|
|
774
|
+
* orchestrator build, so the addon is already loaded and re-parses the
|
|
775
|
+
* hierarchy file set in single-digit milliseconds with the same
|
|
776
|
+
* receiver-annotated call sites as the WASM extractor. Booting the WASM
|
|
777
|
+
* runtime here instead cost ~40–110ms per full build (in-process
|
|
778
|
+
* web-tree-sitter + grammar init dominated) — part of the v3.12.0
|
|
779
|
+
* publish-gate regression. Files the native engine cannot parse (extension
|
|
780
|
+
* outside NATIVE_SUPPORTED_EXTENSIONS, e.g. .mts/.cts) and native parse
|
|
781
|
+
* failures fall back to the WASM backfill path so the sweep stays complete.
|
|
782
|
+
*/
|
|
783
|
+
async function parseFilesForThisDispatch(absFiles, rootDir) {
|
|
784
|
+
const callsByRel = new Map();
|
|
785
|
+
const nativeAbs = absFiles.filter((f) => NATIVE_SUPPORTED_EXTENSIONS.has(path.extname(f).toLowerCase()));
|
|
786
|
+
// Track native-supported files that returned null (per-file parse error) so
|
|
787
|
+
// they can be included in the WASM fallback set below, ensuring no file's
|
|
788
|
+
// this/super call sites are silently discarded.
|
|
789
|
+
const nativeNullFiles = new Set();
|
|
790
|
+
let nativeParsed = false;
|
|
791
|
+
if (nativeAbs.length > 0) {
|
|
792
|
+
const native = loadNative();
|
|
793
|
+
if (native) {
|
|
794
|
+
try {
|
|
795
|
+
const results = native.parseFiles(nativeAbs, rootDir, false, false);
|
|
796
|
+
for (let i = 0; i < results.length; i++) {
|
|
797
|
+
const r = results[i];
|
|
798
|
+
if (!r) {
|
|
799
|
+
// Per-file parse failure — fall back to WASM for this file.
|
|
800
|
+
const abs = nativeAbs[i];
|
|
801
|
+
if (abs)
|
|
802
|
+
nativeNullFiles.add(abs);
|
|
803
|
+
continue;
|
|
804
|
+
}
|
|
805
|
+
callsByRel.set(normalizePath(path.relative(rootDir, r.file)), r.calls ?? []);
|
|
806
|
+
}
|
|
807
|
+
nativeParsed = true;
|
|
808
|
+
}
|
|
809
|
+
catch (e) {
|
|
810
|
+
debug(`this-dispatch native re-parse failed, falling back to WASM: ${toErrorMessage(e)}`);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
714
813
|
}
|
|
715
814
|
// WASM handles: (a) non-native extensions (e.g. .mts/.cts), (b) the entire
|
|
716
815
|
// file list when the native batch threw, and (c) individual files where the
|
|
@@ -727,7 +826,23 @@ async function runPostNativeThisDispatch(db, rootDir, changedFiles, isFullBuild)
|
|
|
727
826
|
for (const [relPath, symbols] of wasmResults) {
|
|
728
827
|
callsByRel.set(relPath, symbols.calls ?? []);
|
|
729
828
|
}
|
|
829
|
+
return { callsByRel, wasmResults };
|
|
830
|
+
}
|
|
831
|
+
/** Emit this/super dispatch edges from re-parsed call sites. */
|
|
832
|
+
function emitThisDispatchEdges(db, callsByRel, chaCtx, lookup, seen) {
|
|
833
|
+
// Find the innermost containing method/function for a call at `line` in `file`.
|
|
834
|
+
// COALESCE maps NULL end_line to a large sentinel so unbounded nodes sort last
|
|
835
|
+
// (SQLite ASC orders NULLs first, so a raw `end_line - line` would pick them first).
|
|
836
|
+
const findCallerByLineStmt = db.prepare(`
|
|
837
|
+
SELECT id, name FROM nodes
|
|
838
|
+
WHERE file = ? AND kind IN ('method', 'function')
|
|
839
|
+
AND line <= ? AND (end_line IS NULL OR end_line >= ?)
|
|
840
|
+
ORDER BY COALESCE(end_line - line, 999999999) ASC
|
|
841
|
+
LIMIT 1
|
|
842
|
+
`);
|
|
730
843
|
const newEdges = [];
|
|
844
|
+
const targetIds = new Set();
|
|
845
|
+
const affectedFiles = new Set();
|
|
731
846
|
for (const [relPath, calls] of callsByRel) {
|
|
732
847
|
for (const call of calls) {
|
|
733
848
|
// Only 'this' and 'super' are class-instance receivers in JS/TS.
|
|
@@ -760,11 +875,10 @@ async function runPostNativeThisDispatch(db, rootDir, changedFiles, isFullBuild)
|
|
|
760
875
|
}
|
|
761
876
|
}
|
|
762
877
|
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
// Free WASM parse trees — mirrors the cleanup in backfillNativeDroppedFiles
|
|
878
|
+
return { newEdges, targetIds, affectedFiles };
|
|
879
|
+
}
|
|
880
|
+
/** Free WASM parse trees after this-dispatch post-pass to prevent memory leaks. */
|
|
881
|
+
function cleanupThisDispatchWasmTrees(wasmResults) {
|
|
768
882
|
for (const [, symbols] of wasmResults) {
|
|
769
883
|
const tree = symbols._tree;
|
|
770
884
|
if (tree && typeof tree.delete === 'function') {
|
|
@@ -778,6 +892,85 @@ async function runPostNativeThisDispatch(db, rootDir, changedFiles, isFullBuild)
|
|
|
778
892
|
symbols._tree = undefined;
|
|
779
893
|
symbols._langId = undefined;
|
|
780
894
|
}
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Phase 8.5: this/super dispatch post-pass for the native orchestrator path.
|
|
898
|
+
*
|
|
899
|
+
* The Rust build pipeline resolves typed receiver calls but does NOT persist raw
|
|
900
|
+
* unresolved call site receiver info (e.g. `this`, `super`) to the DB. This
|
|
901
|
+
* hybrid post-pass re-parses JS/TS/TSX files via WASM to collect call sites with
|
|
902
|
+
* `this`/`super` receivers, then resolves them through the class hierarchy stored
|
|
903
|
+
* in DB `extends` edges — mirroring what `buildChaPostPass` does on the WASM path.
|
|
904
|
+
*
|
|
905
|
+
* Also handles function-as-object-property methods (`f.h = function() { this.g() }`):
|
|
906
|
+
* these use `this` to reference sibling properties on the same object (`f`), so
|
|
907
|
+
* `resolveThisDispatch` resolves them by treating the dot-prefix of the caller name
|
|
908
|
+
* (`f` from `f.h`) as the class and looking up `f.g` directly — no `extends` edge needed.
|
|
909
|
+
*
|
|
910
|
+
* Runs when either `extends` edges exist (class inheritance) OR dot-named `method`
|
|
911
|
+
* nodes exist (func-prop assignments); skips only when neither is present.
|
|
912
|
+
*/
|
|
913
|
+
async function runPostNativeThisDispatch(db, rootDir, changedFiles, isFullBuild) {
|
|
914
|
+
const t0 = performance.now();
|
|
915
|
+
// Fast guard: need at least one extends edge (class inheritance) OR a dot-named
|
|
916
|
+
// method node (func-prop assignment: `f.h = function() { this.g() }`) for
|
|
917
|
+
// this/super dispatch to produce any edges.
|
|
918
|
+
const hasExtends = db.prepare(`SELECT 1 FROM edges WHERE kind = 'extends' LIMIT 1`).get();
|
|
919
|
+
const hasFuncPropMethod = db
|
|
920
|
+
.prepare(`SELECT 1 FROM nodes WHERE kind = 'method' AND INSTR(name, '.') > 0 LIMIT 1`)
|
|
921
|
+
.get();
|
|
922
|
+
const emptyResult = {
|
|
923
|
+
elapsedMs: 0,
|
|
924
|
+
targetIds: new Set(),
|
|
925
|
+
affectedFiles: new Set(),
|
|
926
|
+
};
|
|
927
|
+
if (!hasExtends && !hasFuncPropMethod)
|
|
928
|
+
return emptyResult;
|
|
929
|
+
const parents = buildThisDispatchParentsMap(db, hasExtends);
|
|
930
|
+
// Note: parents may be empty when hasFuncPropMethod but !hasExtends — that is
|
|
931
|
+
// intentional. resolveThisDispatch still resolves `this.g()` inside `f.h` by
|
|
932
|
+
// treating `f` (the dot-prefix of callerName `f.h`) as the class and looking
|
|
933
|
+
// up `f.g` directly via lookup.byName(), without traversing the parents chain.
|
|
934
|
+
const chaCtx = {
|
|
935
|
+
implementors: new Map(), // not needed for this/super resolution
|
|
936
|
+
parents,
|
|
937
|
+
instantiatedTypes: new Set(), // not needed for this/super resolution
|
|
938
|
+
};
|
|
939
|
+
const relFiles = selectThisDispatchFiles(db, changedFiles, isFullBuild);
|
|
940
|
+
if (relFiles.length === 0)
|
|
941
|
+
return emptyResult;
|
|
942
|
+
// DB-backed CallNodeLookup — resolveThisDispatch only calls byName()
|
|
943
|
+
const findByNameStmt = db.prepare(`SELECT id, file, kind FROM nodes WHERE name = ?`);
|
|
944
|
+
const lookup = {
|
|
945
|
+
byName: (name) => findByNameStmt.all(name),
|
|
946
|
+
byNameAndFile: (name, file) => findByNameStmt.all(name).filter((n) => n.file === file),
|
|
947
|
+
isBarrel: () => false,
|
|
948
|
+
resolveBarrel: () => null,
|
|
949
|
+
nodeId: () => undefined,
|
|
950
|
+
};
|
|
951
|
+
// Seed seen-pairs from existing call edges on source nodes in our file set
|
|
952
|
+
const seen = new Set();
|
|
953
|
+
const CHUNK = 500;
|
|
954
|
+
for (let i = 0; i < relFiles.length; i += CHUNK) {
|
|
955
|
+
const chunk = relFiles.slice(i, i + CHUNK);
|
|
956
|
+
const ph = chunk.map(() => '?').join(',');
|
|
957
|
+
const rows = db
|
|
958
|
+
.prepare(`SELECT e.source_id, e.target_id
|
|
959
|
+
FROM edges e
|
|
960
|
+
JOIN nodes n ON e.source_id = n.id
|
|
961
|
+
WHERE e.kind = 'calls' AND n.file IN (${ph})`)
|
|
962
|
+
.all(...chunk);
|
|
963
|
+
for (const r of rows)
|
|
964
|
+
seen.add(`${r.source_id}|${r.target_id}`);
|
|
965
|
+
}
|
|
966
|
+
const absFiles = relFiles.map((f) => path.join(rootDir, f));
|
|
967
|
+
const { callsByRel, wasmResults } = await parseFilesForThisDispatch(absFiles, rootDir);
|
|
968
|
+
const { newEdges, targetIds, affectedFiles } = emitThisDispatchEdges(db, callsByRel, chaCtx, lookup, seen);
|
|
969
|
+
if (newEdges.length > 0) {
|
|
970
|
+
db.transaction(() => batchInsertEdges(db, newEdges))();
|
|
971
|
+
debug(`this/super dispatch post-pass: inserted ${newEdges.length} edge(s)`);
|
|
972
|
+
}
|
|
973
|
+
cleanupThisDispatchWasmTrees(wasmResults);
|
|
781
974
|
return { elapsedMs: performance.now() - t0, targetIds, affectedFiles };
|
|
782
975
|
}
|
|
783
976
|
/** Format timing result from native orchestrator phases + JS post-processing. */
|
|
@@ -880,6 +1073,57 @@ function groupByExtension(relPaths) {
|
|
|
880
1073
|
}
|
|
881
1074
|
return buckets;
|
|
882
1075
|
}
|
|
1076
|
+
/**
|
|
1077
|
+
* Return the subset of relative paths that are gitignored in `rootDir`.
|
|
1078
|
+
*
|
|
1079
|
+
* Runs `git check-ignore --stdin` with all candidate paths piped in. Any
|
|
1080
|
+
* path that git echoes back is gitignored. Fails silently (returns an empty
|
|
1081
|
+
* set) when git is unavailable, the directory is not a git repo, or the
|
|
1082
|
+
* check-ignore call throws — the gap-detection logic handles those cases
|
|
1083
|
+
* gracefully without this filter.
|
|
1084
|
+
*
|
|
1085
|
+
* Uses relative paths (forward-slash separated) as both input and output so
|
|
1086
|
+
* the result set can be matched directly against the `expected` set in
|
|
1087
|
+
* `detectDroppedLanguageGap` without any further path manipulation.
|
|
1088
|
+
*/
|
|
1089
|
+
function queryGitIgnoredFiles(rootDir, relPaths) {
|
|
1090
|
+
const ignored = new Set();
|
|
1091
|
+
const paths = [...relPaths];
|
|
1092
|
+
if (paths.length === 0)
|
|
1093
|
+
return ignored;
|
|
1094
|
+
try {
|
|
1095
|
+
const stdin = paths.join('\n');
|
|
1096
|
+
const output = execFileSync('git', ['check-ignore', '--stdin'], {
|
|
1097
|
+
cwd: rootDir,
|
|
1098
|
+
input: stdin,
|
|
1099
|
+
encoding: 'utf-8',
|
|
1100
|
+
maxBuffer: 100 * 1024 * 1024,
|
|
1101
|
+
// git check-ignore exits with 1 when none of the paths are ignored —
|
|
1102
|
+
// that is not an error for our purposes. stdio: 'pipe' lets us capture
|
|
1103
|
+
// stdout without swallowing stderr, and the try/catch handles the
|
|
1104
|
+
// non-zero exit from execFileSync when ALL paths are non-ignored
|
|
1105
|
+
// (exit code 1 from git check-ignore means "no matches").
|
|
1106
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
1107
|
+
});
|
|
1108
|
+
for (const line of output.split('\n')) {
|
|
1109
|
+
const trimmed = normalizePath(line.trim());
|
|
1110
|
+
if (trimmed)
|
|
1111
|
+
ignored.add(trimmed);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
catch (e) {
|
|
1115
|
+
// Exit code 1 means no paths were ignored — not an error. Any other
|
|
1116
|
+
// failure (git unavailable, not a repo, etc.) is silently swallowed
|
|
1117
|
+
// so the caller proceeds with the unfiltered set.
|
|
1118
|
+
const exitCode = e.status;
|
|
1119
|
+
if (exitCode !== 1) {
|
|
1120
|
+
debug(`queryGitIgnoredFiles: git check-ignore failed: ${toErrorMessage(e)}`);
|
|
1121
|
+
}
|
|
1122
|
+
// On exit code 1, output is empty so ignored stays empty — correct.
|
|
1123
|
+
// On other errors we also proceed with the empty set (safe degradation).
|
|
1124
|
+
}
|
|
1125
|
+
return ignored;
|
|
1126
|
+
}
|
|
883
1127
|
/**
|
|
884
1128
|
* Detect files the native orchestrator silently dropped.
|
|
885
1129
|
*
|
|
@@ -909,7 +1153,15 @@ function groupByExtension(relPaths) {
|
|
|
909
1153
|
*/
|
|
910
1154
|
function detectDroppedLanguageGap(ctx) {
|
|
911
1155
|
const collected = collectFilesUtil(ctx.rootDir, [], ctx.config, new Set());
|
|
912
|
-
const
|
|
1156
|
+
const expectedRaw = collected.files.map((f) => normalizePath(path.relative(ctx.rootDir, f)));
|
|
1157
|
+
// The native Rust engine uses the `ignore` crate with git_ignore(true), so it
|
|
1158
|
+
// respects .gitignore and never processes gitignored files. The JS collectFiles
|
|
1159
|
+
// walker has no gitignore awareness, so without this filter gitignored files
|
|
1160
|
+
// (e.g. NAPI-RS generated crates/codegraph-core/index.js / index.d.ts) appear
|
|
1161
|
+
// in `expected` but not in the DB, causing a spurious "native extractor bug"
|
|
1162
|
+
// WARN and triggering an unnecessary WASM backfill (#1626).
|
|
1163
|
+
const gitIgnored = queryGitIgnoredFiles(ctx.rootDir, expectedRaw);
|
|
1164
|
+
const expected = new Set(gitIgnored.size > 0 ? expectedRaw.filter((r) => !gitIgnored.has(r)) : expectedRaw);
|
|
913
1165
|
const existingNodeRows = ctx.db
|
|
914
1166
|
.prepare("SELECT DISTINCT file FROM nodes WHERE kind = 'file'")
|
|
915
1167
|
.all();
|
|
@@ -947,84 +1199,31 @@ function detectDroppedLanguageGap(ctx) {
|
|
|
947
1199
|
});
|
|
948
1200
|
return { missingRel, missingAbs, staleRel };
|
|
949
1201
|
}
|
|
1202
|
+
// ── backfillNativeDroppedFiles helpers ───────────────────────────────────────
|
|
1203
|
+
/** Purge stale WASM-only files deleted from disk (#1073). */
|
|
1204
|
+
function purgeStaleWasmOnlyFiles(db, staleRel) {
|
|
1205
|
+
// `computeWasmOnlyStaleFiles` guarantees every path here has an extension
|
|
1206
|
+
// outside NATIVE_SUPPORTED_EXTENSIONS, so `classifyNativeDrops` would
|
|
1207
|
+
// always bucket 100% into `unsupported-by-native`. Build the extension
|
|
1208
|
+
// summary directly to avoid a redundant classification pass.
|
|
1209
|
+
const staleByExt = groupByExtension(staleRel);
|
|
1210
|
+
info(`Detected ${staleRel.length} deleted WASM-only file(s) across ${staleByExt.size} extension(s) the native orchestrator skipped; purging stale rows:${formatDropExtensionSummary(staleByExt)}`);
|
|
1211
|
+
purgeFilesData(db, staleRel);
|
|
1212
|
+
}
|
|
950
1213
|
/**
|
|
951
|
-
*
|
|
952
|
-
*
|
|
953
|
-
*
|
|
954
|
-
*
|
|
955
|
-
*
|
|
956
|
-
*
|
|
957
|
-
* Accepts a pre-computed `gap` from `detectDroppedLanguageGap` so the caller
|
|
958
|
-
* can use the same scan for both gating and the actual backfill — avoiding
|
|
959
|
-
* a redundant fs walk when the orchestrator's signals already triggered.
|
|
1214
|
+
* Classify and log dropped file buckets.
|
|
1215
|
+
* Three-way split of native-extractor-failure files:
|
|
1216
|
+
* realFailureBuckets — WASM found symbols → real Rust extractor bug (WARN)
|
|
1217
|
+
* emptyFileBuckets — WASM parsed but found 0 symbols → gitignored/empty (debug)
|
|
1218
|
+
* wasmSkipBuckets — WASM skipped entirely → no file-node insert (debug)
|
|
960
1219
|
*/
|
|
961
|
-
|
|
962
|
-
const { missingRel, missingAbs, staleRel } = gap;
|
|
963
|
-
if (missingAbs.length === 0 && staleRel.length === 0)
|
|
964
|
-
return;
|
|
965
|
-
// Now that we know there's work to do, hand off to better-sqlite3 (needed
|
|
966
|
-
// for the INSERT path below).
|
|
967
|
-
if (ctx.nativeFirstProxy) {
|
|
968
|
-
closeNativeDb(ctx, 'pre-parity-backfill');
|
|
969
|
-
ctx.db = openDb(ctx.dbPath);
|
|
970
|
-
ctx.nativeFirstProxy = false;
|
|
971
|
-
}
|
|
972
|
-
const dbConn = ctx.db;
|
|
973
|
-
// Purge WASM-only files that were deleted from disk (#1073). Rust's
|
|
974
|
-
// detect_removed_files skips them and the insert path below never visits
|
|
975
|
-
// them, so without this their rows would persist across rebuilds until the
|
|
976
|
-
// next full rebuild reset the DB.
|
|
977
|
-
if (staleRel.length > 0) {
|
|
978
|
-
// `computeWasmOnlyStaleFiles` guarantees every path here has an extension
|
|
979
|
-
// outside NATIVE_SUPPORTED_EXTENSIONS, so `classifyNativeDrops` would
|
|
980
|
-
// always bucket 100% into `unsupported-by-native`. Build the extension
|
|
981
|
-
// summary directly to avoid a redundant classification pass.
|
|
982
|
-
const staleByExt = groupByExtension(staleRel);
|
|
983
|
-
info(`Detected ${staleRel.length} deleted WASM-only file(s) across ${staleByExt.size} extension(s) the native orchestrator skipped; purging stale rows:${formatDropExtensionSummary(staleByExt)}`);
|
|
984
|
-
purgeFilesData(dbConn, staleRel);
|
|
985
|
-
}
|
|
986
|
-
if (missingAbs.length === 0)
|
|
987
|
-
return;
|
|
988
|
-
// Parse all missing files via WASM first so we can distinguish real native
|
|
989
|
-
// extractor failures (WASM finds symbols but native didn't) from files the
|
|
990
|
-
// Rust engine legitimately skipped (gitignored artifacts, empty declaration
|
|
991
|
-
// files, etc. where WASM also produces 0 symbols). Both categories are
|
|
992
|
-
// backfilled — only the former triggers a WARN (#1566).
|
|
993
|
-
const wasmResults = await parseFilesWasmForBackfill(missingAbs, ctx.rootDir);
|
|
994
|
-
// Build two sets from wasmResults:
|
|
995
|
-
// wasmParsedFiles — rel-paths present in wasmResults (WASM succeeded, even 0 symbols)
|
|
996
|
-
// wasmFoundSymbols — subset where WASM found ≥1 symbol
|
|
997
|
-
// Files absent from wasmParsedFiles were skipped by WASM entirely (extension
|
|
998
|
-
// not in _extToLang, wasmExtractSymbols returned null, or a read error).
|
|
999
|
-
// Those files do NOT end up in the batchInsertNodes loop below.
|
|
1000
|
-
const wasmParsedFiles = new Set();
|
|
1001
|
-
const wasmFoundSymbols = new Set();
|
|
1002
|
-
for (const [relPath, symbols] of wasmResults) {
|
|
1003
|
-
wasmParsedFiles.add(relPath);
|
|
1004
|
-
if ((symbols.definitions?.length ?? 0) > 0 || (symbols.exports?.length ?? 0) > 0) {
|
|
1005
|
-
wasmFoundSymbols.add(relPath);
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
// Classify drops so users see per-extension reasons instead of just a count
|
|
1009
|
-
// (#1011). `unsupported-by-native` is a legitimate parser limit (no Rust
|
|
1010
|
-
// extractor); `native-extractor-failure` indicates a real native bug since
|
|
1011
|
-
// the language IS supported by the addon yet WASM found symbols the native
|
|
1012
|
-
// engine should have extracted. Files where both engines produce 0 symbols
|
|
1013
|
-
// are legitimately empty (e.g. gitignored napi-generated declaration stubs)
|
|
1014
|
-
// and logged at debug level only.
|
|
1220
|
+
function classifyAndLogDroppedFiles(missingRel, wasmParsedFiles, wasmFoundSymbols) {
|
|
1015
1221
|
const { byReason, totals } = classifyNativeDrops(missingRel);
|
|
1016
1222
|
if (totals['unsupported-by-native'] > 0) {
|
|
1017
1223
|
const buckets = byReason['unsupported-by-native'];
|
|
1018
1224
|
info(`Native orchestrator skipped ${totals['unsupported-by-native']} file(s) across ${buckets.size} extension(s) in languages without a Rust extractor; backfilling via WASM:${formatDropExtensionSummary(buckets)}`);
|
|
1019
1225
|
}
|
|
1020
1226
|
if (totals['native-extractor-failure'] > 0) {
|
|
1021
|
-
// Three-way split of native-extractor-failure files:
|
|
1022
|
-
// realFailureBuckets — WASM found symbols → real Rust extractor bug (WARN)
|
|
1023
|
-
// emptyFileBuckets — WASM parsed but found 0 symbols → gitignored/empty (debug)
|
|
1024
|
-
// These DO receive a file-node insert in the loop below.
|
|
1025
|
-
// wasmSkipBuckets — WASM skipped entirely (ext unknown or parse error) →
|
|
1026
|
-
// no file-node insert, and no WARN (debug only, distinct
|
|
1027
|
-
// message to avoid overstating backfill coverage).
|
|
1028
1227
|
const allFailurePaths = byReason['native-extractor-failure'];
|
|
1029
1228
|
const realFailureBuckets = new Map();
|
|
1030
1229
|
const emptyFileBuckets = new Map();
|
|
@@ -1062,6 +1261,9 @@ async function backfillNativeDroppedFiles(ctx, gap) {
|
|
|
1062
1261
|
debug(`Native orchestrator skipped ${skipCount} file(s) in natively-supported languages that WASM also could not parse (unregistered extension or parse error); no file-node inserted:${formatDropExtensionSummary(wasmSkipBuckets)}`);
|
|
1063
1262
|
}
|
|
1064
1263
|
}
|
|
1264
|
+
}
|
|
1265
|
+
/** Insert node rows for all backfilled files and mark exported symbols. */
|
|
1266
|
+
function insertBackfilledNodes(db, wasmResults) {
|
|
1065
1267
|
const rows = [];
|
|
1066
1268
|
const exportKeys = [];
|
|
1067
1269
|
for (const [relPath, symbols] of wasmResults) {
|
|
@@ -1093,7 +1295,6 @@ async function backfillNativeDroppedFiles(ctx, gap) {
|
|
|
1093
1295
|
exportKeys.push([exp.name, exp.kind, relPath, exp.line]);
|
|
1094
1296
|
}
|
|
1095
1297
|
}
|
|
1096
|
-
const db = dbConn;
|
|
1097
1298
|
batchInsertNodes(db, rows);
|
|
1098
1299
|
// Mark exported symbols in batches — mirrors insertDefinitionsAndExports.
|
|
1099
1300
|
if (exportKeys.length > 0) {
|
|
@@ -1116,17 +1317,21 @@ async function backfillNativeDroppedFiles(ctx, gap) {
|
|
|
1116
1317
|
updateStmt.run(...vals);
|
|
1117
1318
|
}
|
|
1118
1319
|
}
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1320
|
+
}
|
|
1321
|
+
/**
|
|
1322
|
+
* Persist file_hashes rows for every backfilled file.
|
|
1323
|
+
*
|
|
1324
|
+
* The Rust orchestrator only hashes files it parsed itself, so without this
|
|
1325
|
+
* step files in optional-language extensions (e.g. .clj when no Rust extractor
|
|
1326
|
+
* exists) would be missing from `file_hashes` — permanently breaking the JS-side
|
|
1327
|
+
* fast-skip pre-flight (#1054), which rejects on `collected file missing
|
|
1328
|
+
* from file_hashes` and forces every no-op rebuild back through the full
|
|
1329
|
+
* ~2s native pipeline (#1068).
|
|
1330
|
+
*
|
|
1331
|
+
* Iterates `missingRel` (every collected file the Rust orchestrator dropped),
|
|
1332
|
+
* not `wasmResults`, so files that produced zero symbols still get a row.
|
|
1333
|
+
*/
|
|
1334
|
+
function backfillFileHashes(db, missingRel, missingAbs) {
|
|
1130
1335
|
try {
|
|
1131
1336
|
const upsertHash = db.prepare('INSERT OR REPLACE INTO file_hashes (file, hash, mtime, size) VALUES (?, ?, ?, ?)');
|
|
1132
1337
|
const writeHashes = db.transaction(() => {
|
|
@@ -1156,35 +1361,89 @@ async function backfillNativeDroppedFiles(ctx, gap) {
|
|
|
1156
1361
|
catch (e) {
|
|
1157
1362
|
debug(`backfillNativeDroppedFiles: file_hashes write failed (table may not exist): ${toErrorMessage(e)}`);
|
|
1158
1363
|
}
|
|
1159
|
-
// Free WASM parse trees from the inline backfill path (#1058).
|
|
1160
|
-
// `parseFilesWasmInline` sets `symbols._tree` (a live web-tree-sitter Tree
|
|
1161
|
-
// backed by WASM linear memory) on every result, but these symbols are
|
|
1162
|
-
// consumed locally for DB row construction and never added to
|
|
1163
|
-
// `ctx.allSymbols`, so the finalize-stage `releaseWasmTrees` sweep never
|
|
1164
|
-
// sees them. Without this, trees leak WASM memory until process exit —
|
|
1165
|
-
// bounded per run but cumulative across in-process integration tests.
|
|
1166
|
-
// Mirrors the cleanup discipline established for #931.
|
|
1167
|
-
for (const [, symbols] of wasmResults) {
|
|
1168
|
-
const tree = symbols._tree;
|
|
1169
|
-
if (tree && typeof tree.delete === 'function') {
|
|
1170
|
-
try {
|
|
1171
|
-
tree.delete();
|
|
1172
|
-
}
|
|
1173
|
-
catch {
|
|
1174
|
-
/* ignore cleanup errors */
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
symbols._tree = undefined;
|
|
1178
|
-
symbols._langId = undefined;
|
|
1179
|
-
}
|
|
1180
1364
|
}
|
|
1181
1365
|
/**
|
|
1182
|
-
* Backfill
|
|
1183
|
-
*
|
|
1366
|
+
* Backfill files that the native orchestrator silently dropped during parse.
|
|
1367
|
+
* Falls back to WASM + inserts file/symbol nodes so engine counts match (#967).
|
|
1184
1368
|
*
|
|
1185
|
-
*
|
|
1186
|
-
*
|
|
1187
|
-
*
|
|
1369
|
+
* Also purges stale rows for WASM-only files deleted from disk (#1073), which
|
|
1370
|
+
* Rust's `detect_removed_files` filter (#1070) skips.
|
|
1371
|
+
*
|
|
1372
|
+
* Accepts a pre-computed `gap` from `detectDroppedLanguageGap` so the caller
|
|
1373
|
+
* can use the same scan for both gating and the actual backfill — avoiding
|
|
1374
|
+
* a redundant fs walk when the orchestrator's signals already triggered.
|
|
1375
|
+
*/
|
|
1376
|
+
async function backfillNativeDroppedFiles(ctx, gap) {
|
|
1377
|
+
const { missingRel, missingAbs, staleRel } = gap;
|
|
1378
|
+
if (missingAbs.length === 0 && staleRel.length === 0)
|
|
1379
|
+
return;
|
|
1380
|
+
// Now that we know there's work to do, hand off to better-sqlite3 (needed
|
|
1381
|
+
// for the INSERT path below).
|
|
1382
|
+
if (ctx.nativeFirstProxy) {
|
|
1383
|
+
closeNativeDb(ctx, 'pre-parity-backfill');
|
|
1384
|
+
ctx.db = openDb(ctx.dbPath);
|
|
1385
|
+
ctx.nativeFirstProxy = false;
|
|
1386
|
+
}
|
|
1387
|
+
const dbConn = ctx.db;
|
|
1388
|
+
// Purge WASM-only files that were deleted from disk (#1073). Rust's
|
|
1389
|
+
// detect_removed_files skips them and the insert path below never visits
|
|
1390
|
+
// them, so without this their rows would persist across rebuilds until the
|
|
1391
|
+
// next full rebuild reset the DB.
|
|
1392
|
+
if (staleRel.length > 0) {
|
|
1393
|
+
purgeStaleWasmOnlyFiles(dbConn, staleRel);
|
|
1394
|
+
}
|
|
1395
|
+
if (missingAbs.length === 0)
|
|
1396
|
+
return;
|
|
1397
|
+
// Parse all missing files via WASM first so we can distinguish real native
|
|
1398
|
+
// extractor failures (WASM finds symbols but native didn't) from files the
|
|
1399
|
+
// Rust engine legitimately skipped (gitignored artifacts, empty declaration
|
|
1400
|
+
// files, etc. where WASM also produces 0 symbols). Both categories are
|
|
1401
|
+
// backfilled — only the former triggers a WARN (#1566).
|
|
1402
|
+
const wasmResults = await parseFilesWasmForBackfill(missingAbs, ctx.rootDir);
|
|
1403
|
+
// Build two sets from wasmResults:
|
|
1404
|
+
// wasmParsedFiles — rel-paths present in wasmResults (WASM succeeded, even 0 symbols)
|
|
1405
|
+
// wasmFoundSymbols — subset where WASM found ≥1 symbol
|
|
1406
|
+
// Files absent from wasmParsedFiles were skipped by WASM entirely (extension
|
|
1407
|
+
// not in _extToLang, wasmExtractSymbols returned null, or a read error).
|
|
1408
|
+
// Those files do NOT end up in the batchInsertNodes loop below.
|
|
1409
|
+
const wasmParsedFiles = new Set();
|
|
1410
|
+
const wasmFoundSymbols = new Set();
|
|
1411
|
+
for (const [relPath, symbols] of wasmResults) {
|
|
1412
|
+
wasmParsedFiles.add(relPath);
|
|
1413
|
+
if ((symbols.definitions?.length ?? 0) > 0 || (symbols.exports?.length ?? 0) > 0) {
|
|
1414
|
+
wasmFoundSymbols.add(relPath);
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
// Classify drops so users see per-extension reasons instead of just a count
|
|
1418
|
+
// (#1011). `unsupported-by-native` is a legitimate parser limit (no Rust
|
|
1419
|
+
// extractor); `native-extractor-failure` indicates a real native bug since
|
|
1420
|
+
// the language IS supported by the addon yet WASM found symbols the native
|
|
1421
|
+
// engine should have extracted. Files where both engines produce 0 symbols
|
|
1422
|
+
// are legitimately empty (e.g. gitignored napi-generated declaration stubs)
|
|
1423
|
+
// and logged at debug level only.
|
|
1424
|
+
classifyAndLogDroppedFiles(missingRel, wasmParsedFiles, wasmFoundSymbols);
|
|
1425
|
+
insertBackfilledNodes(dbConn, wasmResults);
|
|
1426
|
+
backfillFileHashes(dbConn, missingRel, missingAbs);
|
|
1427
|
+
// Free WASM parse trees from the inline backfill path (#1058).
|
|
1428
|
+
// `parseFilesWasmInline` sets `symbols._tree` (a live web-tree-sitter Tree
|
|
1429
|
+
// backed by WASM linear memory) on every result, but these symbols are
|
|
1430
|
+
// consumed locally for DB row construction and never added to
|
|
1431
|
+
// `ctx.allSymbols`, so the finalize-stage `releaseWasmTrees` sweep never
|
|
1432
|
+
// sees them. Without this, trees leak WASM memory until process exit —
|
|
1433
|
+
// bounded per run but cumulative across in-process integration tests.
|
|
1434
|
+
// Mirrors the cleanup discipline established for #931.
|
|
1435
|
+
cleanupThisDispatchWasmTrees(wasmResults);
|
|
1436
|
+
}
|
|
1437
|
+
/**
|
|
1438
|
+
* Backfill the `technique` column on `calls` edges written by the native Rust
|
|
1439
|
+
* orchestrator, which does not write the column itself. Also lifts any
|
|
1440
|
+
* resolved ts-native edge whose confidence is below TS_NATIVE_CONFIDENCE_FLOOR
|
|
1441
|
+
* to that floor value so that the name-lookup quality of the native resolver is
|
|
1442
|
+
* reflected in the call-confidence metric.
|
|
1443
|
+
*
|
|
1444
|
+
* For full builds, all `calls` edges in the DB are new so a global UPDATE is
|
|
1445
|
+
* correct. For incremental builds, only changed-file source nodes are updated
|
|
1446
|
+
* to avoid overwriting previously-set technique values on unchanged edges.
|
|
1188
1447
|
*/
|
|
1189
1448
|
function backfillEdgeTechniquesAfterNativeOrchestrator(db, isFullBuild, changedFiles) {
|
|
1190
1449
|
// Quiet incremental: no files changed → no new edges inserted, nothing to tag.
|
|
@@ -1195,6 +1454,10 @@ function backfillEdgeTechniquesAfterNativeOrchestrator(db, isFullBuild, changedF
|
|
|
1195
1454
|
}
|
|
1196
1455
|
if (isFullBuild || !changedFiles) {
|
|
1197
1456
|
db.prepare("UPDATE edges SET technique = 'ts-native' WHERE kind = 'calls' AND technique IS NULL").run();
|
|
1457
|
+
// Lift resolved ts-native edges below the confidence floor.
|
|
1458
|
+
db.prepare(`UPDATE edges SET confidence = ?
|
|
1459
|
+
WHERE kind = 'calls' AND technique = 'ts-native'
|
|
1460
|
+
AND confidence > 0 AND confidence < ?`).run(TS_NATIVE_CONFIDENCE_FLOOR, TS_NATIVE_CONFIDENCE_FLOOR);
|
|
1198
1461
|
return;
|
|
1199
1462
|
}
|
|
1200
1463
|
// Incremental: scope to source nodes whose file is one of the changed files.
|
|
@@ -1209,10 +1472,205 @@ function backfillEdgeTechniquesAfterNativeOrchestrator(db, isFullBuild, changedF
|
|
|
1209
1472
|
AND source_id IN (
|
|
1210
1473
|
SELECT id FROM nodes WHERE file IN (${placeholders})
|
|
1211
1474
|
)`).run(...chunk);
|
|
1475
|
+
// Lift resolved ts-native edges below the confidence floor for this chunk.
|
|
1476
|
+
db.prepare(`UPDATE edges SET confidence = ?
|
|
1477
|
+
WHERE kind = 'calls' AND technique = 'ts-native'
|
|
1478
|
+
AND confidence > 0 AND confidence < ?
|
|
1479
|
+
AND source_id IN (
|
|
1480
|
+
SELECT id FROM nodes WHERE file IN (${placeholders})
|
|
1481
|
+
)`).run(TS_NATIVE_CONFIDENCE_FLOOR, TS_NATIVE_CONFIDENCE_FLOOR, ...chunk);
|
|
1212
1482
|
}
|
|
1213
1483
|
});
|
|
1214
1484
|
tx();
|
|
1215
1485
|
}
|
|
1486
|
+
// ── tryNativeOrchestrator helpers ────────────────────────────────────────────
|
|
1487
|
+
/**
|
|
1488
|
+
* Open NativeDatabase on demand — deferred from setupPipeline to skip the
|
|
1489
|
+
* ~60ms cost on no-op/early-exit builds.
|
|
1490
|
+
*
|
|
1491
|
+
* Closes the better-sqlite3 connection first to avoid dual-connection WAL
|
|
1492
|
+
* corruption. On setup failure, falls back to reopening better-sqlite3 and
|
|
1493
|
+
* leaves ctx.nativeDb undefined so the caller falls through to the JS pipeline.
|
|
1494
|
+
*/
|
|
1495
|
+
function openNativeDatabase(ctx) {
|
|
1496
|
+
if (ctx.nativeDb || !ctx.nativeAvailable)
|
|
1497
|
+
return;
|
|
1498
|
+
const native = loadNative();
|
|
1499
|
+
if (!native?.NativeDatabase)
|
|
1500
|
+
return;
|
|
1501
|
+
try {
|
|
1502
|
+
// Close better-sqlite3 before opening rusqlite to avoid WAL conflicts.
|
|
1503
|
+
// Uses raw close() instead of closeDb() intentionally — the advisory lock
|
|
1504
|
+
// is kept and transferred to the NativeDbProxy below, not released here.
|
|
1505
|
+
ctx.db.close();
|
|
1506
|
+
acquireAdvisoryLock(ctx.dbPath);
|
|
1507
|
+
ctx.nativeDb = native.NativeDatabase.openReadWrite(ctx.dbPath);
|
|
1508
|
+
ctx.nativeDb.initSchema();
|
|
1509
|
+
// Replace ctx.db with a NativeDbProxy so post-native JS fallback
|
|
1510
|
+
// (structure, analysis) can use it without reopening better-sqlite3.
|
|
1511
|
+
const proxy = new NativeDbProxy(ctx.nativeDb);
|
|
1512
|
+
proxy.__lockPath = `${ctx.dbPath}.lock`;
|
|
1513
|
+
ctx.db = proxy;
|
|
1514
|
+
ctx.nativeFirstProxy = true;
|
|
1515
|
+
}
|
|
1516
|
+
catch (err) {
|
|
1517
|
+
warn(`NativeDatabase setup failed, falling back to JS: ${toErrorMessage(err)}`);
|
|
1518
|
+
try {
|
|
1519
|
+
ctx.nativeDb?.close();
|
|
1520
|
+
}
|
|
1521
|
+
catch (e) {
|
|
1522
|
+
debug(`tryNativeOrchestrator: close failed during fallback: ${toErrorMessage(e)}`);
|
|
1523
|
+
}
|
|
1524
|
+
ctx.nativeDb = undefined;
|
|
1525
|
+
ctx.nativeFirstProxy = false; // defensive: reset in case future refactors move the assignment above throwing lines
|
|
1526
|
+
releaseAdvisoryLock(`${ctx.dbPath}.lock`);
|
|
1527
|
+
// Reopen better-sqlite3 for JS pipeline fallback
|
|
1528
|
+
ctx.db = openDb(ctx.dbPath);
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
/**
|
|
1532
|
+
* Coordinate all post-native edge-writing post-passes, role re-classification,
|
|
1533
|
+
* and technique backfill. Returns timing data for the build result.
|
|
1534
|
+
*
|
|
1535
|
+
* Post-passes run before structure/analysis so role classification sees the
|
|
1536
|
+
* complete graph including CHA + this/super dispatch edges.
|
|
1537
|
+
*/
|
|
1538
|
+
async function runPostNativePasses(ctx, result) {
|
|
1539
|
+
// Engine parity: the native orchestrator silently drops files whose
|
|
1540
|
+
// Rust extractor/grammar is missing or fails (e.g. HCL, Scala, Swift on
|
|
1541
|
+
// stale native binaries). WASM handles those — backfill via WASM so both
|
|
1542
|
+
// engines process the same file set (#967).
|
|
1543
|
+
//
|
|
1544
|
+
// Detect the gap once (fs walk + 2 DB queries) and use it for both gating
|
|
1545
|
+
// and the backfill itself. On quiet incrementals we still pay the walk so
|
|
1546
|
+
// we can detect brand-new files in dropped-language extensions — a gap that
|
|
1547
|
+
// the orchestrator's `detect_removed_files` filter (#1070) leaves open
|
|
1548
|
+
// (#1083, #1091). The pre-check is cheap because the expensive part (WASM
|
|
1549
|
+
// re-parse of the missing set) is gated below.
|
|
1550
|
+
const gapDetectStart = performance.now();
|
|
1551
|
+
const gap = detectDroppedLanguageGap(ctx);
|
|
1552
|
+
const backfillHappened = gap.missingAbs.length > 0 || gap.staleRel.length > 0;
|
|
1553
|
+
if (backfillHappened) {
|
|
1554
|
+
await backfillNativeDroppedFiles(ctx, gap);
|
|
1555
|
+
}
|
|
1556
|
+
const gapDetectMs = performance.now() - gapDetectStart;
|
|
1557
|
+
// Phase 8.5: this/super dispatch — hybrid WASM re-parse to resolve call sites
|
|
1558
|
+
// whose raw receiver info the Rust pipeline does not persist to DB.
|
|
1559
|
+
// Runs BEFORE the CHA expansion pass so that super.method() → Parent.method edges
|
|
1560
|
+
// (technique='cha') are in the DB when runPostNativeCha expands them to sibling
|
|
1561
|
+
// class overrides (e.g. PostMixin.m → B.m when PostMixin and B both extend A).
|
|
1562
|
+
const { elapsedMs: thisDispatchMs, targetIds: thisDispatchTargetIds, affectedFiles: thisDispatchAffectedFiles, } = await runPostNativeThisDispatch(ctx.db, ctx.rootDir, result.changedFiles, !!result.isFullBuild);
|
|
1563
|
+
// Phase 8.6: expand CHA call edges (interface dispatch → concrete implementations).
|
|
1564
|
+
// Returns the affected files so role re-classification below can be scoped to
|
|
1565
|
+
// the nodes whose fan-in/out actually changed.
|
|
1566
|
+
//
|
|
1567
|
+
// Runs AFTER this/super dispatch so super.method() edges are already in the DB.
|
|
1568
|
+
// The 'cha-expanded' technique tag on this pass's own output prevents re-expansion
|
|
1569
|
+
// of those edges in subsequent incremental builds, while 'cha'-tagged edges from
|
|
1570
|
+
// this/super dispatch remain eligible for expansion here.
|
|
1571
|
+
//
|
|
1572
|
+
// Function-as-object-property methods (`fn.method = function() {}`) are extracted
|
|
1573
|
+
// natively by the Rust engine (#1432) and resolved in-build by its edge builder, so
|
|
1574
|
+
// no WASM re-parse post-pass is needed for them. `Foo.prototype.bar = fn` likewise.
|
|
1575
|
+
const chaStart = performance.now();
|
|
1576
|
+
const { newEdgeCount: chaEdgeCount, affectedFiles: chaAffectedFiles } = runPostNativeCha(ctx.db,
|
|
1577
|
+
// null = full build (scan all call→method edges); array = incremental (gate queries decide scope)
|
|
1578
|
+
result.isFullBuild ? null : (result.changedFiles ?? null));
|
|
1579
|
+
const chaMs = performance.now() - chaStart;
|
|
1580
|
+
// Role re-classification after the Rust orchestrator build.
|
|
1581
|
+
//
|
|
1582
|
+
// Two reasons to re-classify:
|
|
1583
|
+
//
|
|
1584
|
+
// 1. Post-pass edges (CHA, this-dispatch): the Rust orchestrator classifies
|
|
1585
|
+
// roles before these passes add edges, so fan-in/out for their endpoints
|
|
1586
|
+
// is stale. On incremental builds, scope to the affected files for speed.
|
|
1587
|
+
//
|
|
1588
|
+
// 2. hasActiveFileSiblings parity: the Rust classifier does not implement the
|
|
1589
|
+
// JS hasActiveFileSiblings heuristic. That heuristic promotes functions with
|
|
1590
|
+
// fan_in=0 but fan_out>0 to 'leaf' when their file has other connected
|
|
1591
|
+
// callables — preventing false dead-unresolved classifications for functions
|
|
1592
|
+
// like `main` or `square` that call others but are never called themselves.
|
|
1593
|
+
// On full builds, always run a full JS re-classification so the Rust roles
|
|
1594
|
+
// are replaced by the canonical JS classifier output (#1659).
|
|
1595
|
+
//
|
|
1596
|
+
// Strategy:
|
|
1597
|
+
// - Full build: always run full JS classifyNodeRoles(db, null).
|
|
1598
|
+
// - Incremental build with post-pass edges: run scoped re-classification
|
|
1599
|
+
// for the affected files (same as before). The full-build pass already
|
|
1600
|
+
// produced correct JS roles for all unchanged files on the previous build.
|
|
1601
|
+
// - Incremental build with no post-pass edges: skip re-classification
|
|
1602
|
+
// (Rust roles on unchanged files are not stale, and the heuristic gap
|
|
1603
|
+
// was corrected on the last full build).
|
|
1604
|
+
let reclassifyMs = 0;
|
|
1605
|
+
const needsFullReclassify = !!result.isFullBuild;
|
|
1606
|
+
const needsScopedReclassify = !needsFullReclassify && (chaEdgeCount > 0 || thisDispatchTargetIds.size > 0);
|
|
1607
|
+
if (needsFullReclassify || needsScopedReclassify) {
|
|
1608
|
+
let scopedFiles = null;
|
|
1609
|
+
if (needsScopedReclassify) {
|
|
1610
|
+
const affectedFiles = [...new Set([...chaAffectedFiles, ...thisDispatchAffectedFiles])];
|
|
1611
|
+
// When edges were inserted but all their endpoint nodes have null `file`
|
|
1612
|
+
// columns (rare but possible), affectedFiles stays empty even though
|
|
1613
|
+
// fan-in/out changed. Fall back to full-graph re-classification in that
|
|
1614
|
+
// case — scoped classification with an empty set would be a no-op, leaving
|
|
1615
|
+
// roles stale for those nodes.
|
|
1616
|
+
scopedFiles = affectedFiles.length > 0 ? affectedFiles : null;
|
|
1617
|
+
}
|
|
1618
|
+
const reclassifyStart = performance.now();
|
|
1619
|
+
try {
|
|
1620
|
+
const { classifyNodeRoles } = (await import('../../../../features/structure.js'));
|
|
1621
|
+
classifyNodeRoles(ctx.db, scopedFiles);
|
|
1622
|
+
debug(scopedFiles
|
|
1623
|
+
? `Post-pass role re-classification complete (${scopedFiles.length} file(s))`
|
|
1624
|
+
: 'Post-pass role re-classification complete (full graph)');
|
|
1625
|
+
}
|
|
1626
|
+
catch (err) {
|
|
1627
|
+
debug(`Post-pass role re-classification failed: ${toErrorMessage(err)}`);
|
|
1628
|
+
}
|
|
1629
|
+
reclassifyMs = performance.now() - reclassifyStart;
|
|
1630
|
+
}
|
|
1631
|
+
// Backfill the `technique` column on `calls` edges written by the Rust
|
|
1632
|
+
// orchestrator, which does not write the column. Runs after all edge-writing
|
|
1633
|
+
// phases (including the WASM dropped-language backfill, CHA post-pass, and
|
|
1634
|
+
// this/super dispatch) so every new edge in this build cycle gets a label.
|
|
1635
|
+
const techniqueBackfillStart = performance.now();
|
|
1636
|
+
backfillEdgeTechniquesAfterNativeOrchestrator(ctx.db, !!result.isFullBuild, result.changedFiles);
|
|
1637
|
+
const techniqueBackfillMs = performance.now() - techniqueBackfillStart;
|
|
1638
|
+
// Re-count nodes/edges now that all edge-writing post-passes have run: the
|
|
1639
|
+
// Rust orchestrator captured its counts before the JS post-passes added
|
|
1640
|
+
// edges, so both its summary and build_meta under-report (#1452).
|
|
1641
|
+
//
|
|
1642
|
+
// Fast path: skip the COUNT(*) scan when no post-pass wrote any edges.
|
|
1643
|
+
// COUNT(*) on large tables (50K+ edges) is non-trivial, especially via the
|
|
1644
|
+
// NativeDbProxy napi-rs round-trip. When all post-passes were no-ops, the
|
|
1645
|
+
// Rust orchestrator's counts are still accurate — no re-count needed.
|
|
1646
|
+
let finalNodeCount = result.nodeCount ?? 0;
|
|
1647
|
+
let finalEdgeCount = result.edgeCount ?? 0;
|
|
1648
|
+
const postPassWroteData = backfillHappened || chaEdgeCount > 0 || thisDispatchTargetIds.size > 0;
|
|
1649
|
+
if (postPassWroteData) {
|
|
1650
|
+
try {
|
|
1651
|
+
const counts = ctx.db
|
|
1652
|
+
.prepare('SELECT (SELECT COUNT(*) FROM nodes) AS n, (SELECT COUNT(*) FROM edges) AS e')
|
|
1653
|
+
.get();
|
|
1654
|
+
if (counts.n !== finalNodeCount || counts.e !== finalEdgeCount) {
|
|
1655
|
+
finalNodeCount = counts.n;
|
|
1656
|
+
finalEdgeCount = counts.e;
|
|
1657
|
+
setBuildMeta(ctx.db, { node_count: finalNodeCount, edge_count: finalEdgeCount });
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
catch (err) {
|
|
1661
|
+
debug(`Post-pass node/edge re-count failed: ${toErrorMessage(err)}`);
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
info(`Native build orchestrator completed: ${finalNodeCount} nodes, ${finalEdgeCount} edges, ${result.fileCount ?? 0} files`);
|
|
1665
|
+
return {
|
|
1666
|
+
gapDetectMs,
|
|
1667
|
+
chaMs,
|
|
1668
|
+
thisDispatchMs,
|
|
1669
|
+
reclassifyMs,
|
|
1670
|
+
techniqueBackfillMs,
|
|
1671
|
+
backfillHappened,
|
|
1672
|
+
};
|
|
1673
|
+
}
|
|
1216
1674
|
/**
|
|
1217
1675
|
* Try the native build orchestrator.
|
|
1218
1676
|
*
|
|
@@ -1233,46 +1691,39 @@ export async function tryNativeOrchestrator(ctx) {
|
|
|
1233
1691
|
debug(`Skipping native orchestrator: ${skipReason}`);
|
|
1234
1692
|
return undefined;
|
|
1235
1693
|
}
|
|
1236
|
-
|
|
1237
|
-
// ~60ms cost on no-op/early-exit builds. Close the better-sqlite3 connection
|
|
1238
|
-
// first to avoid dual-connection WAL corruption.
|
|
1239
|
-
if (!ctx.nativeDb && ctx.nativeAvailable) {
|
|
1240
|
-
const native = loadNative();
|
|
1241
|
-
if (native?.NativeDatabase) {
|
|
1242
|
-
try {
|
|
1243
|
-
// Close better-sqlite3 before opening rusqlite to avoid WAL conflicts.
|
|
1244
|
-
// Uses raw close() instead of closeDb() intentionally — the advisory lock
|
|
1245
|
-
// is kept and transferred to the NativeDbProxy below, not released here.
|
|
1246
|
-
ctx.db.close();
|
|
1247
|
-
acquireAdvisoryLock(ctx.dbPath);
|
|
1248
|
-
ctx.nativeDb = native.NativeDatabase.openReadWrite(ctx.dbPath);
|
|
1249
|
-
ctx.nativeDb.initSchema();
|
|
1250
|
-
// Replace ctx.db with a NativeDbProxy so post-native JS fallback
|
|
1251
|
-
// (structure, analysis) can use it without reopening better-sqlite3.
|
|
1252
|
-
const proxy = new NativeDbProxy(ctx.nativeDb);
|
|
1253
|
-
proxy.__lockPath = `${ctx.dbPath}.lock`;
|
|
1254
|
-
ctx.db = proxy;
|
|
1255
|
-
ctx.nativeFirstProxy = true;
|
|
1256
|
-
}
|
|
1257
|
-
catch (err) {
|
|
1258
|
-
warn(`NativeDatabase setup failed, falling back to JS: ${toErrorMessage(err)}`);
|
|
1259
|
-
try {
|
|
1260
|
-
ctx.nativeDb?.close();
|
|
1261
|
-
}
|
|
1262
|
-
catch (e) {
|
|
1263
|
-
debug(`tryNativeOrchestrator: close failed during fallback: ${toErrorMessage(e)}`);
|
|
1264
|
-
}
|
|
1265
|
-
ctx.nativeDb = undefined;
|
|
1266
|
-
ctx.nativeFirstProxy = false; // defensive: reset in case future refactors move the assignment above throwing lines
|
|
1267
|
-
releaseAdvisoryLock(`${ctx.dbPath}.lock`);
|
|
1268
|
-
// Reopen better-sqlite3 for JS pipeline fallback
|
|
1269
|
-
ctx.db = openDb(ctx.dbPath);
|
|
1270
|
-
}
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1694
|
+
openNativeDatabase(ctx);
|
|
1273
1695
|
if (!ctx.nativeDb?.buildGraph)
|
|
1274
1696
|
return undefined;
|
|
1275
|
-
|
|
1697
|
+
// The previous full build's clear_all_graph_data() sets PRAGMA foreign_keys = ON
|
|
1698
|
+
// on the native connection. Older native binaries (< v3.14) do not delete
|
|
1699
|
+
// dataflow_vertices / dataflow_summary / call_edge_id rows before purging
|
|
1700
|
+
// nodes/edges during incremental builds, so FK enforcement causes the purge
|
|
1701
|
+
// statements to fail silently — leaving stale nodes and edges that then get
|
|
1702
|
+
// duplicated when the barrel-candidate re-parse re-inserts them (issue #1644).
|
|
1703
|
+
// Disabling FK before buildGraph() lets the purge succeed; FK is restored in
|
|
1704
|
+
// a finally block so post-passes (gap-repair, structure patch) retain FK protection
|
|
1705
|
+
// even if buildGraph() throws.
|
|
1706
|
+
try {
|
|
1707
|
+
ctx.nativeDb.exec('PRAGMA foreign_keys = OFF');
|
|
1708
|
+
}
|
|
1709
|
+
catch {
|
|
1710
|
+
// exec may not exist on very old addon versions — safe to ignore
|
|
1711
|
+
}
|
|
1712
|
+
let resultJson;
|
|
1713
|
+
try {
|
|
1714
|
+
resultJson = ctx.nativeDb.buildGraph(ctx.rootDir, JSON.stringify(ctx.config), JSON.stringify(ctx.aliases), JSON.stringify(ctx.opts));
|
|
1715
|
+
}
|
|
1716
|
+
finally {
|
|
1717
|
+
// Restore FK enforcement so any subsequent writes to this connection
|
|
1718
|
+
// (gap-repair, structure patch) retain FK protection — even if buildGraph()
|
|
1719
|
+
// throws.
|
|
1720
|
+
try {
|
|
1721
|
+
ctx.nativeDb.exec('PRAGMA foreign_keys = ON');
|
|
1722
|
+
}
|
|
1723
|
+
catch {
|
|
1724
|
+
// safe to ignore on very old addon versions
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1276
1727
|
const result = JSON.parse(resultJson);
|
|
1277
1728
|
if (result.earlyExit) {
|
|
1278
1729
|
info('No changes detected');
|
|
@@ -1362,112 +1813,7 @@ export async function tryNativeOrchestrator(ctx) {
|
|
|
1362
1813
|
});
|
|
1363
1814
|
}
|
|
1364
1815
|
}
|
|
1365
|
-
|
|
1366
|
-
// Engine parity: the native orchestrator silently drops files whose
|
|
1367
|
-
// Rust extractor/grammar is missing or fails (e.g. HCL, Scala, Swift on
|
|
1368
|
-
// stale native binaries). WASM handles those — backfill via WASM so both
|
|
1369
|
-
// engines process the same file set (#967).
|
|
1370
|
-
//
|
|
1371
|
-
// Detect the gap once (fs walk + 2 DB queries) and use it for both gating
|
|
1372
|
-
// and the backfill itself. On quiet incrementals we still pay the walk so
|
|
1373
|
-
// we can detect brand-new files in dropped-language extensions — a gap that
|
|
1374
|
-
// the orchestrator's `detect_removed_files` filter (#1070) leaves open
|
|
1375
|
-
// (#1083, #1091). The pre-check is cheap because the expensive part (WASM
|
|
1376
|
-
// re-parse of the missing set) is gated below.
|
|
1377
|
-
const gapDetectStart = performance.now();
|
|
1378
|
-
const gap = detectDroppedLanguageGap(ctx);
|
|
1379
|
-
const backfillHappened = gap.missingAbs.length > 0 || gap.staleRel.length > 0;
|
|
1380
|
-
if (backfillHappened) {
|
|
1381
|
-
await backfillNativeDroppedFiles(ctx, gap);
|
|
1382
|
-
}
|
|
1383
|
-
const gapDetectMs = performance.now() - gapDetectStart;
|
|
1384
|
-
// Phase 8.5: this/super dispatch — hybrid WASM re-parse to resolve call sites
|
|
1385
|
-
// whose raw receiver info the Rust pipeline does not persist to DB.
|
|
1386
|
-
// Runs BEFORE the CHA expansion pass so that super.method() → Parent.method edges
|
|
1387
|
-
// (technique='cha') are in the DB when runPostNativeCha expands them to sibling
|
|
1388
|
-
// class overrides (e.g. PostMixin.m → B.m when PostMixin and B both extend A).
|
|
1389
|
-
const { elapsedMs: thisDispatchMs, targetIds: thisDispatchTargetIds, affectedFiles: thisDispatchAffectedFiles, } = await runPostNativeThisDispatch(ctx.db, ctx.rootDir, result.changedFiles, !!result.isFullBuild);
|
|
1390
|
-
// Phase 8.6: expand CHA call edges (interface dispatch → concrete implementations).
|
|
1391
|
-
// Returns the affected files so role re-classification below can be scoped to
|
|
1392
|
-
// the nodes whose fan-in/out actually changed.
|
|
1393
|
-
//
|
|
1394
|
-
// Runs AFTER this/super dispatch so super.method() edges are already in the DB.
|
|
1395
|
-
// The 'cha-expanded' technique tag on this pass's own output prevents re-expansion
|
|
1396
|
-
// of those edges in subsequent incremental builds, while 'cha'-tagged edges from
|
|
1397
|
-
// this/super dispatch remain eligible for expansion here.
|
|
1398
|
-
//
|
|
1399
|
-
// Function-as-object-property methods (`fn.method = function() {}`) are extracted
|
|
1400
|
-
// natively by the Rust engine (#1432) and resolved in-build by its edge builder, so
|
|
1401
|
-
// no WASM re-parse post-pass is needed for them. `Foo.prototype.bar = fn` likewise.
|
|
1402
|
-
const chaStart = performance.now();
|
|
1403
|
-
const { newEdgeCount: chaEdgeCount, affectedFiles: chaAffectedFiles } = runPostNativeCha(ctx.db,
|
|
1404
|
-
// null = full build (scan all call→method edges); array = incremental (gate queries decide scope)
|
|
1405
|
-
result.isFullBuild ? null : (result.changedFiles ?? null));
|
|
1406
|
-
const chaMs = performance.now() - chaStart;
|
|
1407
|
-
// Role re-classification after JS edge-writing post-passes.
|
|
1408
|
-
// The Rust orchestrator classifies roles before these post-passes (CHA,
|
|
1409
|
-
// this-dispatch) add edges, so roles for the edge endpoints are stale.
|
|
1410
|
-
// Scoped to the files containing those endpoints: a new edge only changes
|
|
1411
|
-
// fan-in/out for its own source and target nodes, so re-classifying their
|
|
1412
|
-
// files restores correctness without re-running the classifier over the
|
|
1413
|
-
// whole graph (which cost ~130ms per build on codegraph itself and was a
|
|
1414
|
-
// major part of the v3.12.0 native full-build benchmark regression).
|
|
1415
|
-
let reclassifyMs = 0;
|
|
1416
|
-
if (chaEdgeCount > 0 || thisDispatchTargetIds.size > 0) {
|
|
1417
|
-
const affectedFiles = [...new Set([...chaAffectedFiles, ...thisDispatchAffectedFiles])];
|
|
1418
|
-
// When edges were inserted but all their endpoint nodes have null `file`
|
|
1419
|
-
// columns (rare but possible), affectedFiles stays empty even though
|
|
1420
|
-
// fan-in/out changed. Fall back to full-graph re-classification in that
|
|
1421
|
-
// case — scoped classification with an empty set would be a no-op, leaving
|
|
1422
|
-
// roles stale for those nodes.
|
|
1423
|
-
const scopedFiles = affectedFiles.length > 0 ? affectedFiles : null;
|
|
1424
|
-
const reclassifyStart = performance.now();
|
|
1425
|
-
try {
|
|
1426
|
-
const { classifyNodeRoles } = (await import('../../../../features/structure.js'));
|
|
1427
|
-
classifyNodeRoles(ctx.db, scopedFiles);
|
|
1428
|
-
debug(scopedFiles
|
|
1429
|
-
? `Post-pass role re-classification complete (${scopedFiles.length} file(s))`
|
|
1430
|
-
: 'Post-pass role re-classification complete (full graph — null-file endpoints)');
|
|
1431
|
-
}
|
|
1432
|
-
catch (err) {
|
|
1433
|
-
debug(`Post-pass role re-classification failed: ${toErrorMessage(err)}`);
|
|
1434
|
-
}
|
|
1435
|
-
reclassifyMs = performance.now() - reclassifyStart;
|
|
1436
|
-
}
|
|
1437
|
-
// Backfill the `technique` column on `calls` edges written by the Rust
|
|
1438
|
-
// orchestrator, which does not write the column. Runs after all edge-writing
|
|
1439
|
-
// phases (including the WASM dropped-language backfill, CHA post-pass, and
|
|
1440
|
-
// this/super dispatch) so every new edge in this build cycle gets a label.
|
|
1441
|
-
const techniqueBackfillStart = performance.now();
|
|
1442
|
-
backfillEdgeTechniquesAfterNativeOrchestrator(ctx.db, !!result.isFullBuild, result.changedFiles);
|
|
1443
|
-
const techniqueBackfillMs = performance.now() - techniqueBackfillStart;
|
|
1444
|
-
// Re-count nodes/edges now that all edge-writing post-passes have run: the
|
|
1445
|
-
// Rust orchestrator captured its counts before the JS post-passes added
|
|
1446
|
-
// edges, so both its summary and build_meta under-report (#1452).
|
|
1447
|
-
//
|
|
1448
|
-
// Fast path: skip the COUNT(*) scan when no post-pass wrote any edges.
|
|
1449
|
-
// COUNT(*) on large tables (50K+ edges) is non-trivial, especially via the
|
|
1450
|
-
// NativeDbProxy napi-rs round-trip. When all post-passes were no-ops, the
|
|
1451
|
-
// Rust orchestrator's counts are still accurate — no re-count needed.
|
|
1452
|
-
let finalNodeCount = result.nodeCount ?? 0;
|
|
1453
|
-
let finalEdgeCount = result.edgeCount ?? 0;
|
|
1454
|
-
const postPassWroteData = backfillHappened || chaEdgeCount > 0 || thisDispatchTargetIds.size > 0;
|
|
1455
|
-
if (postPassWroteData) {
|
|
1456
|
-
try {
|
|
1457
|
-
const counts = ctx.db
|
|
1458
|
-
.prepare('SELECT (SELECT COUNT(*) FROM nodes) AS n, (SELECT COUNT(*) FROM edges) AS e')
|
|
1459
|
-
.get();
|
|
1460
|
-
if (counts.n !== finalNodeCount || counts.e !== finalEdgeCount) {
|
|
1461
|
-
finalNodeCount = counts.n;
|
|
1462
|
-
finalEdgeCount = counts.e;
|
|
1463
|
-
setBuildMeta(ctx.db, { node_count: finalNodeCount, edge_count: finalEdgeCount });
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
catch (err) {
|
|
1467
|
-
debug(`Post-pass node/edge re-count failed: ${toErrorMessage(err)}`);
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
|
-
info(`Native build orchestrator completed: ${finalNodeCount} nodes, ${finalEdgeCount} edges, ${result.fileCount ?? 0} files`);
|
|
1816
|
+
const postPassTimings = await runPostNativePasses(ctx, result);
|
|
1471
1817
|
// ── Structure and analysis fallback (run after edge-writing so roles see full graph) ──
|
|
1472
1818
|
// Reconstruct fileSymbols once for both structure and analysis to avoid two
|
|
1473
1819
|
// expensive DB scans. The DB handoff above already ensured ctx.db is a proper
|
|
@@ -1481,13 +1827,17 @@ export async function tryNativeOrchestrator(ctx) {
|
|
|
1481
1827
|
analysisTiming = await runPostNativeAnalysis(ctx, fileSymbols, result.changedFiles);
|
|
1482
1828
|
}
|
|
1483
1829
|
}
|
|
1830
|
+
// P6: Vertex extraction for the analysisComplete=true path.
|
|
1831
|
+
// When needsAnalysisFallback=false (the normal native case), runPostNativeAnalysis
|
|
1832
|
+
// was skipped, so buildDataflowEdges never ran and dataflow_vertices were never
|
|
1833
|
+
// populated. Re-run the Rust dataflow visitor per file (fast — no re-parse) to
|
|
1834
|
+
// get the DataflowResult, then build vertices and inter-procedural edges.
|
|
1835
|
+
// Languages where Rust has no dataflow rules are silently skipped; a WASM
|
|
1836
|
+
// fallback for those is tracked in issue #1614.
|
|
1837
|
+
if (ctx.opts.dataflow !== false && !needsAnalysisFallback) {
|
|
1838
|
+
await runDataflowVertexPass(ctx, result.changedFiles);
|
|
1839
|
+
}
|
|
1484
1840
|
closeDbPair({ db: ctx.db, nativeDb: ctx.nativeDb });
|
|
1485
|
-
return formatNativeTimingResult(p, structurePatchMs, analysisTiming,
|
|
1486
|
-
gapDetectMs,
|
|
1487
|
-
chaMs,
|
|
1488
|
-
thisDispatchMs,
|
|
1489
|
-
reclassifyMs,
|
|
1490
|
-
techniqueBackfillMs,
|
|
1491
|
-
});
|
|
1841
|
+
return formatNativeTimingResult(p, structurePatchMs, analysisTiming, postPassTimings);
|
|
1492
1842
|
}
|
|
1493
1843
|
//# sourceMappingURL=native-orchestrator.js.map
|