@colbymchenry/codegraph-win32-arm64 1.4.1 → 1.6.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/bin/codegraph.cmd +1 -1
- package/lib/dist/bin/codegraph.js +206 -44
- package/lib/dist/bin/codegraph.js.map +1 -1
- package/lib/dist/context/formatter.d.ts +7 -1
- package/lib/dist/context/formatter.d.ts.map +1 -1
- package/lib/dist/context/formatter.js +12 -6
- package/lib/dist/context/formatter.js.map +1 -1
- package/lib/dist/context/index.d.ts +12 -0
- package/lib/dist/context/index.d.ts.map +1 -1
- package/lib/dist/context/index.js +101 -25
- package/lib/dist/context/index.js.map +1 -1
- package/lib/dist/db/index.d.ts +179 -0
- package/lib/dist/db/index.d.ts.map +1 -1
- package/lib/dist/db/index.js +368 -7
- package/lib/dist/db/index.js.map +1 -1
- package/lib/dist/db/migrations.d.ts +1 -1
- package/lib/dist/db/migrations.d.ts.map +1 -1
- package/lib/dist/db/migrations.js +25 -1
- package/lib/dist/db/migrations.js.map +1 -1
- package/lib/dist/db/queries.d.ts +234 -5
- package/lib/dist/db/queries.d.ts.map +1 -1
- package/lib/dist/db/queries.js +687 -53
- package/lib/dist/db/queries.js.map +1 -1
- package/lib/dist/db/schema.sql +16 -3
- package/lib/dist/db/sqlite-adapter.d.ts +3 -1
- package/lib/dist/db/sqlite-adapter.d.ts.map +1 -1
- package/lib/dist/db/sqlite-adapter.js +22 -4
- package/lib/dist/db/sqlite-adapter.js.map +1 -1
- package/lib/dist/db/wal-valve.d.ts +15 -2
- package/lib/dist/db/wal-valve.d.ts.map +1 -1
- package/lib/dist/db/wal-valve.js +88 -6
- package/lib/dist/db/wal-valve.js.map +1 -1
- package/lib/dist/directory.d.ts +29 -0
- package/lib/dist/directory.d.ts.map +1 -1
- package/lib/dist/directory.js +52 -0
- package/lib/dist/directory.js.map +1 -1
- package/lib/dist/extraction/extraction-version.d.ts +1 -1
- package/lib/dist/extraction/extraction-version.js +1 -1
- package/lib/dist/extraction/function-ref.d.ts.map +1 -1
- package/lib/dist/extraction/function-ref.js +6 -0
- package/lib/dist/extraction/function-ref.js.map +1 -1
- package/lib/dist/extraction/generated-detection.d.ts +48 -12
- package/lib/dist/extraction/generated-detection.d.ts.map +1 -1
- package/lib/dist/extraction/generated-detection.js +176 -11
- package/lib/dist/extraction/generated-detection.js.map +1 -1
- package/lib/dist/extraction/grammars.d.ts.map +1 -1
- package/lib/dist/extraction/grammars.js +101 -2
- package/lib/dist/extraction/grammars.js.map +1 -1
- package/lib/dist/extraction/index.d.ts +138 -3
- package/lib/dist/extraction/index.d.ts.map +1 -1
- package/lib/dist/extraction/index.js +518 -94
- package/lib/dist/extraction/index.js.map +1 -1
- package/lib/dist/extraction/kernel/decode.d.ts +9 -0
- package/lib/dist/extraction/kernel/decode.d.ts.map +1 -0
- package/lib/dist/extraction/kernel/decode.js +162 -0
- package/lib/dist/extraction/kernel/decode.js.map +1 -0
- package/lib/dist/extraction/kernel/index.d.ts +64 -0
- package/lib/dist/extraction/kernel/index.d.ts.map +1 -0
- package/lib/dist/extraction/kernel/index.js +279 -0
- package/lib/dist/extraction/kernel/index.js.map +1 -0
- package/lib/dist/extraction/kernel/layout.d.ts +101 -0
- package/lib/dist/extraction/kernel/layout.d.ts.map +1 -0
- package/lib/dist/extraction/kernel/layout.js +104 -0
- package/lib/dist/extraction/kernel/layout.js.map +1 -0
- package/lib/dist/extraction/kernel/loader.d.ts +103 -0
- package/lib/dist/extraction/kernel/loader.d.ts.map +1 -0
- package/lib/dist/extraction/kernel/loader.js +146 -0
- package/lib/dist/extraction/kernel/loader.js.map +1 -0
- package/lib/dist/extraction/languages/c-cpp.d.ts +14 -0
- package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -1
- package/lib/dist/extraction/languages/c-cpp.js +868 -16
- package/lib/dist/extraction/languages/c-cpp.js.map +1 -1
- package/lib/dist/extraction/languages/erlang.d.ts.map +1 -1
- package/lib/dist/extraction/languages/erlang.js +58 -22
- package/lib/dist/extraction/languages/erlang.js.map +1 -1
- package/lib/dist/extraction/languages/objc.d.ts.map +1 -1
- package/lib/dist/extraction/languages/objc.js +4 -0
- package/lib/dist/extraction/languages/objc.js.map +1 -1
- package/lib/dist/extraction/languages/rust.d.ts +20 -0
- package/lib/dist/extraction/languages/rust.d.ts.map +1 -1
- package/lib/dist/extraction/languages/rust.js +47 -20
- package/lib/dist/extraction/languages/rust.js.map +1 -1
- package/lib/dist/extraction/parse-pool.d.ts +15 -0
- package/lib/dist/extraction/parse-pool.d.ts.map +1 -1
- package/lib/dist/extraction/parse-pool.js +35 -1
- package/lib/dist/extraction/parse-pool.js.map +1 -1
- package/lib/dist/extraction/parse-worker.js +35 -1
- package/lib/dist/extraction/parse-worker.js.map +1 -1
- package/lib/dist/extraction/store-worker.d.ts +24 -0
- package/lib/dist/extraction/store-worker.d.ts.map +1 -0
- package/lib/dist/extraction/store-worker.js +139 -0
- package/lib/dist/extraction/store-worker.js.map +1 -0
- package/lib/dist/extraction/store-writer.d.ts +63 -0
- package/lib/dist/extraction/store-writer.d.ts.map +1 -0
- package/lib/dist/extraction/store-writer.js +174 -0
- package/lib/dist/extraction/store-writer.js.map +1 -0
- package/lib/dist/extraction/tree-sitter-types.d.ts +2 -0
- package/lib/dist/extraction/tree-sitter-types.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.d.ts +27 -5
- package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.js +257 -56
- package/lib/dist/extraction/tree-sitter.js.map +1 -1
- package/lib/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
- package/lib/dist/extraction/wasm-runtime-flags.d.ts +15 -0
- package/lib/dist/extraction/wasm-runtime-flags.d.ts.map +1 -1
- package/lib/dist/extraction/wasm-runtime-flags.js +27 -3
- package/lib/dist/extraction/wasm-runtime-flags.js.map +1 -1
- package/lib/dist/graph/queries.d.ts.map +1 -1
- package/lib/dist/graph/queries.js +2 -0
- package/lib/dist/graph/queries.js.map +1 -1
- package/lib/dist/graph/traversal.js +1 -1
- package/lib/dist/graph/traversal.js.map +1 -1
- package/lib/dist/index.d.ts +36 -2
- package/lib/dist/index.d.ts.map +1 -1
- package/lib/dist/index.js +305 -11
- package/lib/dist/index.js.map +1 -1
- package/lib/dist/installer/beta-signup.d.ts +54 -0
- package/lib/dist/installer/beta-signup.d.ts.map +1 -0
- package/lib/dist/installer/beta-signup.js +178 -0
- package/lib/dist/installer/beta-signup.js.map +1 -0
- package/lib/dist/installer/index.d.ts +4 -3
- package/lib/dist/installer/index.d.ts.map +1 -1
- package/lib/dist/installer/index.js +19 -6
- package/lib/dist/installer/index.js.map +1 -1
- package/lib/dist/installer/targets/claude.d.ts.map +1 -1
- package/lib/dist/installer/targets/claude.js +37 -5
- package/lib/dist/installer/targets/claude.js.map +1 -1
- package/lib/dist/installer/targets/codex.d.ts +22 -8
- package/lib/dist/installer/targets/codex.d.ts.map +1 -1
- package/lib/dist/installer/targets/codex.js +65 -48
- package/lib/dist/installer/targets/codex.js.map +1 -1
- package/lib/dist/installer/targets/copilot-cli.d.ts +32 -0
- package/lib/dist/installer/targets/copilot-cli.d.ts.map +1 -0
- package/lib/dist/installer/targets/copilot-cli.js +209 -0
- package/lib/dist/installer/targets/copilot-cli.js.map +1 -0
- package/lib/dist/installer/targets/copilot-jetbrains.d.ts +42 -0
- package/lib/dist/installer/targets/copilot-jetbrains.d.ts.map +1 -0
- package/lib/dist/installer/targets/copilot-jetbrains.js +238 -0
- package/lib/dist/installer/targets/copilot-jetbrains.js.map +1 -0
- package/lib/dist/installer/targets/copilot-vscode.d.ts +47 -0
- package/lib/dist/installer/targets/copilot-vscode.d.ts.map +1 -0
- package/lib/dist/installer/targets/copilot-vscode.js +219 -0
- package/lib/dist/installer/targets/copilot-vscode.js.map +1 -0
- package/lib/dist/installer/targets/registry.d.ts.map +1 -1
- package/lib/dist/installer/targets/registry.js +6 -0
- package/lib/dist/installer/targets/registry.js.map +1 -1
- package/lib/dist/installer/targets/toml.d.ts +6 -5
- package/lib/dist/installer/targets/toml.d.ts.map +1 -1
- package/lib/dist/installer/targets/toml.js +99 -20
- package/lib/dist/installer/targets/toml.js.map +1 -1
- package/lib/dist/installer/targets/types.d.ts +5 -5
- package/lib/dist/installer/targets/types.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-manager.d.ts +1 -1
- package/lib/dist/mcp/daemon-manager.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-manager.js +1 -1
- package/lib/dist/mcp/daemon-manager.js.map +1 -1
- package/lib/dist/mcp/daemon-paths.d.ts +6 -0
- package/lib/dist/mcp/daemon-paths.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-paths.js +54 -0
- package/lib/dist/mcp/daemon-paths.js.map +1 -1
- package/lib/dist/mcp/daemon-registry.d.ts +10 -0
- package/lib/dist/mcp/daemon-registry.d.ts.map +1 -1
- package/lib/dist/mcp/daemon-registry.js +51 -3
- package/lib/dist/mcp/daemon-registry.js.map +1 -1
- package/lib/dist/mcp/daemon.d.ts +9 -6
- package/lib/dist/mcp/daemon.d.ts.map +1 -1
- package/lib/dist/mcp/daemon.js +10 -8
- package/lib/dist/mcp/daemon.js.map +1 -1
- package/lib/dist/mcp/engine.d.ts +3 -0
- package/lib/dist/mcp/engine.d.ts.map +1 -1
- package/lib/dist/mcp/engine.js +45 -3
- package/lib/dist/mcp/engine.js.map +1 -1
- package/lib/dist/mcp/explore-dedup.d.ts +137 -0
- package/lib/dist/mcp/explore-dedup.d.ts.map +1 -0
- package/lib/dist/mcp/explore-dedup.js +236 -0
- package/lib/dist/mcp/explore-dedup.js.map +1 -0
- package/lib/dist/mcp/explore-diagnostics.d.ts +289 -0
- package/lib/dist/mcp/explore-diagnostics.d.ts.map +1 -0
- package/lib/dist/mcp/explore-diagnostics.js +558 -0
- package/lib/dist/mcp/explore-diagnostics.js.map +1 -0
- package/lib/dist/mcp/explore-session-state.d.ts +217 -0
- package/lib/dist/mcp/explore-session-state.d.ts.map +1 -0
- package/lib/dist/mcp/explore-session-state.js +322 -0
- package/lib/dist/mcp/explore-session-state.js.map +1 -0
- package/lib/dist/mcp/index.d.ts +24 -0
- package/lib/dist/mcp/index.d.ts.map +1 -1
- package/lib/dist/mcp/index.js +67 -6
- package/lib/dist/mcp/index.js.map +1 -1
- package/lib/dist/mcp/liveness-watchdog.d.ts.map +1 -1
- package/lib/dist/mcp/liveness-watchdog.js +3 -1
- package/lib/dist/mcp/liveness-watchdog.js.map +1 -1
- package/lib/dist/mcp/proxy.d.ts.map +1 -1
- package/lib/dist/mcp/proxy.js +6 -1
- package/lib/dist/mcp/proxy.js.map +1 -1
- package/lib/dist/mcp/server-instructions.d.ts +2 -2
- package/lib/dist/mcp/server-instructions.d.ts.map +1 -1
- package/lib/dist/mcp/server-instructions.js +8 -3
- package/lib/dist/mcp/server-instructions.js.map +1 -1
- package/lib/dist/mcp/session.d.ts +16 -0
- package/lib/dist/mcp/session.d.ts.map +1 -1
- package/lib/dist/mcp/session.js +36 -13
- package/lib/dist/mcp/session.js.map +1 -1
- package/lib/dist/mcp/tools.d.ts +276 -10
- package/lib/dist/mcp/tools.d.ts.map +1 -1
- package/lib/dist/mcp/tools.js +2425 -237
- package/lib/dist/mcp/tools.js.map +1 -1
- package/lib/dist/project-config.d.ts +23 -0
- package/lib/dist/project-config.d.ts.map +1 -1
- package/lib/dist/project-config.js +39 -2
- package/lib/dist/project-config.js.map +1 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.d.ts +1 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.js +582 -138
- package/lib/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.d.ts +54 -10
- package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.js +287 -167
- package/lib/dist/resolution/callback-synthesizer.js.map +1 -1
- package/lib/dist/resolution/cooperative-yield.d.ts +10 -2
- package/lib/dist/resolution/cooperative-yield.d.ts.map +1 -1
- package/lib/dist/resolution/cooperative-yield.js +6 -4
- package/lib/dist/resolution/cooperative-yield.js.map +1 -1
- package/lib/dist/resolution/frameworks/go.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/go.js +29 -6
- package/lib/dist/resolution/frameworks/go.js.map +1 -1
- package/lib/dist/resolution/frameworks/swift.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/swift.js +11 -1
- package/lib/dist/resolution/frameworks/swift.js.map +1 -1
- package/lib/dist/resolution/import-resolver.d.ts +2 -3
- package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
- package/lib/dist/resolution/import-resolver.js +184 -9
- package/lib/dist/resolution/import-resolver.js.map +1 -1
- package/lib/dist/resolution/index.d.ts +87 -2
- package/lib/dist/resolution/index.d.ts.map +1 -1
- package/lib/dist/resolution/index.js +731 -134
- package/lib/dist/resolution/index.js.map +1 -1
- package/lib/dist/resolution/memory-budget.d.ts +48 -0
- package/lib/dist/resolution/memory-budget.d.ts.map +1 -0
- package/lib/dist/resolution/memory-budget.js +162 -0
- package/lib/dist/resolution/memory-budget.js.map +1 -0
- package/lib/dist/resolution/name-matcher.d.ts +42 -1
- package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
- package/lib/dist/resolution/name-matcher.js +681 -99
- package/lib/dist/resolution/name-matcher.js.map +1 -1
- package/lib/dist/resolution/path-aliases.d.ts +6 -4
- package/lib/dist/resolution/path-aliases.d.ts.map +1 -1
- package/lib/dist/resolution/path-aliases.js +125 -17
- package/lib/dist/resolution/path-aliases.js.map +1 -1
- package/lib/dist/resolution/resolver-pool.d.ts +106 -0
- package/lib/dist/resolution/resolver-pool.d.ts.map +1 -0
- package/lib/dist/resolution/resolver-pool.js +344 -0
- package/lib/dist/resolution/resolver-pool.js.map +1 -0
- package/lib/dist/resolution/resolver-worker.d.ts +17 -0
- package/lib/dist/resolution/resolver-worker.d.ts.map +1 -0
- package/lib/dist/resolution/resolver-worker.js +141 -0
- package/lib/dist/resolution/resolver-worker.js.map +1 -0
- package/lib/dist/resolution/types.d.ts +3 -0
- package/lib/dist/resolution/types.d.ts.map +1 -1
- package/lib/dist/search/identifier-segments.d.ts +10 -0
- package/lib/dist/search/identifier-segments.d.ts.map +1 -1
- package/lib/dist/search/identifier-segments.js +29 -0
- package/lib/dist/search/identifier-segments.js.map +1 -1
- package/lib/dist/search/query-paths.d.ts +57 -0
- package/lib/dist/search/query-paths.d.ts.map +1 -0
- package/lib/dist/search/query-paths.js +298 -0
- package/lib/dist/search/query-paths.js.map +1 -0
- package/lib/dist/search/query-utils.d.ts +1 -1
- package/lib/dist/search/query-utils.d.ts.map +1 -1
- package/lib/dist/search/query-utils.js +13 -3
- package/lib/dist/search/query-utils.js.map +1 -1
- package/lib/dist/sync/watcher.d.ts +47 -1
- package/lib/dist/sync/watcher.d.ts.map +1 -1
- package/lib/dist/sync/watcher.js +127 -8
- package/lib/dist/sync/watcher.js.map +1 -1
- package/lib/dist/types.d.ts +61 -3
- package/lib/dist/types.d.ts.map +1 -1
- package/lib/dist/types.js +27 -1
- package/lib/dist/types.js.map +1 -1
- package/lib/dist/ui/color.d.ts +21 -0
- package/lib/dist/ui/color.d.ts.map +1 -0
- package/lib/dist/ui/color.js +42 -0
- package/lib/dist/ui/color.js.map +1 -0
- package/lib/dist/ui/glyphs.d.ts +35 -10
- package/lib/dist/ui/glyphs.d.ts.map +1 -1
- package/lib/dist/ui/glyphs.js +59 -12
- package/lib/dist/ui/glyphs.js.map +1 -1
- package/lib/dist/ui/shimmer-progress.d.ts.map +1 -1
- package/lib/dist/ui/shimmer-progress.js +78 -4
- package/lib/dist/ui/shimmer-progress.js.map +1 -1
- package/lib/dist/ui/shimmer-worker.js +25 -17
- package/lib/dist/ui/shimmer-worker.js.map +1 -1
- package/lib/dist/ui/types.d.ts +0 -2
- package/lib/dist/ui/types.d.ts.map +1 -1
- package/lib/dist/upgrade/index.d.ts +7 -0
- package/lib/dist/upgrade/index.d.ts.map +1 -1
- package/lib/dist/upgrade/index.js +18 -5
- package/lib/dist/upgrade/index.js.map +1 -1
- package/lib/kernel/codegraph-kernel.node +0 -0
- package/lib/node_modules/.package-lock.json +1 -1
- package/lib/package.json +6 -1
- package/package.json +6 -2
|
@@ -83,17 +83,55 @@ exports.cFnPointerDispatchEdges = cFnPointerDispatchEdges;
|
|
|
83
83
|
* Whole-graph pass after base resolution; all edges are `provenance:'heuristic'`
|
|
84
84
|
* (`synthesizedBy:'fn-pointer-dispatch'`). High precision via the (type, field)
|
|
85
85
|
* key + a real-function gate; a project with no fn-pointer dispatch is a no-op.
|
|
86
|
+
*
|
|
87
|
+
* ## Fuse-then-link architecture (§7a.8, task #5 step 1)
|
|
88
|
+
*
|
|
89
|
+
* The pass used to sweep every file's text FOUR times (typedefs, registrations,
|
|
90
|
+
* propagation, dispatch), and on the Linux kernel the all-or-nothing source
|
|
91
|
+
* cache declines, so each sweep re-read + re-stripped the whole corpus — 4.4
|
|
92
|
+
* strips/file, ~78s of the ~230s kernel-scale wall (§7a.8 calibration). It now
|
|
93
|
+
* runs as ONE extraction sweep plus filtered linking stages:
|
|
94
|
+
*
|
|
95
|
+
* 1. **Extraction sweep** — reads + strips each file ONCE and collects, per
|
|
96
|
+
* file: typedef names, each struct node's field declarations (parsed
|
|
97
|
+
* structurally, fn-pointer classification deferred — the typedef sets
|
|
98
|
+
* aren't complete mid-sweep), the resolved local includes, and cheap
|
|
99
|
+
* SURVIVAL FILTERS for the later stages (distinct initializer type
|
|
100
|
+
* tokens, array element types, inline-struct summaries, field-assignment
|
|
101
|
+
* field pairs, dispatch field / array names — all interned, a few MB even
|
|
102
|
+
* on the kernel).
|
|
103
|
+
* 2. **Struct-layout linking** — classifies the deferred fields against the
|
|
104
|
+
* now-complete typedef sets and registers layouts by replaying the struct
|
|
105
|
+
* kind-scan, so registration order (which decides same-name layout
|
|
106
|
+
* precedence) is byte-identical to the old dedicated pass.
|
|
107
|
+
* 3. **Registration / propagation / dispatch** — the original pass bodies,
|
|
108
|
+
* UNCHANGED, but each file is first checked against its survival filter
|
|
109
|
+
* and only surviving files are re-stripped (LRU-served). The filters only
|
|
110
|
+
* ever over-approximate: a filtered-out file is one where every match
|
|
111
|
+
* would have failed the pass's own gates before any side effect, so
|
|
112
|
+
* skipping it cannot change the edge set. On the kernel only ~16% of
|
|
113
|
+
* files have any dispatch-shaped match at all, so the lazy re-strips are
|
|
114
|
+
* a fraction of a sweep and total strip work drops ~4.4× → ~1.5×.
|
|
115
|
+
*
|
|
116
|
+
* The extraction sweep is also the step-2 boundary: a native per-file extractor
|
|
117
|
+
* can replace the sweep's scans without touching the linking stages.
|
|
86
118
|
*/
|
|
87
119
|
const path = __importStar(require("node:path"));
|
|
120
|
+
const memory_budget_1 = require("./memory-budget");
|
|
88
121
|
const lru_cache_1 = require("./lru-cache");
|
|
89
122
|
const strip_comments_1 = require("./strip-comments");
|
|
123
|
+
const loader_1 = require("../extraction/kernel/loader");
|
|
90
124
|
const C_CPP_EXT = /\.(c|h|cc|cpp|cxx|hpp|hh|hxx|cppm|ipp|inl|tcc)$/i;
|
|
91
125
|
const FN_KINDS = new Set(['function', 'method']);
|
|
92
126
|
const FANOUT_CAP = 300; // a real command table (git ~150) is legitimate fan-out; this only stops pathological cases.
|
|
93
|
-
|
|
127
|
+
/** Slice a node's body from a pre-split line array — the per-file sweeps
|
|
128
|
+
* call this once per NODE, and splitting the whole file per node was an
|
|
129
|
+
* O(nodes × file-size) term (~1.6M full-file splits on the Linux tree,
|
|
130
|
+
* §7a.3 cFnPtr round). Split once per file, slice many times. */
|
|
131
|
+
function sliceLinesPre(lines, startLine, endLine) {
|
|
94
132
|
if (!startLine)
|
|
95
133
|
return '';
|
|
96
|
-
return
|
|
134
|
+
return lines.slice(startLine - 1, endLine ?? startLine).join('\n');
|
|
97
135
|
}
|
|
98
136
|
/** Index of the `}` matching the `{` at `open` (which must point at a `{`). -1 if unbalanced. */
|
|
99
137
|
function matchBrace(src, open) {
|
|
@@ -274,7 +312,7 @@ function resolveTypeName(name, objEnv) {
|
|
|
274
312
|
let n = name;
|
|
275
313
|
for (let i = 0; objEnv && i < 5; i++) {
|
|
276
314
|
const v = objEnv.get(n);
|
|
277
|
-
const t = v?.trim().match(/^(?:struct\s+)?(\w+)$/);
|
|
315
|
+
const t = v?.trim().match(/^(?:(?:struct|union)\s+)?(\w+)$/);
|
|
278
316
|
if (!t)
|
|
279
317
|
break;
|
|
280
318
|
n = t[1];
|
|
@@ -338,26 +376,105 @@ const C_TYPE_KEYWORDS = new Set([
|
|
|
338
376
|
const INCLUDE_RE = /#[ \t]*include[ \t]+"([^"\n]+)"/g;
|
|
339
377
|
/** Included files worth scanning for registration tables (e.g. a generated `.def`). */
|
|
340
378
|
const INCLUDABLE_EXT = /\.(def|inc|h|hh|hpp|hxx|c|cc|cpp|cxx|ipp|tcc|tbl)$/i;
|
|
341
|
-
|
|
379
|
+
/** `#define NAME single_identifier` (possibly `struct`-prefixed) — an
|
|
380
|
+
* object-macro that COULD alias a struct type name (`resolveTypeName`'s exact
|
|
381
|
+
* value shape). The extraction sweep collects every such NAME into a global
|
|
382
|
+
* set: an initializer type token that direct-misses the struct layouts still
|
|
383
|
+
* survives the registration filter when it is alias-SHAPED anywhere, so the
|
|
384
|
+
* per-file macro-env alias resolution (redis' `COMMAND_STRUCT`) keeps working
|
|
385
|
+
* without retaining per-file object-macro tables (6.1M `#define`s on the
|
|
386
|
+
* Linux tree — the amdgpu register headers — rule that out). Numeric values
|
|
387
|
+
* are excluded: `resolveTypeName` would rewrite to a dead-end token that can
|
|
388
|
+
* never name a struct, so skipping them is exact, and it drops the register
|
|
389
|
+
* flood. */
|
|
390
|
+
const OBJ_ALIAS_RE = /^[ \t]*#[ \t]*define[ \t]+(\w+)[ \t]+(?:(?:struct|union)[ \t]+)*[A-Za-z_]\w*[ \t\r]*$/gm;
|
|
391
|
+
/** `(?:struct )?TYPE name[opt] = {` initializers, where TYPE is a struct that
|
|
392
|
+
* has ≥1 fn-pointer field. Handles both single (`= {…}`) and array
|
|
393
|
+
* (`[] = { {…}, {…} }`) forms. Macro calls inside an element are expanded first. */
|
|
394
|
+
const INIT_RE = /(?:^|[;{}])\s*(?:(?:static|const|extern|register|volatile)\s+)*(?:(?:struct|union)\s+)?(\w+)\s+(\w+)\s*(\[[^\]]*\])?\s*=\s*\{/g;
|
|
395
|
+
/** `struct TAG { … } var[opt] [= {…}]` — the struct is defined INLINE with the
|
|
396
|
+
* table (vim's `cmdname`/`nv_cmd`); its layout never became a node, so parse it
|
|
397
|
+
* here and register it before reading the entries. No leading anchor: a
|
|
398
|
+
* `struct TAG {` with a brace body is always a definition (it may be preceded
|
|
399
|
+
* by a `#define …` line ending in a digit, as in vim), and the trailing
|
|
400
|
+
* `var … = {` check below is what distinguishes a TABLE from a plain type. */
|
|
401
|
+
const INLINE_STRUCT_RE = /\b(?:struct|union)\s+(\w+)\s*\{/g;
|
|
402
|
+
/** `(?:static …)* ELEMTYPE [*] name[…] = { … }` — a bare array of function
|
|
403
|
+
* pointers (no struct wrapper). The optional `*` covers a function-TYPE
|
|
404
|
+
* typedef element (`opcode_t *opcodes[]`); a function-pointer typedef element
|
|
405
|
+
* (`zend_rc_dtor_func_t t[]`) needs none. The typedef-set membership gate
|
|
406
|
+
* is what separates this from a plain data/struct array. */
|
|
407
|
+
const ARRAY_TABLE_RE = /(?:^|[;{}])\s*(?:(?:static|const|extern|register|volatile)\s+)*(\w+)\s+(\*\s*)?(\w+)\s*\[[^\]]*\]\s*=\s*\{/g;
|
|
408
|
+
/** Dispatch sites: `base->…->field(` or `base.…field(` where `field` is a known
|
|
409
|
+
* fn-pointer field. The base may be a chain (`c->cmd->proc`) or carry array
|
|
410
|
+
* subscripts (`cmdnames[i].cmd_func`). An optional `)` before the call covers
|
|
411
|
+
* the parenthesized form `(cmdnames[i].cmd_func)(&ea)` vim uses. */
|
|
412
|
+
const DISPATCH_RE = /((?:\w+(?:\s*\[[^\][]*\])?\s*(?:->|\.)\s*)+)(\w+)\s*\)?\s*\(/g;
|
|
413
|
+
/** Bare-array dispatch: `tbl[i](…)` or the explicit-deref `(*tbl[i])(…)`. The
|
|
414
|
+
* subscript may itself contain a call (`tbl[GC_TYPE(p)](…)`), so the index
|
|
415
|
+
* class excludes only brackets. Precision comes from the `arrayReg` gate —
|
|
416
|
+
* this fires only when `tbl` is a known fn-pointer array. */
|
|
417
|
+
const ARRAY_DISPATCH_RE = /(?:\(\s*\*\s*)?\b(\w+)\s*\[[^\][]*\]\s*\)?\s*\(/g;
|
|
418
|
+
/** Field←field propagation sites: `a->f = b->g`. */
|
|
419
|
+
const FIELD_ASSIGN_RE = /(\w+)\s*(?:->|\.)\s*(\w+)\s*=\s*(\w+)\s*(?:->|\.)\s*(\w+)/g;
|
|
420
|
+
const NO_INCLUDES = [];
|
|
421
|
+
async function cFnPointerDispatchEdges(_queries, ctx, onYield, onFraction) {
|
|
342
422
|
let scannedFiles = 0;
|
|
343
423
|
const files = ctx.getAllFiles().filter((f) => C_CPP_EXT.test(f));
|
|
344
424
|
if (files.length === 0)
|
|
345
425
|
return [];
|
|
426
|
+
// CODEGRAPH_SYNTH_TIMINGS sub-attribution: this pass is 86% of kernel-scale
|
|
427
|
+
// synthesis (306s, §7a.2/§7a.3) — per-stage walls + read/strip accounting
|
|
428
|
+
// name which stage and which cost class owns it. Post-refactor mapping:
|
|
429
|
+
// A = extraction sweep, B = struct-layout linking, C = registration,
|
|
430
|
+
// D = propagation, E = dispatch.
|
|
431
|
+
const prof = process.env.CODEGRAPH_SYNTH_TIMINGS
|
|
432
|
+
? { A: 0, B: 0, C: 0, D: 0, E: 0, readMs: 0, readN: 0, stripMs: 0, stripN: 0, nodesMs: 0, nodesN: 0 }
|
|
433
|
+
: null;
|
|
434
|
+
// Within-pass progress: this is the pass that parks the "Linking dynamic
|
|
435
|
+
// dispatch" bar on C-heavy repos, so it reports a real fraction of its
|
|
436
|
+
// dominant work. `files` is swept once per stage loop below (extraction,
|
|
437
|
+
// registration, propagation, dispatch), reported at the same per-16-files
|
|
438
|
+
// cadence as the cooperative yield.
|
|
439
|
+
const FILE_SWEEPS = 4;
|
|
440
|
+
const tick = async () => {
|
|
441
|
+
if ((++scannedFiles & 15) === 0) {
|
|
442
|
+
onFraction?.(scannedFiles / (files.length * FILE_SWEEPS));
|
|
443
|
+
await onYield();
|
|
444
|
+
}
|
|
445
|
+
};
|
|
346
446
|
// Cache raw + stripped source per file, LRU-BOUNDED. The old unbounded Maps
|
|
347
447
|
// retained every C/C++ file's raw AND stripped text for the whole pass —
|
|
348
448
|
// multiple GB on the Linux kernel, one of the two OOM culprits in #1212.
|
|
349
|
-
//
|
|
350
|
-
//
|
|
351
|
-
// hits; a miss just re-reads + re-strips.
|
|
352
|
-
|
|
449
|
+
// The extraction sweep reads sequentially; the linking stages re-request
|
|
450
|
+
// only surviving files (plus include units), so access is near-sequential
|
|
451
|
+
// and a small LRU hits; a miss just re-reads + re-strips.
|
|
452
|
+
// Cache sizing is memory-budget-aware AND all-or-nothing (§7a.3 cFnPtr
|
|
453
|
+
// round): a partial LRU is WORSE than useless for cyclic sweeps (a first
|
|
454
|
+
// attempt sized ~61k against 63.8k files thrashed to a ~0% cross-sweep hit
|
|
455
|
+
// rate). Hold every stripped file (~24KB each measured on the Linux tree)
|
|
456
|
+
// only when 40% of the live memory budget covers it; otherwise keep the
|
|
457
|
+
// within-stage-locality 128. When the big cache declines (the kernel), the
|
|
458
|
+
// survival filters keep the linking stages' re-strips to a fraction of a
|
|
459
|
+
// sweep. Slack over files.length: non-indexed includes (.def/.inc, generated
|
|
460
|
+
// headers) join the working set mid-pass. Pass-scoped transient, freed on
|
|
461
|
+
// return.
|
|
462
|
+
const fullCacheCap = Math.ceil(files.length * 1.05) + 512;
|
|
463
|
+
const cacheCap = (0, memory_budget_1.memoryBudgetBytes)() * 0.5 >= fullCacheCap * 24_576 ? fullCacheCap : 128;
|
|
464
|
+
const rawCache = new lru_cache_1.LRUCache(Math.min(cacheCap, 4096));
|
|
353
465
|
const raw = (file) => {
|
|
354
466
|
if (rawCache.has(file))
|
|
355
467
|
return rawCache.get(file);
|
|
468
|
+
const t0 = prof ? Date.now() : 0;
|
|
356
469
|
const r = ctx.readFile(file);
|
|
470
|
+
if (prof) {
|
|
471
|
+
prof.readMs += Date.now() - t0;
|
|
472
|
+
prof.readN++;
|
|
473
|
+
}
|
|
357
474
|
rawCache.set(file, r);
|
|
358
475
|
return r;
|
|
359
476
|
};
|
|
360
|
-
const srcCache = new lru_cache_1.LRUCache(
|
|
477
|
+
const srcCache = new lru_cache_1.LRUCache(cacheCap);
|
|
361
478
|
const src = (file) => {
|
|
362
479
|
// A cached '' (empty or unreadable file) returns '' where the miss path
|
|
363
480
|
// returns null for unreadable — every caller falsy-checks, so the two are
|
|
@@ -366,7 +483,12 @@ async function cFnPointerDispatchEdges(_queries, ctx, onYield) {
|
|
|
366
483
|
if (hit !== undefined)
|
|
367
484
|
return hit;
|
|
368
485
|
const r = raw(file);
|
|
486
|
+
const t0 = prof ? Date.now() : 0;
|
|
369
487
|
const s = r == null ? '' : (0, strip_comments_1.stripCommentsForRegex)(r, 'c');
|
|
488
|
+
if (prof) {
|
|
489
|
+
prof.stripMs += Date.now() - t0;
|
|
490
|
+
prof.stripN++;
|
|
491
|
+
}
|
|
370
492
|
srcCache.set(file, s);
|
|
371
493
|
return r == null ? null : s;
|
|
372
494
|
};
|
|
@@ -382,46 +504,40 @@ async function cFnPointerDispatchEdges(_queries, ctx, onYield) {
|
|
|
382
504
|
return inc;
|
|
383
505
|
return null;
|
|
384
506
|
};
|
|
385
|
-
//
|
|
507
|
+
// Retained strings are interned through here. Regex captures off a big file
|
|
508
|
+
// string are V8 sliced strings — retaining one pins the whole parent file
|
|
509
|
+
// text, and the facts tables retain captures from EVERY file for the whole
|
|
510
|
+
// pass. The Buffer round-trip forces a flat copy on first sight; repeats
|
|
511
|
+
// (field names recur heavily) then share the one flat instance.
|
|
512
|
+
const interned = new Map();
|
|
513
|
+
const intern = (x) => {
|
|
514
|
+
let f = interned.get(x);
|
|
515
|
+
if (f === undefined) {
|
|
516
|
+
f = Buffer.from(x, 'utf8').toString('utf8');
|
|
517
|
+
interned.set(f, f);
|
|
518
|
+
}
|
|
519
|
+
return f;
|
|
520
|
+
};
|
|
521
|
+
// ---- Global tables the extraction sweep fills ----
|
|
386
522
|
// fn-pointer: typedef RET (*NAME)(…) → a field `NAME f` is a fn ptr
|
|
387
523
|
// fn-type: typedef RET NAME(params) → a field `NAME *f` is a fn ptr
|
|
388
524
|
// The fn-type form is redis' command idiom: `typedef void redisCommandProc(client*)`
|
|
389
525
|
// declared as `redisCommandProc *proc;`. Without this, `proc` reads as data.
|
|
390
526
|
const fnPtrTypedefs = new Set();
|
|
391
527
|
const fnTypeTypedefs = new Set();
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
if (guts.includes('(*') || guts.includes('( *'))
|
|
406
|
-
continue; // pointer form — handled above
|
|
407
|
-
const fm = guts.match(/\b(\w+)\s*\(/); // last identifier before the param list
|
|
408
|
-
if (fm && !C_TYPE_KEYWORDS.has(fm[1]))
|
|
409
|
-
fnTypeTypedefs.add(fm[1]);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
// ---- Pass B: struct field layouts ----
|
|
413
|
-
// structLayout: struct name → ordered fields, for structs with ≥1 fn-pointer
|
|
414
|
-
// field (drives positional registration + dispatch).
|
|
415
|
-
// allStructFields: EVERY struct name → ALL its field layouts (a name can be
|
|
416
|
-
// reused across files — e.g. redis has two unrelated `client` structs), used
|
|
417
|
-
// to walk a chained receiver's field types (`c->cmd->proc`: client.cmd →
|
|
418
|
-
// redisCommand). The walk searches every same-named layout for the field.
|
|
419
|
-
// fieldToStructs: fn-pointer field name → set of struct names that declare it.
|
|
420
|
-
const structLayout = new Map();
|
|
421
|
-
const allStructFields = new Map();
|
|
422
|
-
const fieldToStructs = new Map();
|
|
423
|
-
// Parse a struct body (the text between its `{` and `}`) into ordered fields.
|
|
424
|
-
const parseStructFields = (inner) => {
|
|
528
|
+
/** Struct node id → its structurally-parsed fields (classified + registered
|
|
529
|
+
* in the linking stage, in kind-scan order). */
|
|
530
|
+
const rawFieldsByNode = new Map();
|
|
531
|
+
const factsByFile = new Map();
|
|
532
|
+
/** Every inline-struct candidate tag anywhere — an over-approximation of the
|
|
533
|
+
* tags the registration stage can add to `structLayout` mid-stage, folded
|
|
534
|
+
* into the registration filter's layout check. */
|
|
535
|
+
const inlineTags = new Set();
|
|
536
|
+
/** Object-macro names with an alias-shaped value anywhere (see OBJ_ALIAS_RE). */
|
|
537
|
+
const aliasNames = new Set();
|
|
538
|
+
// Parse a struct body (the text between its `{` and `}`) into ordered fields,
|
|
539
|
+
// structure only — see RawFieldDecl for why classification is deferred.
|
|
540
|
+
const parseStructFieldsRaw = (inner) => {
|
|
425
541
|
const fields = [];
|
|
426
542
|
let idx = 0;
|
|
427
543
|
for (const rawDecl of splitTopLevel(inner, ';')) {
|
|
@@ -438,11 +554,11 @@ async function cFnPointerDispatchEdges(_queries, ctx, onYield) {
|
|
|
438
554
|
const p = parts[pi].trim();
|
|
439
555
|
let name = null;
|
|
440
556
|
let type = '';
|
|
441
|
-
let
|
|
442
|
-
const
|
|
443
|
-
if (
|
|
444
|
-
name =
|
|
445
|
-
|
|
557
|
+
let ptr = false;
|
|
558
|
+
const pm = p.match(FNPTR_DECL_RE);
|
|
559
|
+
if (pm) {
|
|
560
|
+
name = pm[1]; // `… (*name)(…)` — a function pointer
|
|
561
|
+
ptr = true;
|
|
446
562
|
}
|
|
447
563
|
else if (pi === 0) {
|
|
448
564
|
if (firstTyped) {
|
|
@@ -458,17 +574,288 @@ async function cFnPointerDispatchEdges(_queries, ctx, onYield) {
|
|
|
458
574
|
type = sharedType;
|
|
459
575
|
}
|
|
460
576
|
}
|
|
461
|
-
if (!ptr && type)
|
|
462
|
-
isFnPtr = fnPtrTypedefs.has(type) || fnTypeTypedefs.has(type);
|
|
463
577
|
// Always advance the positional index. An unparsed field (anonymous
|
|
464
578
|
// union, exotic declarator) still occupies one slot, and macro-expanded
|
|
465
579
|
// positional tables (redis' MAKE_CMD) only align if every field counts.
|
|
466
|
-
fields.push({ name
|
|
580
|
+
fields.push({ name, index: idx, ptr, type });
|
|
467
581
|
idx++;
|
|
468
582
|
}
|
|
469
583
|
}
|
|
470
584
|
return fields;
|
|
471
585
|
};
|
|
586
|
+
// Classify deferred fields against the (now-complete) typedef sets.
|
|
587
|
+
const classifyFields = (rawFields) => rawFields.map((f) => ({
|
|
588
|
+
name: f.name ?? '',
|
|
589
|
+
index: f.index,
|
|
590
|
+
isFnPtr: !!f.name &&
|
|
591
|
+
(f.ptr || (!!f.type && (fnPtrTypedefs.has(f.type) || fnTypeTypedefs.has(f.type)))),
|
|
592
|
+
type: f.type,
|
|
593
|
+
}));
|
|
594
|
+
const parseStructFields = (inner) => classifyFields(parseStructFieldsRaw(inner));
|
|
595
|
+
// Exact per-file include resolution (from RAW source — string contents survive).
|
|
596
|
+
const scanIncludes = (file) => {
|
|
597
|
+
const rawText = raw(file);
|
|
598
|
+
if (!rawText || !rawText.includes('include'))
|
|
599
|
+
return NO_INCLUDES;
|
|
600
|
+
const out = [];
|
|
601
|
+
INCLUDE_RE.lastIndex = 0;
|
|
602
|
+
let im;
|
|
603
|
+
while ((im = INCLUDE_RE.exec(rawText))) {
|
|
604
|
+
if (!INCLUDABLE_EXT.test(im[1]))
|
|
605
|
+
continue;
|
|
606
|
+
const t = resolveInclude(file, im[1]);
|
|
607
|
+
if (t)
|
|
608
|
+
out.push(intern(t));
|
|
609
|
+
}
|
|
610
|
+
return out.length ? out : NO_INCLUDES;
|
|
611
|
+
};
|
|
612
|
+
// Indexed files answer from their facts; non-indexed includes (reached by
|
|
613
|
+
// buildEnv's depth-2 recursion) fall back to a bounded lazy scan.
|
|
614
|
+
const includeCache = new lru_cache_1.LRUCache(1024);
|
|
615
|
+
const localIncludesOf = (file) => {
|
|
616
|
+
const f = factsByFile.get(file);
|
|
617
|
+
if (f)
|
|
618
|
+
return f.includes;
|
|
619
|
+
let out = includeCache.get(file);
|
|
620
|
+
if (out)
|
|
621
|
+
return out;
|
|
622
|
+
out = scanIncludes(file);
|
|
623
|
+
includeCache.set(file, out);
|
|
624
|
+
return out;
|
|
625
|
+
};
|
|
626
|
+
// ---- Stage A: the extraction sweep — ONE read + strip per file ----
|
|
627
|
+
//
|
|
628
|
+
// Two implementations, record-identical by the differential suite:
|
|
629
|
+
// • native (task #5 step 2): the kernel's `cfnptrScanFiles` strips and
|
|
630
|
+
// scans a BATCH of files per NAPI call (codegraph-kernel/src/cfnptr.rs —
|
|
631
|
+
// hand-rolled byte machines replicating the JS regex semantics), and the
|
|
632
|
+
// TS side only reads files, ships batches, and interns the returned
|
|
633
|
+
// facts. Include-path resolution stays here (it needs the filesystem).
|
|
634
|
+
// • JS: the original sweep, kept verbatim — the fallback for platforms
|
|
635
|
+
// without a kernel binary, older binaries (feature detection), the
|
|
636
|
+
// CODEGRAPH_KERNEL=0 kill switch, and CODEGRAPH_KERNEL_CFNPTR=0 (this
|
|
637
|
+
// scanner's own switch).
|
|
638
|
+
const kernel = process.env.CODEGRAPH_KERNEL === '0' || process.env.CODEGRAPH_KERNEL_CFNPTR === '0'
|
|
639
|
+
? null
|
|
640
|
+
: (0, loader_1.getKernel)();
|
|
641
|
+
const nativeSweep = kernel && typeof kernel.cfnptrScanFiles === 'function' ? kernel.cfnptrScanFiles.bind(kernel) : null;
|
|
642
|
+
const mergeNativeFacts = (file, out) => {
|
|
643
|
+
for (const t of out.fnPtrTypedefs)
|
|
644
|
+
fnPtrTypedefs.add(intern(t));
|
|
645
|
+
for (const t of out.fnTypeTypedefs)
|
|
646
|
+
fnTypeTypedefs.add(intern(t));
|
|
647
|
+
for (const so of out.structs) {
|
|
648
|
+
if (!so.parsed)
|
|
649
|
+
continue; // body never parsed — the JS sweep records nothing either
|
|
650
|
+
rawFieldsByNode.set(so.id, so.fields.map((f) => ({ name: f.name || null, index: f.index, ptr: f.ptr, type: f.type })));
|
|
651
|
+
}
|
|
652
|
+
for (const t of out.inlineTags)
|
|
653
|
+
inlineTags.add(intern(t));
|
|
654
|
+
for (const t of out.aliasNames)
|
|
655
|
+
aliasNames.add(intern(t));
|
|
656
|
+
const includes = [];
|
|
657
|
+
for (const cap of out.includes) {
|
|
658
|
+
if (!INCLUDABLE_EXT.test(cap))
|
|
659
|
+
continue;
|
|
660
|
+
const t = resolveInclude(file, cap);
|
|
661
|
+
if (t)
|
|
662
|
+
includes.push(intern(t));
|
|
663
|
+
}
|
|
664
|
+
if (out.initTokens.length || out.arrayElems.length || out.inlinePtr || out.inlineTypes.length ||
|
|
665
|
+
out.dPairs.length || out.dispatchFields.length || out.arrayDispatchNames.length || includes.length) {
|
|
666
|
+
factsByFile.set(file, {
|
|
667
|
+
initTokens: out.initTokens.length ? out.initTokens.map(intern) : null,
|
|
668
|
+
arrayElems: out.arrayElems.length ? out.arrayElems.map(intern) : null,
|
|
669
|
+
inlinePtr: out.inlinePtr,
|
|
670
|
+
inlineTypes: out.inlineTypes.length ? out.inlineTypes.map(intern) : null,
|
|
671
|
+
dPairs: out.dPairs.length ? out.dPairs.map(intern) : null,
|
|
672
|
+
dispatchFields: out.dispatchFields.length ? out.dispatchFields.map(intern) : null,
|
|
673
|
+
arrayDispatchNames: out.arrayDispatchNames.length ? out.arrayDispatchNames.map(intern) : null,
|
|
674
|
+
includes: includes.length ? includes : NO_INCLUDES,
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
let tPass = Date.now();
|
|
679
|
+
if (nativeSweep) {
|
|
680
|
+
// Batch of 16 = the tick/onFraction cadence, so yielding and progress
|
|
681
|
+
// reporting keep their shape while the boundary crossing amortizes.
|
|
682
|
+
const BATCH = 16;
|
|
683
|
+
let batch = [];
|
|
684
|
+
const flush = () => {
|
|
685
|
+
if (batch.length === 0)
|
|
686
|
+
return;
|
|
687
|
+
const outs = nativeSweep(batch.map((b) => b.input));
|
|
688
|
+
for (let bi = 0; bi < batch.length; bi++)
|
|
689
|
+
mergeNativeFacts(batch[bi].file, outs[bi]);
|
|
690
|
+
batch = [];
|
|
691
|
+
};
|
|
692
|
+
for (const file of files) {
|
|
693
|
+
await tick();
|
|
694
|
+
const rawText = raw(file);
|
|
695
|
+
if (!rawText)
|
|
696
|
+
continue; // unreadable or empty — the JS sweep skips these too
|
|
697
|
+
const tN = prof ? Date.now() : 0;
|
|
698
|
+
const fileNodes = ctx.getNodesInFile(file);
|
|
699
|
+
if (prof) {
|
|
700
|
+
prof.nodesMs += Date.now() - tN;
|
|
701
|
+
prof.nodesN++;
|
|
702
|
+
}
|
|
703
|
+
const structs = [];
|
|
704
|
+
for (const st of fileNodes) {
|
|
705
|
+
if (st.kind !== 'struct' && st.kind !== 'union')
|
|
706
|
+
continue;
|
|
707
|
+
// sliceLinesPre semantics ride along: falsy startLine never parses,
|
|
708
|
+
// and `endLine ?? startLine` is applied here so the kernel sees the
|
|
709
|
+
// exact slice bounds the JS sweep would use.
|
|
710
|
+
structs.push({ id: st.id, startLine: st.startLine ?? 0, endLine: st.endLine ?? st.startLine ?? 0 });
|
|
711
|
+
}
|
|
712
|
+
batch.push({ file, input: { text: rawText, structs } });
|
|
713
|
+
if (batch.length >= BATCH)
|
|
714
|
+
flush();
|
|
715
|
+
}
|
|
716
|
+
flush();
|
|
717
|
+
}
|
|
718
|
+
// JS sweep (fallback path — see the stage comment above).
|
|
719
|
+
if (!nativeSweep)
|
|
720
|
+
for (const file of files) {
|
|
721
|
+
await tick();
|
|
722
|
+
const s = src(file);
|
|
723
|
+
if (!s)
|
|
724
|
+
continue;
|
|
725
|
+
// Typedefs (cross-file).
|
|
726
|
+
if (s.includes('typedef')) {
|
|
727
|
+
FNPTR_TYPEDEF_RE.lastIndex = 0;
|
|
728
|
+
let m;
|
|
729
|
+
while ((m = FNPTR_TYPEDEF_RE.exec(s)))
|
|
730
|
+
fnPtrTypedefs.add(intern(m[1]));
|
|
731
|
+
FNTYPE_TYPEDEF_STMT_RE.lastIndex = 0;
|
|
732
|
+
while ((m = FNTYPE_TYPEDEF_STMT_RE.exec(s))) {
|
|
733
|
+
const guts = m[1];
|
|
734
|
+
if (guts.includes('(*') || guts.includes('( *'))
|
|
735
|
+
continue; // pointer form — handled above
|
|
736
|
+
const fm = guts.match(/\b(\w+)\s*\(/); // last identifier before the param list
|
|
737
|
+
if (fm && !C_TYPE_KEYWORDS.has(fm[1]))
|
|
738
|
+
fnTypeTypedefs.add(intern(fm[1]));
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
// Struct-node field declarations (registered later in kind-scan order).
|
|
742
|
+
const tN = prof ? Date.now() : 0;
|
|
743
|
+
const fileNodes = ctx.getNodesInFile(file);
|
|
744
|
+
if (prof) {
|
|
745
|
+
prof.nodesMs += Date.now() - tN;
|
|
746
|
+
prof.nodesN++;
|
|
747
|
+
}
|
|
748
|
+
let lines = null;
|
|
749
|
+
for (const st of fileNodes) {
|
|
750
|
+
if (st.kind !== 'struct' && st.kind !== 'union')
|
|
751
|
+
continue;
|
|
752
|
+
lines ??= s.split('\n');
|
|
753
|
+
const body = sliceLinesPre(lines, st.startLine, st.endLine);
|
|
754
|
+
const open = body.indexOf('{');
|
|
755
|
+
const close = open >= 0 ? matchBrace(body, open) : -1;
|
|
756
|
+
if (open < 0 || close < 0)
|
|
757
|
+
continue;
|
|
758
|
+
rawFieldsByNode.set(st.id, parseStructFieldsRaw(body.slice(open + 1, close)));
|
|
759
|
+
}
|
|
760
|
+
// Registration filters. These are full-file, NO-SKIP scans: the original
|
|
761
|
+
// registration pass jumps its scan cursor past a processed initializer
|
|
762
|
+
// body, so a no-skip scan finds a SUPERSET of its matches — exactly the
|
|
763
|
+
// over-approximation the filter needs.
|
|
764
|
+
const initTokens = new Set();
|
|
765
|
+
const arrayElems = new Set();
|
|
766
|
+
const inlineTypes = new Set();
|
|
767
|
+
let inlinePtr = false;
|
|
768
|
+
if (s.includes('{')) {
|
|
769
|
+
INLINE_STRUCT_RE.lastIndex = 0;
|
|
770
|
+
let im;
|
|
771
|
+
while ((im = INLINE_STRUCT_RE.exec(s))) {
|
|
772
|
+
const sOpen = im.index + im[0].length - 1;
|
|
773
|
+
const sClose = matchBrace(s, sOpen);
|
|
774
|
+
if (sClose < 0)
|
|
775
|
+
continue;
|
|
776
|
+
// After `}`, expect `var [opt] [= {…}]` to be a table candidate.
|
|
777
|
+
const vm = s.slice(sClose + 1).match(/^\s*(\w+)\s*(\[[^\]]*\])?\s*(=\s*\{)?/);
|
|
778
|
+
if (!vm || !vm[1])
|
|
779
|
+
continue;
|
|
780
|
+
inlineTags.add(intern(im[1]));
|
|
781
|
+
for (const f of parseStructFieldsRaw(s.slice(sOpen + 1, sClose))) {
|
|
782
|
+
if (!f.name)
|
|
783
|
+
continue;
|
|
784
|
+
if (f.ptr)
|
|
785
|
+
inlinePtr = true;
|
|
786
|
+
else if (f.type)
|
|
787
|
+
inlineTypes.add(intern(f.type));
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
if (s.includes('=')) {
|
|
791
|
+
INIT_RE.lastIndex = 0;
|
|
792
|
+
let m;
|
|
793
|
+
while ((m = INIT_RE.exec(s)))
|
|
794
|
+
initTokens.add(intern(m[1]));
|
|
795
|
+
ARRAY_TABLE_RE.lastIndex = 0;
|
|
796
|
+
while ((m = ARRAY_TABLE_RE.exec(s)))
|
|
797
|
+
arrayElems.add(intern((m[2] ? '*' : '') + m[1]));
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
// Alias-shaped object macros (registration filter support).
|
|
801
|
+
if (s.includes('#define') || s.includes('# define')) {
|
|
802
|
+
const joined = s.replace(/\\\r?\n/g, ' ');
|
|
803
|
+
OBJ_ALIAS_RE.lastIndex = 0;
|
|
804
|
+
let m;
|
|
805
|
+
while ((m = OBJ_ALIAS_RE.exec(joined)))
|
|
806
|
+
aliasNames.add(intern(m[1]));
|
|
807
|
+
}
|
|
808
|
+
// Propagation + dispatch filters (full-file scans ⊇ the per-function-body
|
|
809
|
+
// scans the pass bodies run — a body slice is a substring of the file).
|
|
810
|
+
const dPairs = new Set();
|
|
811
|
+
if (s.includes('=')) {
|
|
812
|
+
FIELD_ASSIGN_RE.lastIndex = 0;
|
|
813
|
+
let m;
|
|
814
|
+
while ((m = FIELD_ASSIGN_RE.exec(s)))
|
|
815
|
+
dPairs.add(intern(m[2] + '\0' + m[4]));
|
|
816
|
+
}
|
|
817
|
+
const dispatchFields = new Set();
|
|
818
|
+
const arrayNames = new Set();
|
|
819
|
+
DISPATCH_RE.lastIndex = 0;
|
|
820
|
+
let dm;
|
|
821
|
+
while ((dm = DISPATCH_RE.exec(s)))
|
|
822
|
+
dispatchFields.add(intern(dm[2]));
|
|
823
|
+
ARRAY_DISPATCH_RE.lastIndex = 0;
|
|
824
|
+
while ((dm = ARRAY_DISPATCH_RE.exec(s)))
|
|
825
|
+
arrayNames.add(intern(dm[1]));
|
|
826
|
+
const includes = scanIncludes(file);
|
|
827
|
+
if (initTokens.size || arrayElems.size || inlinePtr || inlineTypes.size ||
|
|
828
|
+
dPairs.size || dispatchFields.size || arrayNames.size || includes.length) {
|
|
829
|
+
factsByFile.set(file, {
|
|
830
|
+
initTokens: initTokens.size ? [...initTokens] : null,
|
|
831
|
+
arrayElems: arrayElems.size ? [...arrayElems] : null,
|
|
832
|
+
inlinePtr,
|
|
833
|
+
inlineTypes: inlineTypes.size ? [...inlineTypes] : null,
|
|
834
|
+
dPairs: dPairs.size ? [...dPairs] : null,
|
|
835
|
+
dispatchFields: dispatchFields.size ? [...dispatchFields] : null,
|
|
836
|
+
arrayDispatchNames: arrayNames.size ? [...arrayNames] : null,
|
|
837
|
+
includes,
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
if (prof) {
|
|
842
|
+
prof.A = Date.now() - tPass;
|
|
843
|
+
tPass = Date.now();
|
|
844
|
+
}
|
|
845
|
+
// ---- Stage B: struct field layouts (linking — text-free) ----
|
|
846
|
+
// structLayout: struct name → ordered fields, for structs with ≥1 fn-pointer
|
|
847
|
+
// field (drives positional registration + dispatch).
|
|
848
|
+
// allStructFields: EVERY struct name → ALL its field layouts (a name can be
|
|
849
|
+
// reused across files — e.g. redis has two unrelated `client` structs), used
|
|
850
|
+
// to walk a chained receiver's field types (`c->cmd->proc`: client.cmd →
|
|
851
|
+
// redisCommand). The walk searches every same-named layout for the field.
|
|
852
|
+
// fieldToStructs: fn-pointer field name → set of struct names that declare it.
|
|
853
|
+
// Registration REPLAYS the struct kind-scan (rowid order, ≠ the extraction
|
|
854
|
+
// sweep's path order): same-name layout precedence — `structLayout.set`
|
|
855
|
+
// last-wins, `allStructFields` first-match in the chain walk — depends on it.
|
|
856
|
+
const structLayout = new Map();
|
|
857
|
+
const allStructFields = new Map();
|
|
858
|
+
const fieldToStructs = new Map();
|
|
472
859
|
// Register a parsed struct under `name` into the three indexes.
|
|
473
860
|
const registerStructLayout = (name, fields) => {
|
|
474
861
|
if (!allStructFields.has(name))
|
|
@@ -484,27 +871,29 @@ async function cFnPointerDispatchEdges(_queries, ctx, onYield) {
|
|
|
484
871
|
if (fields.some((f) => f.isFnPtr))
|
|
485
872
|
structLayout.set(name, fields);
|
|
486
873
|
};
|
|
487
|
-
for (const
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
874
|
+
for (const kind of ['struct', 'union']) {
|
|
875
|
+
for (const st of (ctx.iterateNodesByKind?.(kind) ?? ctx.getNodesByKind(kind))) {
|
|
876
|
+
if ((++scannedFiles & 255) === 0)
|
|
877
|
+
await onYield();
|
|
878
|
+
if (!C_CPP_EXT.test(st.filePath))
|
|
879
|
+
continue;
|
|
880
|
+
const rawFields = rawFieldsByNode.get(st.id);
|
|
881
|
+
if (!rawFields)
|
|
882
|
+
continue; // file unreadable or body unparsable at sweep time — the old pass skipped it too
|
|
883
|
+
registerStructLayout(st.name, classifyFields(rawFields));
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
rawFieldsByNode.clear();
|
|
887
|
+
if (prof) {
|
|
888
|
+
prof.B = Date.now() - tPass;
|
|
889
|
+
tPass = Date.now();
|
|
501
890
|
}
|
|
502
891
|
// NB: no early return on an empty structLayout here — an inline `struct TAG
|
|
503
892
|
// { … } var[]` table whose struct never became a node (vim's `cmdname`, broken
|
|
504
893
|
// up by `#ifdef`) is discovered later during the unit scan. The `reg.size === 0`
|
|
505
894
|
// guard after registration still short-circuits when nothing bridges.
|
|
506
895
|
const fnPtrFieldOf = (struct, field) => !!structLayout.get(struct)?.some((f) => f.name === field && f.isFnPtr);
|
|
507
|
-
// C/C++ function + method nodes are STREAMED per
|
|
896
|
+
// C/C++ function + method nodes are STREAMED per stage (see D/E) —
|
|
508
897
|
// the old materialized `cFns` array held every function node on the repo
|
|
509
898
|
// (O(nodes) memory, part of the #1212 kernel OOM).
|
|
510
899
|
// ---- function-name → node resolution (prefer a function in the same file) ----
|
|
@@ -521,7 +910,7 @@ async function cFnPointerDispatchEdges(_queries, ctx, onYield) {
|
|
|
521
910
|
}
|
|
522
911
|
return cands[0];
|
|
523
912
|
};
|
|
524
|
-
// ----
|
|
913
|
+
// ---- Stage C: registrations — Map<"struct.field", Set<funcNodeId>> ----
|
|
525
914
|
// Ids only — retaining the full Node per registration (the old `idToNode`)
|
|
526
915
|
// was write-only dead weight at O(registrations) memory.
|
|
527
916
|
const reg = new Map();
|
|
@@ -623,6 +1012,10 @@ async function cFnPointerDispatchEdges(_queries, ctx, onYield) {
|
|
|
623
1012
|
};
|
|
624
1013
|
// Per-file macro + include parsing (any file, indexed or not), cached.
|
|
625
1014
|
// Derived per-file caches, LRU-bounded like the content caches (#1212).
|
|
1015
|
+
// These stay LAZY (recompute-on-miss through `src`): retaining every file's
|
|
1016
|
+
// parsed tables is ruled out by the kernel's 6.1M `#define`s, and the
|
|
1017
|
+
// registration stage below only builds an env for files that survive its
|
|
1018
|
+
// filter or carry local includes, so most files never need one.
|
|
626
1019
|
const fnMacroCache = new lru_cache_1.LRUCache(256);
|
|
627
1020
|
const fileFnMacros = (file) => {
|
|
628
1021
|
let m = fnMacroCache.get(file);
|
|
@@ -650,27 +1043,6 @@ async function cFnPointerDispatchEdges(_queries, ctx, onYield) {
|
|
|
650
1043
|
}
|
|
651
1044
|
return d;
|
|
652
1045
|
};
|
|
653
|
-
const includeCache = new lru_cache_1.LRUCache(1024);
|
|
654
|
-
const localIncludesOf = (file) => {
|
|
655
|
-
let out = includeCache.get(file);
|
|
656
|
-
if (out)
|
|
657
|
-
return out;
|
|
658
|
-
out = [];
|
|
659
|
-
const rawText = raw(file);
|
|
660
|
-
if (rawText && rawText.includes('include')) {
|
|
661
|
-
INCLUDE_RE.lastIndex = 0;
|
|
662
|
-
let im;
|
|
663
|
-
while ((im = INCLUDE_RE.exec(rawText))) {
|
|
664
|
-
if (!INCLUDABLE_EXT.test(im[1]))
|
|
665
|
-
continue;
|
|
666
|
-
const t = resolveInclude(file, im[1]);
|
|
667
|
-
if (t)
|
|
668
|
-
out.push(t);
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
includeCache.set(file, out);
|
|
672
|
-
return out;
|
|
673
|
-
};
|
|
674
1046
|
// A file's effective macro environment = its own #defines PLUS those of the
|
|
675
1047
|
// headers it #includes (redis' `MAKE_CMD` sits beside the table; sqlite's
|
|
676
1048
|
// `FUNCTION` lives in `sqliteInt.h`, included by the file with the table).
|
|
@@ -716,23 +1088,6 @@ async function cFnPointerDispatchEdges(_queries, ctx, onYield) {
|
|
|
716
1088
|
registerStructValue(struct, body, file, env);
|
|
717
1089
|
}
|
|
718
1090
|
};
|
|
719
|
-
// `(?:struct )?TYPE name[opt] = {` initializers, where TYPE is a struct that
|
|
720
|
-
// has ≥1 fn-pointer field. Handles both single (`= {…}`) and array
|
|
721
|
-
// (`[] = { {…}, {…} }`) forms. Macro calls inside an element are expanded first.
|
|
722
|
-
const INIT_RE = /(?:^|[;{}])\s*(?:(?:static|const|extern|register|volatile)\s+)*(?:struct\s+)?(\w+)\s+(\w+)\s*(\[[^\]]*\])?\s*=\s*\{/g;
|
|
723
|
-
// `struct TAG { … } var[opt] [= {…}]` — the struct is defined INLINE with the
|
|
724
|
-
// table (vim's `cmdname`/`nv_cmd`); its layout never became a node, so parse it
|
|
725
|
-
// here and register it before reading the entries. No leading anchor: a
|
|
726
|
-
// `struct TAG {` with a brace body is always a definition (it may be preceded
|
|
727
|
-
// by a `#define …` line ending in a digit, as in vim), and the trailing
|
|
728
|
-
// `var … = {` check below is what distinguishes a TABLE from a plain type.
|
|
729
|
-
const INLINE_STRUCT_RE = /\bstruct\s+(\w+)\s*\{/g;
|
|
730
|
-
// `(?:static …)* ELEMTYPE [*] name[…] = { … }` — a bare array of function
|
|
731
|
-
// pointers (no struct wrapper). The optional `*` covers a function-TYPE
|
|
732
|
-
// typedef element (`opcode_t *opcodes[]`); a function-pointer typedef element
|
|
733
|
-
// (`zend_rc_dtor_func_t t[]`) needs none. The typedef-set membership gate
|
|
734
|
-
// (below) is what separates this from a plain data/struct array.
|
|
735
|
-
const ARRAY_TABLE_RE = /(?:^|[;{}])\s*(?:(?:static|const|extern|register|volatile)\s+)*(\w+)\s+(\*\s*)?(\w+)\s*\[[^\]]*\]\s*=\s*\{/g;
|
|
736
1091
|
// Process ONE unit's text and discard it. The old shape built every unit up
|
|
737
1092
|
// front (`const units: Unit[]`) — the full text of every C file plus its
|
|
738
1093
|
// expanded includes held simultaneously, gigabytes on the kernel (#1212).
|
|
@@ -806,19 +1161,42 @@ async function cFnPointerDispatchEdges(_queries, ctx, onYield) {
|
|
|
806
1161
|
ARRAY_TABLE_RE.lastIndex = close;
|
|
807
1162
|
}
|
|
808
1163
|
};
|
|
809
|
-
//
|
|
810
|
-
//
|
|
1164
|
+
// Can this file's OWN unit have any side effect? Every check mirrors a gate
|
|
1165
|
+
// in processUnit, over-approximated to the filter's coarser knowledge:
|
|
1166
|
+
// • inline structs — the fn-ptr-field gate, with per-candidate field types
|
|
1167
|
+
// unioned per file;
|
|
1168
|
+
// • initializers — `structLayout.has` against the layouts' SUPERSET
|
|
1169
|
+
// (kind-scan layouts ∪ every inline tag — structLayout only grows during
|
|
1170
|
+
// this stage), with alias-shaped tokens surviving in place of the
|
|
1171
|
+
// per-file `resolveTypeName` walk;
|
|
1172
|
+
// • bare arrays — the exact typedef-set gate.
|
|
1173
|
+
// A filtered-out file is one where every match fails its gate before any
|
|
1174
|
+
// side effect, so skipping the unit cannot change the outcome.
|
|
1175
|
+
const typedefHit = (t) => fnPtrTypedefs.has(t) || fnTypeTypedefs.has(t);
|
|
1176
|
+
const regSurvives = (f) => f.inlinePtr ||
|
|
1177
|
+
(f.inlineTypes?.some(typedefHit) ?? false) ||
|
|
1178
|
+
(f.initTokens?.some((t) => structLayout.has(t) || inlineTags.has(t) || aliasNames.has(t)) ?? false) ||
|
|
1179
|
+
(f.arrayElems?.some((e) => e.charCodeAt(0) === 42 /* '*' */ ? typedefHit(e.slice(1)) : fnPtrTypedefs.has(e)) ?? false);
|
|
1180
|
+
// ---- Stage C: registrations — stream each surviving file (and every file's
|
|
1181
|
+
// qualifying local includes) through processUnit, one at a time.
|
|
811
1182
|
for (const file of files) {
|
|
812
|
-
|
|
813
|
-
|
|
1183
|
+
await tick();
|
|
1184
|
+
const facts = factsByFile.get(file);
|
|
1185
|
+
if (!facts)
|
|
1186
|
+
continue; // no facts ⇒ nothing matched at sweep time ⇒ the old pass would no-op here
|
|
1187
|
+
const survives = regSurvives(facts);
|
|
1188
|
+
if (!survives && facts.includes.length === 0)
|
|
1189
|
+
continue;
|
|
814
1190
|
const env = new Map();
|
|
815
1191
|
const objEnv = new Map();
|
|
816
1192
|
const defined = new Set();
|
|
817
1193
|
buildEnv(file, 2, new Set(), env, objEnv, defined);
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
1194
|
+
if (survives) {
|
|
1195
|
+
const s = src(file);
|
|
1196
|
+
if (s)
|
|
1197
|
+
processUnit({ text: s, file, env, objEnv });
|
|
1198
|
+
}
|
|
1199
|
+
for (const target of facts.includes) {
|
|
822
1200
|
if (seenInclude.has(`${file}>${target}`))
|
|
823
1201
|
continue;
|
|
824
1202
|
const incSrc = src(target);
|
|
@@ -847,11 +1225,21 @@ async function cFnPointerDispatchEdges(_queries, ctx, onYield) {
|
|
|
847
1225
|
processUnit({ text, file: target, env: incEnv, objEnv: incObjEnv });
|
|
848
1226
|
}
|
|
849
1227
|
}
|
|
1228
|
+
if (prof) {
|
|
1229
|
+
prof.C = Date.now() - tPass;
|
|
1230
|
+
tPass = Date.now();
|
|
1231
|
+
}
|
|
850
1232
|
// ---- receiver-type resolution within a function's source ----
|
|
851
1233
|
// `(?:struct )?TYPE [*]recv` declared in the params or body → TYPE (if a known
|
|
852
1234
|
// fn-pointer-bearing struct).
|
|
1235
|
+
const recvReCache = new lru_cache_1.LRUCache(4096);
|
|
853
1236
|
const recvTypeIn = (fnSrc, recv) => {
|
|
854
|
-
|
|
1237
|
+
let re = recvReCache.get(recv);
|
|
1238
|
+
if (!re) {
|
|
1239
|
+
re = new RegExp(`(?:(?:struct|union)\\s+)?(\\w+)\\s*\\*?\\s*\\b${recv}\\b\\s*(?:[,)=;]|\\[)`, 'g');
|
|
1240
|
+
recvReCache.set(recv, re);
|
|
1241
|
+
}
|
|
1242
|
+
re.lastIndex = 0;
|
|
855
1243
|
let m;
|
|
856
1244
|
while ((m = re.exec(fnSrc))) {
|
|
857
1245
|
if (structLayout.has(m[1]))
|
|
@@ -863,8 +1251,14 @@ async function cFnPointerDispatchEdges(_queries, ctx, onYield) {
|
|
|
863
1251
|
// structs (the base of a chained receiver needn't carry a fn pointer itself).
|
|
864
1252
|
// Falls back to a file-scope table variable (`cmdnames` in `cmdnames[i].fn()`).
|
|
865
1253
|
const escapeRe = (x) => x.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1254
|
+
const varReCache = new lru_cache_1.LRUCache(4096);
|
|
866
1255
|
const varTypeIn = (fnSrc, v) => {
|
|
867
|
-
|
|
1256
|
+
let re = varReCache.get(v);
|
|
1257
|
+
if (!re) {
|
|
1258
|
+
re = new RegExp(`(?:(?:struct|union)\\s+)?(\\w+)\\s*\\*?\\s*\\b${escapeRe(v)}\\b\\s*(?:[,)=;]|\\[)`, 'g');
|
|
1259
|
+
varReCache.set(v, re);
|
|
1260
|
+
}
|
|
1261
|
+
re.lastIndex = 0;
|
|
868
1262
|
let m;
|
|
869
1263
|
while ((m = re.exec(fnSrc))) {
|
|
870
1264
|
if (!C_TYPE_KEYWORDS.has(m[1]))
|
|
@@ -894,27 +1288,47 @@ async function cFnPointerDispatchEdges(_queries, ctx, onYield) {
|
|
|
894
1288
|
}
|
|
895
1289
|
return t;
|
|
896
1290
|
};
|
|
897
|
-
// ----
|
|
1291
|
+
// ---- Stage D: field←field propagation (`a->f = b->g`) ----
|
|
898
1292
|
// Collected as (targetStruct.field ← sourceStruct.field) pairs, then merged to
|
|
899
1293
|
// a fixpoint so a hook slot inherits a registry field's handlers.
|
|
900
|
-
|
|
1294
|
+
// Filter: a file matters only if SOME collected pair has BOTH fields known as
|
|
1295
|
+
// fn-pointer fields — the loop body's own pre-gate. A skipped file's matches
|
|
1296
|
+
// would all `continue` there, so skipping is side-effect-free.
|
|
901
1297
|
const propagations = [];
|
|
902
1298
|
for (const file of files) {
|
|
903
|
-
|
|
904
|
-
|
|
1299
|
+
await tick();
|
|
1300
|
+
const facts = factsByFile.get(file);
|
|
1301
|
+
if (!facts?.dPairs?.some((p) => {
|
|
1302
|
+
const i = p.indexOf('\0');
|
|
1303
|
+
return fieldToStructs.has(p.slice(0, i)) && fieldToStructs.has(p.slice(i + 1));
|
|
1304
|
+
}))
|
|
1305
|
+
continue;
|
|
905
1306
|
const s = src(file);
|
|
906
1307
|
if (!s || !s.includes('='))
|
|
907
1308
|
continue;
|
|
908
|
-
|
|
1309
|
+
const tN = prof ? Date.now() : 0;
|
|
1310
|
+
const fnsD = ctx.getNodesInFile(file);
|
|
1311
|
+
if (prof) {
|
|
1312
|
+
prof.nodesMs += Date.now() - tN;
|
|
1313
|
+
prof.nodesN++;
|
|
1314
|
+
}
|
|
1315
|
+
const dLines = s.split('\n');
|
|
1316
|
+
for (const fn of fnsD) {
|
|
909
1317
|
if (!FN_KINDS.has(fn.kind))
|
|
910
1318
|
continue;
|
|
911
|
-
const body =
|
|
1319
|
+
const body = sliceLinesPre(dLines, fn.startLine, fn.endLine);
|
|
912
1320
|
if (!body.includes('='))
|
|
913
1321
|
continue;
|
|
914
1322
|
FIELD_ASSIGN_RE.lastIndex = 0;
|
|
915
1323
|
let m;
|
|
916
1324
|
while ((m = FIELD_ASSIGN_RE.exec(body))) {
|
|
917
1325
|
const [, lrecv, lfield, rrecv, rfield] = m;
|
|
1326
|
+
// Pre-gate on field NAMES: `a->f = b->g` matches every struct-field
|
|
1327
|
+
// assignment in the tree (millions on the kernel), but only fields
|
|
1328
|
+
// that are fn-pointer fields of SOME struct can pass fnPtrFieldOf —
|
|
1329
|
+
// skip the two regex type resolutions for the ~99% that can't.
|
|
1330
|
+
if (!fieldToStructs.has(lfield) || !fieldToStructs.has(rfield))
|
|
1331
|
+
continue;
|
|
918
1332
|
const lt = recvTypeIn(body, lrecv);
|
|
919
1333
|
const rt = recvTypeIn(body, rrecv);
|
|
920
1334
|
if (lt && rt && fnPtrFieldOf(lt, lfield) && fnPtrFieldOf(rt, rfield)) {
|
|
@@ -942,34 +1356,57 @@ async function cFnPointerDispatchEdges(_queries, ctx, onYield) {
|
|
|
942
1356
|
if (!changed)
|
|
943
1357
|
break;
|
|
944
1358
|
}
|
|
1359
|
+
if (prof) {
|
|
1360
|
+
prof.D = Date.now() - tPass;
|
|
1361
|
+
tPass = Date.now();
|
|
1362
|
+
}
|
|
945
1363
|
if (reg.size === 0 && arrayReg.size === 0)
|
|
946
1364
|
return [];
|
|
947
|
-
// ----
|
|
948
|
-
//
|
|
949
|
-
//
|
|
950
|
-
// (`
|
|
951
|
-
//
|
|
952
|
-
const DISPATCH_RE = /((?:\w+(?:\s*\[[^\][]*\])?\s*(?:->|\.)\s*)+)(\w+)\s*\)?\s*\(/g;
|
|
953
|
-
// Bare-array dispatch: `tbl[i](…)` or the explicit-deref `(*tbl[i])(…)`. The
|
|
954
|
-
// subscript may itself contain a call (`tbl[GC_TYPE(p)](…)`), so the index
|
|
955
|
-
// class excludes only brackets. Precision comes from the `arrayReg` gate below
|
|
956
|
-
// — this fires only when `tbl` is a known fn-pointer array.
|
|
957
|
-
const ARRAY_DISPATCH_RE = /(?:\(\s*\*\s*)?\b(\w+)\s*\[[^\][]*\]\s*\)?\s*\(/g;
|
|
1365
|
+
// ---- Stage E: dispatch sites → edges ----
|
|
1366
|
+
// Filter: a file matters only if some dispatch field is a known fn-pointer
|
|
1367
|
+
// field, or some subscripted name is a registered fn-pointer array — the loop
|
|
1368
|
+
// body's own first gates (`owners` / `entries`), which a skipped file's
|
|
1369
|
+
// matches would all fail before touching `seen`/`added`/`edges`.
|
|
958
1370
|
const edges = [];
|
|
959
1371
|
const seen = new Set();
|
|
960
1372
|
for (const file of files) {
|
|
961
|
-
|
|
962
|
-
|
|
1373
|
+
await tick();
|
|
1374
|
+
const facts = factsByFile.get(file);
|
|
1375
|
+
if (!facts)
|
|
1376
|
+
continue;
|
|
1377
|
+
const eSurvives = (facts.dispatchFields?.some((f) => fieldToStructs.has(f)) ?? false) ||
|
|
1378
|
+
(arrayReg.size > 0 && (facts.arrayDispatchNames?.some((n) => arrayReg.has(n)) ?? false));
|
|
1379
|
+
if (!eSurvives)
|
|
1380
|
+
continue;
|
|
963
1381
|
const s = src(file);
|
|
964
1382
|
if (!s)
|
|
965
1383
|
continue;
|
|
966
|
-
|
|
1384
|
+
const tN = prof ? Date.now() : 0;
|
|
1385
|
+
const fnsE = ctx.getNodesInFile(file);
|
|
1386
|
+
if (prof) {
|
|
1387
|
+
prof.nodesMs += Date.now() - tN;
|
|
1388
|
+
prof.nodesN++;
|
|
1389
|
+
}
|
|
1390
|
+
const eLines = s.split('\n');
|
|
1391
|
+
for (const fn of fnsE) {
|
|
967
1392
|
if (!FN_KINDS.has(fn.kind))
|
|
968
1393
|
continue;
|
|
969
|
-
const body =
|
|
1394
|
+
const body = sliceLinesPre(eLines, fn.startLine, fn.endLine);
|
|
970
1395
|
DISPATCH_RE.lastIndex = 0;
|
|
971
1396
|
let m;
|
|
972
1397
|
let added = 0;
|
|
1398
|
+
// Incremental line counting: matches arrive in ascending index order, so
|
|
1399
|
+
// count newlines since the previous match instead of re-splitting the
|
|
1400
|
+
// whole body prefix per match (O(body) each — real time on god-files).
|
|
1401
|
+
let lcIdx = 0;
|
|
1402
|
+
let lcLine = fn.startLine;
|
|
1403
|
+
const lineAt = (idx) => {
|
|
1404
|
+
for (let i = lcIdx; i < idx; i++)
|
|
1405
|
+
if (body.charCodeAt(i) === 10)
|
|
1406
|
+
lcLine++;
|
|
1407
|
+
lcIdx = idx;
|
|
1408
|
+
return lcLine;
|
|
1409
|
+
};
|
|
973
1410
|
while ((m = DISPATCH_RE.exec(body)) && added < FANOUT_CAP) {
|
|
974
1411
|
const baseChain = m[1].replace(/\s*(?:->|\.)\s*$/, '').trim(); // receiver, minus the trailing arrow
|
|
975
1412
|
const field = m[2];
|
|
@@ -992,7 +1429,7 @@ async function cFnPointerDispatchEdges(_queries, ctx, onYield) {
|
|
|
992
1429
|
const targets = reg.get(`${struct}.${field}`);
|
|
993
1430
|
if (!targets)
|
|
994
1431
|
continue;
|
|
995
|
-
const line =
|
|
1432
|
+
const line = lineAt(m.index);
|
|
996
1433
|
for (const tid of targets) {
|
|
997
1434
|
if (tid === fn.id)
|
|
998
1435
|
continue;
|
|
@@ -1018,6 +1455,9 @@ async function cFnPointerDispatchEdges(_queries, ctx, onYield) {
|
|
|
1018
1455
|
}
|
|
1019
1456
|
// ---- bare array-of-fn-pointers dispatch (`tbl[i](…)`) ----
|
|
1020
1457
|
if (arrayReg.size && added < FANOUT_CAP) {
|
|
1458
|
+
// Fresh scan from the body's start — rewind the line-count cursor too.
|
|
1459
|
+
lcIdx = 0;
|
|
1460
|
+
lcLine = fn.startLine;
|
|
1021
1461
|
ARRAY_DISPATCH_RE.lastIndex = 0;
|
|
1022
1462
|
while ((m = ARRAY_DISPATCH_RE.exec(body)) && added < FANOUT_CAP) {
|
|
1023
1463
|
const entries = arrayReg.get(m[1]);
|
|
@@ -1030,7 +1470,7 @@ async function cFnPointerDispatchEdges(_queries, ctx, onYield) {
|
|
|
1030
1470
|
: (entries.find((e) => e.file === fn.filePath)?.ids ?? null);
|
|
1031
1471
|
if (!ids)
|
|
1032
1472
|
continue;
|
|
1033
|
-
const line =
|
|
1473
|
+
const line = lineAt(m.index);
|
|
1034
1474
|
for (const tid of ids) {
|
|
1035
1475
|
if (tid === fn.id)
|
|
1036
1476
|
continue;
|
|
@@ -1057,6 +1497,10 @@ async function cFnPointerDispatchEdges(_queries, ctx, onYield) {
|
|
|
1057
1497
|
}
|
|
1058
1498
|
}
|
|
1059
1499
|
}
|
|
1500
|
+
if (prof) {
|
|
1501
|
+
prof.E = Date.now() - tPass;
|
|
1502
|
+
console.error(`[synth-timing] cFnPtr sub: A=${prof.A}ms B=${prof.B}ms C=${prof.C}ms D=${prof.D}ms E=${prof.E}ms | read n=${prof.readN} ${prof.readMs}ms strip n=${prof.stripN} ${prof.stripMs}ms nodesInFile n=${prof.nodesN} ${prof.nodesMs}ms`);
|
|
1503
|
+
}
|
|
1060
1504
|
return edges;
|
|
1061
1505
|
}
|
|
1062
1506
|
//# sourceMappingURL=c-fnptr-synthesizer.js.map
|