Repository navigation
Make pure WASM lowering total over the alphabet - #47
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Reproduced your measurement exactly. Before either PR, of the 26 single-letter programs, 16 lowered (the 13 you listed, plus
candgwhich lower givenio.read/io.write, pluse), and these 10 raisedNotImplementedError: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_nodeends inlift(0),BytecodeVM._apply_operationfalls 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 existingPURE_CONST_VALUESconstant 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":
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_instrasserts 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 intest_tir_to_wat_errors_and_exportthat expectedNotImplementedErrornow asserts the default lowering.🤖 Generated with Claude Code
https://claude.ai/code/session_01K7BqQpyspK2owRy6g6SFxw
Generated by Claude Code