Skip to content

Wasm: non-ambigous closure env type names#2246

Merged
vouillon merged 1 commit into
masterfrom
env-types
May 22, 2026
Merged

Wasm: non-ambigous closure env type names#2246
vouillon merged 1 commit into
masterfrom
env-types

Conversation

@vouillon
Copy link
Copy Markdown
Member

The no_code_pointer optimisation gives some closures a different env type body (no supertype, no function-ref field). At the registration sites, arity was normalised to 0 for these closures, so they registered as cps_env_0_<id> / env_0_<id>. That was not sufficient, though: a genuine arity-0 closure with a code pointer registers the very same name with an incompatible (with-supertype, function-ref-bearing) body. The two clashed — the first one to register won, and the loser emitted a struct.new inconsistent with the recorded type.

I don't have a reproducer on master, but the issue occurs both with loop hoisting (#2245) and WASI (#1831) .

The [no_code_pointer] optimisation gives some closures a different
env type body (no supertype, no function-ref field). At the
registration sites, [arity] was normalised to 0 for these closures,
so they registered as [cps_env_0_<id>] / [env_0_<id>]. That was not
sufficient, though: a genuine arity-0 closure with a code pointer
registers the very same name with an incompatible (with-supertype,
function-ref-bearing) body. The two clashed — the first one to
register won, and the loser emitted a [struct.new] inconsistent
with the recorded type.

Loop hoisting and CPS-mode effect handlers are two natural sources
of arity-0 closures, making the collision easy to trigger.

Drop the arity from the type name when there is no code pointer
(arity is implicit in that case, since the struct has no function-ref
field). The [arity = 0] normalisation is then redundant in
[Closure.bind_environment]; in [Closure.translate] the same applies,
with [need_curry_fun] guarded directly on [no_code_pointer] so no
unused curry function is emitted.
@vouillon vouillon merged commit 744f92f into master May 22, 2026
33 of 34 checks passed
@vouillon vouillon deleted the env-types branch May 22, 2026 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant