soegaard / soegaard/webracket

Bug: Invalid `TODO` emitted in WAT for FFI variables (`array.new_fixed`)

Open
#445 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
126
Forks
3
PR merge metrics
No merged PRs in 30d

Description

Bug: Invalid TODO emitted in WAT for FFI variables (array.new_fixed)
Description

The compiler is emitting invalid WebAssembly text (.wat) when encountering
FFI variables. Specifically, the Reference function classifies FFI variables
as 'ffi, but the corresponding code generation branch is unimplemented and
returns the literal symbol 'TODO.

This results in invalid WAT like:

(array.new_fixed $Args 2 (global.get $symbol:quoted-symbol198) TODO)

which causes a compilation failure:

error: expected an instruction
    --> new-term-w-socket-io.wat:95399:74
95399 |     (array.new_fixed $Args 2 (global.get $symbol:quoted-symbol198) TODO)
       |                                                                          ^
* Compilation Error *
Where it comes from

In compiler.rkt, inside Reference:

(case (classify v)
  ...
  [(ffi)        'TODO]
  ...)

The classification is triggered by:

(define (ffi-variable? v)
  (set-member? ffi-primitives-set
               (if (symbol? v) v (syntax-e (variable-id v)))))

and:

[(ffi-variable? v) 'ffi]

So whenever an FFI primitive is referenced, it ends up generating 'TODO
in the output WAT.

Impact
  • Produces invalid .wat output
  • Breaks wat->wasm compilation
  • Blocks use of FFI primitives in compiled programs
Steps to reproduce

Compile a program that references an FFI primitive (e.g. in
new-term-w-socket-io.rkt). The generated .wat will contain TODO
as an operand in an instruction.

Expected behavior

The compiler should emit a valid WebAssembly instruction for FFI variables,
similar to how primitives or globals are handled.

Actual behavior

The compiler emits the literal token TODO, which is not valid WAT syntax.

Suggested fix

Implement the [(ffi) ...] branch in Reference so that FFI variables are
lowered to valid WebAssembly (likely as globals or imported functions),
instead of returning 'TODO.

Contributor guide

No contributing guide indexed for this repository

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 in compiler.rkt at Reference and trace classify, ffi-variable?, and the (ffi) branch. Reproduce with a program such as new-term-w-socket-io.rkt, then determine how FFI variables should be lowered. Done means the generated WAT contains no TODO operand and wat->wasm compiles it successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
wasm
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.