Skip to content

Lynx vs AtomVM - #2473

Draft
petermm wants to merge 219 commits into
atomvm:release-0.7from
petermm:lynx_atomvm
Draft

petermm wants to merge 219 commits into
atomvm:release-0.7from
petermm:lynx_atomvm

Conversation

@petermm

@petermm petermm commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Leveraging https://github.com/josevalim/lynx with AtomVM - fixing findings on the way, lots of small subtleties found and fixed.

Still early, only one that stands out it perhaps the support for legacy stacktraces, which should maybe be backed out.

All clanker driven.

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

Comment thread src/libAtomVM/context.c Fixed
@petermm
petermm marked this pull request as draft November 9, 2026 21:52
@petermm
petermm force-pushed the lynx_atomvm branch 20 times, most recently from e740cd2 to 42373e4 Compare November 16, 2026 10:42
@petermm
petermm marked this pull request as ready for review November 16, 2026 11:15
@petermm
petermm marked this pull request as draft November 16, 2026 11:46
@petermm

petermm commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Executive summary: I suggest cherry picking from this PR branch..

Lynx / AtomVM: executive fix and cherry-pick summary

Tier 1 — best first cherry-pick candidates

  1. Reject already-registered processes in erlang:register/2.
    Runtime -1 (+4/-5); total +9 (+14/-5). Impact: medium; risk: low.
    Checks whether the target PID/port is already registered in addition to checking
    the name atom, raising badarg instead of registering extra names.
    (Added after the Nov 12 flash snapshot.)

  2. Preserve the first operand in min/2 and max/2 ties.
    Runtime 0 (+2/-2); total +25 (+27/-2). Impact: medium; risk: low.
    Preserves integer/float identity and signed zero on ties instead of returning
    the second operand. Local change to the tie decision.
    Flash Δ (payload / image): ESP32 0 / 0 B; C3 0 / 0 B; AVM 0 B.

  3. Return [] from lists:seq/3 for empty non-unit-step ranges.
    Runtime 0 (+1/-1); total +14 (+15/-1). Impact: medium; risk: low.
    Avoids returning [From] when abs(Incr) > 1 within valid empty bounds
    (To < From for positive steps or To > From for negative steps).
    (Added after the Nov 12 flash snapshot.)

  4. Reject invalid make_fun/3 arities.
    Runtime 0 (+1/-1); total +36 (+37/-1). Impact: medium; risk: low.
    Restricts arity to 0–255 rather than accepting arbitrary integers. The separate
    dynamic arity-check fix (item 16) concerns a different execution path, but this
    commit's tests exercise both: include item 16 if the destination lacks that JIT fix.
    Flash Δ (payload / image): ESP32 +8 / +16 B; C3 +2 / 0 B; AVM 0 B.

  5. Fail binary patterns for non-integer segment sizes.
    Runtime 0 (+4/-4); total +18 (+22/-4). Impact: medium; risk: low.
    Interpreter matching follows the pattern-failure label instead of raising
    badarg. This is a match-versus-construction distinction, not relaxed validation.
    Flash Δ (payload / image): ESP32 +4 / +16 B; C3 +74 / +64 B; AVM 0 B.

  6. Reject non-PIDs in is_process_alive/1.
    Runtime +1 (+1/-0); total +15 (+15/-0). Impact: medium; risk: low.
    Validates the argument before extracting a process ID. A particularly small,
    self-contained public BIF contract fix.
    Flash Δ (payload / image): ESP32 +48 / +48 B; C3 +38 / +32 B; AVM 0 B.

  7. Validate every repeated binary-match scope.
    Runtime +1 (+22/-21); total +16 (+37/-21). Impact: medium; risk: low.
    An invalid earlier scope can no longer be hidden by a valid later option.
    Net growth is tiny, but the option-parser movement is visible in the churn.
    Flash Δ (payload / image): ESP32 0 / 0 B; C3 +24 / +16 B; AVM 0 B.

  8. Keep polling state alive during shutdown callbacks.
    Runtime +2 (+4/-2); total +43 (+45/-2). Impact: high, memory safety;
    risk: localized lifecycle change. Destroys contexts and runs resource-down
    callbacks before freeing platform polling state, avoiding callbacks unregistering
    select events through freed state. Includes an armed-select shutdown regression.
    Flash Δ (payload / image): ESP32 0 / 0 B; C3 0 / 0 B; AVM 0 B.

  9. Reject embedded NULs in integer text.
    Runtime +2 (+3/-1); total +27 (+28/-1). Impact: medium; risk: low.
    Uses the full validated list length rather than strlen, so parsing cannot
    silently accept a numeric prefix before a NUL.
    Flash Δ (payload / image): ESP32 +4 / 0 B; C3 +6 / +16 B; AVM 0 B.

  10. Match OTP error reasons in json:decode/1.
    Runtime +3 (+18/-15); total +52 (+67/-15). Impact: medium; risk: low.
    Stops stripping trailing whitespace before {invalid_byte, 32}, maps default
    binary_to_float/1 overflow badarg to {unexpected_sequence, ...}, and
    raises unexpected_end on lone high surrogates (json.erl + test_json.erl).
    (Added after the Nov 12 flash snapshot.)

  11. Make link(self()) a no-op.
    Runtime +4 (+4/-0); total +55 (+55/-0). Impact: medium; risk: low.
    Avoids creating a spurious self-link and allocating link-monitor state.
    Review independently of the larger unlink/relink bundle.
    Flash Δ (payload / image): ESP32 +20 / +32 B; C3 +14 / +16 B; AVM 0 B.

  12. Validate 0-arity funs in spawn_link/1 and spawn_monitor/1.
    Runtime +4 (+8/-4); total +33 (+38/-5). Impact: medium; risk: low.
    Checks erlang:is_function(Function, 0) in erlang.erl so nonzero-arity or
    non-function arguments raise badarg in the caller like OTP, while leaving
    spawn/1 and spawn_opt/2 unchanged. (Added after the Nov 12 flash snapshot.)

  13. Raise undef for missing modules on Node.
    Runtime +5 (+5/-0); total +7 (+7/-0). Impact: high for Node users;
    risk: low and platform-local. Avoids aborting through unavailable
    XMLHttpRequest; browser loading behavior is unchanged.
    Flash Δ (payload / image): ESP32 0 / 0 B; C3 0 / 0 B; AVM 0 B.
    This changes Node-specific JavaScript, not either ESP32 firmware target.

