Skip to content

fix(runtime): compare closures by code and captured values - #49

Merged
mremond merged 2 commits into
mainfrom
fm/task-7cce240c
Nov 15, 2026
Merged

mremond merged 2 commits into
mainfrom
fm/task-7cce240c

Conversation

@mremond

@mremond mremond commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Why

Closures from the same fun expression with equal captured values should compare equal and work as interchangeable keys, as on BEAM.

What changed

  • Closures compare by their code, arity and captured values instead of allocation addresses.
  • Equivalent closures work as process dictionary, map and ETS keys, including copied and nested captures.
  • Numeric and exact capture comparisons retain their distinct Erlang semantics.

Before and after

Before: Two separately created equal closures compared unequal under both operators and missed lookups in all three key stores.

After: Both comparisons now return true, and all three key stores find the equivalent closure, matching BEAM.

This changes Erlang runtime behavior, not a visual interface; native and BEAM execution transcripts demonstrate the result.

Checked

Live validation: Demonstrated for this version. 2 of 2 scenarios driven live in the product.

Scenario Result Evidence
Closure equality on native and BEAM ✅ Passed live Ten consecutive executions per mode on native-default, native-single and OTP 29.1.2 passed with explicit completion and checked return.
Interchangeable closure keys ✅ Passed live The same fixture verified dictionary, map and four ETS table types; native and BEAM product probes matched.
  • Release build, strict workspace lint and independent review: All passed; independent review confirmed that bringing the branch up to date preserved the approved behavior.
  • Rust workspace suite: 2,187 passed, zero failed, one ignored.
  • Full native Erlang suite: 497 passed, zero failed; two external OneCached fixtures skipped.
  • Allocator configuration regression: Default options and user override passed.
  • Uncaught stacktrace-order regression: Expected frames and order passed.
How it was checked

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

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

Risk

Risk above low: Blast radius, medium — Shared term comparison and compound ETS key encoding change.

Full risk assessment
Dimension Level Why
Blast radius medium Shared term comparison and compound ETS key encoding change.
Behavior low Corrects closure equality and equivalent-key lookups to match BEAM.
Undo low A revert restores behavior; key encoding is only in-memory.
Evidence low Native and BEAM journeys, thirty fixture runs and the complete combined local gate passed.
Sensitivity low No sign-ins, keys, payments or persistent user data are changed.
Novelty low Extends existing comparison and canonical key traversal.
Dependencies low No dependencies added or changed.
Not done

Windows execution and BEAM-compatible fun hashes are not established by this change.

Pipeline

Updates from git push no-mistakes

Infinitary checked this version: an independent review that also judged the documents, and live validation the review accepted.

@github-actions github-actions Bot added this to the 0.1.1 milestone Nov 14, 2026
@mremond
mremond merged commit 5201c70 into main Nov 15, 2026
21 checks passed
@mremond
mremond deleted the fm/task-7cce240c branch November 15, 2026 14:04
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