Repository navigation
Lynx vs AtomVM - #2473
Lynx vs AtomVM#2473petermm wants to merge 219 commits into
Conversation
e740cd2 to
42373e4
Compare
|
Executive summary: I suggest cherry picking from this PR branch.. Lynx / AtomVM: executive fix and cherry-pick summaryTier 1 — best first cherry-pick candidates
Tier 2 — good fixes, but review shared semantics
Tier 3 — dependent bundles and broader changesNumeric list-key lookup: take both steps
Receive timeout validation: reset first, then range-check
Demonitor: option semantics plus incoming-monitor follow-up
Unlink/relink: lifecycle bundle, not a four-line quick win
Function calls and spawning: arity errors must remain Erlang errors
Public exception traces: syntax, normalization, then depth
Timers: synchronous validation and dead-PID cleanup
Tooling and test fixes — ranked separately from shipped runtimeThese five commits fix the validation workflow, tests, or static analysis rather
Lynx API additions — not counted as defect fixesOrdered by net runtime/library growth, independently of the fix ranking:
|
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>
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>
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