mirror of
https://github.com/DeusData/codebase-memory-mcp.git
synced 2026-11-22 17:30:49 +08:00
Four extraction sites did work that grew with the square of the file. Flat labels: NASM instructions and ObjectScript routine statements each walked back over every earlier sibling for the label above them. A search now stops at the sibling the previous search under the same parent started from and takes what that search found, with one memo per ancestor level for NASM's climb. Which label a statement gets is unchanged. Usage classifiers: each identifier's binding, write and argument-label classifiers climbed towards the root, so nesting d levels deep cost d per identifier. A climb that reaches the root undecided now records the path it settled, and the next climb stops where it meets it. Spawn checks: every call's spawn check read all of its file's import rows, on both call resolvers. The rows are indexed on the first question between cbm_spawn_file_begin and cbm_spawn_file_end around each file's call loop. Other rows, an over-long name or a failed allocation read the rows as before, with the same answer. Go route bindings: for every route call the receiver's binding was found by walking back over all earlier statements in the block. A block's bindings are now read once, sorted by name and source order in the file's scratch arena; each question is a binary search for the last binding before the asking statement. Growth tests, counted work when the input doubles, before and after: complexity_flat_preceding_label_is_linear 4.00x to 2.00x; complexity_usage_classifiers_on_deep_nesting_are_linear 3.99x to 2.00x; complexity_spawn_match_is_linear_in_a_files_imports 4.00x to 2.00x, with complexity_spawn_file_index_answers_as_the_rows_do comparing both routes across nine languages; complexity_go_route_bindings_are_near_linear 4.00x to 2.00x (2.18x for group bindings), with handles_go_group_binding_forms_*_issue686 pinning the binding forms on both pipelines. No graph content changes: gitea, helm, flask, nest, tokio, nccl and jellyfin index identically before and after. Each remaining sibling or parent step still walks the parent's children inside tree-sitter; that needs a syntax index. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
77 lines
3.7 KiB
C
77 lines
3.7 KiB
C
/*
|
|
* spawn_patterns.h — process-spawning call sites, per language.
|
|
*
|
|
* Like the HTTP client tables in service_patterns.h: a call that starts
|
|
* another program (subprocess.run, exec.Command, posix_spawn, Process.Start,
|
|
* Command::new, ...) becomes a SPAWNS edge to a Process node named after the
|
|
* program it starts. Nothing resolves the program to code: the edge records
|
|
* that the caller leaves the graph through a process boundary, and which
|
|
* program it starts when the call spells it as a literal.
|
|
*/
|
|
#ifndef CBM_SPAWN_PATTERNS_H
|
|
#define CBM_SPAWN_PATTERNS_H
|
|
|
|
#include "cbm.h"
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
|
|
/* How a table spelling matches a call. */
|
|
typedef enum {
|
|
/* The full spelling, written out or reached through the file's imports
|
|
* (`sp.run` with `import subprocess as sp`, `run` from
|
|
* `from subprocess import run`, Go `exec.Command` from "os/exec"). */
|
|
CBM_SPAWN_QUALIFIED = 0,
|
|
/* A bare name (`system`, `popen`, `exec`): the spelling alone. A
|
|
* definition of that name in the calling module (or one the call reaches
|
|
* through an import) still makes it an ordinary call. */
|
|
CBM_SPAWN_BARE,
|
|
/* A bare name that counts when the file imports `module`
|
|
* (Haskell `callProcess` with System.Process, a destructured
|
|
* `const { spawn } = require("child_process")`). */
|
|
CBM_SPAWN_BARE_IMPORTED,
|
|
/* Groovy `"git status".execute()`: the receiver is the command line. */
|
|
CBM_SPAWN_STRING_RECEIVER,
|
|
} cbm_spawn_rule_t;
|
|
|
|
typedef struct {
|
|
const char *api; /* canonical spelling: "subprocess.run", "os/exec.Command", "system" */
|
|
const char *module; /* the import a CBM_SPAWN_BARE_IMPORTED name needs, else NULL */
|
|
unsigned char rule; /* cbm_spawn_rule_t */
|
|
signed char arg; /* argument holding the program or command line */
|
|
signed char alt; /* second place to look, -1 for none (CreateProcess: name or line),
|
|
* or CBM_SPAWN_ANY_LITERAL */
|
|
} cbm_spawn_api_t;
|
|
|
|
/* `alt` value: the program is the first literal anywhere in the argument,
|
|
* which is an options tuple or struct (Elixir {:spawn, "cat"}, Zig
|
|
* .{ .argv = &.{"ls"} }). Elsewhere only a leading literal or a collection's
|
|
* first element is the program. */
|
|
#define CBM_SPAWN_ANY_LITERAL (-2)
|
|
|
|
/* The spawn API a call names, or NULL. `imports` are the calling file's own
|
|
* import statements (local name -> module path) as extracted, external
|
|
* modules included: subprocess or os/exec never resolve to project nodes, so
|
|
* the resolver's import map does not hold them. Whether the call is a spawn
|
|
* after all is the resolver's to decide: an evidence-backed resolution onto
|
|
* project code (an import, the same module, the LSP; never a name guess)
|
|
* makes it an ordinary call (src/pipeline/pass_spawns.c). */
|
|
const cbm_spawn_api_t *cbm_spawn_match(CBMLanguage lang, const char *callee,
|
|
const CBMImport *imports, int count);
|
|
|
|
/* Around one file's loop over its calls, on one thread: a match on exactly these rows asks them
|
|
* by name, the same answer as reading them all. Any other rows are read as usual. */
|
|
void cbm_spawn_file_begin(const CBMImport *imports, int count);
|
|
void cbm_spawn_file_end(void);
|
|
|
|
/* The program a matched spawn starts: the first literal in its program
|
|
* argument, that literal's first word, without directories
|
|
* ("/usr/bin/git status" -> "git"). CBM_SPAWN_DYNAMIC when the program is
|
|
* not a literal. Writes into buf (at least CBM_SPAWN_PROGRAM_MAX bytes). */
|
|
#define CBM_SPAWN_DYNAMIC "<dynamic>"
|
|
#define CBM_SPAWN_PROGRAM_MAX 64
|
|
void cbm_spawn_program(const cbm_spawn_api_t *api, CBMLanguage lang, const CBMCall *call, char *buf,
|
|
size_t n);
|
|
|
|
#endif
|