Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
refactor(mem): route this branch's allocations through the memory core
Martin Vogel1d58385b513a
diff --git a/.github/workflows/_memwaste.yml b/.github/workflows/_memwaste.ymlindex ab9e1e3c6..174490db6 100644--- a/.github/workflows/_memwaste.yml+++ b/.github/workflows/_memwaste.yml@@ -40,6 +40,10 @@ jobs:run: sudo apt-get update && sudo apt-get install -y zlib1g-dev python3 clang llvm- name: Event lane on this repositoryrun: |+ # `cmd | tee` reports TEE's status: without this a failing lane+ # (a missing exec bit, a build error) passes the step and only+ # surfaces as the ratchet not finding its JSON.+ set -o pipefailmkdir -p "$RUNNER_TEMP/memwaste-event"scripts/memwaste.sh "$GITHUB_WORKSPACE" --top 40 --out "$RUNNER_TEMP/memwaste-event" \| tee "$RUNNER_TEMP/memwaste-event/report.txt"@@ -67,6 +71,10 @@ jobs:# Report-only: the script exits 1 when it flags a super-linear function.continue-on-error: truerun: |+ # `cmd | tee` reports TEE's status: without this a failing lane+ # (a missing exec bit, a build error) passes the step and only+ # surfaces as the ratchet not finding its JSON.+ set -o pipefailmkdir -p "$RUNNER_TEMP/memwaste-scaling"python3 scripts/memwaste-scaling.py --corpus src --replicas 2 \--out "$RUNNER_TEMP/memwaste-scaling" | tee "$RUNNER_TEMP/memwaste-scaling/report.txt"@@ -88,6 +96,10 @@ jobs:run: sudo apt-get update && sudo apt-get install -y zlib1g-dev python3 clang llvm- name: Access lane on this repositoryrun: |+ # `cmd | tee` reports TEE's status: without this a failing lane+ # (a missing exec bit, a build error) passes the step and only+ # surfaces as the ratchet not finding its JSON.+ set -o pipefailmkdir -p "$RUNNER_TEMP/memwaste-access"scripts/memwaste.sh "$GITHUB_WORKSPACE" --lane access --top 40 --sort untouched \--out "$RUNNER_TEMP/memwaste-access" | tee "$RUNNER_TEMP/memwaste-access/report.txt"@@ -109,6 +121,10 @@ jobs:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1- name: Event lane on this repositoryrun: |+ # `cmd | tee` reports TEE's status: without this a failing lane+ # (a missing exec bit, a build error) passes the step and only+ # surfaces as the ratchet not finding its JSON.+ set -o pipefailmkdir -p "$RUNNER_TEMP/memwaste-event"scripts/memwaste.sh "$GITHUB_WORKSPACE" --top 40 --out "$RUNNER_TEMP/memwaste-event" \| tee "$RUNNER_TEMP/memwaste-event/report.txt"@@ -145,6 +161,10 @@ jobs:- name: Event lane on this repositoryshell: msys2 {0}run: |+ # `cmd | tee` reports TEE's status: without this a failing lane+ # (a missing exec bit, a build error) passes the step and only+ # surfaces as the ratchet not finding its JSON.+ set -o pipefailout="$(cygpath -u "$RUNNER_TEMP")/memwaste-event"mkdir -p "$out"CC=clang CXX=clang++ scripts/memwaste.sh "$(cygpath -u "$GITHUB_WORKSPACE")" --top 40 --out "$out" \diff --git a/internal/cbm/lsp/go_lsp.c b/internal/cbm/lsp/go_lsp.cindex 4518bf243..ba7df163b 100644--- a/internal/cbm/lsp/go_lsp.c+++ b/internal/cbm/lsp/go_lsp.c@@ -8,7 +8,7 @@#include <stdatomic.h>// Forward declarations-static void resolve_calls_in_node_inner(GoLSPContext* ctx, TSNode node);+static void resolve_calls_in_node_inner(GoLSPContext *ctx, TSNode node);/* Depth-guarded entry for the AST call-resolution walk. The walk recurses once* per nesting level; a deeply-nested or cyclic file can overflow the native@@ -17,7 +17,7 @@ static void resolve_calls_in_node_inner(GoLSPContext* ctx, TSNode node);* crash. The cap is CBM_LSP_MAX_WALK_DEPTH, env-overridable via the same name.* The walk_depth-- runs after the inner returns, so early returns in the body* never leak the counter. */-static void resolve_calls_in_node(GoLSPContext* ctx, TSNode node) {+static void resolve_calls_in_node(GoLSPContext *ctx, TSNode node) {if (ctx->walk_depth >= cbm_lsp_max_walk_depth())return;ctx->walk_depth++;@@ -27,14 +27,16 @@ static void resolve_calls_in_node(GoLSPContext* ctx, TSNode node) {static void emit_resolved_call(GoLSPContext *ctx, const char *callee_qn, const char *strategy,float confidence, TSNode site);static const char *go_exact_callable_target(GoLSPContext *ctx, TSNode node);-static const CBMType* go_lookup_field(GoLSPContext* ctx, const char* type_qn, const char* field_name, int depth);-static void extract_type_params_from_ast(CBMArena* arena, CBMTypeRegistry* reg,- TSNode root, const char* source, const char* module_qn);+static const CBMType *go_lookup_field(GoLSPContext *ctx, const char *type_qn,+ const char *field_name, int depth);+static void extract_type_params_from_ast(CBMArena *arena, CBMTypeRegistry *reg, TSNode root,+ const char *source, const char *module_qn);// --- Initialization ----void go_lsp_init(GoLSPContext* ctx, CBMArena* arena, const char* source, int source_len,- const CBMTypeRegistry* registry, const char* package_qn, CBMResolvedCallArray* out) {+void go_lsp_init(GoLSPContext *ctx, CBMArena *arena, const char *source, int source_len,+ const CBMTypeRegistry *registry, const char *package_qn,+ CBMResolvedCallArray *out) {memset(ctx, 0, sizeof(GoLSPContext));ctx->arena = arena;ctx->source = source;@@ -45,21 +47,24 @@ void go_lsp_init(GoLSPContext* ctx, CBMArena* arena, const char* source, int souctx->current_scope = cbm_scope_push(arena, NULL); // root scope{- const char* debug_env = getenv("CBM_LSP_DEBUG");+ const char *debug_env = getenv("CBM_LSP_DEBUG");ctx->debug = (debug_env && debug_env[0]);}}-void go_lsp_add_import(GoLSPContext* ctx, const char* local_name, const char* pkg_qn) {+void go_lsp_add_import(GoLSPContext *ctx, const char *local_name, const char *pkg_qn) {// Store in parallel arrays (arena-allocated, grow by doubling)if (ctx->import_count % 32 == 0) {int new_cap = ctx->import_count + 32;- const char** new_names = (const char**)cbm_arena_alloc(ctx->arena, (new_cap + 1) * sizeof(const char*));- const char** new_qns = (const char**)cbm_arena_alloc(ctx->arena, (new_cap + 1) * sizeof(const char*));- if (!new_names || !new_qns) return;+ const char **new_names =+ (const char **)cbm_arena_alloc(ctx->arena, (new_cap + 1) * sizeof(const char *));+ const char **new_qns =+ (const char **)cbm_arena_alloc(ctx->arena, (new_cap + 1) * sizeof(const char *));+ if (!new_names || !new_qns)+ return;if (ctx->import_local_names && ctx->import_count > 0) {- memcpy(new_names, ctx->import_local_names, ctx->import_count * sizeof(const char*));- memcpy(new_qns, ctx->import_package_qns, ctx->import_count * sizeof(const char*));+ memcpy(new_names, ctx->import_local_names, ctx->import_count * sizeof(const char *));+ memcpy(new_qns, ctx->import_package_qns, ctx->import_count * sizeof(const char *));}ctx->import_local_names = new_names;ctx->import_package_qns = new_qns;@@ -71,13 +76,13 @@ void go_lsp_add_import(GoLSPContext* ctx, const char* local_name, const char* pk// --- Helper: get node text ----static char* lsp_node_text(GoLSPContext* ctx, TSNode node) {+static char *lsp_node_text(GoLSPContext *ctx, TSNode node) {return cbm_node_text(ctx->arena, node, ctx->source);}// --- Helper: resolve import alias to package QN ----static const char* resolve_import(GoLSPContext* ctx, const char* local_name) {+static const char *resolve_import(GoLSPContext *ctx, const char *local_name) {for (int i = 0; i < ctx->import_count; i++) {if (strcmp(ctx->import_local_names[i], local_name) == 0) {return ctx->import_package_qns[i];@@ -88,31 +93,26 @@ static const char* resolve_import(GoLSPContext* ctx, const char* local_name) {// --- Helper: check if name is a Go builtin ----static bool is_go_builtin_func(const char* name) {- static const char* builtins[] = {- "make", "new", "append", "len", "cap", "delete",- "close", "copy", "panic", "recover", "print", "println",- "complex", "real", "imag", "min", "max", "clear",- NULL- };- for (const char** b = builtins; *b; b++) {- if (strcmp(name, *b) == 0) return true;+static bool is_go_builtin_func(const char *name) {+ static const char *builtins[] = {"make", "new", "append", "len", "cap",+ "delete", "close", "copy", "panic", "recover",+ "print", "println", "complex", "real", "imag",+ "min", "max", "clear", NULL};+ for (const char **b = builtins; *b; b++) {+ if (strcmp(name, *b) == 0)+ return true;}return false;}// --- Helper: check if name is a Go builtin type ----static const CBMType* resolve_builtin_type(GoLSPContext* ctx, const char* name) {- static const char* builtin_types[] = {- "int", "int8", "int16", "int32", "int64",- "uint", "uint8", "uint16", "uint32", "uint64",- "float32", "float64", "complex64", "complex128",- "string", "bool", "byte", "rune", "error",- "uintptr", "any",- NULL- };- for (const char** b = builtin_types; *b; b++) {+static const CBMType *resolve_builtin_type(GoLSPContext *ctx, const char *name) {+ static const char *builtin_types[] = {+ "int", "int8", "int16", "int32", "int64", "uint", "uint8", "uint16",+ "uint32", "uint64", "float32", "float64", "complex64", "complex128", "string", "bool",+ "byte", "rune", "error", "uintptr", "any", NULL};+ for (const char **b = builtin_types; *b; b++) {if (strcmp(name, *b) == 0) {return cbm_type_builtin(ctx->arena, name);}@@ -122,20 +122,23 @@ static const CBMType* resolve_builtin_type(GoLSPContext* ctx, const char* name)// --- go_parse_type_node: AST type node -> CBMType ----const CBMType* go_parse_type_node(GoLSPContext* ctx, TSNode node) {- if (ts_node_is_null(node)) return cbm_type_unknown();+const CBMType *go_parse_type_node(GoLSPContext *ctx, TSNode node) {+ if (ts_node_is_null(node))+ return cbm_type_unknown();- const char* kind = ts_node_type(node);+ const char *kind = ts_node_type(node);// type_identifier: simple named typeif (strcmp(kind, "type_identifier") == 0) {- char* name = lsp_node_text(ctx, node);- if (!name) return cbm_type_unknown();- const CBMType* builtin = resolve_builtin_type(ctx, name);- if (builtin) return builtin;+ char *name = lsp_node_text(ctx, node);+ if (!name)+ return cbm_type_unknown();+ const CBMType *builtin = resolve_builtin_type(ctx, name);+ if (builtin)+ return builtin;// Resolve as local type: package_qn.TypeNamereturn cbm_type_named(ctx->arena,- cbm_arena_sprintf(ctx->arena, "%s.%s", ctx->package_qn, name));+ cbm_arena_sprintf(ctx->arena, "%s.%s", ctx->package_qn, name));}// qualified_type: pkg.Type@@ -143,12 +146,12 @@ const CBMType* go_parse_type_node(GoLSPContext* ctx, TSNode node) {TSNode pkg_node = ts_node_child_by_field_name(node, "package", 7);TSNode name_node = ts_node_child_by_field_name(node, "name", 4);if (!ts_node_is_null(pkg_node) && !ts_node_is_null(name_node)) {- char* pkg = lsp_node_text(ctx, pkg_node);- char* name = lsp_node_text(ctx, name_node);- const char* pkg_qn = resolve_import(ctx, pkg);+ char *pkg = lsp_node_text(ctx, pkg_node);+ char *name = lsp_node_text(ctx, name_node);+ const char *pkg_qn = resolve_import(ctx, pkg);if (pkg_qn) {return cbm_type_named(ctx->arena,- cbm_arena_sprintf(ctx->arena, "%s.%s", pkg_qn, name));+ cbm_arena_sprintf(ctx->arena, "%s.%s", pkg_qn, name));}}return cbm_type_unknown();@@ -159,7 +162,7 @@ const CBMType* go_parse_type_node(GoLSPContext* ctx, TSNode node) {uint32_t nc = ts_node_named_child_count(node);if (nc > 0) {return cbm_type_pointer(ctx->arena,- go_parse_type_node(ctx, ts_node_named_child(node, nc - 1)));+ go_parse_type_node(ctx, ts_node_named_child(node, nc - 1)));}return cbm_type_unknown();}@@ -186,9 +189,8 @@ const CBMType* go_parse_type_node(GoLSPContext* ctx, TSNode node) {if (strcmp(kind, "map_type") == 0) {TSNode key = ts_node_child_by_field_name(node, "key", 3);TSNode value = ts_node_child_by_field_name(node, "value", 5);- return cbm_type_map(ctx->arena,- go_parse_type_node(ctx, key),- go_parse_type_node(ctx, value));+ return cbm_type_map(ctx->arena, go_parse_type_node(ctx, key),+ go_parse_type_node(ctx, value));}// channel_type: chan T@@ -198,11 +200,13 @@ const CBMType* go_parse_type_node(GoLSPContext* ctx, TSNode node) {value = ts_node_named_child(node, ts_node_named_child_count(node) - 1);}// Determine direction from text- char* text = lsp_node_text(ctx, node);+ char *text = lsp_node_text(ctx, node);int dir = 0;if (text) {- if (strncmp(text, "chan<-", 6) == 0 || strncmp(text, "chan <-", 7) == 0) dir = 1;- else if (strncmp(text, "<-chan", 6) == 0 || strncmp(text, "<- chan", 7) == 0) dir = 2;+ if (strncmp(text, "chan<-", 6) == 0 || strncmp(text, "chan <-", 7) == 0)+ dir = 1;+ else if (strncmp(text, "<-chan", 6) == 0 || strncmp(text, "<- chan", 7) == 0)+ dir = 2;}return cbm_type_channel(ctx->arena, go_parse_type_node(ctx, value), dir);}@@ -214,7 +218,7 @@ const CBMType* go_parse_type_node(GoLSPContext* ctx, TSNode node) {// interface_typeif (strcmp(kind, "interface_type") == 0) {- CBMType* t = (CBMType*)cbm_arena_alloc(ctx->arena, sizeof(CBMType));+ CBMType *t = (CBMType *)cbm_arena_alloc(ctx->arena, sizeof(CBMType));memset(t, 0, sizeof(CBMType));t->kind = CBM_TYPE_INTERFACE;return t;@@ -222,7 +226,7 @@ const CBMType* go_parse_type_node(GoLSPContext* ctx, TSNode node) {// struct_typeif (strcmp(kind, "struct_type") == 0) {- CBMType* t = (CBMType*)cbm_arena_alloc(ctx->arena, sizeof(CBMType));+ CBMType *t = (CBMType *)cbm_arena_alloc(ctx->arena, sizeof(CBMType));memset(t, 0, sizeof(CBMType));t->kind = CBM_TYPE_STRUCT;return t;@@ -249,12 +253,13 @@ const CBMType* go_parse_type_node(GoLSPContext* ctx, TSNode node) {// parameter_list used as result type (multi-return)if (strcmp(kind, "parameter_list") == 0) {int count = 0;- const CBMType* elems[16];+ const CBMType *elems[16];uint32_t nc = ts_node_child_count(node);for (uint32_t i = 0; i < nc && count < 16; i++) {TSNode child = ts_node_child(node, i);- if (ts_node_is_null(child) || !ts_node_is_named(child)) continue;- const char* ck = ts_node_type(child);+ if (ts_node_is_null(child) || !ts_node_is_named(child))+ continue;+ const char *ck = ts_node_type(child);if (strcmp(ck, "parameter_declaration") == 0) {TSNode tn = ts_node_child_by_field_name(child, "type", 4);if (!ts_node_is_null(tn)) {@@ -264,8 +269,10 @@ const CBMType* go_parse_type_node(GoLSPContext* ctx, TSNode node) {elems[count++] = go_parse_type_node(ctx, child);}}- if (count == 1) return elems[0];- if (count > 1) return cbm_type_tuple(ctx->arena, elems, count);+ if (count == 1)+ return elems[0];+ if (count > 1)+ return cbm_type_tuple(ctx->arena, elems, count);}return cbm_type_unknown();@@ -275,14 +282,17 @@ const CBMType* go_parse_type_node(GoLSPContext* ctx, TSNode node) {// Unify a parameter type pattern (containing TYPE_PARAM) against a concrete argument type.// Fills inferred[i] with the concrete type bound to type_param_names[i].-static void go_unify_type(const CBMType* param_type, const CBMType* arg_type,- const char** type_param_names, const CBMType** inferred, int param_count) {- if (!param_type || !arg_type || cbm_type_is_unknown(arg_type)) return;+static void go_unify_type(const CBMType *param_type, const CBMType *arg_type,+ const char **type_param_names, const CBMType **inferred,+ int param_count) {+ if (!param_type || !arg_type || cbm_type_is_unknown(arg_type))+ return;if (param_type->kind == CBM_TYPE_TYPE_PARAM) {for (int i = 0; i < param_count; i++) {if (strcmp(param_type->data.type_param.name, type_param_names[i]) == 0) {- if (!inferred[i]) inferred[i] = arg_type;+ if (!inferred[i])+ inferred[i] = arg_type;break;}}@@ -291,36 +301,41 @@ static void go_unify_type(const CBMType* param_type, const CBMType* arg_type,// Structural matching — recurse into composite typesif (param_type->kind == CBM_TYPE_SLICE && arg_type->kind == CBM_TYPE_SLICE) {- go_unify_type(param_type->data.slice.elem, arg_type->data.slice.elem,- type_param_names, inferred, param_count);+ go_unify_type(param_type->data.slice.elem, arg_type->data.slice.elem, type_param_names,+ inferred, param_count);}if (param_type->kind == CBM_TYPE_POINTER && arg_type->kind == CBM_TYPE_POINTER) {- go_unify_type(param_type->data.pointer.elem, arg_type->data.pointer.elem,- type_param_names, inferred, param_count);+ go_unify_type(param_type->data.pointer.elem, arg_type->data.pointer.elem, type_param_names,+ inferred, param_count);}if (param_type->kind == CBM_TYPE_MAP && arg_type->kind == CBM_TYPE_MAP) {- go_unify_type(param_type->data.map.key, arg_type->data.map.key,- type_param_names, inferred, param_count);- go_unify_type(param_type->data.map.value, arg_type->data.map.value,- type_param_names, inferred, param_count);+ go_unify_type(param_type->data.map.key, arg_type->data.map.key, type_param_names, inferred,+ param_count);+ go_unify_type(param_type->data.map.value, arg_type->data.map.value, type_param_names,+ inferred, param_count);}if (param_type->kind == CBM_TYPE_CHANNEL && arg_type->kind == CBM_TYPE_CHANNEL) {- go_unify_type(param_type->data.channel.elem, arg_type->data.channel.elem,- type_param_names, inferred, param_count);+ go_unify_type(param_type->data.channel.elem, arg_type->data.channel.elem, type_param_names,+ inferred, param_count);}if (param_type->kind == CBM_TYPE_FUNC && arg_type->kind == CBM_TYPE_FUNC) {// Match param typesif (param_type->data.func.param_types && arg_type->data.func.param_types) {- for (int i = 0; param_type->data.func.param_types[i] && arg_type->data.func.param_types[i]; i++) {- go_unify_type(param_type->data.func.param_types[i], arg_type->data.func.param_types[i],- type_param_names, inferred, param_count);+ for (int i = 0;+ param_type->data.func.param_types[i] && arg_type->data.func.param_types[i]; i++) {+ go_unify_type(param_type->data.func.param_types[i],+ arg_type->data.func.param_types[i], type_param_names, inferred,+ param_count);}}// Match return typesif (param_type->data.func.return_types && arg_type->data.func.return_types) {- for (int i = 0; param_type->data.func.return_types[i] && arg_type->data.func.return_types[i]; i++) {- go_unify_type(param_type->data.func.return_types[i], arg_type->data.func.return_types[i],- type_param_names, inferred, param_count);+ for (int i = 0;+ param_type->data.func.return_types[i] && arg_type->data.func.return_types[i];+ i++) {+ go_unify_type(param_type->data.func.return_types[i],+ arg_type->data.func.return_types[i], type_param_names, inferred,+ param_count);}}}@@ -328,33 +343,39 @@ static void go_unify_type(const CBMType* param_type, const CBMType* arg_type,// --- go_eval_expr_type: recursive expression type evaluator ----const CBMType* go_eval_expr_type(GoLSPContext* ctx, TSNode node) {- if (ts_node_is_null(node)) return cbm_type_unknown();+const CBMType *go_eval_expr_type(GoLSPContext *ctx, TSNode node) {+ if (ts_node_is_null(node))+ return cbm_type_unknown();- const char* kind = ts_node_type(node);+ const char *kind = ts_node_type(node);// --- Identifier: scope lookup ---if (strcmp(kind, "identifier") == 0) {- char* name = lsp_node_text(ctx, node);- if (!name) return cbm_type_unknown();+ char *name = lsp_node_text(ctx, node);+ if (!name)+ return cbm_type_unknown();// Check scope first- const CBMType* t = cbm_scope_lookup(ctx->current_scope, name);+ const CBMType *t = cbm_scope_lookup(ctx->current_scope, name);if (cbm_scope_contains(ctx->current_scope, name))return t ? t : cbm_type_unknown();// Check if it's a package-level function- const CBMRegisteredFunc* f = cbm_registry_lookup_symbol(ctx->registry, ctx->package_qn, name);- if (f && f->signature) return f->signature;+ const CBMRegisteredFunc *f =+ cbm_registry_lookup_symbol(ctx->registry, ctx->package_qn, name);+ if (f && f->signature)+ return f->signature;// Check if it's a builtin type (for type conversions like string(x), int(x))- const CBMType* bt = resolve_builtin_type(ctx, name);- if (bt) return cbm_type_named(ctx->arena, name);+ const CBMType *bt = resolve_builtin_type(ctx, name);+ if (bt)+ return cbm_type_named(ctx->arena, name);// Check if it's a registered type (for type conversions like MyType(x))- const char* type_qn = cbm_arena_sprintf(ctx->arena, "%s.%s", ctx->package_qn, name);- const CBMRegisteredType* rt = cbm_registry_lookup_type(ctx->registry, type_qn);- if (rt) return cbm_type_named(ctx->arena, type_qn);+ const char *type_qn = cbm_arena_sprintf(ctx->arena, "%s.%s", ctx->package_qn, name);+ const CBMRegisteredType *rt = cbm_registry_lookup_type(ctx->registry, type_qn);+ if (rt)+ return cbm_type_named(ctx->arena, type_qn);return cbm_type_unknown();}@@ -363,49 +384,57 @@ const CBMType* go_eval_expr_type(GoLSPContext* ctx, TSNode node) {if (strcmp(kind, "selector_expression") == 0) {TSNode operand = ts_node_child_by_field_name(node, "operand", 7);TSNode field = ts_node_child_by_field_name(node, "field", 5);- if (ts_node_is_null(operand) || ts_node_is_null(field)) return cbm_type_unknown();+ if (ts_node_is_null(operand) || ts_node_is_null(field))+ return cbm_type_unknown();- char* field_name = lsp_node_text(ctx, field);- if (!field_name) return cbm_type_unknown();+ char *field_name = lsp_node_text(ctx, field);+ if (!field_name)+ return cbm_type_unknown();// Check if operand is an import alias (pkg.Symbol)if (strcmp(ts_node_type(operand), "identifier") == 0) {- char* pkg_name = lsp_node_text(ctx, operand);+ char *pkg_name = lsp_node_text(ctx, operand);if (pkg_name) {- const char* pkg_qn = resolve_import(ctx, pkg_name);+ const char *pkg_qn = resolve_import(ctx, pkg_name);if (pkg_qn) {// Look up pkg.Symbol as a function or type- const CBMRegisteredFunc* f = cbm_registry_lookup_symbol(ctx->registry, pkg_qn, field_name);- if (f && f->signature) return f->signature;+ const CBMRegisteredFunc *f =+ cbm_registry_lookup_symbol(ctx->registry, pkg_qn, field_name);+ if (f && f->signature)+ return f->signature;// Check if it's a type- char* type_qn = cbm_arena_sprintf(ctx->arena, "%s.%s", pkg_qn, field_name);- const CBMRegisteredType* rt = cbm_registry_lookup_type(ctx->registry, type_qn);- if (rt) return cbm_type_named(ctx->arena, type_qn);+ char *type_qn = cbm_arena_sprintf(ctx->arena, "%s.%s", pkg_qn, field_name);+ const CBMRegisteredType *rt = cbm_registry_lookup_type(ctx->registry, type_qn);+ if (rt)+ return cbm_type_named(ctx->arena, type_qn);return cbm_type_unknown();}}}// Evaluate operand type- const CBMType* recv_type = go_eval_expr_type(ctx, operand);- if (cbm_type_is_unknown(recv_type)) return cbm_type_unknown();+ const CBMType *recv_type = go_eval_expr_type(ctx, operand);+ if (cbm_type_is_unknown(recv_type))+ return cbm_type_unknown();// Auto-deref pointers for method calls- const CBMType* base_type = recv_type;+ const CBMType *base_type = recv_type;if (base_type->kind == CBM_TYPE_POINTER) {base_type = cbm_type_deref(base_type);}if (base_type->kind == CBM_TYPE_NAMED) {- const char* type_qn = base_type->data.named.qualified_name;+ const char *type_qn = base_type->data.named.qualified_name;// Look up method/field (methods recurse through embeddings)- const CBMRegisteredFunc* method = go_lookup_field_or_method(ctx, type_qn, field_name);- if (method && method->signature) return method->signature;+ const CBMRegisteredFunc *method = go_lookup_field_or_method(ctx, type_qn, field_name);+ if (method && method->signature)+ return method->signature;// Check struct fields (with embedded field promotion)- const CBMType* field_type = go_lookup_field(ctx, type_qn, field_name, 0);- if (field_type && !cbm_type_is_unknown(field_type)) return field_type;+ const CBMType *field_type = go_lookup_field(ctx, type_qn, field_name, 0);+ if (field_type && !cbm_type_is_unknown(field_type))+ return field_type;}return cbm_type_unknown();@@ -415,43 +444,45 @@ const CBMType* go_eval_expr_type(GoLSPContext* ctx, TSNode node) {if (strcmp(kind, "call_expression") == 0) {TSNode func_node = ts_node_child_by_field_name(node, "function", 8);TSNode args_node = ts_node_child_by_field_name(node, "arguments", 9);- if (ts_node_is_null(func_node)) return cbm_type_unknown();+ if (ts_node_is_null(func_node))+ return cbm_type_unknown();// Check for builtin callsif (strcmp(ts_node_type(func_node), "identifier") == 0) {- char* name = lsp_node_text(ctx, func_node);+ char *name = lsp_node_text(ctx, func_node);if (name && is_go_builtin_func(name)) {return go_eval_builtin_call(ctx, name, args_node);}}// Evaluate function type- const CBMType* func_type = go_eval_expr_type(ctx, func_node);+ const CBMType *func_type = go_eval_expr_type(ctx, func_node);// If it's a FUNC type, return its return type- if (func_type && func_type->kind == CBM_TYPE_FUNC &&- func_type->data.func.return_types && func_type->data.func.return_types[0]) {+ if (func_type && func_type->kind == CBM_TYPE_FUNC && func_type->data.func.return_types &&+ func_type->data.func.return_types[0]) {// Check for explicit type arguments: call_expression has type_arguments field- // Go tree-sitter: Func[T1, T2](args) → call_expression { function, type_arguments, arguments }+ // Go tree-sitter: Func[T1, T2](args) → call_expression { function, type_arguments,+ // arguments }TSNode targs_node = ts_node_child_by_field_name(node, "type_arguments", 14);if (!ts_node_is_null(targs_node)) {// Look up the registered function to get type_param_names- const CBMRegisteredFunc* rfunc = NULL;- char* func_name = lsp_node_text(ctx, func_node);+ const CBMRegisteredFunc *rfunc = NULL;+ char *func_name = lsp_node_text(ctx, func_node);if (func_name) {- const char* func_qn = cbm_arena_sprintf(ctx->arena, "%s.%s",- ctx->package_qn, func_name);+ const char *func_qn =+ cbm_arena_sprintf(ctx->arena, "%s.%s", ctx->package_qn, func_name);rfunc = cbm_registry_lookup_func(ctx->registry, func_qn);// If not found as local, try via import (selector_expression: pkg.Func)if (!rfunc && strcmp(ts_node_type(func_node), "selector_expression") == 0) {TSNode operand = ts_node_child_by_field_name(func_node, "operand", 7);TSNode field = ts_node_child_by_field_name(func_node, "field", 5);if (!ts_node_is_null(operand) && !ts_node_is_null(field)) {- char* pkg = lsp_node_text(ctx, operand);- char* fn = lsp_node_text(ctx, field);+ char *pkg = lsp_node_text(ctx, operand);+ char *fn = lsp_node_text(ctx, field);if (pkg && fn) {- const char* pkg_qn = resolve_import(ctx, pkg);+ const char *pkg_qn = resolve_import(ctx, pkg);if (pkg_qn) {rfunc = cbm_registry_lookup_symbol(ctx->registry, pkg_qn, fn);}@@ -462,40 +493,44 @@ const CBMType* go_eval_expr_type(GoLSPContext* ctx, TSNode node) {if (rfunc && rfunc->type_param_names) {// Parse type arguments from AST- const CBMType* type_args[16];+ const CBMType *type_args[16];int targ_count = 0;uint32_t ta_nc = ts_node_child_count(targs_node);for (uint32_t ti = 0; ti < ta_nc && targ_count < 15; ti++) {TSNode targ = ts_node_child(targs_node, ti);- if (ts_node_is_null(targ) || !ts_node_is_named(targ)) continue;+ if (ts_node_is_null(targ) || !ts_node_is_named(targ))+ continue;type_args[targ_count++] = go_parse_type_node(ctx, targ);}// Count type paramsint param_count = 0;- while (rfunc->type_param_names[param_count]) param_count++;+ while (rfunc->type_param_names[param_count])+ param_count++;if (targ_count > 0 && targ_count == param_count) {- const CBMType** targ_arr = (const CBMType**)cbm_arena_alloc(- ctx->arena, (targ_count + 1) * sizeof(const CBMType*));- for (int ti = 0; ti < targ_count; ti++) targ_arr[ti] = type_args[ti];+ const CBMType **targ_arr = (const CBMType **)cbm_arena_alloc(+ ctx->arena, (targ_count + 1) * sizeof(const CBMType *));+ for (int ti = 0; ti < targ_count; ti++)+ targ_arr[ti] = type_args[ti];targ_arr[targ_count] = NULL;// Substitute type params in return type(s)int ret_count = 0;- while (func_type->data.func.return_types[ret_count]) ret_count++;+ while (func_type->data.func.return_types[ret_count])+ ret_count++;if (ret_count == 1) {return cbm_type_substitute(ctx->arena,- func_type->data.func.return_types[0],- rfunc->type_param_names, targ_arr);+ func_type->data.func.return_types[0],+ rfunc->type_param_names, targ_arr);}// Multi-return: substitute all- const CBMType** new_rets = (const CBMType**)cbm_arena_alloc(- ctx->arena, (ret_count + 1) * sizeof(const CBMType*));+ const CBMType **new_rets = (const CBMType **)cbm_arena_alloc(+ ctx->arena, (ret_count + 1) * sizeof(const CBMType *));for (int ri = 0; ri < ret_count; ri++) {- new_rets[ri] = cbm_type_substitute(ctx->arena,- func_type->data.func.return_types[ri],+ new_rets[ri] = cbm_type_substitute(+ ctx->arena, func_type->data.func.return_types[ri],rfunc->type_param_names, targ_arr);}new_rets[ret_count] = NULL;@@ -507,20 +542,20 @@ const CBMType* go_eval_expr_type(GoLSPContext* ctx, TSNode node) {// Implicit generics: infer type args from argument typesif (ts_node_is_null(targs_node)) {// Look up registered function to check for type_param_names- const CBMRegisteredFunc* rfunc = NULL;- char* func_name = lsp_node_text(ctx, func_node);+ const CBMRegisteredFunc *rfunc = NULL;+ char *func_name = lsp_node_text(ctx, func_node);if (func_name) {- const char* func_qn = cbm_arena_sprintf(ctx->arena, "%s.%s",- ctx->package_qn, func_name);+ const char *func_qn =+ cbm_arena_sprintf(ctx->arena, "%s.%s", ctx->package_qn, func_name);rfunc = cbm_registry_lookup_func(ctx->registry, func_qn);if (!rfunc && strcmp(ts_node_type(func_node), "selector_expression") == 0) {TSNode operand = ts_node_child_by_field_name(func_node, "operand", 7);TSNode field = ts_node_child_by_field_name(func_node, "field", 5);if (!ts_node_is_null(operand) && !ts_node_is_null(field)) {- char* pkg = lsp_node_text(ctx, operand);- char* fn = lsp_node_text(ctx, field);+ char *pkg = lsp_node_text(ctx, operand);+ char *fn = lsp_node_text(ctx, field);if (pkg && fn) {- const char* pkg_qn = resolve_import(ctx, pkg);+ const char *pkg_qn = resolve_import(ctx, pkg);if (pkg_qn)rfunc = cbm_registry_lookup_symbol(ctx->registry, pkg_qn, fn);}@@ -530,39 +565,49 @@ const CBMType* go_eval_expr_type(GoLSPContext* ctx, TSNode node) {if (rfunc && rfunc->type_param_names && func_type->data.func.param_types) {int tpc = 0;- while (rfunc->type_param_names[tpc]) tpc++;+ while (rfunc->type_param_names[tpc])+ tpc++;// Check if any return type uses a type parambool has_type_param = false;int ret_count = 0;- while (func_type->data.func.return_types[ret_count]) ret_count++;+ while (func_type->data.func.return_types[ret_count])+ ret_count++;for (int ri = 0; ri < ret_count && !has_type_param; ri++) {// Quick check: walk return type tree for TYPE_PARAM nodes- const CBMType* rt = func_type->data.func.return_types[ri];- if (rt->kind == CBM_TYPE_TYPE_PARAM) has_type_param = true;+ const CBMType *rt = func_type->data.func.return_types[ri];+ if (rt->kind == CBM_TYPE_TYPE_PARAM)+ has_type_param = true;else if (rt->kind == CBM_TYPE_SLICE && rt->data.slice.elem &&- rt->data.slice.elem->kind == CBM_TYPE_TYPE_PARAM) has_type_param = true;+ rt->data.slice.elem->kind == CBM_TYPE_TYPE_PARAM)+ has_type_param = true;else if (rt->kind == CBM_TYPE_POINTER && rt->data.pointer.elem &&- rt->data.pointer.elem->kind == CBM_TYPE_TYPE_PARAM) has_type_param = true;+ rt->data.pointer.elem->kind == CBM_TYPE_TYPE_PARAM)+ has_type_param = true;else if (rt->kind == CBM_TYPE_MAP) {- if (rt->data.map.key && rt->data.map.key->kind == CBM_TYPE_TYPE_PARAM) has_type_param = true;- if (rt->data.map.value && rt->data.map.value->kind == CBM_TYPE_TYPE_PARAM) has_type_param = true;+ if (rt->data.map.key && rt->data.map.key->kind == CBM_TYPE_TYPE_PARAM)+ has_type_param = true;+ if (rt->data.map.value &&+ rt->data.map.value->kind == CBM_TYPE_TYPE_PARAM)+ has_type_param = true;}}if (has_type_param && tpc > 0 && tpc <= 16) {// Evaluate argument types and unify- const CBMType* inferred[16] = {0};+ const CBMType *inferred[16] = {0};if (!ts_node_is_null(args_node)) {uint32_t argc = ts_node_named_child_count(args_node);int pi = 0;- for (uint32_t ai = 0; ai < argc && func_type->data.func.param_types[pi]; ai++) {+ for (uint32_t ai = 0; ai < argc && func_type->data.func.param_types[pi];+ ai++) {TSNode arg = ts_node_named_child(args_node, ai);- if (ts_node_is_null(arg)) continue;- const CBMType* arg_type = go_eval_expr_type(ctx, arg);- go_unify_type(func_type->data.func.param_types[pi],- arg_type, rfunc->type_param_names, inferred, tpc);+ if (ts_node_is_null(arg))+ continue;+ const CBMType *arg_type = go_eval_expr_type(ctx, arg);+ go_unify_type(func_type->data.func.param_types[pi], arg_type,+ rfunc->type_param_names, inferred, tpc);pi++;}}@@ -570,25 +615,29 @@ const CBMType* go_eval_expr_type(GoLSPContext* ctx, TSNode node) {// Check if all type params were inferredbool all_inferred = true;for (int i = 0; i < tpc; i++) {- if (!inferred[i]) { all_inferred = false; break; }+ if (!inferred[i]) {+ all_inferred = false;+ break;+ }}if (all_inferred) {- const CBMType** targ_arr = (const CBMType**)cbm_arena_alloc(- ctx->arena, (tpc + 1) * sizeof(const CBMType*));- for (int i = 0; i < tpc; i++) targ_arr[i] = inferred[i];+ const CBMType **targ_arr = (const CBMType **)cbm_arena_alloc(+ ctx->arena, (tpc + 1) * sizeof(const CBMType *));+ for (int i = 0; i < tpc; i++)+ targ_arr[i] = inferred[i];targ_arr[tpc] = NULL;if (ret_count == 1) {return cbm_type_substitute(ctx->arena,- func_type->data.func.return_types[0],- rfunc->type_param_names, targ_arr);+ func_type->data.func.return_types[0],+ rfunc->type_param_names, targ_arr);}- const CBMType** new_rets = (const CBMType**)cbm_arena_alloc(- ctx->arena, (ret_count + 1) * sizeof(const CBMType*));+ const CBMType **new_rets = (const CBMType **)cbm_arena_alloc(+ ctx->arena, (ret_count + 1) * sizeof(const CBMType *));for (int ri = 0; ri < ret_count; ri++) {- new_rets[ri] = cbm_type_substitute(ctx->arena,- func_type->data.func.return_types[ri],+ new_rets[ri] = cbm_type_substitute(+ ctx->arena, func_type->data.func.return_types[ri],rfunc->type_param_names, targ_arr);}new_rets[ret_count] = NULL;@@ -603,7 +652,8 @@ const CBMType* go_eval_expr_type(GoLSPContext* ctx, TSNode node) {return func_type->data.func.return_types[0];}int count = 0;- while (func_type->data.func.return_types[count]) count++;+ while (func_type->data.func.return_types[count])+ count++;if (count > 1) {return cbm_type_tuple(ctx->arena, func_type->data.func.return_types, count);}@@ -617,7 +667,7 @@ const CBMType* go_eval_expr_type(GoLSPContext* ctx, TSNode node) {// Type conversion with composite type syntax: []byte(s), map[K]V(x), etc.// The function node is a type node (slice_type, map_type, etc.){- const char* fk = ts_node_type(func_node);+ const char *fk = ts_node_type(func_node);if (strcmp(fk, "slice_type") == 0 || strcmp(fk, "array_type") == 0 ||strcmp(fk, "map_type") == 0 || strcmp(fk, "pointer_type") == 0 ||strcmp(fk, "channel_type") == 0) {@@ -640,14 +690,16 @@ const CBMType* go_eval_expr_type(GoLSPContext* ctx, TSNode node) {// --- Unary expression: &x, *x, <-ch, !x ---if (strcmp(kind, "unary_expression") == 0) {TSNode operand = ts_node_child_by_field_name(node, "operand", 7);- if (ts_node_is_null(operand)) return cbm_type_unknown();+ if (ts_node_is_null(operand))+ return cbm_type_unknown();// Get operatorfor (uint32_t i = 0; i < ts_node_child_count(node); i++) {TSNode child = ts_node_child(node, i);if (!ts_node_is_named(child)) {- char* op = lsp_node_text(ctx, child);- if (!op) continue;+ char *op = lsp_node_text(ctx, child);+ if (!op)+ continue;if (strcmp(op, "&") == 0) {return cbm_type_pointer(ctx->arena, go_eval_expr_type(ctx, operand));}@@ -655,7 +707,7 @@ const CBMType* go_eval_expr_type(GoLSPContext* ctx, TSNode node) {return cbm_type_deref(go_eval_expr_type(ctx, operand));}if (strcmp(op, "<-") == 0) {- const CBMType* ch_type = go_eval_expr_type(ctx, operand);+ const CBMType *ch_type = go_eval_expr_type(ctx, operand);if (ch_type && ch_type->kind == CBM_TYPE_CHANNEL) {return ch_type->data.channel.elem;}@@ -673,11 +725,15 @@ const CBMType* go_eval_expr_type(GoLSPContext* ctx, TSNode node) {// --- Index expression: a[i] ---if (strcmp(kind, "index_expression") == 0) {TSNode operand = ts_node_child_by_field_name(node, "operand", 7);- if (ts_node_is_null(operand)) return cbm_type_unknown();- const CBMType* op_type = go_eval_expr_type(ctx, operand);- if (!op_type) return cbm_type_unknown();- if (op_type->kind == CBM_TYPE_MAP) return op_type->data.map.value;- if (op_type->kind == CBM_TYPE_SLICE) return op_type->data.slice.elem;+ if (ts_node_is_null(operand))+ return cbm_type_unknown();+ const CBMType *op_type = go_eval_expr_type(ctx, operand);+ if (!op_type)+ return cbm_type_unknown();+ if (op_type->kind == CBM_TYPE_MAP)+ return op_type->data.map.value;+ if (op_type->kind == CBM_TYPE_SLICE)+ return op_type->data.slice.elem;return cbm_type_unknown();}@@ -703,24 +759,25 @@ const CBMType* go_eval_expr_type(GoLSPContext* ctx, TSNode node) {for (uint32_t i = 0; i < ts_node_child_count(node); i++) {TSNode child = ts_node_child(node, i);if (!ts_node_is_named(child)) {- char* op = lsp_node_text(ctx, child);- if (op && (strcmp(op, "==") == 0 || strcmp(op, "!=") == 0 ||- strcmp(op, "<") == 0 || strcmp(op, ">") == 0 ||- strcmp(op, "<=") == 0 || strcmp(op, ">=") == 0 ||+ char *op = lsp_node_text(ctx, child);+ if (op && (strcmp(op, "==") == 0 || strcmp(op, "!=") == 0 || strcmp(op, "<") == 0 ||+ strcmp(op, ">") == 0 || strcmp(op, "<=") == 0 || strcmp(op, ">=") == 0 ||strcmp(op, "&&") == 0 || strcmp(op, "||") == 0)) {return cbm_type_builtin(ctx->arena, "bool");}break;}}- if (!ts_node_is_null(left)) return go_eval_expr_type(ctx, left);+ if (!ts_node_is_null(left))+ return go_eval_expr_type(ctx, left);return cbm_type_unknown();}// --- Slice expression: a[low:high] ---if (strcmp(kind, "slice_expression") == 0) {TSNode operand = ts_node_child_by_field_name(node, "operand", 7);- if (!ts_node_is_null(operand)) return go_eval_expr_type(ctx, operand);+ if (!ts_node_is_null(operand))+ return go_eval_expr_type(ctx, operand);return cbm_type_unknown();}@@ -748,7 +805,7 @@ const CBMType* go_eval_expr_type(GoLSPContext* ctx, TSNode node) {TSNode body = ts_node_child_by_field_name(node, "body", 4);if (!ts_node_is_null(body)) {// Push child scope (inherits all outer bindings via parent chain)- CBMScope* saved = ctx->current_scope;+ CBMScope *saved = ctx->current_scope;ctx->current_scope = cbm_scope_push(ctx->arena, ctx->current_scope);// Bind closure parameters@@ -757,16 +814,18 @@ const CBMType* go_eval_expr_type(GoLSPContext* ctx, TSNode node) {uint32_t nc = ts_node_child_count(params);for (uint32_t i = 0; i < nc; i++) {TSNode param = ts_node_child(params, i);- if (ts_node_is_null(param) || !ts_node_is_named(param)) continue;- if (strcmp(ts_node_type(param), "parameter_declaration") != 0) continue;+ if (ts_node_is_null(param) || !ts_node_is_named(param))+ continue;+ if (strcmp(ts_node_type(param), "parameter_declaration") != 0)+ continue;TSNode type_node = ts_node_child_by_field_name(param, "type", 4);- const CBMType* pt = go_parse_type_node(ctx, type_node);+ const CBMType *pt = go_parse_type_node(ctx, type_node);uint32_t pnc = ts_node_child_count(param);for (uint32_t j = 0; j < pnc; j++) {TSNode ch = ts_node_child(param, j);if (!ts_node_is_null(ch) && ts_node_is_named(ch) &&strcmp(ts_node_type(ch), "identifier") == 0) {- char* pname = lsp_node_text(ctx, ch);+ char *pname = lsp_node_text(ctx, ch);if (pname && strcmp(pname, "_") != 0)cbm_scope_bind(ctx->current_scope, pname, pt);}@@ -781,15 +840,17 @@ const CBMType* go_eval_expr_type(GoLSPContext* ctx, TSNode node) {}// Build full FUNC type with param/return types from AST- const CBMType* pt_arr[16];+ const CBMType *pt_arr[16];int pt_count = 0;TSNode params2 = ts_node_child_by_field_name(node, "parameters", 10);if (!ts_node_is_null(params2)) {uint32_t nc2 = ts_node_child_count(params2);for (uint32_t i = 0; i < nc2 && pt_count < 15; i++) {TSNode p = ts_node_child(params2, i);- if (ts_node_is_null(p) || !ts_node_is_named(p)) continue;- if (strcmp(ts_node_type(p), "parameter_declaration") != 0) continue;+ if (ts_node_is_null(p) || !ts_node_is_named(p))+ continue;+ if (strcmp(ts_node_type(p), "parameter_declaration") != 0)+ continue;TSNode pt = ts_node_child_by_field_name(p, "type", 4);if (!ts_node_is_null(pt))pt_arr[pt_count++] = go_parse_type_node(ctx, pt);@@ -797,7 +858,7 @@ const CBMType* go_eval_expr_type(GoLSPContext* ctx, TSNode node) {}pt_arr[pt_count] = NULL;- const CBMType* rt_arr[16];+ const CBMType *rt_arr[16];int rt_count = 0;TSNode result = ts_node_child_by_field_name(node, "result", 6);if (!ts_node_is_null(result)) {@@ -805,9 +866,11 @@ const CBMType* go_eval_expr_type(GoLSPContext* ctx, TSNode node) {uint32_t rnc = ts_node_child_count(result);for (uint32_t i = 0; i < rnc && rt_count < 15; i++) {TSNode rc = ts_node_child(result, i);- if (ts_node_is_null(rc) || !ts_node_is_named(rc)) continue;+ if (ts_node_is_null(rc) || !ts_node_is_named(rc))+ continue;TSNode rt = ts_node_child_by_field_name(rc, "type", 4);- if (ts_node_is_null(rt)) rt = rc;+ if (ts_node_is_null(rt))+ rt = rc;rt_arr[rt_count++] = go_parse_type_node(ctx, rt);}} else {@@ -816,9 +879,8 @@ const CBMType* go_eval_expr_type(GoLSPContext* ctx, TSNode node) {}rt_arr[rt_count] = NULL;- return cbm_type_func(ctx->arena, NULL,- pt_count > 0 ? (const CBMType**)pt_arr : NULL,- rt_count > 0 ? (const CBMType**)rt_arr : NULL);+ return cbm_type_func(ctx->arena, NULL, pt_count > 0 ? (const CBMType **)pt_arr : NULL,+ rt_count > 0 ? (const CBMType **)rt_arr : NULL);}return cbm_type_unknown();@@ -826,7 +888,7 @@ const CBMType* go_eval_expr_type(GoLSPContext* ctx, TSNode node) {// --- go_eval_builtin_call ----const CBMType* go_eval_builtin_call(GoLSPContext* ctx, const char* name, TSNode args) {+const CBMType *go_eval_builtin_call(GoLSPContext *ctx, const char *name, TSNode args) {// make(Type, ...) -> Typeif (strcmp(name, "make") == 0 && !ts_node_is_null(args)) {uint32_t nc = ts_node_named_child_count(args);@@ -879,17 +941,20 @@ const CBMType* go_eval_builtin_call(GoLSPContext* ctx, const char* name, TSNode// the file's imports; returns NULL when no alias segment is involved.static const char *go_requalify_via_imports(GoLSPContext *ctx, const char *type_qn) {- if (!ctx || !type_qn || !type_qn[0] || ctx->import_count <= 0) return NULL;+ if (!ctx || !type_qn || !type_qn[0] || ctx->import_count <= 0)+ return NULL;for (int j = 0; j < ctx->import_count; j++) {const char *alias = ctx->import_local_names[j];const char *alias_qn = ctx->import_package_qns[j];- if (!alias || !alias[0] || !alias_qn || strchr(alias, '.')) continue;+ if (!alias || !alias[0] || !alias_qn || strchr(alias, '.'))+ continue;size_t alias_len = strlen(alias);/* Last occurrence of a "<dot>alias<dot>" segment in type_qn. */const char *hit = NULL;for (const char *p = type_qn;;) {p = strstr(p, ".");- if (!p) break;+ if (!p)+ break;p++;if (strncmp(p, alias, alias_len) == 0 && p[alias_len] == '.') {hit = p;@@ -904,26 +969,31 @@ static const char *go_requalify_via_imports(GoLSPContext *ctx, const char *type_return NULL;}-static const CBMType* go_lookup_field(GoLSPContext* ctx,- const char* type_qn, const char* field_name, int depth) {- if (!type_qn || !field_name || depth > 5) return NULL;+static const CBMType *go_lookup_field(GoLSPContext *ctx, const char *type_qn,+ const char *field_name, int depth) {+ if (!type_qn || !field_name || depth > 5)+ return NULL;- const CBMRegisteredType* rt = cbm_registry_lookup_type(ctx->registry, type_qn);+ const CBMRegisteredType *rt = cbm_registry_lookup_type(ctx->registry, type_qn);if (!rt && depth == 0) {/* Import-alias re-qualification: field texts from cross-package defs* may embed an alias segment only this file's import map resolves. */- const char* alt_qn = go_requalify_via_imports(ctx, type_qn);- if (alt_qn) rt = cbm_registry_lookup_type(ctx->registry, alt_qn);+ const char *alt_qn = go_requalify_via_imports(ctx, type_qn);+ if (alt_qn)+ rt = cbm_registry_lookup_type(ctx->registry, alt_qn);}- if (!rt) return NULL;+ if (!rt)+ return NULL;// Follow alias chain- if (rt->alias_of) return go_lookup_field(ctx, rt->alias_of, field_name, depth + 1);+ if (rt->alias_of)+ return go_lookup_field(ctx, rt->alias_of, field_name, depth + 1);// Direct field lookupif (rt->field_names) {for (int i = 0; rt->field_names[i]; i++) {- if (strcmp(rt->field_names[i], field_name) == 0 && rt->field_types && rt->field_types[i]) {+ if (strcmp(rt->field_names[i], field_name) == 0 && rt->field_types &&+ rt->field_types[i]) {return rt->field_types[i];}}@@ -932,8 +1002,9 @@ static const CBMType* go_lookup_field(GoLSPContext* ctx,// Promoted fields from embedded typesif (rt->embedded_types) {for (int i = 0; rt->embedded_types[i]; i++) {- const CBMType* f = go_lookup_field(ctx, rt->embedded_types[i], field_name, depth + 1);- if (f) return f;+ const CBMType *f = go_lookup_field(ctx, rt->embedded_types[i], field_name, depth + 1);+ if (f)+ return f;}}@@ -942,40 +1013,49 @@ static const CBMType* go_lookup_field(GoLSPContext* ctx,// --- go_lookup_field_or_method: method sets + embedding ----static const CBMRegisteredFunc* go_lookup_field_or_method_depth(GoLSPContext* ctx,- const char* type_qn, const char* member_name, int depth) {- if (!type_qn || !member_name) return NULL;- if (depth > CBM_LSP_MAX_LOOKUP_DEPTH) return NULL;+static const CBMRegisteredFunc *go_lookup_field_or_method_depth(GoLSPContext *ctx,+ const char *type_qn,+ const char *member_name,+ int depth) {+ if (!type_qn || !member_name)+ return NULL;+ if (depth > CBM_LSP_MAX_LOOKUP_DEPTH)+ return NULL;// Direct method lookup- const CBMRegisteredFunc* f = cbm_registry_lookup_method(ctx->registry, type_qn, member_name);- if (f) return f;+ const CBMRegisteredFunc *f = cbm_registry_lookup_method(ctx->registry, type_qn, member_name);+ if (f)+ return f;/* Import-alias re-qualification fallback: NAMED receivers built from* cross-package field type texts can carry a "<module>.svc.Svc" QN;* retry the method set on the import-resolved QN (see* go_requalify_via_imports). */if (depth == 0) {- const char* alt_qn = go_requalify_via_imports(ctx, type_qn);+ const char *alt_qn = go_requalify_via_imports(ctx, type_qn);if (alt_qn) {f = go_lookup_field_or_method_depth(ctx, alt_qn, member_name, depth + 1);- if (f) return f;+ if (f)+ return f;}}- const CBMRegisteredType* rt = cbm_registry_lookup_type(ctx->registry, type_qn);+ const CBMRegisteredType *rt = cbm_registry_lookup_type(ctx->registry, type_qn);if (rt) {// Follow type alias chainif (rt->alias_of) {f = go_lookup_field_or_method_depth(ctx, rt->alias_of, member_name, depth + 1);- if (f) return f;+ if (f)+ return f;}// Check embedded types (promoted methods)if (rt->embedded_types) {for (int i = 0; rt->embedded_types[i]; i++) {- f = go_lookup_field_or_method_depth(ctx, rt->embedded_types[i], member_name, depth + 1);- if (f) return f;+ f = go_lookup_field_or_method_depth(ctx, rt->embedded_types[i], member_name,+ depth + 1);+ if (f)+ return f;}}}@@ -983,8 +1063,8 @@ static const CBMRegisteredFunc* go_lookup_field_or_method_depth(GoLSPContext* ctreturn NULL;}-const CBMRegisteredFunc* go_lookup_field_or_method(GoLSPContext* ctx,- const char* type_qn, const char* member_name) {+const CBMRegisteredFunc *go_lookup_field_or_method(GoLSPContext *ctx, const char *type_qn,+ const char *member_name) {return go_lookup_field_or_method_depth(ctx, type_qn, member_name, 0);}@@ -1060,17 +1140,19 @@ static void go_scope_bind_value(GoLSPContext *ctx, const char *name, const CBMTy// --- go_process_statement: bind variables from statements ----void go_process_statement(GoLSPContext* ctx, TSNode node) {- if (ts_node_is_null(node)) return;- const char* kind = ts_node_type(node);+void go_process_statement(GoLSPContext *ctx, TSNode node) {+ if (ts_node_is_null(node))+ return;+ const char *kind = ts_node_type(node);// short_var_declaration: a, b := exprif (strcmp(kind, "short_var_declaration") == 0) {TSNode left = ts_node_child_by_field_name(node, "left", 4);TSNode right = ts_node_child_by_field_name(node, "right", 5);- if (ts_node_is_null(left) || ts_node_is_null(right)) return;+ if (ts_node_is_null(left) || ts_node_is_null(right))+ return;- const CBMType* rhs_type = NULL;+ const CBMType *rhs_type = NULL;TSNode single_rhs = {0};// Check if RHS is an expression_list (multiple values)@@ -1093,11 +1175,13 @@ void go_process_statement(GoLSPContext* ctx, TSNode node) {uint32_t lhs_count = ts_node_named_child_count(left);for (uint32_t i = 0; i < lhs_count; i++) {TSNode lhs_var = ts_node_named_child(left, i);- if (strcmp(ts_node_type(lhs_var), "identifier") != 0) continue;- char* var_name = lsp_node_text(ctx, lhs_var);- if (!var_name || strcmp(var_name, "_") == 0) continue;+ if (strcmp(ts_node_type(lhs_var), "identifier") != 0)+ continue;+ char *var_name = lsp_node_text(ctx, lhs_var);+ if (!var_name || strcmp(var_name, "_") == 0)+ continue;- const CBMType* var_type = cbm_type_unknown();+ const CBMType *var_type = cbm_type_unknown();if (rhs_type) {if (rhs_type->kind == CBM_TYPE_TUPLE && (int)i < rhs_type->data.tuple.count) {var_type = rhs_type->data.tuple.elems[i];@@ -1108,7 +1192,7 @@ void go_process_statement(GoLSPContext* ctx, TSNode node) {go_scope_bind_value(ctx, var_name, var_type, i == 0 ? rhs_callable : NULL);}} else if (strcmp(ts_node_type(left), "identifier") == 0) {- char* var_name = lsp_node_text(ctx, left);+ char *var_name = lsp_node_text(ctx, left);if (var_name && strcmp(var_name, "_") != 0 && rhs_type) {go_scope_bind_value(ctx, var_name, rhs_type, rhs_callable);}@@ -1158,7 +1242,7 @@ void go_process_statement(GoLSPContext* ctx, TSNode node) {TSNode type_node = ts_node_child_by_field_name(node, "type", 4);TSNode value_node = ts_node_child_by_field_name(node, "value", 5);- const CBMType* var_type = cbm_type_unknown();+ const CBMType *var_type = cbm_type_unknown();TSNode callable_value = value_node;if (!ts_node_is_null(value_node) &&strcmp(ts_node_type(value_node), "expression_list") == 0) {@@ -1183,9 +1267,10 @@ void go_process_statement(GoLSPContext* ctx, TSNode node) {uint32_t vnc = ts_node_child_count(node);for (uint32_t vi = 0; vi < vnc; vi++) {TSNode ch = ts_node_child(node, vi);- if (ts_node_is_null(ch) || !ts_node_is_named(ch)) continue;+ if (ts_node_is_null(ch) || !ts_node_is_named(ch))+ continue;if (strcmp(ts_node_type(ch), "identifier") == 0) {- char* var_name = lsp_node_text(ctx, ch);+ char *var_name = lsp_node_text(ctx, ch);if (var_name && strcmp(var_name, "_") != 0) {go_scope_bind_value(ctx, var_name, var_type, callable_qn);}@@ -1199,9 +1284,10 @@ void go_process_statement(GoLSPContext* ctx, TSNode node) {TSNode name_node = ts_node_child_by_field_name(node, "name", 4);TSNode type_node = ts_node_child_by_field_name(node, "type", 4);TSNode value_node = ts_node_child_by_field_name(node, "value", 5);- if (ts_node_is_null(name_node)) return;+ if (ts_node_is_null(name_node))+ return;- const CBMType* const_type = cbm_type_unknown();+ const CBMType *const_type = cbm_type_unknown();TSNode callable_value = value_node;if (!ts_node_is_null(value_node) &&strcmp(ts_node_type(value_node), "expression_list") == 0) {@@ -1224,7 +1310,7 @@ void go_process_statement(GoLSPContext* ctx, TSNode node) {ts_node_is_null(callable_value) ? NULL : go_exact_callable_target(ctx, callable_value);if (strcmp(ts_node_type(name_node), "identifier") == 0) {- char* name = lsp_node_text(ctx, name_node);+ char *name = lsp_node_text(ctx, name_node);if (name && strcmp(name, "_") != 0)go_scope_bind_value(ctx, name, const_type, callable_qn);}@@ -1235,13 +1321,14 @@ void go_process_statement(GoLSPContext* ctx, TSNode node) {if (strcmp(kind, "range_clause") == 0) {TSNode left = ts_node_child_by_field_name(node, "left", 4);TSNode right = ts_node_child_by_field_name(node, "right", 5);- if (ts_node_is_null(right)) return;+ if (ts_node_is_null(right))+ return;- const CBMType* container_type = go_eval_expr_type(ctx, right);+ const CBMType *container_type = go_eval_expr_type(ctx, right);// Determine key and value types based on container type- const CBMType* key_type = cbm_type_unknown();- const CBMType* val_type = cbm_type_unknown();+ const CBMType *key_type = cbm_type_unknown();+ const CBMType *val_type = cbm_type_unknown();if (container_type) {switch (container_type->kind) {@@ -1270,9 +1357,11 @@ void go_process_statement(GoLSPContext* ctx, TSNode node) {uint32_t lhs_count = ts_node_named_child_count(left);for (uint32_t i = 0; i < lhs_count; i++) {TSNode var_node = ts_node_named_child(left, i);- if (strcmp(ts_node_type(var_node), "identifier") != 0) continue;- char* var_name = lsp_node_text(ctx, var_node);- if (!var_name || strcmp(var_name, "_") == 0) continue;+ if (strcmp(ts_node_type(var_node), "identifier") != 0)+ continue;+ char *var_name = lsp_node_text(ctx, var_node);+ if (!var_name || strcmp(var_name, "_") == 0)+ continue;cbm_scope_bind(ctx->current_scope, var_name, i == 0 ? key_type : val_type);}}@@ -1288,7 +1377,8 @@ void go_process_statement(GoLSPContext* ctx, TSNode node) {static void go_emit_resolved_kind(GoLSPContext *ctx, const char *callee_qn, const char *strategy,float confidence, const char *source_name, CBMResolvedKind kind,TSNode site) {- if (!ctx->resolved_calls || !callee_qn || !ctx->enclosing_func_qn) return;+ if (!ctx->resolved_calls || !callee_qn || !ctx->enclosing_func_qn)+ return;CBMResolvedCall rc = {0};rc.caller_qn = ctx->enclosing_func_qn;@@ -1347,7 +1437,8 @@ static void emit_unresolved_reference(GoLSPContext *ctx, const char *source_name// Emit a diagnostic for an unresolved call (confidence 0.0).static void emit_unresolved_call(GoLSPContext *ctx, const char *expr_text, const char *reason,TSNode site) {- if (!ctx->resolved_calls || !ctx->enclosing_func_qn) return;+ if (!ctx->resolved_calls || !ctx->enclosing_func_qn)+ return;CBMResolvedCall rc = {0};rc.caller_qn = ctx->enclosing_func_qn;@@ -1430,9 +1521,10 @@ static void go_invalidate_control_flow_aliases(GoLSPContext *ctx, TSNode node, i// --- Walk call expressions and resolve them ----static void resolve_calls_in_node_inner(GoLSPContext* ctx, TSNode node) {- if (ts_node_is_null(node)) return;- const char* kind = ts_node_type(node);+static void resolve_calls_in_node_inner(GoLSPContext *ctx, TSNode node) {+ if (ts_node_is_null(node))+ return;+ const char *kind = ts_node_type(node);// Process statements to build scopego_process_statement(ctx, node);@@ -1448,22 +1540,23 @@ static void resolve_calls_in_node_inner(GoLSPContext* ctx, TSNode node) {go_resolve_value_references_at(ctx, node);TSNode func_node = ts_node_child_by_field_name(node, "function", 8);if (!ts_node_is_null(func_node)) {- const char* fk = ts_node_type(func_node);+ const char *fk = ts_node_type(func_node);// selector_expression: obj.Method() or pkg.Func()if (strcmp(fk, "selector_expression") == 0) {TSNode operand = ts_node_child_by_field_name(func_node, "operand", 7);TSNode field = ts_node_child_by_field_name(func_node, "field", 5);if (!ts_node_is_null(operand) && !ts_node_is_null(field)) {- char* field_name = lsp_node_text(ctx, field);+ char *field_name = lsp_node_text(ctx, field);// Check if operand is a package importif (strcmp(ts_node_type(operand), "identifier") == 0) {- char* pkg_name = lsp_node_text(ctx, operand);+ char *pkg_name = lsp_node_text(ctx, operand);if (pkg_name) {- const char* pkg_qn = resolve_import(ctx, pkg_name);+ const char *pkg_qn = resolve_import(ctx, pkg_name);if (pkg_qn && field_name) {- const CBMRegisteredFunc* f = cbm_registry_lookup_symbol(ctx->registry, pkg_qn, field_name);+ const CBMRegisteredFunc *f =+ cbm_registry_lookup_symbol(ctx->registry, pkg_qn, field_name);if (f) {emit_resolved_call(ctx, f->qualified_name, "lsp_direct", 0.95f,node);@@ -1481,14 +1574,15 @@ static void resolve_calls_in_node_inner(GoLSPContext* ctx, TSNode node) {// Type-based method dispatchif (field_name) {- const CBMType* recv_type = go_eval_expr_type(ctx, operand);- const CBMType* base = recv_type;- if (base && base->kind == CBM_TYPE_POINTER) base = cbm_type_deref(base);+ const CBMType *recv_type = go_eval_expr_type(ctx, operand);+ const CBMType *base = recv_type;+ if (base && base->kind == CBM_TYPE_POINTER)+ base = cbm_type_deref(base);if (base && base->kind == CBM_TYPE_NAMED) {const char *recv_qn = base->data.named.qualified_name;- const CBMRegisteredType *receiver_type = cbm_registry_lookup_type(- ctx->registry, recv_qn);+ const CBMRegisteredType *receiver_type =+ cbm_registry_lookup_type(ctx->registry, recv_qn);const char *alt_qn = NULL;/* Re-qualify NAMED receivers that embed an import* alias segment (cross-package field type texts) —@@ -1497,7 +1591,8 @@ static void resolve_calls_in_node_inner(GoLSPContext* ctx, TSNode node) {alt_qn = go_requalify_via_imports(ctx, recv_qn);if (alt_qn) {receiver_type = cbm_registry_lookup_type(ctx->registry, alt_qn);- if (receiver_type) recv_qn = alt_qn;+ if (receiver_type)+ recv_qn = alt_qn;}}/* Registered interface receivers must reach the@@ -1505,13 +1600,12 @@ static void resolve_calls_in_node_inner(GoLSPContext* ctx, TSNode node) {* method registrations are signatures, not concrete* dispatch targets. */if (!receiver_type || !receiver_type->is_interface) {- const CBMRegisteredFunc *method = go_lookup_field_or_method(- ctx, recv_qn, field_name);+ const CBMRegisteredFunc *method =+ go_lookup_field_or_method(ctx, recv_qn, field_name);if (method) {const char *strategy = "lsp_type_dispatch";if (method->receiver_type &&- strcmp(method->receiver_type,- recv_qn) != 0) {+ strcmp(method->receiver_type, recv_qn) != 0) {strategy = "lsp_embed_dispatch";}emit_resolved_call(ctx, method->qualified_name, strategy, 0.95f,@@ -1521,15 +1615,16 @@ static void resolve_calls_in_node_inner(GoLSPContext* ctx, TSNode node) {}}- // Interface dispatch: NAMED type that is an interface, or bare INTERFACE type+ // Interface dispatch: NAMED type that is an interface, or bare INTERFACE+ // typeif (base && field_name) {bool is_iface = (base->kind == CBM_TYPE_INTERFACE);- const char* iface_qn = NULL;+ const char *iface_qn = NULL;if (!is_iface && base->kind == CBM_TYPE_NAMED) {- const CBMRegisteredType* rt = cbm_registry_lookup_type(ctx->registry,- base->data.named.qualified_name);+ const CBMRegisteredType *rt = cbm_registry_lookup_type(+ ctx->registry, base->data.named.qualified_name);if (!rt) {- const char* alt_qn = go_requalify_via_imports(+ const char *alt_qn = go_requalify_via_imports(ctx, base->data.named.qualified_name);if (alt_qn)rt = cbm_registry_lookup_type(ctx->registry, alt_qn);@@ -1540,34 +1635,47 @@ static void resolve_calls_in_node_inner(GoLSPContext* ctx, TSNode node) {}}if (is_iface) {- // Try interface satisfaction: find concrete types implementing this interface- const CBMRegisteredType* iface_rt = iface_qn ?- cbm_registry_lookup_type(ctx->registry, iface_qn) : NULL;- if (iface_rt && iface_rt->method_names && iface_rt->method_names[0]) {+ // Try interface satisfaction: find concrete types implementing this+ // interface+ const CBMRegisteredType *iface_rt =+ iface_qn ? cbm_registry_lookup_type(ctx->registry, iface_qn)+ : NULL;+ if (iface_rt && iface_rt->method_names &&+ iface_rt->method_names[0]) {// Count interface methodsint iface_mcount = 0;- while (iface_rt->method_names[iface_mcount]) iface_mcount++;+ while (iface_rt->method_names[iface_mcount])+ iface_mcount++;// Scan all registered types for satisfaction- const char* sole_impl_qn = NULL;+ const char *sole_impl_qn = NULL;int impl_count = 0;// Skip stdlib types when interface is from a project package- bool iface_is_project = iface_qn && strchr(iface_qn, '/') != NULL;+ bool iface_is_project =+ iface_qn && strchr(iface_qn, '/') != NULL;CBMTypeShortIter all_types;cbm_registry_all_types_chain(ctx->registry, &all_types);- for (int ti = -1; impl_count < 2 && (ti = cbm_type_short_iter_next(&all_types)) >= 0;) {- const CBMRegisteredType* cand = &all_types.reg->types[ti];- if (cand->is_interface) continue;- if (!cand->qualified_name) continue;- if (cand->alias_of) continue;- // For project interfaces, skip stdlib candidates (no '/' in QN)- if (iface_is_project && !strchr(cand->qualified_name, '/')) continue;+ for (int ti = -1;+ impl_count < 2 &&+ (ti = cbm_type_short_iter_next(&all_types)) >= 0;) {+ const CBMRegisteredType *cand = &all_types.reg->types[ti];+ if (cand->is_interface)+ continue;+ if (!cand->qualified_name)+ continue;+ if (cand->alias_of)+ continue;+ // For project interfaces, skip stdlib candidates (no '/' in+ // QN)+ if (iface_is_project && !strchr(cand->qualified_name, '/'))+ continue;// Check if candidate has all interface methodsbool satisfies = true;for (int mi = 0; mi < iface_mcount; mi++) {- if (!cbm_registry_lookup_method(ctx->registry,- cand->qualified_name, iface_rt->method_names[mi])) {+ if (!cbm_registry_lookup_method(+ ctx->registry, cand->qualified_name,+ iface_rt->method_names[mi])) {satisfies = false;break;}@@ -1580,14 +1688,15 @@ static void resolve_calls_in_node_inner(GoLSPContext* ctx, TSNode node) {if (impl_count == 1 && sole_impl_qn) {// Single implementer: resolve to concrete method- const CBMRegisteredFunc* concrete_method =- cbm_registry_lookup_method(ctx->registry, sole_impl_qn, field_name);+ const CBMRegisteredFunc *concrete_method =+ cbm_registry_lookup_method(ctx->registry, sole_impl_qn,+ field_name);if (concrete_method) {// Sole-implementer interface dispatch is an unambiguous- // resolution (exactly one concrete method); rank it at least- // as high as a direct type dispatch (0.95) so the concrete- // `Type.method` wins over the interface-method type_dispatch- // for the same call site.+ // resolution (exactly one concrete method); rank it at+ // least as high as a direct type dispatch (0.95) so the+ // concrete `Type.method` wins over the interface-method+ // type_dispatch for the same call site.emit_resolved_call(ctx, concrete_method->qualified_name,"lsp_interface_resolve", 0.95f,node);@@ -1615,7 +1724,7 @@ static void resolve_calls_in_node_inner(GoLSPContext* ctx, TSNode node) {field_name),"method_not_found", node);} else if (cbm_type_is_unknown(recv_type)) {- char* operand_text = lsp_node_text(ctx, operand);+ char *operand_text = lsp_node_text(ctx, operand);emit_unresolved_call(ctx,cbm_arena_sprintf(ctx->arena, "%s.%s",@@ -1628,7 +1737,7 @@ static void resolve_calls_in_node_inner(GoLSPContext* ctx, TSNode node) {// Direct function call: FuncName()if (strcmp(fk, "identifier") == 0) {- char* name = lsp_node_text(ctx, func_node);+ char *name = lsp_node_text(ctx, func_node);if (name && !is_go_builtin_func(name)) {if (cbm_scope_contains(ctx->current_scope, name)) {const char *alias_target =@@ -1642,7 +1751,8 @@ static void resolve_calls_in_node_inner(GoLSPContext* ctx, TSNode node) {goto recurse;}// Package-local function- const CBMRegisteredFunc* f = cbm_registry_lookup_symbol(ctx->registry, ctx->package_qn, name);+ const CBMRegisteredFunc *f =+ cbm_registry_lookup_symbol(ctx->registry, ctx->package_qn, name);if (f) {emit_resolved_call(ctx, f->qualified_name, "lsp_direct", 0.95f, node);} else {@@ -1655,18 +1765,16 @@ static void resolve_calls_in_node_inner(GoLSPContext* ctx, TSNode node) {recurse:;// Push scope for blocks and statements that introduce variables- bool push_scope = (strcmp(kind, "block") == 0 ||- strcmp(kind, "if_statement") == 0 ||- strcmp(kind, "for_statement") == 0 ||- strcmp(kind, "expression_switch_statement") == 0);+ bool push_scope =+ (strcmp(kind, "block") == 0 || strcmp(kind, "if_statement") == 0 ||+ strcmp(kind, "for_statement") == 0 || strcmp(kind, "expression_switch_statement") == 0);if (push_scope) {ctx->current_scope = cbm_scope_push(ctx->arena, ctx->current_scope);}// Process initializer field for if/for/switch statements.// Go patterns: if err := f(); ..., for i := 0; ..., switch v := x; v { ... }- if (strcmp(kind, "if_statement") == 0 ||- strcmp(kind, "for_statement") == 0 ||+ if (strcmp(kind, "if_statement") == 0 || strcmp(kind, "for_statement") == 0 ||strcmp(kind, "expression_switch_statement") == 0) {TSNode init = ts_node_child_by_field_name(node, "initializer", 11);if (!ts_node_is_null(init)) {@@ -1692,14 +1800,15 @@ recurse:;// identifier (operand "animal")// type_case (case clause, may repeat)if (strcmp(kind, "type_switch_statement") == 0) {- const char* switch_var = NULL;+ const char *switch_var = NULL;// Pass 1: find switch variable and operand typeuint32_t nc2 = ts_node_child_count(node);bool found_assign = false;for (uint32_t i = 0; i < nc2; i++) {TSNode child = ts_node_child(node, i);- if (ts_node_is_null(child)) continue;- const char* ck = ts_node_type(child);+ if (ts_node_is_null(child))+ continue;+ const char *ck = ts_node_type(child);// expression_list before := is the LHS (variable name)if (!found_assign && strcmp(ck, "expression_list") == 0) {@@ -1709,8 +1818,9 @@ recurse:;}// := operator marks the assignmentif (!ts_node_is_named(child)) {- char* tok = lsp_node_text(ctx, child);- if (tok && strcmp(tok, ":=") == 0) found_assign = true;+ char *tok = lsp_node_text(ctx, child);+ if (tok && strcmp(tok, ":=") == 0)+ found_assign = true;}// identifier after := is the operand being type-switchedif (found_assign && strcmp(ck, "identifier") == 0) {@@ -1721,25 +1831,27 @@ recurse:;// Pass 2: process each type_case with narrowed scopefor (uint32_t i = 0; i < nc2; i++) {TSNode child = ts_node_child(node, i);- if (ts_node_is_null(child) || !ts_node_is_named(child)) continue;- if (strcmp(ts_node_type(child), "type_case") != 0) continue;+ if (ts_node_is_null(child) || !ts_node_is_named(child))+ continue;+ if (strcmp(ts_node_type(child), "type_case") != 0)+ continue;- CBMScope* saved = ctx->current_scope;+ CBMScope *saved = ctx->current_scope;ctx->current_scope = cbm_scope_push(ctx->arena, ctx->current_scope);// Find case type and bind switch variableuint32_t cc_count = ts_node_child_count(child);for (uint32_t j = 0; j < cc_count; j++) {TSNode cc_child = ts_node_child(child, j);- if (ts_node_is_null(cc_child) || !ts_node_is_named(cc_child)) continue;- const char* cc_kind = ts_node_type(cc_child);+ if (ts_node_is_null(cc_child) || !ts_node_is_named(cc_child))+ continue;+ const char *cc_kind = ts_node_type(cc_child);if (strcmp(cc_kind, "type_identifier") == 0 ||strcmp(cc_kind, "qualified_type") == 0 ||- strcmp(cc_kind, "pointer_type") == 0 ||- strcmp(cc_kind, "slice_type") == 0) {+ strcmp(cc_kind, "pointer_type") == 0 || strcmp(cc_kind, "slice_type") == 0) {if (switch_var) {cbm_scope_bind(ctx->current_scope, switch_var,- go_parse_type_node(ctx, cc_child));+ go_parse_type_node(ctx, cc_child));}break;}@@ -1748,20 +1860,22 @@ recurse:;// Recurse into case body statementsfor (uint32_t j = 0; j < cc_count; j++) {TSNode cc_child = ts_node_child(child, j);- if (ts_node_is_null(cc_child) || !ts_node_is_named(cc_child)) continue;- const char* cc_kind = ts_node_type(cc_child);+ if (ts_node_is_null(cc_child) || !ts_node_is_named(cc_child))+ continue;+ const char *cc_kind = ts_node_type(cc_child);// Skip type nodes, process everything else (expression_statement, etc.)if (strcmp(cc_kind, "type_identifier") == 0 ||strcmp(cc_kind, "qualified_type") == 0 ||- strcmp(cc_kind, "pointer_type") == 0 ||- strcmp(cc_kind, "slice_type") == 0) continue;+ strcmp(cc_kind, "pointer_type") == 0 || strcmp(cc_kind, "slice_type") == 0)+ continue;resolve_calls_in_node(ctx, cc_child);}ctx->current_scope = saved;}- if (push_scope) ctx->current_scope = cbm_scope_pop(ctx->current_scope);+ if (push_scope)+ ctx->current_scope = cbm_scope_pop(ctx->current_scope);return;}@@ -1771,19 +1885,21 @@ recurse:;uint32_t nc3 = ts_node_child_count(node);for (uint32_t i = 0; i < nc3; i++) {TSNode child = ts_node_child(node, i);- if (ts_node_is_null(child) || !ts_node_is_named(child)) continue;- const char* ck3 = ts_node_type(child);+ if (ts_node_is_null(child) || !ts_node_is_named(child))+ continue;+ const char *ck3 = ts_node_type(child);if (strcmp(ck3, "communication_case") == 0 || strcmp(ck3, "default_case") == 0) {- CBMScope* saved = ctx->current_scope;+ CBMScope *saved = ctx->current_scope;ctx->current_scope = cbm_scope_push(ctx->arena, ctx->current_scope);// Process children: receive_statement binds vars, then recurse bodyuint32_t cc_count = ts_node_child_count(child);for (uint32_t j = 0; j < cc_count; j++) {TSNode cc_child = ts_node_child(child, j);- if (ts_node_is_null(cc_child) || !ts_node_is_named(cc_child)) continue;- const char* cc_kind = ts_node_type(cc_child);+ if (ts_node_is_null(cc_child) || !ts_node_is_named(cc_child))+ continue;+ const char *cc_kind = ts_node_type(cc_child);if (strcmp(cc_kind, "receive_statement") == 0) {// receive_statement: left := <-right@@ -1792,10 +1908,10 @@ recurse:;TSNode left = ts_node_child_by_field_name(cc_child, "left", 4);TSNode right = ts_node_child_by_field_name(cc_child, "right", 5);if (!ts_node_is_null(right)) {- const CBMType* right_type = go_eval_expr_type(ctx, right);+ const CBMType *right_type = go_eval_expr_type(ctx, right);// right_type might be a channel (if right is the channel)// or already the elem type (if right is a <-ch unary expr)- const CBMType* recv_type = right_type;+ const CBMType *recv_type = right_type;if (right_type && right_type->kind == CBM_TYPE_CHANNEL) {recv_type = right_type->data.channel.elem;}@@ -1804,19 +1920,21 @@ recurse:;uint32_t lhs_count = ts_node_named_child_count(left);for (uint32_t k = 0; k < lhs_count; k++) {TSNode var_node = ts_node_named_child(left, k);- if (strcmp(ts_node_type(var_node), "identifier") != 0) continue;- char* var_name = lsp_node_text(ctx, var_node);- if (!var_name || strcmp(var_name, "_") == 0) continue;+ if (strcmp(ts_node_type(var_node), "identifier") != 0)+ continue;+ char *var_name = lsp_node_text(ctx, var_node);+ if (!var_name || strcmp(var_name, "_") == 0)+ continue;if (k == 0) {cbm_scope_bind(ctx->current_scope, var_name, recv_type);} else {// second var is the ok boolcbm_scope_bind(ctx->current_scope, var_name,- cbm_type_builtin(ctx->arena, "bool"));+ cbm_type_builtin(ctx->arena, "bool"));}}} else if (strcmp(ts_node_type(left), "identifier") == 0) {- char* var_name = lsp_node_text(ctx, left);+ char *var_name = lsp_node_text(ctx, left);if (var_name && strcmp(var_name, "_") != 0) {cbm_scope_bind(ctx->current_scope, var_name, recv_type);}@@ -1832,7 +1950,8 @@ recurse:;ctx->current_scope = saved;}}- if (push_scope) ctx->current_scope = cbm_scope_pop(ctx->current_scope);+ if (push_scope)+ ctx->current_scope = cbm_scope_pop(ctx->current_scope);return;}@@ -1842,7 +1961,7 @@ recurse:;// below runs one level deeper and never touches it.{cbm_cursor_lease_t lease;- TSTreeCursor* cursor = cbm_cursor_acquire(&lease, ctx->walk_depth, node);+ TSTreeCursor *cursor = cbm_cursor_acquire(&lease, ctx->walk_depth, node);if (ts_tree_cursor_goto_first_child(cursor)) {do {resolve_calls_in_node(ctx, ts_tree_cursor_current_node(cursor));@@ -1858,13 +1977,15 @@ recurse:;// --- Process a single function body ----static void process_function(GoLSPContext* ctx, TSNode func_node) {+static void process_function(GoLSPContext *ctx, TSNode func_node) {// Set enclosing function QNTSNode name_node = ts_node_child_by_field_name(func_node, "name", 4);- if (ts_node_is_null(name_node)) return;+ if (ts_node_is_null(name_node))+ return;- char* func_name = lsp_node_text(ctx, name_node);- if (!func_name || !func_name[0]) return;+ char *func_name = lsp_node_text(ctx, name_node);+ if (!func_name || !func_name[0])+ return;// Enclosing-function QN must be the BARE package.Func form (no receiver// type segment). The textual call events (extract_unified.c) source calls@@ -1877,7 +1998,7 @@ static void process_function(GoLSPContext* ctx, TSNode func_node) {ctx->enclosing_func_qn = cbm_arena_sprintf(ctx->arena, "%s.%s", ctx->package_qn, func_name);// Push function scope- CBMScope* saved_scope = ctx->current_scope;+ CBMScope *saved_scope = ctx->current_scope;ctx->current_scope = cbm_scope_push(ctx->arena, ctx->current_scope);// Bind parameters into scope (including variadic)@@ -1886,15 +2007,17 @@ static void process_function(GoLSPContext* ctx, TSNode func_node) {uint32_t nc = ts_node_child_count(params);for (uint32_t i = 0; i < nc; i++) {TSNode param = ts_node_child(params, i);- if (ts_node_is_null(param) || !ts_node_is_named(param)) continue;- const char* pk = ts_node_type(param);+ if (ts_node_is_null(param) || !ts_node_is_named(param))+ continue;+ const char *pk = ts_node_type(param);bool is_variadic = (strcmp(pk, "variadic_parameter_declaration") == 0);- if (!is_variadic && strcmp(pk, "parameter_declaration") != 0) continue;+ if (!is_variadic && strcmp(pk, "parameter_declaration") != 0)+ continue;// Get typeTSNode type_node = ts_node_child_by_field_name(param, "type", 4);- const CBMType* param_type = go_parse_type_node(ctx, type_node);+ const CBMType *param_type = go_parse_type_node(ctx, type_node);// Variadic: ...T is []T in the function bodyif (is_variadic && param_type) {@@ -1905,9 +2028,10 @@ static void process_function(GoLSPContext* ctx, TSNode func_node) {uint32_t pnc = ts_node_child_count(param);for (uint32_t j = 0; j < pnc; j++) {TSNode child = ts_node_child(param, j);- if (ts_node_is_null(child) || !ts_node_is_named(child)) continue;+ if (ts_node_is_null(child) || !ts_node_is_named(child))+ continue;if (strcmp(ts_node_type(child), "identifier") == 0) {- char* pname = lsp_node_text(ctx, child);+ char *pname = lsp_node_text(ctx, child);if (pname && strcmp(pname, "_") != 0) {cbm_scope_bind(ctx->current_scope, pname, param_type);}@@ -1920,23 +2044,26 @@ static void process_function(GoLSPContext* ctx, TSNode func_node) {TSNode result_node = ts_node_child_by_field_name(func_node, "result", 6);if (!ts_node_is_null(result_node)) {// result can be a parameter_list (named returns) or a simple type- const char* rk = ts_node_type(result_node);+ const char *rk = ts_node_type(result_node);if (strcmp(rk, "parameter_list") == 0) {uint32_t rnc = ts_node_child_count(result_node);for (uint32_t i = 0; i < rnc; i++) {TSNode rparam = ts_node_child(result_node, i);- if (ts_node_is_null(rparam) || !ts_node_is_named(rparam)) continue;- if (strcmp(ts_node_type(rparam), "parameter_declaration") != 0) continue;+ if (ts_node_is_null(rparam) || !ts_node_is_named(rparam))+ continue;+ if (strcmp(ts_node_type(rparam), "parameter_declaration") != 0)+ continue;TSNode rtype = ts_node_child_by_field_name(rparam, "type", 4);- const CBMType* ret_type = go_parse_type_node(ctx, rtype);+ const CBMType *ret_type = go_parse_type_node(ctx, rtype);uint32_t rpnc = ts_node_child_count(rparam);for (uint32_t j = 0; j < rpnc; j++) {TSNode child = ts_node_child(rparam, j);- if (ts_node_is_null(child) || !ts_node_is_named(child)) continue;+ if (ts_node_is_null(child) || !ts_node_is_named(child))+ continue;if (strcmp(ts_node_type(child), "identifier") == 0) {- char* rname = lsp_node_text(ctx, child);+ char *rname = lsp_node_text(ctx, child);if (rname && strcmp(rname, "_") != 0) {cbm_scope_bind(ctx->current_scope, rname, ret_type);}@@ -1953,11 +2080,13 @@ static void process_function(GoLSPContext* ctx, TSNode func_node) {uint32_t rnc = ts_node_child_count(recv);for (uint32_t i = 0; i < rnc; i++) {TSNode rp = ts_node_child(recv, i);- if (ts_node_is_null(rp) || !ts_node_is_named(rp)) continue;- if (strcmp(ts_node_type(rp), "parameter_declaration") != 0) continue;+ if (ts_node_is_null(rp) || !ts_node_is_named(rp))+ continue;+ if (strcmp(ts_node_type(rp), "parameter_declaration") != 0)+ continue;TSNode rtype = ts_node_child_by_field_name(rp, "type", 4);- const CBMType* recv_type = go_parse_type_node(ctx, rtype);+ const CBMType *recv_type = go_parse_type_node(ctx, rtype);// Find receiver nameuint32_t rpnc = ts_node_child_count(rp);@@ -1965,7 +2094,7 @@ static void process_function(GoLSPContext* ctx, TSNode func_node) {TSNode rc = ts_node_child(rp, j);if (!ts_node_is_null(rc) && ts_node_is_named(rc) &&strcmp(ts_node_type(rc), "identifier") == 0) {- char* rname = lsp_node_text(ctx, rc);+ char *rname = lsp_node_text(ctx, rc);if (rname && strcmp(rname, "_") != 0) {cbm_scope_bind(ctx->current_scope, rname, recv_type);}@@ -1987,24 +2116,26 @@ static void process_function(GoLSPContext* ctx, TSNode func_node) {// --- Process entire file ----void go_lsp_process_file(GoLSPContext* ctx, TSNode root) {- if (ts_node_is_null(root)) return;+void go_lsp_process_file(GoLSPContext *ctx, TSNode root) {+ if (ts_node_is_null(root))+ return;// Collect top-level children once (O(n)); ts_node_child(root,i) is O(i) → O(n²).uint32_t kn = 0;- TSNode* kids = cbm_lsp_collect_children(ctx->arena, root, &kn);+ TSNode *kids = cbm_lsp_collect_children(ctx->arena, root, &kn);// Pass 1: Bind package-level var/const declarations into root scope.// Must happen before processing functions so all globals are visible.for (uint32_t i = 0; i < kn; i++) {TSNode child = kids[i];- const char* kind = ts_node_type(child);+ const char *kind = ts_node_type(child);if (strcmp(kind, "var_declaration") == 0 || strcmp(kind, "const_declaration") == 0) {uint32_t vnc = ts_node_child_count(child);for (uint32_t j = 0; j < vnc; j++) {TSNode spec = ts_node_child(child, j);- if (ts_node_is_null(spec) || !ts_node_is_named(spec)) continue;+ if (ts_node_is_null(spec) || !ts_node_is_named(spec))+ continue;go_process_statement(ctx, spec);}}@@ -2013,10 +2144,9 @@ void go_lsp_process_file(GoLSPContext* ctx, TSNode root) {// Pass 2: Process function/method bodiesfor (uint32_t i = 0; i < kn; i++) {TSNode child = kids[i];- const char* kind = ts_node_type(child);+ const char *kind = ts_node_type(child);- if (strcmp(kind, "function_declaration") == 0 ||- strcmp(kind, "method_declaration") == 0) {+ if (strcmp(kind, "function_declaration") == 0 || strcmp(kind, "method_declaration") == 0) {process_function(ctx, child);}}@@ -2024,8 +2154,9 @@ void go_lsp_process_file(GoLSPContext* ctx, TSNode root) {// --- Helper: parse Go return type text into CBMType ----const CBMType* cbm_parse_return_type_text(CBMArena* a, const char* text, const char* module_qn) {- if (!text || !text[0]) return cbm_type_unknown();+const CBMType *cbm_parse_return_type_text(CBMArena *a, const char *text, const char *module_qn) {+ if (!text || !text[0])+ return cbm_type_unknown();// Pointer: *Fooif (text[0] == '*') {@@ -2038,15 +2169,13 @@ const CBMType* cbm_parse_return_type_text(CBMArena* a, const char* text, const c}// Builtin types- static const char* builtins[] = {- "int","int8","int16","int32","int64",- "uint","uint8","uint16","uint32","uint64",- "float32","float64","string","bool","byte","rune","error",- "any","uintptr",- NULL- };- for (const char** b = builtins; *b; b++) {- if (strcmp(text, *b) == 0) return cbm_type_builtin(a, text);+ static const char *builtins[] = {"int", "int8", "int16", "int32", "int64",+ "uint", "uint8", "uint16", "uint32", "uint64",+ "float32", "float64", "string", "bool", "byte",+ "rune", "error", "any", "uintptr", NULL};+ for (const char **b = builtins; *b; b++) {+ if (strcmp(text, *b) == 0)+ return cbm_type_builtin(a, text);}// Named type: assume local to module@@ -2083,34 +2212,36 @@ typedef struct {static _Atomic(go_stdlib_holder_t *) g_go_stdlib_shared;-static const CBMTypeRegistry* go_stdlib_shared(void) {- go_stdlib_holder_t* ready = atomic_load_explicit(&g_go_stdlib_shared, memory_order_acquire);- if (ready) return &ready->reg;- go_stdlib_holder_t* built = (go_stdlib_holder_t*)calloc(1, sizeof(*built));- if (!built) return NULL;+static const CBMTypeRegistry *go_stdlib_shared(void) {+ go_stdlib_holder_t *ready = atomic_load_explicit(&g_go_stdlib_shared, memory_order_acquire);+ if (ready)+ return &ready->reg;+ go_stdlib_holder_t *built = cbm_calloc(CBM_MEM_CLASS_OTHER, sizeof(*built));+ if (!built)+ return NULL;cbm_arena_init(&built->arena);if (built->arena.nblocks == 0) {- free(built);+ cbm_free(CBM_MEM_CLASS_OTHER, built);return NULL;}cbm_registry_init(&built->reg, &built->arena);cbm_go_stdlib_register(&built->reg, &built->arena);cbm_registry_finalize(&built->reg);built->reg.read_only = true;- go_stdlib_holder_t* expected = NULL;+ go_stdlib_holder_t *expected = NULL;if (atomic_compare_exchange_strong_explicit(&g_go_stdlib_shared, &expected, built,memory_order_acq_rel, memory_order_acquire)) {return &built->reg;}cbm_arena_destroy(&built->arena);- free(built);+ cbm_free(CBM_MEM_CLASS_OTHER, built);return &expected->reg;}/* A per-file registry sees the stdlib: chained to the shared copy, or* registered into it when the shared copy cannot be built. */-static void go_registry_with_stdlib(CBMTypeRegistry* reg, CBMArena* arena) {- const CBMTypeRegistry* shared = go_stdlib_shared();+static void go_registry_with_stdlib(CBMTypeRegistry *reg, CBMArena *arena) {+ const CBMTypeRegistry *shared = go_stdlib_shared();if (shared) {reg->fallback = shared;} else {@@ -2120,8 +2251,8 @@ static void go_registry_with_stdlib(CBMTypeRegistry* reg, CBMArena* arena) {// --- Entry point: build registry from file defs + run LSP ----void cbm_run_go_lsp(CBMArena* arena, CBMFileResult* result,- const char* source, int source_len, TSNode root) {+void cbm_run_go_lsp(CBMArena *arena, CBMFileResult *result, const char *source, int source_len,+ TSNode root) {CBMTypeRegistry reg;cbm_registry_init(®, arena);@@ -2129,12 +2260,13 @@ void cbm_run_go_lsp(CBMArena* arena, CBMFileResult* result,// Go stdlib types/functions: the shared sealed registry, chainedgo_registry_with_stdlib(®, arena);- const char* module_qn = result->module_qn;+ const char *module_qn = result->module_qn;// Phase 1: Register all types and functions from the file's own definitionsfor (int i = 0; i < result->defs.count; i++) {- CBMDefinition* d = &result->defs.items[i];- if (!d->qualified_name || !d->name) continue;+ CBMDefinition *d = &result->defs.items[i];+ if (!d->qualified_name || !d->name)+ continue;// Register every type-like container (Class/Struct/Type/Interface/Enum/// Trait). Struct included so a Go `type T struct {...}` (now labelled@@ -2149,13 +2281,16 @@ void cbm_run_go_lsp(CBMArena* arena, CBMFileResult* result,// Populate embedded_types from base_classes (Go struct embedding)if (d->base_classes) {int bc_count = 0;- while (d->base_classes[bc_count]) bc_count++;+ while (d->base_classes[bc_count])+ bc_count++;if (bc_count > 0) {- const char** embedded = (const char**)cbm_arena_alloc(arena, (bc_count + 1) * sizeof(const char*));+ const char **embedded = (const char **)cbm_arena_alloc(+ arena, (bc_count + 1) * sizeof(const char *));for (int j = 0; j < bc_count; j++) {- const char* bc = d->base_classes[j];+ const char *bc = d->base_classes[j];// Strip pointer prefix for embedded *Type- while (bc[0] == '*') bc++;+ while (bc[0] == '*')+ bc++;// Qualify the embedded type nameembedded[j] = cbm_arena_sprintf(arena, "%s.%s", module_qn, bc);}@@ -2175,20 +2310,23 @@ void cbm_run_go_lsp(CBMArena* arena, CBMFileResult* result,rf.short_name = d->name;// Build FUNC type from return_types- const CBMType** ret_types = NULL;+ const CBMType **ret_types = NULL;if (d->return_types) {int count = 0;- while (d->return_types[count]) count++;+ while (d->return_types[count])+ count++;if (count > 0) {- ret_types = (const CBMType**)cbm_arena_alloc(arena, (count + 1) * sizeof(const CBMType*));+ ret_types = (const CBMType **)cbm_arena_alloc(+ arena, (count + 1) * sizeof(const CBMType *));for (int j = 0; j < count; j++) {- ret_types[j] = cbm_parse_return_type_text(arena, d->return_types[j], module_qn);+ ret_types[j] =+ cbm_parse_return_type_text(arena, d->return_types[j], module_qn);}ret_types[count] = NULL;}} else if (d->return_type && d->return_type[0]) {// Fallback: single return_type string- ret_types = (const CBMType**)cbm_arena_alloc(arena, 2 * sizeof(const CBMType*));+ ret_types = (const CBMType **)cbm_arena_alloc(arena, 2 * sizeof(const CBMType *));ret_types[0] = cbm_parse_return_type_text(arena, d->return_type, module_qn);ret_types[1] = NULL;}@@ -2197,7 +2335,7 @@ void cbm_run_go_lsp(CBMArena* arena, CBMFileResult* result,* is present, including a non-NULL carrier with an explicit zero* count. Its slots deliberately have no names because legacy name* extraction is not guaranteed to have the same multiplicity. */- const CBMType** param_types_arr = NULL;+ const CBMType **param_types_arr = NULL;const char **param_names_arr = NULL;bool has_ordered_params =d->signature_param_types != NULL || d->signature_param_count > 0;@@ -2209,11 +2347,14 @@ void cbm_run_go_lsp(CBMArena* arena, CBMFileResult* result,} else if (d->param_types) {param_names_arr = d->param_names;int count = 0;- while (d->param_types[count]) count++;+ while (d->param_types[count])+ count++;if (count > 0) {- param_types_arr = (const CBMType**)cbm_arena_alloc(arena, (count + 1) * sizeof(const CBMType*));+ param_types_arr = (const CBMType **)cbm_arena_alloc(+ arena, (count + 1) * sizeof(const CBMType *));for (int j = 0; j < count; j++) {- param_types_arr[j] = cbm_parse_return_type_text(arena, d->param_types[j], module_qn);+ param_types_arr[j] =+ cbm_parse_return_type_text(arena, d->param_types[j], module_qn);}param_types_arr[count] = NULL;}@@ -2265,28 +2406,32 @@ void cbm_run_go_lsp(CBMArena* arena, CBMFileResult* result,{// Collect top-level children once (O(n)); ts_node_child(root,i) is O(i) → O(n²).uint32_t rkn = 0;- TSNode* rkids = cbm_lsp_collect_children(arena, root, &rkn);+ TSNode *rkids = cbm_lsp_collect_children(arena, root, &rkn);for (uint32_t i = 0; i < rkn; i++) {TSNode top = rkids[i];- const char* tk = ts_node_type(top);+ const char *tk = ts_node_type(top);// type_declaration contains type_spec children- if (strcmp(tk, "type_declaration") != 0) continue;+ if (strcmp(tk, "type_declaration") != 0)+ continue;uint32_t td_nc = ts_node_child_count(top);for (uint32_t j = 0; j < td_nc; j++) {TSNode spec = ts_node_child(top, j);- if (ts_node_is_null(spec) || !ts_node_is_named(spec)) continue;- const char* spec_kind = ts_node_type(spec);+ if (ts_node_is_null(spec) || !ts_node_is_named(spec))+ continue;+ const char *spec_kind = ts_node_type(spec);// type_alias: type Foo = Barif (strcmp(spec_kind, "type_alias") == 0) {TSNode alias_name = ts_node_child_by_field_name(spec, "name", 4);TSNode alias_type = ts_node_child_by_field_name(spec, "type", 4);if (!ts_node_is_null(alias_name) && !ts_node_is_null(alias_type)) {- char* aname = cbm_node_text(arena, alias_name, source);- char* atarget = cbm_node_text(arena, alias_type, source);+ char *aname = cbm_node_text(arena, alias_name, source);+ char *atarget = cbm_node_text(arena, alias_type, source);if (aname && aname[0] && atarget && atarget[0]) {- const char* alias_type_qn = cbm_arena_sprintf(arena, "%s.%s", module_qn, aname);- const char* alias_target_qn = cbm_arena_sprintf(arena, "%s.%s", module_qn, atarget);+ const char *alias_type_qn =+ cbm_arena_sprintf(arena, "%s.%s", module_qn, aname);+ const char *alias_target_qn =+ cbm_arena_sprintf(arena, "%s.%s", module_qn, atarget);bool found_a = false;for (int ti = 0; ti < reg.type_count; ti++) {if (reg.types[ti].qualified_name &&@@ -2309,30 +2454,34 @@ void cbm_run_go_lsp(CBMArena* arena, CBMFileResult* result,continue;}- if (strcmp(spec_kind, "type_spec") != 0) continue;+ if (strcmp(spec_kind, "type_spec") != 0)+ continue;TSNode name_node = ts_node_child_by_field_name(spec, "name", 4);TSNode type_node = ts_node_child_by_field_name(spec, "type", 4);- if (ts_node_is_null(name_node) || ts_node_is_null(type_node)) continue;+ if (ts_node_is_null(name_node) || ts_node_is_null(type_node))+ continue;- char* type_name = cbm_node_text(arena,name_node, source);- if (!type_name || !type_name[0]) continue;- const char* type_qn = cbm_arena_sprintf(arena, "%s.%s", module_qn, type_name);+ char *type_name = cbm_node_text(arena, name_node, source);+ if (!type_name || !type_name[0])+ continue;+ const char *type_qn = cbm_arena_sprintf(arena, "%s.%s", module_qn, type_name);// Interface type: extract method names for satisfaction checkingif (strcmp(ts_node_type(type_node), "interface_type") == 0) {- const char* iface_methods[64];+ const char *iface_methods[64];int iface_method_count = 0;uint32_t inl_nc = ts_node_named_child_count(type_node);for (uint32_t k = 0; k < inl_nc && iface_method_count < 63; k++) {TSNode child = ts_node_named_child(type_node, k);- if (ts_node_is_null(child)) continue;- const char* ck = ts_node_type(child);+ if (ts_node_is_null(child))+ continue;+ const char *ck = ts_node_type(child);// method_spec: MethodName(params) returnsif (strcmp(ck, "method_spec") == 0 || strcmp(ck, "method_elem") == 0) {TSNode mname = ts_node_child_by_field_name(child, "name", 4);if (!ts_node_is_null(mname)) {- char* mn = cbm_node_text(arena, mname, source);+ char *mn = cbm_node_text(arena, mname, source);if (mn && mn[0]) {iface_methods[iface_method_count++] = mn;}@@ -2342,9 +2491,10 @@ void cbm_run_go_lsp(CBMArena* arena, CBMFileResult* result,if (iface_method_count > 0) {for (int ti = 0; ti < reg.type_count; ti++) {if (!reg.types[ti].qualified_name ||- strcmp(reg.types[ti].qualified_name, type_qn) != 0) continue;- const char** names = (const char**)cbm_arena_alloc(arena,- (iface_method_count + 1) * sizeof(const char*));+ strcmp(reg.types[ti].qualified_name, type_qn) != 0)+ continue;+ const char **names = (const char **)cbm_arena_alloc(+ arena, (iface_method_count + 1) * sizeof(const char *));for (int mi = 0; mi < iface_method_count; mi++) {names[mi] = iface_methods[mi];}@@ -2356,7 +2506,8 @@ void cbm_run_go_lsp(CBMArena* arena, CBMFileResult* result,continue;}- if (strcmp(ts_node_type(type_node), "struct_type") != 0) continue;+ if (strcmp(ts_node_type(type_node), "struct_type") != 0)+ continue;// Find field_declaration_list inside struct_typeTSNode field_list = ts_node_child_by_field_name(type_node, "body", 4);@@ -2365,13 +2516,14 @@ void cbm_run_go_lsp(CBMArena* arena, CBMFileResult* result,if (ts_node_named_child_count(type_node) > 0)field_list = ts_node_named_child(type_node, 0);}- if (ts_node_is_null(field_list)) continue;+ if (ts_node_is_null(field_list))+ continue;// Scan field_declarations for embeds and named fields- const char* embeds[16];+ const char *embeds[16];int embed_count = 0;- const char* fld_names[64];- const CBMType* fld_types[64];+ const char *fld_names[64];+ const CBMType *fld_types[64];int fld_count = 0;// Create a temporary LSP context for parsing field types@@ -2386,8 +2538,10 @@ void cbm_run_go_lsp(CBMArena* arena, CBMFileResult* result,uint32_t fl_nc = ts_node_child_count(field_list);for (uint32_t k = 0; k < fl_nc; k++) {TSNode field = ts_node_child(field_list, k);- if (ts_node_is_null(field) || !ts_node_is_named(field)) continue;- if (strcmp(ts_node_type(field), "field_declaration") != 0) continue;+ if (ts_node_is_null(field) || !ts_node_is_named(field))+ continue;+ if (strcmp(ts_node_type(field), "field_declaration") != 0)+ continue;TSNode fname = ts_node_child_by_field_name(field, "name", 4);TSNode ftype = ts_node_child_by_field_name(field, "type", 4);@@ -2395,16 +2549,19 @@ void cbm_run_go_lsp(CBMArena* arena, CBMFileResult* result,if (ts_node_is_null(fname) && !ts_node_is_null(ftype)) {// Embedded field: has type but no nameif (embed_count < 15) {- char* embed_text = cbm_node_text(arena, ftype, source);+ char *embed_text = cbm_node_text(arena, ftype, source);if (embed_text && embed_text[0]) {- const char* et = embed_text;- while (*et == '*') et++;- embeds[embed_count++] = cbm_arena_sprintf(arena, "%s.%s", module_qn, et);+ const char *et = embed_text;+ while (*et == '*')+ et++;+ embeds[embed_count++] =+ cbm_arena_sprintf(arena, "%s.%s", module_qn, et);}}- } else if (!ts_node_is_null(fname) && !ts_node_is_null(ftype) && fld_count < 63) {+ } else if (!ts_node_is_null(fname) && !ts_node_is_null(ftype) &&+ fld_count < 63) {// Named field: name + type- char* fn = cbm_node_text(arena, fname, source);+ char *fn = cbm_node_text(arena, fname, source);if (fn && fn[0]) {fld_names[fld_count] = fn;fld_types[fld_count] = go_parse_type_node(&tmp_ctx, ftype);@@ -2416,20 +2573,22 @@ void cbm_run_go_lsp(CBMArena* arena, CBMFileResult* result,// Find the registered type and update itfor (int ti = 0; ti < reg.type_count; ti++) {if (!reg.types[ti].qualified_name ||- strcmp(reg.types[ti].qualified_name, type_qn) != 0) continue;+ strcmp(reg.types[ti].qualified_name, type_qn) != 0)+ continue;if (embed_count > 0) {- const char** arr = (const char**)cbm_arena_alloc(arena,- (embed_count + 1) * sizeof(const char*));- for (int ei = 0; ei < embed_count; ei++) arr[ei] = embeds[ei];+ const char **arr = (const char **)cbm_arena_alloc(+ arena, (embed_count + 1) * sizeof(const char *));+ for (int ei = 0; ei < embed_count; ei++)+ arr[ei] = embeds[ei];arr[embed_count] = NULL;reg.types[ti].embedded_types = arr;}if (fld_count > 0) {- const char** names = (const char**)cbm_arena_alloc(arena,- (fld_count + 1) * sizeof(const char*));- const CBMType** types = (const CBMType**)cbm_arena_alloc(arena,- (fld_count + 1) * sizeof(const CBMType*));+ const char **names = (const char **)cbm_arena_alloc(+ arena, (fld_count + 1) * sizeof(const char *));+ const CBMType **types = (const CBMType **)cbm_arena_alloc(+ arena, (fld_count + 1) * sizeof(const CBMType *));for (int fi = 0; fi < fld_count; fi++) {names[fi] = fld_names[fi];types[fi] = fld_types[fi];@@ -2454,7 +2613,7 @@ void cbm_run_go_lsp(CBMArena* arena, CBMFileResult* result,// Add importsfor (int i = 0; i < result->imports.count; i++) {- CBMImport* imp = &result->imports.items[i];+ CBMImport *imp = &result->imports.items[i];if (imp->local_name && imp->module_path) {go_lsp_add_import(&lsp_ctx, imp->local_name, imp->module_path);}@@ -2467,30 +2626,35 @@ void cbm_run_go_lsp(CBMArena* arena, CBMFileResult* result,// --- Cross-file LSP: parse source, build registry from defs, run LSP ---// Helper: split "|"-separated string into array of CBMType*.-static const CBMType** split_pipe_types(CBMArena* a, const char* text, const char* module_qn) {- if (!text || !text[0]) return NULL;+static const CBMType **split_pipe_types(CBMArena *a, const char *text, const char *module_qn) {+ if (!text || !text[0])+ return NULL;// Count separatorsint count = 1;- for (const char* p = text; *p; p++) {- if (*p == '|') count++;+ for (const char *p = text; *p; p++) {+ if (*p == '|')+ count++;}- const CBMType** arr = (const CBMType**)cbm_arena_alloc(a, (count + 1) * sizeof(const CBMType*));- if (!arr) return NULL;+ const CBMType **arr =+ (const CBMType **)cbm_arena_alloc(a, (count + 1) * sizeof(const CBMType *));+ if (!arr)+ return NULL;// Split and parse each type- char* buf = cbm_arena_strdup(a, text);+ char *buf = cbm_arena_strdup(a, text);int idx = 0;- char* start = buf;- for (char* p = buf; ; p++) {+ char *start = buf;+ for (char *p = buf;; p++) {if (*p == '|' || *p == '\0') {char save = *p;*p = '\0';if (start[0]) {arr[idx++] = cbm_parse_return_type_text(a, start, module_qn);}- if (save == '\0') break;+ if (save == '\0')+ break;start = p + 1;}}@@ -2499,28 +2663,32 @@ static const CBMType** split_pipe_types(CBMArena* a, const char* text, const cha}// Helper: split "|"-separated string into array of const char*.-static const char** split_pipe_strings(CBMArena* a, const char* text) {- if (!text || !text[0]) return NULL;+static const char **split_pipe_strings(CBMArena *a, const char *text) {+ if (!text || !text[0])+ return NULL;int count = 1;- for (const char* p = text; *p; p++) {- if (*p == '|') count++;+ for (const char *p = text; *p; p++) {+ if (*p == '|')+ count++;}- const char** arr = (const char**)cbm_arena_alloc(a, (count + 1) * sizeof(const char*));- if (!arr) return NULL;+ const char **arr = (const char **)cbm_arena_alloc(a, (count + 1) * sizeof(const char *));+ if (!arr)+ return NULL;- char* buf = cbm_arena_strdup(a, text);+ char *buf = cbm_arena_strdup(a, text);int idx = 0;- char* start = buf;- for (char* p = buf; ; p++) {+ char *start = buf;+ for (char *p = buf;; p++) {if (*p == '|' || *p == '\0') {char save = *p;*p = '\0';if (start[0]) {arr[idx++] = cbm_arena_strdup(a, start);}- if (save == '\0') break;+ if (save == '\0')+ break;start = p + 1;}}@@ -2533,31 +2701,38 @@ static const char** split_pipe_strings(CBMArena* a, const char* text) {// type_text is resolved relative to def_module_qn./* Parse "name:type|name:type" into NULL-terminated name/type arrays. False when* nothing parsed (or on allocation failure): the type keeps no field info. */-static bool parse_field_defs(CBMArena* arena, const char* field_defs, const char* def_module_qn,- const char*** names_out, const CBMType*** types_out) {+static bool parse_field_defs(CBMArena *arena, const char *field_defs, const char *def_module_qn,+ const char ***names_out, const CBMType ***types_out) {// Count fieldsint count = 1;- for (const char* p = field_defs; *p; p++) {- if (*p == '|') count++;+ for (const char *p = field_defs; *p; p++) {+ if (*p == '|')+ count++;}- if (count > 63) count = 63;+ if (count > 63)+ count = 63;- const char** names = (const char**)cbm_arena_alloc(arena, (count + 1) * sizeof(const char*));- const CBMType** types = (const CBMType**)cbm_arena_alloc(arena, (count + 1) * sizeof(const CBMType*));- if (!names || !types) return false;+ const char **names = (const char **)cbm_arena_alloc(arena, (count + 1) * sizeof(const char *));+ const CBMType **types =+ (const CBMType **)cbm_arena_alloc(arena, (count + 1) * sizeof(const CBMType *));+ if (!names || !types)+ return false;- char* buf = cbm_arena_strdup(arena, field_defs);+ char *buf = cbm_arena_strdup(arena, field_defs);int idx = 0;- char* start = buf;- for (char* p = buf; ; p++) {+ char *start = buf;+ for (char *p = buf;; p++) {if (*p == '|' || *p == '\0') {char save = *p;*p = '\0';// Parse "name:type"- char* colon = NULL;- for (char* q = start; *q; q++) {- if (*q == ':') { colon = q; break; }+ char *colon = NULL;+ for (char *q = start; *q; q++) {+ if (*q == ':') {+ colon = q;+ break;+ }}if (colon && idx < count) {*colon = '\0';@@ -2565,7 +2740,8 @@ static bool parse_field_defs(CBMArena* arena, const char* field_defs, const chartypes[idx] = cbm_parse_return_type_text(arena, colon + 1, def_module_qn);idx++;}- if (save == '\0') break;+ if (save == '\0')+ break;start = p + 1;}}@@ -2576,11 +2752,12 @@ static bool parse_field_defs(CBMArena* arena, const char* field_defs, const charreturn idx > 0;}-static void parse_field_defs_into_type(CBMArena* arena, CBMTypeRegistry* reg,- const char* type_qn, const char* field_defs, const char* def_module_qn) {- if (!field_defs || !field_defs[0] || !type_qn) return;- const char** names = NULL;- const CBMType** types = NULL;+static void parse_field_defs_into_type(CBMArena *arena, CBMTypeRegistry *reg, const char *type_qn,+ const char *field_defs, const char *def_module_qn) {+ if (!field_defs || !field_defs[0] || !type_qn)+ return;+ const char **names = NULL;+ const CBMType **types = NULL;if (parse_field_defs(arena, field_defs, def_module_qn, &names, &types)) {// Find the registered type and update field infofor (int ti = 0; ti < reg->type_count; ti++) {@@ -2599,16 +2776,19 @@ static void parse_field_defs_into_type(CBMArena* arena, CBMTypeRegistry* reg,// Helper: parse a tree-sitter type AST node with type param awareness.// Like go_parse_type_node but checks type_identifier against type_param_names first,// and works without a full GoLSPContext (uses raw arena/source/module_qn).-static const CBMType* parse_type_node_with_params(CBMArena* arena, TSNode node,- const char* source, const char* module_qn, const char** type_param_names) {- if (ts_node_is_null(node)) return cbm_type_unknown();+static const CBMType *parse_type_node_with_params(CBMArena *arena, TSNode node, const char *source,+ const char *module_qn,+ const char **type_param_names) {+ if (ts_node_is_null(node))+ return cbm_type_unknown();- const char* kind = ts_node_type(node);+ const char *kind = ts_node_type(node);// type_identifier: check type params first, then resolve as named typeif (strcmp(kind, "type_identifier") == 0) {- char* name = cbm_node_text(arena, node, source);- if (!name) return cbm_type_unknown();+ char *name = cbm_node_text(arena, node, source);+ if (!name)+ return cbm_type_unknown();// Check type param namesif (type_param_names) {for (int i = 0; type_param_names[i]; i++) {@@ -2618,13 +2798,11 @@ static const CBMType* parse_type_node_with_params(CBMArena* arena, TSNode node,}}// Builtin types- if (strcmp(name, "int") == 0 || strcmp(name, "string") == 0 ||- strcmp(name, "bool") == 0 || strcmp(name, "float64") == 0 ||- strcmp(name, "float32") == 0 || strcmp(name, "byte") == 0 ||- strcmp(name, "rune") == 0 || strcmp(name, "error") == 0 ||- strcmp(name, "any") == 0 || strcmp(name, "int8") == 0 ||- strcmp(name, "int16") == 0 || strcmp(name, "int32") == 0 ||- strcmp(name, "int64") == 0 || strcmp(name, "uint") == 0 ||+ if (strcmp(name, "int") == 0 || strcmp(name, "string") == 0 || strcmp(name, "bool") == 0 ||+ strcmp(name, "float64") == 0 || strcmp(name, "float32") == 0 ||+ strcmp(name, "byte") == 0 || strcmp(name, "rune") == 0 || strcmp(name, "error") == 0 ||+ strcmp(name, "any") == 0 || strcmp(name, "int8") == 0 || strcmp(name, "int16") == 0 ||+ strcmp(name, "int32") == 0 || strcmp(name, "int64") == 0 || strcmp(name, "uint") == 0 ||strcmp(name, "uint8") == 0 || strcmp(name, "uint16") == 0 ||strcmp(name, "uint32") == 0 || strcmp(name, "uint64") == 0 ||strcmp(name, "uintptr") == 0) {@@ -2635,8 +2813,8 @@ static const CBMType* parse_type_node_with_params(CBMArena* arena, TSNode node,// type_elem: wrapper in type_argumentsif (strcmp(kind, "type_elem") == 0 && ts_node_named_child_count(node) > 0) {- return parse_type_node_with_params(arena, ts_node_named_child(node, 0),- source, module_qn, type_param_names);+ return parse_type_node_with_params(arena, ts_node_named_child(node, 0), source, module_qn,+ type_param_names);}// qualified_type: pkg.Type@@ -2644,8 +2822,8 @@ static const CBMType* parse_type_node_with_params(CBMArena* arena, TSNode node,TSNode pkg_node = ts_node_child_by_field_name(node, "package", 7);TSNode name_node = ts_node_child_by_field_name(node, "name", 4);if (!ts_node_is_null(pkg_node) && !ts_node_is_null(name_node)) {- char* pkg = cbm_node_text(arena, pkg_node, source);- char* name = cbm_node_text(arena, name_node, source);+ char *pkg = cbm_node_text(arena, pkg_node, source);+ char *name = cbm_node_text(arena, name_node, source);if (pkg && name) {return cbm_type_named(arena, cbm_arena_sprintf(arena, "%s.%s", pkg, name));}@@ -2657,8 +2835,9 @@ static const CBMType* parse_type_node_with_params(CBMArena* arena, TSNode node,if (strcmp(kind, "pointer_type") == 0) {uint32_t nc = ts_node_named_child_count(node);if (nc > 0)- return cbm_type_pointer(arena, parse_type_node_with_params(arena,- ts_node_named_child(node, nc - 1), source, module_qn, type_param_names));+ return cbm_type_pointer(+ arena, parse_type_node_with_params(arena, ts_node_named_child(node, nc - 1), source,+ module_qn, type_param_names));return cbm_type_unknown();}@@ -2667,8 +2846,8 @@ static const CBMType* parse_type_node_with_params(CBMArena* arena, TSNode node,TSNode elem = ts_node_child_by_field_name(node, "element", 7);if (ts_node_is_null(elem) && ts_node_named_child_count(node) > 0)elem = ts_node_named_child(node, ts_node_named_child_count(node) - 1);- return cbm_type_slice(arena, parse_type_node_with_params(arena,- elem, source, module_qn, type_param_names));+ return cbm_type_slice(+ arena, parse_type_node_with_params(arena, elem, source, module_qn, type_param_names));}// array_type: [N]T@@ -2676,16 +2855,16 @@ static const CBMType* parse_type_node_with_params(CBMArena* arena, TSNode node,TSNode elem = ts_node_child_by_field_name(node, "element", 7);if (ts_node_is_null(elem) && ts_node_named_child_count(node) > 0)elem = ts_node_named_child(node, ts_node_named_child_count(node) - 1);- return cbm_type_slice(arena, parse_type_node_with_params(arena,- elem, source, module_qn, type_param_names));+ return cbm_type_slice(+ arena, parse_type_node_with_params(arena, elem, source, module_qn, type_param_names));}// map_type: map[K]Vif (strcmp(kind, "map_type") == 0) {TSNode key = ts_node_child_by_field_name(node, "key", 3);TSNode value = ts_node_child_by_field_name(node, "value", 5);- return cbm_type_map(arena,- parse_type_node_with_params(arena, key, source, module_qn, type_param_names),+ return cbm_type_map(+ arena, parse_type_node_with_params(arena, key, source, module_qn, type_param_names),parse_type_node_with_params(arena, value, source, module_qn, type_param_names));}@@ -2694,14 +2873,17 @@ static const CBMType* parse_type_node_with_params(CBMArena* arena, TSNode node,TSNode value = ts_node_child_by_field_name(node, "value", 5);if (ts_node_is_null(value) && ts_node_named_child_count(node) > 0)value = ts_node_named_child(node, ts_node_named_child_count(node) - 1);- char* text = cbm_node_text(arena, node, source);+ char *text = cbm_node_text(arena, node, source);int dir = 0;if (text) {- if (strncmp(text, "chan<-", 6) == 0 || strncmp(text, "chan <-", 7) == 0) dir = 1;- else if (strncmp(text, "<-chan", 6) == 0 || strncmp(text, "<- chan", 7) == 0) dir = 2;+ if (strncmp(text, "chan<-", 6) == 0 || strncmp(text, "chan <-", 7) == 0)+ dir = 1;+ else if (strncmp(text, "<-chan", 6) == 0 || strncmp(text, "<- chan", 7) == 0)+ dir = 2;}- return cbm_type_channel(arena, parse_type_node_with_params(arena,- value, source, module_qn, type_param_names), dir);+ return cbm_type_channel(+ arena, parse_type_node_with_params(arena, value, source, module_qn, type_param_names),+ dir);}// function_type: func(T) R — full parsing with type param awareness@@ -2709,51 +2891,54 @@ static const CBMType* parse_type_node_with_params(CBMArena* arena, TSNode node,TSNode params_node = ts_node_child_by_field_name(node, "parameters", 10);TSNode result_node = ts_node_child_by_field_name(node, "result", 6);- const CBMType* param_types_arr[16];+ const CBMType *param_types_arr[16];int pc = 0;if (!ts_node_is_null(params_node)) {uint32_t pnc = ts_node_child_count(params_node);for (uint32_t i = 0; i < pnc && pc < 15; i++) {TSNode child = ts_node_child(params_node, i);- if (ts_node_is_null(child) || !ts_node_is_named(child)) continue;+ if (ts_node_is_null(child) || !ts_node_is_named(child))+ continue;if (strcmp(ts_node_type(child), "parameter_declaration") == 0) {TSNode pt = ts_node_child_by_field_name(child, "type", 4);if (!ts_node_is_null(pt))- param_types_arr[pc++] = parse_type_node_with_params(arena,- pt, source, module_qn, type_param_names);+ param_types_arr[pc++] = parse_type_node_with_params(+ arena, pt, source, module_qn, type_param_names);}}}param_types_arr[pc] = NULL;- const CBMType* ret_types_arr[16];+ const CBMType *ret_types_arr[16];int rc = 0;if (!ts_node_is_null(result_node)) {if (strcmp(ts_node_type(result_node), "parameter_list") == 0) {uint32_t rnc = ts_node_child_count(result_node);for (uint32_t i = 0; i < rnc && rc < 15; i++) {TSNode child = ts_node_child(result_node, i);- if (ts_node_is_null(child) || !ts_node_is_named(child)) continue;+ if (ts_node_is_null(child) || !ts_node_is_named(child))+ continue;TSNode rt = ts_node_child_by_field_name(child, "type", 4);- if (ts_node_is_null(rt)) rt = child;- ret_types_arr[rc++] = parse_type_node_with_params(arena,- rt, source, module_qn, type_param_names);+ if (ts_node_is_null(rt))+ rt = child;+ ret_types_arr[rc++] =+ parse_type_node_with_params(arena, rt, source, module_qn, type_param_names);}} else {- ret_types_arr[rc++] = parse_type_node_with_params(arena,- result_node, source, module_qn, type_param_names);+ ret_types_arr[rc++] = parse_type_node_with_params(arena, result_node, source,+ module_qn, type_param_names);}}ret_types_arr[rc] = NULL;- const CBMType** pt = pc > 0 ? (const CBMType**)param_types_arr : NULL;- const CBMType** rt = rc > 0 ? (const CBMType**)ret_types_arr : NULL;+ const CBMType **pt = pc > 0 ? (const CBMType **)param_types_arr : NULL;+ const CBMType **rt = rc > 0 ? (const CBMType **)ret_types_arr : NULL;return cbm_type_func(arena, NULL, pt, rt);}// interface_typeif (strcmp(kind, "interface_type") == 0) {- CBMType* t = (CBMType*)cbm_arena_alloc(arena, sizeof(CBMType));+ CBMType *t = (CBMType *)cbm_arena_alloc(arena, sizeof(CBMType));memset(t, 0, sizeof(CBMType));t->kind = CBM_TYPE_INTERFACE;return t;@@ -2761,15 +2946,16 @@ static const CBMType* parse_type_node_with_params(CBMArena* arena, TSNode node,// parenthesized_type: (T)if (strcmp(kind, "parenthesized_type") == 0 && ts_node_named_child_count(node) > 0) {- return parse_type_node_with_params(arena, ts_node_named_child(node, 0),- source, module_qn, type_param_names);+ return parse_type_node_with_params(arena, ts_node_named_child(node, 0), source, module_qn,+ type_param_names);}// generic_type: Type[T1, T2]if (strcmp(kind, "generic_type") == 0) {TSNode type_node = ts_node_child_by_field_name(node, "type", 4);if (!ts_node_is_null(type_node))- return parse_type_node_with_params(arena, type_node, source, module_qn, type_param_names);+ return parse_type_node_with_params(arena, type_node, source, module_qn,+ type_param_names);}return cbm_type_unknown();@@ -2813,34 +2999,40 @@ static const CBMType *cbm_go_lsp_keep_known_refinement(const CBMType *candidate,// Scan AST for generic function declarations and set type_param_names + re-parse// return types on matching registered functions.-static void extract_type_params_from_ast(CBMArena* arena, CBMTypeRegistry* reg,- TSNode root, const char* source, const char* module_qn) {+static void extract_type_params_from_ast(CBMArena *arena, CBMTypeRegistry *reg, TSNode root,+ const char *source, const char *module_qn) {// Collect top-level children once (O(n)); ts_node_child(root,i) is O(i) → O(n²).uint32_t rkn = 0;- TSNode* rkids = cbm_lsp_collect_children(arena, root, &rkn);+ TSNode *rkids = cbm_lsp_collect_children(arena, root, &rkn);for (uint32_t i = 0; i < rkn; i++) {TSNode top = rkids[i];- if (strcmp(ts_node_type(top), "function_declaration") != 0) continue;+ if (strcmp(ts_node_type(top), "function_declaration") != 0)+ continue;// Check for type_parameter_list (field name: "type_parameters", 15 chars)TSNode tp_list = ts_node_child_by_field_name(top, "type_parameters", 15);- if (ts_node_is_null(tp_list)) continue;+ if (ts_node_is_null(tp_list))+ continue;// Get function nameTSNode name_node = ts_node_child_by_field_name(top, "name", 4);- if (ts_node_is_null(name_node)) continue;- char* func_name = cbm_node_text(arena, name_node, source);- if (!func_name || !func_name[0]) continue;+ if (ts_node_is_null(name_node))+ continue;+ char *func_name = cbm_node_text(arena, name_node, source);+ if (!func_name || !func_name[0])+ continue;// Extract type param names from type_parameter_declaration children- const char* params[16];+ const char *params[16];int param_count = 0;uint32_t tp_nc = ts_node_child_count(tp_list);for (uint32_t j = 0; j < tp_nc && param_count < 15; j++) {TSNode child = ts_node_child(tp_list, j);- if (ts_node_is_null(child) || !ts_node_is_named(child)) continue;- if (strcmp(ts_node_type(child), "type_parameter_declaration") != 0) continue;+ if (ts_node_is_null(child) || !ts_node_is_named(child))+ continue;+ if (strcmp(ts_node_type(child), "type_parameter_declaration") != 0)+ continue;TSNode pname = ts_node_child_by_field_name(child, "name", 4);if (ts_node_is_null(pname)) {// Fallback: first type_identifier child@@ -2855,21 +3047,24 @@ static void extract_type_params_from_ast(CBMArena* arena, CBMTypeRegistry* reg,}}if (!ts_node_is_null(pname)) {- char* pn = cbm_node_text(arena, pname, source);+ char *pn = cbm_node_text(arena, pname, source);if (pn && pn[0]) {params[param_count++] = cbm_arena_strdup(arena, pn);}}}- if (param_count == 0) continue;+ if (param_count == 0)+ continue;params[param_count] = NULL;// Build arena-allocated type_param_names array- const char** tp_names = (const char**)cbm_arena_alloc(arena, (param_count + 1) * sizeof(const char*));- for (int j = 0; j <= param_count; j++) tp_names[j] = params[j];+ const char **tp_names =+ (const char **)cbm_arena_alloc(arena, (param_count + 1) * sizeof(const char *));+ for (int j = 0; j <= param_count; j++)+ tp_names[j] = params[j];// Find the matching registered function and set type_param_names- const char* func_qn = cbm_arena_sprintf(arena, "%s.%s", module_qn, func_name);+ const char *func_qn = cbm_arena_sprintf(arena, "%s.%s", module_qn, func_name);for (int fi = 0; fi < reg->func_count; fi++) {if (reg->funcs[fi].qualified_name &&strcmp(reg->funcs[fi].qualified_name, func_qn) == 0) {@@ -2878,23 +3073,24 @@ static void extract_type_params_from_ast(CBMArena* arena, CBMTypeRegistry* reg,// Re-parse return types with type param awarenessif (reg->funcs[fi].signature && reg->funcs[fi].signature->kind == CBM_TYPE_FUNC &®->funcs[fi].signature->data.func.return_types) {- const CBMType** old_rets = reg->funcs[fi].signature->data.func.return_types;+ const CBMType **old_rets = reg->funcs[fi].signature->data.func.return_types;int ret_count = 0;- while (old_rets[ret_count]) ret_count++;+ while (old_rets[ret_count])+ ret_count++;// Check if any return type is a NAMED that matches a type parambool needs_reparse = false;for (int ri = 0; ri < ret_count && !needs_reparse; ri++) {- const CBMType* check = old_rets[ri];+ const CBMType *check = old_rets[ri];// Unwrap slice/pointer to get inner named typeif (check->kind == CBM_TYPE_SLICE && check->data.slice.elem)check = check->data.slice.elem;else if (check->kind == CBM_TYPE_POINTER && check->data.pointer.elem)check = check->data.pointer.elem;if (check->kind == CBM_TYPE_NAMED) {- const char* qn = check->data.named.qualified_name;- const char* dot = strrchr(qn, '.');- const char* short_name = dot ? dot + 1 : qn;+ const char *qn = check->data.named.qualified_name;+ const char *dot = strrchr(qn, '.');+ const char *short_name = dot ? dot + 1 : qn;for (int pi = 0; pi < param_count; pi++) {if (strcmp(short_name, tp_names[pi]) == 0) {needs_reparse = true;@@ -2907,17 +3103,19 @@ static void extract_type_params_from_ast(CBMArena* arena, CBMTypeRegistry* reg,if (needs_reparse) {TSNode result_node = ts_node_child_by_field_name(top, "result", 6);if (!ts_node_is_null(result_node)) {- const CBMType** new_rets = (const CBMType**)cbm_arena_alloc(arena,- (ret_count + 1) * sizeof(const CBMType*));+ const CBMType **new_rets = (const CBMType **)cbm_arena_alloc(+ arena, (ret_count + 1) * sizeof(const CBMType *));if (strcmp(ts_node_type(result_node), "parameter_list") == 0) {int idx = 0;uint32_t rnc = ts_node_child_count(result_node);for (uint32_t ri = 0; ri < rnc && idx < ret_count; ri++) {TSNode rchild = ts_node_child(result_node, ri);- if (ts_node_is_null(rchild) || !ts_node_is_named(rchild)) continue;+ if (ts_node_is_null(rchild) || !ts_node_is_named(rchild))+ continue;TSNode rtype = ts_node_child_by_field_name(rchild, "type", 4);- if (ts_node_is_null(rtype)) rtype = rchild;+ if (ts_node_is_null(rtype))+ rtype = rchild;const CBMType *parsed = parse_type_node_with_params(arena, rtype, source, module_qn, tp_names);new_rets[idx] =@@ -2951,20 +3149,22 @@ static void extract_type_params_from_ast(CBMArena* arena, CBMTypeRegistry* reg,// Also re-parse param types with TYPE_PARAM awareness (for implicit generics)if (reg->funcs[fi].signature && reg->funcs[fi].signature->kind == CBM_TYPE_FUNC &®->funcs[fi].signature->data.func.param_types) {- const CBMType** old_params = reg->funcs[fi].signature->data.func.param_types;+ const CBMType **old_params = reg->funcs[fi].signature->data.func.param_types;int pc = 0;- while (old_params[pc]) pc++;+ while (old_params[pc])+ pc++;// Re-parse from AST parameter listTSNode params_node = ts_node_child_by_field_name(top, "parameters", 10);if (!ts_node_is_null(params_node)) {- const CBMType** new_params = (const CBMType**)cbm_arena_alloc(arena,- (pc + 1) * sizeof(const CBMType*));+ const CBMType **new_params = (const CBMType **)cbm_arena_alloc(+ arena, (pc + 1) * sizeof(const CBMType *));int idx = 0;bool overflow = false;uint32_t pnc = ts_node_child_count(params_node);for (uint32_t pi = 0; pi < pnc && !overflow; pi++) {TSNode pchild = ts_node_child(params_node, pi);- if (ts_node_is_null(pchild) || !ts_node_is_named(pchild)) continue;+ if (ts_node_is_null(pchild) || !ts_node_is_named(pchild))+ continue;const char *param_kind = ts_node_type(pchild);if (strcmp(param_kind, "parameter_declaration") != 0 &&strcmp(param_kind, "variadic_parameter_declaration") != 0) {@@ -3006,30 +3206,30 @@ static void extract_type_params_from_ast(CBMArena* arena, CBMTypeRegistry* reg,}// Forward: tree-sitter Go language (from lang_specs.c)-extern const TSLanguage* tree_sitter_go(void);--void cbm_run_go_lsp_cross(- CBMArena* arena,- const char* source, int source_len,- const char* module_qn,- CBMLSPDef* defs, int def_count,- const char** import_names, const char** import_qns, int import_count,- TSTree* cached_tree,- CBMResolvedCallArray* out)-{- if (!source || source_len <= 0) return;+extern const TSLanguage *tree_sitter_go(void);++void cbm_run_go_lsp_cross(CBMArena *arena, const char *source, int source_len,+ const char *module_qn, CBMLSPDef *defs, int def_count,+ const char **import_names, const char **import_qns, int import_count,+ TSTree *cached_tree, CBMResolvedCallArray *out) {+ if (!source || source_len <= 0)+ return;// 1. Use cached tree if available, otherwise parse fresh- TSParser* parser = NULL;- TSTree* tree = cached_tree;+ TSParser *parser = NULL;+ TSTree *tree = cached_tree;bool owns_tree = false;if (!tree) {parser = ts_parser_new();- if (!parser) return;+ if (!parser)+ return;ts_parser_set_language(parser, tree_sitter_go());tree = ts_parser_parse_string(parser, NULL, source, source_len);owns_tree = true;- if (!tree) { ts_parser_delete(parser); return; }+ if (!tree) {+ ts_parser_delete(parser);+ return;+ }}TSNode root = ts_tree_root_node(tree);@@ -3044,18 +3244,19 @@ void cbm_run_go_lsp_cross(// wasted work. On kubernetes (~110k defs × 11k files × 5 strdups// ~= 6B mallocs) this alone saves ~90s of resolve wall time.for (int i = 0; i < def_count; i++) {- CBMLSPDef* d = &defs[i];- if (!d->qualified_name || !d->short_name || !d->label) continue;+ CBMLSPDef *d = &defs[i];+ if (!d->qualified_name || !d->short_name || !d->label)+ continue;- const char* def_mod = d->def_module_qn ? d->def_module_qn : module_qn;+ const char *def_mod = d->def_module_qn ? d->def_module_qn : module_qn;// Every type-like container (Type/Class/Struct/Interface/Enum/Trait).// Struct included so Go structs (now labelled "Struct") register as types.if (cbm_label_is_type_like(d->label)) {CBMRegisteredType rt;memset(&rt, 0, sizeof(rt));- rt.qualified_name = d->qualified_name; // borrowed- rt.short_name = d->short_name; // borrowed+ rt.qualified_name = d->qualified_name; // borrowed+ rt.short_name = d->short_name; // borrowedrt.is_interface = d->is_interface || strcmp(d->label, "Interface") == 0;rt.embedded_types = split_pipe_strings(arena, d->embedded_types);@@ -3076,11 +3277,11 @@ void cbm_run_go_lsp_cross(if (strcmp(d->label, "Function") == 0 || strcmp(d->label, "Method") == 0) {CBMRegisteredFunc rf;memset(&rf, 0, sizeof(rf));- rf.qualified_name = d->qualified_name; // borrowed- rf.short_name = d->short_name; // borrowed+ rf.qualified_name = d->qualified_name; // borrowed+ rf.short_name = d->short_name; // borrowed// Build FUNC type from return_types text- const CBMType** ret_types = split_pipe_types(arena, d->return_types, def_mod);+ const CBMType **ret_types = split_pipe_types(arena, d->return_types, def_mod);CBMGoLSPSignatureParserContext param_parser_ctx = {def_mod};const CBMType **param_types = cbm_type_materialize_signature_params(arena, d->signature_param_types, d->signature_param_count,@@ -3089,14 +3290,14 @@ void cbm_run_go_lsp_cross(// Method receiverif (strcmp(d->label, "Method") == 0 && d->receiver_type && d->receiver_type[0]) {- rf.receiver_type = d->receiver_type; // borrowed+ rf.receiver_type = d->receiver_type; // borrowed// Auto-create type entry if not existsif (!cbm_registry_lookup_type(®, rf.receiver_type)) {CBMRegisteredType auto_type;memset(&auto_type, 0, sizeof(auto_type));auto_type.qualified_name = rf.receiver_type;- const char* dot = strrchr(d->receiver_type, '.');- auto_type.short_name = dot ? dot + 1 : rf.receiver_type; // borrowed substring+ const char *dot = strrchr(d->receiver_type, '.');+ auto_type.short_name = dot ? dot + 1 : rf.receiver_type; // borrowed substringcbm_registry_add_type(®, auto_type);}}@@ -3109,26 +3310,30 @@ void cbm_run_go_lsp_cross({// Collect top-level children once (O(n)); ts_node_child(root,i) is O(i) → O(n²).uint32_t rkn = 0;- TSNode* rkids = cbm_lsp_collect_children(arena, root, &rkn);+ TSNode *rkids = cbm_lsp_collect_children(arena, root, &rkn);for (uint32_t i = 0; i < rkn; i++) {TSNode top = rkids[i];- if (strcmp(ts_node_type(top), "type_declaration") != 0) continue;+ if (strcmp(ts_node_type(top), "type_declaration") != 0)+ continue;uint32_t td_nc = ts_node_child_count(top);for (uint32_t j = 0; j < td_nc; j++) {TSNode spec = ts_node_child(top, j);- if (ts_node_is_null(spec) || !ts_node_is_named(spec)) continue;- const char* spec_kind2 = ts_node_type(spec);+ if (ts_node_is_null(spec) || !ts_node_is_named(spec))+ continue;+ const char *spec_kind2 = ts_node_type(spec);// type_alias: type Foo = Barif (strcmp(spec_kind2, "type_alias") == 0) {TSNode alias_name = ts_node_child_by_field_name(spec, "name", 4);TSNode alias_type = ts_node_child_by_field_name(spec, "type", 4);if (!ts_node_is_null(alias_name) && !ts_node_is_null(alias_type)) {- char* aname = cbm_node_text(arena, alias_name, source);- char* atarget = cbm_node_text(arena, alias_type, source);+ char *aname = cbm_node_text(arena, alias_name, source);+ char *atarget = cbm_node_text(arena, alias_type, source);if (aname && aname[0] && atarget && atarget[0]) {- const char* alias_type_qn = cbm_arena_sprintf(arena, "%s.%s", module_qn, aname);- const char* alias_target_qn = cbm_arena_sprintf(arena, "%s.%s", module_qn, atarget);+ const char *alias_type_qn =+ cbm_arena_sprintf(arena, "%s.%s", module_qn, aname);+ const char *alias_target_qn =+ cbm_arena_sprintf(arena, "%s.%s", module_qn, atarget);bool found_a = false;for (int ti = 0; ti < reg.type_count; ti++) {if (reg.types[ti].qualified_name &&@@ -3151,28 +3356,33 @@ void cbm_run_go_lsp_cross(continue;}- if (strcmp(spec_kind2, "type_spec") != 0) continue;+ if (strcmp(spec_kind2, "type_spec") != 0)+ continue;TSNode name_node = ts_node_child_by_field_name(spec, "name", 4);TSNode type_node = ts_node_child_by_field_name(spec, "type", 4);- if (ts_node_is_null(name_node) || ts_node_is_null(type_node)) continue;- if (strcmp(ts_node_type(type_node), "struct_type") != 0) continue;+ if (ts_node_is_null(name_node) || ts_node_is_null(type_node))+ continue;+ if (strcmp(ts_node_type(type_node), "struct_type") != 0)+ continue;- char* type_name = cbm_node_text(arena, name_node, source);- if (!type_name || !type_name[0]) continue;- const char* type_qn = cbm_arena_sprintf(arena, "%s.%s", module_qn, type_name);+ char *type_name = cbm_node_text(arena, name_node, source);+ if (!type_name || !type_name[0])+ continue;+ const char *type_qn = cbm_arena_sprintf(arena, "%s.%s", module_qn, type_name);TSNode field_list = ts_node_child_by_field_name(type_node, "body", 4);if (ts_node_is_null(field_list)) {if (ts_node_named_child_count(type_node) > 0)field_list = ts_node_named_child(type_node, 0);}- if (ts_node_is_null(field_list)) continue;+ if (ts_node_is_null(field_list))+ continue;- const char* embeds[16];+ const char *embeds[16];int embed_count = 0;- const char* fld_names[64];- const CBMType* fld_types[64];+ const char *fld_names[64];+ const CBMType *fld_types[64];int fld_count = 0;GoLSPContext tmp_ctx;@@ -3189,21 +3399,26 @@ void cbm_run_go_lsp_cross(uint32_t fl_nc = ts_node_child_count(field_list);for (uint32_t k = 0; k < fl_nc; k++) {TSNode field = ts_node_child(field_list, k);- if (ts_node_is_null(field) || !ts_node_is_named(field)) continue;- if (strcmp(ts_node_type(field), "field_declaration") != 0) continue;+ if (ts_node_is_null(field) || !ts_node_is_named(field))+ continue;+ if (strcmp(ts_node_type(field), "field_declaration") != 0)+ continue;TSNode fname = ts_node_child_by_field_name(field, "name", 4);TSNode ftype = ts_node_child_by_field_name(field, "type", 4);if (ts_node_is_null(fname) && !ts_node_is_null(ftype)) {if (embed_count < 15) {- char* embed_text = cbm_node_text(arena, ftype, source);+ char *embed_text = cbm_node_text(arena, ftype, source);if (embed_text && embed_text[0]) {- const char* et = embed_text;- while (*et == '*') et++;- embeds[embed_count++] = cbm_arena_sprintf(arena, "%s.%s", module_qn, et);+ const char *et = embed_text;+ while (*et == '*')+ et++;+ embeds[embed_count++] =+ cbm_arena_sprintf(arena, "%s.%s", module_qn, et);}}- } else if (!ts_node_is_null(fname) && !ts_node_is_null(ftype) && fld_count < 63) {- char* fn = cbm_node_text(arena, fname, source);+ } else if (!ts_node_is_null(fname) && !ts_node_is_null(ftype) &&+ fld_count < 63) {+ char *fn = cbm_node_text(arena, fname, source);if (fn && fn[0]) {fld_names[fld_count] = fn;fld_types[fld_count] = go_parse_type_node(&tmp_ctx, ftype);@@ -3214,20 +3429,22 @@ void cbm_run_go_lsp_cross(for (int ti = 0; ti < reg.type_count; ti++) {if (!reg.types[ti].qualified_name ||- strcmp(reg.types[ti].qualified_name, type_qn) != 0) continue;+ strcmp(reg.types[ti].qualified_name, type_qn) != 0)+ continue;if (embed_count > 0) {- const char** arr = (const char**)cbm_arena_alloc(arena,- (embed_count + 1) * sizeof(const char*));- for (int ei = 0; ei < embed_count; ei++) arr[ei] = embeds[ei];+ const char **arr = (const char **)cbm_arena_alloc(+ arena, (embed_count + 1) * sizeof(const char *));+ for (int ei = 0; ei < embed_count; ei++)+ arr[ei] = embeds[ei];arr[embed_count] = NULL;reg.types[ti].embedded_types = arr;}if (fld_count > 0) {- const char** names = (const char**)cbm_arena_alloc(arena,- (fld_count + 1) * sizeof(const char*));- const CBMType** types = (const CBMType**)cbm_arena_alloc(arena,- (fld_count + 1) * sizeof(const CBMType*));+ const char **names = (const char **)cbm_arena_alloc(+ arena, (fld_count + 1) * sizeof(const char *));+ const CBMType **types = (const CBMType **)cbm_arena_alloc(+ arena, (fld_count + 1) * sizeof(const CBMType *));for (int fi = 0; fi < fld_count; fi++) {names[fi] = fld_names[fi];types[fi] = fld_types[fi];@@ -3269,7 +3486,8 @@ void cbm_run_go_lsp_cross(// 5. Cleanup — only free if we allocatedif (owns_tree) {ts_tree_delete(tree);- if (parser) ts_parser_delete(parser);+ if (parser)+ ts_parser_delete(parser);}}@@ -3288,11 +3506,12 @@ void cbm_run_go_lsp_cross(* 1b (and not already in defs[] embedded_types/field_defs strings) are* missed. In practice the per-file LSP during extract already captures* those via the def strings. */-CBMTypeRegistry* cbm_go_build_cross_registry(- CBMArena* arena, CBMLSPDef* defs, int def_count) {- if (!arena) return NULL;- CBMTypeRegistry* reg = (CBMTypeRegistry*)cbm_arena_alloc(arena, sizeof(*reg));- if (!reg) return NULL;+CBMTypeRegistry *cbm_go_build_cross_registry(CBMArena *arena, CBMLSPDef *defs, int def_count) {+ if (!arena)+ return NULL;+ CBMTypeRegistry *reg = (CBMTypeRegistry *)cbm_arena_alloc(arena, sizeof(*reg));+ if (!reg)+ return NULL;cbm_registry_init(reg, arena);cbm_go_stdlib_register(reg, arena);@@ -3304,28 +3523,30 @@ CBMTypeRegistry* cbm_go_build_cross_registry(* 2026-09-17). First-match semantics are kept exactly: a receiver's* placeholder type added before its struct still receives the fields.* NULL on allocation failure: the linear paths below run as before. */- CBMHashTable* first_type = cbm_ht_create((uint32_t)(def_count / 4 + 1024));+ CBMHashTable *first_type = cbm_ht_create((uint32_t)(def_count / 4 + 1024));int noted_types = 0;-#define GO_NOTE_NEW_TYPES() \- do { \- for (; first_type && noted_types < reg->type_count; noted_types++) { \- const char* tqn = reg->types[noted_types].qualified_name; \- if (tqn && !cbm_ht_has(first_type, tqn)) { \- cbm_ht_set(first_type, tqn, (void*)(uintptr_t)(noted_types + 1)); \- } \- } \+#define GO_NOTE_NEW_TYPES() \+ do { \+ for (; first_type && noted_types < reg->type_count; noted_types++) { \+ const char *tqn = reg->types[noted_types].qualified_name; \+ if (tqn && !cbm_ht_has(first_type, tqn)) { \+ cbm_ht_set(first_type, tqn, (void *)(uintptr_t)(noted_types + 1)); \+ } \+ } \} while (0)GO_NOTE_NEW_TYPES();for (int i = 0; i < def_count; i++) {- CBMLSPDef* d = &defs[i];- if (!d->qualified_name || !d->short_name || !d->label) continue;+ CBMLSPDef *d = &defs[i];+ if (!d->qualified_name || !d->short_name || !d->label)+ continue;/* Filter to Go defs only — the all_defs[] array is mixed-language. */- if (d->lang != CBM_LANG_GO) continue;+ if (d->lang != CBM_LANG_GO)+ continue;/* In the pre-built path every def carries its own def_module_qn* (set by cbm_pxc_collect_all_defs). There is no caller module to* fall back to — this registry is project-wide, not per-file. */- const char* def_mod = d->def_module_qn ? d->def_module_qn : "";+ const char *def_mod = d->def_module_qn ? d->def_module_qn : "";// Every type-like container (Type/Class/Struct/Interface/Enum/Trait).// Struct included so Go structs (now labelled "Struct") register as types.@@ -3343,16 +3564,16 @@ CBMTypeRegistry* cbm_go_build_cross_registry(GO_NOTE_NEW_TYPES();if (d->field_defs && d->field_defs[0]) {if (first_type) {- const char** names = NULL;- const CBMType** types = NULL;+ const char **names = NULL;+ const CBMType **types = NULL;uintptr_t at = (uintptr_t)cbm_ht_get(first_type, rt.qualified_name);if (parse_field_defs(arena, d->field_defs, def_mod, &names, &types) && at) {reg->types[at - 1].field_names = names;reg->types[at - 1].field_types = types;}} else {- parse_field_defs_into_type(arena, reg, rt.qualified_name,- d->field_defs, def_mod);+ parse_field_defs_into_type(arena, reg, rt.qualified_name, d->field_defs,+ def_mod);}}}@@ -3362,7 +3583,7 @@ CBMTypeRegistry* cbm_go_build_cross_registry(memset(&rf, 0, sizeof(rf));rf.qualified_name = d->qualified_name; /* borrowed */rf.short_name = d->short_name;- const CBMType** ret_types = split_pipe_types(arena, d->return_types, def_mod);+ const CBMType **ret_types = split_pipe_types(arena, d->return_types, def_mod);CBMGoLSPSignatureParserContext param_parser_ctx = {def_mod};const CBMType **param_types = cbm_type_materialize_signature_params(arena, d->signature_param_types, d->signature_param_count,@@ -3376,7 +3597,7 @@ CBMTypeRegistry* cbm_go_build_cross_registry(CBMRegisteredType auto_type;memset(&auto_type, 0, sizeof(auto_type));auto_type.qualified_name = rf.receiver_type;- const char* dot = strrchr(d->receiver_type, '.');+ const char *dot = strrchr(d->receiver_type, '.');auto_type.short_name = dot ? dot + 1 : rf.receiver_type;cbm_registry_add_type(reg, auto_type);GO_NOTE_NEW_TYPES();@@ -3393,26 +3614,28 @@ CBMTypeRegistry* cbm_go_build_cross_registry(return reg;}-void cbm_run_go_lsp_cross_with_registry(- CBMArena* arena,- const char* source, int source_len,- const char* module_qn,- CBMTypeRegistry* reg,- const char** import_names, const char** import_qns, int import_count,- TSTree* cached_tree,- CBMResolvedCallArray* out) {- if (!source || source_len <= 0 || !reg) return;-- TSParser* parser = NULL;- TSTree* tree = cached_tree;+void cbm_run_go_lsp_cross_with_registry(CBMArena *arena, const char *source, int source_len,+ const char *module_qn, CBMTypeRegistry *reg,+ const char **import_names, const char **import_qns,+ int import_count, TSTree *cached_tree,+ CBMResolvedCallArray *out) {+ if (!source || source_len <= 0 || !reg)+ return;++ TSParser *parser = NULL;+ TSTree *tree = cached_tree;bool owns_tree = false;if (!tree) {parser = ts_parser_new();- if (!parser) return;+ if (!parser)+ return;ts_parser_set_language(parser, tree_sitter_go());tree = ts_parser_parse_string(parser, NULL, source, source_len);owns_tree = true;- if (!tree) { ts_parser_delete(parser); return; }+ if (!tree) {+ ts_parser_delete(parser);+ return;+ }}TSNode root = ts_tree_root_node(tree);@@ -3430,7 +3653,8 @@ void cbm_run_go_lsp_cross_with_registry(if (owns_tree) {ts_tree_delete(tree);- if (parser) ts_parser_delete(parser);+ if (parser)+ ts_parser_delete(parser);}}@@ -3461,46 +3685,47 @@ void cbm_run_go_lsp_cross_with_registry(* This is what the user meant: walk the AST ONCE (during extract),* capture everything cross-LSP needs as metadata, and let cross-LSP* be a pure lookup pass. */-int cbm_go_fast_resolve_qualified_calls(- CBMFileResult* result,- CBMTypeRegistry* reg,- const char** import_names, const char** import_qns, int import_count) {- if (!result || !reg) return 0;+int cbm_go_fast_resolve_qualified_calls(CBMFileResult *result, CBMTypeRegistry *reg,+ const char **import_names, const char **import_qns,+ int import_count) {+ if (!result || !reg)+ return 0;/* Snapshot the count: we append to resolved_calls inside the loop,* but only want to scan the original unresolved entries. */int initial_count = result->resolved_calls.count;int newly_resolved = 0;for (int i = 0; i < initial_count; i++) {- const CBMResolvedCall* uc = &result->resolved_calls.items[i];- if (!uc->strategy || !uc->callee_qn || !uc->caller_qn) continue;- if (strcmp(uc->strategy, "lsp_unresolved") != 0) continue;+ const CBMResolvedCall *uc = &result->resolved_calls.items[i];+ if (!uc->strategy || !uc->callee_qn || !uc->caller_qn)+ continue;+ if (strcmp(uc->strategy, "lsp_unresolved") != 0)+ continue;/* Case 1: callee_qn is already a fully-qualified type/pkg* symbol that per-file LSP couldn't find in its local registry* but the global registry has. (method_not_found with NAMED* receiver, or any other case where callee_qn looks like a* full QN). Direct lookup. */- const CBMRegisteredFunc* f = cbm_registry_lookup_func(reg, uc->callee_qn);+ const CBMRegisteredFunc *f = cbm_registry_lookup_func(reg, uc->callee_qn);/* Case 2: callee_qn is "local_pkg_alias.suffix" — the alias* needs translating through the file's import map to get the* real module QN. */if (!f) {- const char* dot = strchr(uc->callee_qn, '.');+ const char *dot = strchr(uc->callee_qn, '.');if (dot) {size_t prefix_len = (size_t)(dot - uc->callee_qn);if (prefix_len > 0 && prefix_len < 256) {char prefix[256];memcpy(prefix, uc->callee_qn, prefix_len);prefix[prefix_len] = '\0';- const char* suffix = dot + 1;+ const char *suffix = dot + 1;for (int j = 0; j < import_count; j++) {if (import_names[j] && import_qns[j] &&strcmp(prefix, import_names[j]) == 0) {char fq[1024];- int n = snprintf(fq, sizeof(fq), "%s.%s",- import_qns[j], suffix);+ int n = snprintf(fq, sizeof(fq), "%s.%s", import_qns[j], suffix);if (n > 0 && n < (int)sizeof(fq)) {f = cbm_registry_lookup_func(reg, fq);}@@ -3519,7 +3744,8 @@ int cbm_go_fast_resolve_qualified_calls(f = cbm_registry_lookup_symbol(reg, result->module_qn, uc->callee_qn);}- if (!f) continue;+ if (!f)+ continue;/* Emit a resolved entry. cbm_pipeline_find_lsp_resolution* picks the highest-confidence match, so the unresolved entry@@ -3546,18 +3772,17 @@ int cbm_go_fast_resolve_qualified_calls(// --- Batch cross-file LSP ----void cbm_batch_go_lsp_cross(- CBMArena* arena,- CBMBatchGoLSPFile* files, int file_count,- CBMResolvedCallArray* out)-{- if (!files || file_count <= 0 || !out) return;+void cbm_batch_go_lsp_cross(CBMArena *arena, CBMBatchGoLSPFile *files, int file_count,+ CBMResolvedCallArray *out) {+ if (!files || file_count <= 0 || !out)+ return;for (int f = 0; f < file_count; f++) {- CBMBatchGoLSPFile* file = &files[f];+ CBMBatchGoLSPFile *file = &files[f];memset(&out[f], 0, sizeof(CBMResolvedCallArray));- if (!file->source || file->source_len <= 0 || file->def_count <= 0) continue;+ if (!file->source || file->source_len <= 0 || file->def_count <= 0)+ continue;// Per-file arena: registry + temp data freed after each fileCBMArena file_arena;@@ -3567,29 +3792,24 @@ void cbm_batch_go_lsp_cross(memset(&file_out, 0, sizeof(file_out));// Delegate to existing per-file function- cbm_run_go_lsp_cross(- &file_arena,- file->source, file->source_len,- file->module_qn,- file->defs, file->def_count,- file->import_names, file->import_qns, file->import_count,- file->cached_tree,- &file_out);+ cbm_run_go_lsp_cross(&file_arena, file->source, file->source_len, file->module_qn,+ file->defs, file->def_count, file->import_names, file->import_qns,+ file->import_count, file->cached_tree, &file_out);// Copy results to output arena (must outlive per-file arena)if (file_out.count > 0) {out[f].count = file_out.count;- out[f].items = (CBMResolvedCall*)cbm_arena_alloc(arena,- file_out.count * sizeof(CBMResolvedCall));+ out[f].items =+ (CBMResolvedCall *)cbm_arena_alloc(arena, file_out.count * sizeof(CBMResolvedCall));for (int j = 0; j < file_out.count; j++) {- CBMResolvedCall* src = &file_out.items[j];- CBMResolvedCall* dst = &out[f].items[j];+ CBMResolvedCall *src = &file_out.items[j];+ CBMResolvedCall *dst = &out[f].items[j];memset(dst, 0, sizeof(*dst));dst->caller_qn = src->caller_qn ? cbm_arena_strdup(arena, src->caller_qn) : NULL;dst->callee_qn = src->callee_qn ? cbm_arena_strdup(arena, src->callee_qn) : NULL;- dst->strategy = src->strategy ? cbm_arena_strdup(arena, src->strategy) : NULL;+ dst->strategy = src->strategy ? cbm_arena_strdup(arena, src->strategy) : NULL;dst->confidence = src->confidence;- dst->reason = src->reason ? cbm_arena_strdup(arena, src->reason) : NULL;+ dst->reason = src->reason ? cbm_arena_strdup(arena, src->reason) : NULL;dst->kind = src->kind;dst->site_start_byte = src->site_start_byte;dst->site_end_byte = src->site_end_byte;diff --git a/internal/cbm/result_compact.c b/internal/cbm/result_compact.cindex 47bf44e66..d237b2a17 100644--- a/internal/cbm/result_compact.c+++ b/internal/cbm/result_compact.c@@ -449,7 +449,9 @@ static bool cr_scratch_get(cr_ctx_t *c) {if (!buf) {return false;}- memset(buf, 0, slot_bytes); /* MEASURE needs an empty table; the sequence is written before it is read */+ memset(+ buf, 0,+ slot_bytes); /* MEASURE needs an empty table; the sequence is written before it is read */c->slots = (cr_slot_t *)buf;c->seq = c->refs ? (uint32_t *)((char *)buf + slot_bytes) : NULL;return true;diff --git a/internal/cbm/sqlite_writer.c b/internal/cbm/sqlite_writer.cindex bbec4ed46..55ab937d4 100644--- a/internal/cbm/sqlite_writer.c+++ b/internal/cbm/sqlite_writer.c@@ -15,8 +15,8 @@// - Varints: 1-9 bytes, big-endian, MSB continuation#include "sqlite_writer.h"-#include "foundation/arena.h" /* index-cell arena */-#include "foundation/compat.h" /* CBM_TLS */+#include "foundation/arena.h" /* index-cell arena */+#include "foundation/compat.h" /* CBM_TLS */#include "foundation/constants.h"#include "foundation/compat_fs.h"#include "foundation/compat_thread.h"diff --git a/scripts/memory-core-baseline.txt b/scripts/memory-core-baseline.txtindex 29a58da11..8bc450f7f 100644--- a/scripts/memory-core-baseline.txt+++ b/scripts/memory-core-baseline.txt@@ -13,7 +13,7 @@ internal/cbm/lsp/perl_lsp.c 21internal/cbm/lsp/py_lsp.c 2internal/cbm/macro_table.c 1internal/cbm/service_patterns.c 2-internal/cbm/sqlite_writer.c 92+internal/cbm/sqlite_writer.c 74src/cli/activation_transaction.c 80src/cli/agent_clients.c 73src/cli/agent_profiles.c 7@@ -69,7 +69,7 @@ src/pipeline/pass_envscan.c 2src/pipeline/pass_githistory.c 27src/pipeline/pass_importance.c 4src/pipeline/pass_infrascan.c 2-src/pipeline/pass_k8s.c 13+src/pipeline/pass_k8s.c 6src/pipeline/pass_lsp_cross.c 50src/pipeline/pass_parallel.c 31src/pipeline/pass_pkgmap.c 82@@ -80,7 +80,7 @@ src/pipeline/path_alias.c 42src/pipeline/pipeline.c 134src/pipeline/pipeline_delta.c 19src/pipeline/pipeline_incremental.c 144-src/pipeline/registry.c 19+src/pipeline/registry.c 17src/pipeline/worker_pool.c 2src/store/store.c 358src/ui/config.c 12diff --git a/src/foundation/arena.c b/src/foundation/arena.cindex ec39d8d6c..7d16f1043 100644--- a/src/foundation/arena.c+++ b/src/foundation/arena.c@@ -43,8 +43,7 @@ static void arena_waste_report(const CBMArena *a) {uint64_t current_rest = a->block_size > a->used ? a->block_size - a->used : 0;uint64_t wasted = a->waste_tail + current_rest + unreached;uint64_t used = capacity > wasted ? capacity - wasted : 0;- cbm_memev_container(CBM_WORK_CT_ARENA, a->waste_site, capacity, used,- (uint64_t)a->waste_grows);+ cbm_memev_container(CBM_WORK_CT_ARENA, a->waste_site, capacity, used, (uint64_t)a->waste_grows);}#define ARENA_SITE() __builtin_return_address(0)#elsediff --git a/src/foundation/dyn_array.h b/src/foundation/dyn_array.hindex 37c55f597..19acb578f 100644--- a/src/foundation/dyn_array.h+++ b/src/foundation/dyn_array.h@@ -23,8 +23,8 @@#include "mem_core.h" /* same directory: units without -Isrc include this header relatively */#if defined(CBM_MEMWASTE) && CBM_MEMWASTE#include "mem_events.h"-#define CBM_DA_WASTE_NOTE(da) \- cbm_memev_da_note((size_t)(da)->cap * sizeof(*(da)->items), \+#define CBM_DA_WASTE_NOTE(da) \+ cbm_memev_da_note((size_t)(da)->cap * sizeof(*(da)->items), \(size_t)(da)->count * sizeof(*(da)->items), (size_t)(da)->cap)#else#define CBM_DA_WASTE_NOTE(da) ((void)0)diff --git a/src/foundation/hash_table.c b/src/foundation/hash_table.cindex 8c18e4f55..6d45c0f2b 100644--- a/src/foundation/hash_table.c+++ b/src/foundation/hash_table.c@@ -66,13 +66,13 @@ struct CBMHashTable {#define HT_SITE() __builtin_return_address(0)enum { HT_SLOT_BYTES = sizeof(cbm_vt_bucket) + sizeof(uint16_t) };#define HT_WROTE(ht) ((ht)->waste_generation++)-#define HT_LOOKED_UP(ht, key, found) \- do { \- if (cbm_memev_enabled()) { \- /* site = the table's creation site: lookups are charged to the table */ \- cbm_work_note_ht(CBM_WORK_HT_GET, (ht)->waste_site, (ht), (key), \- (ht)->waste_generation, (found)); \- } \+#define HT_LOOKED_UP(ht, key, found) \+ do { \+ if (cbm_memev_enabled()) { \+ /* site = the table's creation site: lookups are charged to the table */ \+ cbm_work_note_ht(CBM_WORK_HT_GET, (ht)->waste_site, (ht), (key), \+ (ht)->waste_generation, (found)); \+ } \} while (0)#else#define HT_SITE() NULLdiff --git a/src/foundation/mem_core.c b/src/foundation/mem_core.cindex 425e617fa..121d2696d 100644--- a/src/foundation/mem_core.c+++ b/src/foundation/mem_core.c@@ -231,13 +231,12 @@ static bool core_reports_frees(void) {cbm_memev_hint(__builtin_return_address(0), (int)(cls)); \} \} while (0)-#define MEMEV_ALLOCATED(block, bytes, flags) \- do { \- if (cbm_memev_hint_pending()) { \- cbm_memev_alloc_ex((block), (bytes), \- (block) ? charge_size((block), (bytes)) : 0, NULL, \- (flags)); \- } \+#define MEMEV_ALLOCATED(block, bytes, flags) \+ do { \+ if (cbm_memev_hint_pending()) { \+ cbm_memev_alloc_ex((block), (bytes), (block) ? charge_size((block), (bytes)) : 0, \+ NULL, (flags)); \+ } \} while (0)#define MEMEV_REALLOCATED(old_block, grown, bytes) \do { \diff --git a/src/foundation/mem_events.c b/src/foundation/mem_events.cindex 80b4ee19f..0ccb84c69 100644--- a/src/foundation/mem_events.c+++ b/src/foundation/mem_events.c@@ -71,7 +71,7 @@ enum {MEMEV_SEQ_MASK = (1 << MEMEV_SEQ_BITS) - 1,MEMEV_PHASE_CAP = 63, /* stored in 6 bits */MEMEV_PHASE_LABEL = 48,- MEMEV_LINE = 2048, /* a site line with every field at 20 digits is ~1,150 bytes */+ MEMEV_LINE = 2048, /* a site line with every field at 20 digits is ~1,150 bytes */MEMEV_PTR_SHIFT = 4, /* allocators align to 16: the low bits carry no entropy */MEMEV_REPEAT_SLOTS = 256,MEMEV_PATH_BITS = 20,@@ -126,8 +126,7 @@ static void vm_put(void *p, size_t bytes) {typedef atomic_flag memev_lock_t;static void lock_take(memev_lock_t *l) {- while (atomic_flag_test_and_set_explicit(l, memory_order_acquire)) {- }+ while (atomic_flag_test_and_set_explicit(l, memory_order_acquire)) {}}static void lock_drop(memev_lock_t *l) {@@ -267,10 +266,10 @@ static _Atomic bool g_observer_installed;static _Atomic uintptr_t g_image_base;static const char *const g_work_names[CBM_WORK_KIND_COUNT] = {- "memcpy", "memmove", "memset", "memcmp", "strlen", "strcmp", "strncmp",- "read", "write", "pread", "pwrite", "open", "stat", "fopen",- "fread", "fwrite", "opendir", "readdir", "mutex", "parallel_for", "pool_ops",- "ht_get", "ht_set", "dead_write", "ct_arena", "ct_dyn_array", "ct_hash_table",+ "memcpy", "memmove", "memset", "memcmp", "strlen", "strcmp", "strncmp",+ "read", "write", "pread", "pwrite", "open", "stat", "fopen",+ "fread", "fwrite", "opendir", "readdir", "mutex", "parallel_for", "pool_ops",+ "ht_get", "ht_set", "dead_write", "ct_arena", "ct_dyn_array", "ct_hash_table",};const char *cbm_work_kind_name(cbm_work_kind_t kind) {@@ -369,9 +368,9 @@ static bool key_ready(void) {int state = atomic_load_explicit(&g_key_state, memory_order_acquire);while (state != 2) {int expect = 0;- if (state == 0 && atomic_compare_exchange_strong_explicit(&g_key_state, &expect, 1,- memory_order_acq_rel,- memory_order_acquire)) {+ if (state == 0 &&+ atomic_compare_exchange_strong_explicit(&g_key_state, &expect, 1, memory_order_acq_rel,+ memory_order_acquire)) {#ifdef _WIN32/* A plain TLS slot, released from the loader's thread-detach* callback (cbm_memev_thread_end, compat_thread.c). An FLS@@ -510,9 +509,8 @@ static uint32_t key_index(_Atomic uintptr_t *keys, uint32_t cap, uintptr_t key)}if (seen == 0) {uintptr_t expect = 0;- if (atomic_compare_exchange_strong_explicit(&keys[idx], &expect, key,- memory_order_acq_rel,- memory_order_acquire) ||+ if (atomic_compare_exchange_strong_explicit(+ &keys[idx], &expect, key, memory_order_acq_rel, memory_order_acquire) ||expect == key) {return idx;}@@ -818,8 +816,8 @@ static void acc_give_id(tl_state_t *st, uint32_t id) {lock_drop(&g_acc_lock);}-static void acc_track(tl_state_t *st, uintptr_t block, uint64_t usable, uint32_t site,- bool zeroed, bool filled, bool written) {+static void acc_track(tl_state_t *st, uintptr_t block, uint64_t usable, uint32_t site, bool zeroed,+ bool filled, bool written) {if (!acc_init()) {return;}@@ -1034,8 +1032,8 @@ static void record_alloc(tl_state_t *st, uintptr_t block, size_t requested, sizebool zeroed = (flags & CBM_MEMEV_ZEROED) != 0;bool filled = false;- if (!zeroed && !(flags & (CBM_MEMEV_FOREIGN | CBM_MEMEV_WRITTEN)) && charged <= MEMEV_FILL_CAP &&- fill_enabled()) {+ if (!zeroed && !(flags & (CBM_MEMEV_FOREIGN | CBM_MEMEV_WRITTEN)) &&+ charged <= MEMEV_FILL_CAP && fill_enabled()) {memset((void *)block, MEMEV_FILL_BYTE, (size_t)charged);filled = true;}@@ -1049,9 +1047,9 @@ static void record_alloc(tl_state_t *st, uintptr_t block, size_t requested, sizee->seq = (st->slot << MEMEV_SEQ_BITS) | st->alloc_seq;e->site = (uint16_t)sid;e->mem_class = (int8_t)mem_class;- e->meta = (uint8_t)((atomic_load_explicit(&g_phase, memory_order_relaxed) &- META_PHASE_MASK) |- (filled ? META_FILLED : 0) | (zeroed ? META_ZEROED : 0));+ e->meta =+ (uint8_t)((atomic_load_explicit(&g_phase, memory_order_relaxed) & META_PHASE_MASK) |+ (filled ? META_FILLED : 0) | (zeroed ? META_ZEROED : 0));}lock_drop(&sh->lock);if (!e) {@@ -1070,15 +1068,13 @@ static void record_alloc(tl_state_t *st, uintptr_t block, size_t requested, sizec->live_blocks++;#if defined(CBM_MEMWASTE_ACCESS) && CBM_MEMWASTE_ACCESSif (!(flags & (CBM_MEMEV_FOREIGN | CBM_MEMEV_LIBRARY))) {- acc_track(st, block, charged, sid, zeroed, filled,- (flags & CBM_MEMEV_WRITTEN) != 0);+ acc_track(st, block, charged, sid, zeroed, filled, (flags & CBM_MEMEV_WRITTEN) != 0);}#endif}}-void cbm_memev_alloc_ex(void *block, size_t requested, size_t usable, void *site,- unsigned flags) {+void cbm_memev_alloc_ex(void *block, size_t requested, size_t usable, void *site, unsigned flags) {if (!cbm_memev_enabled()) {return;}@@ -1142,8 +1138,8 @@ void cbm_memev_free(void *block) {int scan_written = -1;if ((e.meta & (META_FILLED | META_ZEROED)) && e.usable <= MEMEV_FILL_CAP) {bool zeroed = (e.meta & META_ZEROED) != 0;- scan_t sc = scan_block((const uint8_t *)block, (size_t)e.usable,- zeroed ? 0 : MEMEV_FILL_BYTE);+ scan_t sc =+ scan_block((const uint8_t *)block, (size_t)e.usable, zeroed ? 0 : MEMEV_FILL_BYTE);scan_written = sc.high_water > 0 ? 1 : 0;c->scanned_blocks++;if (zeroed) {@@ -1173,8 +1169,7 @@ void cbm_memev_free_foreign(void *block) {atomic_fetch_add_explicit(&g_foreign_frees, 1, memory_order_relaxed);}-void cbm_memev_realloc(void *old_block, void *grown, size_t requested, size_t usable,- void *site) {+void cbm_memev_realloc(void *old_block, void *grown, size_t requested, size_t usable, void *site) {if (!cbm_memev_enabled()) {return;}@@ -1333,8 +1328,7 @@ uint64_t cbm_memev_thread_ops(void) {return st ? st->ops : 0;}-void cbm_work_note(cbm_work_kind_t kind, void *site, uint64_t bytes, uint64_t aux1,- uint64_t aux2) {+void cbm_work_note(cbm_work_kind_t kind, void *site, uint64_t bytes, uint64_t aux1, uint64_t aux2) {if ((int)kind < 0 || kind >= CBM_WORK_KIND_COUNT || !cbm_memev_enabled()) {return;}@@ -1382,11 +1376,9 @@ void cbm_work_note_strlen(void *site, const char *s, size_t len) {return;}st->busy = true;- strlen_pair_t *slot =- &st->strlen_cache[mix((uint64_t)(uintptr_t)s) & (MEMEV_REPEAT_SLOTS - 1)];+ strlen_pair_t *slot = &st->strlen_cache[mix((uint64_t)(uintptr_t)s) & (MEMEV_REPEAT_SLOTS - 1)];uint64_t content = bytes_hash(s, len);- uint64_t repeat =- (slot->ptr == s && slot->len == len && slot->content_hash == content) ? 1 : 0;+ uint64_t repeat = (slot->ptr == s && slot->len == len && slot->content_hash == content) ? 1 : 0;slot->ptr = s;slot->len = len;slot->content_hash = content;@@ -1424,9 +1416,8 @@ void cbm_work_note_path(cbm_work_kind_t kind, void *site, const char *path, bool}if (seen == 0) {uint64_t expect = 0;- if (atomic_compare_exchange_strong_explicit(&g_path_hashes[idx], &expect, h,- memory_order_relaxed,- memory_order_relaxed)) {+ if (atomic_compare_exchange_strong_explicit(+ &g_path_hashes[idx], &expect, h, memory_order_relaxed, memory_order_relaxed)) {break;}if (expect == h) {@@ -1456,10 +1447,10 @@ void cbm_work_note_ht(cbm_work_kind_t kind, void *site, const void *table, constht_pair_t *slot =&st->ht_cache[mix((uint64_t)(uintptr_t)table ^ (key_hash * 0x9e3779b97f4a7c15ULL)) &(MEMEV_REPEAT_SLOTS - 1)];- repeat = (slot->table == table && slot->key_hash == key_hash &&- slot->generation == generation)- ? 1- : 0;+ repeat =+ (slot->table == table && slot->key_hash == key_hash && slot->generation == generation)+ ? 1+ : 0;slot->table = table;slot->key_hash = key_hash;slot->generation = generation;@@ -1518,8 +1509,7 @@ static void flush_state(tl_state_t *st) {st->work_dirty_count = 0;lock_drop(&g_merge_lock);atomic_fetch_add_explicit(&g_untracked_frees, st->untracked_frees, memory_order_relaxed);- atomic_fetch_add_explicit(&g_pointer_table_full, st->pointer_table_full,- memory_order_relaxed);+ atomic_fetch_add_explicit(&g_pointer_table_full, st->pointer_table_full, memory_order_relaxed);atomic_fetch_add_explicit(&g_site_table_full, st->site_table_full, memory_order_relaxed);atomic_fetch_add_explicit(&g_work_table_full, st->work_table_full, memory_order_relaxed);st->untracked_frees = 0;@@ -1618,8 +1608,8 @@ static void snapshot_phase(uint32_t phase_now) {continue;}const uint8_t *p = (const uint8_t *)e->block;- scan_t sc = scan_block(p, (size_t)e->usable,- (e->meta & META_ZEROED) ? 0 : MEMEV_FILL_BYTE);+ scan_t sc =+ scan_block(p, (size_t)e->usable, (e->meta & META_ZEROED) ? 0 : MEMEV_FILL_BYTE);if (sc.high_water == 0) {continue; /* nothing written: that is never-written waste, not a duplicate */}@@ -1881,7 +1871,8 @@ static bool dump_locked(const char *path, const char *why) {line, sizeof(line),"{\"memwaste\":2,\"why\":\"%s\",\"pid\":%d,\"image_base\":\"0x%llx\",\"phase\":%u,""\"phase_label\":\"%s\",\"rss_bytes\":%llu,\"allocs\":%llu,\"frees\":%llu,"- "\"untracked_frees\":%llu,\"foreign_frees\":%llu,\"reallocs\":%llu,\"requested_bytes\":%llu,\"usable_bytes\":%llu,"+ "\"untracked_frees\":%llu,\"foreign_frees\":%llu,\"reallocs\":%llu,\"requested_bytes\":%"+ "llu,\"usable_bytes\":%llu,""\"realloc_copy_bytes\":%llu,\"live_bytes\":%llu,\"live_blocks\":%llu,\"raw_bytes\":%llu,""\"sites\":%llu,\"site_table_full\":%llu,\"pointer_table_full\":%llu,""\"work_table_full\":%llu,\"layer_vm_bytes\":%llu,\"layer_threads\":%lld,"@@ -1891,13 +1882,12 @@ static bool dump_locked(const char *path, const char *why) {atomic_load_explicit(&g_phase, memory_order_relaxed), label,(unsigned long long)cbm_mem_rss(), (unsigned long long)t.allocs,(unsigned long long)t.frees, (unsigned long long)t.untracked_frees,- (unsigned long long)t.foreign_frees,- (unsigned long long)t.reallocs, (unsigned long long)t.requested_bytes,- (unsigned long long)t.usable_bytes, (unsigned long long)t.realloc_copy_bytes,- (unsigned long long)t.live_bytes, (unsigned long long)t.live_blocks,- (unsigned long long)t.raw_bytes, (unsigned long long)t.sites,- (unsigned long long)t.site_table_full, (unsigned long long)t.pointer_table_full,- (unsigned long long)t.work_table_full,+ (unsigned long long)t.foreign_frees, (unsigned long long)t.reallocs,+ (unsigned long long)t.requested_bytes, (unsigned long long)t.usable_bytes,+ (unsigned long long)t.realloc_copy_bytes, (unsigned long long)t.live_bytes,+ (unsigned long long)t.live_blocks, (unsigned long long)t.raw_bytes,+ (unsigned long long)t.sites, (unsigned long long)t.site_table_full,+ (unsigned long long)t.pointer_table_full, (unsigned long long)t.work_table_full,(unsigned long long)atomic_load_explicit(&g_layer_vm_bytes, memory_order_relaxed),(long long)atomic_load_explicit(&g_layer_threads, memory_order_relaxed),fill_enabled() ? 1 : 0,@@ -1933,13 +1923,12 @@ static bool dump_locked(const char *path, const char *why) {(unsigned long long)r.live_bytes, (unsigned long long)r.live_blocks,(unsigned long long)r.short_lived, (unsigned long long)r.raw_bytes,(unsigned long long)r.scanned_blocks, (unsigned long long)r.never_written_bytes,- (unsigned long long)r.over_requested_bytes,- (unsigned long long)r.zero_untouched_bytes, (unsigned long long)r.retained_bytes,- (unsigned long long)r.dup_bytes, (unsigned long long)r.dup_blocks,- (unsigned long long)r.acc_untouched_blocks, (unsigned long long)r.acc_untouched_bytes,- (unsigned long long)r.acc_dead_blocks, (unsigned long long)r.acc_dead_bytes,- (unsigned long long)r.acc_uninit_reads, (unsigned long long)r.acc_idle_bytes,- (unsigned long long)r.acc_opaque_blocks);+ (unsigned long long)r.over_requested_bytes, (unsigned long long)r.zero_untouched_bytes,+ (unsigned long long)r.retained_bytes, (unsigned long long)r.dup_bytes,+ (unsigned long long)r.dup_blocks, (unsigned long long)r.acc_untouched_blocks,+ (unsigned long long)r.acc_untouched_bytes, (unsigned long long)r.acc_dead_blocks,+ (unsigned long long)r.acc_dead_bytes, (unsigned long long)r.acc_uninit_reads,+ (unsigned long long)r.acc_idle_bytes, (unsigned long long)r.acc_opaque_blocks);ok = len > 0 && (size_t)len < sizeof(line) && write_all(fd, line, (size_t)len);}for (uint32_t i = 0; ok && i < MEMEV_WORK_CAP; i++) {@@ -2050,8 +2039,7 @@ void cbm_memev_alloc(void *block, size_t requested, size_t usable, void *site) {(void)usable;(void)site;}-void cbm_memev_alloc_ex(void *block, size_t requested, size_t usable, void *site,- unsigned flags) {+void cbm_memev_alloc_ex(void *block, size_t requested, size_t usable, void *site, unsigned flags) {(void)block;(void)requested;(void)usable;@@ -2064,8 +2052,7 @@ void cbm_memev_free(void *block) {void cbm_memev_free_foreign(void *block) {(void)block;}-void cbm_memev_realloc(void *old_block, void *grown, size_t requested, size_t usable,- void *site) {+void cbm_memev_realloc(void *old_block, void *grown, size_t requested, size_t usable, void *site) {(void)old_block;(void)grown;(void)requested;@@ -2088,8 +2075,7 @@ void cbm_memev_set_observer_installed(bool installed) {bool cbm_memev_observer_installed(void) {return false;}-void cbm_memev_flush_thread(void) {-}+void cbm_memev_flush_thread(void) {}void cbm_memev_phase(const char *label) {(void)label;}@@ -2112,8 +2098,7 @@ void cbm_memev_library_leave(void) {}void *cbm_memev_library_site(void) {return NULL;}-void cbm_work_note(cbm_work_kind_t kind, void *site, uint64_t bytes, uint64_t aux1,- uint64_t aux2) {+void cbm_work_note(cbm_work_kind_t kind, void *site, uint64_t bytes, uint64_t aux1, uint64_t aux2) {(void)kind;(void)site;(void)bytes;@@ -2165,8 +2150,7 @@ bool cbm_memev_dump(const char *path, const char *why) {(void)why;return false;}-void cbm_memev_reset_for_tests(void) {-}+void cbm_memev_reset_for_tests(void) {}void cbm_memev_scan_for_tests(bool fill, bool dupes) {(void)fill;(void)dupes;diff --git a/src/foundation/mem_events.h b/src/foundation/mem_events.hindex 30eb05088..e244c4666 100644--- a/src/foundation/mem_events.h+++ b/src/foundation/mem_events.h@@ -242,8 +242,7 @@ typedef enum {enum { CBM_WORK_TINY_IO = 512 };const char *cbm_work_kind_name(cbm_work_kind_t kind);-void cbm_work_note(cbm_work_kind_t kind, void *site, uint64_t bytes, uint64_t aux1,- uint64_t aux2);+void cbm_work_note(cbm_work_kind_t kind, void *site, uint64_t bytes, uint64_t aux1, uint64_t aux2);void cbm_work_note_strlen(void *site, const char *s, size_t len);/* Events (allocations and work notes) this thread has produced so far. A pool@@ -324,8 +323,8 @@ typedef struct {uint64_t acc_untouched_bytes;uint64_t acc_dead_blocks; /* written, never read */uint64_t acc_dead_bytes;- uint64_t acc_uninit_reads; /* read before any write, not calloc */- uint64_t acc_idle_bytes; /* last accessed in an earlier phase than freed */+ uint64_t acc_uninit_reads; /* read before any write, not calloc */+ uint64_t acc_idle_bytes; /* last accessed in an earlier phase than freed */uint64_t acc_opaque_blocks; /* written (fill scan) with no callback: no verdict possible */} cbm_memev_site_t;diff --git a/src/foundation/mem_override_darwin.c b/src/foundation/mem_override_darwin.cindex 370e6428a..80997b768 100644--- a/src/foundation/mem_override_darwin.c+++ b/src/foundation/mem_override_darwin.c@@ -120,8 +120,7 @@ static void *obs_calloc(malloc_zone_t *z, size_t count, size_t n) {if (p && cbm_memev_enabled()) {unsigned flags;void *site = caller_site(__builtin_frame_address(0), &flags);- cbm_memev_alloc_ex(p, count * n, g_orig->size(g_orig, p), site,- flags | CBM_MEMEV_ZEROED);+ cbm_memev_alloc_ex(p, count * n, g_orig->size(g_orig, p), site, flags | CBM_MEMEV_ZEROED);}return p;}diff --git a/src/foundation/mem_override_libc.c b/src/foundation/mem_override_libc.cindex b86b8e0d1..257258a4d 100644--- a/src/foundation/mem_override_libc.c+++ b/src/foundation/mem_override_libc.c@@ -140,8 +140,8 @@ __attribute__((constructor(101))) static void libc_resolve(void) {* constructor resolves its own target once. */#define RESOLVED(ptr, name) ((ptr) ? (ptr) : ((ptr) = dlsym(RTLD_NEXT, name)))-__attribute__((no_builtin("memcpy", "memmove", "memset")))-static void *slow_move(void *d, const void *s, size_t n) {+__attribute__((no_builtin("memcpy", "memmove",+ "memset"))) static void *slow_move(void *d, const void *s, size_t n) {unsigned char *dd = (unsigned char *)d;const unsigned char *ss = (const unsigned char *)s;if (dd < ss) {@@ -156,8 +156,7 @@ static void *slow_move(void *d, const void *s, size_t n) {return d;}-__attribute__((no_builtin("memset")))-static void *slow_set(void *d, int c, size_t n) {+__attribute__((no_builtin("memset"))) static void *slow_set(void *d, int c, size_t n) {unsigned char *dd = (unsigned char *)d;for (size_t i = 0; i < n; i++) {dd[i] = (unsigned char)c;@@ -165,8 +164,7 @@ static void *slow_set(void *d, int c, size_t n) {return d;}-__attribute__((no_builtin("strlen")))-static size_t slow_strlen(const char *s) {+__attribute__((no_builtin("strlen"))) static size_t slow_strlen(const char *s) {size_t i = 0;while (s[i]) {i++;@@ -174,8 +172,10 @@ static size_t slow_strlen(const char *s) {return i;}-__attribute__((no_builtin("memcmp", "strcmp", "strncmp")))-static int slow_ncmp(const char *a, const char *b, size_t n, bool stop_at_nul) {+__attribute__((no_builtin("memcmp", "strcmp", "strncmp"))) static int slow_ncmp(const char *a,+ const char *b,+ size_t n,+ bool stop_at_nul) {for (size_t i = 0; i < n; i++) {unsigned char x = (unsigned char)a[i];unsigned char y = (unsigned char)b[i];@@ -209,14 +209,14 @@ void *(memset)(void *d, int c, size_t n) {return r_memset ? r_memset(d, c, n) : slow_set(d, c, n);}-int (memcmp)(const void *a, const void *b, size_t n) {+int(memcmp)(const void *a, const void *b, size_t n) {note_bytes(CBM_WORK_MEMCMP, SITE(), n);ACC_LOAD(a, n);ACC_LOAD(b, n);return r_memcmp ? r_memcmp(a, b, n) : slow_ncmp((const char *)a, (const char *)b, n, false);}-size_t (strlen)(const char *s) {+size_t(strlen)(const char *s) {size_t n = r_strlen ? r_strlen(s) : slow_strlen(s);if (cbm_memev_enabled()) {cbm_work_note_strlen(SITE(), s, n);@@ -225,14 +225,14 @@ size_t (strlen)(const char *s) {return n;}-int (strcmp)(const char *a, const char *b) {+int(strcmp)(const char *a, const char *b) {note_bytes(CBM_WORK_STRCMP, SITE(), 0);ACC_LOAD(a, 1);ACC_LOAD(b, 1);return r_strcmp ? r_strcmp(a, b) : slow_ncmp(a, b, (size_t)-1, true);}-int (strncmp)(const char *a, const char *b, size_t n) {+int(strncmp)(const char *a, const char *b, size_t n) {note_bytes(CBM_WORK_STRNCMP, SITE(), n);ACC_LOAD(a, 1);ACC_LOAD(b, 1);diff --git a/src/foundation/mem_override_posix.c b/src/foundation/mem_override_posix.cindex af340fd23..ee3e13e0d 100644--- a/src/foundation/mem_override_posix.c+++ b/src/foundation/mem_override_posix.c@@ -47,12 +47,12 @@* the `memwaste` flavour. Frees are reported BEFORE the block goes back. */#if defined(CBM_MEMWASTE) && CBM_MEMWASTE#include "foundation/mem_events.h"-#define OBS_ALLOC_F(block, requested, flags) \- do { \- if ((block) && cbm_memev_enabled()) { \- cbm_memev_alloc_ex((block), (requested), mi_usable_size(block), \- __builtin_return_address(0), (unsigned)(flags)); \- } \+#define OBS_ALLOC_F(block, requested, flags) \+ do { \+ if ((block) && cbm_memev_enabled()) { \+ cbm_memev_alloc_ex((block), (requested), mi_usable_size(block), \+ __builtin_return_address(0), (unsigned)(flags)); \+ } \} while (0)#define OBS_ALLOC(block, requested) OBS_ALLOC_F((block), (requested), 0)#define OBS_REALLOC(old_block, grown, requested) \diff --git a/src/foundation/mem_override_win.c b/src/foundation/mem_override_win.cindex cf7e1a790..e18b09d11 100644--- a/src/foundation/mem_override_win.c+++ b/src/foundation/mem_override_win.c@@ -73,12 +73,12 @@ static inline bool mem_override_is_ours(const void *block) {* caller's return address is the allocation site. Compiled to nothing outside* the `memwaste` flavour. Frees are reported BEFORE the block goes back. */#if defined(CBM_MEMWASTE) && CBM_MEMWASTE-#define OBS_ALLOC_F(block, requested, flags) \- do { \- if ((block) && cbm_memev_enabled()) { \- cbm_memev_alloc_ex((block), (requested), mi_usable_size(block), \- __builtin_return_address(0), (unsigned)(flags)); \- } \+#define OBS_ALLOC_F(block, requested, flags) \+ do { \+ if ((block) && cbm_memev_enabled()) { \+ cbm_memev_alloc_ex((block), (requested), mi_usable_size(block), \+ __builtin_return_address(0), (unsigned)(flags)); \+ } \} while (0)#define OBS_ALLOC(block, requested) OBS_ALLOC_F((block), (requested), 0)#define OBS_REALLOC(old_block, grown, requested) \@@ -90,7 +90,7 @@ static inline bool mem_override_is_ours(const void *block) {} while (0)/* A block mimalloc did not make came from the CRT or a system DLL: the layer* could never have seen its allocation, so it is not an untracked free. */-#define OBS_FREE(block) \+#define OBS_FREE(block) \(mem_override_is_ours(block) ? cbm_memev_free(block) : cbm_memev_free_foreign(block))#else#define OBS_ALLOC(block, requested) ((void)0)diff --git a/src/pipeline/lsp_surface.c b/src/pipeline/lsp_surface.cindex ba0ade761..5a8c89f97 100644--- a/src/pipeline/lsp_surface.c+++ b/src/pipeline/lsp_surface.c@@ -74,8 +74,8 @@ static void add_str_array_or_null(yyjson_mut_doc *doc, yyjson_mut_val *obj, cons/* Serialize one file's surface: its slice of all_defs plus the registry-only* symbols from its raw extraction defs. Returns a malloc'd JSON string and its* length. */-static char *surface_file_to_json(const CBMFileResult *result, const CBMLSPDef *defs,- int def_count, size_t *out_len) {+static char *surface_file_to_json(const CBMFileResult *result, const CBMLSPDef *defs, int def_count,+ size_t *out_len) {yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);if (!doc) {return NULL;@@ -161,8 +161,8 @@ static void surface_row_one(int i, void *arg) {int start = job->def_starts ? job->def_starts[i] : 0;int end = job->def_starts ? job->def_starts[i + 1] : 0;size_t json_len = 0;- char *json = surface_file_to_json(fr, job->all_defs ? job->all_defs + start : NULL,- end - start, &json_len);+ char *json = surface_file_to_json(fr, job->all_defs ? job->all_defs + start : NULL, end - start,+ &json_len);cbm_pipeline_result_release(fr, loaded);if (!json) {atomic_store_explicit(&job->failed, true, memory_order_relaxed);diff --git a/src/pipeline/pass_configlink.c b/src/pipeline/pass_configlink.cindex 776a7d862..1ee3ecf4b 100644--- a/src/pipeline/pass_configlink.c+++ b/src/pipeline/pass_configlink.c@@ -21,7 +21,7 @@#include <stdlib.h>#include <string.h>#include <ctype.h>-#include "foundation/platform.h" /* cbm_default_worker_count */+#include "foundation/platform.h" /* cbm_default_worker_count */#include "pipeline/worker_pool.h"#include "foundation/compat_regex.h"@@ -256,8 +256,8 @@ typedef struct {_Atomic bool failed;} key_match_job_t;-static double key_pair_confidence(const char *config_norm, size_t config_len,- const char *code_norm, size_t code_len) {+static double key_pair_confidence(const char *config_norm, size_t config_len, const char *code_norm,+ size_t code_len) {if (config_len > code_len) {return 0.0;}@@ -280,15 +280,15 @@ static void key_match_worker(int worker_id, void *arg) {}key_match_list_t *list = &job->lists[ci];for (int co = 0; co < job->code_count; co++) {- double confidence =- key_pair_confidence(job->config[ci].normalized, job->config_len[ci],- job->code[co].normalized, job->code_len[co]);+ double confidence = key_pair_confidence(job->config[ci].normalized, job->config_len[ci],+ job->code[co].normalized, job->code_len[co]);if (confidence <= 0.0) {continue;}if (list->count == list->cap) {int cap = list->cap ? list->cap * PAIR_LEN : CBM_SZ_16;- key_match_t *grown = realloc(list->items, (size_t)cap * sizeof(*grown));+ key_match_t *grown =+ cbm_realloc(CBM_MEM_CLASS_OTHER, list->items, (size_t)cap * sizeof(*grown));if (!grown) {atomic_store_explicit(&job->failed, true, memory_order_relaxed);return;@@ -323,9 +323,11 @@ static int strategy_key_symbols(cbm_gbuf_t *gb) {int edge_count = 0;- size_t *config_len = malloc((size_t)config_count * sizeof(size_t));- size_t *code_len = malloc((size_t)(code_count > 0 ? code_count : 1) * sizeof(size_t));- key_match_list_t *lists = calloc((size_t)config_count, sizeof(key_match_list_t));+ size_t *config_len = cbm_alloc(CBM_MEM_CLASS_OTHER, (size_t)config_count * sizeof(size_t));+ size_t *code_len =+ cbm_alloc(CBM_MEM_CLASS_OTHER, (size_t)(code_count > 0 ? code_count : 1) * sizeof(size_t));+ key_match_list_t *lists =+ cbm_calloc(CBM_MEM_CLASS_OTHER, (size_t)config_count * sizeof(key_match_list_t));bool parallel_ok = config_len && code_len && lists;if (parallel_ok) {for (int ci = 0; ci < config_count; ci++) {@@ -346,8 +348,9 @@ static int strategy_key_symbols(cbm_gbuf_t *gb) {atomic_init(&job.next, 0);atomic_init(&job.failed, false);int workers = cbm_default_worker_count(false);- cbm_parallel_for(workers, key_match_worker, &job,- (cbm_parallel_for_opts_t){.max_workers = workers, .force_pthreads = false});+ cbm_parallel_for(+ workers, key_match_worker, &job,+ (cbm_parallel_for_opts_t){.max_workers = workers, .force_pthreads = false});parallel_ok = !atomic_load_explicit(&job.failed, memory_order_relaxed);}if (parallel_ok) {@@ -366,11 +369,11 @@ static int strategy_key_symbols(cbm_gbuf_t *gb) {}}for (int ci = 0; lists && ci < config_count; ci++) {- free(lists[ci].items);+ cbm_free(CBM_MEM_CLASS_OTHER, lists[ci].items);}- free(lists);- free(config_len);- free(code_len);+ cbm_free(CBM_MEM_CLASS_OTHER, lists);+ cbm_free(CBM_MEM_CLASS_OTHER, config_len);+ cbm_free(CBM_MEM_CLASS_OTHER, code_len);if (parallel_ok) {return edge_count;}@@ -529,12 +532,12 @@ static int prepare_dep_imports(cbm_gbuf_t *gb, const cbm_gbuf_edge_t *const *impbytes += (qlen < QN_CAP ? qlen : QN_CAP - SKIP_ONE) + SKIP_ONE;}}- dep_import_t *items = (dep_import_t *)malloc((size_t)(import_count > 0 ? import_count : 1) *- sizeof(dep_import_t));- char *block = (char *)malloc(bytes > 0 ? bytes : 1);+ dep_import_t *items = cbm_alloc(+ CBM_MEM_CLASS_OTHER, (size_t)(import_count > 0 ? import_count : 1) * sizeof(dep_import_t));+ char *block = cbm_alloc(CBM_MEM_CLASS_OTHER, bytes > 0 ? bytes : 1);if (!items || !block) {- free(items);- free(block);+ cbm_free(CBM_MEM_CLASS_OTHER, items);+ cbm_free(CBM_MEM_CLASS_OTHER, block);return 0;}int n = 0;@@ -591,8 +594,7 @@ static int strategy_dep_imports(cbm_gbuf_t *gb) {int edge_count = 0;dep_import_t *prepared = NULL;char *prepared_block = NULL;- int prepared_count =- prepare_dep_imports(gb, imports, import_count, &prepared, &prepared_block);+ int prepared_count = prepare_dep_imports(gb, imports, import_count, &prepared, &prepared_block);for (int di = 0; di < dep_count && prepared; di++) {char dep_lower[CBM_SZ_256];@@ -615,8 +617,8 @@ static int strategy_dep_imports(cbm_gbuf_t *gb) {}/* gbuf data is borrowed; only the prepared copies are owned */- free(prepared);- free(prepared_block);+ cbm_free(CBM_MEM_CLASS_OTHER, prepared);+ cbm_free(CBM_MEM_CLASS_OTHER, prepared_block);return edge_count;}diff --git a/src/pipeline/pass_k8s.c b/src/pipeline/pass_k8s.cindex 806203f6c..3a6982ef6 100644--- a/src/pipeline/pass_k8s.c+++ b/src/pipeline/pass_k8s.c@@ -53,7 +53,7 @@ static char *k8s_read_file(const char *path, int *out_len) {/* +pad: tree-sitter lexer lookahead reads past EOF; keep it in-bounds */enum { CBM_TS_LOOKAHEAD_PAD = 16 };- char *buf = malloc((size_t)size + CBM_TS_LOOKAHEAD_PAD);+ char *buf = cbm_alloc(CBM_MEM_CLASS_OTHER, (size_t)size + CBM_TS_LOOKAHEAD_PAD);if (!buf) {(void)fclose(f);return NULL;@@ -362,8 +362,8 @@ static void k8s_link_selectors(cbm_pipeline_ctx_t *ctx, const k8s_record_array_t* must free after this call returns). When `rec` is non-NULL it is populated* with the first Resource's node id, name and label/selector values for later* cross-manifest selector matching. */-static void handle_k8s_manifest(cbm_pipeline_ctx_t *ctx, const char *rel_path,- const char *source, const CBMFileResult *res, k8s_record_t *rec) {+static void handle_k8s_manifest(cbm_pipeline_ctx_t *ctx, const char *rel_path, const char *source,+ const CBMFileResult *res, k8s_record_t *rec) {int resource_count = 0;if (!res) {@@ -651,9 +651,9 @@ static void k8s_prep_file(const k8s_prep_job_t *job, int i, k8s_prep_t *out) {int src_len = 0;char *source = k8s_read_file(path, &src_len);if (source) {- out->res = cbm_extract_file(source, src_len, CBM_LANG_KUSTOMIZE,- ctx->project_name, rel, CBM_EXTRACT_BUDGET, NULL, NULL);- free(source);+ out->res = cbm_extract_file(source, src_len, CBM_LANG_KUSTOMIZE, ctx->project_name,+ rel, CBM_EXTRACT_BUDGET, NULL, NULL);+ cbm_free(CBM_MEM_CLASS_OTHER, source);}}} else if (lang == CBM_LANG_YAML || lang == CBM_LANG_K8S) {@@ -672,7 +672,7 @@ static void k8s_prep_file(const k8s_prep_job_t *job, int i, k8s_prep_t *out) {out->res = cbm_extract_file(out->source, out->src_len, CBM_LANG_K8S, ctx->project_name,rel, CBM_EXTRACT_BUDGET, NULL, NULL);} else {- free(out->source);+ cbm_free(CBM_MEM_CLASS_OTHER, out->source);out->source = NULL;}}@@ -707,12 +707,12 @@ int cbm_pipeline_pass_k8s(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,/* Collect per-manifest selector/label records for cross-manifest matching. */k8s_record_array_t recs = {0};- recs.items = calloc(K8S_MAX_RECORDS, sizeof(*recs.items));+ recs.items = cbm_calloc(CBM_MEM_CLASS_OTHER, K8S_MAX_RECORDS * sizeof(*recs.items));recs.cap = recs.items ? K8S_MAX_RECORDS : 0;- k8s_prep_t *prep = calloc(K8S_CHUNK, sizeof(*prep));+ k8s_prep_t *prep = cbm_calloc(CBM_MEM_CLASS_OTHER, K8S_CHUNK * sizeof(*prep));if (!prep) {- free(recs.items);+ cbm_free(CBM_MEM_CLASS_OTHER, recs.items);return CBM_NOT_FOUND;}int workers = cbm_default_worker_count(false);@@ -720,15 +720,16 @@ int cbm_pipeline_pass_k8s(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,for (int begin = 0; begin < file_count; begin += K8S_CHUNK) {int end = begin + K8S_CHUNK < file_count ? begin + K8S_CHUNK : file_count;if (cbm_pipeline_check_cancel(ctx)) {- free(prep);- free(recs.items);+ cbm_free(CBM_MEM_CLASS_OTHER, prep);+ cbm_free(CBM_MEM_CLASS_OTHER, recs.items);return CBM_NOT_FOUND;}memset(prep, 0, (size_t)K8S_CHUNK * sizeof(*prep));k8s_prep_job_t job = {.ctx = ctx, .files = files, .prep = prep, .begin = begin, .end = end};atomic_init(&job.next, begin);- cbm_parallel_for(workers, k8s_prep_worker, &job,- (cbm_parallel_for_opts_t){.max_workers = workers, .force_pthreads = false});+ cbm_parallel_for(+ workers, k8s_prep_worker, &job,+ (cbm_parallel_for_opts_t){.max_workers = workers, .force_pthreads = false});bool cancelled = false;for (int i = begin; i < end; i++) {@@ -755,8 +756,7 @@ int cbm_pipeline_pass_k8s(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,helm_count++;break;case K8S_MANIFEST: {- k8s_record_t *rec =- (recs.count < recs.cap) ? &recs.items[recs.count] : NULL;+ k8s_record_t *rec = (recs.count < recs.cap) ? &recs.items[recs.count] : NULL;handle_k8s_manifest(ctx, rel, p->source, p->res, rec);if (rec && rec->node_id > 0) {recs.count++;@@ -769,22 +769,22 @@ int cbm_pipeline_pass_k8s(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,break;}}- free(p->source);+ cbm_free(CBM_MEM_CLASS_OTHER, p->source);if (p->res) {cbm_free_result(p->res);}}if (cancelled) {- free(prep);- free(recs.items);+ cbm_free(CBM_MEM_CLASS_OTHER, prep);+ cbm_free(CBM_MEM_CLASS_OTHER, recs.items);return CBM_NOT_FOUND;}}- free(prep);+ cbm_free(CBM_MEM_CLASS_OTHER, prep);/* Connect Services to the workloads their selectors target (INFRA_MAPS). */k8s_link_selectors(ctx, &recs);- free(recs.items);+ cbm_free(CBM_MEM_CLASS_OTHER, recs.items);cbm_log_info("pass.done", "pass", "k8s", "kustomize", itoa_k8s(kustomize_count), "manifests",itoa_k8s(manifest_count));diff --git a/src/pipeline/pass_semantic.c b/src/pipeline/pass_semantic.cindex c2275c1ae..48dab0083 100644--- a/src/pipeline/pass_semantic.c+++ b/src/pipeline/pass_semantic.c@@ -446,7 +446,8 @@ int cbm_pipeline_implements_go(cbm_pipeline_ctx_t *ctx) {}for (int t = 0; t < type_count; t++) {if (types[t]->qualified_name) {- cbm_ht_set(ix.type_by_qn, types[t]->qualified_name, (void *)(intptr_t)(t + SKIP_ONE));+ cbm_ht_set(ix.type_by_qn, types[t]->qualified_name,+ (void *)(intptr_t)(t + SKIP_ONE));}const cbm_gbuf_edge_t **tdm = NULL;int tdm_count = 0;@@ -518,8 +519,8 @@ int cbm_pipeline_implements_go(cbm_pipeline_ctx_t *ctx) {continue;}for (int k = 0; k < shortest->count; k++) {- edge_count +=- check_go_class_implements(ctx, types[shortest->items[k]], iface, imethods, im_count);+ edge_count += check_go_class_implements(ctx, types[shortest->items[k]], iface, imethods,+ im_count);}}if (ix.by_name) {diff --git a/src/pipeline/pipeline.c b/src/pipeline/pipeline.cindex 187a13a1e..7a69be998 100644--- a/src/pipeline/pipeline.c+++ b/src/pipeline/pipeline.c@@ -3154,6 +3154,25 @@ static const char *const cbm_stage_sidecar_tails[] = {"", "-wal", "-shm", "-jour/* If `name` is "<base>.stage.<6 alphanumerics><known tail>", return the* length of the stage name proper (without the tail); 0 otherwise. */+static size_t stage_entry_stage_length(const char *name, const char *base, size_t base_len);++/* The same test with the base taken from the name itself, so a sweep reclaims+ * stages belonging to ANY project in this cache directory.+ *+ * Why it must not be per-project: a run killed outright (OOM killer, SIGKILL)+ * cleans nothing up, and until 2026-09-18 its staging database was only removed+ * when THAT project was indexed again — a kernel index killed once left 15 GB+ * parked until someone re-indexed the kernel, and forever if nobody did. The+ * per-stage lock probe still decides safety, so a live writer's stage is kept+ * whichever project it belongs to. */+static size_t stage_entry_stage_length_any_base(const char *name) {+ const char *marker = strstr(name, cbm_stage_marker);+ if (!marker) {+ return 0;+ }+ return stage_entry_stage_length(name, name, (size_t)(marker - name));+}+static size_t stage_entry_stage_length(const char *name, const char *base, size_t base_len) {if (strncmp(name, base, base_len) != 0) {return 0;@@ -3309,7 +3328,10 @@ static void sweep_orphan_stages(const char *final_path) {stage_name_list_t list = {0};cbm_dirent_t *entry;while ((entry = cbm_readdir(dir)) != NULL) {- size_t stage_len = stage_entry_stage_length(entry->name, base, base_len);+ /* Any project's orphan, not just this one's: see+ * stage_entry_stage_length_any_base. `base` still anchors the log line+ * and the path rebuild below. */+ size_t stage_len = stage_entry_stage_length_any_base(entry->name);if (stage_len) {stage_name_list_add(&list, entry->name, stage_len);}diff --git a/src/pipeline/registry.c b/src/pipeline/registry.cindex 3a2fb7912..f052f80c4 100644--- a/src/pipeline/registry.c+++ b/src/pipeline/registry.c@@ -237,8 +237,8 @@ static const char *best_by_import_distance(const char **candidates, const uint8_const char *best = NULL;int best_score = CBM_NOT_FOUND;for (int i = 0; i < count; i++) {- int score = candidate_score(candidates[i], module_qn,- is_test_flags ? (int)is_test_flags[i] : -1);+ int score =+ candidate_score(candidates[i], module_qn, is_test_flags ? (int)is_test_flags[i] : -1);if (score > best_score) {best_score = score;best = candidates[i];@@ -968,9 +968,8 @@ static cbm_resolution_t resolve_multi_with_imports(const qn_array_t *arr, const}}/* No import-reachable — use all candidates with penalty */- const char *best =- best_by_import_distance((const char **)arr->items, qn_test_flags(arr), arr->count,- module_qn);+ const char *best = best_by_import_distance((const char **)arr->items, qn_test_flags(arr),+ arr->count, module_qn);if (best) {double conf = candidate_count_penalty(CONF_SUFFIX_MATCH * REG_HALF_PENALTY, arr->count);return (cbm_resolution_t){best, "suffix_match", conf, arr->count};@@ -1156,9 +1155,8 @@ static cbm_resolution_t resolve_name_lookup(const cbm_registry_t *r, const charif (import_vals && import_count > 0) {return resolve_multi_with_imports(arr, module_qn, import_vals, import_count);}- const char *best =- best_by_import_distance((const char **)arr->items, qn_test_flags(arr), arr->count,- module_qn);+ const char *best = best_by_import_distance((const char **)arr->items, qn_test_flags(arr),+ arr->count, module_qn);if (best) {if (!receiver_chain_admits(callee_name, best)) {return empty_result();@@ -1338,9 +1336,8 @@ cbm_fuzzy_result_t cbm_registry_fuzzy_resolve(const cbm_registry_t *r, const chaif (fcount == 0) {/* No import-reachable — use originals with penalty */- const char *best =- best_by_import_distance((const char **)arr->items, qn_test_flags(arr), arr->count,- module_qn);+ const char *best = best_by_import_distance((const char **)arr->items, qn_test_flags(arr),+ arr->count, module_qn);if (!best) {return no_match;}@@ -1354,10 +1351,8 @@ cbm_fuzzy_result_t cbm_registry_fuzzy_resolve(const cbm_registry_t *r, const cha{fptr[0], "fuzzy", candidate_count_penalty(CONF_FUZZY_SINGLE, arr->count), arr->count},true};}- const char *best =- best_by_import_distance(fptr,- fptr == (const char **)arr->items ? qn_test_flags(arr) : NULL,- fcount, module_qn);+ const char *best = best_by_import_distance(+ fptr, fptr == (const char **)arr->items ? qn_test_flags(arr) : NULL, fcount, module_qn);if (!best) {return no_match;}diff --git a/src/pipeline/worker_pool.c b/src/pipeline/worker_pool.cindex 908b514bb..2247fccd5 100644--- a/src/pipeline/worker_pool.c+++ b/src/pipeline/worker_pool.c@@ -88,11 +88,11 @@ static void run_pthreads_counted(int count, cbm_parallel_fn fn, void *ctx, int nvoid *site) {_Atomic int next_idx = 0;pthread_worker_arg_t wa = {.fn = fn, .ctx = ctx, .next_idx = &next_idx, .count = count};- cbm_thread_t *threads = (cbm_thread_t *)malloc((size_t)nworkers * sizeof(cbm_thread_t));- wp_counted_arg_t *args = (wp_counted_arg_t *)calloc((size_t)nworkers, sizeof(*args));+ cbm_thread_t *threads = cbm_alloc(CBM_MEM_CLASS_OTHER, (size_t)nworkers * sizeof(cbm_thread_t));+ wp_counted_arg_t *args = cbm_calloc(CBM_MEM_CLASS_OTHER, (size_t)nworkers * sizeof(*args));if (!threads || !args) {- free(threads);- free(args);+ cbm_free(CBM_MEM_CLASS_OTHER, threads);+ cbm_free(CBM_MEM_CLASS_OTHER, args);run_serial(count, fn, ctx);return;}@@ -137,8 +137,8 @@ static void run_pthreads_counted(int count, cbm_parallel_fn fn, void *ctx, int ncbm_work_note(CBM_WORK_PARALLEL_FOR, site, (uint64_t)count, imbalance, (uint64_t)participants);cbm_work_note(CBM_WORK_POOL_OPS, site, sum_ops, (uint64_t)participants * max_ops - sum_ops,(uint64_t)participants);- free(threads);- free(args);+ cbm_free(CBM_MEM_CLASS_OTHER, threads);+ cbm_free(CBM_MEM_CLASS_OTHER, args);}#endifdiff --git a/tests/fuzz/cbm_fuzz.c b/tests/fuzz/cbm_fuzz.cindex fa6df2c92..9e333d79e 100644--- a/tests/fuzz/cbm_fuzz.c+++ b/tests/fuzz/cbm_fuzz.c@@ -146,9 +146,10 @@ static void fuzz_config(const uint8_t *data, size_t size) {}switch (data[0]) {case 't':- (void)cbm_toml_upsert_managed_block(path, "# BEGIN codebase-memory", "# END codebase-memory",- "owned = true\n");- (void)cbm_toml_remove_managed_block(path, "# BEGIN codebase-memory", "# END codebase-memory");+ (void)cbm_toml_upsert_managed_block(path, "# BEGIN codebase-memory",+ "# END codebase-memory", "owned = true\n");+ (void)cbm_toml_remove_managed_block(path, "# BEGIN codebase-memory",+ "# END codebase-memory");break;case 'y':(void)cbm_yaml_upsert_mapping_entry(path, "mcp_servers", "codebase-memory",diff --git a/tests/test_hash_table.c b/tests/test_hash_table.cindex 58bbcd8c9..4df4212c6 100644--- a/tests/test_hash_table.c+++ b/tests/test_hash_table.c@@ -55,7 +55,7 @@ TEST(ht_set_overwrite_adopts_the_new_key_pointer) {ASSERT_EQ(cbm_ht_get_key(ht, "shared"), first);ASSERT_EQ(cbm_ht_set(ht, second, &v2), &v1);ASSERT_EQ(cbm_ht_get_key(ht, "shared"), second); /* the old buffer is no longer referenced */- memcpy(first, "gone!!", 7); /* the caller reuses the old buffer */+ memcpy(first, "gone!!", 7); /* the caller reuses the old buffer */ASSERT_EQ(*(int *)cbm_ht_get(ht, "shared"), 2);ASSERT_EQ(cbm_ht_count(ht), 1);cbm_ht_free(ht);diff --git a/tests/test_mem_events.c b/tests/test_mem_events.cindex a3ddfd05c..d49e91db5 100644--- a/tests/test_mem_events.c+++ b/tests/test_mem_events.c@@ -309,9 +309,11 @@ TEST(memev_dump_writes_header_sites_and_work) {strstr(line, "\"allocs\":2");}site_a = site_a || strstr(line, "\"site\":\"0xa000\",\"allocs\":1");- site_b = site_b || (strstr(line, "\"site\":\"0xb000\"") && strstr(line, "\"usable_bytes\":1024"));- work = work || (strstr(line, "\"work\":\"memcpy\"") && strstr(line, "\"site\":\"0xc000\"") &&- strstr(line, "\"bytes\":4096") && strstr(line, "\"peak\":4096"));+ site_b = site_b ||+ (strstr(line, "\"site\":\"0xb000\"") && strstr(line, "\"usable_bytes\":1024"));+ work =+ work || (strstr(line, "\"work\":\"memcpy\"") && strstr(line, "\"site\":\"0xc000\"") &&+ strstr(line, "\"bytes\":4096") && strstr(line, "\"peak\":4096"));}fclose(f);(void)remove(path);@@ -350,8 +352,8 @@ TEST(memev_fill_scan_measures_never_written_and_over_requested) {cbm_memev_free(big);cbm_memev_alloc(holed, 80, sizeof(holed), SITE_B);- memset(holed, 2, 16); /* [0, 16) written */- memset(holed + 64, 3, 16); /* [64, 80) written: [16, 64) is a 48-byte hole */+ memset(holed, 2, 16); /* [0, 16) written */+ memset(holed + 64, 3, 16); /* [64, 80) written: [16, 64) is a 48-byte hole */cbm_memev_free(holed);cbm_memev_site_t a;diff --git a/tests/test_registry.c b/tests/test_registry.cindex 8d9ecaaf9..2674e7b1d 100644--- a/tests/test_registry.c+++ b/tests/test_registry.c@@ -301,8 +301,7 @@ TEST(resolve_qualified_disambiguates_same_name) {ASSERT_TRUE(!nomatch.strategy || strcmp(nomatch.strategy, "qualified_suffix") != 0);/* A bare call stays ambiguous (no qualifier → no disambiguation signal). */- cbm_resolution_t bare =- cbm_registry_resolve(r, "save", "proj.lib.App.Caller", NULL, NULL, 0);+ cbm_resolution_t bare = cbm_registry_resolve(r, "save", "proj.lib.App.Caller", NULL, NULL, 0);ASSERT_TRUE(!bare.strategy || strcmp(bare.strategy, "qualified_suffix") != 0);cbm_registry_free(r);@@ -826,26 +825,26 @@ TEST(cross_language_suffix_match_drops_py_vs_js) {* strategy that collapses them; unique_name is #1572 and must stay. */ASSERT_TRUE(cbm_suppress_cross_language_suffix_match(CBM_LANG_PYTHON, "web/src/pages/Editor.js","suffix_match"));- ASSERT_TRUE(cbm_suppress_cross_language_suffix_match(CBM_LANG_JAVASCRIPT, "store.py",- "suffix_match"));- ASSERT_TRUE(cbm_suppress_cross_language_suffix_match(CBM_LANG_BASH, "cli/main.py",- "suffix_match"));- ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(CBM_LANG_PYTHON, "store.py",- "suffix_match"));- ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(CBM_LANG_PYTHON, "web/src/pages/Editor.js",- "unique_name"));- ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(CBM_LANG_PYTHON, "web/src/pages/Editor.js",- "same_module"));- ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(CBM_LANG_PYTHON, "web/src/pages/Editor.js",- "import_map"));+ ASSERT_TRUE(+ cbm_suppress_cross_language_suffix_match(CBM_LANG_JAVASCRIPT, "store.py", "suffix_match"));+ ASSERT_TRUE(+ cbm_suppress_cross_language_suffix_match(CBM_LANG_BASH, "cli/main.py", "suffix_match"));+ ASSERT_FALSE(+ cbm_suppress_cross_language_suffix_match(CBM_LANG_PYTHON, "store.py", "suffix_match"));+ ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(+ CBM_LANG_PYTHON, "web/src/pages/Editor.js", "unique_name"));+ ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(+ CBM_LANG_PYTHON, "web/src/pages/Editor.js", "same_module"));+ ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(CBM_LANG_PYTHON,+ "web/src/pages/Editor.js", "import_map"));/* JS/TS/TSX are one family. */ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(CBM_LANG_JAVASCRIPT, "lib/util.ts","suffix_match"));ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(CBM_LANG_TYPESCRIPT, "ui/Panel.tsx","suffix_match"));ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(CBM_LANG_PYTHON, NULL, "suffix_match"));- ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(CBM_LANG_COUNT, "store.py",- "suffix_match"));+ ASSERT_FALSE(+ cbm_suppress_cross_language_suffix_match(CBM_LANG_COUNT, "store.py", "suffix_match"));PASS();}diff --git a/tests/test_simhash.c b/tests/test_simhash.cindex 9c114c431..a7f538d4c 100644--- a/tests/test_simhash.c+++ b/tests/test_simhash.c@@ -69,118 +69,118 @@ static int count_similar_to_edges(const cbm_gbuf_t *gb) {/* Large Go function template for fingerprint tests. Must have enough* structural diversity (>= 32 unique structural trigrams) after leaf-only* tokenisation and normalisation. */-#define GO_VALIDATE_USER_SRC \- "package main\n" \- "import \"errors\"\n" \- "import \"strings\"\n" \- "func ValidateUser(u User) error {\n" \- " if u.Name == \"\" {\n" \- " return errors.New(\"name required\")\n" \- " }\n" \- " if len(u.Name) > 100 {\n" \- " return errors.New(\"name too long\")\n" \- " }\n" \- " if u.Age < 0 {\n" \- " return errors.New(\"invalid age\")\n" \- " }\n" \- " if u.Age > 200 {\n" \- " return errors.New(\"age too high\")\n" \- " }\n" \- " if u.Email == \"\" {\n" \- " return errors.New(\"email required\")\n" \- " }\n" \- " if !strings.Contains(u.Email, \"@\") {\n" \- " return errors.New(\"invalid email\")\n" \- " }\n" \- " if u.Phone == \"\" {\n" \- " return errors.New(\"phone required\")\n" \- " }\n" \- " if len(u.Phone) < 7 {\n" \- " return errors.New(\"phone too short\")\n" \- " }\n" \- " if u.Country == \"\" {\n" \+#define GO_VALIDATE_USER_SRC \+ "package main\n" \+ "import \"errors\"\n" \+ "import \"strings\"\n" \+ "func ValidateUser(u User) error {\n" \+ " if u.Name == \"\" {\n" \+ " return errors.New(\"name required\")\n" \+ " }\n" \+ " if len(u.Name) > 100 {\n" \+ " return errors.New(\"name too long\")\n" \+ " }\n" \+ " if u.Age < 0 {\n" \+ " return errors.New(\"invalid age\")\n" \+ " }\n" \+ " if u.Age > 200 {\n" \+ " return errors.New(\"age too high\")\n" \+ " }\n" \+ " if u.Email == \"\" {\n" \+ " return errors.New(\"email required\")\n" \+ " }\n" \+ " if !strings.Contains(u.Email, \"@\") {\n" \+ " return errors.New(\"invalid email\")\n" \+ " }\n" \+ " if u.Phone == \"\" {\n" \+ " return errors.New(\"phone required\")\n" \+ " }\n" \+ " if len(u.Phone) < 7 {\n" \+ " return errors.New(\"phone too short\")\n" \+ " }\n" \+ " if u.Country == \"\" {\n" \" return errors.New(\"country required\")\n" \- " }\n" \- " for _, c := range u.Tags {\n" \- " if c == \"\" {\n" \- " return errors.New(\"empty tag\")\n" \- " }\n" \- " }\n" \- " return nil\n" \+ " }\n" \+ " for _, c := range u.Tags {\n" \+ " if c == \"\" {\n" \+ " return errors.New(\"empty tag\")\n" \+ " }\n" \+ " }\n" \+ " return nil\n" \"}\n"/* Same structure, different names/types — near-clone */-#define GO_VALIDATE_ORDER_SRC \- "package main\n" \- "import \"errors\"\n" \- "import \"strings\"\n" \- "func ValidateOrder(o Order) error {\n" \- " if o.Title == \"\" {\n" \- " return errors.New(\"title required\")\n" \- " }\n" \- " if len(o.Title) > 100 {\n" \- " return errors.New(\"title too long\")\n" \- " }\n" \- " if o.Amount < 0 {\n" \- " return errors.New(\"invalid amount\")\n" \- " }\n" \- " if o.Amount > 200 {\n" \- " return errors.New(\"amount too high\")\n" \- " }\n" \- " if o.Status == \"\" {\n" \- " return errors.New(\"status required\")\n" \- " }\n" \- " if !strings.Contains(o.Status, \"@\") {\n" \- " return errors.New(\"invalid status\")\n" \- " }\n" \- " if o.Region == \"\" {\n" \- " return errors.New(\"region required\")\n" \- " }\n" \- " if len(o.Region) < 7 {\n" \+#define GO_VALIDATE_ORDER_SRC \+ "package main\n" \+ "import \"errors\"\n" \+ "import \"strings\"\n" \+ "func ValidateOrder(o Order) error {\n" \+ " if o.Title == \"\" {\n" \+ " return errors.New(\"title required\")\n" \+ " }\n" \+ " if len(o.Title) > 100 {\n" \+ " return errors.New(\"title too long\")\n" \+ " }\n" \+ " if o.Amount < 0 {\n" \+ " return errors.New(\"invalid amount\")\n" \+ " }\n" \+ " if o.Amount > 200 {\n" \+ " return errors.New(\"amount too high\")\n" \+ " }\n" \+ " if o.Status == \"\" {\n" \+ " return errors.New(\"status required\")\n" \+ " }\n" \+ " if !strings.Contains(o.Status, \"@\") {\n" \+ " return errors.New(\"invalid status\")\n" \+ " }\n" \+ " if o.Region == \"\" {\n" \+ " return errors.New(\"region required\")\n" \+ " }\n" \+ " if len(o.Region) < 7 {\n" \" return errors.New(\"region too short\")\n" \- " }\n" \- " if o.Vendor == \"\" {\n" \- " return errors.New(\"vendor required\")\n" \- " }\n" \- " for _, c := range o.Items {\n" \- " if c == \"\" {\n" \- " return errors.New(\"empty item\")\n" \- " }\n" \- " }\n" \- " return nil\n" \+ " }\n" \+ " if o.Vendor == \"\" {\n" \+ " return errors.New(\"vendor required\")\n" \+ " }\n" \+ " for _, c := range o.Items {\n" \+ " if c == \"\" {\n" \+ " return errors.New(\"empty item\")\n" \+ " }\n" \+ " }\n" \+ " return nil\n" \"}\n"/* Completely different structure */-#define GO_HANDLE_REQUEST_SRC \- "package main\n" \- "import \"net/http\"\n" \- "import \"encoding/json\"\n" \- "import \"io\"\n" \+#define GO_HANDLE_REQUEST_SRC \+ "package main\n" \+ "import \"net/http\"\n" \+ "import \"encoding/json\"\n" \+ "import \"io\"\n" \"func HandleRequest(w http.ResponseWriter, r *http.Request) {\n" \- " body, err := io.ReadAll(r.Body)\n" \- " if err != nil {\n" \- " http.Error(w, err.Error(), 400)\n" \- " return\n" \- " }\n" \- " defer r.Body.Close()\n" \- " var data map[string]interface{}\n" \- " if err := json.Unmarshal(body, &data); err != nil {\n" \- " http.Error(w, err.Error(), 400)\n" \- " return\n" \- " }\n" \- " result := make(map[string]interface{})\n" \- " for k, v := range data {\n" \- " switch val := v.(type) {\n" \- " case string:\n" \- " result[k] = strings.ToUpper(val)\n" \- " case float64:\n" \- " result[k] = val * 2\n" \- " default:\n" \- " result[k] = v\n" \- " }\n" \- " }\n" \- " w.Header().Set(\"Content-Type\", \"application/json\")\n" \- " json.NewEncoder(w).Encode(result)\n" \+ " body, err := io.ReadAll(r.Body)\n" \+ " if err != nil {\n" \+ " http.Error(w, err.Error(), 400)\n" \+ " return\n" \+ " }\n" \+ " defer r.Body.Close()\n" \+ " var data map[string]interface{}\n" \+ " if err := json.Unmarshal(body, &data); err != nil {\n" \+ " http.Error(w, err.Error(), 400)\n" \+ " return\n" \+ " }\n" \+ " result := make(map[string]interface{})\n" \+ " for k, v := range data {\n" \+ " switch val := v.(type) {\n" \+ " case string:\n" \+ " result[k] = strings.ToUpper(val)\n" \+ " case float64:\n" \+ " result[k] = val * 2\n" \+ " default:\n" \+ " result[k] = v\n" \+ " }\n" \+ " }\n" \+ " w.Header().Set(\"Content-Type\", \"application/json\")\n" \+ " json.NewEncoder(w).Encode(result)\n" \"}\n"/* ═══════════════════════════════════════════════════════════════════@@ -205,8 +205,7 @@ TEST(minhash_identical_source_same_fingerprint) {ASSERT_EQ(d1->fingerprint_k, CBM_MINHASH_K);/* Identical source → identical fingerprint */- ASSERT_MEM_EQ(d1->fingerprint, d2->fingerprint,- (size_t)CBM_MINHASH_K * sizeof(uint32_t));+ ASSERT_MEM_EQ(d1->fingerprint, d2->fingerprint, (size_t)CBM_MINHASH_K * sizeof(uint32_t));cbm_free_result(r1);cbm_free_result(r2);@@ -230,9 +229,8 @@ TEST(minhash_renamed_vars_same_fingerprint) {ASSERT_NOT_NULL(da->fingerprint);ASSERT_NOT_NULL(db->fingerprint);- double j = cbm_minhash_jaccard(- (const cbm_minhash_t *)da->fingerprint,- (const cbm_minhash_t *)db->fingerprint);+ double j = cbm_minhash_jaccard((const cbm_minhash_t *)da->fingerprint,+ (const cbm_minhash_t *)db->fingerprint);/* Renamed vars + same structure → very high Jaccard */ASSERT_TRUE(j >= 0.90);@@ -258,9 +256,8 @@ TEST(minhash_different_code_different_fingerprint) {ASSERT_NOT_NULL(da->fingerprint);ASSERT_NOT_NULL(db->fingerprint);- double j = cbm_minhash_jaccard(- (const cbm_minhash_t *)da->fingerprint,- (const cbm_minhash_t *)db->fingerprint);+ double j = cbm_minhash_jaccard((const cbm_minhash_t *)da->fingerprint,+ (const cbm_minhash_t *)db->fingerprint);/* Different structure → low Jaccard */ASSERT_TRUE(j < 0.5);@@ -274,48 +271,47 @@ TEST(minhash_minor_edit_high_jaccard) {const char *src_a = GO_VALIDATE_USER_SRC;/* ValidateUser with one extra check added at the end */- const char *src_b =- "package main\n"- "import \"errors\"\n"- "import \"strings\"\n"- "func ValidateUser(u User) error {\n"- " if u.Name == \"\" {\n"- " return errors.New(\"name required\")\n"- " }\n"- " if len(u.Name) > 100 {\n"- " return errors.New(\"name too long\")\n"- " }\n"- " if u.Age < 0 {\n"- " return errors.New(\"invalid age\")\n"- " }\n"- " if u.Age > 200 {\n"- " return errors.New(\"age too high\")\n"- " }\n"- " if u.Email == \"\" {\n"- " return errors.New(\"email required\")\n"- " }\n"- " if !strings.Contains(u.Email, \"@\") {\n"- " return errors.New(\"invalid email\")\n"- " }\n"- " if u.Phone == \"\" {\n"- " return errors.New(\"phone required\")\n"- " }\n"- " if len(u.Phone) < 7 {\n"- " return errors.New(\"phone too short\")\n"- " }\n"- " if u.Country == \"\" {\n"- " return errors.New(\"country required\")\n"- " }\n"- " for _, c := range u.Tags {\n"- " if c == \"\" {\n"- " return errors.New(\"empty tag\")\n"- " }\n"- " }\n"- " if u.Active == false {\n"- " return errors.New(\"user inactive\")\n"- " }\n"- " return nil\n"- "}\n";+ const char *src_b = "package main\n"+ "import \"errors\"\n"+ "import \"strings\"\n"+ "func ValidateUser(u User) error {\n"+ " if u.Name == \"\" {\n"+ " return errors.New(\"name required\")\n"+ " }\n"+ " if len(u.Name) > 100 {\n"+ " return errors.New(\"name too long\")\n"+ " }\n"+ " if u.Age < 0 {\n"+ " return errors.New(\"invalid age\")\n"+ " }\n"+ " if u.Age > 200 {\n"+ " return errors.New(\"age too high\")\n"+ " }\n"+ " if u.Email == \"\" {\n"+ " return errors.New(\"email required\")\n"+ " }\n"+ " if !strings.Contains(u.Email, \"@\") {\n"+ " return errors.New(\"invalid email\")\n"+ " }\n"+ " if u.Phone == \"\" {\n"+ " return errors.New(\"phone required\")\n"+ " }\n"+ " if len(u.Phone) < 7 {\n"+ " return errors.New(\"phone too short\")\n"+ " }\n"+ " if u.Country == \"\" {\n"+ " return errors.New(\"country required\")\n"+ " }\n"+ " for _, c := range u.Tags {\n"+ " if c == \"\" {\n"+ " return errors.New(\"empty tag\")\n"+ " }\n"+ " }\n"+ " if u.Active == false {\n"+ " return errors.New(\"user inactive\")\n"+ " }\n"+ " return nil\n"+ "}\n";CBMFileResult *ra = extract_one(src_a, CBM_LANG_GO, "test", "a.go");CBMFileResult *rb = extract_one(src_b, CBM_LANG_GO, "test", "b.go");@@ -329,9 +325,8 @@ TEST(minhash_minor_edit_high_jaccard) {ASSERT_NOT_NULL(da->fingerprint);ASSERT_NOT_NULL(db->fingerprint);- double j = cbm_minhash_jaccard(- (const cbm_minhash_t *)da->fingerprint,- (const cbm_minhash_t *)db->fingerprint);+ double j = cbm_minhash_jaccard((const cbm_minhash_t *)da->fingerprint,+ (const cbm_minhash_t *)db->fingerprint);/* Minor edit → moderately high Jaccard. Trigram-based MinHash* is sensitive to insertions (shifts the trigram window), so a* single added statement may drop Jaccard more than expected.@@ -348,9 +343,8 @@ TEST(minhash_minor_edit_high_jaccard) {* Note: even a 2-line Go function can have 15+ AST nodes (Go's AST is verbose).* Use a truly minimal function to test the threshold. */TEST(minhash_empty_body_skipped) {- const char *src =- "package main\n"- "func Noop() {}\n";+ const char *src = "package main\n"+ "func Noop() {}\n";CBMFileResult *r = extract_one(src, CBM_LANG_GO, "test", "tiny.go");ASSERT_NOT_NULL(r);@@ -384,9 +378,8 @@ TEST(minhash_type_annotation_normalized) {ASSERT_NOT_NULL(da->fingerprint);ASSERT_NOT_NULL(db->fingerprint);- double j = cbm_minhash_jaccard(- (const cbm_minhash_t *)da->fingerprint,- (const cbm_minhash_t *)db->fingerprint);+ double j = cbm_minhash_jaccard((const cbm_minhash_t *)da->fingerprint,+ (const cbm_minhash_t *)db->fingerprint);/* Type annotations normalised → high Jaccard */ASSERT_TRUE(j >= 0.90);@@ -710,7 +703,8 @@ TEST(pass_similarity_edge_properties) {make_fp_props(props_b, sizeof(props_b), &fp_b);cbm_gbuf_t *gb = cbm_gbuf_new("test", "/tmp");- int64_t id_a = cbm_gbuf_upsert_node(gb, "Function", "foo", "test.a.foo", "a.go", 1, 10, props_a);+ int64_t id_a =+ cbm_gbuf_upsert_node(gb, "Function", "foo", "test.a.foo", "a.go", 1, 10, props_a);cbm_gbuf_upsert_node(gb, "Function", "bar", "test.b.bar", "b.go", 1, 10, props_b);atomic_int cancelled = 0;@@ -856,7 +850,8 @@ static int setup_sim_test_repo(void) {/* Near-clone: ValidateUser and ValidateOrder have same structure, different names.* Must be large enough (>= 30 leaf tokens, >= 32 unique structural trigrams). */- th_write_file(TH_PATH(g_sim_tmpdir, "pkg/validation/user_validator.go"),+ th_write_file(+ TH_PATH(g_sim_tmpdir, "pkg/validation/user_validator.go"),"package validation\n""import \"errors\"\n""import \"strings\"\n"@@ -876,7 +871,8 @@ static int setup_sim_test_repo(void) {" return nil\n""}\n");- th_write_file(TH_PATH(g_sim_tmpdir, "pkg/validation/order_validator.go"),+ th_write_file(+ TH_PATH(g_sim_tmpdir, "pkg/validation/order_validator.go"),"package validation\n""import \"errors\"\n""import \"strings\"\n"@@ -897,17 +893,15 @@ static int setup_sim_test_repo(void) {"}\n");/* Completely different function — also large enough for fingerprinting */- th_write_file(TH_PATH(g_sim_tmpdir, "pkg/handler/user_handler.go"),- GO_HANDLE_REQUEST_SRC);+ th_write_file(TH_PATH(g_sim_tmpdir, "pkg/handler/user_handler.go"), GO_HANDLE_REQUEST_SRC);/* Tiny function — should be skipped */- th_write_file(TH_PATH(g_sim_tmpdir, "pkg/util/tiny_helper.go"),- "package util\n"- "\n"- "func Max(a, b int) int {\n"- " if a > b { return a }\n"- " return b\n"- "}\n");+ th_write_file(TH_PATH(g_sim_tmpdir, "pkg/util/tiny_helper.go"), "package util\n"+ "\n"+ "func Max(a, b int) int {\n"+ " if a > b { return a }\n"+ " return b\n"+ "}\n");return 0;}@@ -976,44 +970,42 @@ TEST(pipeline_minhash_no_false_positives) {}/* 5 diverse functions — no clones */- th_write_file(TH_PATH(g_sim_tmpdir, "a.go"),- "package main\n"- "func SortSlice(s []int) {\n"- " for i := 0; i < len(s); i++ {\n"- " for j := i+1; j < len(s); j++ {\n"- " if s[i] > s[j] {\n"- " s[i], s[j] = s[j], s[i]\n"- " }\n"- " }\n"- " }\n"- "}\n");+ th_write_file(TH_PATH(g_sim_tmpdir, "a.go"), "package main\n"+ "func SortSlice(s []int) {\n"+ " for i := 0; i < len(s); i++ {\n"+ " for j := i+1; j < len(s); j++ {\n"+ " if s[i] > s[j] {\n"+ " s[i], s[j] = s[j], s[i]\n"+ " }\n"+ " }\n"+ " }\n"+ "}\n");th_write_file(TH_PATH(g_sim_tmpdir, "b.go"),- "package main\n"- "import \"net/http\"\n"- "func ServeAPI(mux *http.ServeMux) {\n"- " mux.HandleFunc(\"/health\", func(w http.ResponseWriter, r *http.Request) {\n"- " w.WriteHeader(200)\n"- " w.Write([]byte(\"ok\"))\n"- " })\n"- " mux.HandleFunc(\"/ready\", func(w http.ResponseWriter, r *http.Request) {\n"- " w.WriteHeader(200)\n"- " w.Write([]byte(\"ready\"))\n"- " })\n"- "}\n");-- th_write_file(TH_PATH(g_sim_tmpdir, "c.go"),- "package main\n"- "import \"fmt\"\n"- "func PrintTree(node *Node, depth int) {\n"- " for i := 0; i < depth; i++ {\n"- " fmt.Print(\" \")\n"- " }\n"- " fmt.Println(node.Value)\n"- " for _, child := range node.Children {\n"- " PrintTree(child, depth+1)\n"- " }\n"- "}\n");+ "package main\n"+ "import \"net/http\"\n"+ "func ServeAPI(mux *http.ServeMux) {\n"+ " mux.HandleFunc(\"/health\", func(w http.ResponseWriter, r *http.Request) {\n"+ " w.WriteHeader(200)\n"+ " w.Write([]byte(\"ok\"))\n"+ " })\n"+ " mux.HandleFunc(\"/ready\", func(w http.ResponseWriter, r *http.Request) {\n"+ " w.WriteHeader(200)\n"+ " w.Write([]byte(\"ready\"))\n"+ " })\n"+ "}\n");++ th_write_file(TH_PATH(g_sim_tmpdir, "c.go"), "package main\n"+ "import \"fmt\"\n"+ "func PrintTree(node *Node, depth int) {\n"+ " for i := 0; i < depth; i++ {\n"+ " fmt.Print(\" \")\n"+ " }\n"+ " fmt.Println(node.Value)\n"+ " for _, child := range node.Children {\n"+ " PrintTree(child, depth+1)\n"+ " }\n"+ "}\n");char db_path[512];snprintf(db_path, sizeof(db_path), "%s/test.db", g_sim_tmpdir);@@ -1029,7 +1021,8 @@ TEST(pipeline_minhash_no_false_positives) {cbm_edge_t *edges = NULL;int edge_count = 0;- cbm_store_find_edges_by_type(s, cbm_pipeline_project_name(p), "SIMILAR_TO", &edges, &edge_count);+ cbm_store_find_edges_by_type(s, cbm_pipeline_project_name(p), "SIMILAR_TO", &edges,+ &edge_count);ASSERT_EQ(edge_count, 0); /* No clones → no SIMILAR_TO edges */@@ -1072,17 +1065,17 @@ TEST(pipeline_minhash_incremental) {/* Step 2: Modify order_validator.go to be completely different */th_write_file(TH_PATH(g_sim_tmpdir, "pkg/validation/order_validator.go"),- "package validation\n"- "\n"- "import \"net/http\"\n"- "\n"- "func HandleOrder(w http.ResponseWriter, r *http.Request) {\n"- " data := make(map[string]interface{})\n"- " for k, v := range r.URL.Query() {\n"- " data[k] = v[0]\n"- " }\n"- " w.Header().Set(\"Content-Type\", \"application/json\")\n"- "}\n");+ "package validation\n"+ "\n"+ "import \"net/http\"\n"+ "\n"+ "func HandleOrder(w http.ResponseWriter, r *http.Request) {\n"+ " data := make(map[string]interface{})\n"+ " for k, v := range r.URL.Query() {\n"+ " data[k] = v[0]\n"+ " }\n"+ " w.Header().Set(\"Content-Type\", \"application/json\")\n"+ "}\n");/* Step 3: Incremental reindex */cbm_pipeline_t *p2 = cbm_pipeline_new(g_sim_tmpdir, db_path, CBM_MODE_FULL);@@ -1132,7 +1125,8 @@ TEST(pipeline_minhash_incremental_new_clone) {cbm_pipeline_free(p1);/* Step 2: Add a new near-clone of ValidateUser */- th_write_file(TH_PATH(g_sim_tmpdir, "pkg/validation/address_validator.go"),+ th_write_file(+ TH_PATH(g_sim_tmpdir, "pkg/validation/address_validator.go"),"package validation\n""import \"errors\"\n""import \"strings\"\n"