commit 3835e9d2503c407c83fc7f3195f01bd6ae033c92
parent 0f62395863b90231877320b7f7c8f669f8023133
Author: Ryan Sepassi <rsepassi@gmail.com>
Date: Wed, 10 Jun 2026 07:05:45 -0700
cleanup(wasm): hoist WasmCgControl to file scope
The per-function control-stack entry typedef was declared inside the
~1960-line wasm_emit_cg_into; move it to file scope for discoverability.
Pure scope move, zero behavior change. test-wasm-front 549/0.
(Left the link_jit preflight duplicate-global check in place: its comment
documents that it must validate before mutating image-visible state, and
append_cursor is committed before the main-loop duplicate check — removing
the preflight would leak partial cursor advances on a late panic.)
Diffstat:
2 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/doc/plan/TODO.md b/doc/plan/TODO.md
@@ -137,7 +137,8 @@ Add new deferred fixes below as they are discovered.
- `jit_append_obj_inner` (`src/link/link_jit.c`, ~482 lines reimplementing the AOT
pipeline; had a verbatim-duplicated duplicate-global check).
- `wasm_emit_cg_into` (`lang/wasm/cg.c`, ~1960 lines fusing module setup with a
- 174-case opcode switch; hoist `WasmCgControl` to file scope).
+ 174-case opcode switch). (`WasmCgControl` is now hoisted to file scope; the
+ module-setup/opcode-switch split remains.)
- `c_emit_data_symbol` (`src/arch/c_target/c_emit.c`, ~306 lines; doubled reloc-walk).
## Cross-platform test failures
diff --git a/lang/wasm/cg.c b/lang/wasm/cg.c
@@ -2010,6 +2010,16 @@ static void wasm_cg_cache_funcref_entry(
kit_cg_label_place(cg, done);
}
+/* Per-function control-stack entry for the opcode walk in wasm_emit_cg_into:
+ * one frame per structured block/loop/if, carrying its CG labels. */
+typedef struct WasmCgControl {
+ uint8_t kind;
+ int seen_else;
+ KitCgLabel start;
+ KitCgLabel end;
+ KitCgLabel else_label;
+} WasmCgControl;
+
void wasm_emit_cg_into(KitCompiler* c, KitCg* cg, const WasmModule* m) {
KitCgBuiltinTypes b = kit_cg_builtin_types(c);
WasmCgRuntime rt;
@@ -2330,13 +2340,6 @@ void wasm_emit_cg_into(KitCompiler* c, KitCg* cg, const WasmModule* m) {
wasm_cg_emit_runtime_layout_metadata(c, cg, b, m, &rt);
for (i = 0; i < m->nfuncs; ++i) {
const WasmFunc* f = &m->funcs[i];
- typedef struct WasmCgControl {
- uint8_t kind;
- int seen_else;
- KitCgLabel start;
- KitCgLabel end;
- KitCgLabel else_label;
- } WasmCgControl;
/* Per-function arena-allocated locals and control stack. locals is
* sized to nparams + nlocals; the control stack starts at 16 entries
* and doubles in-place on overflow (arena pointers are stable, so