Skip to content

fix(runtime): write printable lists as strings under ~p and ~tp - #112

Merged
mremond merged 1 commit into
mainfrom
infinitary-batch/58bf63d7
Dec 5, 2026
Merged

mremond merged 1 commit into
mainfrom
infinitary-batch/58bf63d7

Conversation

@mremond

@mremond mremond commented Dec 5, 2026

Copy link
Copy Markdown
Member

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

  • ~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.

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

BeforeAfter

Native stdout prints [97,98,99], [9,10], [104,105,10], [7], a tab-containing list, a nested list and a tuple's list all as integers.

Native stdout prints "abc", "\t\n", "hi\n", [7], "tab\there", ["abc","def"] and {ok,"line\n"}, matching BEAM.

Checked

  • Full local gate before the rebase onto the parser-only main commit: Release build, clippy with warnings denied, 2,306 Rust tests (1 ignored), allocator check, 563 Erlang tests (2 expected skips) and the stacktrace order check passed.
  • After the rebase: Release build, the nine io_* end-to-end tests and the BEAM parity probe passed again.
  • New io_format_printable_list test: Fails on the previous main at its first assertion; passes unchanged on BEAM and in 10 of 10 native runs.
  • Edited Rust test format_term_printable_binary: Fails when the quote escape is broken; passes in 10 of 10 runs with the code restored.
  • Independent code review: No blocking issues; its two documentation wording points are fixed.
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
Dimension Level Why
Blast radius low Only the ~p and ~tp term writer in the runtime changes.
Behavior low Corrects ~p output to match BEAM; values themselves are unchanged.
Undo low Reverting restores numeric list output; no data is rewritten.
Evidence low Native output matches BEAM byte for byte across a 101-line probe.
Sensitivity low Display formatting only; no saved data, keys or services.
Novelty low Extends the existing term writer and shares its binary escape rule.
Dependencies low No dependencies added or updated.
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.

~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.
@mremond
mremond merged commit dd3c80c into main Dec 5, 2026
21 checks passed
@mremond
mremond deleted the infinitary-batch/58bf63d7 branch December 5, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant