fix(runtime+codegen): #1002 — native util.format / util.formatWithOptions#1011
Merged
Conversation
…ions The manifest entries for `util.format` and `util.formatWithOptions` lifted the #463 gate but no native runtime was wired up. Both calls fell through the receiver-less native-method-call early-out in `lower_call/native.rs` and returned `TAG_UNDEFINED` — `console.log(util.format("hi %s", "x"))` printed `undefined`, and `test_util_format_with_options` had been the parity gate's lone NEW failure since #948 added the manifest entry. Three small pieces: - runtime/builtins.rs: new `js_util_format(arr_ptr)` walks a heap array whose element 0 is the format string and 1.. are substitution values. Handles `%s` / `%d` / `%i` / `%f` / `%j` / `%o` / `%O` / `%%` and appends any trailing args space-separated — same shape as Node's `util.format`. - codegen/runtime_decls.rs: declare the extern. - codegen/lower_call/native.rs: ahead of the receiver-less fall-through, recognize `util.format` / `util.formatWithOptions`, bundle the args into a heap array (mirrors `js_console_log_spread`), and dispatch. `formatWithOptions` drops `args[0]` (the inspect-options bag) and delegates to the same runtime — full options-passthrough (real `%o`/`%O` styling with colors/depth/breakLength) is a follow-up. Validation: - `node test-files/test_util_format_with_options.ts` and the perry binary now produce the same output (`Hello world` + `x=k y=7`). - `scripts/run_native_no_fallback_tests.sh` — 35 passed, 0 failed (no regression on the broader smoke).
proggeramlug
added a commit
that referenced
this pull request
May 18, 2026
Both PRs were admin-merged with lint red. Land the trivial fmt cleanup so subsequent PRs don't inherit the lint failure on top of their own diffs.
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.
Closes #1002.
Summary
#948 added
util.format/util.formatWithOptionsto the API manifest(lifting the #463 gate) but never wired a native runtime. Both calls
fell through the receiver-less native-method-call early-out in
lower_call/native.rsand returnedTAG_UNDEFINED:test_util_format_with_optionshas been the loneNEW FAILURESentry onthe parity gate since #948 landed — admin-bypassed on #944, #947, #958,
#997, #1000, #1003, #1004, #1009.
Fix
Three small pieces:
crates/perry-runtime/src/builtins.rs— newjs_util_format(arr_ptr) -> f64. Walks an array whose element 0 isthe format string and 1.. are substitution values. Handles
%s/%d/%i/%f/%j/%o/%O/%%and appendsany trailing args space-separated. Falls back to a space-joined
format_jsvaluewhen the first arg isn't a string (same shape asNode's util.format).
crates/perry-codegen/src/runtime_decls.rs— declare theextern.
crates/perry-codegen/src/lower_call/native.rs— ahead of thereceiver-less fall-through, recognize
util.format/util.formatWithOptionsand bundle the call args into a heap array(mirrors
js_console_log_spread), then dispatch.formatWithOptionsdropsargs[0](theutil.inspectoptionsbag) and delegates to the same runtime — full options-passthrough
(real
%o/%Ostyling withcolors,depth,breakLength, …)is a follow-up.
Test plan
cargo build --release -p perry-runtime -p perry-stdlib -p perry ./target/release/perry test-files/test_util_format_with_options.ts -o /tmp/p && /tmp/p node --experimental-strip-types test-files/test_util_format_with_options.tsundefined\nundefined.Hello world\nx=k y=7— exact parity withnode --experimental-strip-types.scripts/run_native_no_fallback_tests.sh— 35 passed, 0 failed (no regression on the broader smoke).