Skip to content

Dispatch @deriving by name instead of through a registry - #9157

Merged
cknitt merged 2 commits into
masterfrom
deriving-dispatch
Nov 1, 2026
Merged

cknitt merged 2 commits into
masterfrom
deriving-dispatch

Conversation

@cknitt

@cknitt cknitt commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Split out of #9153.

Ast_derive kept a process-global table of derivers, filled at startup by a side effect in Bs_builtin_ppx. It had a single entry (accessors), and an expression_gen field nothing read. dispatch now matches on the deriver name directly, still giving the removed derivers (abstract, jsConverter) their dedicated errors. Ast_derive_projector exposes check_config, structure_gen and signature_gen as plain functions, and no longer depends on Ast_derive.

A future deriver, for example a user-defined one from compile-time evaluation, would be resolved per compilation in dispatch, from what is in scope. A table filled once when the process starts would be the wrong place for that, especially with rewatch compiling many packages in one process.

New super_errors fixtures, deriving_unknown.res and deriving_accessors_config.res, pin the two error paths dispatch handles. A second commit makes both messages say which attribute is wrong and what to write instead, in the style of the removed-deriver errors:

Code Before After
@deriving(lenses) lenses is not supported @deriving(lenses) is not supported. The only deriver is @deriving(accessors).
@deriving({accessors: true}) such configuration is not supported @deriving(accessors) takes no configuration.

Most of the ast_derive_projector.ml diff is re-indentation; with -w it is +41/−83 across the PR.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gKyiYMf54wPRxFdUWe

Ast_derive kept a process-global table of derivers, filled at startup by
a side effect in Bs_builtin_ppx, with a single entry (accessors) and an
expression_gen field nothing read. dispatch now matches the name
directly, so it stays the one place a future deriver would be resolved.
The projector exposes its generators as plain functions. New
super_errors fixtures pin the unknown-deriver and configuration errors,
which are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gKyiYMf54wPRxFdUWe
Signed-off-by: Christoph Knittel <ck@cca.io>
@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Changelog

💅 Polish

  • Clearer errors for an unknown deriver (@deriving(lenses) is not supported. The only deriver is @deriving(accessors).) and for a configuration passed to @deriving(accessors).

🏠 Internal

  • Dispatch @deriving by name instead of through a registry that had a single deriver.

Semantic Diff

2 commits · Full page

Dispatch @deriving by name instead of through a registry

2874653 · cknitt + Claude · Oct 31, 2026, 10:20 UTC

Ast_derive kept a process-global table of derivers, filled at startup by a side effect in Bs_builtin_ppx, with a single entry (accessors) and an expression_gen field nothing read. dispatch now matches the name directly, so it stays the one place a future deriver would be resolved. The projector exposes its generators as plain functions. New super_errors fixtures pin the unknown-deriver and configuration errors, which are unchanged.

✨ Name the deriver in @deriving errors and say what is supported

e84079e · cknitt + Claude · Nov 01, 2026, 06:43 UTC · new

Why

Review: "lenses is not supported" and "such configuration is not supported" didn't say which attribute was wrong or what to write instead. The messages now follow the removed-deriver ones.

Diagnostic modified (unknown deriver)

@deriving(lenses)
type t = {name: string}

diagnostic

-lenses is not supported
+@deriving(lenses) is not supported. The only deriver is @deriving(accessors).

Diagnostic modified (configuration for accessors)

@deriving({accessors: true})
type t = {name: string}

diagnostic

-such configuration is not supported
+@deriving(accessors) takes no configuration.

@codecov

codecov Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.54839% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.75%. Comparing base (8e26a9c) to head (e84079e).

Files with missing lines Patch % Lines
compiler/frontend/ast_derive_projector.ml 92.85% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9157   +/-   ##
=======================================
  Coverage   81.74%   81.75%           
=======================================
  Files         460      460           
  Lines       64944    64941    -3     
=======================================
- Hits        53091    53090    -1     
+ Misses      11853    11851    -2     
Files with missing lines Coverage Δ
compiler/frontend/ast_derive.ml 100.00% <100.00%> (ø)
compiler/frontend/bs_builtin_ppx.ml 90.33% <ø> (-0.04%) ⬇️
compiler/frontend/ast_derive_projector.ml 92.98% <92.85%> (+2.81%) ⬆️
🚀 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.

Why:
    Review: "lenses is not supported" and "such configuration is not
    supported" didn't say which attribute was wrong or what to write
    instead. The messages now follow the removed-deriver ones.

Diagnostic modified (unknown deriver):
Example:
    @deriving(lenses)
    type t = {name: string}
Before (diagnostic): lenses is not supported
After (diagnostic): @deriving(lenses) is not supported. The only deriver is @deriving(accessors).

Diagnostic modified (configuration for accessors):
Example:
    @deriving({accessors: true})
    type t = {name: string}
Before (diagnostic): such configuration is not supported
After (diagnostic): @deriving(accessors) takes no configuration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gKyiYMf54wPRxFdUWe
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt

cknitt commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

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-11-01T06:44:55.539371Z e84079e 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 marked this pull request as ready for review November 1, 2026 06:44
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: e84079e3b4

ℹ️ 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".

@cknitt
cknitt requested a review from cristianoc November 1, 2026 06:45
@cknitt
cknitt enabled auto-merge (squash) November 1, 2026 06:47
@pkg-pr-new

pkg-pr-new Bot commented Nov 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: e84079e

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

@cknitt
cknitt merged commit afcff73 into master Nov 1, 2026
26 checks passed
@cknitt
cknitt deleted the deriving-dispatch branch November 1, 2026 13:30
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