Tier 2 — good fixes, but review shared semantics

  1. Order improper-list tails by ordinary term order.
    Runtime -8 (+0/-8); total +10 (+18/-8). Impact: high for comparison
    correctness. Removes the special treatment that put a nil tail below every
    other tail. Shared comparator behavior makes this more than a trivial deletion.
    Flash Δ (payload / image): ESP32 -32 / -32 B; C3 -24 / -32 B; AVM 0 B.

  2. Compare all map keys before map values.
    Runtime -1 (+15/-16); total +20 (+36/-16). Impact: high for map ordering.
    Prevents an early value difference overriding a later key difference;
    also handles consecutive key-scope markers in the comparison stack.
    Flash Δ (payload / image): ESP32 +468 / +464 B; C3 +388 / +384 B; AVM 0 B.

  3. Compare dynamic function arities at full width.
    Runtime +3 (+5/-2); total +3 (+5/-2). Impact: medium; JIT-specific.
    Clears unused C-integer result bits without truncating the queried arity.
    Review generated-code width handling; this commit has no standalone regression
    test addition. Reuse arity-boundary coverage from cbc125831.
    Flash Δ (payload / image): ESP32 0 / 0 B; C3 0 / 0 B; AVM 0 B.
    Zero here is profile-specific: this fix changes the disabled JIT compiler.

  4. Validate monitor target types before fast paths.
    Runtime +3 (+9/-6); total +97 (+103/-6). Impact: medium.
    Distinguishes process and port targets even for self/dead-target paths;
    a registered name of the wrong target type produces noproc as OTP does.
    Flash Δ (payload / image): ESP32 -4 / -16 B; C3 +6 / 0 B; AVM 0 B.

  5. Distinguish signed zero in exact comparison and map keys.
    Runtime +7 (+7/-0); total +61 (+61/-0). Impact: high for exact-key
    correctness. Aligns with OTP 27+ while retaining numeric equality for the
    non-exact comparison path. Review shared equality and ordering consumers.
    Flash Δ (payload / image): ESP32 +44 / +32 B; C3 +44 / +48 B; AVM 0 B.

  6. Honor float-match units and zero-width fields.
    Runtime +7 (+10/-3); total +34 (+39/-5). Impact: medium.
    Uses effective scaled width; zero-width matches return positive zero without
    advancing input. Changes interpreter matching and the JIT primitive.
    Flash Δ (payload / image): ESP32 +68 / +64 B; C3 +14 / +16 B; AVM 0 B.

  7. Dispatch arity-3 BIFs dynamically.
    Runtime +8 (+8/-0); total +25 (+25/-0). Impact: medium.
    Adds the missing arity-3 BIFFunctionType case in interpreter and JIT
    maybe_call_native so dynamic calls to erlang:is_integer/3 do not fall
    through to undef. (Added after the Nov 12 flash snapshot.)

  8. Deliver trapped exits when linking dead processes.
    Runtime +11 (+11/-0); total +47 (+47/-0). Impact: medium.
    With trap_exit, returns true and delivers an EXIT/noproc message
    instead of raising. Changes observable process-lifecycle semantics.
    Flash Δ (payload / image): ESP32 +96 / +96 B; C3 +74 / +80 B; AVM 0 B.

  9. Check binary_to_atom 255-char UTF-8 limit per code point.
    Runtime +14 (+24/-10); total +33 (+43/-10). Impact: medium.
    Raises system_limit (or badarg for binary_to_existing_atom) as soon as
    255 valid UTF-8 code points are read instead of rejecting trailing invalid
    bytes first, and frees the temporary latin1 conversion buffer.
    (Added after the Nov 12 flash snapshot.)

  10. Align set options and empty-left operations with OTP.
    Runtime +14 (+20/-6); total +70 (+76/-6). Impact: medium.
    Corrects constructor option defaults/precedence and lazy empty-left
    subtract/2 / is_subset/2 handling. Still version-2-only: this does not
    implement v1 sets.
    Include the OTP 27 test correction ef9165c9d.
    Flash Δ (payload / image): ESP32 0 / 0 B; C3 0 / 0 B; AVM +488 B.

  11. Honor float bitstring construction units.
    Runtime +19 (+53/-34); total +50 (+84/-34). Impact: high for affected
    bit syntax. Keeps allocation, validation, and insertion consistent across
    interpreter, JIT compilation, and legacy opcodes. Review all those paths together.
    Flash Δ (payload / image): ESP32 +1156 / +1152 B; C3 +1182 / +1184 B; AVM 0 B.

  12. Round big integers to double once.
    Runtime +26 (+31/-5); total +72 (+77/-5). Impact: high for numeric
    correctness. Builds one correctly rounded significand with ties-to-even;
    affects float/1 and division, so precision boundaries deserve focused review.
    Flash Δ (payload / image): ESP32 +280 / +272 B; C3 +312 / +320 B; AVM 0 B.

  13. Preserve precision in mixed integer/float comparisons.
    Runtime +30 (+32/-2); total +83 (+85/-2). Impact: high for comparison
    correctness. Keeps unequal integers distinguishable from rounded floats beyond
    the exact-integer boundary: 2^53 for double, 2^24 for float32. Shared comparator.
    Flash Δ (payload / image): ESP32 +292 / +304 B; C3 +302 / +288 B; AVM 0 B.

  14. Avoid double-rounding small integers into float32.
    Runtime +32 (+111/-79); total +68 (+147/-79). Impact: high for numeric
    bitstring parity. Casts unboxed small integers directly or via integer arithmetic
    on |value| > 2^53 instead of routing through binary64 in interpreter and JIT.
    (Added after the Nov 12 flash snapshot.)

  15. Avoid bs_create_bin register exhaustion on UTF segments.
    Runtime +78 (+95/-17); total +170 (+190/-20). Impact: high for 6-register
    JIT backends (x86_64, armv6m). Decodes literal flags at JIT compile time,
    skips unused UTF size terms, orders term_to_int before runtime flags, and
    adds -ifdef(JIT_DWARF) pass-through stubs to jit_wasm32.
    (Added after the Nov 12 flash snapshot.)

