Skip to content

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.

Merge branch 'main' into perf/py-cross-registry-index

Nelson Spence3b79e3d3bdfd
diff --cc internal/cbm/lsp/py_lsp.c
index e3ce24098,70de5dce7..04da95135
--- a/internal/cbm/lsp/py_lsp.c
+++ b/internal/cbm/lsp/py_lsp.c
@@@ -4966,36 -4965,51 +4966,77 @@@ static const char **py_split_pipe(CBMAr
return out;
}
+ /* Split a class def's field_defs ("name:QN|name:QN", built by the Python
+ * field fold in pass_lsp_cross.c) into the parallel NULL-terminated arrays a
+ * CBMRegisteredType carries. The types are already project QNs, so each one
+ * becomes a NAMED type verbatim. Without this, `obj.field.method()` on a class
+ * from another file lost the field's type (#1277); same-file classes get their
+ * fields from the per-file walk instead. Pure string work: no registry lookup
+ * happens here, so it is safe inside the type-registration pass. */
+ static void py_split_field_defs(CBMArena *arena, const char *field_defs, const char ***names_out,
+ const CBMType ***types_out) {
+ *names_out = NULL;
+ *types_out = NULL;
+ const char **pairs = py_split_pipe(arena, field_defs);
+ if (!pairs)
+ return;
+ int n = 0;
+ while (pairs[n])
+ n++;
+ const char **names =
+ (const char **)cbm_arena_alloc(arena, (size_t)(n + 1) * sizeof(const char *));
+ const CBMType **types =
+ (const CBMType **)cbm_arena_alloc(arena, (size_t)(n + 1) * sizeof(const CBMType *));
+ if (!names || !types)
+ return;
+ int kept = 0;
+ for (int i = 0; i < n; i++) {
+ char *colon = strchr(pairs[i], ':');
+ if (!colon || colon == pairs[i] || !colon[1])
+ continue;
+ *colon = '\0'; /* pairs[i] is this call's own arena copy */
+ names[kept] = pairs[i];
+ types[kept] = cbm_type_named(arena, colon + 1);
+ kept++;
+ }
+ if (kept == 0)
+ return;
+ names[kept] = NULL;
+ types[kept] = NULL;
+ *names_out = names;
+ *types_out = types;
+ }
+
+/* Qualified names of reg->types[0..noted), for a caller that registers into a
+ * registry it does not finalize until the end (cbm_py_build_cross_registry):
+ * that registry's own lookup scans every type. qns == NULL probes the
+ * registry instead. */
+typedef struct {
+ CBMHashTable *qns;
+ int noted;
+} PyKnownTypes;
+
+/* Note the types added since the last call. Run after every add_type, so an
+ * add that failed silently cannot desync set and registry. If the set cannot
+ * grow it is dropped and probes fall back to the registry. */
+static void py_note_known_types(PyKnownTypes *known, const CBMTypeRegistry *reg) {
+ for (; known && known->qns && known->noted < reg->type_count; known->noted++) {
+ const char *qn = reg->types[known->noted].qualified_name;
+ if (!qn || cbm_ht_has(known->qns, qn))
+ continue;
+ cbm_ht_set(known->qns, qn, (void *)(uintptr_t)(known->noted + 1));
+ if (!cbm_ht_has(known->qns, qn)) {
+ cbm_ht_free(known->qns);
+ known->qns = NULL;
+ }
+ }
+}
+
/* Build a registry from CBMLSPDef[] supplied by the caller — covers both
- * the source file's own defs and cross-file referenced defs. */
+ * the source file's own defs and cross-file referenced defs. known is NULL
+ * except for the shared Tier-2 build. */
static void py_register_lsp_defs(CBMArena *arena, CBMArena *idx_arena, CBMTypeRegistry *reg,
- CBMLSPDef *defs, int def_count) {
+ CBMLSPDef *defs, int def_count, PyKnownTypes *known) {
/* Pass 1: types only — the method pass probes the registry per Method def
* (receiver auto-registration), which is a LINEAR scan pre-finalize:
* O(methods x types) per file (same quadratic as php_register_lsp_defs;
@@@ -5017,8 -5031,8 +5058,9 @@@
if (d->method_names_str && d->method_names_str[0]) {
rt.method_names = py_split_pipe(arena, d->method_names_str);
}
+ py_split_field_defs(arena, d->field_defs, &rt.field_names, &rt.field_types);
cbm_registry_add_type(reg, rt);
+ py_note_known_types(known, reg);
}
}
/* idx_arena == NULL skips the mid-build finalize: the tier-2 builder
diff --cc tests/test_py_lsp.c
index 798c80a7b,d65341900..d92769bd5
--- a/tests/test_py_lsp.c
+++ b/tests/test_py_lsp.c
@@@ -2278,8 -2306,9 +2391,10 @@@ SUITE(py_lsp)
RUN_TEST(pylsp_pep695_generic_class);
/* Phase 9 — cross-file + batch */
RUN_TEST(pylsp_crossfile_method_dispatch);
+ RUN_TEST(pylsp_crossfile_receiver_through_typed_field);
+ RUN_TEST(pylsp_crossfile_typed_field_shared_registry);
RUN_TEST(pylsp_fused_self_attr_chain_via_overlay);
+ RUN_TEST(pylsp_cross_registry_interleaved_order);
RUN_TEST(pylsp_crossfile_classmethod_on_class_issue228);
RUN_TEST(pylsp_crossfile_inheritance);
RUN_TEST(pylsp_batch_two_files);