Skip to content

Commit c695cb7

Browse files
Merge branch 'main' into fix/py-definitions-oom
2 parents ffa0b32 + 13ce2c0 commit c695cb7

3 files changed

Lines changed: 461 additions & 60 deletions

File tree

‎src/pipeline/registry.c‎

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -858,9 +858,38 @@ void cbm_registry_free(cbm_registry_t *r) {
858858

859859
/* ── Registration ────────────────────────────────────────────────── */
860860

861+
/* Record `owned_qn` in the by-name bucket for `key`, keeping the bucket's
862+
* is_test flags in step with its entries.
863+
*
864+
* No array dedup needed: cbm_registry_add's exact-map check guarantees the QN
865+
* is new, and it calls this at most once per distinct key. */
866+
static void index_under_name(cbm_registry_t *r, const char *key, const char *owned_qn) {
867+
qn_array_t *arr = cbm_ht_get(r->by_name, key);
868+
if (!arr) {
869+
arr = calloc(CBM_ALLOC_ONE, sizeof(qn_array_t));
870+
cbm_ht_set(r->by_name, strdup(key), arr);
871+
}
872+
int before = arr->count;
873+
cbm_da_push(arr, (char *)owned_qn);
874+
if (arr->count == before) {
875+
return; /* the name could not be recorded: no verdict to cache */
876+
}
877+
if (arr->count > arr->is_test_cap) {
878+
int want = arr->cap > 0 ? arr->cap : arr->count;
879+
uint8_t *grown =
880+
cbm_realloc(CBM_MEM_CLASS_DYN_ARRAY, arr->is_test, (size_t)want * sizeof(uint8_t));
881+
if (grown) {
882+
arr->is_test = grown;
883+
arr->is_test_cap = want;
884+
}
885+
}
886+
if (arr->count <= arr->is_test_cap) {
887+
arr->is_test[arr->count - SKIP_ONE] = is_test_qn(owned_qn) ? 1 : 0;
888+
}
889+
}
890+
861891
void cbm_registry_add(cbm_registry_t *r, const char *name, const char *qualified_name,
862892
const char *label) {
863-
(void)name;
864893
if (!r || !qualified_name || !label) {
865894
return;
866895
}
@@ -893,30 +922,37 @@ void cbm_registry_add(cbm_registry_t *r, const char *name, const char *qualified
893922
cbm_ht_set(r->exact, strdup(qualified_name), (void *)interned);
894923
const char *owned_qn = cbm_ht_get_key(r->exact, qualified_name);
895924

896-
/* Index by simple name.
897-
* No array dedup needed: exact-map check above guarantees uniqueness. */
898-
const char *simple = simple_name(qualified_name);
899-
qn_array_t *arr = cbm_ht_get(r->by_name, simple);
900-
if (!arr) {
901-
arr = calloc(CBM_ALLOC_ONE, sizeof(qn_array_t));
902-
cbm_ht_set(r->by_name, strdup(simple), arr);
903-
}
904-
int before = arr->count;
905-
cbm_da_push(arr, (char *)owned_qn);
906-
if (arr->count == before) {
907-
return; /* the name could not be recorded: no verdict to cache */
908-
}
909-
if (arr->count > arr->is_test_cap) {
910-
int want = arr->cap > 0 ? arr->cap : arr->count;
911-
uint8_t *grown =
912-
cbm_realloc(CBM_MEM_CLASS_DYN_ARRAY, arr->is_test, (size_t)want * sizeof(uint8_t));
913-
if (grown) {
914-
arr->is_test = grown;
915-
arr->is_test_cap = want;
916-
}
917-
}
918-
if (arr->count <= arr->is_test_cap) {
919-
arr->is_test[arr->count - SKIP_ONE] = is_test_qn(owned_qn) ? 1 : 0;
925+
/* Index the symbol under the QN's last dot segment, and additionally under
926+
* the name its caller passed when that segment carries a '#' fence.
927+
*
928+
* The derived key is the one every language has always used and it stays
929+
* unconditional, so a grammar whose QNs carry no '#' is byte-identical to
930+
* before this commit. The second key exists for one shape: a fenced tail is
931+
* a literal string no bare callee is ever written as. rust_cfg_qualified_name
932+
* mints a `#[cfg(test)]` twin as "proj.lib.add#cfg(test)", simple_name() has
933+
* no '#' handling, so the derived key filed that function under the whole
934+
* string "add#cfg(test)" where no bare `add` callee could reach it.
935+
*
936+
* Gating on the fence rather than on the file's language is what makes
937+
* "unchanged for every other grammar" checkable instead of asserted. Every
938+
* by-name lookup keys through simple_name(), which splits on '.' and "::"
939+
* only, so a passed name that differs from the derived key by anything
940+
* OTHER than a fence is a key no lookup can reach: an HCL block's
941+
* "resource.aws_instance.web" and a TOML table's "tool.poetry.dependencies"
942+
* are both already indexed under the tail a reference spells, and adding
943+
* their dotted form would only widen the bucket the scorer walks.
944+
*
945+
* `name` is NULL or empty only for callers that have no symbol name to
946+
* give; those have the derived key and nothing else. */
947+
const char *derived = simple_name(qualified_name);
948+
index_under_name(r, derived, owned_qn);
949+
/* '#' is a QN fence, and extract_defs.c's rust_cfg_qualified_name is the
950+
* only thing in the tree that mints one today. A grammar that starts
951+
* minting a '#' opts into this second key by doing so, whatever it means by
952+
* the fence: its symbols become reachable under the passed name as well,
953+
* and they share that name's bucket with everything else filed under it. */
954+
if (name && name[0] && strchr(derived, '#') && strcmp(name, derived) != 0) {
955+
index_under_name(r, name, owned_qn);
920956
}
921957
}
922958

0 commit comments

Comments
 (0)