Skip to content

fix(extract,analyze): filter Swift/Foundation/SwiftUI builtins from resolution and god-node ranking (#2147)#2149

Open
MasterFede5 wants to merge 1 commit into
Graphify-Labs:v8from
MasterFede5:fix/2147-swift-builtin-noise
Open

fix(extract,analyze): filter Swift/Foundation/SwiftUI builtins from resolution and god-node ranking (#2147)#2149
MasterFede5 wants to merge 1 commit into
Graphify-Labs:v8from
MasterFede5:fix/2147-swift-builtin-noise

Conversation

@MasterFede5

Copy link
Copy Markdown

Fixes #2147.

Problem

_LANGUAGE_BUILTIN_GLOBALS (graphify/extractors/base.py) and _BUILTIN_NOISE_LABELS (graphify/analyze.py) cover only JS/TS and Python, so on Swift codebases:

  • Framework symbols (Foundation, NSLock, View, Data, ...) dominate the god-nodes report instead of project abstractions (the issue reports Foundation at 105 edges and NSLock at 102 on a ~360k-word SwiftUI/AVFoundation corpus).
  • _resolve_swift_member_calls had no builtin guard at all, so a receiver typed with a builtin (let payload: Data) could bind cross-file to a same-named user symbol — the same phantom-edge shape TS/JS new/type references to builtin globals (e.g. Date) collapse onto same-named user symbols → false god node #1726 fixed for TypeScript ("the cross-file CALL resolver already skips these globals; do the same here").

Changes

  • graphify/extractors/base.py — add Swift stdlib value-type initializers (Int, Double, Data, UUID, ...), conformance protocols (Sendable, Codable, Equatable, Hashable, Identifiable, ...), common Foundation types (NSLock, DispatchQueue, JSONDecoder, ...), and SwiftUI View/Color/Font to _LANGUAGE_BUILTIN_GLOBALS. String/Date/URL/Error were already present via the ECMAScript section.
  • graphify/analyze.py — add the same set plus framework module names (Foundation, SwiftUI, UIKit, AppKit, Combine) to _BUILTIN_NOISE_LABELS so god_nodes() stops ranking them.
  • graphify/extract.py_resolve_swift_member_calls now skips builtin receiver types, mirroring the TS/JS new/type references to builtin globals (e.g. Date) collapse onto same-named user symbols → false god node #1726 guard the TS/Python member-call resolvers already have.

Scope notes

  • The shared-list tradeoff (a user class literally named Data/View in another language loses receiver-type resolution) is the same one already accepted for Request/Response/Error/File in the existing list; the guard only affects resolution to user symbols, never node extraction itself.
  • The issue's item 3 (migrating Swift extraction out of extract.py into graphify/extractors/swift.py so per-language builtin lists can live with their extractor) is intentionally left as follow-up.
  • Conformance-edge emission (implements → Sendable stubs from inheritance_specifier) is untouched — filtering those changes graph content for every Swift repo and mirrors what Python does today with inherits → Exception, so it felt like a maintainer call. The god-node symptom those stubs cause is addressed by the analyze.py filter.

Tests

tests/test_swift_builtin_noise.py:

  • Parametrized god_nodes() exclusion for Foundation, SwiftUI, NSLock, Data, View, Sendable, Codable, DispatchQueue, Color (mirrors the npm dep-block test shape).
  • Extraction-level regression: builtin-typed receiver (let payload: Data) does not bind to a user class Data in another file.
  • Guard is a no-op for genuine user types: engine.play() on a user-typed property still resolves cross-file (Cross-file class relationships are mostly undetected by AST extraction #1356 shape).

Targeted run: tests/test_swift_builtin_noise.py tests/test_builtin_global_type_refs.py tests/test_analyze.py tests/test_god_nodes_cli.py tests/test_swift_cross_file_calls.py → 73 passed. Full suite on Windows: 3366 passed / 51 failed — the identical 51 failures occur on a clean v8 checkout in the same environment (missing optional deps / Windows-specific), i.e. no regressions from this change.

🤖 Generated with Claude Code

…esolution and god-node ranking (Graphify-Labs#2147)

_LANGUAGE_BUILTIN_GLOBALS and _BUILTIN_NOISE_LABELS covered only JS/TS and
Python, so on Swift codebases framework symbols (Foundation, NSLock, View,
Data, Sendable, ...) ranked as god nodes, and the Swift member-call resolver
could bind a builtin-typed receiver (let d: Data) to a same-named user symbol
in another file — the same phantom-edge shape Graphify-Labs#1726 fixed for TypeScript.

- extractors/base.py: add Swift stdlib value types, conformance protocols,
  Foundation types, and SwiftUI View/Color/Font to _LANGUAGE_BUILTIN_GLOBALS
- analyze.py: add the same set plus framework module names (Foundation,
  SwiftUI, UIKit, AppKit, Combine) to _BUILTIN_NOISE_LABELS
- extract.py: _resolve_swift_member_calls now skips builtin receiver types,
  matching the guard the TS/Python member-call resolvers already have (Graphify-Labs#1726)
- tests: god_nodes exclusion (parametrized) + Swift builtin-receiver
  no-bind regression + user-type-still-resolves guard

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Swift/Foundation/SwiftUI builtins missing from _LANGUAGE_BUILTIN_GLOBALS and _BUILTIN_NOISE_LABELS (false god-nodes, phantom bridges)

1 participant