Skip to content

fix(mlir): doom #230 MLIR→wasm playable path - #250

Merged
godofecht merged 5 commits into
mainfrom
cursor/mlir-struct-statics-b994
Aug 9, 2026
Merged

godofecht merged 5 commits into
mainfrom
cursor/mlir-struct-statics-b994

Conversation

@godofecht

@godofecht godofecht commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes the Flow side of #230: doom-flow MLIR→wasm boots and is interactive in-browser (title / menu via Enter).

MLIR fixes (doom)

  1. Struct module statics — emit LLVM init regions (no undef)
  2. Unsigned %// — remui/divui when operands are uN
  3. u8 widen — extui not extsi (255→255)
  4. &module_global — addressof, not alloca spill (thinker list / wasm table OOB)

CI (this follow-up)

Tier-2 failed on pre-existing examples/wasm/parallel_scaling.flow (let mut cur_shards = SHARDS_MAX). Root cause: Symbol(..., const, exported, decl) put decl in is_mutable so definition was always None. Fixed construction + _is_const_scalar accepts module const refs.

Verification

  • Unit: struct statics, unsigned ops, addressof, module statics (+ const-ref init)
  • parallel_scaling.flow --strict transpiles
  • Browser MLIR doom interactive (local)
  • CI green after this push
Open in Web Open in Cursor 

cursoragent and others added 3 commits August 9, 2026 16:55
Bare llvm.mlir.global for struct / struct-array statics lowered to
LLVM undef, so doom tables (iwads, menus, animdefs, …) were garbage
and W_ReadLump failed with incomplete reads.

Emit LLVM-dialect-only init regions (arith is illegal there): fold
constant field exprs, addressof string literals, insertvalue structs,
and llvm.mlir.zero for missing/aggregate defaults.

Co-authored-by: Abhishek Shivakumar <[email protected]>
Two MLIR bugs blocked doom-flow on wasm:

1. Struct / struct-array module statics lowered to LLVM undef
   (iwads, menus, animdefs, …). Emit LLVM-dialect init regions.

2. u32 `%` / `/` used signed srem/sdiv when unsigned-ness was not
   tracked on call results / global loads. W_LumpNameHash % n then
   produced negative GEP indices, corrupted the heap (FILE*), and
   W_ReadLump failed with incomplete reads after W_GenerateHashTable.

Co-authored-by: Abhishek Shivakumar <[email protected]>
ptr<u8>[i] as i32 was using arith.extsi (255→-1), breaking Doom WAD
SHORT/LONG assembly and R_InitTextures patch lookup. Mark unsigned
loads/casts and use extui; same for u8 struct fields.

Co-authored-by: Abhishek Shivakumar <[email protected]>
@cursor cursor Bot changed the title fix(mlir): initialize struct module statics (doom #230) fix(mlir): struct statics + unsigned ops for doom #230 Aug 9, 2026
&thinkercap spilled the global address into a fresh alloca and returned
the alloca pointer (pointer-to-pointer). Thinker list init wrote through
stack temps; P_Ticker then call_indirect'd heap addresses → wasm table
index OOB / frozen title screen.

Co-authored-by: Abhishek Shivakumar <[email protected]>
@cursor cursor Bot changed the title fix(mlir): struct statics + unsigned ops for doom #230 fix(mlir): doom #230 MLIR→wasm playable path Aug 9, 2026
Symbol(const) stuffed the ConstDecl into is_mutable (positional arg
bug), so definition was always None and `let mut x = SOME_CONST`
failed strict tier-2 (examples/wasm/parallel_scaling.flow). Pass
definition= explicitly; accept const bindings in _is_const_scalar.

Co-authored-by: Abhishek Shivakumar <[email protected]>
@godofecht
godofecht marked this pull request as ready for review August 9, 2026 19:41
@cursor

cursor Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@godofecht
godofecht merged commit 0ecb0cb into main Aug 9, 2026
15 checks passed
@cursor
cursor Bot deleted the cursor/mlir-struct-statics-b994 branch August 9, 2026 20:11
cursor Bot pushed a commit that referenced this pull request Aug 9, 2026
)

Confirm #253/#254 against Flow tip: addressof for module globals (from #250)
stops -O1+ turning drawshim getters into unreachable/noreturn, and static
string arrays initialize via _emit_static_llvm_array_global. Size ptr/string
to 4 bytes under --wasm32 in memref layouts (#255). Refresh doom_mlir -O2
preview and document status.

Co-authored-by: Cursor Agent <[email protected]>
godofecht added a commit that referenced this pull request Aug 9, 2026
* fix(mlir): initialize struct module statics (doom #230)

Bare llvm.mlir.global for struct / struct-array statics lowered to
LLVM undef, so doom tables (iwads, menus, animdefs, …) were garbage
and W_ReadLump failed with incomplete reads.

Emit LLVM-dialect-only init regions (arith is illegal there): fold
constant field exprs, addressof string literals, insertvalue structs,
and llvm.mlir.zero for missing/aggregate defaults.

Co-authored-by: Abhishek Shivakumar <[email protected]>

* fix(mlir): struct static inits + unsigned rem/div (#230)

Two MLIR bugs blocked doom-flow on wasm:

1. Struct / struct-array module statics lowered to LLVM undef
   (iwads, menus, animdefs, …). Emit LLVM-dialect init regions.

2. u32 `%` / `/` used signed srem/sdiv when unsigned-ness was not
   tracked on call results / global loads. W_LumpNameHash % n then
   produced negative GEP indices, corrupted the heap (FILE*), and
   W_ReadLump failed with incomplete reads after W_GenerateHashTable.

Co-authored-by: Abhishek Shivakumar <[email protected]>

* fix(mlir): zero-extend u8 loads on widen (#230)

ptr<u8>[i] as i32 was using arith.extsi (255→-1), breaking Doom WAD
SHORT/LONG assembly and R_InitTextures patch lookup. Mark unsigned
loads/casts and use extui; same for u8 struct fields.

Co-authored-by: Abhishek Shivakumar <[email protected]>

* fix(mlir): &module_global is addressof, not alloca spill (#230)

&thinkercap spilled the global address into a fresh alloca and returned
the alloca pointer (pointer-to-pointer). Thinker list init wrote through
stack temps; P_Ticker then call_indirect'd heap addresses → wasm table
index OOB / frozen title screen.

Co-authored-by: Abhishek Shivakumar <[email protected]>

* fix(types): const refs are valid module-static initializers

Symbol(const) stuffed the ConstDecl into is_mutable (positional arg
bug), so definition was always None and `let mut x = SOME_CONST`
failed strict tier-2 (examples/wasm/parallel_scaling.flow). Pass
definition= explicitly; accept const bindings in _is_const_scalar.

Co-authored-by: Abhishek Shivakumar <[email protected]>

---------

Co-authored-by: Cursor Agent <[email protected]>
godofecht added a commit that referenced this pull request Aug 9, 2026
Record that BACKEND=mlir doom boots in-browser after the generator fixes
on main, and document the dual C|MLIR→emcc near-term path.

Co-authored-by: Abhishek Shivakumar <[email protected]>
godofecht added a commit that referenced this pull request Aug 9, 2026
)

Confirm #253/#254 against Flow tip: addressof for module globals (from #250)
stops -O1+ turning drawshim getters into unreachable/noreturn, and static
string arrays initialize via _emit_static_llvm_array_global. Size ptr/string
to 4 bytes under --wasm32 in memref layouts (#255). Refresh doom_mlir -O2
preview and document status.

Co-authored-by: Cursor Agent <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants