mirror of
https://github.com/safishamsi/graphify.git
synced 2026-10-15 00:19:33 +00:00
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.
This commit is contained in:
1 parent
88cb2a8cd1
commit
2d766780bc
2 files changed
+32
-34
No files matched your search
@@ -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)
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user