Skip to content

Commit 1c97a4d

Browse files
committed
Merge origin/main into fix/elixir-extraction-defects
Signed-off-by: Martin Vogel <[email protected]>
2 parents 6cc63d2 + 7b398de commit 1c97a4d

24 files changed

Lines changed: 1010 additions & 77 deletions

‎internal/cbm/cbm.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "foundation/hash_table.h" // CBMHashTable — crash-supervisor quarantine set
3131
#include "foundation/str_util.h" // cbm_json_escape — variants file_path
3232
#include "tree_sitter/api.h" // TSParser, TSNode, TSTree, TSInput, TSLanguage, TSPoint, TSParseOptions, TSParseState
33+
#include "foundation/platform.h"
3334
#include "foundation/constants.h"
3435
#include "mimalloc.h" // mi_malloc/mi_calloc/mi_realloc/mi_free/mi_usable_size — bind 3rd-party allocators (#424)
3536
#if defined(CBM_BIND_TS_ALLOCATOR) && CBM_BIND_TS_ALLOCATOR
@@ -1259,7 +1260,9 @@ static int count_params_from_signature(const char *sig) {
12591260
* unlucky in-flight file is never quarantined alone. The env var is set
12601261
* solely by the supervisor during recovery — a no-op on normal runs. */
12611262
static void cbm_index_mark(const char *rel_path, char event) {
1262-
const char *mf = getenv("CBM_INDEX_MARKER_FILE");
1263+
char marker_path[CBM_SZ_4K];
1264+
const char *mf =
1265+
cbm_safe_getenv("CBM_INDEX_MARKER_FILE", marker_path, sizeof(marker_path), NULL);
12631266
if (!mf || !mf[0] || !rel_path || !rel_path[0]) {
12641267
return;
12651268
}
@@ -1296,7 +1299,9 @@ enum { CBM_QSET_UNINIT = 0, CBM_QSET_INITING = 1, CBM_QSET_INITED = 2 };
12961299
static atomic_int g_quarantine_state = CBM_QSET_UNINIT;
12971300

12981301
static void cbm_quarantine_load(void) {
1299-
const char *qf = getenv("CBM_INDEX_QUARANTINE_FILE");
1302+
char quarantine_path[CBM_SZ_4K];
1303+
const char *qf = cbm_safe_getenv("CBM_INDEX_QUARANTINE_FILE", quarantine_path,
1304+
sizeof(quarantine_path), NULL);
13001305
if (!qf || !qf[0]) {
13011306
return; /* normal path: empty set */
13021307
}

‎internal/cbm/cbm.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,12 @@ typedef struct {
313313
* change of all, store_impact.h follow_variant_keys). NULL on every other
314314
* definition. Tail field: zero-init stays valid. */
315315
const char *variant_key;
316+
/* Go only (#2033): the raw aliased type text of an identity alias
317+
* `type A = B` ("B"). Carried to the cross-file registries so a method
318+
* call on A from another file follows the alias to B's method set. NULL
319+
* for a defined type `type A B` (its method set is its own) and in every
320+
* other language. Tail field: zero-init stays valid. */
321+
const char *alias_target;
316322
} CBMDefinition;
317323

318324
/* Argument captured from a call expression */

‎internal/cbm/extract_defs.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8299,6 +8299,15 @@ static void emit_class_def(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *s
82998299
def.decl_namespace = cs_type_decl_namespace(a, node, ctx->source);
83008300
}
83018301
def.base_classes = extract_base_classes(a, node, ctx->source, ctx->language);
8302+
// Go identity alias `type A = B` (#2033): keep the aliased type text so the
8303+
// cross-file registries can set alias_of. A defined type `type A B` is a
8304+
// type_spec and never gets here with this kind.
8305+
if (ctx->language == CBM_LANG_GO && strcmp(kind, "type_alias") == 0) {
8306+
TSNode target = ts_node_child_by_field_name(node, TS_FIELD("type"));
8307+
if (!ts_node_is_null(target)) {
8308+
def.alias_target = cbm_node_text(a, target, ctx->source);
8309+
}
8310+
}
83028311
def.decorators = extract_decorators(a, node, ctx->source, ctx->language, spec);
83038312
def.docstring = extract_docstring(ctx, node, name);
83048313

‎internal/cbm/lang_specs.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,7 @@ static const char *solidity_field_types[] = {"state_variable_declaration", "stru
10391039
static const char *solidity_call_types[] = {"call_expression", "call", "new_expression", NULL};
10401040
static const char *solidity_import_types[] = {"import_directive", "import", "using_directive",
10411041
NULL};
1042+
static const char *solidity_decorator_types[] = {"modifier_invocation", NULL};
10421043
static const char *solidity_branch_types[] = {"if_statement", "for_statement",
10431044
"while_statement", "do_while_statement",
10441045
"try_statement", NULL};
@@ -2116,7 +2117,7 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
21162117
solidity_field_types, solidity_module_types, solidity_call_types,
21172118
solidity_import_types, empty_types, solidity_branch_types,
21182119
solidity_var_types, solidity_assign_types, solidity_throw_types, NULL,
2119-
empty_types, NULL, NULL, tree_sitter_solidity, NULL},
2120+
solidity_decorator_types, NULL, NULL, tree_sitter_solidity, NULL},
21202121

21212122
// CBM_LANG_TYPST
21222123
[CBM_LANG_TYPST] = {CBM_LANG_TYPST, typst_func_types, empty_types, empty_types,

‎internal/cbm/lsp/go_lsp.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,6 +2705,27 @@ static const char **split_pipe_strings(CBMArena *a, const char *text) {
27052705
return idx > 0 ? arr : NULL;
27062706
}
27072707

2708+
/* QN of the type an identity alias `type A = B` names, for the def-driven
2709+
* cross-file registries (#2033). The per-file AST scan sets alias_of only for
2710+
* the file it walks, so an alias declared in another file of the package
2711+
* reaches a call only through here. Only a bare identifier is qualified (B
2712+
* declared in A's package); a qualified, pointer, composite or generic target
2713+
* stays NULL rather than guessed. */
2714+
static const char *go_alias_target_qn(CBMArena *arena, const char *target,
2715+
const char *def_module_qn) {
2716+
if (!target || !target[0] || !def_module_qn || !def_module_qn[0]) {
2717+
return NULL;
2718+
}
2719+
for (const unsigned char *p = (const unsigned char *)target; *p; p++) {
2720+
bool ident = (*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') ||
2721+
(*p >= '0' && *p <= '9') || *p == '_' || *p >= 0x80;
2722+
if (!ident) {
2723+
return NULL;
2724+
}
2725+
}
2726+
return cbm_arena_sprintf(arena, "%s.%s", def_module_qn, target);
2727+
}
2728+
27082729
// Helper: parse "|"-separated "name:type" field definitions and populate a registered type.
27092730
// Format: "Binder:Binder|Name:string|Count:int"
27102731
// type_text is resolved relative to def_module_qn.
@@ -3273,6 +3294,7 @@ void cbm_run_go_lsp_cross(CBMArena *arena, const char *source, int source_len,
32733294
if (rt.is_interface && d->method_names_str && d->method_names_str[0]) {
32743295
rt.method_names = split_pipe_strings(arena, d->method_names_str);
32753296
}
3297+
rt.alias_of = go_alias_target_qn(arena, d->alias_target, def_mod);
32763298

32773299
cbm_registry_add_type(&reg, rt);
32783300

@@ -3569,6 +3591,7 @@ CBMTypeRegistry *cbm_go_build_cross_registry(CBMArena *arena, CBMLSPDef *defs, i
35693591
if (rt.is_interface && d->method_names_str && d->method_names_str[0]) {
35703592
rt.method_names = split_pipe_strings(arena, d->method_names_str);
35713593
}
3594+
rt.alias_of = go_alias_target_qn(arena, d->alias_target, def_mod);
35723595
cbm_registry_add_type(reg, rt);
35733596
GO_NOTE_NEW_TYPES();
35743597
if (d->field_defs && d->field_defs[0]) {

‎internal/cbm/lsp/go_lsp.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ typedef struct {
102102
/* Callable identity (#2061): signature suffix of this def's graph QN;
103103
* qualified_name stays the base QN. NULL = none (always, until enabled). */
104104
const char *sig;
105+
/* Go only (#2033): raw aliased type text of `type A = B` ("B"), qualified
106+
* by the registrar against def_module_qn like return_types. NULL = not an
107+
* identity alias. */
108+
const char *alias_target;
105109
} CBMLSPDef;
106110

107111
// Parse source, build registry from defs + stdlib, run LSP.

0 commit comments

Comments
 (0)