Skip to content

Use the stdlib Hashtbl for the compiler's hash sets - #8787

Draft
cknitt wants to merge 3 commits into
stdlib-hashtblfrom
stdlib-hashset
Draft

cknitt wants to merge 3 commits into
stdlib-hashtblfrom
stdlib-hashset

Conversation

@cknitt

@cknitt cknitt commented Oct 10, 2026

Copy link
Copy Markdown
Member

Second of four PRs moving the compiler's own collections onto the OCaml standard library, stacked on #8786. This one covers hash sets.

Hash_set_ident, Hash_set_string and Used_attributes.Attribute_name_set are now unit tables from Hashtbl.Make, using the same equality and hash functions as before. Lam_module_ident.Hash_set is an alias of Lam_module_ident.Hash. Hash_set and Hash_set_gen are removed, together with their ounit tests.

  • Keep-first adds. Every add is guarded by mem, so the first key added is kept. This matters for Lam_module_ident: two module ids can be equal while carrying different ids, and the first one decides the name the import is bound to. Lam_module_ident.set_add does this for the module sets.
  • Deterministic import order. The hard dependencies were sorted by module name only, so ties fell back to hash-set order. Ties happen when the same module is imported both with and without default. They are now broken by kind and then default. The one change in the generated output is key_word_property.mjs. There the old order put default first for one module and last for another; now the plain import always comes first.

Output: byte-identical to #8786 on 627 of 628 files; the exception is key_word_property.res, described above.

Performance: neutral (CPU +0.2%, allocation −0.1% vs master). Earlier figures that suggested a speedup didn't reproduce.

🤖 Generated with Claude Code

cknitt and others added 2 commits October 10, 2026 18:50
Hash sets are unit Hashtbl.Make tables; adds keep the first key. Sort hard
dependencies by a total order so ties no longer depend on hash order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Knittel <ck@cca.io>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt added this pull request to stack #8788 October 10, 2026 18:50
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Knittel <ck@cca.io>
@pkg-pr-new

pkg-pr-new Bot commented Oct 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@8787

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@8787

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@8787

@rescript/darwin-x64

npm i https://pkg.pr.new/@rescript/darwin-x64@8787

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@8787

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@8787

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@8787

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@8787

commit: 9b8ce57

@codecov

codecov Bot commented Oct 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.64%. Comparing base (ccb7c23) to head (9b8ce57).

Files with missing lines Patch % Lines
compiler/core/lam_module_ident.ml 75.00% 2 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                 @@
##           stdlib-hashtbl    #8787      +/-   ##
==================================================
- Coverage           80.66%   80.64%   -0.03%     
==================================================
  Files                 461      458       -3     
  Lines               62630    62523     -107     
==================================================
- Hits                50520    50420     -100     
+ Misses              12110    12103       -7     
Files with missing lines Coverage Δ
compiler/core/js_fold_basic.ml 100.00% <ø> (ø)
compiler/core/lam_check.ml 95.00% <100.00%> (ø)
compiler/core/lam_coercion.ml 97.50% <100.00%> (ø)
compiler/core/lam_compile_env.ml 84.44% <100.00%> (ø)
compiler/core/lam_compile_main.ml 89.87% <100.00%> (+0.16%) ⬆️
compiler/core/lam_dce.ml 92.10% <ø> (ø)
compiler/ext/hash_set_ident.ml 100.00% <ø> (ø)
compiler/ml/used_attributes.ml 100.00% <100.00%> (ø)
tests/ounit_tests/ounit_tests_main.ml 100.00% <ø> (ø)
compiler/core/lam_module_ident.ml 90.90% <75.00%> (-9.10%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
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.

1 participant