Conversation
…roject symbol (#2127) `from unittest.mock import patch` names a module outside the project. Strategy 1 of cbm_pipeline_resolve_import_node cannot resolve it, so the Strategy-3 symbol-name fallback bound the import to the only project definition whose leaf is `patch` -- a REST view's PkgConfigView.patch -- and every `patch(...)` call became an import_map CALLS edge at confidence 0.95. Once that IMPORTS edge is gone the same call falls through to the weak short-name strategies (unique_name 0.75, suffix_match), which bind it again; `mock.patch(...)`, `json.loads(...)`, `os.path.join(...)` reached project methods the same way, because the member guard exempts import-rooted receivers. Two per-language (Python-only) rules, both keyed on the import's module chain rather than on any spelling list: - Import side (pass_pkgmap.c, shared by both drivers): for an import whose module is not in the project, a Strategy-3 hit must spell the import's module chain as an ordered subsequence of its QN (a sys.path root or src/ layout the resolver missed still qualifies), and whatever names a module (an enclosing path segment, any segment of a plain `import x`) may only bind a Module/File node. Imports of project modules are unchanged (they may re-export from anywhere). - Call side (pass_calls.c + pass_parallel.c, identical gates): a call whose root identifier is bound by an external import (no IMPORTS edge materialized it) and whose weak-strategy target contradicts that import's chain is not emitted as a plain CALLS edge. import_map / same_module / lsp_* edges are never touched. django/django (parallel pipeline): CALLS 62,430 -> 60,123, TESTS 29,872 -> 28,571, IMPORTS 16,068 -> 15,491. Removed CALLS are member calls through stdlib imports (1,900: os.path.join -> defaultfilters.join, json.loads -> signing.loads, mock.patch -> RedirectView.patch) and bare calls of stdlib names (398: date -> defaultfilters.date, urlsplit -> MultiPartParser.parse); a random 25-edge sample was 25/25 false. Six IMPORTS are re-targeted to the real definition (template_tests.utils.setup, multiple_database TestRouter, pr_quality errors.Message). Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
The memory-core ratchet flagged src/pipeline/pass_pkgmap.c growing by 2 raw allocator sites (82 -> 84). Both are frees of strings returned by cbm_pipeline_fqn_compute and cbm_pipeline_resolve_module, which the core never counted, so they now go through safe_free as the rest of the codebase does rather than raw free or cbm_free. Behaviour is unchanged; pass_pkgmap.c is back at its baseline of 82. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For Python, an import from a module outside the project (
from unittest.mock import patch,import json) could be bound by the import resolver's name-only fallback to any same-named project definition. That gaveimport_mapCALLS edges at 0.95; when the import edge was missing, the weakunique_name/suffix_matchfallbacks did the same.pass_pkgmap.c, shared by both drivers): for external Python imports, a Strategy-3 fallback hit must contain the import's module chain as an ordered subsequence, and module-naming segments only bind Module/File nodes. Project-internal imports and re-exports are unchanged.unique_name,suffix_match,field_type_hint,fuzzy) whose root is bound by an external import and contradict its chain are not emitted.import_map,same_moduleandlsp_*edges are untouched. Per-language (Python only), keyed on the module chain rather than a name list.django/django (fresh index each, parallel pipeline): CALLS 62,430 → 60,123, TESTS 29,872 → 28,571, IMPORTS 16,068 → 15,491. A random sample of 25 removed CALLS was 25/25 false (e.g.
os.path.join→ a template filter,json.loads→signing.loads,mock.patch→RedirectView.patch); 6 IMPORTS were re-targeted to the real definition.Tests:
edge_imports::ei_py_external_import_never_binds_project_symbol(sequential and parallel legs, with a recall pin for re-exports) plus registry unit testsimport_binding_suppress_drops_only_weak_contradicted_callsandpython_import_binding_contradicts_only_foreign_chains. RED before the fix; RED on revert, and disabling only the call guard also goes RED, so both halves bind.Known leftovers (not in this PR): a plain
import Xof a stdlib name can still bind to a nested project module of the same name; internal re-exported names can still get weak false targets for bare calls.Touches
pass_calls.c/pass_parallel.c(one extra operand indrop_plain_call) alongside #2332 and #2339.Fixes #2127