Skip to content

codegen(wasm): an extern lowered to WASI is also emitted as an unsatisfiable env import (e.g. env.clock_now_ms) #851

Backlog

Description

@hyperpolymath

An in-file extern fn clock_now_ms makes core wasm emit an unsatisfiable import. The failure is loud: a WASI-only host cannot instantiate the module.

extern fn clock_now_ms(clock_id: Int) -> Int;
pub fn main() -> () { println(int_to_string(clock_now_ms(0) * 0)); }

The compiled module's imports are wasi_snapshot_preview1.fd_write, wasi_snapshot_preview1.clock_time_get and env.clock_now_ms. The call itself is lowered to WASI clock_time_get, so the env import is unused. bun run then fails with import env:clock_now_ms must be an object. Re-verified on main-based build 161eaaf; the same happens on main without PR #841.

Fix: when an extern is lowered by a WASI intrinsic arm, do not also emit it as an env import. Check the same for the other WASI-lowered externs (env_*, arg_*, file_*, net_*).


Generated by Claude Code

Activity

  1. whatproblem-ai commented on Dec 1, 2026

    @whatproblem-ai

    Problem: When an extern such as clock_now_ms is lowered to a WASI intrinsic (clock_time_get), core wasm codegen also emits it as an env import. In the repro, env.clock_now_ms is emitted but never used. A WASI-only host cannot satisfy that import, so instantiation fails (bun run: import env:clock_now_ms must be an object). Seen on 161eaaf and on main without PR #841.

    Expected: Externs lowered by a WASI intrinsic arm emit no env import. The same holds for the env_*, arg_*, file_* and net_* externs.

    Missing: exact compile command/target flags


    Clarity: 92%. Clear enough to work on.

    ⌨️ Commands · 💬 Have feedback? Tell us · 🎯 New here? Add WhatProblem to your repo · 🔒 Privacy

  2. added
    architecture
    bindings
    enhancement
    on Dec 1, 2026
  3. added
    bug
    priority:p2
    scope:repo
    status:ready
    on Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    architecturebindingsbugenhancementpriority:p2scope:repostatus:ready

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions