Skip to content

Commit 729ce33

Browse files
committed
fix(java): register generated record accessors by qualified name only
A record's implicit accessors are members the compiler writes and the source never spells. Their nodes now carry the property generated=record, and every registry registration path files them in the exact (qualified-name) map only, never in the short-name index. The Java type-aware resolver still binds p.y() on a Point to Point.y; a call such as v.y() on a type from outside the project no longer binds the accessor through a unique_name / suffix_match / field_type_hint / fuzzy guess. - extract_defs.c: each implicit accessor carries extra_props generated=record (key CBM_PROP_GENERATED, cbm.h). - registry.c: cbm_registry_add_qn_only, and the pure predicates cbm_def_props_generated / cbm_node_props_generated. - pass_definitions.c, pass_parallel.c, pipeline_incremental.c: the three registration sites route a generated member to the exact map only. - pipeline_delta.c: the incremental preseed proxy keeps the mark, so an incremental re-index registers the member exactly as a full one does (the proxy carried only a few properties and the accessor came back into the short-name index). Tests: pipeline_java_record_accessors_generated_qn_only (sequential, parallel and incremental venues) and two registry unit tests. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 373c090 commit 729ce33

10 files changed

Lines changed: 419 additions & 14 deletions

File tree

‎internal/cbm/cbm.h‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,10 @@ typedef struct {
298298
* are bound to the owning result's source identity before cross-file use. */
299299
uint32_t test_name_start_byte, test_name_end_byte;
300300
uint32_t test_body_start_byte, test_body_end_byte;
301-
/* Documents only: facts a document definition adds to its node's
302-
* properties, as a NULL-terminated key, value, key, value, ... list (an
303-
* ADR's id, status, date, deciders, title). Keys are fixed literals; the
301+
/* Facts a definition adds to its node's properties, as a NULL-terminated
302+
* key, value, key, value, ... list: a document's (an ADR's id, status,
303+
* date, deciders, title), or CBM_PROP_GENERATED on a member the compiler
304+
* writes and the source never spells. Keys are fixed literals; the
304305
* values are escaped where the properties are written. Tail field:
305306
* zero-init stays valid. */
306307
const char **extra_props;
@@ -315,6 +316,13 @@ typedef struct {
315316
const char *variant_key;
316317
} CBMDefinition;
317318

319+
/* extra_props key of a generated member, one the compiler writes and the
320+
* source never spells: a Java record's implicit accessor carries
321+
* `generated: record`. The node keeps the property, and the pipeline registers
322+
* such a definition by qualified name only, so no short-name guess can land on
323+
* it (pipeline.h cbm_def_props_generated). */
324+
#define CBM_PROP_GENERATED "generated"
325+
318326
/* Argument captured from a call expression */
319327
typedef struct {
320328
const char *expr; // raw expression text ("payload.info", "MY_URL", "'hello'")

‎internal/cbm/extract_defs.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9668,6 +9668,16 @@ static void extract_record_accessors(CBMExtractCtx *ctx, TSNode node, const char
96689668
const char *type = cbm_node_text(a, ctype, ctx->source);
96699669
adef.return_type = spread && type ? cbm_arena_sprintf(a, "%s[]", type) : type;
96709670
}
9671+
/* The compiler writes this member and the source never spells it: its
9672+
* node says so, and the pipeline registers it by qualified name only,
9673+
* so no short-name guess can land on it. */
9674+
const char **kv = (const char **)cbm_arena_alloc(a, CBM_SZ_3 * sizeof(char *));
9675+
if (kv) {
9676+
kv[0] = CBM_PROP_GENERATED;
9677+
kv[SKIP_ONE] = "record";
9678+
kv[PAIR_LEN] = NULL;
9679+
}
9680+
adef.extra_props = kv;
96719681
cbm_defs_push(&ctx->result->defs, a, adef);
96729682
}
96739683
}

