leanprover / leanprover/lean4

LLVM backend generates incorrect `main` function for wasm32

Open
#2,085 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P-low
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Steps to Reproduce

hello.lean

def main : IO Unit := do
  IO.println s!"Hello!"
  1. lean --bc=Hello.bc --target=wasm32 hello.lean
  2. wasm2wat Hello.bc.o | grep main
  (func $_lean_main (type 0) (param i32) (result i32)
  (func $_init_l_main___closed__1 (type 2) (result i32)
        call $_init_l_main___closed__1
  (func $main (type 6) (param i64 i32) (result i64)
      call $_lean_main
  (data $l_main___closed__1 (i32.const 0) "\00\00\00\00")

Expected behavior: main's signature should be (i32, i32) -> i32

Actual behavior: is (i64, i32) -> i64

Versions

Lean (version 4.0.0, commit 4b974fd60b9f, Release)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the hello.lean example and reproduce the issue using lean --bc=Hello.bc --target=wasm32 hello.lean. Inspect the LLVM backend path that generates wasm32's main entry point, then use wasm2wat Hello.bc.o to compare the emitted signature with the expected (i32, i32) -> i32 result.

Written by the indexing model from the issue text.

Assessment

Tech stack
wasm
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.