Skip to content

Check compiler-flags when a build starts - #9304

Draft
cknitt wants to merge 1 commit into
masterfrom
validate-compiler-flags
Draft

cknitt wants to merge 1 commit into
masterfrom
validate-compiler-flags

Conversation

@cknitt

@cknitt cknitt commented Nov 14, 2026

Copy link
Copy Markdown
Member

Step 1 of #9303.

The build system passed compiler-flags from rescript.json to the compiler unchecked:

  • An unknown flag failed every module with the same "Unknown option" error.
  • A flag the build system sets itself, such as -bs-ns, silently conflicted with its own.

A build now checks each package's flags once, before compiling, and reports a problem as an error in that rescript.json:

rescript.json: field "compiler-flags": unknown flag "-bs-fooo"
rescript.json: field "compiler-flags": flag "-open" needs a value
rescript.json: field "compiler-flags": "Belt" is not a flag
rescript.json: field "compiler-flags": flag "-bs-ns" is set by the build system
rescript.json: field "compiler-flags": flag "-v" does not compile a module
  • Rescript_compiler_driver.check_flags walks the flags against bsc's own flag table, like the parser does, but doesn't apply them. Some flags act as soon as they're parsed: -e compiles a string, -v prints and exits, -format reads a file.
  • Flag values, such as warning specs, are not checked yet. That comes with the typed request in the next step of Pass a typed compile request from the build system to the compiler, and validate user compiler flags #9303.
  • The build system owns the reserved lists: the flags it passes itself, and the flags with which bsc doesn't compile.
  • format, clean and compiler-args don't check the flags, so a bad flag doesn't stop formatting.

Tests

  • rewatch/tests/compile/25-invalid-compiler-flags.sh: each kind of error. It also checks that formatting ignores the flags and that valid flags still build.
  • Unit tests for check_flags, including values that start with a dash and a reserved flag's name used as a value.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gHAzsdStoCEpBgx2tS

Why:
    The build system passed the entries of compiler-flags to the compiler
    unchecked. An unknown flag failed every module with the same error,
    and a flag that the build system sets itself, such as -bs-ns, silently
    conflicted with its own. A build now checks the flags of every package
    against the compiler's flag table once, without applying them. Format,
    clean and compiler-args don't compile, so they don't check them.

Diagnostic added (unknown compiler flag):
Example:
    // rescript.json
    {"name": "flags", "sources": ["src"], "compiler-flags": ["-bs-fooo"]}
Before (diagnostic):
    Unknown option "-bs-fooo".
    (for every module)
After (diagnostic):
    rescript.json: field "compiler-flags": unknown flag "-bs-fooo"

The other new errors: a flag without its value, a value where a flag is
expected, a flag the build system sets itself (-o, -bs-ns,
-bs-package-name, -bs-package-output, -bs-project-root, -bs-read-cmi,
-bs-ast, -runtime-path), and a flag with which the compiler does not
compile (-e, -v, -version, -warn-help, -format, -reprint-source).

Review: Why not run the flag parser on the flags? Some flags act when
    parsed: -e compiles a string, -v prints and exits, -format reads a
    file. Values such as warning specs are checked once a typed request
    replaces the flag strings (#9303).

Part of #9303

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

Copy link
Copy Markdown

Changelog

💅 Polish

  • Report an unknown flag, a flag without its value, or a flag the build system sets itself in compiler-flags once, as an error in rescript.json, instead of failing every module.

Semantic Diff

1 commit · Full page

Check compiler-flags when a build starts

84940e7 · cknitt + Claude · Nov 14, 2026, 09:37 UTC

Why

The build system passed the entries of compiler-flags to the compiler unchecked. An unknown flag failed every module with the same error, and a flag that the build system sets itself, such as -bs-ns, silently conflicted with its own. A build now checks the flags of every package against the compiler's flag table once, without applying them. Format, clean and compiler-args don't compile, so they don't check them.

Diagnostic added (unknown compiler flag)

// rescript.json
{"name": "flags", "sources": ["src"], "compiler-flags": ["-bs-fooo"]}

diagnostic

-Unknown option "-bs-fooo".
-(for every module)
+rescript.json: field "compiler-flags": unknown flag "-bs-fooo"

The other new errors: a flag without its value, a value where a flag is expected, a flag the build system sets itself (-o, -bs-ns, -bs-package-name, -bs-package-output, -bs-project-root, -bs-read-cmi, -bs-ast, -runtime-path), and a flag with which the compiler does not compile (-e, -v, -version, -warn-help, -format, -reprint-source).

Part of #9303

Review

@codecov

codecov Bot commented Nov 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 58.33333% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.06%. Comparing base (1efa212) to head (84940e7).

Files with missing lines Patch % Lines
compiler/bsc/rescript_compiler_driver.ml 58.33% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9304      +/-   ##
==========================================
- Coverage   82.06%   82.06%   -0.01%     
==========================================
  Files         455      455              
  Lines       65399    65411      +12     
==========================================
+ Hits        53672    53679       +7     
- Misses      11727    11732       +5     
Files with missing lines Coverage Δ
compiler/bsc/rescript_compiler_driver.ml 80.00% <58.33%> (-0.92%) ⬇️
🚀 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.

@github-actions

Copy link
Copy Markdown

✅ Compiler benchmarks

Allocated words

In total: 640,953,454 → 640,960,318 (±0.00%).

Generated projects: 920,897,697 → 920,902,093 (±0.00%).

None of the 265 benchmarks changed by 0.1% or more.

Instructions

In total: 9,209,713,949 → 9,209,427,884 (±0.00%).

None of the 33 benchmarks changed by 0.1% or more.

Output size

In total: 25,843,406 → 25,843,406 (±0.00%).

None of the 13 benchmarks changed by 0.1% or more.

Pull request 84940e7 compared with base 1efa212 in this run.

@pkg-pr-new

pkg-pr-new Bot commented Nov 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 84940e7

@github-actions

Copy link
Copy Markdown

@cknitt

cknitt commented Nov 14, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T10:00:42.531707Z 84940e7 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 84940e72bc

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

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