wasm: make integer/string builtins available to the -os browser target - #27517
Merged
medvednikov merged 1 commit intoJun 21, 2026
Merged
Conversation
`int.str()` (and the other int→string helpers), the `min_int`/`max_int` builtin
constants, and `tos()` live in `int_notd_no_imports.v` /
`string_notd_no_imports.v`, which were only compiled for `-os wasi`. So on
`-os browser`, `println(int)`, `'${int}'` interpolation, integer concatenation,
and `min_int`/`max_int` all failed (checker: "does not have a .str() function" /
"undefined ident: max_int"; or at the encoder, "called function int.str does
not exist").
These helpers are pure (no imports, no wasi/JS-specific calls), so move them
from `vlib/builtin/wasm/wasi/` to the shared `vlib/builtin/wasm/` dir; both
browser and wasi builds pick them up. No symbol conflicts — neither the browser
nor the wasi builtin defines `tos` or `int.str`. Follow-up to vlang#27450 (which
fixed the browser `eprintln` panic).
Adds vlib/v/gen/wasm/tests/browser_int_builtins_test.v.
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.
Description
On the
-os browserwasm target, anything that needs integer→string conversion fails to compile:(and a program that gets past the checker hits the encoder panic
called function int.str does not exist.)Root cause
int.str()and the other int→string helpers, themin_int/max_intbuiltin constants, andtos()are defined in:vlib/builtin/wasm/wasi/int_notd_no_imports.vvlib/builtin/wasm/wasi/string_notd_no_imports.vvlib/v/builder/compile.vonly adds thewasm/wasi/builtin dir for-os wasi; for-os browserit addswasm/browser/, which providesprintln(string)/panic/eprintlnbut no integer formatting. So integers can't be printed on browser.Fix
Both files are pure (no
import, no wasi/JS-specific calls —tosjust wrapsstring{str, len}, the int helpers are arithmetic over adigit_pairsconst). Move them fromvlib/builtin/wasm/wasi/to the sharedvlib/builtin/wasm/dir so both browser and wasi builds compile them.No symbol conflicts: neither the browser nor the wasi
builtin_notd_no_imports.v, nor the sharedstring.v/builtin.v, definestosorint.str.This is a follow-up to #27450 (which fixed the
-os browsereprintlnpanic).After
-os wasiis unaffected (it picks the same files up from the shared dir now); the fullvlib/v/gen/wasm/tests/suite passes.Tests
Adds
vlib/v/gen/wasm/tests/browser_int_builtins_test.v(compiles a browser program usingprintln(int),int.str(), integer concat, andmin_int/max_int).Checklist
v test vlib/v/gen/wasm/tests/passes-os wasiregression-checkedv fmt -wapplied