‎src/pipeline/pass_definitions.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,15 @@ static void process_def(cbm_pipeline_ctx_t *ctx, const CBMDefinition *def, const
509509
* (helpers.c): callables + type-like containers (INHERITS/IMPLEMENTS/method/
510510
* field resolution), Variable/Field (READS/WRITES resolution), and Table/View
511511
* (SQL FROM/JOIN lineage). pass_parallel.c and pipeline_incremental.c seed
512-
* through the same predicate, so the three registries cannot diverge. */
512+
* through the same predicate, so the three registries cannot diverge.
513+
* A generated member is registered by qualified name only, at all three. */
513514
if (node_id > 0 && cbm_label_is_registry_symbol(def->label)) {
514-
cbm_registry_add_lang_in_module(ctx->registry, def->name, def->qualified_name, def->label,
515-
lang, module_prefix_len);
515+
if (cbm_def_props_generated(def->extra_props)) {
516+
cbm_registry_add_qn_only(ctx->registry, def->qualified_name, def->label);
517+
} else {
518+
cbm_registry_add_lang_in_module(ctx->registry, def->name, def->qualified_name,
519+
def->label, lang, module_prefix_len);
520+
}
516521
}
517522
char *file_qn = cbm_pipeline_fqn_compute(ctx->project_name, rel, "__file__");
518523
const cbm_gbuf_node_t *file_node = cbm_gbuf_find_by_qn(ctx->gbuf, file_qn);

‎src/pipeline/pass_parallel.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,10 +1811,15 @@ static int register_and_link_def(cbm_pipeline_ctx_t *ctx, const CBMDefinition *d
18111811
return 0;
18121812
}
18131813
/* Registry membership is defined ONCE by cbm_label_is_registry_symbol
1814-
* (helpers.c) — see pass_definitions.c for the per-label rationale. */
1814+
* (helpers.c) — see pass_definitions.c for the per-label rationale, and
1815+
* for the generated member registered by qualified name only. */
18151816
if (cbm_label_is_registry_symbol(def->label)) {
1816-
cbm_registry_add_lang_in_module(ctx->registry, def->name, def->qualified_name, def->label,
1817-
lang, module_prefix_len);
1817+
if (cbm_def_props_generated(def->extra_props)) {
1818+
cbm_registry_add_qn_only(ctx->registry, def->qualified_name, def->label);
1819+
} else {
1820+
cbm_registry_add_lang_in_module(ctx->registry, def->name, def->qualified_name,
1821+
def->label, lang, module_prefix_len);
1822+
}
18181823
(*reg_entries)++;
18191824
}
18201825
char marked[CBM_SZ_4K];

‎src/pipeline/pipeline.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,24 @@ void cbm_registry_add_lang_in_module(cbm_registry_t *r, const char *name,
277277
const char *qualified_name, const char *label,
278278
CBMLanguage lang, size_t module_prefix_len);
279279

280+
/* Register a symbol for exact (qualified-name) lookups only: it is never
281+
* offered to the short-name strategies (unique_name, suffix_match,
282+
* field_type_hint, fuzzy). For a generated member (cbm_def_props_generated),
283+
* which the source never spells, so only a type-aware resolver that knows its
284+
* owner may bind it. The three graph registration sites route such a symbol
285+
* here instead of cbm_registry_add_lang_in_module. */
286+
void cbm_registry_add_qn_only(cbm_registry_t *r, const char *qualified_name, const char *label);
287+
288+
/* True when a definition's extra_props (key, value, ..., NULL) carry the
289+
* generated-member key (cbm.h CBM_PROP_GENERATED), e.g. a Java record's
290+
* implicit accessor. Pure; unit-tested in test_registry.c. */
291+
bool cbm_def_props_generated(const char *const *extra_props);
292+
293+
/* The stored-node twin of cbm_def_props_generated, for the incremental
294+
* registry seed: true when a node's properties JSON carries that key as a
295+
* string property. Pure; unit-tested in test_registry.c. */
296+
bool cbm_node_props_generated(const char *properties_json);
297+
280298
/* True when code in `caller` can call a symbol defined in `target` by bare
281299
* name: same language, same interop family (JS/TS + script hosts, C/C++/CUDA/
282300
* ObjC, JVM, .NET, ...; the table lives in registry.c), or Swift with the C

‎src/pipeline/pipeline_delta.c‎

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,39 @@ static char *delta_owner_props(const char *project, const char *name, const char
590590
return out;
591591
}
592592

593+
/* `props` (a JSON object) with a generated member's mark (cbm.h
594+
* CBM_PROP_GENERATED) added, or NULL when `generated` is NULL/empty
595+
* (CBM_MEM_CLASS_OTHER; the caller frees). */
596+
static char *delta_generated_props(const char *props, const char *generated) {
597+
if (!generated || !generated[0]) {
598+
return NULL;
599+
}
600+
size_t pl = props ? strlen(props) : 0;
601+
bool has_members = pl > PAIR_LEN && props[0] == '{' && props[pl - SKIP_ONE] == '}';
602+
size_t cap = pl + PAIR_LEN * strlen(generated) + CBM_SZ_32;
603+
char *out = (char *)cbm_alloc(CBM_MEM_CLASS_OTHER, cap);
604+
if (!out) {
605+
return NULL;
606+
}
607+
size_t k = 0;
608+
if (has_members) {
609+
memcpy(out, props, pl - SKIP_ONE);
610+
k = pl - SKIP_ONE;
611+
out[k++] = ',';
612+
} else {
613+
out[k++] = '{';
614+
}
615+
k += (size_t)snprintf(out + k, cap - k, "\"%s\":\"", CBM_PROP_GENERATED);
616+
for (const char *p = generated; *p && k + CBM_SZ_3 < cap; p++) {
617+
if (*p == '"' || *p == '\\') {
618+
out[k++] = '\\';
619+
}
620+
out[k++] = *p;
621+
}
622+
snprintf(out + k, cap - k, "\"}");
623+
return out;
624+
}
625+
593626
int64_t cbm_delta_preseed(cbm_store_t *store, const char *project, cbm_gbuf_t *gbuf) {
594627
sqlite3 *db = cbm_store_get_db(store);
595628
if (!db) {
@@ -634,7 +667,12 @@ int64_t cbm_delta_preseed(cbm_store_t *store, const char *project, cbm_gbuf_t *g
634667
* goes by -- a Go method's QN has no receiver, a class-body variable's QN
635668
* no class. A document naming `Order.Reset` binds such a node through
636669
* its owner (doc_links_pdf.c), so a re-resolved document needs it too.
637-
* Only where owner + name differs from the QN (delta_owner_props). */
670+
* Only where owner + name differs from the QN (delta_owner_props).
671+
*
672+
* And a generated member's mark (a Java record's implicit accessor, a
673+
* Method node): the registry seed reads it to register the member by
674+
* qualified name only, as the full build does (cbm_node_props_generated);
675+
* without it the proxy came back into the short-name index. */
638676
sqlite3_stmt *stmt = NULL;
639677
if (sqlite3_prepare_v2(
640678
db,
@@ -646,7 +684,10 @@ int64_t cbm_delta_preseed(cbm_store_t *store, const char *project, cbm_gbuf_t *g
646684
" start_line, end_line,"
647685
" CASE WHEN label IN ('Method','Variable')"
648686
" AND instr(properties, '\"parent_class\"') > 0"
649-
" THEN json_extract(properties, '$.parent_class') END"
687+
" THEN json_extract(properties, '$.parent_class') END,"
688+
" CASE WHEN label = 'Method'"
689+
" AND instr(properties, '\"" CBM_PROP_GENERATED "\"') > 0"
690+
" THEN json_extract(properties, '$." CBM_PROP_GENERATED "') END"
650691
" FROM nodes"
651692
" WHERE project = ?1 AND label NOT IN"
652693
" ('Macro','Comment','Section','Branch','Commit','Tag')"
@@ -670,13 +711,16 @@ int64_t cbm_delta_preseed(cbm_store_t *store, const char *project, cbm_gbuf_t *g
670711
int start_line = sqlite3_column_int(stmt, 6);
671712
int end_line = sqlite3_column_int(stmt, 7);
672713
const char *parent = (const char *)sqlite3_column_text(stmt, 8);
714+
const char *generated = (const char *)sqlite3_column_text(stmt, 9);
673715
char *owner_props =
674716
parent ? delta_owner_props(project, name, qn, parent, client_props) : NULL;
717+
const char *props = owner_props ? owner_props : (client_props ? client_props : "{}");
718+
char *generated_props = delta_generated_props(props, generated);
675719
/* Pin the gbuf id to the database id: proxies ARE their rows. */
676720
cbm_gbuf_set_next_id(gbuf, id);
677-
int64_t got =
678-
cbm_gbuf_upsert_node(gbuf, label, name, qn, fp ? fp : "", start_line, end_line,
679-
owner_props ? owner_props : (client_props ? client_props : "{}"));
721+
int64_t got = cbm_gbuf_upsert_node(gbuf, label, name, qn, fp ? fp : "", start_line,
722+
end_line, generated_props ? generated_props : props);
723+
cbm_free(CBM_MEM_CLASS_OTHER, generated_props);
680724
cbm_free(CBM_MEM_CLASS_OTHER, owner_props);
681725
if (got != id) {
682726
/* A QN collision inside the preseed set would silently split

‎src/pipeline/pipeline_incremental.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,12 @@ static void registry_visitor(const cbm_gbuf_node_t *node, void *userdata) {
13481348
if (!incr_label_is_registry_symbol(node->label)) {
13491349
return;
13501350
}
1351+
/* A generated member stays out of the short-name index here as in the
1352+
* full index (pass_definitions.c); its node carries the mark. */
1353+
if (cbm_node_props_generated(node->properties_json)) {
1354+
cbm_registry_add_qn_only(seed->registry, node->qualified_name, node->label);
1355+
return;
1356+
}
13511357
CBMLanguage lang = cbm_registry_synthetic_path_language(node->file_path);
13521358
if (lang == CBM_LANG_COUNT && seed->lang_by_path && node->file_path) {
13531359
void *v = cbm_ht_get(seed->lang_by_path, node->file_path);

‎src/pipeline/registry.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,32 @@ void cbm_registry_add_lang_in_module(cbm_registry_t *r, const char *name,
14061406
}
14071407
}
14081408

1409+
/* A generated member (a Java record's implicit accessor) is a definition the
1410+
* source never spells: no call names it except through its owner's type. The
1411+
* exact map holds it for the LSP targets and the import/same-module lookups,
1412+
* as it holds a Python function's locals; the by-name index does not, so no
1413+
* unique_name / suffix_match / field_type_hint / fuzzy guess can land on it. */
1414+
void cbm_registry_add_qn_only(cbm_registry_t *r, const char *qualified_name, const char *label) {
1415+
if (!r || !qualified_name || !label) {
1416+
return;
1417+
}
1418+
(void)registry_add_exact(r, qualified_name, label);
1419+
}
1420+
1421+
bool cbm_def_props_generated(const char *const *extra_props) {
1422+
for (const char *const *kv = extra_props; kv && kv[0] && kv[SKIP_ONE]; kv += PAIR_LEN) {
1423+
if (strcmp(kv[0], CBM_PROP_GENERATED) == 0) {
1424+
return true;
1425+
}
1426+
}
1427+
return false;
1428+
}
1429+
1430+
bool cbm_node_props_generated(const char *properties_json) {
1431+
/* The key as the definition passes write it: "generated":"<value>". */
1432+
return properties_json && strstr(properties_json, "\"" CBM_PROP_GENERATED "\":\"") != NULL;
1433+
}
1434+
14091435
/* ── Lookup ──────────────────────────────────────────────────────── */
14101436

14111437
bool cbm_registry_exists(const cbm_registry_t *r, const char *qn) {

0 commit comments

Comments
 (0)