wcc/ww: .wwi separate-compile consumer — w6c -c codegen filter (#22 M3)
New `w6c -c` (both stages): separate-compile / primary-only codegen. Emit code+DATA ONLY for a package's own (imported==0) decls; treat every `.wwi`-sourced (imported==1) dep decl as an external. Pure addition behind the flag — combined.ww stays the LIVE path, `-c` is off on every existing invocation, so the 990-997 byte-id gates + all prior tests are unperturbed. The keystone (rob): a `.wwi` is body-less/init-less prototype source, and cgen already skips body-less fns as externs, so dep fns/types/defs emit NOTHING for free. The single genuinely-new guard is an imported value- global (`export let`): its DATAW would DUPLICATE the dep's own definition (link collision), so it is skipped. The `imported==0` gate is applied at all top-level emit sites for uniformity (close-by-construction): the fn loop, emit_lets/emitletdataw, emit_defs/emitdefconstants, and let_pre_intern/letpreintern — that last one because an imported dep's body initializer interns strlits while its rhs-stripped `.wwi` does not, which would shift the _S_ sequence; gating it keeps the strlit table a pure function of the package's own decls. EXACTLY symmetric with M2's producer `imported==0` filter — same predicate both directions. Driver `--sep` build_one_sep + per-package archives + multi-.a link + cache + BROAD real-target dual-path soak are M3-tail (#46, rob ruling B): M3-core ships the codegen spine + a self-contained gate that proves all codegen correctness without a production driver. Gate 989_m3sep_run: a synth leaf->mid->root fixture carrying all four cross-boundary fact-classes (fn signature, struct LAYOUT, `def` const VALUE, `export let` value-global). Per package, holding `-c` constant: `w6c -c` of (deps-as-bodies) == (deps-as-.wwi) byte-for-byte (the .wwi conveys exactly the dep facts P's codegen needs); cs==ww at the .s AND final-exe level (rule 10); sep-path determinism; the value-global guard (imported origin_tag never re-emits DATAW); and behavioral identity (the linked program's exit code is the real cross-boundary computation). COLD: .wwi materialized fresh every run (no warm cache). combined.ww regen'd for wwdump + w6c (both embed cgen.ww); diff is exactly the four guards + the flag wiring, nothing spurious.
This commit is contained in:
@@ -41184,8 +41184,15 @@ export fn cgfile(c: *cgen, file: *node) void = {
|
||||
let d: *node = file.list;
|
||||
for (d != nil) {
|
||||
if (d.kind == nkind.N_FNDECL) {
|
||||
if (d.body != nil) {
|
||||
cgfn(c, d);
|
||||
// #22 M3: emit code ONLY for this package's own decls. A
|
||||
// `.wwi` dep fn is a body-less prototype that already skips
|
||||
// (the body != nil gate); the explicit imported gate also
|
||||
// covers a dep fn that still carries a body in a transitional
|
||||
// unit, keeping the "emit iff imported==0" rule exception-free.
|
||||
if (!(c.sepmode != 0 && d.imported != 0)) {
|
||||
if (d.body != nil) {
|
||||
cgfn(c, d);
|
||||
};
|
||||
};
|
||||
};
|
||||
d = d.next;
|
||||
@@ -41738,6 +41745,14 @@ type cgen = struct {
|
||||
// global receiver wired; mutually exclusive with sretdestoff.
|
||||
sretdestnode: *node,
|
||||
sretforward: i32,
|
||||
// #22 M3 `-c`: separate-compile / primary-only codegen. Emit code+
|
||||
// DATA ONLY for this package's own (imported==0) decls; treat every
|
||||
// `.wwi`-sourced (imported==1) dep decl as an external. Off on the
|
||||
// combined path (every existing invocation) so M3 is a pure addition.
|
||||
// NOT reset by cgeninit (which runs per-fn) — set once in main and
|
||||
// must survive to the post-loop emitletdataw/emitdefconstants pass,
|
||||
// like strlits/ffis. Symmetric with cstage Cg.sep_mode.
|
||||
sepmode: i32,
|
||||
};
|
||||
|
||||
// Top-level mutable `let` registry. Mirrors cmd/w6c/cgen.c LetVar.
|
||||
@@ -42659,6 +42674,14 @@ export fn letpreintern(c: *cgen, file: *node) void = {
|
||||
if (file == nil) { return; };
|
||||
let d: *node = file.list;
|
||||
for (d != nil) {
|
||||
// #22 M3: skip imported deps so the strlit table (and its _S_
|
||||
// sequence) is a pure function of THIS package's own decls. A
|
||||
// dep's body initializer would intern here, but its `.wwi` (init
|
||||
// stripped) would not — gating on imported keeps the
|
||||
// bodies-vs-.wwi `.s` byte-identical for P's own symbols. Cross-
|
||||
// module str-def splicing rides the def registry (interned at the
|
||||
// use site, not here), so it is unaffected.
|
||||
if (c.sepmode != 0 && d.imported != 0) { d = d.next; continue; };
|
||||
// #8/GAP-B: a `def [N]str` needs the SAME element-strlit
|
||||
// pre-interning as the let [N]str arm (the #18 ordering
|
||||
// contract) so emitstrarraydata's DATAR rows find their _S_
|
||||
@@ -44123,6 +44146,13 @@ fn emittupledata(c: *cgen, name: str, module: str, tt: *node, rhs: *node) bool =
|
||||
fn emitletdataw(c: *cgen, file: *node) void = {
|
||||
let d: *node = file.list;
|
||||
for (d != nil) {
|
||||
// #22 M3 THE ONE REAL GUARD: a `.wwi` dep value-global is
|
||||
// initializer-less; emitting a DATAW for it would DUPLICATE the
|
||||
// definition that lives in the dep's own .o → link collision.
|
||||
// Gate on the explicit imported flag (NOT no-rhs: a package's OWN
|
||||
// init-less let must still zero-init). Symmetric with M2's
|
||||
// producer imported==0 filter — same predicate both ways.
|
||||
if (c.sepmode != 0 && d.imported != 0) { d = d.next; continue; };
|
||||
if (d.kind == nkind.N_LET) {
|
||||
let nm: str = d.str;
|
||||
if (nm.len > 0) {
|
||||
@@ -44461,6 +44491,12 @@ fn emitletdataw(c: *cgen, file: *node) void = {
|
||||
fn emitdefconstants(c: *cgen, file: *node) void = {
|
||||
let d: *node = file.list;
|
||||
for (d != nil) {
|
||||
// #22 M3: a `.wwi` dep def with DATA storage (int-fold / float /
|
||||
// struct / array) must NOT re-emit — the dep's own .o owns the
|
||||
// symbol. Str defs are inline-spliced (never emitted here), so
|
||||
// they need no gate; the def registry stays populated for imported
|
||||
// decls so the target's LOAD paths still resolve the extern.
|
||||
if (c.sepmode != 0 && d.imported != 0) { d = d.next; continue; };
|
||||
if (d.kind == nkind.N_DEF) {
|
||||
let r: *node = d.rhs;
|
||||
let v: u64 = 0u64;
|
||||
@@ -45931,6 +45967,9 @@ export fn main(argc: i32, argv: **u8) i32 = {
|
||||
let out: *u8 = nil;
|
||||
let wwiout: *u8 = nil; // -I <out.wwi>: M2 export-data producer
|
||||
let testmode: i32 = 0i32; // #15: `-T` test-mode
|
||||
let sepmode: i32 = 0i32; // -c: #22 M3 separate-compile / primary-
|
||||
// only codegen (emit imported==0 decls
|
||||
// only; treat `.wwi` deps as external)
|
||||
|
||||
let i: i32 = 1;
|
||||
for (i < argc) {
|
||||
@@ -45953,6 +45992,8 @@ export fn main(argc: i32, argv: **u8) i32 = {
|
||||
wwiout = argv[i];
|
||||
} else { if (cstreq(a, "-T")) {
|
||||
testmode = 1i32;
|
||||
} else { if (cstreq(a, "-c")) {
|
||||
sepmode = 1i32;
|
||||
} else { if (a[0u64] == 45u8) {
|
||||
let m: str = "w6c: unknown flag\n";
|
||||
os.write(2, m.ptr, m.len: u64);
|
||||
@@ -45964,7 +46005,7 @@ export fn main(argc: i32, argv: **u8) i32 = {
|
||||
return 2;
|
||||
};
|
||||
src = a;
|
||||
}; }; }; };
|
||||
}; }; }; }; };
|
||||
i += 1;
|
||||
};
|
||||
|
||||
@@ -46043,6 +46084,7 @@ export fn main(argc: i32, argv: **u8) i32 = {
|
||||
|
||||
let cg: cgen;
|
||||
cgeninit(&cg);
|
||||
cg.sepmode = sepmode;
|
||||
cgfile(&cg, f);
|
||||
return 0;
|
||||
};
|
||||
|
||||
@@ -82,6 +82,9 @@ export fn main(argc: i32, argv: **u8) i32 = {
|
||||
let out: *u8 = nil;
|
||||
let wwiout: *u8 = nil; // -I <out.wwi>: M2 export-data producer
|
||||
let testmode: i32 = 0i32; // #15: `-T` test-mode
|
||||
let sepmode: i32 = 0i32; // -c: #22 M3 separate-compile / primary-
|
||||
// only codegen (emit imported==0 decls
|
||||
// only; treat `.wwi` deps as external)
|
||||
|
||||
let i: i32 = 1;
|
||||
for (i < argc) {
|
||||
@@ -104,6 +107,8 @@ export fn main(argc: i32, argv: **u8) i32 = {
|
||||
wwiout = argv[i];
|
||||
} else { if (cstreq(a, "-T")) {
|
||||
testmode = 1i32;
|
||||
} else { if (cstreq(a, "-c")) {
|
||||
sepmode = 1i32;
|
||||
} else { if (a[0u64] == 45u8) {
|
||||
let m: str = "w6c: unknown flag\n";
|
||||
os.write(2, m.ptr, m.len: u64);
|
||||
@@ -115,7 +120,7 @@ export fn main(argc: i32, argv: **u8) i32 = {
|
||||
return 2;
|
||||
};
|
||||
src = a;
|
||||
}; }; }; };
|
||||
}; }; }; }; };
|
||||
i += 1;
|
||||
};
|
||||
|
||||
@@ -194,6 +199,7 @@ export fn main(argc: i32, argv: **u8) i32 = {
|
||||
|
||||
let cg: cgen;
|
||||
cgeninit(&cg);
|
||||
cg.sepmode = sepmode;
|
||||
cgfile(&cg, f);
|
||||
return 0;
|
||||
};
|
||||
|
||||
@@ -539,6 +539,14 @@ type cgen = struct {
|
||||
// global receiver wired; mutually exclusive with sretdestoff.
|
||||
sretdestnode: *node,
|
||||
sretforward: i32,
|
||||
// #22 M3 `-c`: separate-compile / primary-only codegen. Emit code+
|
||||
// DATA ONLY for this package's own (imported==0) decls; treat every
|
||||
// `.wwi`-sourced (imported==1) dep decl as an external. Off on the
|
||||
// combined path (every existing invocation) so M3 is a pure addition.
|
||||
// NOT reset by cgeninit (which runs per-fn) — set once in main and
|
||||
// must survive to the post-loop emitletdataw/emitdefconstants pass,
|
||||
// like strlits/ffis. Symmetric with cstage Cg.sep_mode.
|
||||
sepmode: i32,
|
||||
};
|
||||
|
||||
// Top-level mutable `let` registry. Mirrors cmd/w6c/cgen.c LetVar.
|
||||
@@ -1460,6 +1468,14 @@ export fn letpreintern(c: *cgen, file: *node) void = {
|
||||
if (file == nil) { return; };
|
||||
let d: *node = file.list;
|
||||
for (d != nil) {
|
||||
// #22 M3: skip imported deps so the strlit table (and its _S_
|
||||
// sequence) is a pure function of THIS package's own decls. A
|
||||
// dep's body initializer would intern here, but its `.wwi` (init
|
||||
// stripped) would not — gating on imported keeps the
|
||||
// bodies-vs-.wwi `.s` byte-identical for P's own symbols. Cross-
|
||||
// module str-def splicing rides the def registry (interned at the
|
||||
// use site, not here), so it is unaffected.
|
||||
if (c.sepmode != 0 && d.imported != 0) { d = d.next; continue; };
|
||||
// #8/GAP-B: a `def [N]str` needs the SAME element-strlit
|
||||
// pre-interning as the let [N]str arm (the #18 ordering
|
||||
// contract) so emitstrarraydata's DATAR rows find their _S_
|
||||
@@ -2924,6 +2940,13 @@ fn emittupledata(c: *cgen, name: str, module: str, tt: *node, rhs: *node) bool =
|
||||
fn emitletdataw(c: *cgen, file: *node) void = {
|
||||
let d: *node = file.list;
|
||||
for (d != nil) {
|
||||
// #22 M3 THE ONE REAL GUARD: a `.wwi` dep value-global is
|
||||
// initializer-less; emitting a DATAW for it would DUPLICATE the
|
||||
// definition that lives in the dep's own .o → link collision.
|
||||
// Gate on the explicit imported flag (NOT no-rhs: a package's OWN
|
||||
// init-less let must still zero-init). Symmetric with M2's
|
||||
// producer imported==0 filter — same predicate both ways.
|
||||
if (c.sepmode != 0 && d.imported != 0) { d = d.next; continue; };
|
||||
if (d.kind == nkind.N_LET) {
|
||||
let nm: str = d.str;
|
||||
if (nm.len > 0) {
|
||||
@@ -3262,6 +3285,12 @@ fn emitletdataw(c: *cgen, file: *node) void = {
|
||||
fn emitdefconstants(c: *cgen, file: *node) void = {
|
||||
let d: *node = file.list;
|
||||
for (d != nil) {
|
||||
// #22 M3: a `.wwi` dep def with DATA storage (int-fold / float /
|
||||
// struct / array) must NOT re-emit — the dep's own .o owns the
|
||||
// symbol. Str defs are inline-spliced (never emitted here), so
|
||||
// they need no gate; the def registry stays populated for imported
|
||||
// decls so the target's LOAD paths still resolve the extern.
|
||||
if (c.sepmode != 0 && d.imported != 0) { d = d.next; continue; };
|
||||
if (d.kind == nkind.N_DEF) {
|
||||
let r: *node = d.rhs;
|
||||
let v: u64 = 0u64;
|
||||
|
||||
@@ -647,8 +647,15 @@ export fn cgfile(c: *cgen, file: *node) void = {
|
||||
let d: *node = file.list;
|
||||
for (d != nil) {
|
||||
if (d.kind == nkind.N_FNDECL) {
|
||||
if (d.body != nil) {
|
||||
cgfn(c, d);
|
||||
// #22 M3: emit code ONLY for this package's own decls. A
|
||||
// `.wwi` dep fn is a body-less prototype that already skips
|
||||
// (the body != nil gate); the explicit imported gate also
|
||||
// covers a dep fn that still carries a body in a transitional
|
||||
// unit, keeping the "emit iff imported==0" rule exception-free.
|
||||
if (!(c.sepmode != 0 && d.imported != 0)) {
|
||||
if (d.body != nil) {
|
||||
cgfn(c, d);
|
||||
};
|
||||
};
|
||||
};
|
||||
d = d.next;
|
||||
|
||||
@@ -41184,8 +41184,15 @@ export fn cgfile(c: *cgen, file: *node) void = {
|
||||
let d: *node = file.list;
|
||||
for (d != nil) {
|
||||
if (d.kind == nkind.N_FNDECL) {
|
||||
if (d.body != nil) {
|
||||
cgfn(c, d);
|
||||
// #22 M3: emit code ONLY for this package's own decls. A
|
||||
// `.wwi` dep fn is a body-less prototype that already skips
|
||||
// (the body != nil gate); the explicit imported gate also
|
||||
// covers a dep fn that still carries a body in a transitional
|
||||
// unit, keeping the "emit iff imported==0" rule exception-free.
|
||||
if (!(c.sepmode != 0 && d.imported != 0)) {
|
||||
if (d.body != nil) {
|
||||
cgfn(c, d);
|
||||
};
|
||||
};
|
||||
};
|
||||
d = d.next;
|
||||
@@ -41738,6 +41745,14 @@ type cgen = struct {
|
||||
// global receiver wired; mutually exclusive with sretdestoff.
|
||||
sretdestnode: *node,
|
||||
sretforward: i32,
|
||||
// #22 M3 `-c`: separate-compile / primary-only codegen. Emit code+
|
||||
// DATA ONLY for this package's own (imported==0) decls; treat every
|
||||
// `.wwi`-sourced (imported==1) dep decl as an external. Off on the
|
||||
// combined path (every existing invocation) so M3 is a pure addition.
|
||||
// NOT reset by cgeninit (which runs per-fn) — set once in main and
|
||||
// must survive to the post-loop emitletdataw/emitdefconstants pass,
|
||||
// like strlits/ffis. Symmetric with cstage Cg.sep_mode.
|
||||
sepmode: i32,
|
||||
};
|
||||
|
||||
// Top-level mutable `let` registry. Mirrors cmd/w6c/cgen.c LetVar.
|
||||
@@ -42659,6 +42674,14 @@ export fn letpreintern(c: *cgen, file: *node) void = {
|
||||
if (file == nil) { return; };
|
||||
let d: *node = file.list;
|
||||
for (d != nil) {
|
||||
// #22 M3: skip imported deps so the strlit table (and its _S_
|
||||
// sequence) is a pure function of THIS package's own decls. A
|
||||
// dep's body initializer would intern here, but its `.wwi` (init
|
||||
// stripped) would not — gating on imported keeps the
|
||||
// bodies-vs-.wwi `.s` byte-identical for P's own symbols. Cross-
|
||||
// module str-def splicing rides the def registry (interned at the
|
||||
// use site, not here), so it is unaffected.
|
||||
if (c.sepmode != 0 && d.imported != 0) { d = d.next; continue; };
|
||||
// #8/GAP-B: a `def [N]str` needs the SAME element-strlit
|
||||
// pre-interning as the let [N]str arm (the #18 ordering
|
||||
// contract) so emitstrarraydata's DATAR rows find their _S_
|
||||
@@ -44123,6 +44146,13 @@ fn emittupledata(c: *cgen, name: str, module: str, tt: *node, rhs: *node) bool =
|
||||
fn emitletdataw(c: *cgen, file: *node) void = {
|
||||
let d: *node = file.list;
|
||||
for (d != nil) {
|
||||
// #22 M3 THE ONE REAL GUARD: a `.wwi` dep value-global is
|
||||
// initializer-less; emitting a DATAW for it would DUPLICATE the
|
||||
// definition that lives in the dep's own .o → link collision.
|
||||
// Gate on the explicit imported flag (NOT no-rhs: a package's OWN
|
||||
// init-less let must still zero-init). Symmetric with M2's
|
||||
// producer imported==0 filter — same predicate both ways.
|
||||
if (c.sepmode != 0 && d.imported != 0) { d = d.next; continue; };
|
||||
if (d.kind == nkind.N_LET) {
|
||||
let nm: str = d.str;
|
||||
if (nm.len > 0) {
|
||||
@@ -44461,6 +44491,12 @@ fn emitletdataw(c: *cgen, file: *node) void = {
|
||||
fn emitdefconstants(c: *cgen, file: *node) void = {
|
||||
let d: *node = file.list;
|
||||
for (d != nil) {
|
||||
// #22 M3: a `.wwi` dep def with DATA storage (int-fold / float /
|
||||
// struct / array) must NOT re-emit — the dep's own .o owns the
|
||||
// symbol. Str defs are inline-spliced (never emitted here), so
|
||||
// they need no gate; the def registry stays populated for imported
|
||||
// decls so the target's LOAD paths still resolve the extern.
|
||||
if (c.sepmode != 0 && d.imported != 0) { d = d.next; continue; };
|
||||
if (d.kind == nkind.N_DEF) {
|
||||
let r: *node = d.rhs;
|
||||
let v: u64 = 0u64;
|
||||
|
||||
Reference in New Issue
Block a user