Skip to content

Read @throws from library declarations in exception analysis - #9198

Open
cknitt wants to merge 5 commits into
masterfrom
drift-9182-temporal-exn
Open

cknitt wants to merge 5 commits into
masterfrom
drift-9182-temporal-exn

Conversation

@cknitt

@cknitt cknitt commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

The exception analysis knew what library functions throw only from a hand-kept table in analysis/reanalyze/src/exn_lib.ml, and that table drifted. #9182 is the example: the eight Temporal fromStringOrThrow functions were never added, so rescript-tools reanalyze -exception treated Temporal.PlainDate.fromStringOrThrow("x") as throwing nothing. A few Intl and Belt functions were missing as well. Third-party libraries, and a project's own externals, had no way to declare their exceptions at all.

Fixes #9182

The new rule

At each call, the analysis reads @throws(...) from the declaration of the value being called. The .cmi keeps the attributes of externals and interface declarations, so their @throws reaches calls from other modules and packages. It also survives module aliases, open, include, functor results and first-class modules.

A call's exceptions are declared(f) ∪ values(f): the declaration's @throws, together with the values-table entry (the @throws on the implementation's own binding, as before). There is no table any more. I chose the union over letting one source win because either source can be the only one written down. An annotated .resi let whose .res binding isn't annotated is a common case, and a call can throw whatever either source names.

A @throws without a payload still means nothing, as it always has on bindings.

Compiler: resolving the names in @throws

A @throws(E) names an exception as written, and which exception that is depends on the opens, aliases and includes in scope. Reanalyze cannot work that out, because a .cmt keeps no environments. So the type checker resolves the names where they are written: for externals, lets in signatures and interfaces (including module types and functor parameters), and every let binding. It adds a generated @res.throws attribute listing each exception's readable name and identity, and the inferred signature keeps it next to @throws. The new module is compiler/ml/throws_attribute.ml.

The identity is the path of the defining source file as the compiler was given it (absolute in a rewatch build), without the extension, plus the exception's name, as src/Lib#E. It is the same through every alias, open, include and functor, and for a module's .res and .resi. A file compiled with -no-keep-locs, as the runtime and Belt are, keeps no locations in its .cmi, so its exceptions are identified by name alone (#Undefined), also while that file itself is compiled.

Exception analysis compares these identities with the constructors that catches and throws use. Messages name an exception by its full path (Lib.Inner.F), leaving out the current file's name for its own, so the annotation a message suggests resolves. For that, Typemod records which module of the current file defines each exception and module.

The type checker loads the modules a @throws names, so Depend now counts them as dependencies, like any other use, and the build compiles them first. This is the one breaking change: a module named in @throws that itself depends on the annotating module is now a dependency cycle.

A name that is not an exception in scope gets the new warning 113 (on by default, not an error, once per name) and is listed as written. The @throws payload may be one name, or an array, tuple or list{...} of names.

Known limits: a rebinding (exception Mine = Lib.E) is a new definition, so catching Mine does not catch Lib.E, as on master. Exceptions with the same name in one file share an identity, as do the exceptions of two applications of one functor and same-named exceptions of -no-keep-locs files.

Compiler: @throws in inferred signatures

A let in a module without an interface used to lose its attributes in the inferred signature, so its @throws couldn't reach other modules. That is why Stdlib.panic needed the table. Typemod.type_structure already copied a binding's @deprecated into the signature item (#8924). It now copies the @throws attributes the same way, into the signature only. Only @throws is copied: #9210 removed the other spellings (@throw, @raises, @raise) from reanalyze.

Other attributes stay out on purpose. A doc comment is an attribute, and having it in the .cmi would make editing a comment recompile the module's dependents. A module with a .resi is unaffected, because its .cmi holds the interface's declarations. The test below checks that an annotated binding behind an unannotated .resi is still not reported through the signature. The .cmi format and magic numbers are unchanged.

What moved into the sources

Every stdlib and Belt declaration the table listed now carries its own annotation, in its .resi or, where a module has none, in the .res:

  • the getExn/getOrThrow family across Belt's collections (including the .res-only internal ones), Option and Result
  • Belt.Array.getExn/setExn (Assert_failure)
  • List, Null, Nullable, Option, Result, Bool and BigInt *OrThrow
  • JSON.parseOrThrow and stringifyAny
  • the JsError throwers
  • / and mod (Division_by_zero)
  • Stdlib.panic and Stdlib.assertEqual

The functions #9182 found missing are annotated too: the Temporal fromStringOrThrow, the Intl *Exn externals, Belt.MutableStack.popOrThrow, and Belt.Map.Dict/Belt.Set.Dict getOrThrow.

One correction: the old table said assertEqual throws JsExn, but it is implemented with assert(false), which throws Assert_failure. The annotation now says Assert_failure. The two payload-less @throws in Stdlib_JSON.res now name JsExn.

The only change to generated JavaScript is the line number inside assertEqual's Assert_failure in Stdlib.mjs/Stdlib.cjs, which moved because a line was added above it.

I deliberately left unannotated the functions that throw only for some arguments and whose names don't say so: Temporal constructors and arithmetic, Int.range with step 0, and Date.toTemporalInstant on an invalid date. Annotating them would flag every call to them. The % operator, the same primitive as mod, was never in the table, and I've left it as it was.

exn_lib.ml is deleted, along with the Yojson stub, its test and the empty BsJson.res. Calls to bs-json or Yojson functions are reported only if those libraries annotate their declarations.

Guard

tests/analysis_tests/tests-reanalyze/checkThrowsAnnotations.mjs runs at the start of the reanalyze test.sh. It fails when a stdlib or Belt value named *OrThrow or *Exn has no @throws(...) with a payload. It checks the module's .resi, or every let and external of a .res that has no interface. JsError.toJsExn is allowlisted because it converts a value and throws nothing. Removing a single annotation makes the guard fail.

Tests

  • src/exception/ThrowsDecl.res, ThrowsIface.res/.resi and ThrowsDeclCalls.res are new. Calls from another module to an annotated external, a nested external, an annotated .resi let (whose .res binding is unannotated), a .resi external, and a module type's let reached through a functor and a first-class module are reported. So are calls made through a pipe, an alias, open and include.
    • callViaLetIncluded calls an annotated let in a .res without an interface, through an include, so the values table can't see it. It is reported only because of the typemod change.
    • callImplOnlyIncluded shows that a .resi without @throws still wins over an annotated .res binding.
  • StdlibTest.res and BeltTest.res keep the cases from the first version of this PR. They also cover panic and assertEqual, which reach calls through the new signature attributes, plus JsError.RangeError.throwWithMessage, List.headOrThrow, Bool.fromStringOrThrow, Nullable.getOrThrow, JSON.stringifyAny, Belt.Array.getExn and Belt.MutableQueue.popOrThrow.
  • ThrowsLibExn.res/ThrowsLibExnCalls.res, ThrowsErrors.res/ThrowsRepo.res/ThrowsRepoCalls.res and ThrowsReexport.res cover exception names: a library's own exception caught by its qualified name, through open, an alias, a rebind and an include; a caller's own E not catching the library's E; a @throws naming a third module's exception; and a binding's own @throws written after open or through an alias. UseS calls through a functor parameter, and catchRebound shows the rebinding limit.
  • ThrowsScopes.res (with ThrowsIfaceOpen.res/.resi and ThrowsAlias.res) covers an interface whose @throws comes after an open, an alias of an alias in another file, an include of an include, a functor body's own exception, a list{...} payload, and Lazy.Undefined from the runtime (no locations). uncaughtNested and uncaughtLocal in ThrowsLibExnCalls.res pin the full names in messages, and annotatedLocal follows the suggestion.
  • tests/build_tests/super_errors/fixtures/throws_unbound_warning.res shows warning 113 for an unknown name and for a constructor that is not an exception, once for a destructuring let, and none for a payload-less @throws or under @warning("-113").
  • tests/build_tests/throws_dependency builds a module that names another only in @throws; before the Depend change the build order left the name unresolved.
  • ExnPayloadGuard.res takes over TestYojson.res's case: catching an exception with a payload pattern and a guard, using its own exception.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gGhHjzBTXqSo8Dckpb

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Changelog

🚀 New Feature

  • Exception analysis reads @throws from library and external declarations, including third-party ones, instead of a built-in list, and a @throws on a let now reaches other modules even without an interface.

Semantic Diff

1 commit · Full page

Read @throws from library declarations in exception analysis

1d38461 · cknitt + Claude · Nov 03, 2026, 18:23 UTC

Why

The exception analysis knew what library functions throw only from a table kept by hand in exn_lib.ml. The table drifted: the Temporal fromStringOrThrow functions were never added (#9182), and neither were a few Intl and Belt ones. Third-party libraries and a project's own externals had no way to say what they throw.

A call now takes the exceptions named by the @throws on the declaration of the value it calls, and the table is gone. The .cmi keeps the attributes of externals and interface declarations, so their @throws reaches calls in other modules and packages, through aliases, open, include, functors and first-class modules. For a let in a module without an interface, the type checker now copies the binding's @throws into the inferred signature, as it already did for @deprecated. The stdlib and Belt declare what their throwing functions throw, and a guard in the reanalyze tests fails when a stdlib or Belt *OrThrow or *Exn declaration has no @throws(...).

Analysis modified (exceptions of a call to f, Exception.Event loop)

rule

BeforeAfter
$$\begin{array}{l}\color{red}{\mathrm{throws}(\texttt{f})=\mathrm{values}(\texttt{f})} \qquad \color{red}{\mathrm{when}\ \texttt{f}\ \mathrm{is}\ \mathrm{in}\ \mathrm{the}\ \mathrm{values}\ \mathrm{table}} \\ \color{red}{\mathrm{throws}(\texttt{f})=\mathrm{table}(\texttt{f})} \qquad \color{red}{\mathrm{otherwise}}\end{array}$$ $$\begin{array}{l}\color{green}{\mathrm{throws}(\texttt{f})=\mathrm{declared}(\texttt{f})∪\mathrm{values}(\texttt{f})}\end{array}$$

Signature modified (inferred signature of a module without an interface, Typemod.type_structure)

/** Finds the value. */
@throws(Not_found)
let find = x => x > 0 ? x : throw(Not_found)

rescript · Before: the signature in the .cmi

+@throws(Not_found)
 let find: int => int

Reanalyze modified (calls to annotated externals)

// Lib.res
@throws(JsExn)
external parse: string => int = "parseInt"

// App.res
let parse = s => Lib.parse(s)

@throws(JsExn)
let parseAnnotated = s => Lib.parse(s)

let date = () => Temporal.PlainDate.fromStringOrThrow("x")

reanalyze

-Exception Analysis
-App.res:4:5-18
-parseAnnotated throws nothing and is annotated with redundant @throws(JsExn)
 
-Analysis reported 1 issues (Exception Analysis:1)
 
+Exception Analysis
+App.res:1:5-9
+parse might throw JsExn (App.res:1:17) and is not annotated with @throws(JsExn)
 
+Exception Analysis
+App.res:6:5-8
+date might throw JsExn (App.res:6:17) and is not annotated with @throws(JsExn)
 
+Analysis reported 2 issues (Exception Analysis:2)

Fixes #9182

Review

  • Why the union of the declaration and the values table, rather than one winning? The values table holds the @throws on the implementation's binding, the declaration the one in its interface. Either can be the only one written, as with an annotated .resi let whose .res isn't annotated, so the call can throw what either names.
  • Why does the inferred signature take only the @throws family and @deprecated, and not every attribute? A doc comment is an attribute too: in the .cmi it would make editing a comment recompile the module's dependents. A module with a .resi is unchanged, since its .cmi holds the interface's declarations.
  • What does a @throws without a payload mean? Nothing, as on a binding. The guard requires a payload, and the stdlib's two payload-less @throws in Stdlib_JSON.res now name JsExn.

@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.82390% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.22%. Comparing base (643e9c0) to head (629ea53).

Files with missing lines Patch % Lines
compiler/typing/throws_attribute.ml 85.18% 12 Missing ⚠️
analysis/reanalyze/src/exn.ml 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9198      +/-   ##
==========================================
+ Coverage   82.21%   82.22%   +0.01%     
==========================================
  Files         460      460              
  Lines       65551    65660     +109     
==========================================
+ Hits        53891    53989      +98     
- Misses      11660    11671      +11     
Files with missing lines Coverage Δ
analysis/reanalyze/src/exception.ml 82.47% <100.00%> (+0.90%) ⬆️
analysis/reanalyze/src/exceptions.ml 92.85% <ø> (ø)
compiler/typing/depend.ml 88.23% <100.00%> (+0.28%) ⬆️
compiler/typing/typecore.ml 89.13% <100.00%> (+<0.01%) ⬆️
compiler/typing/typedecl.ml 83.71% <100.00%> (+0.01%) ⬆️
compiler/typing/typemod.ml 77.63% <100.00%> (+0.53%) ⬆️
compiler/typing/warnings.ml 76.32% <100.00%> (+0.19%) ⬆️
analysis/reanalyze/src/exn.ml 91.66% <91.66%> (-8.34%) ⬇️
compiler/typing/throws_attribute.ml 85.18% <85.18%> (ø)

... and 4 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.

@pkg-pr-new

pkg-pr-new Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 629ea53

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

@cknitt
cknitt force-pushed the drift-9182-temporal-exn branch from 0a37396 to 9b3d665 Compare November 3, 2026 18:59
@cknitt cknitt changed the title Know the Temporal fromStringOrThrow and other missing throwing functions in exception analysis Read @throws from library declarations in exception analysis Nov 3, 2026
@cknitt

cknitt commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 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-19T19:01:39.425896Z b0666ce 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. Swish!

Reviewed commit: 9b3d66507a

ℹ️ 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 force-pushed the drift-9182-temporal-exn branch from 9b3d665 to 76f8a78 Compare November 3, 2026 19:40
@cknitt

cknitt commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 76f8a7895a

ℹ️ 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 force-pushed the drift-9182-temporal-exn branch 2 times, most recently from 68c774c to 1d38461 Compare November 3, 2026 19:59
@cknitt
cknitt requested a review from cristianoc November 3, 2026 20:14
@cknitt
cknitt marked this pull request as ready for review November 3, 2026 20:14
@cknitt
cknitt force-pushed the drift-9182-temporal-exn branch from 1d38461 to 18ed190 Compare November 10, 2026 16:18
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Changelog

💥 Breaking Change

  • A module named in @throws is now a dependency of the module that names it, so a dependency cycle through such a name is an error. Move the exception to a module of its own.

🚀 New Feature

  • Exception analysis reads @throws from library and external declarations, including third-party ones, instead of a built-in list (which also covered bs-json and Yojson), and a @throws on a let now reaches other modules even without an interface.
  • The compiler resolves the exceptions a @throws names where it is written, so exception analysis matches them with catches through opens, aliases, includes and functors, and warns (warning 113) about a name that is not an exception in scope.

Semantic Diff

5 commits · Full page

Read @throws from library declarations in exception analysis

d110acf · cknitt + Claude · Nov 03, 2026, 18:23 UTC

Why

The exception analysis knew what library functions throw only from a table kept by hand in exn_lib.ml. The table drifted: the Temporal fromStringOrThrow functions were never added (#9182), and neither were a few Intl and Belt ones. Third-party libraries and a project's own externals had no way to say what they throw.

A call now takes the exceptions named by the @throws on the declaration of the value it calls, and the table is gone. The .cmi keeps the attributes of externals and interface declarations, so their @throws reaches calls in other modules and packages, through aliases, open, include, functors and first-class modules. For a let in a module without an interface, the type checker now copies the binding's @throws into the inferred signature, as it already did for @deprecated. The stdlib and Belt declare what their throwing functions throw, and a guard in the reanalyze tests fails when a stdlib or Belt *OrThrow or *Exn declaration has no @throws(...).

Analysis modified (exceptions of a call to f, Exception.Event loop)

rule

BeforeAfter
$$\begin{array}{l}\color{red}{\mathrm{throws}(\texttt{f})=\mathrm{values}(\texttt{f})} \qquad \color{red}{\mathrm{when}\ \texttt{f}\ \mathrm{is}\ \mathrm{in}\ \mathrm{the}\ \mathrm{values}\ \mathrm{table}} \\ \color{red}{\mathrm{throws}(\texttt{f})=\mathrm{table}(\texttt{f})} \qquad \color{red}{\mathrm{otherwise}}\end{array}$$ $$\begin{array}{l}\color{green}{\mathrm{throws}(\texttt{f})=\mathrm{declared}(\texttt{f})∪\mathrm{values}(\texttt{f})}\end{array}$$

Signature modified (inferred signature of a module without an interface, Typemod.type_structure)

/** Finds the value. */
@throws(Not_found)
let find = x => x > 0 ? x : throw(Not_found)

rescript · Before: the signature in the .cmi

+@throws(Not_found)
 let find: int => int

Reanalyze modified (calls to annotated externals)

// Lib.res
@throws(JsExn)
external parse: string => int = "parseInt"

// App.res
let parse = s => Lib.parse(s)

@throws(JsExn)
let parseAnnotated = s => Lib.parse(s)

let date = () => Temporal.PlainDate.fromStringOrThrow("x")

reanalyze

-Exception Analysis
-App.res:4:5-18
-parseAnnotated throws nothing and is annotated with redundant @throws(JsExn)
 
-Analysis reported 1 issues (Exception Analysis:1)
 
+Exception Analysis
+App.res:1:5-9
+parse might throw JsExn (App.res:1:17) and is not annotated with @throws(JsExn)
 
+Exception Analysis
+App.res:6:5-8
+date might throw JsExn (App.res:6:17) and is not annotated with @throws(JsExn)
 
+Analysis reported 2 issues (Exception Analysis:2)

Fixes #9182

Review

  • Why the union of the declaration and the values table, rather than one winning? The values table holds the @throws on the implementation's binding, the declaration the one in its interface. Either can be the only one written, as with an annotated .resi let whose .res isn't annotated, so the call can throw what either names.
  • Why does the inferred signature take only the @throws family and @deprecated, and not every attribute? A doc comment is an attribute too: in the .cmi it would make editing a comment recompile the module's dependents. A module with a .resi is unchanged, since its .cmi holds the interface's declarations.
  • What does a @throws without a payload mean? Nothing, as on a binding. The guard requires a payload, and the stdlib's two payload-less @throws in Stdlib_JSON.res now name JsExn.
Drop the empty BsJson module from the deadcode debug snapshot

2293610 · cknitt + Claude · Nov 10, 2026, 17:30 UTC

Why

Since #9245 every .cmt lands in the flat lib/rescript, so the empty src/exception/BsJson.res logged "Implementation 0" in the deadcode debug output. This PR deletes that file, so the line goes away.

Resolve the exceptions @throws names in the type checker

172814c · cknitt + Claude · Nov 19, 2026, 08:01 UTC

Why

Review on #9198: a library's @throws(E) reached callers as the bare name E, while a catch was compared as written (Lib.E), so a correct catch was still reported and a caller's own E could hide the library's. Reanalyze cannot resolve names itself, because a .cmt keeps no environments; two attempts to guess the scope from the file still got opens in interfaces, functors, includes and aliases wrong.

The type checker now looks up each name in a @throws where it is written, for externals, lets in signatures and interfaces, and every let binding. It adds a generated @res.throws that lists each exception's readable name and identity, and the inferred signature keeps it next to @throws. The identity is the defining file without its extension and the exception's name (src/Lib#E), so a module's .res and .resi agree and moving a definition within its file changes nothing. Exception analysis compares these identities with the constructors that catches and throws name.

A name that is not an exception in scope gets the new warning 113 and is listed as written. A rebinding (exception Mine = Lib.E) is a new definition, so catching Mine does not catch Lib.E, as before. Two exceptions with the same name in one file share an identity.

Typedtree modified (@throws resolved where it is written)

module Errors = {
  exception NotFound
}
open Errors
@throws(NotFound)
external find: int => int = "find"

typed

 Tstr_primitive
 value_description find/1003
   attribute "throws"
       structure_item
         Pstr_eval
         expression
           Pexp_construct "NotFound"
           []
+  attribute "res.throws"
+      structure_item
+        Pstr_eval
+        expression
+          Pexp_array
+            expression
+              Pexp_tuple
+                expression
+                  Pexp_constant PConst_string (source="Repo.Errors.NotFound", semantic="Repo.Errors.NotFound")
+                expression
+                  Pexp_constant PConst_string (source="Repo#NotFound", semantic="Repo#NotFound")

Diagnostic added (warning 113)

@throws(Missing)
let f = () => 1

diagnostic · After · tests/build_tests/super_errors/fixtures/throws_unbound_warning.res

Warning number 113
throws_unbound_warning.res:3:9-15

@throws names Missing, which is not an exception in scope here. Exception analysis cannot match it with the exceptions callers catch.

Reanalyze modified (catches of another module's exceptions)

// ThrowsLibExn.res
exception E
@throws(E)
external parse: string => int = "parseThrowing"

// ThrowsLibExnCalls.res
let catchExternal = s =>
  try ThrowsLibExn.parse(s) catch {
  | ThrowsLibExn.E => 0
  }

reanalyze · tests/analysis_tests/tests-reanalyze/deadcode/src/exception

-Exception Analysis
-ThrowsLibExnCalls.res:4:5-17
-catchExternal might throw E (ThrowsLibExnCalls.res:5:6) and is not annotated with @throws(E)
 
-Exception Analysis
-ThrowsRepoCalls.res:18:5-16
-catchViaOpen might throw Bad (ThrowsRepoCalls.res:19:6) and is not annotated with @throws(Bad)
 
-Exception Analysis
-ThrowsScopes.res:2:5-18
-catchIfaceOpen might throw NotFound (ThrowsScopes.res:3:6) and is not annotated with @throws(NotFound)
 
-Exception Analysis
-ThrowsLibExnCalls.res:103:7-12
-caught might throw E (ThrowsLibExnCalls.res:104:8) and is not annotated with @throws(E)
 
 …
 
-Exception Analysis
-ThrowsLibExnCalls.res:81:5-16
-catchRebound might throw E (ThrowsLibExnCalls.res:82:6) and is not annotated with @throws(E)
 
+Exception Analysis
+ThrowsLibExnCalls.res:81:5-16
+catchRebound might throw ThrowsLibExn.E (ThrowsLibExnCalls.res:82:6) and is not annotated with @throws(ThrowsLibExn.E)

Review

  • Why an identity from the file and name instead of the path? The type checker has no module prefix for a file's own exceptions, and a path changes with aliases and namespaces. The file and name are the same through every alias, open, include and functor, and in the .res and .resi.
  • Does this recompile more? Only the attribute is new, and it holds names, not positions, so it changes only when the exception is renamed or moves to another file.
Read list payloads in @throws and name location-less exceptions explicitly

60f3830 · cknitt + Claude · Nov 19, 2026, 19:04 UTC

Why

Codex review on #9198: the compiler's new @throws reader dropped list{A, B} payloads and constructors written with arguments, which reanalyze's old reader accepted, so such annotations silently stopped declaring anything. It also derived an exception's identity from a location that a .cmi built with -no-keep-locs (the runtime's and Belt's) does not keep.

The reader again takes list{...} and M.E(...) as before. An exception whose .cmi has no locations is now identified as #Name on purpose, rather than through the placeholder file name _none_. Codex's crash report for that case does not hold, since Filename.remove_extension does not raise on _none_, but the identity was accidental.

AST modified (res.throws for a list payload)

exception E
@throws(list{E, Not_found})
let f = () => throw(E)

text · number of res.throws attributes in bsc -dtypedtree

-0
+1
Make modules named in @throws dependencies and name nested exceptions exactly

629ea53 · cknitt + Claude · Nov 19, 2026, 19:19 UTC

Why

Review of #9198: the type checker loads the module a @throws names, but the dependency scanner skipped attributes. A module named only there was built in any order, so the name resolved or got warning 113 depending on the build, and a later edit could fail with "inconsistent assumptions". Messages also named an exception defined in a nested module without that module, so the annotation they suggested did not resolve. And a library built with -no-keep-locs recorded its own exceptions with its file, while its users see them without one.

Depend now adds the modules a @throws names, like any other use, so they are built first. A module that is both named in @throws and depends on the annotating module now gives a dependency cycle error.

Typemod records which module of the current file defines each exception and module, so a file's own exception is named Lib.Inner.F. Under -no-keep-locs a file's own exceptions are identified by name alone also while it is compiled. Warning 113 is shown once for a let that destructures a tuple.

Diagnostic modified (an exception of a nested module)

// ThrowsLibExn.res
module Inner = {
  exception F
  @throws(F)
  external find: int => int = "findThrowing"
}

// ThrowsLibExnCalls.res
let uncaughtNested = x => ThrowsLibExn.Inner.find(x)

reanalyze · tests/analysis_tests/tests-reanalyze/deadcode/src/exception/ThrowsLibExnCalls.res

-Exception Analysis
-ThrowsLibExnCalls.res:110:5-18
-uncaughtNested might throw ThrowsLibExn.F (ThrowsLibExnCalls.res:110:26) and is not annotated with @throws(ThrowsLibExn.F)
 
+Exception Analysis
+ThrowsLibExnCalls.res:110:5-18
+uncaughtNested might throw ThrowsLibExn.Inner.F (ThrowsLibExnCalls.res:110:26) and is not annotated with @throws(ThrowsLibExn.Inner.F)

Diagnostic modified (a module named only in @throws, tests/build_tests/throws_dependency)

// A.res
@throws(Z.E)
external find: int => int = "find"

// Z.res
exception E

diagnostic · Before: A.res built before Z.res

-Warning number 113
-@throws names Z.E, which is not an exception in scope here. Exception analysis cannot match it with the exceptions callers catch.
+Z.res built first, no warning

⚠️ Breaking: A module named in @throws that itself depends on the annotating module is now a dependency cycle. Move the exception to a module of its own.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

✅ Compiler benchmarks

Allocated words

In total: 636,516,783 → 637,517,152 (+0.16%).

Generated projects: 629,041,764 → 629,721,508 (+0.11%).

Benchmark Base Head Change
packages/@rescript/runtime/Stdlib_JsError.resi (inputs changed) 184,968 194,700 +5.26%
packages/@rescript/belt/src/Belt_MutableQueue.resi (inputs changed) 207,326 212,166 +2.33%
packages/@rescript/runtime/Stdlib_Intl.res (inputs changed) 173,862 177,753 +2.24%
packages/@rescript/runtime/Stdlib_Bool.resi (inputs changed) 116,818 118,395 +1.35%
packages/@rescript/runtime/Stdlib_BigInt.resi (inputs changed) 186,569 189,015 +1.31%
packages/@rescript/belt/src/Belt_Result.resi (inputs changed) 240,168 243,260 +1.29%
packages/@rescript/runtime/Stdlib_JSON.resi (inputs changed) 237,027 240,007 +1.26%
packages/@rescript/belt/src/Belt_Option.resi (inputs changed) 243,374 246,242 +1.18%
packages/@rescript/belt/src/Belt_SetString.resi (inputs changed) 259,922 262,873 +1.14%
packages/@rescript/belt/src/Belt_SetInt.resi (inputs changed) 260,049 262,998 +1.13%
234 more changes
Benchmark Base Head Change
packages/@rescript/belt/src/Belt_MutableSetInt.resi (inputs changed) 265,113 268,073 +1.12%
packages/@rescript/belt/src/Belt_MutableSetString.resi (inputs changed) 264,996 267,954 +1.12%
packages/@rescript/runtime/Pervasives.res (inputs changed) 239,805 242,452 +1.10%
packages/@rescript/belt/src/Belt_MutableStack.resi (inputs changed) 169,281 171,120 +1.09%
packages/@rescript/belt/src/Belt_MutableMapInt.resi (inputs changed) 315,111 318,099 +0.95%
packages/@rescript/belt/src/Belt_MutableMapString.resi (inputs changed) 314,993 317,979 +0.95%
packages/@rescript/belt/src/Belt_List.resi (inputs changed) 758,744 765,924 +0.95%
packages/@rescript/runtime/Stdlib_JsError.res (inputs changed) 229,751 231,908 +0.94%
packages/@rescript/runtime/Stdlib_List.resi (inputs changed) 409,863 413,621 +0.92%
packages/@rescript/belt/src/Belt_MutableMap.resi (inputs changed) 395,444 399,010 +0.90%
packages/@rescript/belt/src/Belt_MutableSet.resi (inputs changed) 397,546 401,075 +0.89%
packages/@rescript/belt/src/Belt_Set.resi (inputs changed) 437,438 441,256 +0.87%
packages/@rescript/runtime/Stdlib_JSON.res (inputs changed) 296,903 299,472 +0.87%
packages/@rescript/runtime/Stdlib_Null.resi (inputs changed) 204,431 206,199 +0.86%
packages/@rescript/runtime/Stdlib_Nullable.resi (inputs changed) 199,672 201,307 +0.82%
packages/@rescript/runtime/Stdlib_Temporal.res (inputs changed) 223,963 225,772 +0.81%
packages/@rescript/belt/src/Belt_Array.resi (inputs changed) 650,336 655,550 +0.80%
build/Namespace/edit 7,875,810 7,938,178 +0.79%
packages/@rescript/runtime/Stdlib.res (inputs changed) 980,476 988,238 +0.79%
packages/@rescript/belt/src/Belt_MapString.resi (inputs changed) 391,308 394,321 +0.77%
packages/@rescript/belt/src/Belt_MapInt.resi (inputs changed) 391,351 394,364 +0.77%
packages/@rescript/belt/src/Belt_SetDict.resi (inputs changed) 402,680 405,635 +0.73%
packages/@rescript/runtime/RescriptTools_ExtractCodeBlocks.res (inputs changed) 112,140 112,915 +0.69%
packages/@rescript/runtime/Stdlib_Option.resi (inputs changed) 236,507 238,108 +0.68%
packages/@rescript/belt/src/Belt_Map.resi (inputs changed) 579,471 583,363 +0.67%
packages/@rescript/belt/src/Belt.res (inputs changed) 187,948 189,209 +0.67%
packages/@rescript/runtime/Stdlib_Result.resi (inputs changed) 296,377 298,246 +0.63%
packages/@rescript/runtime/Stdlib_Temporal_Instant.res (inputs changed) 307,599 309,513 +0.62%
packages/@rescript/runtime/Stdlib_Temporal_PlainMonthDay.res (inputs changed) 268,246 269,869 +0.61%
packages/@rescript/belt/src/Belt_MapDict.resi (inputs changed) 513,298 516,306 +0.59%
packages/@rescript/runtime/Primitive_list.resi (inputs changed) 91,887 92,416 +0.58%
packages/@rescript/runtime/Primitive_float_extern.res (inputs changed) 93,687 94,216 +0.56%
packages/@rescript/runtime/RescriptTools.res (inputs changed) 104,517 105,102 +0.56%
packages/@rescript/runtime/Stdlib_Blob.res (inputs changed) 93,905 94,429 +0.56%
packages/@rescript/belt/src/Belt_internalAVLset.resi (inputs changed) 354,869 356,840 +0.56%
packages/@rescript/runtime/Primitive_promise.res (inputs changed) 97,062 97,596 +0.55%
packages/@rescript/belt/src/Belt_Int.resi (inputs changed) 149,771 150,592 +0.55%
packages/@rescript/runtime/Stdlib_File.res (inputs changed) 95,714 96,238 +0.55%
packages/@rescript/runtime/Primitive_int_extern.res (inputs changed) 97,915 98,449 +0.55%
packages/@rescript/runtime/Primitive_string_extern.res (inputs changed) 98,223 98,757 +0.54%
packages/@rescript/belt/src/Belt_Float.resi (inputs changed) 151,251 152,072 +0.54%
packages/@rescript/runtime/Primitive_exceptions.resi (inputs changed) 100,319 100,860 +0.54%
packages/@rescript/runtime/Stdlib_Iterable.resi (inputs changed) 98,169 98,698 +0.54%
packages/@rescript/runtime/Stdlib_AsyncIterable.resi (inputs changed) 98,318 98,847 +0.54%
packages/@rescript/runtime/Stdlib_Iterable.res (inputs changed) 98,944 99,473 +0.53%
packages/@rescript/runtime/Stdlib_AsyncIterable.res (inputs changed) 99,015 99,544 +0.53%
packages/@rescript/runtime/Obj.res (inputs changed) 99,164 99,693 +0.53%
packages/@rescript/runtime/Primitive_hash.resi (inputs changed) 102,744 103,288 +0.53%
packages/@rescript/belt/src/Belt_internalBucketsType.res (inputs changed) 291,615 293,147 +0.53%
packages/@rescript/runtime/Stdlib_Temporal_PlainTime.res (inputs changed) 320,257 321,931 +0.52%
packages/@rescript/runtime/Primitive_module.resi (inputs changed) 103,182 103,721 +0.52%
packages/@rescript/runtime/Primitive_dict.res (inputs changed) 102,715 103,249 +0.52%
packages/@rescript/runtime/Stdlib_Bool.res (inputs changed) 146,012 146,766 +0.52%
parse/Napkinscript.res 10,716,173 10,771,441 +0.52%
packages/@rescript/belt/src/Belt_Float.res (inputs changed) 165,048 165,899 +0.52%
packages/@rescript/belt/src/Belt_Int.res (inputs changed) 165,790 166,641 +0.51%
packages/@rescript/runtime/Stdlib_ArrayBuffer.res (inputs changed) 107,537 108,081 +0.51%
packages/@rescript/runtime/Stdlib_TaggedTemplate.resi (inputs changed) 106,124 106,653 +0.50%
packages/@rescript/belt/src/Belt_HashSetString.resi (inputs changed) 175,553 176,419 +0.49%
packages/@rescript/belt/src/Belt_HashSetInt.resi (inputs changed) 175,666 176,532 +0.49%
packages/@rescript/belt/src/Belt_internalBucketsType.resi (inputs changed) 164,724 165,535 +0.49%
packages/@rescript/runtime/Stdlib_ArrayBuffer.resi (inputs changed) 110,989 111,533 +0.49%
packages/@rescript/runtime/Primitive_object.resi (inputs changed) 117,125 117,699 +0.49%
packages/@rescript/runtime/Stdlib_Lazy.resi (inputs changed) 112,434 112,985 +0.49%
packages/@rescript/runtime/Primitive_object_extern.res (inputs changed) 114,729 115,288 +0.49%
packages/@rescript/runtime/Stdlib_TaggedTemplate.res (inputs changed) 115,368 115,927 +0.48%
packages/@rescript/belt/src/Belt_SortArrayString.resi (inputs changed) 169,577 170,398 +0.48%
packages/@rescript/belt/src/Belt_SortArrayInt.resi (inputs changed) 169,695 170,516 +0.48%
packages/@rescript/runtime/Primitive_array_extern.res (inputs changed) 114,220 114,769 +0.48%
packages/@rescript/belt/src/Belt_Range.resi (inputs changed) 176,657 177,488 +0.47%
packages/@rescript/runtime/Dom_storage2.res (inputs changed) 120,182 120,746 +0.47%
packages/@rescript/runtime/Stdlib_Intl_Segments.res (inputs changed) 116,601 117,140 +0.46%
packages/@rescript/runtime/Stdlib_Temporal_Duration.res (inputs changed) 373,600 375,323 +0.46%
packages/@rescript/belt/src/Belt_internalSetInt.res (inputs changed) 730,723 734,090 +0.46%
packages/@rescript/belt/src/Belt_internalSetString.res (inputs changed) 731,914 735,278 +0.46%
packages/@rescript/runtime/Stdlib_JsExn.resi (inputs changed) 122,775 123,339 +0.46%
packages/@rescript/runtime/Jsx.res (inputs changed) 121,738 122,297 +0.46%
packages/@rescript/runtime/Stdlib_Global.res (inputs changed) 141,743 142,393 +0.46%
packages/@rescript/runtime/Stdlib_BigInt.res (inputs changed) 207,074 208,019 +0.46%
packages/@rescript/runtime/Primitive_option.resi (inputs changed) 122,265 122,819 +0.45%
packages/@rescript/runtime/Stdlib_Int.res (inputs changed) 455,336 457,385 +0.45%
packages/@rescript/runtime/Stdlib_Ordering.res (inputs changed) 152,340 153,024 +0.45%
packages/@rescript/runtime/Stdlib_WeakSet.res (inputs changed) 123,172 123,721 +0.45%
packages/@rescript/runtime/Stdlib_Temporal_PlainYearMonth.res (inputs changed) 382,285 383,981 +0.44%
packages/@rescript/belt/src/Belt_internalAVLtree.resi (inputs changed) 452,423 454,430 +0.44%
packages/@rescript/belt/src/Belt_internalSetBuckets.resi (inputs changed) 194,250 195,091 +0.43%
packages/@rescript/runtime/Stdlib_Temporal_PlainDate.res (inputs changed) 403,907 405,651 +0.43%
packages/@rescript/runtime/Stdlib_Symbol.res (inputs changed) 146,511 147,130 +0.42%
packages/@rescript/runtime/Stdlib_Type.resi (inputs changed) 135,946 136,515 +0.42%
packages/@rescript/belt/src/Belt_HashMapString.resi (inputs changed) 213,714 214,605 +0.42%
packages/@rescript/belt/src/Belt_HashMapInt.resi (inputs changed) 213,828 214,719 +0.42%
packages/@rescript/runtime/Stdlib_JsExn.res (inputs changed) 173,080 173,799 +0.42%
packages/@rescript/runtime/Stdlib_Global.resi (inputs changed) 155,548 156,192 +0.41%
packages/@rescript/belt/src/Belt_HashSet.resi (inputs changed) 222,778 223,694 +0.41%
packages/@rescript/runtime/Stdlib_WeakMap.res (inputs changed) 135,503 136,057 +0.41%
packages/@rescript/runtime/Primitive_float.res (inputs changed) 146,893 147,492 +0.41%
packages/@rescript/runtime/Stdlib_Temporal_PlainDateTime.res (inputs changed) 438,194 439,978 +0.41%
packages/@rescript/runtime/Primitive_bool.res (inputs changed) 147,218 147,817 +0.41%
build/Namespace/clean 84,167,009 84,507,895 +0.41%
packages/@rescript/runtime/Stdlib_RegExp.res (inputs changed) 163,713 164,375 +0.40%
packages/@rescript/runtime/Dom_storage.res (inputs changed) 167,042 167,706 +0.40%
packages/@rescript/belt/src/Belt_Id.res (inputs changed) 289,887 291,036 +0.40%
packages/@rescript/belt/src/Belt_Option.res (inputs changed) 389,121 390,663 +0.40%
packages/@rescript/runtime/Primitive_string.res (inputs changed) 159,592 160,216 +0.39%
packages/@rescript/belt/src/Belt_Set.res (inputs changed) 857,946 861,271 +0.39%
packages/@rescript/runtime/Stdlib_Symbol.resi (inputs changed) 160,141 160,760 +0.39%
packages/@rescript/runtime/Stdlib_Temporal_Now.res (inputs changed) 143,495 144,049 +0.39%
packages/@rescript/belt/src/Belt_internalBuckets.resi (inputs changed) 223,042 223,898 +0.38%
packages/@rescript/belt/src/Belt_Id.resi (inputs changed) 260,286 261,283 +0.38%
packages/@rescript/runtime/Primitive_int.res (inputs changed) 171,842 172,491 +0.38%
packages/@rescript/belt/src/Belt_Range.res (inputs changed) 288,346 289,427 +0.37%
packages/@rescript/runtime/Stdlib_IterableIterator.resi (inputs changed) 149,406 149,965 +0.37%
packages/@rescript/runtime/Primitive_exceptions.res (inputs changed) 201,232 201,983 +0.37%
packages/@rescript/runtime/Primitive_bigint.res (inputs changed) 177,314 177,973 +0.37%
packages/@rescript/runtime/Primitive_array.res (inputs changed) 191,984 192,688 +0.37%
packages/@rescript/runtime/Stdlib_Lazy.res (inputs changed) 221,184 221,990 +0.36%
packages/@rescript/runtime/Stdlib_Iterator.resi (inputs changed) 159,246 159,820 +0.36%
packages/@rescript/belt/src/Belt_Map.res (inputs changed) 981,236 984,770 +0.36%
packages/@rescript/runtime/Stdlib_Pair.res (inputs changed) 165,262 165,857 +0.36%
packages/@rescript/belt/src/Belt_SortArray.resi (inputs changed) 253,942 254,853 +0.36%
packages/@rescript/runtime/Stdlib_Float.resi (inputs changed) 194,292 194,986 +0.36%
packages/@rescript/runtime/Stdlib_Null.res (inputs changed) 332,359 333,544 +0.36%
packages/@rescript/runtime/Stdlib_Intl_NumberFormat_Grouping.res (inputs changed) 159,421 159,988 +0.36%
packages/@rescript/runtime/Stdlib_Intl_Segmenter.res (inputs changed) 154,540 155,089 +0.36%
packages/@rescript/runtime/Stdlib_Float.res (inputs changed) 218,863 219,635 +0.35%
packages/@rescript/runtime/Stdlib_IterableIterator.res (inputs changed) 178,852 179,481 +0.35%
packages/@rescript/runtime/Stdlib_RegExp.resi (inputs changed) 187,800 188,459 +0.35%
packages/@rescript/runtime/Stdlib_AsyncIterableIterator.resi (inputs changed) 159,925 160,484 +0.35%
packages/@rescript/runtime/Stdlib_Generator.resi (inputs changed) 160,547 161,106 +0.35%
packages/@rescript/runtime/Primitive_list.res (inputs changed) 203,745 204,454 +0.35%
packages/@rescript/belt/src/Belt_MutableQueue.res (inputs changed) 791,334 794,062 +0.34%
packages/@rescript/belt/src/Belt_Result.res (inputs changed) 409,437 410,848 +0.34%
packages/@rescript/runtime/Stdlib_Intl_Common.res (inputs changed) 154,360 154,884 +0.34%
packages/@rescript/runtime/Stdlib_AsyncGenerator.resi (inputs changed) 165,925 166,484 +0.34%
packages/@rescript/runtime/Stdlib_Type.res (inputs changed) 201,438 202,114 +0.34%
packages/@rescript/belt/src/Belt_MutableStack.res (inputs changed) 387,514 388,802 +0.33%
packages/@rescript/runtime/Stdlib_Int.resi (inputs changed) 206,103 206,777 +0.33%
packages/@rescript/runtime/Stdlib_Intl_ListFormat.res (inputs changed) 169,825 170,379 +0.33%
packages/@rescript/runtime/Stdlib_AsyncIterator.resi (inputs changed) 177,818 178,397 +0.33%
packages/@rescript/runtime/Stdlib_Iterator.res (inputs changed) 234,922 235,686 +0.33%
packages/@rescript/runtime/Stdlib_Generator.res (inputs changed) 200,286 200,935 +0.32%
packages/@rescript/runtime/Stdlib_Temporal_ZonedDateTime.res (inputs changed) 574,181 576,013 +0.32%
packages/@rescript/runtime/Stdlib_Nullable.res (inputs changed) 329,857 330,907 +0.32%
packages/@rescript/belt/src/Belt_HashMap.resi (inputs changed) 296,908 297,849 +0.32%
packages/@rescript/runtime/Stdlib_Math.res (inputs changed) 327,556 328,588 +0.32%
packages/@rescript/belt/src/Belt_MapInt.res (inputs changed) 1,181,363 1,185,033 +0.31%
packages/@rescript/belt/src/Belt_MapString.res (inputs changed) 1,181,899 1,185,568 +0.31%
packages/@rescript/runtime/Stdlib_Set.res (inputs changed) 210,990 211,639 +0.31%
packages/@rescript/runtime/Stdlib_AsyncGenerator.res (inputs changed) 211,156 211,805 +0.31%
packages/@rescript/runtime/Stdlib_Intl_Collator.res (inputs changed) 178,667 179,216 +0.31%
packages/@rescript/runtime/Stdlib_Intl_RelativeTimeFormat.res (inputs changed) 180,464 181,018 +0.31%
packages/@rescript/runtime/Stdlib_Map.res (inputs changed) 205,648 206,277 +0.31%
packages/@rescript/runtime/Stdlib_Option.res (inputs changed) 753,633 755,934 +0.31%
packages/@rescript/belt/src/Belt_MutableMap.res (inputs changed) 1,302,290 1,306,265 +0.31%
packages/@rescript/runtime/Stdlib_Intl_Locale.res (inputs changed) 198,068 198,662 +0.30%
packages/@rescript/belt/src/Belt_HashSetInt.res (inputs changed) 850,520 853,051 +0.30%
packages/@rescript/belt/src/Belt_HashSetString.res (inputs changed) 850,837 853,366 +0.30%
packages/@rescript/belt/src/Belt_internalSetBuckets.res (inputs changed) 699,079 701,152 +0.30%
packages/@rescript/runtime/Stdlib_AsyncIterableIterator.res (inputs changed) 228,325 228,999 +0.30%
packages/@rescript/belt/src/Belt_MutableMapString.res (inputs changed) 1,155,019 1,158,382 +0.29%
packages/@rescript/belt/src/Belt_MutableMapInt.res (inputs changed) 1,154,742 1,158,102 +0.29%
packages/@rescript/runtime/Stdlib_Math.resi (inputs changed) 328,324 329,278 +0.29%
packages/@rescript/runtime/Stdlib_DataView.res (inputs changed) 230,306 230,965 +0.29%
packages/@rescript/runtime/Primitive_option.res (inputs changed) 297,411 298,259 +0.29%
packages/@rescript/belt/src/Belt_SetInt.res (inputs changed) 1,289,624 1,293,301 +0.29%
packages/@rescript/belt/src/Belt_SetString.res (inputs changed) 1,290,353 1,294,031 +0.29%
packages/@rescript/runtime/RescriptTools_Docgen.resi (inputs changed) 273,524 274,299 +0.28%
packages/@rescript/runtime/Stdlib_Map.resi (inputs changed) 217,108 217,717 +0.28%
packages/@rescript/runtime/Stdlib_Intl_PluralRules.res (inputs changed) 201,889 202,453 +0.28%
packages/@rescript/belt/src/Belt_HashSet.res (inputs changed) 978,208 980,915 +0.28%
packages/@rescript/belt/src/Belt_internalMapInt.res (inputs changed) 1,408,499 1,412,395 +0.28%
packages/@rescript/runtime/Stdlib_AsyncIterator.res (inputs changed) 294,756 295,570 +0.28%
packages/@rescript/runtime/Stdlib_Set.resi (inputs changed) 228,953 229,582 +0.27%
packages/@rescript/belt/src/Belt_Array.res (inputs changed) 2,154,235 2,160,149 +0.27%
packages/@rescript/runtime/RescriptTools_Docgen.res (inputs changed) 283,791 284,566 +0.27%
parse/RedBlackTreeNoComments.res 355,139 356,105 +0.27%
packages/@rescript/belt/src/Belt_internalMapString.res (inputs changed) 1,410,343 1,414,160 +0.27%
packages/@rescript/runtime/Primitive_module.res (inputs changed) 337,540 338,448 +0.27%
parse/RedBlackTree.res 362,852 363,818 +0.27%
packages/@rescript/runtime/Stdlib_Dict.resi (inputs changed) 240,779 241,418 +0.27%
packages/@rescript/runtime/Stdlib_IteratorObject.resi (inputs changed) 234,376 234,985 +0.26%
packages/@rescript/runtime/Stdlib_IteratorObject.res (inputs changed) 250,722 251,371 +0.26%
packages/@rescript/runtime/Stdlib_Object.res (inputs changed) 247,331 247,970 +0.26%
packages/@rescript/belt/src/Belt_HashMapInt.res (inputs changed) 1,060,707 1,063,447 +0.26%
packages/@rescript/belt/src/Belt_MutableSet.res (inputs changed) 1,902,475 1,907,384 +0.26%
packages/@rescript/belt/src/Belt_HashMapString.res (inputs changed) 1,061,419 1,064,155 +0.26%
packages/@rescript/belt/src/Belt_MapDict.res (inputs changed) 1,630,823 1,634,979 +0.25%
packages/@rescript/belt/src/Belt_MutableSetString.res (inputs changed) 1,665,801 1,670,038 +0.25%
packages/@rescript/runtime/Stdlib_Dict.res (inputs changed) 320,111 320,925 +0.25%
packages/@rescript/runtime/Stdlib_Console.res (inputs changed) 370,179 371,118 +0.25%
packages/@rescript/belt/src/Belt_MutableSetInt.res (inputs changed) 1,664,555 1,668,724 +0.25%
packages/@rescript/belt/src/Belt_SetDict.res (inputs changed) 1,445,985 1,449,600 +0.25%
packages/@rescript/runtime/Primitive_js_extern.res (inputs changed) 239,834 240,426 +0.25%
packages/@rescript/belt/src/Belt_HashMap.res (inputs changed) 1,200,049 1,203,010 +0.25%
packages/@rescript/runtime/Stdlib_DataView.resi (inputs changed) 268,044 268,703 +0.25%
packages/@rescript/belt/src/Belt_internalBuckets.res (inputs changed) 966,624 968,950 +0.24%
packages/@rescript/belt/src/Belt_SortArray.res (inputs changed) 1,447,582 1,451,010 +0.24%
packages/@rescript/runtime/Stdlib_Console.resi (inputs changed) 411,610 412,549 +0.23%
packages/@rescript/belt/src/Belt_SortArrayString.res (inputs changed) 1,344,225 1,347,247 +0.22%
packages/@rescript/belt/src/Belt_SortArrayInt.res (inputs changed) 1,342,429 1,345,446 +0.22%
packages/@rescript/belt/src/Belt_List.res (inputs changed) 3,175,359 3,181,770 +0.20%
packages/@rescript/runtime/Stdlib_Array.res (inputs changed) 1,281,101 1,283,669 +0.20%
packages/@rescript/runtime/Stdlib_String.res (inputs changed) 503,934 504,928 +0.20%
packages/@rescript/runtime/Stdlib_Promise.res (inputs changed) 352,778 353,442 +0.19%
packages/@rescript/runtime/Stdlib_Date.res (inputs changed) 551,778 552,815 +0.19%
packages/@rescript/runtime/Stdlib_Result.res (inputs changed) 1,268,255 1,270,625 +0.19%
packages/@rescript/runtime/JsxEvent.res (inputs changed) 1,090,874 1,092,904 +0.19%
packages/@rescript/runtime/Stdlib_Promise.resi (inputs changed) 356,017 356,656 +0.18%
build/clean 236,615,322 237,030,663 +0.18%
packages/@rescript/runtime/Stdlib_Int8Array.res (inputs changed) 343,494 344,081 +0.17%
packages/@rescript/runtime/Stdlib_Uint8Array.res (inputs changed) 343,507 344,094 +0.17%
packages/@rescript/runtime/Stdlib_Float32Array.res (inputs changed) 343,614 344,201 +0.17%
packages/@rescript/runtime/Stdlib_Float64Array.res (inputs changed) 343,614 344,201 +0.17%
packages/@rescript/runtime/Stdlib_Int16Array.res (inputs changed) 343,639 344,226 +0.17%
packages/@rescript/runtime/Stdlib_Int32Array.res (inputs changed) 343,641 344,228 +0.17%
packages/@rescript/runtime/Stdlib_Uint16Array.res (inputs changed) 343,646 344,233 +0.17%
packages/@rescript/runtime/Stdlib_Uint32Array.res (inputs changed) 343,646 344,233 +0.17%
packages/@rescript/runtime/Stdlib_BigInt64Array.res (inputs changed) 343,671 344,258 +0.17%
packages/@rescript/runtime/Stdlib_BigUint64Array.res (inputs changed) 343,748 344,335 +0.17%
packages/@rescript/runtime/Stdlib_Uint8ClampedArray.res (inputs changed) 344,022 344,609 +0.17%
packages/@rescript/belt/src/Belt_internalAVLset.res (inputs changed) 2,876,034 2,880,939 +0.17%
packages/@rescript/runtime/Stdlib_String.resi (inputs changed) 497,477 498,316 +0.17%
packages/@rescript/runtime/Primitive_hash.res (inputs changed) 964,614 966,187 +0.16%
packages/@rescript/runtime/Stdlib_Date.resi (inputs changed) 614,248 615,242 +0.16%
packages/@rescript/runtime/Primitive_object.res (inputs changed) 1,154,866 1,156,713 +0.16%
packages/@rescript/belt/src/Belt_internalAVLtree.res (inputs changed) 3,506,403 3,512,000 +0.16%
packages/@rescript/runtime/Stdlib_Intl_NumberFormat.res (inputs changed) 404,810 405,452 +0.16%
packages/@rescript/runtime/Stdlib_List.res (inputs changed) 2,686,422 2,690,680 +0.16%
stress/InlineChain.res 3,511,206 3,516,672 +0.16%
packages/@rescript/runtime/Stdlib_Intl_DateTimeFormat.res (inputs changed) 389,599 390,163 +0.14%
packages/@rescript/runtime/Stdlib_Temporal_Common.res (inputs changed) 366,668 367,192 +0.14%
build/leaf-edit 13,027,765 13,046,130 +0.14%
packages/@rescript/runtime/Stdlib_TypedArray.res (inputs changed) 785,351 786,413 +0.14%
packages/@rescript/runtime/Stdlib_Array.resi (inputs changed) 728,603 729,582 +0.13%

(inputs changed): this pull request changes runtime or Belt sources, so these benchmarks compile different code than on the base, and their changes don't count as regressions.

Instructions

In total: 9,221,447,599 → 9,225,751,340 (+0.05%).

Benchmark Base Head Change
packages/@rescript/belt/src/Belt_Array.resi (inputs changed) 33,712,068 34,454,684 +2.20%
packages/@rescript/belt/src/Belt_List.resi (inputs changed) 38,983,767 39,310,606 +0.84%
packages/@rescript/runtime/Stdlib_List.resi (inputs changed) 24,524,422 24,691,820 +0.68%
packages/@rescript/runtime/Stdlib_Temporal_PlainDate.res (inputs changed) 24,087,504 24,176,868 +0.37%
packages/@rescript/runtime/Stdlib_Temporal_PlainDateTime.res (inputs changed) 25,527,318 25,611,057 +0.33%
packages/@rescript/runtime/Stdlib_Temporal_ZonedDateTime.res (inputs changed) 31,195,025 31,289,245 +0.30%
packages/@rescript/runtime/Stdlib_Math.resi (inputs changed) 21,296,990 21,343,489 +0.22%
packages/@rescript/belt/src/Belt_List.res (inputs changed) 118,135,857 118,353,681 +0.18%
packages/@rescript/runtime/Stdlib_String.resi (inputs changed) 29,450,820 29,494,973 +0.15%
packages/@rescript/runtime/Stdlib_TypedArray.res (inputs changed) 41,308,327 41,366,599 +0.14%
4 more changes
Benchmark Base Head Change
packages/@rescript/runtime/Stdlib_Array.resi (inputs changed) 40,104,929 40,160,652 +0.14%
parse/Napkinscript.res 333,234,229 333,676,409 +0.13%
packages/@rescript/belt/src/Belt_internalAVLtree.res (inputs changed) 136,420,166 136,592,971 +0.13%
packages/@rescript/runtime/Stdlib_Date.resi (inputs changed) 34,294,290 34,334,277 +0.12%

(inputs changed): this pull request changes runtime or Belt sources, so these benchmarks compile different code than on the base, and their changes don't count as regressions.

Output size

In total: 25,962,507 → 26,011,644 (+0.19%).

Benchmark Base Head Change
output/belt/*.cmi (inputs changed) 460,980 467,931 +1.51%
output/belt/*.cmti (inputs changed) 980,059 989,134 +0.93%
output/runtime/*.cmti (inputs changed) 1,115,148 1,118,865 +0.33%
output/runtime/*.cmi (inputs changed) 1,919,667 1,924,137 +0.23%
output/tests/*.cmi 2,356,307 2,360,607 +0.18%
output/playground/compiler.js 1,889,071 1,891,914 +0.15%
output/belt/*.cmt (inputs changed) 2,752,575 2,756,311 +0.14%
output/runtime/*.cmt (inputs changed) 3,035,969 3,039,413 +0.11%

(inputs changed): this pull request changes runtime or Belt sources, so these benchmarks compile different code than on the base, and their changes don't count as regressions.

Pull request 629ea53 compared with base 643e9c0 in this run.

@github-actions

Copy link
Copy Markdown

@cristianoc cristianoc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dot, Cristiano's assistant, reviewing at his request.

One correctness issue in the new library-declaration path: custom exception names are transferred across module boundaries without resolving their defining scope. Please add a cross-module custom-exception regression and preserve exception identity consistently. Exact-head CI is green. This finding is based on static tracing; I did not run a compiler-built reproducer locally (OCaml/dune unavailable).

current_events :=
{
Event.exceptions = Exceptions.empty;
Event.exceptions = get_exceptions_from_annotations vd.val_attributes;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Resolve declaration exception identities before transferring them to callers

For a library interface declaring exception E and @throws(E) let f: unit => unit, a consumer's try Lib.f() catch { | Lib.E => () } contributes the raw annotation string E here, but the catch is represented as Lib.E. Exn.from_string is identity, Exn.from_lid keeps the qualifier, and the catch subtracts sets of those strings, so the correctly caught exception is still reported as uncaught. Conversely, catching an unrelated local E can suppress the library exception. The existing new fixtures use globally named builtins and miss this case. Please resolve names in the declaration's defining scope and compare canonical exception identities on both sides, with a custom-library-exception regression.

cknitt added a commit that referenced this pull request Nov 17, 2026
Why:
    Review finding on #9198: a library's `@throws(E)` reached the caller as
    the bare name `E`, while a catch was compared by its spelling, `Lib.E`.
    So a correct catch still reported the exception, and a caller's own `E`
    could hide the library's.

Now a catch or throw names an exception by its constructor's path: `Lib.E`
whether it is written `Lib.E`, `E` after `open Lib` or `L.E` for
`module L = Lib`. A callee's `@throws` names are resolved in the callee's
scope (`Lib.Inner.E`, then `Lib.E`), picking the first one the project
catches or throws. For a callee in another file the bare name is not a
candidate. Predefined exceptions such as `Not_found` and `JsExn` keep
their bare names. The same applies to the values table, so an annotated
`let` in another file without an interface is fixed too. That case is
older than this PR.

Reanalyze modified (cross-module exception names):
Example:
    // ThrowsLibExn.res
    exception E
    @throws(E)
    external parse: string => int = "parseThrowing"
    @throws(E)
    let viaLet = x => x > 0 ? x : throw(E)
    module Inner = {
      exception F
      @throws(F)
      external find: int => int = "findThrowing"
    }

    // ThrowsLibExnCalls.res
    let catchExternal = s =>
      try ThrowsLibExn.parse(s) catch {
      | ThrowsLibExn.E => 0
      }

    let catchViaLet = x =>
      try ThrowsLibExn.viaLet(x) catch {
      | ThrowsLibExn.E => 0
      }

    let catchNested = x =>
      try ThrowsLibExn.Inner.find(x) catch {
      | ThrowsLibExn.Inner.F => 0
      }

    exception E

    let catchUnrelatedLocal = s =>
      try ThrowsLibExn.parse(s) catch {
      | E => 0
      }
Before (reanalyze):
    Exception Analysis
    ThrowsLibExnCalls.res:1:5-17
    catchExternal might throw E (ThrowsLibExnCalls.res:2:6) and is not annotated with @throws(E)

    Exception Analysis
    ThrowsLibExnCalls.res:6:5-15
    catchViaLet might throw E (ThrowsLibExnCalls.res:7:6) and is not annotated with @throws(E)

    Exception Analysis
    ThrowsLibExnCalls.res:11:5-15
    catchNested might throw F (ThrowsLibExnCalls.res:12:6) and is not annotated with @throws(F)
After (reanalyze):
    Exception Analysis
    ThrowsLibExnCalls.res:18:5-23
    catchUnrelatedLocal might throw ThrowsLibExn.E (ThrowsLibExnCalls.res:19:6) and is not annotated with @throws(ThrowsLibExn.E)

Review: Where do the candidate names come from, without the declaration's environment? The .cmt keeps no environments, so a name is resolved against the exceptions the project's files catch or throw. A catch can only match one of those, so the choice matters for matching. When none is known, the innermost candidate is used, which only affects the message.
Review: What does a caller now write in its own annotation? The qualified name, `@throws(ThrowsLibExn.E)`, which the message suggests. A bare `E` after `open ThrowsLibExn` no longer matches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHA54VKxsXvCQyC2vw
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the drift-9182-temporal-exn branch from bd4a722 to 9be7aca Compare November 19, 2026 06:16
cknitt added a commit that referenced this pull request Nov 19, 2026
Why:
    Review finding on #9198: a library's `@throws(E)` reached the caller as
    the bare name `E`, while a catch was compared by its spelling, `Lib.E`.
    So a correct catch still reported the exception, and a caller's own `E`
    could hide the library's.

Now a catch or throw names an exception by its constructor's path: `Lib.E`
whether it is written `Lib.E`, `E` after `open Lib` or `L.E` for
`module L = Lib`. A callee's `@throws` names are resolved in the callee's
scope (`Lib.Inner.E`, then `Lib.E`), picking the first one the project
catches or throws. For a callee in another file the bare name is not a
candidate. Predefined exceptions such as `Not_found` and `JsExn` keep
their bare names. The same applies to the values table, so an annotated
`let` in another file without an interface is fixed too. That case is
older than this PR.

Reanalyze modified (cross-module exception names):
Example:
    // ThrowsLibExn.res
    exception E
    @throws(E)
    external parse: string => int = "parseThrowing"
    @throws(E)
    let viaLet = x => x > 0 ? x : throw(E)
    module Inner = {
      exception F
      @throws(F)
      external find: int => int = "findThrowing"
    }

    // ThrowsLibExnCalls.res
    let catchExternal = s =>
      try ThrowsLibExn.parse(s) catch {
      | ThrowsLibExn.E => 0
      }

    let catchViaLet = x =>
      try ThrowsLibExn.viaLet(x) catch {
      | ThrowsLibExn.E => 0
      }

    let catchNested = x =>
      try ThrowsLibExn.Inner.find(x) catch {
      | ThrowsLibExn.Inner.F => 0
      }

    exception E

    let catchUnrelatedLocal = s =>
      try ThrowsLibExn.parse(s) catch {
      | E => 0
      }
Before (reanalyze):
    Exception Analysis
    ThrowsLibExnCalls.res:1:5-17
    catchExternal might throw E (ThrowsLibExnCalls.res:2:6) and is not annotated with @throws(E)

    Exception Analysis
    ThrowsLibExnCalls.res:6:5-15
    catchViaLet might throw E (ThrowsLibExnCalls.res:7:6) and is not annotated with @throws(E)

    Exception Analysis
    ThrowsLibExnCalls.res:11:5-15
    catchNested might throw F (ThrowsLibExnCalls.res:12:6) and is not annotated with @throws(F)
After (reanalyze):
    Exception Analysis
    ThrowsLibExnCalls.res:18:5-23
    catchUnrelatedLocal might throw ThrowsLibExn.E (ThrowsLibExnCalls.res:19:6) and is not annotated with @throws(ThrowsLibExn.E)

Review: Where do the candidate names come from, without the declaration's environment? The .cmt keeps no environments, so a name is resolved against the exceptions the project's files catch or throw. A catch can only match one of those, so the choice matters for matching. When none is known, the innermost candidate is used, which only affects the message.
Review: What does a caller now write in its own annotation? The qualified name, `@throws(ThrowsLibExn.E)`, which the message suggests. A bare `E` after `open ThrowsLibExn` no longer matches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHA54VKxsXvCQyC2vw
Signed-off-by: Christoph Knittel <ck@cca.io>
cknitt added a commit that referenced this pull request Nov 19, 2026
Why:
    Review on #9198: a library's `@throws(E)` reached callers as the bare
    name `E`, while a catch was compared as written (`Lib.E`), so a correct
    catch was still reported and a caller's own `E` could hide the
    library's. Reanalyze cannot resolve names itself, because a .cmt keeps
    no environments; two attempts to guess the scope from the file still
    got opens in interfaces, functors, includes and aliases wrong.

The type checker now looks up each name in a `@throws` where it is
written, for externals, `let`s in signatures and interfaces, and every
`let` binding. It adds a generated `@res.throws` that lists each
exception's readable name and identity, and the inferred signature keeps
it next to `@throws`. The identity is the defining file without its
extension and the exception's name (`src/Lib#E`), so a module's .res and
.resi agree and moving a definition within its file changes nothing.
Exception analysis compares these identities with the constructors that
catches and throws name.

A name that is not an exception in scope gets the new warning 113 and is
listed as written. A rebinding (`exception Mine = Lib.E`) is a new
definition, so catching `Mine` does not catch `Lib.E`, as before. Two
exceptions with the same name in one file share an identity.

Typedtree modified (@throws resolved where it is written):
Example:
    module Errors = {
      exception NotFound
    }
    open Errors
    @throws(NotFound)
    external find: int => int = "find"
Before (typed):
    Tstr_primitive
    value_description find/1003
      attribute "throws"
        [
          structure_item
            Pstr_eval
            expression
              Pexp_construct "NotFound"
              []
        ]
After (typed):
    Tstr_primitive
    value_description find/1003
      attribute "throws"
        [
          structure_item
            Pstr_eval
            expression
              Pexp_construct "NotFound"
              []
        ]
      attribute "res.throws"
        [
          structure_item
            Pstr_eval
            expression
              Pexp_array
              [
                expression
                  Pexp_tuple
                  [
                    expression
                      Pexp_constant PConst_string (source="Repo.Errors.NotFound", semantic="Repo.Errors.NotFound")
                    expression
                      Pexp_constant PConst_string (source="Repo#NotFound", semantic="Repo#NotFound")
                  ]
              ]
        ]

Diagnostic added (warning 113):
Example:
    @throws(Missing)
    let f = () => 1
After (diagnostic): tests/build_tests/super_errors/fixtures/throws_unbound_warning.res
    Warning number 113
    throws_unbound_warning.res:3:9-15

    @throws names Missing, which is not an exception in scope here. Exception analysis cannot match it with the exceptions callers catch.

Reanalyze modified (catches of another module's exceptions):
Example:
    // ThrowsLibExn.res
    exception E
    @throws(E)
    external parse: string => int = "parseThrowing"

    // ThrowsLibExnCalls.res
    let catchExternal = s =>
      try ThrowsLibExn.parse(s) catch {
      | ThrowsLibExn.E => 0
      }
Before (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception
    Exception Analysis
    ThrowsLibExnCalls.res:4:5-17
    catchExternal might throw E (ThrowsLibExnCalls.res:5:6) and is not annotated with @throws(E)

    Exception Analysis
    ThrowsRepoCalls.res:18:5-16
    catchViaOpen might throw Bad (ThrowsRepoCalls.res:19:6) and is not annotated with @throws(Bad)

    Exception Analysis
    ThrowsScopes.res:2:5-18
    catchIfaceOpen might throw NotFound (ThrowsScopes.res:3:6) and is not annotated with @throws(NotFound)

    Exception Analysis
    ThrowsLibExnCalls.res:103:7-12
    caught might throw E (ThrowsLibExnCalls.res:104:8) and is not annotated with @throws(E)

    …

    Exception Analysis
    ThrowsLibExnCalls.res:81:5-16
    catchRebound might throw E (ThrowsLibExnCalls.res:82:6) and is not annotated with @throws(E)
After (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception
    Exception Analysis
    ThrowsLibExnCalls.res:81:5-16
    catchRebound might throw ThrowsLibExn.E (ThrowsLibExnCalls.res:82:6) and is not annotated with @throws(ThrowsLibExn.E)

Review: Why an identity from the file and name instead of the path? The type checker has no module prefix for a file's own exceptions, and a path changes with aliases and namespaces. The file and name are the same through every alias, open, include and functor, and in the .res and .resi.
Review: Does this recompile more? Only the attribute is new, and it holds names, not positions, so it changes only when the exception is renamed or moves to another file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHA54VKxsXvCQyC2vw
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the drift-9182-temporal-exn branch from 9be7aca to 0786ca1 Compare November 19, 2026 08:01
cknitt added a commit that referenced this pull request Nov 19, 2026
Why:
    Review on #9198: a library's `@throws(E)` reached callers as the bare
    name `E`, while a catch was compared as written (`Lib.E`), so a correct
    catch was still reported and a caller's own `E` could hide the
    library's. Reanalyze cannot resolve names itself, because a .cmt keeps
    no environments; two attempts to guess the scope from the file still
    got opens in interfaces, functors, includes and aliases wrong.

The type checker now looks up each name in a `@throws` where it is
written, for externals, `let`s in signatures and interfaces, and every
`let` binding. It adds a generated `@res.throws` that lists each
exception's readable name and identity, and the inferred signature keeps
it next to `@throws`. The identity is the defining file without its
extension and the exception's name (`src/Lib#E`), so a module's .res and
.resi agree and moving a definition within its file changes nothing.
Exception analysis compares these identities with the constructors that
catches and throws name.

A name that is not an exception in scope gets the new warning 113 and is
listed as written. A rebinding (`exception Mine = Lib.E`) is a new
definition, so catching `Mine` does not catch `Lib.E`, as before. Two
exceptions with the same name in one file share an identity.

Typedtree modified (@throws resolved where it is written):
Example:
    module Errors = {
      exception NotFound
    }
    open Errors
    @throws(NotFound)
    external find: int => int = "find"
Before (typed):
    Tstr_primitive
    value_description find/1003
      attribute "throws"
        [
          structure_item
            Pstr_eval
            expression
              Pexp_construct "NotFound"
              []
        ]
After (typed):
    Tstr_primitive
    value_description find/1003
      attribute "throws"
        [
          structure_item
            Pstr_eval
            expression
              Pexp_construct "NotFound"
              []
        ]
      attribute "res.throws"
        [
          structure_item
            Pstr_eval
            expression
              Pexp_array
              [
                expression
                  Pexp_tuple
                  [
                    expression
                      Pexp_constant PConst_string (source="Repo.Errors.NotFound", semantic="Repo.Errors.NotFound")
                    expression
                      Pexp_constant PConst_string (source="Repo#NotFound", semantic="Repo#NotFound")
                  ]
              ]
        ]

Diagnostic added (warning 113):
Example:
    @throws(Missing)
    let f = () => 1
After (diagnostic): tests/build_tests/super_errors/fixtures/throws_unbound_warning.res
    Warning number 113
    throws_unbound_warning.res:3:9-15

    @throws names Missing, which is not an exception in scope here. Exception analysis cannot match it with the exceptions callers catch.

Reanalyze modified (catches of another module's exceptions):
Example:
    // ThrowsLibExn.res
    exception E
    @throws(E)
    external parse: string => int = "parseThrowing"

    // ThrowsLibExnCalls.res
    let catchExternal = s =>
      try ThrowsLibExn.parse(s) catch {
      | ThrowsLibExn.E => 0
      }
Before (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception
    Exception Analysis
    ThrowsLibExnCalls.res:4:5-17
    catchExternal might throw E (ThrowsLibExnCalls.res:5:6) and is not annotated with @throws(E)

    Exception Analysis
    ThrowsRepoCalls.res:18:5-16
    catchViaOpen might throw Bad (ThrowsRepoCalls.res:19:6) and is not annotated with @throws(Bad)

    Exception Analysis
    ThrowsScopes.res:2:5-18
    catchIfaceOpen might throw NotFound (ThrowsScopes.res:3:6) and is not annotated with @throws(NotFound)

    Exception Analysis
    ThrowsLibExnCalls.res:103:7-12
    caught might throw E (ThrowsLibExnCalls.res:104:8) and is not annotated with @throws(E)

    …

    Exception Analysis
    ThrowsLibExnCalls.res:81:5-16
    catchRebound might throw E (ThrowsLibExnCalls.res:82:6) and is not annotated with @throws(E)
After (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception
    Exception Analysis
    ThrowsLibExnCalls.res:81:5-16
    catchRebound might throw ThrowsLibExn.E (ThrowsLibExnCalls.res:82:6) and is not annotated with @throws(ThrowsLibExn.E)

Review: Why an identity from the file and name instead of the path? The type checker has no module prefix for a file's own exceptions, and a path changes with aliases and namespaces. The file and name are the same through every alias, open, include and functor, and in the .res and .resi.
Review: Does this recompile more? Only the attribute is new, and it holds names, not positions, so it changes only when the exception is renamed or moves to another file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHA54VKxsXvCQyC2vw
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the drift-9182-temporal-exn branch from 0786ca1 to b0666ce Compare November 19, 2026 18:32
@cknitt

cknitt commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b0666ce189

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

Comment thread compiler/ml/throws_attribute.ml Resolved
Comment thread compiler/typing/throws_attribute.ml Resolved
cknitt added a commit that referenced this pull request Nov 19, 2026
…citly

Why:
    Codex review on #9198: the compiler's new @throws reader dropped
    `list{A, B}` payloads and constructors written with arguments, which
    reanalyze's old reader accepted, so such annotations silently stopped
    declaring anything. It also derived an exception's identity from a
    location that a .cmi built with -no-keep-locs (the runtime's and
    Belt's) does not keep.

The reader again takes `list{...}` and `M.E(...)` as before. An exception
whose .cmi has no locations is now identified as `#Name` on purpose,
rather than through the placeholder file name `_none_`. Codex's crash
report for that case does not hold, since `Filename.remove_extension`
does not raise on `_none_`, but the identity was accidental.

AST modified (res.throws for a list payload):
Example:
    exception E
    @throws(list{E, Not_found})
    let f = () => throw(E)
Before (text): number of res.throws attributes in bsc -dtypedtree
    0
After (text): number of res.throws attributes in bsc -dtypedtree
    1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHA54VKxsXvCQyC2vw
Signed-off-by: Christoph Knittel <ck@cca.io>
cknitt added a commit that referenced this pull request Nov 19, 2026
… exactly

Why:
    Review of #9198: the type checker loads the module a @throws names, but
    the dependency scanner skipped attributes. A module named only there was
    built in any order, so the name resolved or got warning 113 depending
    on the build, and a later edit could fail with "inconsistent
    assumptions". Messages also named an exception defined in a nested
    module without that module, so the annotation they suggested did not
    resolve. And a library built with -no-keep-locs recorded its own
    exceptions with its file, while its users see them without one.

`Depend` now adds the modules a @throws names, like any other use, so
they are built first. A module that is both named in @throws and depends
on the annotating module now gives a dependency cycle error.

`Typemod` records which module of the current file defines each
exception and module, so a file's own exception is named `Lib.Inner.F`.
Under -no-keep-locs a file's own exceptions are identified by name alone
also while it is compiled. Warning 113 is shown once for a `let` that
destructures a tuple.

Diagnostic modified (an exception of a nested module):
Example:
    // ThrowsLibExn.res
    module Inner = {
      exception F
      @throws(F)
      external find: int => int = "findThrowing"
    }

    // ThrowsLibExnCalls.res
    let uncaughtNested = x => ThrowsLibExn.Inner.find(x)
Before (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception/ThrowsLibExnCalls.res
    Exception Analysis
    ThrowsLibExnCalls.res:110:5-18
    uncaughtNested might throw ThrowsLibExn.F (ThrowsLibExnCalls.res:110:26) and is not annotated with @throws(ThrowsLibExn.F)
After (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception/ThrowsLibExnCalls.res
    Exception Analysis
    ThrowsLibExnCalls.res:110:5-18
    uncaughtNested might throw ThrowsLibExn.Inner.F (ThrowsLibExnCalls.res:110:26) and is not annotated with @throws(ThrowsLibExn.Inner.F)

Diagnostic modified (a module named only in @throws, tests/build_tests/throws_dependency):
Example:
    // A.res
    @throws(Z.E)
    external find: int => int = "find"

    // Z.res
    exception E
Before (diagnostic): A.res built before Z.res
    Warning number 113
    @throws names Z.E, which is not an exception in scope here. Exception analysis cannot match it with the exceptions callers catch.
After (diagnostic): Z.res built first, no warning

Breaking: A module named in @throws that itself depends on the annotating module is now a dependency cycle. Move the exception to a module of its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHA54VKxsXvCQyC2vw
Signed-off-by: Christoph Knittel <ck@cca.io>
cknitt added a commit that referenced this pull request Nov 20, 2026
Why:
    Review on #9198: a library's `@throws(E)` reached callers as the bare
    name `E`, while a catch was compared as written (`Lib.E`), so a correct
    catch was still reported and a caller's own `E` could hide the
    library's. Reanalyze cannot resolve names itself, because a .cmt keeps
    no environments; two attempts to guess the scope from the file still
    got opens in interfaces, functors, includes and aliases wrong.

The type checker now looks up each name in a `@throws` where it is
written, for externals, `let`s in signatures and interfaces, and every
`let` binding. It adds a generated `@res.throws` that lists each
exception's readable name and identity, and the inferred signature keeps
it next to `@throws`. The identity is the defining file without its
extension and the exception's name (`src/Lib#E`), so a module's .res and
.resi agree and moving a definition within its file changes nothing.
Exception analysis compares these identities with the constructors that
catches and throws name.

A name that is not an exception in scope gets the new warning 113 and is
listed as written. A rebinding (`exception Mine = Lib.E`) is a new
definition, so catching `Mine` does not catch `Lib.E`, as before. Two
exceptions with the same name in one file share an identity.

Typedtree modified (@throws resolved where it is written):
Example:
    module Errors = {
      exception NotFound
    }
    open Errors
    @throws(NotFound)
    external find: int => int = "find"
Before (typed):
    Tstr_primitive
    value_description find/1003
      attribute "throws"
        [
          structure_item
            Pstr_eval
            expression
              Pexp_construct "NotFound"
              []
        ]
After (typed):
    Tstr_primitive
    value_description find/1003
      attribute "throws"
        [
          structure_item
            Pstr_eval
            expression
              Pexp_construct "NotFound"
              []
        ]
      attribute "res.throws"
        [
          structure_item
            Pstr_eval
            expression
              Pexp_array
              [
                expression
                  Pexp_tuple
                  [
                    expression
                      Pexp_constant PConst_string (source="Repo.Errors.NotFound", semantic="Repo.Errors.NotFound")
                    expression
                      Pexp_constant PConst_string (source="Repo#NotFound", semantic="Repo#NotFound")
                  ]
              ]
        ]

Diagnostic added (warning 113):
Example:
    @throws(Missing)
    let f = () => 1
After (diagnostic): tests/build_tests/super_errors/fixtures/throws_unbound_warning.res
    Warning number 113
    throws_unbound_warning.res:3:9-15

    @throws names Missing, which is not an exception in scope here. Exception analysis cannot match it with the exceptions callers catch.

Reanalyze modified (catches of another module's exceptions):
Example:
    // ThrowsLibExn.res
    exception E
    @throws(E)
    external parse: string => int = "parseThrowing"

    // ThrowsLibExnCalls.res
    let catchExternal = s =>
      try ThrowsLibExn.parse(s) catch {
      | ThrowsLibExn.E => 0
      }
Before (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception
    Exception Analysis
    ThrowsLibExnCalls.res:4:5-17
    catchExternal might throw E (ThrowsLibExnCalls.res:5:6) and is not annotated with @throws(E)

    Exception Analysis
    ThrowsRepoCalls.res:18:5-16
    catchViaOpen might throw Bad (ThrowsRepoCalls.res:19:6) and is not annotated with @throws(Bad)

    Exception Analysis
    ThrowsScopes.res:2:5-18
    catchIfaceOpen might throw NotFound (ThrowsScopes.res:3:6) and is not annotated with @throws(NotFound)

    Exception Analysis
    ThrowsLibExnCalls.res:103:7-12
    caught might throw E (ThrowsLibExnCalls.res:104:8) and is not annotated with @throws(E)

    …

    Exception Analysis
    ThrowsLibExnCalls.res:81:5-16
    catchRebound might throw E (ThrowsLibExnCalls.res:82:6) and is not annotated with @throws(E)
After (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception
    Exception Analysis
    ThrowsLibExnCalls.res:81:5-16
    catchRebound might throw ThrowsLibExn.E (ThrowsLibExnCalls.res:82:6) and is not annotated with @throws(ThrowsLibExn.E)

Review: Why an identity from the file and name instead of the path? The type checker has no module prefix for a file's own exceptions, and a path changes with aliases and namespaces. The file and name are the same through every alias, open, include and functor, and in the .res and .resi.
Review: Does this recompile more? Only the attribute is new, and it holds names, not positions, so it changes only when the exception is renamed or moves to another file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHA54VKxsXvCQyC2vw
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the drift-9182-temporal-exn branch from 52da1a6 to 866c860 Compare November 20, 2026 21:12
cknitt added a commit that referenced this pull request Nov 20, 2026
…citly

Why:
    Codex review on #9198: the compiler's new @throws reader dropped
    `list{A, B}` payloads and constructors written with arguments, which
    reanalyze's old reader accepted, so such annotations silently stopped
    declaring anything. It also derived an exception's identity from a
    location that a .cmi built with -no-keep-locs (the runtime's and
    Belt's) does not keep.

The reader again takes `list{...}` and `M.E(...)` as before. An exception
whose .cmi has no locations is now identified as `#Name` on purpose,
rather than through the placeholder file name `_none_`. Codex's crash
report for that case does not hold, since `Filename.remove_extension`
does not raise on `_none_`, but the identity was accidental.

AST modified (res.throws for a list payload):
Example:
    exception E
    @throws(list{E, Not_found})
    let f = () => throw(E)
Before (text): number of res.throws attributes in bsc -dtypedtree
    0
After (text): number of res.throws attributes in bsc -dtypedtree
    1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHA54VKxsXvCQyC2vw
Signed-off-by: Christoph Knittel <ck@cca.io>
cknitt added a commit that referenced this pull request Nov 20, 2026
… exactly

Why:
    Review of #9198: the type checker loads the module a @throws names, but
    the dependency scanner skipped attributes. A module named only there was
    built in any order, so the name resolved or got warning 113 depending
    on the build, and a later edit could fail with "inconsistent
    assumptions". Messages also named an exception defined in a nested
    module without that module, so the annotation they suggested did not
    resolve. And a library built with -no-keep-locs recorded its own
    exceptions with its file, while its users see them without one.

`Depend` now adds the modules a @throws names, like any other use, so
they are built first. A module that is both named in @throws and depends
on the annotating module now gives a dependency cycle error.

`Typemod` records which module of the current file defines each
exception and module, so a file's own exception is named `Lib.Inner.F`.
Under -no-keep-locs a file's own exceptions are identified by name alone
also while it is compiled. Warning 113 is shown once for a `let` that
destructures a tuple.

Diagnostic modified (an exception of a nested module):
Example:
    // ThrowsLibExn.res
    module Inner = {
      exception F
      @throws(F)
      external find: int => int = "findThrowing"
    }

    // ThrowsLibExnCalls.res
    let uncaughtNested = x => ThrowsLibExn.Inner.find(x)
Before (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception/ThrowsLibExnCalls.res
    Exception Analysis
    ThrowsLibExnCalls.res:110:5-18
    uncaughtNested might throw ThrowsLibExn.F (ThrowsLibExnCalls.res:110:26) and is not annotated with @throws(ThrowsLibExn.F)
After (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception/ThrowsLibExnCalls.res
    Exception Analysis
    ThrowsLibExnCalls.res:110:5-18
    uncaughtNested might throw ThrowsLibExn.Inner.F (ThrowsLibExnCalls.res:110:26) and is not annotated with @throws(ThrowsLibExn.Inner.F)

Diagnostic modified (a module named only in @throws, tests/build_tests/throws_dependency):
Example:
    // A.res
    @throws(Z.E)
    external find: int => int = "find"

    // Z.res
    exception E
Before (diagnostic): A.res built before Z.res
    Warning number 113
    @throws names Z.E, which is not an exception in scope here. Exception analysis cannot match it with the exceptions callers catch.
After (diagnostic): Z.res built first, no warning

Breaking: A module named in @throws that itself depends on the annotating module is now a dependency cycle. Move the exception to a module of its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHA54VKxsXvCQyC2vw
Signed-off-by: Christoph Knittel <ck@cca.io>
cknitt and others added 5 commits November 23, 2026 06:34
Why:
    The exception analysis knew what library functions throw only from a
    table kept by hand in exn_lib.ml. The table drifted: the Temporal
    `fromStringOrThrow` functions were never added (#9182), and neither
    were a few Intl and Belt ones. Third-party libraries and a project's
    own externals had no way to say what they throw.

A call now takes the exceptions named by the `@throws` on the declaration
of the value it calls, and the table is gone. The `.cmi` keeps the
attributes of externals and interface declarations, so their `@throws`
reaches calls in other modules and packages, through aliases, `open`,
`include`, functors and first-class modules. For a `let` in a module
without an interface, the type checker now copies the binding's `@throws`
into the inferred signature, as it already did for `@deprecated`. The
stdlib and Belt declare what their throwing functions throw, and a guard
in the reanalyze tests fails when a stdlib or Belt `*OrThrow` or `*Exn`
declaration has no `@throws(...)`.

Analysis modified (exceptions of a call to `f`, `Exception.Event` loop):
Before (rule):
    throws(`f`) = values(`f`)   when `f` is in the values table
    throws(`f`) = table(`f`)   otherwise
After (rule):
    throws(`f`) = declared(`f`) ∪ values(`f`)

Signature modified (inferred signature of a module without an interface, `Typemod.type_structure`):
Example:
    /** Finds the value. */
    @throws(Not_found)
    let find = x => x > 0 ? x : throw(Not_found)
Before (rescript): the signature in the .cmi
    let find: int => int
After (rescript):
    @throws(Not_found)
    let find: int => int

Reanalyze modified (calls to annotated externals):
Example:
    // Lib.res
    @throws(JsExn)
    external parse: string => int = "parseInt"

    // App.res
    let parse = s => Lib.parse(s)

    @throws(JsExn)
    let parseAnnotated = s => Lib.parse(s)

    let date = () => Temporal.PlainDate.fromStringOrThrow("x")
Before (reanalyze):
    Exception Analysis
    App.res:4:5-18
    parseAnnotated throws nothing and is annotated with redundant @throws(JsExn)

    Analysis reported 1 issues (Exception Analysis:1)
After (reanalyze):
    Exception Analysis
    App.res:1:5-9
    parse might throw JsExn (App.res:1:17) and is not annotated with @throws(JsExn)

    Exception Analysis
    App.res:6:5-8
    date might throw JsExn (App.res:6:17) and is not annotated with @throws(JsExn)

    Analysis reported 2 issues (Exception Analysis:2)

Review: Why the union of the declaration and the values table, rather than
one winning? The values table holds the `@throws` on the implementation's
binding, the declaration the one in its interface. Either can be the only
one written, as with an annotated `.resi` `let` whose `.res` isn't
annotated, so the call can throw what either names.

Review: Why does the inferred signature take only the `@throws` family and
`@deprecated`, and not every attribute? A doc comment is an attribute too:
in the `.cmi` it would make editing a comment recompile the module's
dependents. A module with a `.resi` is unchanged, since its `.cmi` holds
the interface's declarations.

Review: What does a `@throws` without a payload mean? Nothing, as on a
binding. The guard requires a payload, and the stdlib's two payload-less
`@throws` in Stdlib_JSON.res now name `JsExn`.

Fixes #9182

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gGhHjzBTXqSo8Dckpb
Signed-off-by: Christoph Knittel <ck@cca.io>
Why:
    Since #9245 every .cmt lands in the flat lib/rescript, so the empty
    src/exception/BsJson.res logged "Implementation 0" in the deadcode
    debug output. This PR deletes that file, so the line goes away.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHi59ptFC3WWfiDQH4
Signed-off-by: Christoph Knittel <ck@cca.io>
Why:
    Review on #9198: a library's `@throws(E)` reached callers as the bare
    name `E`, while a catch was compared as written (`Lib.E`), so a correct
    catch was still reported and a caller's own `E` could hide the
    library's. Reanalyze cannot resolve names itself, because a .cmt keeps
    no environments; two attempts to guess the scope from the file still
    got opens in interfaces, functors, includes and aliases wrong.

The type checker now looks up each name in a `@throws` where it is
written, for externals, `let`s in signatures and interfaces, and every
`let` binding. It adds a generated `@res.throws` that lists each
exception's readable name and identity, and the inferred signature keeps
it next to `@throws`. The identity is the defining file without its
extension and the exception's name (`src/Lib#E`), so a module's .res and
.resi agree and moving a definition within its file changes nothing.
Exception analysis compares these identities with the constructors that
catches and throws name.

A name that is not an exception in scope gets the new warning 113 and is
listed as written. A rebinding (`exception Mine = Lib.E`) is a new
definition, so catching `Mine` does not catch `Lib.E`, as before. Two
exceptions with the same name in one file share an identity.

Typedtree modified (@throws resolved where it is written):
Example:
    module Errors = {
      exception NotFound
    }
    open Errors
    @throws(NotFound)
    external find: int => int = "find"
Before (typed):
    Tstr_primitive
    value_description find/1003
      attribute "throws"
        [
          structure_item
            Pstr_eval
            expression
              Pexp_construct "NotFound"
              []
        ]
After (typed):
    Tstr_primitive
    value_description find/1003
      attribute "throws"
        [
          structure_item
            Pstr_eval
            expression
              Pexp_construct "NotFound"
              []
        ]
      attribute "res.throws"
        [
          structure_item
            Pstr_eval
            expression
              Pexp_array
              [
                expression
                  Pexp_tuple
                  [
                    expression
                      Pexp_constant PConst_string (source="Repo.Errors.NotFound", semantic="Repo.Errors.NotFound")
                    expression
                      Pexp_constant PConst_string (source="Repo#NotFound", semantic="Repo#NotFound")
                  ]
              ]
        ]

Diagnostic added (warning 113):
Example:
    @throws(Missing)
    let f = () => 1
After (diagnostic): tests/build_tests/super_errors/fixtures/throws_unbound_warning.res
    Warning number 113
    throws_unbound_warning.res:3:9-15

    @throws names Missing, which is not an exception in scope here. Exception analysis cannot match it with the exceptions callers catch.

Reanalyze modified (catches of another module's exceptions):
Example:
    // ThrowsLibExn.res
    exception E
    @throws(E)
    external parse: string => int = "parseThrowing"

    // ThrowsLibExnCalls.res
    let catchExternal = s =>
      try ThrowsLibExn.parse(s) catch {
      | ThrowsLibExn.E => 0
      }
Before (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception
    Exception Analysis
    ThrowsLibExnCalls.res:4:5-17
    catchExternal might throw E (ThrowsLibExnCalls.res:5:6) and is not annotated with @throws(E)

    Exception Analysis
    ThrowsRepoCalls.res:18:5-16
    catchViaOpen might throw Bad (ThrowsRepoCalls.res:19:6) and is not annotated with @throws(Bad)

    Exception Analysis
    ThrowsScopes.res:2:5-18
    catchIfaceOpen might throw NotFound (ThrowsScopes.res:3:6) and is not annotated with @throws(NotFound)

    Exception Analysis
    ThrowsLibExnCalls.res:103:7-12
    caught might throw E (ThrowsLibExnCalls.res:104:8) and is not annotated with @throws(E)

    …

    Exception Analysis
    ThrowsLibExnCalls.res:81:5-16
    catchRebound might throw E (ThrowsLibExnCalls.res:82:6) and is not annotated with @throws(E)
After (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception
    Exception Analysis
    ThrowsLibExnCalls.res:81:5-16
    catchRebound might throw ThrowsLibExn.E (ThrowsLibExnCalls.res:82:6) and is not annotated with @throws(ThrowsLibExn.E)

Review: Why an identity from the file and name instead of the path? The type checker has no module prefix for a file's own exceptions, and a path changes with aliases and namespaces. The file and name are the same through every alias, open, include and functor, and in the .res and .resi.
Review: Does this recompile more? Only the attribute is new, and it holds names, not positions, so it changes only when the exception is renamed or moves to another file.

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

Why:
    Codex review on #9198: the compiler's new @throws reader dropped
    `list{A, B}` payloads and constructors written with arguments, which
    reanalyze's old reader accepted, so such annotations silently stopped
    declaring anything. It also derived an exception's identity from a
    location that a .cmi built with -no-keep-locs (the runtime's and
    Belt's) does not keep.

The reader again takes `list{...}` and `M.E(...)` as before. An exception
whose .cmi has no locations is now identified as `#Name` on purpose,
rather than through the placeholder file name `_none_`. Codex's crash
report for that case does not hold, since `Filename.remove_extension`
does not raise on `_none_`, but the identity was accidental.

AST modified (res.throws for a list payload):
Example:
    exception E
    @throws(list{E, Not_found})
    let f = () => throw(E)
Before (text): number of res.throws attributes in bsc -dtypedtree
    0
After (text): number of res.throws attributes in bsc -dtypedtree
    1

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

Why:
    Review of #9198: the type checker loads the module a @throws names, but
    the dependency scanner skipped attributes. A module named only there was
    built in any order, so the name resolved or got warning 113 depending
    on the build, and a later edit could fail with "inconsistent
    assumptions". Messages also named an exception defined in a nested
    module without that module, so the annotation they suggested did not
    resolve. And a library built with -no-keep-locs recorded its own
    exceptions with its file, while its users see them without one.

`Depend` now adds the modules a @throws names, like any other use, so
they are built first. A module that is both named in @throws and depends
on the annotating module now gives a dependency cycle error.

`Typemod` records which module of the current file defines each
exception and module, so a file's own exception is named `Lib.Inner.F`.
Under -no-keep-locs a file's own exceptions are identified by name alone
also while it is compiled. Warning 113 is shown once for a `let` that
destructures a tuple.

Diagnostic modified (an exception of a nested module):
Example:
    // ThrowsLibExn.res
    module Inner = {
      exception F
      @throws(F)
      external find: int => int = "findThrowing"
    }

    // ThrowsLibExnCalls.res
    let uncaughtNested = x => ThrowsLibExn.Inner.find(x)
Before (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception/ThrowsLibExnCalls.res
    Exception Analysis
    ThrowsLibExnCalls.res:110:5-18
    uncaughtNested might throw ThrowsLibExn.F (ThrowsLibExnCalls.res:110:26) and is not annotated with @throws(ThrowsLibExn.F)
After (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception/ThrowsLibExnCalls.res
    Exception Analysis
    ThrowsLibExnCalls.res:110:5-18
    uncaughtNested might throw ThrowsLibExn.Inner.F (ThrowsLibExnCalls.res:110:26) and is not annotated with @throws(ThrowsLibExn.Inner.F)

Diagnostic modified (a module named only in @throws, tests/build_tests/throws_dependency):
Example:
    // A.res
    @throws(Z.E)
    external find: int => int = "find"

    // Z.res
    exception E
Before (diagnostic): A.res built before Z.res
    Warning number 113
    @throws names Z.E, which is not an exception in scope here. Exception analysis cannot match it with the exceptions callers catch.
After (diagnostic): Z.res built first, no warning

Breaking: A module named in @throws that itself depends on the annotating module is now a dependency cycle. Move the exception to a module of its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHA54VKxsXvCQyC2vw
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the drift-9182-temporal-exn branch from 866c860 to 629ea53 Compare November 23, 2026 06:47

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.

Exception analysis does not know the Temporal fromStringOrThrow functions

2 participants