Skip to content

Commit 9faddf2

Browse files
Haofeiclaude
andcommitted
docs: scope generated-namespace-isolation as architectural follow-up
Record why module namespace isolation is not a local patch: identical names across files are currently rejected (one merged Program/HIR, RS0005) and lowered into one flat Rust namespace, so the item requires a scope-aware, module-qualified name-resolution layer. Document the concrete design (symbol table keyed by (module, name); module-scoped reference resolution with shadowing; module-mangled unique lowering reusing the #lower_name override seam) and note #lower_name as the shipped interim mitigation. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent fec1ea9 commit 9faddf2

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

docs/tinygrad-port-todo.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@ manual wrapper.
1616
type alias, struct, method, and generated helper with related names cannot
1717
collide after Rust lowering; diagnostics report the RSS source symbol, not only
1818
the lowered Rust name.
19+
_Status (open — architectural):_ identical names across files are currently
20+
*rejected*, not isolated — every source merges into one `Program`/HIR
21+
(`merge_programs``Hir::duplicate_symbols`, RS0005) and lowers into one flat
22+
Rust namespace, so this item is not a detection gap but a request to *allow*
23+
per-module coexistence. That requires a scope-aware, module-qualified
24+
name-resolution layer, not a local patch:
25+
(1) key the symbol table / HIR by `(module, name)` (module = the file's `module`
26+
decl) instead of bare name, so same-named symbols in different modules are
27+
distinct rather than duplicates;
28+
(2) resolve every reference through module scope — local defs, then `use`
29+
imports, then fully-qualified `mod.name` — while honoring shadowing by
30+
locals/params/fields (this scope tracking is the bulk of the work and the main
31+
regression risk, since it touches name resolution for *all* programs);
32+
(3) lower each symbol to a module-mangled, globally unique Rust ident and
33+
rewrite all resolved references to it (the per-run override hook added for
34+
`#lower_name` is the lowering seam, but it must become module/file-aware);
35+
(4) keep diagnostics reporting the module-qualified RSS source symbol.
36+
_Interim mitigation (shipped):_ the `#lower_name("...")` escape hatch lets a
37+
port pin a unique backend symbol for a colliding declaration today (see the
38+
lowered-name item below), which is exactly the manual workaround this item
39+
would automate. Deferred as a dedicated change: rushing the resolver risks
40+
breaking name resolution for every program, so it is intentionally not bundled
41+
with the smaller items.
1942

2043
- [ ] **Stable source-qualified symbol identity.** Store and expose a symbol's
2144
module path, source qualified name, kind, visibility, and lowered backend name.

0 commit comments

Comments
 (0)