Skip to content

Use the stdlib Hashtbl for the compiler's hash tables - #8786

Merged
cknitt merged 4 commits into
masterfrom
stdlib-hashtbl
Oct 11, 2026
Merged

cknitt merged 4 commits into
masterfrom
stdlib-hashtbl

Conversation

@cknitt

@cknitt cknitt commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

First of four PRs moving the compiler's own collections onto the OCaml standard library. This one covers hash tables.

Hash_ident, Hash_int, Lam_module_ident.Hash and the polymorphic-variant match table in Polyvar_pattern_match are now Hashtbl.Make instances with the same equality and hash functions. The module names stay, so the types are still shared across the compiler; call sites use the stdlib API. Hash and Hash_gen are removed.

Changes beyond the API rename:

  • Lam_compile_env used find_key_opt to reuse the id a JS module was first bound to. The stdlib has no such lookup, so the External entry now carries that id.
  • Lam_beta_reduce_util.simple_beta_reduce sequenced unused arguments in the hash table's iteration order, so a different table would have changed the output. It now folds over the parameters. This is also a small bug fix (separate commit): for f(log(1), log(2), log(3), log(4)) with only the last parameter used, the unused arguments ran as 2, 3, 1 before and now run as 1, 2, 3. The new inline_unused_arg_order_test checks this at runtime. A used argument is still substituted into the body, so it runs after the unused ones, as before.
  • The ounit tests that only exercised the removed Hash implementation are dropped.

Output: apart from the evaluation-order fix, the generated JS and diagnostics are byte-identical to master on 627 files (Belt, all of tests/tests/src, and the benchmark stress inputs).

Performance: neutral (CPU +0.5%, allocation −0.1% vs master, within noise on a shared machine). The motivation is less code to maintain, not speed.

🤖 Generated with Claude Code

cknitt and others added 4 commits October 10, 2026 18:43
simple_beta_reduce sequenced the unused arguments in the iteration order of
its parameter hash table; fold over the parameters instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Knittel <ck@cca.io>
Hash_ident, Hash_int, Lam_module_ident.Hash and the polyvar match table are
now Hashtbl.Make instances; the ext Hash module is removed.

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>
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@8786

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: ccb7c23

@github-actions

Copy link
Copy Markdown

@codecov

codecov Bot commented Oct 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.61905% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.66%. Comparing base (1c50add) to head (ccb7c23).

Files with missing lines Patch % Lines
compiler/core/lam_compile_env.ml 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8786      +/-   ##
==========================================
- Coverage   80.66%   80.66%   -0.01%     
==========================================
  Files         463      461       -2     
  Lines       62792    62630     -162     
==========================================
- Hits        50651    50520     -131     
+ Misses      12141    12110      -31     
Files with missing lines Coverage Δ
compiler/core/js_pass_flatten_and_mark_dead.ml 76.74% <100.00%> (ø)
compiler/core/js_pass_get_used.ml 96.15% <100.00%> (+0.32%) ⬆️
compiler/core/lam_beta_reduce.ml 84.31% <100.00%> (+0.98%) ⬆️
compiler/core/lam_beta_reduce_util.ml 97.22% <100.00%> (-0.08%) ⬇️
compiler/core/lam_bounded_vars.ml 65.75% <100.00%> (+0.96%) ⬆️
compiler/core/lam_exit_count.ml 100.00% <100.00%> (ø)
compiler/core/lam_module_ident.ml 100.00% <ø> (ø)
compiler/core/lam_pass_lets_dce.ml 85.50% <100.00%> (+0.43%) ⬆️
compiler/core/lam_stats.ml 85.71% <100.00%> (ø)
compiler/core/polyvar_pattern_match.ml 100.00% <100.00%> (ø)
... and 4 more
🚀 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.

@cknitt

cknitt commented Oct 11, 2026

Copy link
Copy Markdown
Member Author

@codex review

@cknitt
cknitt marked this pull request as ready for review October 11, 2026 05:24
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: ccb7c23f78

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T05:27:17.735571Z ccb7c23 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cknitt
cknitt requested a review from cristianoc October 11, 2026 05:28
@cknitt
cknitt merged commit 2087137 into master Oct 11, 2026
24 checks passed
@cknitt
cknitt deleted the stdlib-hashtbl branch October 11, 2026 07:07
aspeddro pushed a commit to aspeddro/rescript-compiler that referenced this pull request Oct 31, 2026
…8786)

* Evaluate unused arguments of inlined calls in parameter order

simple_beta_reduce sequenced the unused arguments in the iteration order of
its parameter hash table; fold over the parameters instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Knittel <ck@cca.io>

* Use the stdlib Hashtbl for the compiler's hash tables

Hash_ident, Hash_int, Lam_module_ident.Hash and the polyvar match table are
now Hashtbl.Make instances; the ext Hash module is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Knittel <ck@cca.io>

* Add PR link to CHANGELOG

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Knittel <ck@cca.io>

* Reword CHANGELOG entry

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Knittel <ck@cca.io>

---------

Signed-off-by: Christoph Knittel <ck@cca.io>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Pedro Castro <aspeddro@gmail.com>
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.

2 participants