lib: extract rt module from os, sweep imports

Hare puts runtime allocation in rt::, not os:: (ref/hare/rt/malloc.ha:27,
README). ww's `@symbol("rt_alloc") fn alloc(n: u64) *void;` lived at
lib/os/os.ww as a historical bootstrap shortcut; this commit relocates
it to a new lib/rt/malloc.ww and sweeps every site that depended on
`import os` for the alloc decl over to `import rt`.

This is commit 1 of 3 in the lib/rt extraction (#35):
  1. (this) move decl, sweep imports — preserves shape
  2. rename rt_alloc → rt_malloc (#38)
  3. nullable return type + OOM-propagating builtin lowering (#39)

No rename here. Symbol stays rt_alloc, function stays `alloc`, return
stays *void. Behavior identical — same ffi resolution outcome, just
sourced from a different module file. The rt::ensure runtime helper at
selfhost/rt/ensure.ww is its own compilation unit with a local decl and
is untouched.

Side effect: every wcc cgen file used `rt` as a local *node variable
name for "return type." `import rt;` shadows the module, so each
selfhost/cmd/wcc/{check,cgenstmt,cgenexpr,cgenutil}.ww site renamed
to `rtyp`. Mechanical follow-through; only the wcc module-import was
forced to do this rename.

Verified 132/132 + 995_self_rebuild byte-identity (5 wwstage tools
round-trip byte-identical).
This commit is contained in:
2026-05-20 20:39:52 +09:00
parent a1ee817906
commit d68d3c7eb4
34 changed files with 530 additions and 488 deletions

View File

@@ -516,9 +516,9 @@ export fn taggedcallslot(c: *cgen, n: *node) i32 = {
let callee: *node = n.lhs;
if (callee == nil) { return 0; };
if (callee.kind != nkind.N_IDENT) { return 0; };
let rt: *node = fnretlookup(c, callee.str);
if (!istaggedtype(c, rt)) { return 0; };
return slotsize(c, rt);
let rtyp: *node = fnretlookup(c, callee.str);
if (!istaggedtype(c, rtyp)) { return 0; };
return slotsize(c, rtyp);
};
fn nodeisslice(c: *cgen, n: *node) bool = {
@@ -547,8 +547,8 @@ fn nodeisslice(c: *cgen, n: *node) bool = {
let callee: *node = n.lhs;
if (callee != nil) {
if (callee.kind == nkind.N_IDENT) {
let rt: *node = fnretlookupmod(c, callee.str, c.curmod);
return isslicetype(c, rt);
let rtyp: *node = fnretlookupmod(c, callee.str, c.curmod);
return isslicetype(c, rtyp);
};
if (callee.kind == nkind.N_DOT) {
let cmod: str;
@@ -558,8 +558,8 @@ fn nodeisslice(c: *cgen, n: *node) bool = {
cmod = callee.lhs.str;
};
};
let rt: *node = fnretlookupmod(c, callee.str, cmod);
return isslicetype(c, rt);
let rtyp: *node = fnretlookupmod(c, callee.str, cmod);
return isslicetype(c, rtyp);
};
};
return false;
@@ -674,8 +674,8 @@ fn nodeisstr(c: *cgen, n: *node) bool = {
let callee: *node = n.lhs;
if (callee != nil) {
if (callee.kind == nkind.N_IDENT) {
let rt: *node = fnretlookupmod(c, callee.str, c.curmod);
return isstrtype(c, rt);
let rtyp: *node = fnretlookupmod(c, callee.str, c.curmod);
return isstrtype(c, rtyp);
};
// #34: cross-module N_DOT — route through fnretlookupmod
// so a same-leaf caller-module fn (different return shape)
@@ -688,8 +688,8 @@ fn nodeisstr(c: *cgen, n: *node) bool = {
cmod = callee.lhs.str;
};
};
let rt: *node = fnretlookupmod(c, callee.str, cmod);
return isstrtype(c, rt);
let rtyp: *node = fnretlookupmod(c, callee.str, cmod);
return isstrtype(c, rtyp);
};
};
return false;
@@ -1605,8 +1605,8 @@ export fn callsretsize(c: *cgen, n: *node) i32 = {
};
};
if (cn.len == 0) { return 0; };
let rt: *node = fnretlookupmod(c, cn, cmod);
return sretretsize(c, rt);
let rtyp: *node = fnretlookupmod(c, cn, cmod);
return sretretsize(c, rtyp);
};
fn structlookup(c: *cgen, name: str) *structinfo = {
@@ -1863,16 +1863,16 @@ fn inferletcalltype(c: *cgen, rhs: *node) *node = {
};
};
if (cname.len == 0) { return nil; };
let rt: *node = fnretlookupmod(c, cname, cmod);
if (rt == nil) { return nil; };
let rtyp: *node = fnretlookupmod(c, cname, cmod);
if (rtyp == nil) { return nil; };
if (unwrap) {
// Strip error variants — success type is the first
// variant of the tagged return.
if (rt.kind != nkind.N_TTAGGED) { return nil; };
return rt.list;
if (rtyp.kind != nkind.N_TTAGGED) { return nil; };
return rtyp.list;
};
// Plain call: declared return type is the local's type.
return rt;
return rtyp;
};
// letslotsize — slot size for a `let` binding. Like slotsize, but
@@ -2339,8 +2339,8 @@ fn matchscrutt(c: *cgen, scrut: *node) *node = {
};
};
if (cnm.len > 0) {
let rt: *node = fnretlookupmod(c, cnm, cmod);
if (rt != nil) { return resolvetagged(c, rt); };
let rtyp: *node = fnretlookupmod(c, cnm, cmod);
if (rtyp != nil) { return resolvetagged(c, rtyp); };
};
};
return nil;
@@ -2534,9 +2534,9 @@ export fn exprfloatkind(c: *cgen, n: *node) i32 = {
if (n.lhs.kind == nkind.N_IDENT) { nm = n.lhs.str; };
};
if (nm.len > 0) {
let rt: *node = fnretlookup(c, nm);
if (isf32type(c, rt)) { return 1; };
if (isfloattype(c, rt)) { return 2; };
let rtyp: *node = fnretlookup(c, nm);
if (isf32type(c, rtyp)) { return 1; };
if (isfloattype(c, rtyp)) { return 2; };
};
return 0;
};
@@ -3055,9 +3055,9 @@ fn rhstaggedabicall(c: *cgen, src: *node) bool = {
};
};
if (calleename.len > 0) {
let rt: *node = fnretlookupmod(c, calleename, cmod);
if (rt != nil) {
if (istaggedtype(c, rt)) { return true; };
let rtyp: *node = fnretlookupmod(c, calleename, cmod);
if (rtyp != nil) {
if (istaggedtype(c, rtyp)) { return true; };
};
};
};