From 2d766780bc8569624d3f11c1fd029e8cd35d0ebf Mon Sep 17 00:00:00 2001 From: Liam McElhaney Date: Thu, 1 Oct 2026 13:07:56 -0400 Subject: [PATCH] refactor(rust): keep the builtin-type set language-local Move _RUST_BUILTIN_TYPES from extractors/base.py next to the Rust extractor, matching _GO_PREDECLARED_FUNCS and _RUST_TRAIT_METHOD_BLOCKLIST. The shared _LANGUAGE_BUILTIN_GLOBALS is consulted with no language gate, so a Rust-only set belongs with the language that reads it; this also keeps base.py's public surface unchanged. --- graphify/extractors/base.py | 27 ------------------------- graphify/extractors/rust.py | 39 ++++++++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/graphify/extractors/base.py b/graphify/extractors/base.py index 32e5fc0fa..148fc18c6 100644 --- a/graphify/extractors/base.py +++ b/graphify/extractors/base.py @@ -51,33 +51,6 @@ _LANGUAGE_BUILTIN_GLOBALS: frozenset[str] = frozenset({ }) -# Rust prelude / std types. Kept separate from _LANGUAGE_BUILTIN_GLOBALS so the -# filter applies to Rust type references only: the same names are ordinary user -# types elsewhere (Python `pathlib.Path`, a Kotlin `Result`), and folding them -# into the shared set would suppress those. Without this set a Rust codebase -# resolves every `Option`/`Vec`/`String`/`Result` annotation to one canonical -# node, making the language's own primitives the top god nodes. -_RUST_BUILTIN_TYPES: frozenset[str] = frozenset({ - # prelude types and aliases - "String", "str", "Option", "Result", "Vec", "VecDeque", "Box", "Rc", - "Arc", "Weak", "RefCell", "Cell", "Cow", "Pin", - # collections - "HashMap", "HashSet", "BTreeMap", "BTreeSet", "BinaryHeap", - # paths / OS strings - "Path", "PathBuf", "OsStr", "OsString", "CStr", "CString", - # time / ranges / markers - "Duration", "Instant", "SystemTime", "Ordering", "Range", "RangeInclusive", - "RangeFrom", "RangeTo", "RangeFull", "PhantomData", "ManuallyDrop", - "NonZeroU8", "NonZeroU16", "NonZeroU32", "NonZeroU64", "NonZeroUsize", - # variants and core traits - "Some", "None", "Ok", "Err", "Self", - "Default", "Clone", "Copy", "Debug", "Display", "Error", "From", "Into", - "TryFrom", "TryInto", "AsRef", "AsMut", "Iterator", "IntoIterator", - "Extend", "PartialEq", "Eq", "PartialOrd", "Ord", "Hash", "Send", "Sync", - "Sized", "Drop", "Deref", "DerefMut", "Future", "Fn", "FnMut", "FnOnce", -}) - - def _make_id(*parts: str) -> str: return make_id(*parts) diff --git a/graphify/extractors/rust.py b/graphify/extractors/rust.py index 84b35c9ec..eeb4035ab 100644 --- a/graphify/extractors/rust.py +++ b/graphify/extractors/rust.py @@ -3,13 +3,38 @@ from __future__ import annotations from pathlib import Path -from graphify.extractors.base import ( - _LANGUAGE_BUILTIN_GLOBALS, - _RUST_BUILTIN_TYPES, - _file_stem, - _make_id, - _read_text, -) +from graphify.extractors.base import _LANGUAGE_BUILTIN_GLOBALS, _file_stem, _make_id, _read_text + + +# Rust prelude / std types. Language-local (like _GO_PREDECLARED_FUNCS and +# _RUST_TRAIT_METHOD_BLOCKLIST below) rather than added to the shared +# _LANGUAGE_BUILTIN_GLOBALS: the shared set is consulted with no language gate, +# and `Path`, `Result`, `Error`, `From`, `Into`, `Iterator`, `Default` and +# friends are ordinary user type names in the other languages that read it. +# +# Without this set a Rust codebase resolves every `Option`/`Vec`/`String`/ +# `Result` annotation to a few canonical nodes, so the language's own primitives +# become the top god nodes (a ~1,200-file workspace had `String` at #1 with +# ~1,700 edges). Filtering is definition-aware: see _rust_collect_type_refs. +_RUST_BUILTIN_TYPES: frozenset[str] = frozenset({ + # prelude types and aliases + "String", "str", "Option", "Result", "Vec", "VecDeque", "Box", "Rc", + "Arc", "Weak", "RefCell", "Cell", "Cow", "Pin", + # collections + "HashMap", "HashSet", "BTreeMap", "BTreeSet", "BinaryHeap", + # paths / OS strings + "Path", "PathBuf", "OsStr", "OsString", "CStr", "CString", + # time / ranges / markers + "Duration", "Instant", "SystemTime", "Ordering", "Range", "RangeInclusive", + "RangeFrom", "RangeTo", "RangeFull", "PhantomData", "ManuallyDrop", + "NonZeroU8", "NonZeroU16", "NonZeroU32", "NonZeroU64", "NonZeroUsize", + # variants and core traits + "Some", "None", "Ok", "Err", "Self", + "Default", "Clone", "Copy", "Debug", "Display", "Error", "From", "Into", + "TryFrom", "TryInto", "AsRef", "AsMut", "Iterator", "IntoIterator", + "Extend", "PartialEq", "Eq", "PartialOrd", "Ord", "Hash", "Send", "Sync", + "Sized", "Drop", "Deref", "DerefMut", "Future", "Fn", "FnMut", "FnOnce", +}) def _rust_collect_type_refs(