Skip to content

Annotate the stdlib's runtime classes - #8948

Open
cknitt wants to merge 1 commit into
instanceof-typeof-annotationsfrom
stdlib-instanceof-annotations
Open

cknitt wants to merge 1 commit into
instanceof-typeof-annotationsfrom
stdlib-instanceof-annotations

Conversation

@cknitt

@cknitt cknitt commented Oct 21, 2026

Copy link
Copy Markdown
Member

Fixes #8938. Stacked on the @instanceOf/@typeOf PR.

The stdlib's class-backed types now declare their class instead of only @notUndefined:

  • Classes: ArrayBuffer, DataView, Date, RegExp, Map, Set, WeakMap, WeakSet, JsError (Error), and the Intl classes (Intl.Collator, Intl.DateTimeFormat, Intl.ListFormat, Intl.Locale, Intl.NumberFormat, Intl.PluralRules, Intl.RelativeTimeFormat, Intl.Segmenter) get @instanceOf.
  • Symbols: Symbol.t gets @typeOf("symbol").
  • Typed arrays: each typed array alias gets its own @instanceOf.
  • File and Blob: Blob.t gets @instanceOf("Blob"), and File.t becomes @instanceOf("File") type t = private Blob.t. A file is now known to be a blob, so a Blob case excludes files, and (file :> Blob.t) upcasts.

JsError.t, Symbol.t and the Intl classes can now be untagged variant cases, which they couldn't before.

Unchanged, because their values have no single class or typeof, so they keep @notUndefined:

  • Jsx.element and Jsx.component: anything React accepts.
  • Iterator/AsyncIterator: protocol objects.
  • TypedArray.t<'a>: %TypedArray% is not a global.
  • Intl.Segments: no global constructor.
  • Intl.NumberFormat.Grouping: a boolean or a string.
  • Lazy.

Generated code changes only where Blob and File cases meet: in UntaggedVariants.mjs, the Blob case now excludes files.

Test: tests/tests/src/untagged_file_blob_test.res declares Blob before File, and checks a Blob case matched alone and the upcast.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Fc7LEuyEfynjaKCVEBPmTF

@cknitt
cknitt added this pull request to stack #8951 October 21, 2026 18:14
@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.18%. Comparing base (dbe05fb) to head (42175d8).

Additional details and impacted files
@@                        Coverage Diff                        @@
##           instanceof-typeof-annotations    #8948      +/-   ##
=================================================================
- Coverage                          81.21%   81.18%   -0.04%     
=================================================================
  Files                                457      457              
  Lines                              63927    63927              
=================================================================
- Hits                               51921    51899      -22     
- Misses                             12006    12028      +22     

see 2 files 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.

Why:
    Untagged variants recognized stdlib classes only by type name, with no
    relation between them, so a `Blob` case declared before a `File` case
    also caught files (#8938).

Types whose values are instances of a global class now say so with
`@instanceOf` instead of `@notUndefined`, `Symbol.t` with
`@typeOf("symbol")`, and `File.t` is a private abbreviation of `Blob.t`.
`JsError.t`, `Symbol.t` and the `Intl` classes can be untagged variant
cases too. Fixes #8938.

JS modified (Blob and File cases):
Example:
    @unboxed
    type upload = Blob(Blob.t) | File(File.t)

    let kind = upload =>
      switch upload {
      | Blob(_) => "blob"
      | File(_) => "file"
      }
Before (js):
    if (upload instanceof Blob) {
      return "blob";
    } else {
      return "file";
    }
After (js):
    if (upload instanceof Blob && !(upload instanceof File)) {
      return "blob";
    } else {
      return "file";
    }

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Fc7LEuyEfynjaKCVEBPmTF
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the stdlib-instanceof-annotations branch from 1107e5d to 42175d8 Compare October 21, 2026 18:22
@github-actions

Copy link
Copy Markdown

@cknitt

cknitt commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 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-10-21T18:33:17.170195Z 42175d8 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. You're on a roll.

Reviewed commit: 42175d89af

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

@pkg-pr-new

pkg-pr-new Bot commented Oct 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 42175d8

@cknitt
cknitt requested a review from cristianoc October 21, 2026 19:23
@cknitt
cknitt marked this pull request as ready for review October 21, 2026 19:23

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.

Untagged variant with Blob and File cases never matches File when Blob is declared first

1 participant