Tier 3 — dependent bundles and broader changes

Numeric list-key lookup: take both steps

  1. Use numeric equality for list-key lookup.
    Runtime 0 (+1/-1); total +16 (+17/-1). Impact: medium.
    Changes lists:keyfind/3 and keymember/3, including nested numbers, signed
    zero, and first-match behavior. Not the final compatibility fix on its own.
    Flash Δ (payload / image): ESP32 0 / 0 B; C3 -8 / 0 B; AVM 0 B.

  2. Match OTP's immediate-integer key lookup behavior.
    Runtime +10 (+17/-7); total +49 (+56/-7). Impact: medium.
    Follow-up to item 29: integer-key versus float-field lookup follows OTP's binary64
    conversion behavior, while boxed, reverse-direction, and nested comparisons
    retain their distinct behavior. Representation-sensitive; do not generalize
    the 64-bit oracle results to 32-bit targets without validation.
    Flash Δ (payload / image): ESP32 +96 / +96 B; C3 +108 / +112 B; AVM 0 B.

Receive timeout validation: reset first, then range-check

  1. Reset receive scanning after invalid timeouts.
    Runtime +8 (+8/-0); total +41 (+41/-0). Impact: high for mailbox
    correctness. Restores scanning and match flags after rejected timeouts in
    interpreter and native execution.
    Flash Δ (payload / image): ESP32 +40 / +48 B; C3 +24 / +32 B; AVM 0 B.

  2. Enforce the finite receive-timeout range.
    Runtime -8 (+6/-14); total +50 (+65/-15). Impact: medium.
    Follow-up to item 31: validates the unsigned 32-bit range, including oversized
    boxed integers, while preserving the receive-state reset.
    Flash Δ (payload / image): ESP32 +72 / +80 B; C3 +56 / +48 B; AVM 0 B.

Demonitor: option semantics plus incoming-monitor follow-up

  1. Validate demonitor options and implement flush/info semantics.
    Runtime +6 (+18/-12); total +48 (+60/-12). Impact: high for mailbox
    correctness. Validates options before removal; aligns active/inactive monitor
    results and removes the first matching five-tuple during flush regardless of tag.
    Flash Δ (payload / image): ESP32 -16 / -16 B; C3 -32 / -32 B; AVM 0 B.

  2. Flush even when the reference identifies an incoming monitor.
    Runtime -2 (+2/-4); total +55 (+59/-4). Impact: medium.
    Follow-up to item 33: the target must not remove another process's monitor, but
    [flush] must still scan the caller's own mailbox.
    Flash Δ (payload / image): ESP32 +16 / +16 B; C3 -4 / 0 B; AVM 0 B.

Unlink/relink: lifecycle bundle, not a four-line quick win

  1. Repair local unlink/relink transitions.
    Runtime +4 (+42/-38); total +115 (+153/-38). Impact: high;
    review risk: high. Handles pending relinks, stale acknowledgments, and crossed
    unlinks. Changes context_add_monitor and its interpreter/JIT/scheduler callers.
    Flash Δ (payload / image): ESP32 +72 / +64 B; C3 +134 / +144 B; AVM 0 B.

  2. Ignore queued linked exits after unlink.
    Runtime +7 (+24/-17); total +60 (+77/-17). Impact: high.
    Follow-up to item 35: deactivates local links before dead-peer lookup and suppresses
    already-queued linked exits after unlinking. Review with the state machine above.
    Flash Δ (payload / image): ESP32 +32 / +32 B; C3 +46 / +32 B; AVM 0 B.

Function calls and spawning: arity errors must remain Erlang errors

  1. Check fun-call arity before entering exports/BIFs.
    Runtime +48 (+56/-8); total +98 (+106/-8). Impact: high.
    Produces {badarity,{Fun,Args}}, with GC rooting, extended-register handling,
    and context stack-bound adjustments. More than an error-message-only change.
    Flash Δ (payload / image): ESP32 +220 / +208 B; C3 +232 / +240 B; AVM 0 B.

  2. Spawn external and wrong-arity functions inside the child.
    Runtime +14 (+33/-19); total +80 (+100/-20). Impact: high.
    Builds on item 37 so invalid startup becomes the child's Erlang failure rather
    than a VM abort or invalid closure startup. Uses bundled Erlang apply support.
    Flash Δ (payload / image): ESP32 +84 / +80 B; C3 +162 / +160 B; AVM 0 B.

Public exception traces: syntax, normalization, then depth

  1. Validate public raise/3 stack-frame syntax.
    Runtime +46 (+46/-0); total +117 (+117/-0). Impact: medium.
    Validates before changing exception state; malformed traces return the atom
    badarg. Also accounts for builds without stacktrace creation.
    Flash Δ (payload / image): ESP32 +160 / +160 B; C3 +224 / +224 B; AVM 0 B.

  2. Normalize legacy stack frames.
    Runtime +33 (+33/-0); total +79 (+79/-0). Impact: medium.
    Builds on item 39: supplies empty location lists for legacy frames and roots
    values across GC. Keep normalization and validation consistent.
    Flash Δ (payload / image): ESP32 +264 / +272 B; C3 +254 / +240 B; AVM 0 B.

  3. Honor configurable backtrace depth.
    Runtime +48 (+54/-6); total +139 (+146/-7). Impact: medium;
    scope: compatibility plus configuration API. Builds on items 39–40, with VM-global
    backtrace_depth, default 8 and maximum 64. Validates the entire supplied
    trace before truncating; not merely a smaller error payload.
    Flash Δ (payload / image): ESP32 +176 / +176 B; C3 +168 / +176 B; AVM 0 B.

Timers: synchronous validation and dead-PID cleanup

  1. Validate send_after/cancel_timer arguments synchronously.
    Runtime +17 (+32/-15); total +70 (+85/-15). Impact: high for timer
    contract parity. Validates arguments in the caller before spawning/messaging
    timer workers and raises badarg (cancel_timer/1 for non-references;
    erlang:send_after/3 for invalid arguments or delays outside 0..4294967295 ms).
    (Added after the Nov 12 flash snapshot.)

  2. Stop PID-targeted timers when their destination exits.
    Runtime +18 (+19/-1); total +90 (+91/-1). Impact: medium.
    Builds on item 42: monitors PID destinations in timer_manager, cleans up on
    DOWN, and keeps registered-name timers independent of process lifetime.
    (Added after the Nov 12 flash snapshot.)

Tooling and test fixes — ranked separately from shipped runtime

