Repository navigation
fix(runtime): write printable lists as strings under ~p and ~tp - #112
Merged
Merged
Conversation
~p and ~tp print a list as a double-quoted string whenever BEAM does, with newline, tab and the other control escapes written as BEAM writes them. Strings inside lists, tuples and maps print as strings too. Lists BEAM keeps numeric, such as [7], [127] or [8364], and every list under ~lp and ~w, print as before.
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.
Why
Native io:format and io_lib:format printed every list as integers under ~p, so "abc" read [97,98,99] and "hi\n" read [104,105,10], where BEAM prints the strings.
What changed
Before and after
Before: On the previous main, 61 of 101 lines of a ~p/~tp probe differed from BEAM, because every printable list printed as integers.
After: All 101 probe lines, covering ~p, ~tp, ~lp, ~w and io_lib:format, match BEAM OTP 29 byte for byte.
Native stdout of io:format("~p~n", [L]) for seven lists
Checked
How it was checked
cargo build --release --locked
cargo clippy --workspace --all-targets --locked -- -D warnings
cargo test --workspace --locked --no-fail-fast
python3 scripts/test-allocator-config.py
./target/release/nera test -j 1 --timeout 30
python3 scripts/test-stacktrace-order.py
A 49-case probe under ~p and ~tp plus ~lp, ~w and io_lib:format controls, built natively and run on BEAM OTP 29, compared byte for byte
Risk
Risk: low in every dimension.
Full risk assessment
Not done
CI has not run on this branch, which has no pull request of its own; it runs on the combined pull request that carries this change, before anything merges.
~P still prints printable lists as integers.
~p still does not wrap long terms at the line width as BEAM does.
When stdout is not UTF-8, BEAM writes codes 160 to 255 as single bytes while Nera writes UTF-8, as it already did for binaries.