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/w6a/opcodes.ww — types + constants shared across the
// w6a port. Mirrors cmd/w6a/a.h and cmd/w6c/6.out.h.
@@ -3086,6 +3094,7 @@ type asm_ = struct {
errs: i32,
};
//ww:module-reset
// selfhost/cmd/w6a/lex.ww — port of cmd/w6a/lex.c.
//
// Character-level helpers for w6a's line-oriented parser. The parser
@@ -3164,6 +3173,7 @@ export fn parsenum(p: *u8, n: u64) (i64, u64) = {
return v, i;
};
//ww:module-reset
// selfhost/cmd/w6a/parse.ww — port of cmd/w6a/parse.c.
//
// Line-oriented parser for the asm subset emitted by w6c.
@@ -3764,6 +3774,7 @@ export fn parse(a: *asm_) i32 = {
return a.errs;
};
//ww:module-reset
// selfhost/cmd/w6a/asm.ww — port of cmd/w6a/asm.c.
//
// Encode the parsed aprog list into amd64 machine bytes, appending to
@@ -4620,6 +4631,7 @@ export fn encode(a: *asm_) i32 = {
return a.errs;
};
//ww:module-reset
// selfhost/cmd/w6a/obj.ww — port of cmd/w6a/obj.c.
//
// Emit a tiny ELF64 relocatable object. Layout (in file order):
@@ -5033,6 +5045,7 @@ export fn emitelf(a: *asm_, fd: i32) i32 = {
return 0;
};
//ww:module-reset
// selfhost/cmd/w6a/main.ww — port of cmd/w6a/main.c.
//
// w6a = amd64 assembler. Read .s, parse, encode, emit ELF .o.