self-host: Int.div + float-literal interpolation lexing + replay Unit normalization#437
Merged
Conversation
…ation
Two self-host interpreter gaps surfaced by a VM-vs-self-host corpus audit:
- Int.div was missing from the interpreter's builtin registry (callInt
dispatch + isBuiltinCallName), so any program using the 0.24 Int.div
idiom hit 'unknown int builtin: Int.div'. Add builtinIntDiv, delegating
to the real Int.div so it inherits full partiality (division by zero +
overflow) and the canonical error strings.
- Float literals inside string interpolation ('{1.5}') lexed as TkInt
then choked on the '.' — tokenizeInterpDigit always emitted TkInt and
never checked for a decimal point. Mirror the main-path float handling
(tokenizeAfterInt et al.) with interpolation-aware variants.
Non-interactive example corpus VM-vs-self-host parity: 17/25 -> 21/25.
Regenerated src/self_host/ via aver compile --target rust.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The VM and wasm-gc replay formats serialize a Unit return as JSON null; the rust/self-host backend wrapped it as a ValUnit variant object, so a recording made by one backend spuriously failed to replay on the self-host (output mismatch -> panic) for any Unit-returning main — i.e. almost every program. The --with-replay codegen now canonicalizes the ValUnit variant back to null at the record and replay serialization points, so recordings replay cleanly across VM / wasm-gc / self-host. A 0.23-recorded wumpus game session (116 effects) now replays MATCH on the self-host, matching VM and wasm-gc. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The self-host regen step runs 'cargo fmt' (not --all), which doesn't descend into the aver_self_host_cli bin's generated modules; one long line in eval/core slipped past. Run fmt --all so 'cargo fmt --all --check' is clean in CI. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
A VM-vs-self-host parity audit during 0.24 prep found the self-hosted interpreter lagged the other backends. This PR closes the three tractable gaps; the two larger ones (higher-order functions, multi-module type resolution) are tracked in #436.
Int.div on self-host
The interpreter's builtin registry knew
Int.modbut notInt.div, so any program using the 0.24Int.dividiom hitunknown int builtin: Int.div. AddedbuiltinIntDiv, delegating to the realInt.divso it inherits full partiality (division by zero + overflow) and the canonical error strings.Float literals in string interpolation
"{1.5}"lexed asTkIntthen choked on the.— the interpolation lexer (tokenizeInterpDigit) always emitted an int and never checked for a decimal point. Mirrored the main-path float handling with interpolation-aware variants. (Float literals outside interpolation already worked.)Replay Unit normalization (all rust/self-host targets)
The VM and wasm-gc replay formats serialize a Unit return as JSON
null; the rust/self-host backend wrapped it as aValUnitvariant object, so a recording made by one backend spuriously failed to replay on the self-host (mismatch → panic) for any Unit-returningmain. The--with-replaycodegen now canonicalizesValUnitback tonullat the record/replay serialization points.Result
aver runvsaver run --self-host: 17/25 → 21/25 parity (remaining 4 are the multi-module/refinement cases in self-host parity: higher-order functions + multi-module type resolution #436).src/self_host/regenerated viaaver compile --target rust.🤖 Generated with Claude Code