These five commits fix the validation workflow, tests, or static analysis rather
than application runtime semantics. Lynx-runner fixes presuppose the runner exists.
All five have 0 attributable ESP32/C3 firmware and 0 AVM bytes in these profiles;
unlike the 36 runtime/API entries, this is established from their changed inputs,
not five additional firmware-build pairs.

  1. Validate the actual bundled lists module.
    Total -6 (+8/-14). High validation value: stops substituting OTP's
    lists.beam, which could hide AtomVM library differences. Requires the
    excluded lists:sum/1 addition for the runner's own use; only take this
    tooling change if the destination already provides that API.
  2. Include public theorem declarations in inventory.
    Total 0 (+2/-2). Small runner fix: avoids silently missing public theorems.
  3. Make set-constructor regressions portable to OTP 27.
    Total +2 (+3/-1). Keep with item 23: version defaults differ, so assertions that
    require v2 error behavior explicitly request v2 instead of relying on the default.
  4. Correct no-GC allocation classification in CodeQL.
    Total +20 (+23/-3). Improves static-analysis coverage by exempting only known
    MEMORY_NO_GC constants. This is not itself a runtime use-after-GC repair.
  5. Remove differential trace output overhead.
    Total +20 (+26/-6). Chunks trace formatting; the recorded 70,796-byte case
    improved from 26.13 seconds to 0.15 seconds. This is transport/formatting
    performance, not a measured AtomVM application speedup.

Lynx API additions — not counted as defect fixes

Ordered by net runtime/library growth, independently of the fix ranking:

  • Tuple-range binary_part/2. Runtime +20 (+20/-0);
    total +35 (+35/-0). Reuses binary_part/3, including guard support.
    Flash Δ (payload / image): ESP32 +528 / +528 B; C3 +550 / +544 B; AVM +36 B.
  • Scoped binary:split/3. Runtime +23 (+36/-13);
    total +49 (+62/-13). Adds scope selection, preserves outside bytes, and keeps
    sizing and construction passes consistent, including negative lengths.
    Flash Δ (payload / image): ESP32 +188 / +192 B; C3 +158 / +160 B; AVM 0 B.
  • List lists:unzip/1. Runtime +23 (+23/-0);
    total +39 (+39/-0). Splits a list of pairs into two order-preserving lists
    and raises function_clause for malformed elements or improper lists.
    (Added after the Nov 12 flash snapshot.)
  • Monotonic erlang:send_after/4. Runtime +49
    (+60/-11); total +116 (+131/-15). Adds relative and {abs, boolean()}
    monotonic deadlines, last-option-wins validation, and monotonic cancellation
    times (retaining the 0..4294967295 ms future-delay limit). Builds on items 42–43.
    (Added after the Nov 12 flash snapshot.)
  • Process dictionary get_keys/0,1. Runtime +50 (+50/-0);
    total +85 (+85/-0). Adds key queries with exact value matching and GC rooting.
    Flash Δ (payload / image): ESP32 +204 / +192 B; C3 +218 / +224 B; AVM +76 B.

OTP 27 distinguishes positive and negative floating-point zero in exact
comparisons. Treating them as equal selected the wrong pattern clause
and collapsed distinct map keys.

Distinguish their signs in exact comparisons and map keys, including
nested map keys, while preserving numerical equality and ordering.
Extend the comparison regression test and document the fix.

Signed-off-by: Peter Madsen-Mygdal <petermm@gmail.com>
Compare seeded numeric, map and bitstring cases against OTP without
requiring executable-process ports in AtomVM. Retain failing inputs,
support replay and bounded shrinking, and optionally check Lynx laws.

Exercise the public runner with real runtimes and deliberately incorrect
target output.

Signed-off-by: Peter Madsen-Mygdal <petermm@gmail.com>
When an integer and float round to the same floating-point value,
compare their exact integer values beyond the lossless precision limit.
Keep the existing fast path for unambiguous and small comparisons.

Cover both operand orders, positive and negative boundaries, guards,
and nested terms. The regression fails on the previous implementation
and passes on OTP and AtomVM with this fix.

Signed-off-by: Peter Madsen-Mygdal <petermm@gmail.com>
Accumulate the significand and discarded-bit information as integers,
then round to nearest with ties to even before scaling to double.
Repeated floating-point accumulation could lose lower bits too early,
affecting float/1 and arithmetic such as division.

Keep a direct uint64 conversion for small magnitudes. Cover halfway
boundaries, both signs, carry into a new digit, the integer limit,
guard conversion and the reduced division reproducer.

Signed-off-by: Peter Madsen-Mygdal <petermm@gmail.com>
Export differential:binary_etf/5 in tools/test/lynx/differential.erl and
append 836 unique recipes (14,811 total, preserving all 13,975 preceding
recipes) in tools/test/lynx/lean_runtime.py covering binary_to_term/1,2,
term_to_binary/1,2, float bit preservation (-0.0), [safe] atom
isolation, [used] offset progression, BIT_BINARY_EXT widths 1..8,
MAP_EXT numeric and duplicate keys, option validation, compressed and
minor_version round-trips, bit-sliced offsets 0..7, and deep nested
compound trees.

