Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-deterministic representation of map as string #8606

Closed
pguyot opened this issue Jun 22, 2024 · 1 comment
Closed

Non-deterministic representation of map as string #8606

pguyot opened this issue Jun 22, 2024 · 1 comment
Labels
bug Issue is reported as a bug

Comments

@pguyot
Copy link
Contributor

pguyot commented Jun 22, 2024

Describe the bug
Until OTP-27, the following map:

#{a => 1, b => 2}

would have the following representation:

"#{a => 1,b => 2}"

With OTP-27, the representation can non-deterministically also be:

"#{b = >2,a => 1}"

To Reproduce

mkdir /tmp/test_beam
cd /tmp/test_beam

Then run the following command a dozen times:

erl -pa . -eval 'io:format("~p\n", [#{a=>1,b=>2}]).' -run init stop -noshell

Expected behavior
Representation should be deterministic or non-determinism should be documented (couldn't find it in OTP27 release notes).

Affected versions
OTP-27.0

Additional context

This was observed on macOS:

ProductName: macOS
ProductVersion: 14.5
BuildVersion: 23F79

with OTP-27 from MacPorts on an amd64 machine.

Screenshot 2024-06-22 at 22 51 22
@michalmuskala
Copy link
Contributor

michalmuskala commented Jun 23, 2024

This was changed in OTP 26 and is documented in the release notes: https://erlang.org/download/otp_src_26.0.readme (under OTP-18414). Maps were never documented as having any particular order, and in fact maps larger than 32 keys in previous releases would have a largely unpredictable order of keys when printed (different to maps with less than 32 keys) - such order should have never been relied upon, as it was never guaranteed.

Maps can be printed sorted using io:format("~kp", [Value])., with the k and K modifiers documented in io:fwrite/3.

@pguyot pguyot closed this as completed Jun 23, 2024
bettio added a commit to atomvm/AtomVM that referenced this issue Jun 23, 2024
Update build matrices and set OTP27 as the default

* Update Linux Build matrix to favor more compilers, three latest OTP versions,
while maintaining builds from 21 to master, reducing combinations from 46 to 39
* Update Run tests on BEAM workflow to include OTP27
* Update build and test on other Linuxes to use OTP27
* Fix test_io_lib for OTP27 (including workaround for
erlang/otp#8606)
* Fix compilation with gcc-14

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug
Projects
None yet
Development

No branches or pull requests

2 participants