fix(extract,analyze): filter Swift/Foundation/SwiftUI builtins from resolution and god-node ranking (#2147)#2149
Open
MasterFede5 wants to merge 1 commit into
Conversation
…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>
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.
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:Foundation,NSLock,View,Data, ...) dominate the god-nodes report instead of project abstractions (the issue reportsFoundationat 105 edges andNSLockat 102 on a ~360k-word SwiftUI/AVFoundation corpus)._resolve_swift_member_callshad 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/JSnew/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 SwiftUIView/Color/Fontto_LANGUAGE_BUILTIN_GLOBALS.String/Date/URL/Errorwere 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_LABELSsogod_nodes()stops ranking them.graphify/extract.py—_resolve_swift_member_callsnow skips builtin receiver types, mirroring the TS/JSnew/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
Data/Viewin another language loses receiver-type resolution) is the same one already accepted forRequest/Response/Error/Filein the existing list; the guard only affects resolution to user symbols, never node extraction itself.extract.pyintographify/extractors/swift.pyso per-language builtin lists can live with their extractor) is intentionally left as follow-up.implements → Sendablestubs frominheritance_specifier) is untouched — filtering those changes graph content for every Swift repo and mirrors what Python does today withinherits → Exception, so it felt like a maintainer call. The god-node symptom those stubs cause is addressed by theanalyze.pyfilter.Tests
tests/test_swift_builtin_noise.py:god_nodes()exclusion forFoundation,SwiftUI,NSLock,Data,View,Sendable,Codable,DispatchQueue,Color(mirrors the npm dep-block test shape).let payload: Data) does not bind to a userclass Datain another file.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 cleanv8checkout in the same environment (missing optional deps / Windows-specific), i.e. no regressions from this change.🤖 Generated with Claude Code