Add independent pure-Elixir BINARY_ETF_MODEL contracts and
test_binary_etf_preserves_wire_options_and_replay to
tools/test/lynx/test_validate.py, and update Lynx PLAN.md, README.md,
and TODOS.md.

Signed-off-by: Peter M <petermm@gmail.com>
…new/2 options

Replace assert(term_is_tuple(op)) in apply_op (src/libAtomVM/ets.c) with
an explicit EtsBadEntry check so non-tuple entries inside operation lists
raise badarg instead of crashing the VM.

Move the default-tuple arity check (tuple_arity(default) <= key_index)
in lookup_or_default before the key lookup so ets:update_element/4 and
ets:update_counter/4 reject invalid default tuples even when the key
already exists, matching OTP 29.

Replace interop_kv_get_value* lookups in nif_ets_new (src/libAtomVM/nifs.c)
with strict proper-list option traversal rejecting unknown options,
invalid option tuples/values, {named_table, Bool}, keypos >= 2^64, and
improper tails while matching OTP conflict precedence for table types
and access modes.

Add standalone regression test_option_validation_and_bad_counter_ops/0
to tests/erlang_tests/test_ets.erl and document the fixes in
CHANGELOG.md.

Signed-off-by: Peter M <petermm@gmail.com>
Add standalone helper tools/test/lynx/ets_tables.erl (registered in
tools/test/lynx/validate.py) so ETS observer logic does not push
differential.erl past AArch64 jit_aarch64_asm's +/-1 MiB adr limit.

Append 237 unique multi-step ets_table recipes (15,048 total, preserving
all 14,811 preceding recipes) in tools/test/lynx/lean_runtime.py covering
all 15 ets exports across set/bag/duplicate_bag, keypos 1..3, option
validation and precedence, named_table collisions, -0.0 vs 0.0, bit-sliced
keys, cross-process access, owner-exit cleanup, and GC retention.

Add pure-Elixir ETS_MODEL and test_ets_preserves_table_semantics_access_and_replay
to tools/test/lynx/test_validate.py, and update Lynx PLAN.md, README.md,
and TODOS.md.

Signed-off-by: Peter M <petermm@gmail.com>
…ata handling

Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
…y latin1 sizing

Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
…data length

Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
…rity

Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
- Drop is_binary/1 guard on erlang:md5/1 so iodata hashes and invalid inputs raise badarg
- Dispatch crypto:crypto_init/3 externally via ?MODULE:crypto_init/4
- Reuse strict parse_cipher_flag_or_options in nif_crypto_crypto_one_time, enable aes_{128,192,256}_ofb when MBEDTLS_CIPHER_MODE_OFB is defined, loop multi-block ECB updates, reject partial blocks under {padding, none}, and map padding errors to error tag
- Support empty <<>> HMAC keys in nif_crypto_mac and nif_crypto_mac_init via RFC 2104 1-byte zero padding
- Allow mac_finalN/2 length 0 and reject negative/out-of-range/non-integer lengths with badarg; map PSA_ERROR_INVALID_PADDING to error tag in nif_crypto_crypto_final
- Set default CCM tag length to 12 while comparing against PSA_AEAD_TAG_LENGTH (16), validate 6-arity EncFlag == true, and reject out-of-range encrypt/decrypt AEAD tag lengths
- Reject 0 iterations in nif_crypto_pbkdf2_hmac
- Extend standalone regressions in tests/erlang_tests/test_crypto*.erl and add tests/libs/estdlib/test_crypto.erl plus CHANGELOG.md entry

Signed-off-by: Peter M <petermm@gmail.com>
- Add 335 recipes (174 non-PSA + 161 PSA-gated via HAVE_PSA_CRYPTO) covering 18 deterministic exports via crypto_ops:observe/5 (total 20,031)
- Add HAVE_PSA_CRYPTO capability detection and requires_psa_crypto filtering in validate.py
- Add independent pure-Elixir CRYPTO_OPS_MODEL (zero :crypto/:erlang.md5 calls) and test_crypto_ops_and_replay in test_validate.py
- Document results across interpreter, AArch64 precompiled, on-demand JIT, and OTP 27/28/29 in PLAN.md, README.md, and TODOS.md

