Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/pipeline/pass_calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1060,18 +1060,20 @@ static bool calls_emit_lsp_target(cbm_pipeline_ctx_t *ctx, const CBMCall *call,

/* Vendor receivers, Java library receivers and cross-language name guesses
* cannot bind project calls. Keep the registry policy shared with the
* parallel resolver. */
* parallel resolver. `caller_test`: cbm_pipeline_caller_is_test of the
* calling definition. */
static cbm_resolution_t calls_registry_resolution(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
const char *module_qn, const char **imp_keys,
const char **imp_vals, int imp_count,
CBMLanguage lang, bool rust_external,
bool php_vendor_call, bool java_external) {
bool php_vendor_call, bool java_external,
bool caller_test) {
cbm_resolution_t res = {0};
if (!rust_external && !php_vendor_call && !java_external) {
/* Python LEGB fallback first (MUST match pass_parallel.c). */
res =
cbm_registry_resolve_call_scoped(ctx->registry, call->callee_name, module_qn, imp_keys,
imp_vals, imp_count, lang, call->enclosing_func_qn);
res = cbm_registry_resolve_call_scoped(ctx->registry, call->callee_name, module_qn,
imp_keys, imp_vals, imp_count, lang,
call->enclosing_func_qn, caller_test);
/* Cross-language veto: a name-only guess never binds another
* language's symbol (a JS app.get must not become Python's
* builtins.dict.get). The vetoed answer becomes EMPTY here, before
Expand Down Expand Up @@ -1239,7 +1241,8 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call, const CBM
cbm_resolution_t res = {0};
if (swift_candidates >= 0) {
res = calls_registry_resolution(ctx, call, module_qn, imp_keys, imp_vals, imp_count, lang,
rust_external, php_vendor_call, java_external);
rust_external, php_vendor_call, java_external,
cbm_pipeline_caller_is_test(source_node, rel, lang));
}
/* `p->open(fd)`: the registry does not split a callee on the arrow, and a
* member is not a name it could resolve anyway. The object's type decides,
Expand Down
16 changes: 12 additions & 4 deletions src/pipeline/pass_definitions.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum { PD_SWIFT_PROPS_MARGIN = 80 };
#include "foundation/mem_core.h"
#include "foundation/str_util.h"
#include "cbm.h"
#include "helpers.h" /* cbm_is_test_file */
#include "arena.h"
#include "iris_export_xml.h"
#include "simhash/minhash.h"
Expand Down Expand Up @@ -522,15 +523,22 @@ static void process_def(cbm_pipeline_ctx_t *ctx, const CBMDefinition *def, const
* (SQL FROM/JOIN lineage). pass_parallel.c and pipeline_incremental.c seed
* through the same predicate, so the three registries cannot diverge.
* A generated member is registered by qualified name only, at all three.
* The registry's test verdict is the extractor's OR the test-double path
* rule (cbm_registry_test_double_path) on the node's file, at all three. */
* The registry's test verdict is the extractor's, OR the extractor's own
* file rule (cbm_is_test_file) on the node's file and language, OR the
* test-double path rule (cbm_registry_test_double_path), at all three.
* The file rule is needed because the extractor gives a definition the
* file's verdict only for functions, methods and the module: a variable,
* field or class in a test file keeps is_test=false, and ranked as real
* code it beat production candidates on proximity. Ranking only: the
* stored is_test property is untouched. */
if (node_id > 0 && cbm_label_is_registry_symbol(def->label)) {
if (cbm_def_props_generated(def->extra_props)) {
cbm_registry_add_qn_only(ctx->registry, def->qualified_name, def->label);
} else {
bool is_test = def->is_test || cbm_is_test_file(def_rel, lang) ||
cbm_registry_test_double_path(def_rel);
cbm_registry_add_lang_in_module(ctx->registry, def->name, def->qualified_name,
def->label, lang, module_prefix_len,
def->is_test || cbm_registry_test_double_path(def_rel));
def->label, lang, module_prefix_len, is_test);
}
if (def->qn_sig_off) {
cbm_registry_set_swift_signature(ctx->registry, def->qualified_name,
Expand Down
24 changes: 14 additions & 10 deletions src/pipeline/pass_parallel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1826,15 +1826,17 @@ static int register_and_link_def(cbm_pipeline_ctx_t *ctx, const CBMDefinition *d
/* Registry membership is defined ONCE by cbm_label_is_registry_symbol
* (helpers.c) — see pass_definitions.c for the per-label rationale, for
* the generated member registered by qualified name only, and for the
* test-double path rule, judged on the path the def's node stores. */
* test verdict (the extractor's, its file rule, the test-double path
* rule), judged on the path the def's node stores. */
if (cbm_label_is_registry_symbol(def->label)) {
if (cbm_def_props_generated(def->extra_props)) {
cbm_registry_add_qn_only(ctx->registry, def->qualified_name, def->label);
} else {
const char *def_rel = def->file_path ? def->file_path : rel;
bool is_test = def->is_test || cbm_is_test_file(def_rel, lang) ||
cbm_registry_test_double_path(def_rel);
cbm_registry_add_lang_in_module(ctx->registry, def->name, def->qualified_name,
def->label, lang, module_prefix_len,
def->is_test || cbm_registry_test_double_path(def_rel));
def->label, lang, module_prefix_len, is_test);
}
if (def->qn_sig_off) {
cbm_registry_set_swift_signature(ctx->registry, def->qualified_name,
Expand Down Expand Up @@ -3466,9 +3468,9 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB
if ((!res.qualified_name || !res.qualified_name[0]) && !call->requires_lsp_resolution &&
!rust_external && !php_vendor_call && !java_external && count == 0) {
/* Python LEGB fallback first (MUST match pass_calls.c). */
res = cbm_registry_resolve_call_scoped(rc->registry, call->callee_name, module_qn,
imp_keys, imp_vals, imp_count, lang,
call->enclosing_func_qn);
res = cbm_registry_resolve_call_scoped(
rc->registry, call->callee_name, module_qn, imp_keys, imp_vals, imp_count, lang,
call->enclosing_func_qn, cbm_pipeline_caller_is_test(source_node, rel, lang));
}
/* `p->open(fd)`: the registry does not split a callee on the arrow.
* The object's type decides, as for the dot call handled further
Expand Down Expand Up @@ -3940,8 +3942,9 @@ static void resolve_file_usages(resolve_ctx_t *rc, resolve_worker_state_t *ws,
(lang == CBM_LANG_SQL)
? cbm_registry_resolve_lineage(rc->registry, usage->ref_name, module_qn,
imp_keys, imp_vals, imp_count)
: cbm_registry_resolve_lang(rc->registry, usage->ref_name, module_qn, imp_keys,
imp_vals, imp_count, lang);
: cbm_registry_resolve_ref(rc->registry, usage->ref_name, module_qn, imp_keys,
imp_vals, imp_count, lang,
cbm_pipeline_caller_is_test(src, rel, lang));
if (!res.qualified_name || res.qualified_name[0] == '\0') {
continue;
}
Expand Down Expand Up @@ -4080,8 +4083,9 @@ static void resolve_file_rw(resolve_ctx_t *rc, resolve_worker_state_t *ws, CBMFi
}
continue;
}
cbm_resolution_t res = cbm_registry_resolve_lang(rc->registry, rw->var_name, module_qn,
imp_keys, imp_vals, imp_count, lang);
cbm_resolution_t res =
cbm_registry_resolve_ref(rc->registry, rw->var_name, module_qn, imp_keys, imp_vals,
imp_count, lang, cbm_pipeline_caller_is_test(src, rel, lang));
if (!res.qualified_name || res.qualified_name[0] == '\0') {
continue;
}
Expand Down
6 changes: 6 additions & 0 deletions src/pipeline/pass_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum {
#include "graph_buffer/graph_buffer.h"
#include "discover/discover.h"
#include "foundation/log.h"
#include "helpers.h" /* cbm_is_test_file */

#include <stdio.h>
#include <stdlib.h>
Expand All @@ -52,6 +53,11 @@ bool cbm_node_is_test(const cbm_gbuf_node_t *n) {
return strstr(n->properties_json, "\"is_test\":true") != NULL;
}

bool cbm_pipeline_caller_is_test(const cbm_gbuf_node_t *source, const char *rel, CBMLanguage lang) {
return cbm_node_is_test(source) || cbm_is_test_file(rel, lang) ||
cbm_registry_test_double_path(rel);
}

/* Helper to check suffix. */
static bool str_ends_with(const char *s, size_t slen, const char *suffix) {
size_t sflen = strlen(suffix);
Expand Down
10 changes: 6 additions & 4 deletions src/pipeline/pass_usages.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ static int resolve_usage_edges(cbm_pipeline_ctx_t *ctx, const CBMFileResult *res
(lang == CBM_LANG_SQL)
? cbm_registry_resolve_lineage(ctx->registry, usage->ref_name, module_qn,
imp_keys, imp_vals, imp_count)
: cbm_registry_resolve_lang(ctx->registry, usage->ref_name, module_qn, imp_keys,
imp_vals, imp_count, lang);
: cbm_registry_resolve_ref(ctx->registry, usage->ref_name, module_qn, imp_keys,
imp_vals, imp_count, lang,
cbm_pipeline_caller_is_test(src, rel, lang));
if (!res.qualified_name || res.qualified_name[0] == '\0') {
continue;
}
Expand Down Expand Up @@ -405,8 +406,9 @@ static int resolve_rw_edges(cbm_pipeline_ctx_t *ctx, const CBMFileResult *result
continue;
}

cbm_resolution_t res = cbm_registry_resolve_lang(ctx->registry, rw->var_name, module_qn,
imp_keys, imp_vals, imp_count, lang);
cbm_resolution_t res =
cbm_registry_resolve_ref(ctx->registry, rw->var_name, module_qn, imp_keys, imp_vals,
imp_count, lang, cbm_pipeline_caller_is_test(src, rel, lang));
if (!res.qualified_name || res.qualified_name[0] == '\0') {
continue;
}
Expand Down
15 changes: 10 additions & 5 deletions src/pipeline/pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,12 @@ void cbm_registry_free(cbm_registry_t *r);

/* Register a function/method/class. All strings are copied. The entry's
* language is unknown, so name-based resolution never filters it out.
* `is_test` is the extractor's verdict for this symbol (CBMDefinition.is_test:
* the file's test-ness OR the definition's own test attributes). The registry
* stores it and scores with it; it does not derive test-ness from the QN. */
* `is_test` is the caller's test verdict for this symbol: the seeders pass the
* extractor's (CBMDefinition.is_test: a definition's own test attributes, and
* for functions, methods and the module the file's test-ness) OR the
* extractor's file rule (cbm_is_test_file) OR cbm_registry_test_double_path.
* The registry stores it and scores with it; it does not derive test-ness
* from the QN. */
void cbm_registry_add(cbm_registry_t *r, const char *name, const char *qualified_name,
const char *label, bool is_test);

Expand All @@ -297,8 +300,10 @@ void cbm_registry_add(cbm_registry_t *r, const char *name, const char *qualified
* clientsets and mock packages in ordinary files the extractor rightly does
* not call tests; a call should still prefer real code over them. The three
* registry seeders (pass_definitions.c, pass_parallel.c,
* pipeline_incremental.c) pass the extractor's verdict OR this, so full and
* incremental indexes rank alike. It never decides what a node is: the stored
* pipeline_incremental.c) pass the extractor's verdict OR its file rule
* (cbm_is_test_file, so every definition in a test file ranks as test, not
* only its callables) OR this, so full and incremental indexes rank alike.
* Neither path rule decides what a node is: the stored
* is_test property, TESTS edges and importance stay with cbm_is_test_path. */
bool cbm_registry_test_double_path(const char *rel_path);

Expand Down
8 changes: 5 additions & 3 deletions src/pipeline/pipeline_incremental.c
Original file line number Diff line number Diff line change
Expand Up @@ -1396,9 +1396,11 @@ static void registry_visitor(const cbm_gbuf_node_t *node, void *userdata) {
size_t prefix_len = lang == CBM_LANG_PYTHON
? cbm_pipeline_fqn_symbol_prefix_len(seed->project, node->file_path)
: 0;
/* The full index's verdict: the extractor's (stored as is_test) OR the
* test-double path rule on the node's file (pass_definitions.c). */
bool is_test = cbm_node_is_test(node) || cbm_registry_test_double_path(node->file_path);
/* The full index's verdict (pass_definitions.c): the extractor's (stored
* as is_test) OR its file rule on the node's file and the language the
* full index extracted it with OR the test-double path rule. */
bool is_test = cbm_node_is_test(node) || cbm_is_test_file(node->file_path, lang) ||
cbm_registry_test_double_path(node->file_path);
cbm_registry_add_lang_in_module(seed->registry, node->name, node->qualified_name, node->label,
lang, prefix_len, is_test);
if (node->properties_json) {
Expand Down
21 changes: 19 additions & 2 deletions src/pipeline/pipeline_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,15 @@ cbm_resolution_t cbm_registry_resolve_lang(const cbm_registry_t *r, const char *
const char *module_qn, const char **import_map_keys,
const char **import_map_vals, int import_map_count,
CBMLanguage lang);
/* As cbm_registry_resolve_lang, for a reference made by a definition (USAGE,
* READS, WRITES): `caller_test` is that definition's test verdict
* (cbm_pipeline_caller_is_test). Test or test-double code may use test code
* as freely as real code, so for it no candidate takes the registry's test
* penalty; a production reference keeps the full rule. */
cbm_resolution_t cbm_registry_resolve_ref(const cbm_registry_t *r, const char *ref_name,
const char *module_qn, const char **import_map_keys,
const char **import_map_vals, int import_map_count,
CBMLanguage lang, bool caller_test);
/* The CALLS variant: as cbm_registry_resolve_lang, except that a bare C call
* (no `.` / `->`) does not consider Field or Method nodes, which it can never
* call, and that in a C# file a built-in type keyword root (`int.TryParse`)
Expand All @@ -269,13 +278,21 @@ cbm_resolution_t cbm_registry_resolve_call_lang(const cbm_registry_t *r, const c
/* The registry step of BOTH call resolvers once the LSP has not answered:
* for Python, the def or class `callee_name` binds in the nearest def enclosing
* `scope_qn` (cbm_registry_resolve_lexical, "lexical_scope"); otherwise, or
* when there is no such local, cbm_registry_resolve_call_lang. */
* when there is no such local, cbm_registry_resolve_call_lang. `caller_test`:
* the calling definition's test verdict, as for cbm_registry_resolve_ref. */
cbm_resolution_t cbm_registry_resolve_call_scoped(const cbm_registry_t *r, const char *callee_name,
const char *module_qn,
const char **import_map_keys,
const char **import_map_vals,
int import_map_count, CBMLanguage lang,
const char *scope_qn);
const char *scope_qn, bool caller_test);
/* The test verdict of the code making a reference, by the same three rules the
* registry ranks candidates with: the extractor's verdict stored on the
* caller's node (cbm_node_is_test), the extractor's file rule
* (cbm_is_test_file on `rel` and `lang`) and the test-double path rule
* (cbm_registry_test_double_path). Both call resolvers and both reference
* resolvers ask it, so full and incremental indexes agree. */
bool cbm_pipeline_caller_is_test(const cbm_gbuf_node_t *source, const char *rel, CBMLanguage lang);
/* Python: the bare base `base` of the class `class_qn` nested in a class body
* binds the sibling class of that body (`<enclosing class>.<base>`) when the
* sibling is defined earlier in the same file (Python evaluates the bases in
Expand Down
Loading
Loading