Skip to content

fix(runtime): write printable lists as strings under ~P and ~tP - #113

Merged
mremond merged 1 commit into
mainfrom
infinitary-batch/76784f8c
Dec 6, 2026
Merged

mremond merged 1 commit into
mainfrom
infinitary-batch/76784f8c

Conversation

@mremond

@mremond mremond commented Dec 6, 2026

Copy link
Copy Markdown
Member

Why

Natively, io:format("~P", ["hi\n", 5]) printed [104,105,10], where BEAM prints "hi\n". The depth-limited ~P writer never wrote a list as a string, even after ~p learned to.

What changed

  • ~P and ~tP print a printable Latin-1 list as a double-quoted string, using the same rule ~p uses.
  • The string prints whole however little depth remains; at depth 1 a list still prints as [...].
  • Lists inside lists, tuples and maps are judged at the depth where each one is written.
  • ~lP and ~W keep lists numeric, as on BEAM.

Before and after

Before: On the previous main, 23 of 52 lines of a ~P probe differed from BEAM OTP 29, because every printable list printed as integers.

After: All 52 probe lines, covering ~P, ~tP, ~lP and ~W at several depths, match BEAM OTP 29 byte for byte.

Native output of io_lib:format for seven ~P and ~lP calls

BeforeAfter

Native output before the change: "hi\n" at depth 5 prints [104,105,10], "abc" at depth 2 prints [97|...], and nested strings print as integer lists

Native output after the change: "hi\n", "abc", ["abc","def"] and #{1 => "ab"} print as strings, while depth 1 still prints [...] and ~lP still prints [97,98,99]

Checked

  • Full local gate (release build, clippy with warnings denied, workspace tests, allocator check, Erlang suite, stacktrace order check): All passed: 2,306 Rust tests with 1 ignored, and 565 Erlang tests with 2 expected skips
  • Final version with comment and doc fixes: Release build, clippy, the ten io_* end-to-end tests and the BEAM parity probe passed again
  • New io_format_depth_printable_list test: Fails on the previous main at its first assertion; passes unchanged on BEAM and in 10 of 10 native runs, with identical stdout
  • Test with ~lP forced to write strings: Fails at its ~lP assertion, so the l modifier is covered
  • Independent code review: Found nothing blocking; I fixed its comment and documentation points
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 ~P, ~tP, ~lP and ~W probe, 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 depth-limited term writer behind ~P and ~W changes
Behavior low Corrects ~P output to match BEAM; ~W, ~lP and depth-1 output are unchanged
Undo low Revert the commits; no data or settings change
Evidence low Native output matches BEAM byte for byte on a 52-line probe and a new test
Sensitivity low Touches only text formatting
Novelty low Reuses the existing printable-list helper inside the existing writer
Dependencies low No dependencies added or updated
Not done

~P and ~tP still write printable binaries as numbers; BEAM writes <<"abc">>, and under ~P only the first 4 characters per remaining depth level. This is already listed in the known limits.

~p and ~P still do not wrap long terms at the line width as BEAM does. The known limits now name ~P too.

~P and ~tP print a printable Latin-1 list as a double-quoted string, using the same rule ~p uses.

The string prints whole however little depth remains; at depth 1 a list still prints as [...].

Lists inside lists, tuples and maps are judged at the depth where each one is written.

~lP and ~W keep lists numeric, as on BEAM.
@mremond
mremond merged commit 30b8133 into main Dec 6, 2026
21 checks passed
@mremond
mremond deleted the infinitary-batch/76784f8c branch December 6, 2026 21:48
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