Skip to content

Annotate the stdlib's runtime classes - #8948

Merged
cknitt merged 2 commits into
instanceof-typeof-annotationsfrom
stdlib-instanceof-annotations
Oct 22, 2026
Merged

cknitt merged 2 commits 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.19%. Comparing base (16ee5bb) to head (25a5ddc).
⚠️ Report is 2 commits behind head on instanceof-typeof-annotations.

Additional details and impacted files
@@                        Coverage Diff                        @@
##           instanceof-typeof-annotations    #8948      +/-   ##
=================================================================
- Coverage                          81.22%   81.19%   -0.04%     
=================================================================
  Files                                457      457              
  Lines                              64027    64027              
=================================================================
- Hits                               52008    51986      -22     
- Misses                             12019    12041      +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.

@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: 25a5ddc

cknitt and others added 2 commits October 22, 2026 16:57
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>
Why:
    With the stdlib annotated, `Blob.t` and `File.t` are never undefined
    and #8938 is fixed, which the spec and its test still stated the other
    way round.

Rule 5 lists the stdlib's annotations, rule 12 unboxes `option` of a
variant with a `Blob.t` payload, and the known bug of overlapping classes is
gone. The typed-array bug stays, filed as #8955.

Representation modified (option of a variant with a Blob payload):
Example:
    @unboxed type withBlob = BBlob(Blob.t) | BString(string)
    let someWithBlob = (v: withBlob): option<withBlob> => Some(v)
Before (js): return Primitive_option.some(v);
After (js): return v;

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 42175d8 to 25a5ddc Compare October 22, 2026 17:01
@cknitt
cknitt merged commit 25a5ddc into master Oct 22, 2026
30 of 46 checks passed
@cknitt
cknitt deleted the stdlib-instanceof-annotations branch October 22, 2026 18:46
@cknitt

cknitt commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

Folded into #8950: the mechanism and the stdlib annotations land together. GitHub shows this PR as merged because #8950's branch now contains its commits; nothing reached master. #8949 is now based on #8950.

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