wcc/ww: mangle imported symbols on dotted import path (#22 M1, #32)

Switch symbol mangling from the import leaf clause to the full dotted import path for directory packages; single-file imports keep package-clause mangling (isdir-gate: imported<=>directory-import). The root build unit's fn main stays bare, every other top-level decl mangles, closing #31's duplicate-main hazard by construction (#32). Both stages, byte-identical.

Single commit, not split: the bare rename (f244af3) is red on its own because it unmasks cross-module resolution gaps that do not reproduce pre-M1, so the fixes are intrinsic to making the rename correct. Included: wwstage fnret/fnparamslookupmod map import alias->path (#199b cross-module union-variant scrutinee resolved the wrong fn's union); cstage use_path prefers the referencing module's import for an ambiguous leaf alias (sha256 crypto.math vs strconv math). Tests table-driven: 989_m1mangle_run/_sym, 989_m1union_run (gate-visible per-arm exit codes + cs==ww byte-id).
This commit is contained in:
2026-06-15 17:37:18 +09:00
parent 64d6c15e41
commit f308818b4b
30 changed files with 1851 additions and 241 deletions

View File

@@ -1,3 +1,4 @@
//ww:module time
// time — clocks, instants, durations. Mirrors Hare's lib/time
// (ref/hare/time/duration.ha, instant.ha, arithm.ha,
// +linux/functions.ha). Calendar / date / strftime / timezone /
@@ -95,6 +96,7 @@ export fn compare(a: instant, b: instant) i8 = {
return 0i8;
};
//ww:module rt
// rt — runtime primitives exposed to ww programs.
// Mirrors Hare's rt:: module placement (ref/hare/rt/).
@@ -118,6 +120,7 @@ package rt;
// a future task (task #39). ref/hare/rt/malloc.ha:27.
@symbol("rt_malloc") export fn malloc(n: u64) *void;
//ww:module os
// os — process and filesystem facade. The body of each call lands
// either in libwwrt.a (rt_syscall trampoline) or libc bindings,
// depending on how the program was linked.
@@ -856,6 +859,7 @@ export fn exists(path: str) bool = {
return r >= 0i64;
};
//ww:module types
// types — integer limits. Mirrors Hare's types::limits (I8_MAX, …)
// platform-fixed for amd64. Numeric helpers live in lib/math, matching
// Hare's split between types::limits and math::.
@@ -900,6 +904,7 @@ def UINTPTR_MAX: uintptr = U64_MAX: uintptr;
def RUNE_MIN: rune = '\0';
//ww:module bytes
// bytes — slice operations over []u8. Mirrors Hare's bytes module
// (ref/hare/bytes/) for the in-tree subset: search/equality/prefix
// helpers used by lib/encoding, lib/bufio, lib/memio.
@@ -1451,6 +1456,7 @@ export fn rcut(in: []u8, delim: (u8 | []u8)) ([]u8, []u8) = {
};
};
//ww:module encoding.utf8
// encoding/utf8 — UTF-8 encode/decode. Hare port; see
// ref/hare/encoding/utf8/{types,rune,encode,decode,decodetable}.ha.
//
@@ -1908,6 +1914,7 @@ export fn position(d: *decoder) i32 = {
};
//ww:module strings
// strings — operations over str ({ptr,len}). Hare port; see
// ref/hare/strings/.
//
@@ -2860,6 +2867,7 @@ export fn rpad(s: str, p: rune, maxlen: i32) str = {
return frombytes(buf);
};
//ww:module-reset
// selfhost/cmd/w6l/sym.ww — port of cmd/w6l/sym.c.
//
// Linker symbol table. Singly-linked list, usually a few hundred
@@ -2961,6 +2969,7 @@ export fn lookup(l: *lnk, name: str) *lsym = {
return nil;
};
//ww:module-reset
// selfhost/cmd/w6l/obj.ww — port of cmd/w6l/obj.c.
//
// Loads relocatable ELF64 .o files emitted by w6a, appends .text to
@@ -3580,6 +3589,7 @@ fn loadimage(l: *lnk, path: *u8, buf: *u8, len: u64) i32 = {
return 0;
};
//ww:module-reset
// selfhost/cmd/w6l/dyn.ww — port of cmd/w6l/dyn.c.
//
// Load a shared object (ET_DYN) so the linker knows which symbols it
@@ -3983,6 +3993,7 @@ export fn soversion(so: *lso, name: str) str = {
return result;
};
//ww:module-reset
// selfhost/cmd/w6l/pass.ww — port of cmd/w6l/pass.c.
//
// Resolution + relocation. l_resolve flags every undefined symbol
@@ -4115,6 +4126,7 @@ export fn relocate(l: *lnk, textva: u64, datava: u64) i32 = {
return l.errs;
};
//ww:module-reset
// selfhost/cmd/w6l/dynout.ww — port of cmd/w6l/dynout.c.
//
// Emit a dynamic-linked ELF executable. The shape is the simplest
@@ -4867,6 +4879,7 @@ export fn emitdynelf(l: *lnk, fd: i32, base: u64, entry: u64) i32 = {
return 0;
};
//ww:module-reset
// selfhost/cmd/w6l/out.ww — port of cmd/w6l/out.c.
//
// Emit a static ELF64 executable. File layout (per the C original):
@@ -5048,6 +5061,7 @@ export fn emitelf(l: *lnk, fd: i32, base: u64, entry: u64) i32 = {
return 0;
};
//ww:module-reset
// selfhost/cmd/w6l/main.ww — port of cmd/w6l/main.c.
//
// w6l = amd64 linker. Reads relocatable ELF .o files, SysV `ar`