|
| 1 | +# Feature request: cross-module enum-variant / constant usage |
| 2 | + |
| 3 | +**Status:** requested · **Driver:** tinygrad-rsmc module de-prefixing |
| 4 | +**Repro built on:** current `rss` (post module-isolation + use-aliasing) |
| 5 | + |
| 6 | +## Summary |
| 7 | + |
| 8 | +Make enum/sum **variants** and **constants** defined in one `module` usable from |
| 9 | +another without one `use` line per symbol. Today only per-symbol |
| 10 | +`use module.NAME` + bare reference works; **qualified value access fails** and |
| 11 | +**glob imports are unsupported**. This blocks de-prefixing enum/const-heavy files. |
| 12 | + |
| 13 | +## Motivation / impact |
| 14 | + |
| 15 | +The tinygrad-rsmc port has a single `Ops` sum type with ~100 variants |
| 16 | +(`ADD`, `MUL`, `GLOBAL`, `INDEX`, …) referenced across ~100 files, plus shared |
| 17 | +constants. To put `Ops` in `module ops`, every consumer must currently add a |
| 18 | +separate `use ops.ADD`, `use ops.MUL`, … — thousands of `use` lines — and two |
| 19 | +modules that both define a same-named variant can't be used in one file at all |
| 20 | +(no qualification, no aliasing for values). That makes module de-prefixing of |
| 21 | +these files impractical, which is the last refactor still gated. |
| 22 | + |
| 23 | +## Current behavior (verified) |
| 24 | + |
| 25 | +```rss |
| 26 | +// ops.rss |
| 27 | +module ops |
| 28 | +sum Ops { ADD, MUL, OTHER } |
| 29 | +const MAX_OPS: Int = 64 |
| 30 | +``` |
| 31 | + |
| 32 | +```rss |
| 33 | +// user.rss |
| 34 | +module user |
| 35 | +use ops.Ops |
| 36 | +use ops.ADD |
| 37 | +use ops.MAX_OPS |
| 38 | + |
| 39 | +fn a(o: read Ops) -> Int { return 1 } // OK (type via use) |
| 40 | +fn b() -> fresh Ops { return ADD } // OK (variant via use + bare) |
| 41 | +fn d() -> Int { return MAX_OPS } // OK (const via use + bare) |
| 42 | + |
| 43 | +fn c() -> fresh Ops { return ops.MUL } // error[RS0026]: unknown value binding `ops` |
| 44 | +fn e() -> Int { return ops.MAX_OPS } // error[RS0026]: unknown value binding `ops` |
| 45 | +``` |
| 46 | + |
| 47 | +```rss |
| 48 | +use ops.* // error[RS0015]: unsupported RSScript syntax |
| 49 | +``` |
| 50 | + |
| 51 | +So: qualified *calls* (`ops.fn()`) resolve, but qualified *values* |
| 52 | +(`ops.MUL`, `ops.MAX_OPS`) do not, and there is no glob form. |
| 53 | + |
| 54 | +## Proposed behavior — either option unblocks this |
| 55 | + |
| 56 | +1. **Qualified value access:** resolve `module.Variant` and `module.CONST` in |
| 57 | + value position the same way `module.fn()` already resolves in call position. |
| 58 | + (Preferred — also gives per-use disambiguation for same-named variants across |
| 59 | + modules, which `use` alone cannot.) |
| 60 | +2. **Glob import:** support `use module.*` to bring every public symbol of a |
| 61 | + module into scope at once. (Simpler for the common "import the whole ops |
| 62 | + enum" case; does not solve cross-module name collisions.) |
| 63 | + |
| 64 | +Ideally both; #1 is the more general fix. |
| 65 | + |
| 66 | +## Acceptance criteria |
| 67 | + |
| 68 | +- `fn c() -> fresh Ops { return ops.MUL }` and `fn e() -> Int { return ops.MAX_OPS }` |
| 69 | + check clean. |
| 70 | +- (If #2) `use ops.*` brings `Ops`, its variants, and `MAX_OPS` into scope. |
| 71 | +- A file can reference two same-named variants from different modules — at least |
| 72 | + one via qualification (#1). |
| 73 | + |
| 74 | +## Notes |
| 75 | + |
| 76 | +- Pairs with the portman rss-adapter `module` awareness already shipped, which |
| 77 | + reconstructs the flat owner-qualified identity for de-prefixed functions. |
| 78 | +- Scope is enum variants and constants specifically; types and functions already |
| 79 | + work via `use` / qualified calls. |
0 commit comments