explicit_imports.py: names used by include!()d files

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Pavlo Ratushnyi
2026-11-14 12:45:28 +01:00
co-authored by Claude Sonnet 5.5
parent 945f20524a
commit 2f562efa36
+24
View File
@@ -381,6 +381,8 @@ class Plan:
A file whose needs include a conditionally declared name is blocked (kept as a glob)."""
orig = self.crate
tokens = {f: tokens_of(strip_code(self.texts[f]), self.texts[f]) for f in orig.by_file}
for f in orig.by_file: # `include!("file.rs")`: the included text is compiled as part of this file
tokens[f] |= self.included_tokens(f, set())
extra = self.extra_requirements()
req, needs, self.blocked = {}, {}, set()
for f in sorted(orig.by_file, key=lambda f: -len(f.parts)):
@@ -438,6 +440,28 @@ class Plan:
self._platform_cache[f] = out
return out
def included_tokens(self, f, seen):
out = set()
for m in re.finditer(r'include!\(\s*"([^"]+)"\s*\)', self.texts[f]):
target = (f.parent / m.group(1)).resolve()
if target in seen or not target.is_file():
continue
seen.add(target)
text = target.read_text(encoding="utf-8")
out |= tokens_of(strip_code(text), text)
out |= self.included_tokens_text(target, text, seen)
return out
def included_tokens_text(self, target, text, seen):
out = set()
for m in re.finditer(r'include!\(\s*"([^"]+)"\s*\)', text):
inner = (target.parent / m.group(1)).resolve()
if inner not in seen and inner.is_file():
seen.add(inner)
body = inner.read_text(encoding="utf-8")
out |= tokens_of(strip_code(body), body) | self.included_tokens_text(inner, body, seen)
return out
def sees_arch_glob(self, mod):
"""Whether a `use std::arch::x86_64::*;` sits on the module's parent chain (its intrinsics come through `super`)."""
ancestor = mod.parent