Understand any codebase instantly. System intelligence for codebases, built for humans and AI.
TypeScript aiai-memoryclaude-codeclicode-analysiscode-mappingcode-memorycodebase-understandingcodexdeveloper-toolsllmopenclawpersistent-memoryprogram-analysissoftware-architecturesystem-intelligencesystem-mapping
fix(ingest): bare calls in Python, Rust and PHP never resolve to a class member
KageBinaryec785a7c7245
diff --git a/core-ingestion/src/__tests__/queries.php.test.ts b/core-ingestion/src/__tests__/queries.php.test.tsindex 82a0df55..8503f928 100644--- a/core-ingestion/src/__tests__/queries.php.test.ts+++ b/core-ingestion/src/__tests__/queries.php.test.ts@@ -96,7 +96,7 @@ function run(Service $service): void {expect(result?.relationships.filter(rel => rel.predicate === 'CALLS')).toEqual([{ srcName: 'run', dstName: 'Service', predicate: 'CALLS', phpCallKind: 'constructor' },- { srcName: 'run', dstName: 'helper', predicate: 'CALLS', phpCallKind: 'function' },+ { srcName: 'run', dstName: 'helper', predicate: 'CALLS', phpCallKind: 'function', bareCall: true },{ srcName: 'run', dstName: 'Service.execute', predicate: 'CALLS', phpCallKind: 'member' },]);});diff --git a/core-ingestion/src/__tests__/queries.python.test.ts b/core-ingestion/src/__tests__/queries.python.test.tsindex 92ce22e4..f1181dbd 100644--- a/core-ingestion/src/__tests__/queries.python.test.ts+++ b/core-ingestion/src/__tests__/queries.python.test.ts@@ -57,6 +57,7 @@ def top_level():srcName: 'Service.run',dstName: 'helper',predicate: 'CALLS',+ bareCall: true,});expect(result!.relationships).toContainEqual({srcName: 'Service.run',@@ -121,6 +122,7 @@ def my_view(request):srcName: 'my_view',dstName: 'MyClass',predicate: 'CALLS',+ bareCall: true,});// conn resolved to MyClass via assignTypeMap → MyClass.executeexpect(result!.relationships).toContainEqual({@@ -152,6 +154,7 @@ class AdminSite:srcName: 'AdminSite.login',dstName: 'AdminAuthenticationForm',predicate: 'CALLS',+ bareCall: true,});});diff --git a/core-ingestion/src/__tests__/queries.rust.test.ts b/core-ingestion/src/__tests__/queries.rust.test.tsindex aec4c347..3855d014 100644--- a/core-ingestion/src/__tests__/queries.rust.test.ts+++ b/core-ingestion/src/__tests__/queries.rust.test.ts@@ -166,6 +166,7 @@ fn make() {srcName: 'make',dstName: 'foo',predicate: 'CALLS',+ bareCall: true,});});diff --git a/core-ingestion/src/__tests__/resolveEdges.scope.test.ts b/core-ingestion/src/__tests__/resolveEdges.scope.test.tsindex 9a18c349..a1f795e7 100644--- a/core-ingestion/src/__tests__/resolveEdges.scope.test.ts+++ b/core-ingestion/src/__tests__/resolveEdges.scope.test.ts@@ -243,6 +243,41 @@ describe('call resolution respects lexical scope (JS/TS)', () => {});});+describe('bare calls never resolve to a class member (Python, Rust, PHP)', () => {+ it('Python: describe() does not link to another file\'s Foo.describe method', () => {+ const method = parse('pkg/fixtures.py', 'class Foo:\n def describe(self):\n return 1\n');+ const caller = parse('pkg/test_x.py', 'def test_x():\n describe("x")\n');+ expect(callsTo(resolveEdges([caller, method]), method.filePath)).toEqual([]);+ });++ it('Python: a member call still reaches the method, and a bare call a module-scope function', () => {+ const lib = parse('pkg/lib.py', 'class Foo:\n def describe(self):\n return 1\n\ndef helper_fn():\n return 2\n');+ const caller = parse('pkg/main.py', 'def run(obj):\n obj.describe()\n return helper_fn()\n');+ const edges = callsTo(resolveEdges([caller, lib]), lib.filePath);+ expect(edges).toEqual(expect.arrayContaining([+ expect.objectContaining({ dstName: 'describe', dstQualifiedKey: 'Foo.describe' }),+ expect.objectContaining({ dstName: 'helper_fn', dstQualifiedKey: 'helper_fn' }),+ ]));+ expect(edges).toHaveLength(2);+ });++ it('Rust: describe() does not link to an impl method; a free function still resolves', () => {+ const lib = parse('src/lib.rs', 'struct Foo;\nimpl Foo {\n fn describe(&self) -> i32 { 1 }\n}\npub fn helper_fn() -> i32 { 2 }\n');+ const caller = parse('src/main.rs', 'fn t() {\n describe();\n helper_fn();\n}\n');+ expect(callsTo(resolveEdges([caller, lib]), lib.filePath)).toEqual([+ expect.objectContaining({ dstName: 'helper_fn', dstQualifiedKey: 'helper_fn' }),+ ]);+ });++ it('PHP: describe() does not link to a class method; a function still resolves', () => {+ const lib = parse('src/Lib.php', '<?php\nclass Foo {\n public function describe() { return 1; }\n}\nfunction helper_fn() { return 2; }\n');+ const caller = parse('src/main.php', '<?php\nfunction t() {\n describe();\n helper_fn();\n}\n');+ expect(callsTo(resolveEdges([caller, lib]), lib.filePath)).toEqual([+ expect.objectContaining({ dstName: 'helper_fn', dstQualifiedKey: 'helper_fn' }),+ ]);+ });+});+describe('dynamic and helper-literal imports (JS/TS)', () => {const LOADER_PATH = 'ix-cli/src/cli/commands/ingestion-loader.ts';const LOADER_SOURCE = [diff --git a/core-ingestion/src/index.ts b/core-ingestion/src/index.tsindex a4d367cd..7ed4b5dc 100644--- a/core-ingestion/src/index.ts+++ b/core-ingestion/src/index.ts@@ -215,11 +215,14 @@ export interface ParsedRelationship {*/importBinding?: boolean;/**- * JS/TS CALLS only: true when every call site folded into this relationship- * calls a plain identifier (`foo()`, `new Foo()`), never a member- * (`obj.foo()`). A plain identifier is resolved by lexical scope, so it can+ * CALLS only (JS/TS, Python, Rust, PHP): true when every call site folded+ * into this relationship calls a plain identifier (`foo()`, `new Foo()` in+ * JS/TS), never a member (`obj.foo()`, `self.foo()`, `$this->foo()`). In+ * these languages a plain identifier is resolved by lexical scope, so it can* only denote a module-scope declaration — never a class member in another- * file. Absent means "at least one member-shaped use, or unknown".+ * file. (Not set for Java, C#, Kotlin, Scala, C++, Ruby..., where a bare call+ * can be an implicit-`this` method.) Absent means "at least one+ * member-shaped use, or unknown".*/bareCall?: true;/**@@ -2547,8 +2550,11 @@ export function parseFile(filePath: string, source: string): FileParseResult | nconst importBindings: ImportBinding[] = [];const jsTsImportedLocalNames = new Set<string>();const jsTsImportUseHasUnshadowed = new Map<string, boolean>();- // JS/TS: per `${scope}\x00${callKey}`, whether every call site folded into- // that CALLS relationship is a plain identifier call (see ParsedRelationship.bareCall).+ // Per `${scope}\x00${callKey}`, whether every call site folded into that+ // CALLS relationship is a plain identifier call (see ParsedRelationship.bareCall).+ // Only for languages where such a call can never reach a class member.+ const tracksBareCalls = isJsTs || language === SupportedLanguages.Python ||+ language === SupportedLanguages.Rust || language === SupportedLanguages.PHP;const jsTsCallBareOnly = new Map<string, boolean>();const jsTsCallRelationship = new Map<string, ParsedRelationship>();// JS/TS: helper-literal module paths already emitted (see importVia).@@ -3218,12 +3224,32 @@ export function parseFile(filePath: string, source: string): FileParseResult | nconst callKey = phpCallKind ? `${phpCallKind}:${effectiveCallee}` : effectiveCallee;const bareKey = `${scope}\x00${callKey}`;- if (isJsTs) {- // `foo()` / `new Foo()`: the JS/TS queries capture the callee as an- // `identifier` only there; `obj.foo()` captures a property_identifier.- // (Read from the node's own type: `.parent` walks down from the root- // in these bindings, which is quadratic in a long call chain.)- const isBare = !qualifierCapture && callName.node.type === 'identifier';+ if (tracksBareCalls) {+ let isBare: boolean;+ if (isJsTs) {+ // `foo()` / `new Foo()`: the JS/TS queries capture the callee as an+ // `identifier` only there; `obj.foo()` captures a property_identifier.+ // (Read from the node's own type: `.parent` walks down from the root+ // in these bindings, which is quadratic in a long call chain.)+ isBare = !qualifierCapture && callName.node.type === 'identifier';+ } else if (language === SupportedLanguages.PHP) {+ // `foo()` is a function_call_expression; a method is only reachable+ // through `$obj->`, `?->`, `Class::` or `new`.+ isBare = phpCallKind === 'function';+ } else if (language === SupportedLanguages.Python) {+ // `foo()` / `f(key=foo)`: an identifier that is not the attribute of+ // `obj.foo()`. A method needs `self.` / `cls.` / `obj.`. A callee+ // rewritten through a local alias (`cls = mod.Engine; cls()`) is not+ // what the call site spelled, so it is left unmarked.+ isBare = !qualifierCapture && effectiveCallee === callee &&+ callName.node.type === 'identifier' && callName.node.parent?.type !== 'attribute';+ } else {+ // Rust: `foo()` / `foo::<T>()`. A method or associated function needs+ // `self.` / `x.` / `Type::`.+ const parentType = callName.node.parent?.type;+ isBare = !qualifierCapture && callName.node.type === 'identifier' &&+ (parentType === 'call_expression' || parentType === 'generic_function');+ }jsTsCallBareOnly.set(bareKey, (jsTsCallBareOnly.get(bareKey) ?? true) && isBare);}if (!seen.has(callKey)) {@@ -3235,7 +3261,7 @@ export function parseFile(filePath: string, source: string): FileParseResult | n...(phpCallKind ? { phpCallKind } : {}),};relationships.push(rel);- if (isJsTs) jsTsCallRelationship.set(bareKey, rel);+ if (tracksBareCalls) jsTsCallRelationship.set(bareKey, rel);}continue;}@@ -4950,9 +4976,9 @@ export function resolveEdges(}}- // Reachability filter for every cross-file tier below (JS/TS only; other- // languages keep plain name matching):- // - A bare call (`foo()`, rel.bareCall) is resolved by lexical scope, so+ // Reachability filter for every cross-file tier below:+ // - A bare call (`foo()`, rel.bareCall; set by the parser for JS/TS,+ // Python, Rust and PHP) is resolved by lexical scope, so// it can only denote a module-scope declaration. A class member of the// same name (`SampleCommand.describe`) is reachable only through a// receiver and is never a candidate.@@ -4963,9 +4989,9 @@ export function resolveEdges(// under a directory named after it (`packages/utils/**` for// `@acme/utils`, `packages/babel-types/**` for `@babel/types`). This// keeps monorepo workspace imports resolving while an external- // package's names stop landing on unrelated same-named symbols.+ // package's names stop landing on unrelated same-named symbols (JS/TS only).// The global tier applies the first rule differently -- see there.- const bareCall = srcIsJsTs && rel.predicate === 'CALLS' && rel.bareCall === true;+ const bareCall = rel.predicate === 'CALLS' && rel.bareCall === true;const boundPackage = srcIsJsTs && binding && isBarePackageSpecifier(binding.pkg) &&(bindingProviderFiles?.length ?? 0) === 0 && !(configuredBindingTargets?.length)? binding.pkg