Signed-off-by: Peter M <petermm@gmail.com>
- Add is_list guards to filename functions (join/1,2, split/1, dirname/1, basename/1,2, extension/1, rootname/1,2) so non-list inputs raise function_clause instead of badarg.
- Fix io_lib:format/2 and fwrite/2 entry/parse error normalization (badarg), stacked t/l/k modifiers, ~n/~~ field widths, ~p field widths, [short] floats, improper lists, improper binary tails (~s/~ts), negative ~g and significant-digit boundaries, and ~f/~e/~g precision validation.
- Fix io_lib:write_atom/1 (empty atom, 'else', backslash/control/octal escapes, Latin-1 identifiers), write_binary/3 (Depth, CharLimit, partial bitstrings), write_string/1,2 (quotes, backslashes, \d/octal escapes, custom quote char), printable_list/1 (DEL/C1/surrogates), and chars_length/1 input guards.
- Add standalone regressions to tests/libs/estdlib/test_filename.erl and tests/libs/estdlib/test_io_lib.erl and update CHANGELOG.md.

Signed-off-by: Peter M <petermm@gmail.com>
…verage

- Add standalone Erlang helpers filename_ops, io_lib_ops, math_ops, and zlib_ops with GC retention checks.
- Add 566 recipes (150 filename, 176 io_lib, 208 math, 32 zlib:compress/1 gated on WITH_ZLIB via requires_zlib) in lean_runtime.py and validate.py, covering all 43 exports across the four modules (total 20,597).
- Add independent pure-Elixir oracle models (FILENAME_OPS_MODEL, IO_LIB_OPS_MODEL, MATH_OPS_MODEL with <= 4 ULP transcendental tolerance and exact -0.0/error checks, and ZLIB_OPS_MODEL with RFC 1950/1951 INFLATE + Adler-32), 16 negative controls, and test_stdlib_nif_ops_and_replay in test_validate.py.
- Update PLAN.md, README.md, and TODOS.md.

Signed-off-by: Peter M <petermm@gmail.com>
Fix OTP divergences found while building differential tests for calendar
and json:

- calendar:system_time_to_universal_time/2 in src/libAtomVM/nifs.c:
  use floor division (floor_div_i64) for negative timestamps and
  remainders, validate int64 timestamps with term_is_int64 (preventing
  corrupted results on non-integers and SIGSEGV on floats/bignums),
  support positive integer time units, and check gmtime_r for NULL.
- json:encode_map/2 in libs/estdlib/src/json.erl: add an is_map(Map)
  guard so non-map arguments raise function_clause matching OTP instead
  of {badmap, _}.
- Add standalone regressions to tests/erlang_tests/test_system_time.erl
  and tests/libs/estdlib/test_json.erl, and document both fixes in
  CHANGELOG.md.

Signed-off-by: Peter M <petermm@gmail.com>
Add 321 deterministic differential recipes (59 maps_ops + 156 json_ops +
106 calendar_ops; corpus total 20,597 -> 20,918) covering the remaining
6/34 maps exports, all 17 json exports, and all 6 implemented calendar
exports via standalone helpers in tools/test/lynx/.

- Remove calendar_negative_subsecond_system_time (4 cases) from
  tools/test/lynx/expected_failures.json (192 -> 188).
- Add pure-Elixir oracle models (MAPS_OPS_MODEL, JSON_OPS_MODEL,
  CALENDAR_OPS_MODEL, using no :maps, Map., :json, JSON., or :calendar),
  12 negative wrong-result controls, test_maps_json_calendar_ops_and_replay,
  and updated strict expected-failures checks in test_validate.py.
- Verify 321/321 on interpreter (build) and AArch64 native
  (.amp/in/build-native), 109/109 on scoped on-demand JIT covering all
  29 op tags (.amp/in/build-on-demand), exact cross-mode ETF parity,
  and observer-only OTP parity (321/321 on OTP 29.1.3; 315/321 on OTP
  27.3.4.12 and 28.3.1 due to OTP 29 time_to_seconds/1 bounds guards).
- Update tools/test/lynx/{PLAN.md,README.md,TODOS.md}.

Signed-off-by: Peter M <petermm@gmail.com>
Update AtomVM's Lynx integration to upstream main 0963cdecf4409a16cf9172f7baf3cf0034165382
(Lean 4.36.0) and adopt its v0.2.0/post-v0.2.0 features:

- Migrate tools/test/lynx/validate.exs from removed Lynx.Laws.verify/2 to
  data-centric Lynx.verify/3, record structured manifest["proofs"] data,
  exclude Elixir.Lynx.Support.Fixtures.beam, run under MIX_ENV=test, and
  forward --jobs (> 1) to LEAN_NUM_THREADS for parallel law elaboration.
- Add --export-proofs, --check-proofs, and --check-proofs-paranoid to
  tools/test/lynx/validate.py to export .ndjson proof declarations and
  verify them independently with lake check [--paranoid] --from-export.
- Add --verify-estdlib with estdlib_laws.erl, directory prelude/postlude
  modules (estdlib_proofs/{prelude/AtomVMCalendar.lean,
  postlude/CalendarFacts.lean,laws.exs}), and 38 differential runtime
  checks (fixtures.estdlib_proof_cases()), proving 9 formal laws directly
  against AtomVM's libs/estdlib/src/{calendar.erl,queue.erl}.
