Skip to content

fix(extract): filter Kotlin builtin/stdlib types from references graph#1876

Open
kebwlmbhee wants to merge 1 commit into
Graphify-Labs:v8from
kebwlmbhee:fix/kotlin-builtin-type-noise-filter
Open

fix(extract): filter Kotlin builtin/stdlib types from references graph#1876
kebwlmbhee wants to merge 1 commit into
Graphify-Labs:v8from
kebwlmbhee:fix/kotlin-builtin-type-noise-filter

Conversation

@kebwlmbhee

Copy link
Copy Markdown

Problem

_java_collect_type_refs filters out JDK builtin types via _JAVA_BUILTIN_TYPES before emitting a graph node/edge, and the same pattern exists for Python (_PYTHON_ANNOTATION_NOISE) and Go (_GO_PREDECLARED_TYPES). _kotlin_collect_type_refs has no equivalent — every Boolean, String, Int, List, ... language-level type annotation in a .kt file becomes a real graph node/edge.

In practice this means two unrelated Kotlin files that share nothing but Boolean/String/Int type annotations get treated as connected, and cluster-only groups them into the same community — a false positive with no real code coupling behind it. Confirmed by checking actual import statements between files in a real project: zero relation beyond one legitimate case.

Fix

Add _KOTLIN_BUILTIN_TYPES mirroring _JAVA_BUILTIN_TYPES (kotlin.* scalars, collections, and throwables — deliberately not Android/JVM framework types like Context/View/Bundle, staying consistent with how _JAVA_BUILTIN_TYPES doesn't filter framework-specific types either), and check it plus _JAVA_BUILTIN_TYPES (Kotlin freely references java.util.Date/UUID/etc) at the three call sites in _kotlin_collect_type_refs that previously appended unconditionally.

Deliberately excludes "Result" from the filter even though kotlin.Result exists — it collides with the very common user-defined sealed-class name. Confirmed against this repo's own tests/fixtures/sample.kt, which defines its own class Result<T>; an earlier version of this patch that included "Result" broke test_kotlin_parameter_return_generic_and_field_contexts.

Evidence

Real-world Android/Kotlin project (~400 source files), full graphify . --code-only + cluster-only . --no-label:

Before After
Nodes 3693 3239 (-12%)
Edges 6481 5221 (-19%)
Communities 269 271

Concretely: a utility file (ScreenExt.kt, purely Int/Float typed screen-dimension helpers) went from being merged into a 5-file grab-bag community (connected only via shared Boolean/Int type nodes) to splitting cleanly into its own community.

Testing

  • Added test_kotlin_builtin_types_not_emitted_as_references and test_kotlin_user_types_still_emit_references to tests/test_languages.py (the latter guards specifically against the Result collision above).
  • Full suite: 3142 passed, 31 skipped — the 5 failures on a clean checkout of v8 (test_collect_files_skips_hidden, 4x test_ollama_retry_cap.py needing the optional openai package) are pre-existing/environmental and unaffected by this change (verified by running the same tests against v8 with this commit stashed out).

Scope note

This intentionally does not touch Android/JVM framework types (Context, View, Bundle, SharedPreferences, JSONObject, ...). Those still create some false-hub clustering in Android projects specifically; filtering them is a separate, more debatable scope-expansion (you'd lose "who touches SharedPreferences" as a real signal) and isn't part of this PR.

_kotlin_collect_type_refs had no equivalent of _JAVA_BUILTIN_TYPES /
_PYTHON_ANNOTATION_NOISE / _GO_PREDECLARED_TYPES, so every Boolean/String/
Int/List/... type annotation in a .kt file became a real graph node/edge.
Unrelated files sharing only these language-level types were getting
merged into the same community by cluster-only.

Add _KOTLIN_BUILTIN_TYPES (kotlin.* scalars, collections, throwables -
deliberately not Android/JVM framework types like Context/View/Bundle,
matching how _JAVA_BUILTIN_TYPES doesn't filter framework types either)
and check it plus _JAVA_BUILTIN_TYPES (Kotlin freely references
java.util.Date/UUID/etc) at the three call sites that previously appended
unconditionally.

Deliberately excludes "Result" from the filter list even though
kotlin.Result exists - it collides with the very common user-defined
sealed-class name (confirmed against this repo's own sample.kt fixture,
which defines its own Result<T>).

Verified on a ~400-file Android/Kotlin project: 3693->3239 nodes (-12%),
6481->5221 edges (-19%), with a previously merged 5-file grab-bag
community cleanly splitting out an unrelated screen-dimension utility.
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.

1 participant