Repository navigation
Conversation
…e index Swift has no per-type imports inside a module, so every cross-file type name becomes a sourceless stub that the generic label-based passes must repair. Several ordinary patterns defeated them: - A declaration next to its own same-file `extension` shares the extension's id and was skipped as a merge candidate, so an extension of it in another file stayed a second sourced node and every reference from other files stayed on per-file stubs. - An extension of a type declared outside the corpus (`extension View`, `private extension String`) acted as the declaration and absorbed same-named references (Graphify-Labs#4574). - Nested type names were cut to their first segment (`Layout.Pane` -> `Layout`), and same-named nested types under different outers collapsed into one node (Graphify-Labs#4575). - Cross-file constructor calls `Foo(...)` were always dropped, since a Swift file never imports a type from its own module. What changes: - Phase 1: `swift_extensions[]` records carry `declared`, and a node built only from `extension` blocks carries `_swift_extension_only`. Such a node is never a canonical merge or rewire target; the real declaration is, even with a same-file extension. `graphify update` keeps the marker on context nodes (cli.py, watch.py). - Phase 2: Swift type nodes carry `_swift_qualified` paths, reference edges `_swift_scope`, and `swift_type_table` gains `scopes`. A new `_resolve_swift_type_references` pass binds references by Swift name lookup (innermost scope first) through `_swift_type_index` / `_swift_lookup` before the bare-label rewire, and fails closed on ambiguity. Extension targets resolve through the same lookup. - Phase 3: nested types get their enclosing type's id, salted only on a collision with a member of the same slug. - Phase 4: `Foo(...)` binds as an INFERRED `calls` edge with `context="constructor"` when the lexical lookup finds one type; the `callers` filter in serve.py keeps those edges. - Member calls: receiver types resolve through per-file scopes; a receiver whose same-file writes disagree binds nothing and is not parked; dotted names never fall back to the label key; an extension of `[T]`, `[K: V]` or `T?` extends `Swift.Array` / `Swift.Dictionary` / `Swift.Optional`; only Swift callers are handled and only Swift or Objective-C targets are bound. `_AST_CACHE_SCHEMA` goes to 26 because per-file Swift output changes. Nested Swift type ids change, so saved queries naming one stop matching. Fixes Graphify-Labs#4574 Fixes Graphify-Labs#4575 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Records the root causes (RC1-RC5), the phase design, the fixed contracts and decisions, and the implementation notes behind the Swift type index, so a reviewer can check the code against the intended lookup rules and their fail-closed cases. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Swift branches added to _extract_generic's walk() pushed it past
pyright's code-flow complexity limit ("Code is too complex to
analyze"), so pyright stopped checking the whole function and hid its
existing errors. The Swift class id, qualified-path bookkeeping,
sugar-extension label, scope stack push/pop and body-scope notes now
live in small nested helpers next to the other Swift helpers. No
behaviour change; upstream's own code in walk() is untouched.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n-only ctor targets Three defects found in review of the Swift type index: - `Action.Delegate` slugged to the id of a same-file `case delegate` (ids are caseless; the case keeps the plain id and the nested type is salted), so the same-file shortcut in ensure_named_node pointed the reference at the enum case. A dotted Swift name declared in the file now maps to its nested type's real id first. - A Swift extension of an Objective-C class folds onto the ObjC node, which has no `_swift_qualified`; _swift_caller_scope returned None and `Item()` inside that extension lost the constructor edge v8 had. A non-Swift owner now gives file scope "". - The generic constructor fallback still accepted an `_swift_extension_only` node, so `External()` of a library type bound to `extension External`. Swift calls now drop such candidates. The RFC D25 note now says which writes the same-file agreement check sees; factory bindings and annotated locals are not covered yet. Accepted risks: - F2 `Outer.Inner.go()` binds `Outer.go`: the extractor keeps only the receiver head; same on v8 whenever any type table exists (follow-up). - F3 a typealias and an upper-cased static factory with one name in one type let the factory retry treat an annotation as a call (artificial; needs per-entry provenance). - F4 a same-file `extension Outer.State` before the declaration keeps the dotted label, so `State()` binds the top-level `State`, as on v8 (follow-up). - F6 a nested factory shadowing a same-named top-level factory binds `make()` but not the member call on its result (fail-closed; follow-up: choose the factory by lexical lookup). - F7 a same-file typed member call can still bind by bare label before the scoped resolver, as on v8 (follow-up). - F8 factory bindings and annotated locals are outside the D25 agreement check, so one local name in two functions can bind to the first write, as on v8 (follow-up). Co-Authored-By: Claude Opus 5.5 <[email protected]>
The round-1 fix mapped a dotted Swift name declared in the file to the
nested type at that absolute path. Inside `Outer`, `Model.Item` then
bound the top-level `Model.Item` instead of `Outer.Model.Item`, which
hides it. The older same-file id shortcut had the same flaw whenever
the top-level type came first in the file, and it is what let
`Action.Delegate` reach a `case delegate`.
A dotted Swift name now never takes the same-file id shortcut: it stays
a sourceless stub, and the existing Swift type pass binds it through
`_swift_lookup` from the edge's `_swift_scope`, as it already does for
cross-file dotted references.
Accepted risks:
- A same-file dotted reference to an extension-only node with no declaration anywhere (`extension A.B {}` plus `var x: A.B`) stays on a stub instead of the file-local extension node, like any undeclared type.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the pull request, @idachev. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.
Not checked: tests were not run; formal verification proved 0 of 14 changed function(s) (1 sampled, not proven, 12 not verified).
Formal verification. 1 change(s) alter behavior, breaking input(s) attached. PR-changed functions: 2/14 verified (0 proven, 1 may-equivalent, 1 distinguished) · 12 not verified (7 vacuous, 5 unsupported).
Behavior changes: \_swift\_classify\_base changes behavior, here is the input that shows it.
The verifier found a concrete input on which \_swift\_classify\_base behaves differently before and after the change. If that change is intended, ship it; if not, this is your bug.
Guarantee: This difference was REPRODUCED, the verifier actually ran both versions on that input and saw them disagree. It is real, not an artifact.
Evidence: On input \{"name":"'\.'","kind":"None","is\_first":"False","protocols":"set\(\)","classes":"\{''\}"\}, the old code produced 'implements' but the new code produces 'inherits' (outputs first differ at character 2). Paste that input straight into a regression test.
Not verified on this run: dispatch\_command (vacuous: never exercised), \_merge\_swift\_extensions (vacuous: never exercised), \_node\_label\_key (unsupported), \_resolve\_swift\_member\_calls (unsupported), \_rewire\_unique\_stub\_nodes (unsupported), \_extract\_generic (unsupported), \_swift\_collect\_type\_refs (vacuous: never exercised), \_swift\_constructor\_type (vacuous: never exercised), \_swift\_local\_var\_types (vacuous: never exercised), \_swift\_user\_type\_name (vacuous: never exercised), and 2 more.
Graphify review — findings
Fixes Swift cross-file type resolution so references to a type that has a same-file extension plus an extension in another file land on the real declaration instead of per-file sourceless stubs. Extensions of types declared outside the corpus (View, String) no longer pose as declarations and fail closed, nested types such as Layout.Pane keep their qualified identity, and cross-file constructor calls like Layout(panes: []) now bind to the declaration. It also stops the spurious "node 'foundation' is minted by two different files" warning for repeated import statements, and the AST cache schema bumps from 25 to 26, so existing caches rebuild once. Adds the RFC that traces the problem to five root causes and documents the phased plan, and the diff includes the Swift tests covering these cases.
Review partial — this diff was larger than one review pass covers, so later files were not reviewed; some findings may be missing.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 5376 functions depend on the 1822 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract()— 1044 callers, 66 callees - worse:
_rebuild_code()— 192 callers, 60 callees - worse:
_extract_generic()— 20 callers, 47 callees - worse:
_rewire_unique_stub_nodes()— 14 callers, 12 callees - worse:
walk()— 1 callers, 88 callees - new:
_assert_struct_untouched()— 7 callers, 4 callees - new:
_assert_declaration()— 8 callers, 3 callees - new:
_assert_external_extension()— 6 callers, 3 callees - …and 22 more — each is listed as a finding
Verification — 5376 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 5324 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
461 of 461 test file(s) selected (100%) via static blast radius.
Escalated to a full run for safety — the selection is not trustworthy on its own (see below). CI should run the whole suite.
tests/pi.test.ts— full-run-safetytests/test_affected_cli.py— impact, full-run-safetytests/test_affected_defines.py— full-run-safetytests/test_affected_member_seed.py— full-run-safetytests/test_affected_overrides.py— impact, full-run-safetytests/test_affected_path_file_node.py— full-run-safetytests/test_agents_platform.py— impact, full-run-safetytests/test_alias_folding.py— full-run-safetytests/test_analyze.py— full-run-safetytests/test_anthropic_custom_endpoint.py— full-run-safetytests/test_antigravity_install.py— full-run-safetytests/test_apm_fallback_version.py— full-run-safetytests/test_architecture_doc.py— full-run-safetytests/test_astro_extraction.py— impact, full-run-safetytests/test_astro_import_ids.py— impact, full-run-safetytests/test_atomic_canvas_export.py— full-run-safetytests/test_atomic_version_stamp.py— full-run-safetytests/test_atomic_writes.py— full-run-safetytests/test_backend_env_isolation.py— full-run-safetytests/test_backend_extras.py— full-run-safetytests/test_backend_opt_in.py— full-run-safetytests/test_benchmark.py— impact, full-run-safetytests/test_benchmark_raw_graph.py— impact, full-run-safetytests/test_benchmark_real_query.py— impact, full-run-safetytests/test_binary_media_words.py— impact, full-run-safetytests/test_blade_extractor.py— impact, full-run-safetytests/test_build.py— impact, full-run-safetytests/test_build_located_semantic_identity.py— full-run-safetytests/test_build_merge_dedup_scope.py— full-run-safetytests/test_build_merge_hyperedges_and_prune.py— full-run-safetytests/test_build_merge_shrink_guard.py— full-run-safetytests/test_builtin_global_type_refs.py— impact, full-run-safetytests/test_c_include_resolution.py— impact, full-run-safetytests/test_cache.py— impact, full-run-safetytests/test_cache_long_paths.py— impact, full-run-safetytests/test_cache_stale_import_target.py— impact, full-run-safetytests/test_callflow_html.py— full-run-safetytests/test_cargo_introspect.py— full-run-safetytests/test_cargo_missing_manifest.py— full-run-safetytests/test_carried_hyperedge_remap.py— full-run-safetytests/test_case_sensitive_resolution.py— impact, full-run-safetytests/test_charmap_encoding.py— impact, full-run-safetytests/test_chunking.py— impact, full-run-safetytests/test_cjs_module_extension.py— impact, full-run-safetytests/test_claude_cli_backend.py— full-run-safetytests/test_claude_md.py— full-run-safetytests/test_cli_broken_pipe.py— full-run-safetytests/test_cli_export.py— impact, full-run-safetytests/test_cli_help.py— full-run-safetytests/test_cloud_cta.py— impact, full-run-safety- … and 411 more
non-code file(s) changed (
docs/swift-cross-file-type-resolution-rfc.md) → running the full suite for safety (a code graph can't see config/fixture/data deps)
changed code file(s) with no mapped test (
docs/swift-cross-file-type-resolution-rfc.md) — a coverage gap or a missing link — running the full suite rather than only the selected tests
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Docs that may be stale (advisory)
ARCHITECTURE.md§ Module responsibilities (lines 13-41): references changed symbolsgraphARCHITECTURE.md§ Edge direction in graph.json (lines 73-78): references changed symbolsgraphBENCHMARKS.md§ Reproducing (lines 190-203): references changed symbolsgraphCHANGELOG.md§ 0.9.93 (2026-10-20) (lines 53-79): references changed symbolsgraphCHANGELOG.md§ 0.9.92 (2026-10-16) (lines 80-105): references changed symbolsgraphCHANGELOG.md§ 0.9.90 (2026-10-13) (lines 119-137): references changed symbolsgraphCHANGELOG.md§ 0.9.88 (2026-10-12) (lines 152-176): references changed symbolscheck,graphCHANGELOG.md§ 0.9.87 (2026-10-12) (lines 177-199): references changed symbolsgraphCHANGELOG.md§ 0.9.86 (2026-10-11) (lines 200-221): references changed symbolsgraphCHANGELOG.md§ 0.9.85 (2026-10-10) (lines 222-244): references changed symbolsgraph
…and 10 more.
Formal verification
Behavior changes: \_swift\_classify\_base changes behavior, here is the input that shows it.
The verifier found a concrete input on which \_swift\_classify\_base behaves differently before and after the change. If that change is intended, ship it; if not, this is your bug.
Guarantee: This difference was REPRODUCED, the verifier actually ran both versions on that input and saw them disagree. It is real, not an artifact.
Evidence: On input \{"name":"'\.'","kind":"None","is\_first":"False","protocols":"set\(\)","classes":"\{''\}"\}, the old code produced 'implements' but the new code produces 'inherits' (outputs first differ at character 2). Paste that input straight into a regression test.
Could not verify: Could not verify dispatch\_command.
The verifier did not have enough to check dispatch\_command, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 40 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly SystemExit — names the real obstacle, not a sampling gap)
Could not verify: Could not verify \_merge\_swift\_extensions.
The verifier did not have enough to check \_merge\_swift\_extensions, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: non-vacuity: domain too small (only 1 distinct inputs exercised, need 3) — 'no divergence' would be near-vacuous
Could not verify: Could not verify \_node\_label\_key.
The verifier did not have enough to check \_node\_label\_key, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: the input domain has 17 values but only 12 distinct were tested — a small finite domain must be EXHAUSTED, not sampled (an untested input could invert the result)
Could not verify: Could not verify \_resolve\_swift\_member\_calls.
The verifier did not have enough to check \_resolve\_swift\_member\_calls, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verified: a runtime divergence was observed, but the two versions' package snapshots loaded differently in the sandbox (old: {'fallback': {'graphify.extractors.julia': 'ModuleNotFoundError', 'graphify.extractors.objc': 'ModuleNotFoundError'}, 'missing': ['graphify.extractors.engine']}, new: {'fallback': {'graphify.build': 'ModuleNotFoundError', 'graphify.detect': 'ModuleNotFoundError', 'graphify.extractors.julia': 'ModuleNotFoundError', 'graphify.extractors.objc': 'ModuleNotFoundError'}, 'missing': ['graphify.extractors.engine', 'graphify.google_workspace', 'graphify.validate']}), so it may be an environment artifact rather than the edit
Could not verify: Could not verify \_rewire\_unique\_stub\_nodes.
The verifier did not have enough to check \_rewire\_unique\_stub\_nodes, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: the input domain has 81 values but only 11 distinct were tested — a small finite domain must be EXHAUSTED, not sampled (an untested input could invert the result)
No difference found (not proven): No behavior difference found in extract (not a proof).
The verifier ran both versions of extract on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.
Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.
Note: An input the sampler did not try could still differ.
Could not verify: Could not verify \_extract\_generic.
The verifier did not have enough to check \_extract\_generic, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: parameter `config` is annotated `LanguageConfig` — outside the synthesizable primitive/collection set
Could not verify: Could not verify \_swift\_collect\_type\_refs.
The verifier did not have enough to check \_swift\_collect\_type\_refs, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 235 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)
Could not verify: Could not verify \_swift\_constructor\_type.
The verifier did not have enough to check \_swift\_constructor\_type, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 228 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)
Could not verify: Could not verify \_swift\_local\_var\_types.
The verifier did not have enough to check \_swift\_local\_var\_types, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 235 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)
Could not verify: Could not verify \_swift\_user\_type\_name.
The verifier did not have enough to check \_swift\_user\_type\_name, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 228 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)
Could not verify: Could not verify \_filter\_graph\_by\_context.
The verifier did not have enough to check \_filter\_graph\_by\_context, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 12 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous
Could not verify: Could not verify \_rebuild\_code.
The verifier did not have enough to check \_rebuild\_code, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: nondeterministic output (both versions disagreed with themselves on the witness) — not a behaviour change; a function whose output is not a function of its inputs (random / time / uuid / os.urandom, or state carried across calls) cannot be soundly distinguished by execution, so this tier abstains for the whole function
· 20 grounded finding(s) anchored inline below; 5 more finding(s) on lines outside this diff (see the check run); 5 additional anchorable finding(s) not shown (cap).
| return next((c for c in decl.children if c.type in _SWIFT_TYPE_BODY_TYPES), None) | ||
|
|
||
|
|
||
| def _swift_body_members(body_node, source: bytes) -> list[tuple[str, str]]: |
There was a problem hiding this comment.
_swift_body_members()
fans out to 6 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
| swift_nested_groups: dict = {} | ||
| swift_path_nids: dict[str, str] = {} | ||
|
|
||
| def _swift_member_nid(parent_path: str | None, parent_nid: str, name: str, |
There was a problem hiding this comment.
_swift_member_nid()
high coupling complexity (Ca·Ce = 12).
Grounded coupling-delta finding (deterministic), not an LLM guess.
| assert _xext_has_edge(result, file_node["id"], nid, "contains"), f"{ext_file} does not contain {nid}" | ||
|
|
||
|
|
||
| def test_declaration_with_same_file_extension_absorbs_cross_file_extension(tmp_path: Path): |
There was a problem hiding this comment.
test_declaration_with_same_file_extension_absorbs_cross_file_extension()
fans out to 6 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
| assert expected <= refs, f"references that missed the declaration: {sorted(expected - refs)}" | ||
|
|
||
|
|
||
| def test_extension_of_outside_type_does_not_absorb_references(tmp_path: Path): |
There was a problem hiding this comment.
test_extension_of_outside_type_does_not_absorb_references()
fans out to 7 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
| assert (".shout()", "return_type", "StringExt.swift") in _xext_incoming(result, string_ext["id"]) | ||
|
|
||
|
|
||
| def test_extension_only_type_extended_in_two_files_stays_unresolved(tmp_path: Path): |
There was a problem hiding this comment.
test_extension_only_type_extended_in_two_files_stays_unresolved()
fans out to 6 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
| assert not leftovers, f"the extension must not survive as its own node: {leftovers}" | ||
|
|
||
|
|
||
| def test_qualified_conformance_and_generic_args_resolve(tmp_path: Path): |
There was a problem hiding this comment.
test_qualified_conformance_and_generic_args_resolve()
fans out to 6 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
|
|
||
| # ── controls ────────────────────────────────────────────────────────────────── | ||
|
|
||
| def test_ambiguous_bare_name_stays_on_stub(tmp_path: Path): |
There was a problem hiding this comment.
test_ambiguous_bare_name_stays_on_stub()
fans out to 6 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
| }, "x.go() must not bind to OuterInner.go()" | ||
|
|
||
|
|
||
| def test_same_file_duplicate_nested_names_stay_ambiguous(tmp_path: Path): |
There was a problem hiding this comment.
test_same_file_duplicate_nested_names_stay_ambiguous()
fans out to 7 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
| ) | ||
|
|
||
|
|
||
| def test_no_cross_language_binding(tmp_path: Path): |
There was a problem hiding this comment.
test_no_cross_language_binding()
fans out to 6 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
| assert ts_store not in targets | ||
|
|
||
|
|
||
| def test_swift_reference_to_non_swift_type_keeps_generic_rewire(tmp_path: Path): |
There was a problem hiding this comment.
test_swift_reference_to_non_swift_type_keeps_generic_rewire()
fans out to 8 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
Behaviour is unchanged. Six small clean-ups in code this branch adds: - Extract _swift_upper_navigation_path() and use it from both _swift_constructor_type() and _swift_navigation_type_head(), which carried the same upper-cased navigation-chain walk. - _swift_record_class() calls _swift_is_extension() instead of repeating its body inline. - _resolve_swift_member_calls() drops an is_swift_call check that the early Swift-only gate already guarantees. - _resolve_swift_type_references() builds the node list for the type index once and reuses it for the Swift source ids. - engine.py imports _SWIFT_TYPE_REFERENCE_RELATIONS from resolution.py instead of defining an identical _SWIFT_SCOPED_RELATIONS, so the walk that stamps the scope and the pass that reads it share one set. - The RFC names _swift_salted_member_nid without a stale line range. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replace the example type, file and member names in the RFC, in the Swift test fixtures and in a few code comments with neutral ones (Shape, Shape.Point, Canvas.State, Converter, Recipe), renamed consistently in the asserted labels, paths and ids. The RFC's real-app section no longer quotes file paths, line numbers, file sizes or exact corpus counts. Test structure and assertions are unchanged; the code changes are comment-only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Swift member-call target gate admitted every `.h` target, but a header can be C or C++ as well as Objective-C, so `Inner.go()` bound a C++ `Inner::go`, and a missing method fell back to a type-only `references` edge to the C++ class. A `.h` target now binds only when it is an ObjC method (its label carries the `+`/`-` sigil) or a type that owns one. The label and the method edges are already persisted, so the rule also holds on incremental rebuilds; per-file output is unchanged, so no cache schema bump. The change only removes edges. Accepted loss: a type-only `references` edge to an ObjC class with no ObjC method in the corpus. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Swift constructor branch, its extension-only candidate filter, the dotted-stub guard, the Swift type index, the type-reference source set and the type-reference file selection tested the raw file name, so a file remapped to Swift in .graphifyrc lost or gained the wrong edges, and a corpus of .SWIFT files skipped the type-reference pass. One helper, _is_swift_source, now decides by the effective suffix, case-insensitively. All six checks run in the cross-file passes; per-file output is unchanged, so no cache schema bump. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…clarations A nested Swift type's id joins its parent's id and its name, so `Outer.State` and a file-level `Outer_State` or `outer_state()`, or `Outer.A.B` and `Outer.A_B`, minted one id; add_node dropped the second node and its methods hung under the survivor. A per-file pre-scan now records the owners of each plain id. A nested type yields to any member or function and to any type of the same or a shallower depth, and is salted, so the shallower declaration keeps the plain id and the outcome does not depend on declaration order. A member that its sibling collision group already salts does not count as holding the plain id, so no id is salted needlessly. Written references such as `Outer.State` stay stubs and the Swift type pass binds them to the salted node through its qualified path. This changes per-file ids for affected .swift files; the AST cache schema bump already in this series covers it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A Swift receiver whose written type goes through a typealias, an associatedtype, a generic parameter or parameter pack, a type declared inside a function, closure or accessor body, or a `Self`-qualified path names a type the corpus type index cannot see. The in-file bare-label bind and the corpus resolver then bound the call to an unrelated same-named type. Such a write now marks the name's scope unknown at once (a sticky `scopes[name] = None`, the same mark two conflicting writes leave), so nothing is bound and nothing is parked. The same holds for binding sites the receiver table does not read: typed locals, typed closure parameters, every name of a multi-binding property, file-scope bindings, and initializers or factories through an unproven type, annotated or not. A scopes-only result is serialized so the mark reaches the AST cache, and the resolver checks the unknown scope before the upper-case type arm, so a variable spelled `X` is not the type `X`. The change only removes edges: `var x: A; x.go()` still binds `A.go`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What does this PR do?
Fixes #4574
Fixes #4575
Fixes #4754
Problem. In a Swift corpus many type references never reach the declaration of the type they name. Swift has no per-type imports inside a module, so every cross-file type name starts as a sourceless stub that the label-based passes have to repair, and several ordinary patterns defeat them:
extensionand also extended in another file ([Bug]: Swift: types extended across files, qualified nested paths and constructor calls do not resolve #4754, case 1);extension View,private extension String) that absorbs every same-named reference ([Bug]: Swift: an extension of a type outside the corpus (private extension String) captures every reference to that type #4574);Catalog.Item.ID) cut to their first segment ([Bug]: Swift: types extended across files, qualified nested paths and constructor calls do not resolve #4754, case 2), and same-named nested types under different parents collapsing into one node ([Bug]: Swift: same-named nested types in one file collapse into one node (e.g. twoCodingKeysenums) #4575);Widget(...)dropped because a Swift file never imports a type from its own module ([Bug]: Swift: types extended across files, qualified nested paths and constructor calls do not resolve #4754, case 3).The root causes (RC1-RC5), the design and the decisions are in
docs/swift-cross-file-type-resolution-rfc.md, added by this PR.Approach. Deterministic, fail-closed Swift name lookup, in the RFC's phases. Phases 1-4 depend on each other (the RFC explains why Phase 3 cannot ship without Phases 2 and 4), so they are one PR.
private extension String) captures every reference to that type #4574, [Bug]: Swift: types extended across files, qualified nested paths and constructor calls do not resolve #4754 case 1).swift_extensions[]records carrydeclared, and a node built only fromextensionblocks carries_swift_extension_only. Such a node is never a canonical merge or rewire target; the real declaration is, even when it has a same-file extension.graphify updatekeeps the marker on context nodes (cli.py,watch.py)._swift_qualifiedpaths, reference edges carry_swift_scope, andswift_type_tablegainsscopes. A new_resolve_swift_type_referencespass binds a reference by its written path (Catalog.Item.IDstays dotted) through_swift_type_index/_swift_lookup, before the bare-label rewire: the innermost scope that declares the name wins, two candidates at that level are ambiguous and bind nothing, and a name declared nowhere keeps its dotted stub label. Extension targets resolve through the same lookup.CodingKeysenums) #4575). A nested type gets an id under its enclosing type, soA.StateandB.State(or twoCodingKeys) in one file stay two nodes. The id is salted only on a collision with a member of the same slug.Widget(...)binds as anINFERREDcallsedge withcontext="constructor"when the lexical lookup finds exactly one type. A same-file constructor call to a nested type, or to a label shared by several Swift types in the file, goes through the same pass.serve.py: the "callers of X" question keepscontext="constructor"edges, otherwise these edges would be invisible to it.x.go()binds through a per-file receiver table that records each name's type and enclosing scope. When two writes of one name in a file disagree on type or scope, the name binds nothing and is not parked for cross-repo resolution.Wrong bindings fixed on the way, each with a regression test:
Item.IDresolves only through the Swift lookup; it no longer binds a concatenatedItemIDthrough the member-call fallback or the stub rewire.[T],[K: V],T?extendsSwift.Array/Swift.Dictionary/Swift.Optionalinstead of folding ontoT.referencesedge to it when the method is not defined in the extension..graphifyrcoverride counts) and binds only.swift/.m/.mm/.htargets.Fixed after review (the first three in commits
fix(swift): dotted refs to nested types, ObjC-owned callers, extension-only ctor targetsandfix(swift): resolve same-file dotted type names by lexical lookup; the others name their commit), each with a regression test:Action.Delegateslugged to the id of a same-filecase delegate(ids are caseless; the case keeps the plain id and the nested type is salted), so it pointed at the enum case; and a same-file shortcut by absolute path ignored lexical scope, soModel.Itemwritten insideOutercould bind a top-levelModel.Iteminstead ofOuter.Model.Item. A dotted Swift name no longer takes the same-file id shortcut: it stays a stub and the Phase 2 lookup binds it with the reference's scope (test_dotted_reference_reaches_nested_type_not_same_slug_enum_case,test_dotted_reference_uses_lexical_scope_over_same_named_top_level, both declaration orders).Item()inside that extension lost the constructor edge v8 has. A non-Swift owner now gives file scope (test_constructor_call_in_extension_of_objc_class_binds).External()of a library type bound toextension External(as on v8). Swift calls now drop such candidates (test_constructor_call_does_not_bind_extension_only_node).fix(swift): do not bind Swift calls to C/C++ declarations in .h headers: the member-call target gate admitted every.htarget, soInner.go()could bind a C++Inner::godeclared in a header, and a missing method fell back to a type-onlyreferencesedge to the C++ class. A.htarget now binds only when it is an Objective-C method (its label carries the-/+sigil) or a type that owns one (test_swift_type_call_does_not_bind_cpp_class_method_in_h,test_swift_call_to_cpp_class_emits_no_reference_in_h,test_swift_instance_call_still_binds_objc_instance_method_in_h).fix(swift): honour language overrides in Swift suffix checks: six checks (the constructor branch, its extension-only candidate filter, the dotted-stub guard, the Swift type index, the type-reference source set and the type-reference file selection) tested the raw file name, so a file remapped to Swift in.graphifyrclost or gained edges, and a corpus of.SWIFTfiles skipped the type-reference pass. One helper now decides by the effective suffix, ignoring case (test_constructor_in_language_override_file_binds_lexical_type,test_uppercase_swift_suffix_corpus_binds_type_reference).fix(swift): keep nested type ids distinct from same-file top-level declarations: a nested type's id joins its parent's id and its name, soOuter.Stateand a file-levelOuter_Stateorouter_state()minted one id and the second node was dropped. A nested type now yields that id to any member or function and to any type of the same or a shallower depth, and is salted, independent of declaration order (test_nested_type_does_not_swallow_toplevel_underscore_type,test_nested_type_does_not_swallow_toplevel_function).fix(swift): bind nothing for receivers whose written type is unproven: a receiver typed with a name that something else in the file shadows (atypealias, anassociatedtype, a generic parameter or pack, a type declared inside a function body, aSelf.-qualified path, a generic-constrained prefix or a generic argument) bound the call to a same-named type elsewhere. Such a write now makes the name bind nothing in that file, for properties (every name of a multi-binding declaration), parameters, typed locals, typed closure parameters, file-scope bindings and initializers or factories called through such a type, also when the binding is annotated; nothing is parked, andvar x: A; x.go()still bindsA.go(tests/test_swift_receiver_fail_closed.py).Three commits change no behaviour.
refactor(swift): tidy the new Swift resolution helpersremoves duplication in the new helpers (one shared navigation-path walk, one shared relation set, one redundant check dropped), anddocs(swift): use generic examples in the RFC and fixturesonly renames examples in the RFC, test fixtures and comments. The third,refactor(swift): split Swift call binding out of walk() for pyright, only moves the new Swift branches of_extract_generic'swalk()into small nested helpers, with no behaviour change: they had pushedwalk()past pyright's complexity limit, so pyright stopped checking the whole function.Cache and upgrade.
_AST_CACHE_SCHEMAgoes from 25 to 26, once for all phases, because per-file Swift output changes. The first build after the upgrade re-extracts every file. Nested Swift types get new ids, so saved queries and--seedids that name a nested Swift type have to be updated. On a large Swift corpus the dedup shrink guard may refuse the first graph if it is smaller than the old one;--allow-dedup-shrinklets it through.Related PRs and issues.
private extension String) captures every reference to that type #4574. This PR uses a different marker: only a node built purely from extensions is marked, so a declaration with its own same-file extension stays a merge target (the [Bug]: Swift: types extended across files, qualified nested paths and constructor calls do not resolve #4754 case 1 layout). If this PR is accepted, it supersedes fix(swift): stop an extension of an outside type absorbing every same-named reference #4600.CodingKeysenums) #4575 with a similar parent-qualified id for nested types. This PR overlaps with it on nested type identity and adds the lookup that resolvesOuter.Innerwritten in another file; if this PR is accepted, it supersedes fix(swift): keep same-named nested types under different outers apart #4599.typealiasnodes. It is complementary and not included here; both change the Swift extractor, so whichever lands second may need a rebase.Split out. Two small fixes found during this work are separate PRs and do not depend on this one or on each other: #4756 (no dedup collision warning for shared module nodes, RFC Phase 5) and #4757 (the Python member-call pass binds only Python callers and targets).
Notes for maintainers
_AST_CACHE_SCHEMA25 -> 26 because it changes per-file Swift output; feel free to adjust the number or fold it into your release bump.Type of change
Verification & Invariants
Invariants: extraction stays deterministic (no ambient state, no file reads in the resolvers); ambiguity binds nothing instead of guessing (fail-closed); no binding across language families; a sourceless stub never wins over a sourced declaration; an extension of a type outside the corpus is never treated as its declaration. Persisted state this invalidates: the AST cache (schema bump) and any saved id of a nested Swift type.
How was this tested?
New test files:
tests/test_swift_type_index.py,test_swift_type_resolution.py,test_swift_nested_constructor_calls.py,test_swift_member_call_scopes.py,test_swift_member_call_target_gate.py,test_swift_extension_only_member_calls.py,test_swift_sugar_extensions.py,test_swift_dotted_label_key.py,test_swift_language_override.py,test_swift_nested_id_collision.py; additions totest_swift_cross_file_calls.pyandtest_serve.py.On this branch at its current head (rebased on v8
92741d16):Pyright: the error sets compared by file and message (line stripped) show 0 new errors.
Regression tests fail on v8: the new and changed test files copied into a v8
92741d16checkout and run against v8 code give 55 failed and 1 collection error in the Swift and serve files (the same run also held the test files of the two split-out PRs, which account for its other 6 failures; 216 tests passed in total). The failures includetest_extension_of_outside_type_does_not_absorb_references(#4574),test_same_file_nested_types_get_distinct_ids(#4575),test_declaration_with_same_file_extension_absorbs_cross_file_extension(#4754 case 1),test_cross_file_constructor_call_emits_inferred_call(#4754 case 3) andtest_callers_question_keeps_constructor_call_edges(serve).test_swift_type_index.pycannot be collected on v8 because it imports_swift_type_index/_swift_lookup. The 216 that pass are the controls.Real-project check: a SwiftUI app with several hundred Swift files, built with
graphify extract <app> --code-only,GRAPHIFY_BACKEND=none, no API keys set. These numbers were measured on an earlier revision of this change set, before the rebase onto92741d16, against v8c588b72d(0.9.94). Since that measurement the branch changed only by the rebase, thewalk()refactor above (no behaviour change), the removal of the Python-pass change that now ships as #4757, and the review fixes above; the real-app check was not rerun after those fixes.c588b72d)affected <declaration id>, depth 1, other files / usesaffected "<name>"(label)No unique node matchINFERREDconstructorcallsItem.ID->ItemID)calls/referencesEXTRACTEDcallsThe total of Swift references that end on a stub rises (4836 -> 7040). That is by design: references to an extension-only type (
View,NSEvent) no longer bind to the extension (#4574), and dotted names stay dotted stubs instead of binding a lookalike.The drop in
EXTRACTEDcallswas checked per call site (caller, file, line, callee name), not by node id, since nested types now get parent-qualified ids. Of the 370 call sites that lost anEXTRACTEDcallsedge, 314 still have an edge to the same target: 248 are in-file constructor calls of nested types that are now recorded asINFERRED, and 66 collapsed into an existingreferencesedge on the same node pair, since the graph keeps one edge per pair. Another 26 were wrong bindings that are now gone (self-recursion through a receiver of a different type, a receiver of an external type bound to a same-named local method, and one call bound to an extension-only node that now binds to the real type). The remaining 30 are real losses, listed under limitations: 21 member calls whose receiver is written several times in the same file, 6 qualified nested-type constructorsOuter.Inner(...), and 3 self-loops from a type's static property calling its own initializer. On the other side, 164EXTRACTEDcalls were added, 142 of them cross-fileType.member(...)calls whose receiver type was checked to match the target's owner.Known limitations / unsupported cases
Outer.TandT. 21 correct same-file member calls on the app above are lost this way. A narrower rule is follow-up work.Outer.Inner(...)reaches onlyOuter(areferencesedge) or nothing; thecallsedge toInneris not emitted (6 calls on the app above, plus 3 self-loop initializer calls)..hheader that owns no Objective-C method (for example an@interfacethat declares only properties) is no longer a target of a Swift type-onlyreferencesedge, since the gate cannot tell it from a C or C++ type (accepted loss of the.hfix above).referencesedge.if let/guard let/forbindings with a type annotation or tuple patterns (let (x, y): (State, Int)), and a local bound by a resolvable factory can still shadow a typed parameter of the same name, so such a receiver can bind to a same-named type elsewhere, as on v8 (follow-up).let x = Box<Int>()throughtypealias Box<T> = Other<T>), wrapped initializers (try Box.make(),(Box.make())) or nested factory paths, and sees only shadowing declarations in the current file (atypealiasdeclared in a type in another file, used from an extension of that type), so these receivers can still bind to a same-named type, as before this change (follow-up).Outer.Inner.go()bindsOuter.go, as on v8 (follow-up).extension Outer.Stateabovestruct Outer) creates the node with the dotted label, soState()binds a top-levelState, as on v8 (follow-up).make()but not the member call on its result (fail-closed; follow-up: choose the factory by lexical lookup).a.b.go()), protocol-extension default implementations and conditional conformances.Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. Not applicable: no skillgen fragments changed.🤖 Generated with Claude Code