Repository navigation
self-host P2 slice 5: the core's parallel arrays become arrays of structs #8017
Description
Part of #5980 (phase P2: "The core rewrites its parallel arrays into structs once it can compile them"). This is the last P2 slice; it follows #8000, #8007, #8012 and #8016.
specs/compiler/core/t27core.t27 keeps its tables as 20 parallel i64 arrays:
tk_kind,tk_pos,tk_len;nd_kind...nd_d;mod_from...mod_text;pulled,pulled_mod.
Since #8000 the core compiles structs byte-identically with gen-c, so it can hold its own tables as arrays of structs.
This slice
- Four structs,
Tok,Node,ModandPull, with one array each:toks,nodes,mods,pulls. Each array is a repeat of an all-zero literal, which gen-c writes as{0}. - Every
tk_kind[i]becomestoks[i].kind, and so on.mkandadd_tokwrite a whole struct literal, andswap_pulledcopies structs. - The fixpoint
core(core.t27) == gen-c(core.t27)then runs through:- struct declarations;
- zero struct repeats;
- literals;
- struct copies;
- field reads, writes and
op=.
t27core_ddc.t27restates the four arrays in place of the 20 (the structs arrive with itsuse) and is repinned.- No output byte changes: every fixture and the corpus differential must stay as they are.
Gate: cargo test -p t27c --test core_selfhost on the t27c lab, with the fixpoint, the core tests, every fixture and the corpus differential. The DDC also passes under Zig and t27b.
When this lands, every P2 construct is accepted in a lossless subset or refused by code with a filed defect, so P2 can be ticked in #5980's body.
User Scenarios
- Given the core compiler represents tokens, nodes, modules, and pulls as 20 parallel i64 arrays in
specs/compiler/core/t27core.t27, when the self-host fixpoint test runs, then the core compiles structs byte-identically to gen-c and all 20 arrays are replaced by four struct arrays (toks,nodes,mods,pulls) with zero struct repeats.
Requirements
FR-001: The core MUST declare four structs Tok, Node, Mod, Pull with fields corresponding to the 20 parallel arrays.
FR-002: The core MUST replace the 20 parallel arrays with four arrays of structs: toks, nodes, mods, pulls, each initialized as a zero struct repeat written as {0}.
FR-003: Every array access such as tk_kind[i] MUST become a field access toks[i].kind, and similarly for all 20 fields.
FR-004: The functions mk, add_tok, and swap_pulled MUST write or copy whole struct literals instead of individual fields.
FR-005: The fixpoint core(core.t27) == gen-c(core.t27) MUST pass for struct declarations, zero struct repeats, struct literals, struct copies, and field reads, writes, and op= operations.
FR-006: No fixture output or corpus differential byte MUST change.
Success Criteria
cargo test -p t27c --test core_selfhostexits 0- Fixpoint comparison
core(core.t27) == gen-c(core.t27)passes with exit 0 - All core tests pass with exit 0
- Every fixture test passes with exit 0
- Corpus differential shows 0 byte changes
- DDC passes under Zig and t27b with exit 0
Boundary
- specs/compiler/core/t27core.t27
- .trinity/seals/core.json
Activity
t27core: its parallel arrays become arrays of structs (Closes #8017) (#…