compiler: Support long UTF-8 encoded atoms #8913
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Support for atoms containing any Unicode code point was added in Erlang/OTP 20 (#1078).
After that change, an atom can contain up to 255 Unicode code points. However, atoms used in Erlang source code is still limited to 255 bytes because the atom table in the BEAM file only has a byte for holding the length in bytes of the atom text. For instance, the
🟦
character has a four-byte encoding (<<240,159,159,166>>
), meaning that Erlang source code containing a literal atom consisting of 64 or more such characters cannot be compiled.This pull request changes the atom table in BEAM files to use
two bytesa variable length encoding for the length of each atom. For atoms up to 15 bytes, the length is encoded in one byte. The header for the atom table is also changed to indicate thattwo-byte lengththe new encodiging of lengths are used. Attempting to load a BEAM file compiled with Erlang/OTP 28 in Erlang/OTP 27 or earlier will result in the following error message:beam_lib
is updated to handle the new format. External tools that usebeam_lib:chunks(Beam, [atoms])
to read the atom table will continue to work. External tools that do their own parsing of the atom table will need to be updated.