Skip to content

fix(ir): record the throw call's line in its stack frame - #93

Merged
mremond merged 1 commit into
mainfrom
infinitary-batch/be8fdb5f
Nov 26, 2026
Merged

mremond merged 1 commit into
mainfrom
infinitary-batch/be8fdb5f

Conversation

@mremond

@mremond mremond commented Nov 26, 2026

Copy link
Copy Markdown
Member

Why

When a program used throw/1, the error details pointed at line 0, or at the wrong line, instead of the line holding the throw. BEAM and Nera's own error/1 point at the right line.

What changed

  • People debugging a Nera program now see the real line of a throw: in a caught stacktrace, in the exit reason a monitor or link receives, and in the crash message printed when a process dies.
  • A new test checks this in compiled Nera programs and runs unchanged on BEAM.

Before and after

Before: With throw/1 on line 5 and a throw after another call on line 9, Nera reported lines 0 and 8, while BEAM OTP 29 reported 5 and 9.

After: The same program reports lines 5 and 9, matching BEAM, and the crash message prints line 5.

Nothing on a screen changes: the fix shows in error details and crash messages, which the checks below record as text.

Checked

  • A small test program run with Nera before and after the change, and on BEAM OTP 29: Before: lines 0, 6, 8 and 0 for the uncaught throw. After, and on BEAM: lines 5, 6, 9 and 5.
  • The new test against the unchanged compiler: It fails with {badmatch,{line,0}}; run case by case, every throw case fails except the erlang:throw/1 control, and the error/1 control passes.
  • The new test, repeated: 10 of 10 passes with the default scheduler count, 10 of 10 with one scheduler, and 10 of 10 on BEAM OTP 29.
  • Full local check run: Release builds, lint with warnings denied, 2,263 Rust tests, the allocator check, 549 of 551 end-to-end tests (2 skipped for missing external modules) and the stacktrace-order check pass.
  • Independent review of the change: No correctness problem found; its correction to the changelog's description of the old behavior is applied.
How it was checked

cargo build --release --locked -p nera-runtime && cargo build --release --locked -p nera

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 throw_stacktrace_line (10 runs, and 10 with NERA_SCHEDULERS=1)

erlc tests/throw_stacktrace_line.erl && erl -noshell -eval 'ok = throw_stacktrace_line:test(), halt().' (10 runs, OTP 29)

Risk

Risk: low in every dimension.

Full risk assessment
Dimension Level Why
Blast radius low One lowering function for throw/1 gains a line update before the raise.
Behavior low Corrects the line number in throw error details; nothing else changes.
Undo low Revert the commit.
Evidence low Shown end to end natively and on BEAM, plus the full local check run.
Sensitivity low No saved data, settings, sign-ins or releases.
Novelty low Reuses the same line update other raises and calls already emit.
Dependencies low No dependency changes.
Not done

Three related defects seen on the way are tracked separately: inline runtime errors such as badarith can name a stale line, a tail-call apply of a raising function drops the caller's frame, and fun erlang:throw/1 does not compile.

People debugging a Nera program now see the real line of a throw: in a caught stacktrace, in the exit reason a monitor or link receives, and in the crash message printed when a process dies.

A new test checks this in compiled Nera programs and runs unchanged on BEAM.
@github-actions github-actions Bot added this to the 0.1.1 milestone Nov 26, 2026
@mremond
mremond merged commit 4d48c9b into main Nov 26, 2026
22 checks passed
@mremond
mremond deleted the infinitary-batch/be8fdb5f branch November 26, 2026 14:55
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