Skip to content

fix(swift): extract computed & observed properties (#2181) - #2220

Closed
ozdemirsarman wants to merge 1 commit into
Graphify-Labs:v8from
ozdemirsarman:fix/swift-computed-properties
Closed

ozdemirsarman wants to merge 1 commit into
Graphify-Labs:v8from
ozdemirsarman:fix/swift-computed-properties

Conversation

@ozdemirsarman

Copy link
Copy Markdown
Contributor

Closes #2181.

Problem

Swift's extractor only treats function_declaration, init_declaration,
deinit_declaration and subscript_declaration as callables
(_SWIFT_CONFIG.function_types). Computed properties parse as
property_declaration → computed_property → statements, which no branch
handled — so they produced no node and their bodies were never walked.

For SwiftUI this is severe: var body: some View { … } is a computed property,
so an entire view file collapses to just the file + struct nodes and every UI
element and call inside body disappears. willSet/didSet observers have the
same shape and lost their body calls too.

Before (repro)

struct PlayerScrubber: View {
    var body: some View { VStack { doTap() } }  // dropped
    var toggled: Int { 1 }                       // dropped
    func doTap() {}                              // extracted
}

Only .doTap() was emitted; body, toggled, and the doTap() call inside
body were all missing.

Fix

In the Swift property_declaration branch (which already collects type-annotation
references), after the existing handling: if the property has a computed_property
or willset_didset_block child, emit a function-like member node (.name,
method edge to the enclosing type) and defer its body to the call-walk via
function_bodies — the same mechanism methods use. This is additive: the
existing references/field edges from the property's type are unchanged.

Stored properties have no body child, so they are untouched (no regression).

After

.body and .toggled are emitted, and the doTap() call inside body now
produces a calls edge from .body → .doTap(), so the view hierarchy is
traversed.

Tests

Adds tests/test_swift_computed_properties.py:

  • computed property emits a node and its body is walked (call captured);
  • stored property is not emitted as a member but still yields its type
    references edge (regression guard);
  • willSet/didSet observer body is walked.

Full language test suite (test_languages.py, 324 tests) and the existing Swift
tests pass with no changes.

function_types only recognised func/init/deinit/subscript, so computed properties (var body: some View { ... }) and willSet/didSet observers produced no node and their bodies were never walked — erasing the whole SwiftUI view layer. Emit a function-like member node for them and defer the body to the call-walk via function_bodies; stored properties are unchanged. Adds tests.
@safishamsi

Copy link
Copy Markdown
Member

Thanks @ozdemirsarman. Shipped in v0.9.28 (cherry-picked to v8 to preserve your authorship). Closed-unmerged here, but it's in the release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.28

@safishamsi safishamsi closed this Jul 27, 2026
durmazoguzhan added a commit to durmazoguzhan/graphify that referenced this pull request Aug 24, 2026
C# was the only language with a class-shaped type layer whose state was missing
from the graph. A field or property produced a `references` edge to its type and
no node of its own, so nothing could point at a member. C++ has emitted a node
per data member with a `defines` edge for a while, Graphify-Labs#2971 is adding the same for C
structs, and Graphify-Labs#2220 gave Swift computed properties nodes. This puts C# on that
line, using the same relation and `context="field"` as the C++ branch.

The member node does not depend on what the member is typed as, so it is emitted
before the type checks: a primitive and a generic parameter both leave a member
behind even though neither produces a type reference. Properties keep landing on
`defines` rather than `method`, since a property is state, not a call target.

Cost on a 1457-file .NET service: 9925 -> 15489 nodes and 29547 -> 34989 edges,
+56% and +18%. It is a DTO-heavy corpus, which is where that ratio comes from.
The added nodes are leaves, so the hub structure is unchanged: the top god nodes
are identical except ProductService moving 259 -> 263 edges.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01NCycXc9pjGzovxrZqojPUE
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: computed properties emit no node — erases the entire SwiftUI view layer (var body is a computed property)

2 participants