- Update .github/workflows/lynx-differential.yaml, test_validate.py,
  PLAN.md, README.md, and TODOS.md.

Signed-off-by: Peter M <petermm@gmail.com>
- Fix do_replace_state/3 checking system_replace_state/1 instead of arity 2 so Mod:system_replace_state/2 is invoked.
- Route sys client APIs through send_system_msg/2,3 + mfa/2,3 so dead or unregistered targets exit with OTP {Reason, {sys, Func, Args}} tuples.
- Add standalone regression tests in tests/libs/estdlib/test_sys.erl and update CHANGELOG.md.

Signed-off-by: Peter M <petermm@gmail.com>
- Export and implement system_replace_state/2 so sys:replace_state/2,3 mutates ModState rather than the internal #state{} record.
- Guard ServerRef ! {'', Reason} against badarg in stop/3 so unregistered names exit noproc instead of badarg.
- Exit {Reason, {gen_server, call, [ServerRef, Request]}} in call/2 instead of adding the implicit 5000 timeout.
- Unify invalid handle_call/cast/info/continue returns to terminate with {bad_return_value, Reply}.
- Add standalone regression tests in tests/libs/estdlib/test_gen_server.erl and update CHANGELOG.md.

Signed-off-by: Peter M <petermm@gmail.com>
- Store initial state_timeout timer_map refs from init/1 and ignore stale or superseded state_timeout messages in handle_info/2.
- Cancel prior state_timeout timer when replaced in the same state via do_handle_state.
- Match OTP call/2 infinity default timeout and include Timeout in call/3 exit MFA tuples.
- Handle init -> ignore and {bad_return_from_init, Other}, guard optional terminate/3, and accept single-action tuples in handle_actions/2.
- Add standalone regression tests in tests/libs/estdlib/test_gen_statem.erl and update CHANGELOG.md.

Signed-off-by: Peter M <petermm@gmail.com>
- Remove handlers and invoke terminate/2 with OTP reasons (remove_handler, {error, Other/Term}, {error, {'EXIT', ...}}) when handle_event/2 requests removal, returns invalid terms, or raises.
- Delete handlers even when terminate/2 throws during delete_handler/3.
- Guard optional terminate/2 callback with erlang:function_exported/3.
- Add standalone regression tests in tests/libs/estdlib/test_gen_event.erl and update CHANGELOG.md.

Signed-off-by: Peter M <petermm@gmail.com>
- Handle ignore returns from supervisor:init/1.
- Unwrap {Reason, #child{}} into Reason inside start_children/2 so failed init returns {error, {shutdown, {failed_to_start_child, Id, Reason}}}.
- Do not restart transient children exiting with shutdown or {shutdown, _}.
- Keep cleanly stopped transient children with pid = undefined instead of deleting them, allowing which_children/count_children/restart_child/delete_child.
- Omit temporary children returning ignore in start_children/2 and start_child/2.
- Add standalone regression tests in tests/libs/estdlib/test_supervisor.erl and update CHANGELOG.md.

Signed-off-by: Peter M <petermm@gmail.com>
Add 179 deterministic differential recipes (28 proc_lib_ops + 51 gen_server_ops +
30 gen_statem_ops + 13 gen_event_ops + 28 supervisor_ops + 29 sys_ops;
corpus total 20,918 -> 21,097) covering local spawn/start/call/cast/info/
continue/timeout/monitor/stop/supervision/system-message flows across the six
OTP process and behaviour modules via standalone helpers in tools/test/lynx/.

- Add proc_lib_ops, gen_server_ops, gen_statem_ops, gen_event_ops (with
  gen_event_aux), supervisor_ops, and sys_ops (with sys_ops_cb) and register
  them in validate.py.
- Add pure-Elixir oracle OTP_BEHAVIOURS_ORACLE_DRIVER (using no :proc_lib,
  :gen_server, GenServer, :gen_statem, :gen_event, :supervisor, Supervisor,
  or :sys), 18 negative wrong-result controls (0 Elixir compiler warnings),
  and test_otp_behaviours_ops_and_replay in test_validate.py (plus update
  total recipe count assertion to 21,097).
- Verify 179/179 on interpreter (build) and AArch64 native
  (.amp/in/build-native), 125/125 on scoped on-demand JIT covering all 6
  modules and all 70 distinct ops (.amp/in/build-on-demand), exact cross-mode
  ETF parity, and 179/179 observer-only parity across OTP 27.3.4.12, 28.3.1,
  and 29.1.3.
- Update tools/test/lynx/{PLAN.md,README.md,TODOS.md}.

Signed-off-by: Peter M <petermm@gmail.com>
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.

2 participants