-
Notifications
You must be signed in to change notification settings - Fork 20
fix(stats): native coupling hotspots exclude structural edges, matching map (#2388) #2528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+61
−9
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a call such as
userService.getUser()resolves its receiver to a symbol in another file, this filter excludes the resultingreceiveredge from both fan-in and fan-out, causing genuinely central modules to be under-reported or incorrectly ranked as coupling hotspots.Knowledge Base Used:
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This exclusion isn't new — it's pre-existing, intentional behavior this PR mirrors from the TypeScript side, not a regression introduced here.
The
receiveredge doesn't represent the actual invocation coupling foruserService.getUser(). PerresolveReceiverEdge's doc comment insrc/domain/graph/builder/call-resolver.ts:737, it "resolve[s] the receiver-type edge" — i.e. it points toUserService(the class), not togetUser(the method actually being invoked). The real cross-file dependency — the caller depending on the target file's exported method — is captured separately by the primarycallsedge, resolved via CHA/RTA dispatch (build-edges.ts Steps 1-4/6) before this receiver-type edge is emitted as a supplementary Step 5. Thatcallsedge is never filtered out of coupling counts byNON_COUPLING_EDGE_KINDS(onlycontains/parameter_of/receiverare), so a resolved cross-file method call is already fully represented in fan-in/fan-out.This also isn't specific to hotspots:
classifyNodeRolesFull's own fan-in/fan-out computation (src/features/structure.ts) — which drives dead-code role classification, not juststats/map— already excludesreceiverfrom both, viakind IN ('calls', 'imports-type')for fan-in andkind = 'calls'for fan-out. Three independent consumers (role classification,map,stats) all treatreceiveras structural rather than coupling, consistent with howparameter_ofis treated for the same reason (a type/structural relationship, not an invocation). Changing that classification forstats/mapalone would make them inconsistent with role classification's own coupling model, and would be a design change affecting existing, shippedcodegraph mapbehavior — out of scope for this issue, which asked specifically to make the native path match the existing TypeScript filter, not to redesign what counts as coupling.If there's a concrete case where a receiver-type edge is the only signal for a resolved cross-file dependency (no accompanying
callsedge), that would be a genuine edge case worth its own issue — but it wouldn't be fixed by includingreceiverbroadly in coupling counts, since the vast majority ofreceiveredges are redundant with an already-countedcallsedge to the specific method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, and thank you for the detailed explanation. The
receiveredge records the receiver-type relationship (class declaration), not the invocation — the actual cross-file dependency is already captured by the accompanyingcallsedge, which is never filtered. Since all three consumers (role classification,map,stats) consistently treatreceiveras structural, this exclusion is coherent and intentional, and this PR is correctly mirroring the existing TS behavior rather than introducing a new design decision.Shall I remember this as a rule: "In this repo,
receiveredges are structural (receiver-type), not coupling —callsedges carry the invocation signal, so excludingreceiverfrom fan-in/fan-out counts is intentional and consistent across all three consumers (role classification, map, stats)"?