Skip to content

fix(runtime): iterate built-in atom map keys in BEAM order - #104

Merged
mremond merged 1 commit into
mainfrom
infinitary-batch/19b502f7
Dec 2, 2026
Merged

mremond merged 1 commit into
mainfrom
infinitary-batch/19b502f7

Conversation

@mremond

@mremond mremond commented Dec 2, 2026

Copy link
Copy Markdown
Member

Why

Programs compiled by Nera listed a map's true key before its false key, while BEAM, the standard Erlang runtime, lists false first, so their output differed.

What changed

  • People will notice: maps of up to 32 keys now list false before true, as BEAM does, wherever a program walks, prints or encodes them
  • The same now holds for 30 more names that exist before any program runs, such as error before ok
  • All other keys keep their previous order, which can still differ from BEAM

Before and after

Before: `maps:keys(#{true => 1, false => 2})` returned `[true, false]` in a compiled program, and all 16 lines of a probe that walks such maps differed from Erlang/OTP 29.

After: It returns `[false, true]`, and the same probe prints 16 of 16 lines identical to Erlang/OTP 29.

The change shows only in the values and text that compiled programs produce, so there is no screen to picture.

Checked

  • The new test, run on Nera, on Nera with a single scheduler thread, and on Erlang/OTP 29: Passed 10 of 10 times on each
  • Each of the test's 26 comparisons on the compiler without the fix: All 26 fail there; all pass with the fix and on Erlang/OTP 29
  • The test on Erlang/OTP 29 with two of its names replaced by made-up ones: Fails as it should, so the Erlang/OTP run really checks the order
  • Build, lint, 2,303 Rust tests and 556 end-to-end tests, run locally: All pass; 2 end-to-end tests are skipped because they need modules outside the project
  • Comparisons of the Cowlib and Thoas libraries between Erlang/OTP 29 and Nera: 122 Cowlib and 80 Thoas cases agree; the Cowlib demo keeps only its two known differences
  • Independent review of the change: Found no defect in the code; its points on wording and test strength 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

./target/release/nera test map_builtin_atom_order -j 1 --timeout 30 (ten times, and ten times with NERA_SCHEDULERS=1)

erlc tests/map_builtin_atom_order.erl && erl -noshell -eval 'map_builtin_atom_order:test(), halt().' (ten times on Erlang/OTP 29.1.2, plus embedded mode and other start options)

python3 tests/integration/cowlib/runner.py, python3 tests/integration/thoas/differential/runner.py and python3 scripts/test-cowlib-demo.py

Risk

Risk above low: Blast radius, medium — Every walk of a small map goes through the changed key comparison

Full risk assessment
Dimension Level Why
Blast radius medium Every walk of a small map goes through the changed key comparison
Behavior low Corrects a defect: only maps holding two or more built-in atom keys change order
Undo low Reverting the commit restores the previous order; no data or settings move
Evidence low Shown end to end on Nera and on BEAM, with the full suite and library comparisons
Sensitivity low No sign-ins, keys, saved data or release steps are touched
Novelty low A small rank table added to the existing map key sort
Dependencies low No package added or updated
Not done

Keys that are not among the names Nera creates at startup keep their previous order, which can differ from BEAM. BEAM also places some of its own names, such as timeout, between the ones fixed here.

Messages logged through error_logger print maps with a separate printer that this change does not touch. That defect is recorded separately.

The hosted checks have not run on this version: they start only on pull requests, and this change joins a shared pull request once approved.

People will notice: maps of up to 32 keys now list false before true, as BEAM does, wherever a program walks, prints or encodes them

The same now holds for 30 more names that exist before any program runs, such as error before ok

All other keys keep their previous order, which can still differ from BEAM
@github-actions github-actions Bot added this to the 0.1.1 milestone Dec 2, 2026
@mremond
mremond merged commit a7ea70b into main Dec 2, 2026
22 checks passed
@mremond
mremond deleted the infinitary-batch/19b502f7 branch December 2, 2026 22:27
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