diff --git a/gitnexus/bench/scope-capture/baselines.json b/gitnexus/bench/scope-capture/baselines.json index 72dce2c65..b687aa74c 100644 --- a/gitnexus/bench/scope-capture/baselines.json +++ b/gitnexus/bench/scope-capture/baselines.json @@ -117,7 +117,7 @@ "_rebaselined_2766_receiver_chain_wire_v2": "#2766: receiver-chain wire format v1 -> v2 (name-free `await` / `index` step kinds). The VERSION prefix is part of every emitted `@reference.receiver-chain` capture, so every chain-minting language's capture text changed. WIRE-FORMAT CHANGE, NOT A CAPTURE-SET CHANGE: the same chains are minted for the same sites, spelled `2|\u2026` instead of `1|\u2026`. Exactly the 12 chain-minting languages drifted; c, cobol and dart did not, which is the check that this is the prefix and not a capture regression. Accompanied by SCHEMA_BUMP 34 -> 37 and INCREMENTAL_SCHEMA_VERSION 28 -> 31 so a stale index is rejected rather than replaying chains a v2 decoder refuses. Prior fc81941b0a921074fa80dc448284de9a23bd07358ddc84d4894797cc08c3fe83 -> 1c8c9c4b54036fa24c2a81e39ea530e938645c856d369075e5f437da78218c57." }, "swift": { - "fingerprint": "b0c89f8de1a4ce30409182e79c1c14cbc49a509d18d853c0d7c5f22f1f66be06", + "fingerprint": "a6d61e3749c9c02b9a54611e42d03db02f8fabfded3d7ce53a1b7229d3d38d59", "scaling_budget": 1.5, "_rebaselined_callable_flow_2522_review": "PR #2522 review hardening: callable operands retain expression/qualified identity and formals retain signature metadata. Prior 5f923c6604d825d12b249f31c155b0f4d13a8379d532e5dde64a0f9b15cf4725 -> 7687ee2466e16020a12440a03fbda53e63aa05f94b4481f6133c09867a0d560d; scaling 1.042 < 1.5.", "_rebaselined_callable_flow_2522_followup": "PR #2522 follow-up: Swift function-value callable flow facts with invocation-result suppression. Prior 180ac68e780bdf6f9089d53f51cbb9a66aed3e7774631cc3fcbaae5020213998 -> 5f923c6604d825d12b249f31c155b0f4d13a8379d532e5dde64a0f9b15cf4725; scaling 1.043 < 1.5.", @@ -129,7 +129,8 @@ "_rebaselined_nested_constructor_3262": "#3262: the existing nested-constructor fixture now uses the qualified legal form `extension Outer.Container`, covering full extension-owner recovery. Fixture-only capture drift; no capture logic changed. Prior adef9284feaecd39cb490aebce83876e15b9150c7a04b00a396feb78b7e1e0a9 -> 3ac80b64776969effb75c8d32aa0bc38fc6a41c6c115a33829c502559fa404f9; scaling 1.025 < 1.5.", "_rebaselined_3309_call_result_assignment": "#3309: the Swift protocol-extension regression fixture adds one file with an untyped local initialized from a helper call, plus a compound-field receiver call. The capture query is unchanged; this is fixture-corpus growth only. capture_groups_fp 1235 -> 1272 and fixture_count 62 -> 64; synthetic scale counts remain 5012/16012. Prior adef9284feaecd39cb490aebce83876e15b9150c7a04b00a396feb78b7e1e0a9 -> 4d32535d454cd79086f0fcaec3b75de855c1314e73630321460e569f19aa484f; measured scaling 1.020 < 1.5.", "_rebaselined_3309_exact_return_replay": "#3309 follow-up: Swift callable declarations now emit exact return-type captures, and untyped local initializers emit call-result assignment captures through direct, try, await, and try-await forms. This is intentional capture-set growth covered by exact-callable collision and wrapper regressions. Prior 4d32535d454cd79086f0fcaec3b75de855c1314e73630321460e569f19aa484f -> 724553c91e8ebcf872d7302b14105d59476c230f9b623acdacc0b58e39912329; hosted benchmark scaling remained within the existing 1.5 budget.", - "_rebaselined_3308_merge_main": "Merge origin/main into #3308: combine #3262 fixture-owner recovery with #3309 protocol-extension capture growth. Prior 3ac80b64776969effb75c8d32aa0bc38fc6a41c6c115a33829c502559fa404f9 + 724553c91e8ebcf872d7302b14105d59476c230f9b623acdacc0b58e39912329 -> b0c89f8de1a4ce30409182e79c1c14cbc49a509d18d853c0d7c5f22f1f66be06; capture_groups_fp 1297, fixture_count 67." + "_rebaselined_3308_merge_main": "Merge origin/main into #3308: combine #3262 fixture-owner recovery with #3309 protocol-extension capture growth. Prior 3ac80b64776969effb75c8d32aa0bc38fc6a41c6c115a33829c502559fa404f9 + 724553c91e8ebcf872d7302b14105d59476c230f9b623acdacc0b58e39912329 -> b0c89f8de1a4ce30409182e79c1c14cbc49a509d18d853c0d7c5f22f1f66be06; capture_groups_fp 1297, fixture_count 67.", + "_rebaselined_3308_public_extension": "#3308 review: the nested-constructor fixture now uses `public extension Outer.Container` so owner recovery is gated on modifier-prefixed headers. Fixture-only digest drift. Prior b0c89f8de1a4ce30409182e79c1c14cbc49a509d18d853c0d7c5f22f1f66be06 -> a6d61e3749c9c02b9a54611e42d03db02f8fabfded3d7ce53a1b7229d3d38d59; capture_groups_fp 1297, fixture_count 67." }, "dart": { "fingerprint": "3a8ddabbeb1cba47a4757451d4f79d726ca230fd15e860772b11526fbb1c6687", diff --git a/gitnexus/src/core/ingestion/languages/swift/target-siblings.ts b/gitnexus/src/core/ingestion/languages/swift/target-siblings.ts index 8d838505a..9c64ae42a 100644 --- a/gitnexus/src/core/ingestion/languages/swift/target-siblings.ts +++ b/gitnexus/src/core/ingestion/languages/swift/target-siblings.ts @@ -122,9 +122,14 @@ function scopeOwnerKey(scope: Scope, source: string | undefined): string | undef // only the trailing owner on members (`Inner.f` for `extension Outer.Inner`), // so recover the full owner from this scope's declaration text first. const representative = firstBoundDefinition(scope); - const sourceOwner = source === undefined ? undefined : swiftExtensionOwner(source, scope); - if (representative !== undefined && sourceOwner !== undefined) { - return logicalOwnerKey({ ...representative, qualifiedName: sourceOwner }); + if (source !== undefined) { + const sourceOwner = swiftExtensionOwner(source, scope); + if (representative !== undefined && sourceOwner !== undefined) { + return logicalOwnerKey({ ...representative, qualifiedName: sourceOwner }); + } + // Source was available. Do not last-dot-guess: member qualified names are + // trailing-only, so `Inner.make` would key `Inner` instead of `Outer.Inner`. + return undefined; } // Hand-built fixtures and old cached shapes may have no source text. Keep @@ -155,7 +160,11 @@ function firstBoundDefinition(scope: Scope): SymbolDefinition | undefined { return undefined; } -/** Read `extension Outer.Inner` from the exact class-scope source range. */ +/** + * Read `extension Outer.Inner` from the class-scope source range. + * Access modifiers and attributes (`public`, `@MainActor`, `@available`) + * may precede the keyword, so the match is not start-anchored. + */ function swiftExtensionOwner(source: string, scope: Scope): string | undefined { const starts = [0, 0]; for (let index = 0; index < source.length; index += 1) { @@ -164,7 +173,7 @@ function swiftExtensionOwner(source: string, scope: Scope): string | undefined { const start = starts[scope.range.startLine]; if (start === undefined) return undefined; const declaration = source.slice(start + scope.range.startCol); - const match = /^\s*extension\s+([A-Za-z_][A-Za-z0-9_]*(?:\s*\.\s*[A-Za-z_][A-Za-z0-9_]*)*)/.exec( + const match = /\bextension\s+([A-Za-z_][A-Za-z0-9_]*(?:\s*\.\s*[A-Za-z_][A-Za-z0-9_]*)*)/.exec( declaration, ); return match?.[1]?.replace(/\s+/g, ''); diff --git a/gitnexus/test/fixtures/lang-resolution/swift-nested-constructor-extension/Builder.swift b/gitnexus/test/fixtures/lang-resolution/swift-nested-constructor-extension/Builder.swift index a1d1ae34e..5b15f19cb 100644 --- a/gitnexus/test/fixtures/lang-resolution/swift-nested-constructor-extension/Builder.swift +++ b/gitnexus/test/fixtures/lang-resolution/swift-nested-constructor-extension/Builder.swift @@ -1,4 +1,4 @@ -extension Outer.Container { +public extension Outer.Container { static func makeEntry() -> Entry { Entry(id: 1, text: "sample") } diff --git a/gitnexus/test/fixtures/swift-captures-golden/expected-captures.json b/gitnexus/test/fixtures/swift-captures-golden/expected-captures.json index 5102a64cd..503266a0f 100644 --- a/gitnexus/test/fixtures/swift-captures-golden/expected-captures.json +++ b/gitnexus/test/fixtures/swift-captures-golden/expected-captures.json @@ -173,7 +173,7 @@ }, "swift-nested-constructor-extension/Builder.swift": { "captureGroups": 7, - "digest": "bc5b2ebd1efe51d5870d8e9fe6b1cf78f6824852490f537c3f457daca861bf9f" + "digest": "8e4e01966ad669ef2e8ea6fc032053540588507e75ecabe142ab5f0b35211cb2" }, "swift-nested-constructor-extension/Standalone.swift": { "captureGroups": 5, diff --git a/gitnexus/test/integration/resolvers/swift.test.ts b/gitnexus/test/integration/resolvers/swift.test.ts index 3ee3de225..3d38b8924 100644 --- a/gitnexus/test/integration/resolvers/swift.test.ts +++ b/gitnexus/test/integration/resolvers/swift.test.ts @@ -1302,7 +1302,9 @@ describe.skipIf(!swiftAvailable)('Swift nested-type extension (extension Foo.Bar // the extended type over an unrelated top-level type with the same short name. // --------------------------------------------------------------------------- -describe.skipIf(!swiftAvailable)('Swift nested constructor lookup in an extension (#3262)', () => { +describe.skipIf(!swiftAvailable)( + 'Swift nested constructor lookup in a public qualified extension (#3262)', + () => { let result: PipelineResult; beforeAll(async () => { @@ -1312,7 +1314,7 @@ describe.skipIf(!swiftAvailable)('Swift nested constructor lookup in an extensio ); }, 60000); - it('resolves Entry(id:text:) to Container.Entry and not the top-level Entry', () => { + it('resolves Entry(id:text:) to Outer.Container.Entry and not the top-level Entry', () => { const entryCalls = getRelationships(result, 'CALLS').filter( (call) => call.source === 'makeEntry' && call.target === 'Entry', ); diff --git a/gitnexus/test/unit/scope-resolution/swift/target-siblings.test.ts b/gitnexus/test/unit/scope-resolution/swift/target-siblings.test.ts index bc4cfcd52..e8abdbae2 100644 --- a/gitnexus/test/unit/scope-resolution/swift/target-siblings.test.ts +++ b/gitnexus/test/unit/scope-resolution/swift/target-siblings.test.ts @@ -226,4 +226,131 @@ describe('Swift target sibling visibility', () => { { def: entry, origin: 'namespace' }, ]); }); + + it.each([ + ['public extension Outer.Inner {\n static func makeEntry() {}\n}\n'], + ['@MainActor\nextension Outer.Inner {\n static func makeEntry() {}\n}\n'], + ['@available(iOS 15, *)\npublic extension Outer.Inner {\n static func makeEntry() {}\n}\n'], + ])('recovers a qualified owner through modifiers and attributes: %j', (extensionSource) => { + const { declaration, extension, entry, indexes, bindingAugmentations } = + qualifiedExtensionFixture(extensionSource); + + populateSwiftTargetSiblings([declaration, extension], indexes, { + fileContents: new Map([['Builder.swift', extensionSource]]), + }); + + expect(bindingAugmentations.get(classId('Builder.swift'))?.get('Entry')).toEqual([ + { def: entry, origin: 'namespace' }, + ]); + }); + + it('prefers Outer.Inner.Entry over a colliding top-level Inner.Entry', () => { + const topInner: SymbolDefinition = { + nodeId: 'def:TopInner.swift:Inner', + filePath: 'TopInner.swift', + type: 'Class', + qualifiedName: 'Inner', + }; + const wrongEntry: SymbolDefinition = { + nodeId: 'def:TopInner.swift:Inner.Entry', + filePath: 'TopInner.swift', + type: 'Class', + qualifiedName: 'Inner.Entry', + ownerId: topInner.nodeId, + }; + const extensionSource = 'public extension Outer.Inner {\n static func makeEntry() {}\n}\n'; + const { declaration, extension, entry, indexes, bindingAugmentations } = + qualifiedExtensionFixture(extensionSource, { extraDefs: [topInner, wrongEntry] }); + + populateSwiftTargetSiblings([declaration, extension], indexes, { + fileContents: new Map([['Builder.swift', extensionSource]]), + }); + + expect(bindingAugmentations.get(classId('Builder.swift'))?.get('Entry')).toEqual([ + { def: entry, origin: 'namespace' }, + ]); + }); + + it('does not last-dot-guess Inner when source is present but not an extension', () => { + const topInner: SymbolDefinition = { + nodeId: 'def:TopInner.swift:Inner', + filePath: 'TopInner.swift', + type: 'Class', + qualifiedName: 'Inner', + }; + const wrongEntry: SymbolDefinition = { + nodeId: 'def:TopInner.swift:Inner.Entry', + filePath: 'TopInner.swift', + type: 'Class', + qualifiedName: 'Inner.Entry', + ownerId: topInner.nodeId, + }; + const { declaration, extension, indexes, bindingAugmentations } = qualifiedExtensionFixture( + 'struct Unrelated {}\n', + { extraDefs: [topInner, wrongEntry] }, + ); + + populateSwiftTargetSiblings([declaration, extension], indexes, { + fileContents: new Map([['Builder.swift', 'struct Unrelated {}\n']]), + }); + + expect(bindingAugmentations.get(classId('Builder.swift'))?.get('Entry')).toBeUndefined(); + }); }); + +function qualifiedExtensionFixture( + extensionSource: string, + options: { extraDefs?: readonly SymbolDefinition[] } = {}, +) { + const inner: SymbolDefinition = { + nodeId: 'def:Types.swift:Outer.Inner', + filePath: 'Types.swift', + type: 'Class', + qualifiedName: 'Outer.Inner', + }; + const entry: SymbolDefinition = { + nodeId: 'def:Types.swift:Outer.Inner.Entry', + filePath: 'Types.swift', + type: 'Class', + qualifiedName: 'Outer.Inner.Entry', + ownerId: inner.nodeId, + }; + const makeEntry: SymbolDefinition = { + nodeId: 'def:Builder.swift:Inner.makeEntry', + filePath: 'Builder.swift', + type: 'Method', + qualifiedName: 'Inner.makeEntry', + }; + const extraDefs = options.extraDefs ?? []; + const declaration = parsedFile( + 'Types.swift', + [inner], + new Map([['Entry', [{ def: entry, origin: 'local' }]]]), + [inner, entry], + ); + const extension = parsedFile( + 'Builder.swift', + [], + new Map([['makeEntry', [{ def: makeEntry, origin: 'local' }]]]), + [makeEntry], + { + startLine: 1, + startCol: 0, + endLine: 3, + endCol: 1, + }, + ); + const bindingAugmentations = new Map(); + const allDefs = [inner, entry, makeEntry, ...extraDefs]; + const indexes = { + defs: buildDefIndex(allDefs), + moduleScopes: { + byFilePath: new Map([ + ['Types.swift', moduleId('Types.swift')], + ['Builder.swift', moduleId('Builder.swift')], + ]), + }, + bindingAugmentations, + } as unknown as ScopeResolutionIndexes; + return { declaration, extension, entry, indexes, bindingAugmentations }; +}