Skip to content

fix(beam): prevent identifier collisions and atom overflow - #5017

Merged
dbrattli merged 5 commits into
mainfrom
fix/beam-identifier-collisions
Oct 4, 2026
Merged

dbrattli merged 5 commits into
mainfrom
fix/beam-identifier-collisions

Conversation

@dbrattli

@dbrattli dbrattli commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Distinct F# names can collapse to the same Erlang function or map key, silently losing code or state. Long names can also overflow the atom limit, including when erlc derives closure names or the compiler joins already-bounded names.

This change preserves encoded punctuation, reports declaration and state-key collisions, and separates captured class bindings from public members. Atoms are capped at 223 characters to leave room for Erlang-generated names, with consistent construction for interface setter keys and object override names. Direct GetHashCode() calls honor class overrides.

Native BEAM compilation uses SHA-256 for bounded-name suffixes. Standalone retains the existing 32-bit djb2 hash for web examples, without Crypto.ts, cryptography metadata, or new BCL replacements. Overlong names may differ between compiler hosts; detected standalone state-key collisions are reported to the UI.

Validation of the final implementation:

  • ./build.sh test beam: 2,714 .NET tests and 2,763 BEAM tests passed, including generated Erlang compilation, entry-point fixtures, and negative collision diagnostics.
  • Standalone compiler and worker rebuilt successfully; worker tests passed with 43 metadata assemblies, including BEAM bounded-name hashing and mutable-state collision diagnostics.
  • Formatting checks for changed compiler/build files and git diff --check passed.

Regression coverage includes colliding bounded mutable names, long interface setters on object expressions and classes, long override entity names, direct hash-code overrides, and interface setter-key collision diagnostics.

Review follow-up

Maxime's suggestions in #5041 are incorporated into this PR:

  • Remove Crypto.ts, cryptography metadata, and the JavaScript BCL crypto replacements. Native BEAM keeps SHA-256; standalone uses the existing djb2 hash for web examples, accepting different overlong names between compiler hosts.
  • Cap atoms at 223 characters and re-cap composed names to leave room for erlc decorations.
  • Restrict private renaming to captured locals so public and cross-file calls retain their expected names.
  • Extend collision diagnostics to class/val fields, union tags, and interface members.

The follow-up review and regression tests also led to these fixes in 3a972fab5:

  • Construct long interface setter keys consistently in definitions, lookups, and collision diagnostics.
  • Normalize override entity names consistently before hashing definitions and calls.
  • Diagnose colliding mutable-state keys instead of silently sharing state.
  • Include BEAM code-generation diagnostics in the standalone UI's error results.
  • Honor class overrides in direct GetHashCode() calls, an additional issue exposed by the expanded tests.

Comment thread src/Fable.Transforms/Beam/Prelude.fs Fixed
@dbrattli dbrattli changed the title fix(beam): prevent identifier collisions fix(beam): prevent identifier collisions and atom overflow Sep 30, 2026
@dbrattli
dbrattli marked this pull request as draft October 2, 2026 06:38
@dbrattli
dbrattli marked this pull request as ready for review October 4, 2026 15:29
@dbrattli
dbrattli merged commit b9ce2fd into main Oct 4, 2026
51 checks passed
@dbrattli
dbrattli deleted the fix/beam-identifier-collisions branch October 4, 2026 19:42
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.

3 participants