Skip to content

Make pure WASM lowering total over the alphabet - #47

Merged
seanwevans merged 1 commit into
claude/wasm-e-zero-borrowsfrom
claude/wasm-total-lowering
Sep 3, 2026
Merged

seanwevans merged 1 commit into
claude/wasm-e-zero-borrowsfrom
claude/wasm-total-lowering

Conversation

@seanwevans

Copy link
Copy Markdown
Owner

Stacked on #46. Base is claude/wasm-e-zero-borrows, since both touch the pure-op lowering block. Merge #46 first and this retargets to main cleanly.

Problem

Reproduced your measurement exactly. Before either PR, of the 26 single-letter programs, 16 lowered (the 13 you listed, plus c and g which lower given io.read/io.write, plus e), and these 10 raised NotImplementedError:

i k r t u v w x y z

All 10 are pure-grade with no rule, because the pure-op table was the literal {"A": 1, "D": 2, "F": 5} and everything else fell off the end into a raise.

Change

Pure ops with no rule of their own now lower to PURE_DEFAULT_VALUE (0).

This is not an invented semantics — both interpreters already return 0 for an opcode they have no rule for (analysis.evaluate_node ends in lift(0), BytecodeVM._apply_operation falls back to 0), so the WASM backend now agrees with them instead of refusing. Same principle as #46.

The inline {"A": 1, "D": 2, "F": 5} literal is replaced by the existing PURE_CONST_VALUES constant it was duplicating.

Result: 26/26 single-letter programs lower, and no pure opcode can raise NotImplementedError.

One boundary deliberately left in place

Sweeping all 676 two-letter programs surfaces 20 remaining failures — all of the form "a pure or IO instruction borrows a value produced by a state/sys/meta instruction":

be he je le me ne oe pe qe se   ValueError: Unknown borrow target ... for op E
bg hg jg lg mg ng og pg qg sg   ValueError: IO operation G argument ... depends on B [state],
                                            which cannot be lowered to WebAssembly

I did not make these total. WebAssembly cannot compute those values, and substituting a placeholder would be a silent semantic lie rather than a lowering. The repo already treats this as deliberate — test_tir_to_wat_rejects_io_args_from_non_lowered_instr asserts the refusal. A new test now pins it as an explicit choice rather than an unexamined gap.

Closing it properly means lowering state ops to WASM memory, which is a design change rather than a table fix. Happy to take that on separately if you want it.

Tests

Parametrised over all 26 letters, plus checks that undefined pure ops agree with the bytecode VM, that the named constants keep their values, and that the cross-grade boundary still refuses. The pure_instr.op = "Z" assertion in test_tir_to_wat_errors_and_export that expected NotImplementedError now asserts the default lowering.

🤖 Generated with Claude Code

https://claude.ai/code/session_01K7BqQpyspK2owRy6g6SFxw


Generated by Claude Code

Only 16 of the 26 single-letter programs lowered; i, k, r, t, u, v, w, x, y
and z raised NotImplementedError, because the pure-op table was the literal
{"A": 1, "D": 2, "F": 5} and everything else fell off the end.

Pure ops with no rule of their own now lower to PURE_DEFAULT_VALUE. This is
not an invented semantics: both interpreters already return 0 for an opcode
they have no rule for — analysis.evaluate_node ends in lift(0) and
BytecodeVM._apply_operation falls back to 0 — so the WASM backend now agrees
with them instead of refusing. The inline literal is replaced by the
existing PURE_CONST_VALUES constant it was duplicating.

All 26 single-letter programs lower, and no pure opcode can raise
NotImplementedError.

One boundary is deliberately left in place: a pure or IO instruction that
borrows a value produced by a state/sys/meta instruction still raises,
because WebAssembly cannot compute that value and substituting a placeholder
would be a silent semantic lie rather than a lowering. That refusal already
had a test asserting it; a further test now pins it as an explicit choice
rather than a gap.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K7BqQpyspK2owRy6g6SFxw
@seanwevans
seanwevans merged commit 7b27b8b into claude/wasm-e-zero-borrows Sep 3, 2026
2 checks passed
@seanwevans
seanwevans deleted the claude/wasm-total-lowering branch September 3, 2026 17:58
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