Skip to content

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

Open
cknitt wants to merge 1 commit into
masterfrom
drift-9182-temporal-exn
Open

cknitt wants to merge 1 commit into
masterfrom
drift-9182-temporal-exn

Conversation

@cknitt

@cknitt cknitt commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Fixes #9182

The problem

Exception analysis (rescript-tools reanalyze -exception) knew which library functions throw only from a hand-written table in analysis/reanalyze/src/exn_lib.ml, and that table fell behind the standard library. #9182 is one example: the eight Temporal fromStringOrThrow functions were never added, so Temporal.PlainDate.fromStringOrThrow("x") counted as throwing nothing. Some Intl and Belt functions were missing too. Third-party libraries and a project's own externals had no way to declare their exceptions at all.

The fix

The table is gone. Functions declare their exceptions with @throws where they are declared, and the analysis reads that at each call.

@throws on declarations reaches callers. The .cmi keeps the attributes of externals and of lets in interfaces, so their @throws reaches calls from other modules and packages, including calls through aliases, open, include, functor results and first-class modules.

A let without an interface keeps its @throws too. Until now, a let in a module without a .resi lost its attributes in the inferred signature, which is why Stdlib.panic had to be in the table. The type checker already copied @deprecated into the signature (#8924); it now copies @throws the same way. Nothing else is copied: a doc comment in the .cmi, for example, would make every edit of it recompile the module's dependents. The .cmi format is unchanged.

The stdlib and Belt annotate themselves. Every function the table listed now has its own @throws, in its .resi, or in its .res where there is no interface:

  • the getExn/getOrThrow family across Belt's collections, Option and Result
  • Belt.Array.getExn and setExn (Assert_failure)
  • the *OrThrow functions of List, Null, Nullable, Option, Result, Bool and BigInt
  • JSON.parseOrThrow and stringifyAny
  • the JsError functions that throw
  • / and mod (Division_by_zero)
  • Stdlib.panic and Stdlib.assertEqual

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

A guard keeps the annotations complete. tests/analysis_tests/tests-reanalyze/checkThrowsAnnotations.mjs runs before the reanalyze tests and fails if a stdlib or Belt function named *OrThrow or *Exn has no @throws. JsError.toJsExn is exempt, because it converts a value and throws nothing.

Decisions to review

The declaration wins over the implementation. A call's exceptions come from the @throws of the declaration the caller sees, for example a let in a .resi. Only when that declaration has no @throws does the analysis fall back to the @throws on the implementation's own let, so an annotated .res behind an unannotated .resi still counts. If both are annotated, the interface wins, because its exceptions are the ones callers know about. The downside: when a .resi lists fewer exceptions than its .res, the extra ones are hidden from callers.

Functions that throw only for some arguments stay unannotated, when their names don't say so: the Temporal constructors and arithmetic, Int.range with a step of 0, and Date.toTemporalInstant on an invalid date. Annotating them would flag every call. The % operator was never in the table either, although it is the same primitive as mod.

Known limit

Exception analysis still compares exceptions by name, as on master. That is exact for the predefined exceptions all stdlib and Belt annotations name, such as Not_found and JsExn. It is not exact for a library's own exceptions: a library's @throws(E) reaches the caller as E, while the caller's catch says Lib.E. #9476, stacked on this PR, fixes that.

Tests

  • New reanalyze exception tests (ThrowsDecl.res, ThrowsIface.res/.resi, ThrowsDeclCalls.res) call annotated externals, .resi lets and module type members from another module, also through a pipe, an alias, open, include, a functor and a first-class module. callViaLetIncluded is only reported because a let without an interface now keeps its @throws in the signature. callImplOnlyIncluded checks that an unannotated .resi still hides an annotated .res binding from other modules.
  • catchNarrowed calls a function whose .resi lists fewer exceptions than its .res, and only the interface's count.
  • StdlibTest.res and BeltTest.res cover the new stdlib and Belt annotations, including panic and assertEqual.
  • ExnPayloadGuard.res replaces the deleted Yojson test: catching an exception with a payload pattern and a guard.

🤖 Generated with Claude Code

@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 88.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.49%. Comparing base (5e5a3a7) to head (d5177af).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
analysis/reanalyze/src/exception.ml 86.36% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9198      +/-   ##
==========================================
+ Coverage   82.47%   82.49%   +0.02%     
==========================================
  Files         466      466              
  Lines       66070    66122      +52     
==========================================
+ Hits        54493    54550      +57     
+ Misses      11577    11572       -5     
Files with missing lines Coverage Δ
analysis/reanalyze/src/exn.ml 100.00% <ø> (ø)
compiler/typing/typemod.ml 77.89% <100.00%> (+0.19%) ⬆️
analysis/reanalyze/src/exception.ml 81.63% <86.36%> (+0.06%) ⬆️

... and 5 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: d5177af

@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-29T08:30:55.572628Z 4bcdd86 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

🚀 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

d5177af · cknitt + Claude · Nov 30, 2026, 19:51 UTC · edited

Why

Exception analysis knew which library functions throw only from a hand-written table in exn_lib.ml, and the table fell behind. The Temporal fromStringOrThrow functions were never added (#9182), and neither were some Intl and Belt functions. Third-party libraries and a project's own externals had no way to declare their exceptions.

The table is gone. At each call, the analysis now reads the @throws on the declaration of the called function. The .cmi keeps the attributes of externals and of lets in interfaces, so their @throws reaches calls in other modules and packages.

A let in a module without an interface used to lose its attributes in the inferred signature. The type checker now copies its @throws there, as it already did for @deprecated.

The stdlib and Belt annotate their throwing functions themselves. A guard in the reanalyze tests fails when a stdlib or Belt function named *OrThrow or *Exn has no @throws.

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

rule

BeforeAfter
$$\begin{array}{l}\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 \mathrm{otherwise}\end{array}$$ $$\begin{array}{l}\color{green}{\mathrm{throws}(\texttt{f})=\mathrm{declared}(\texttt{f})} \qquad \color{green}{\mathrm{when}\ \mathrm{the}\ \mathrm{declaration}\ \mathrm{has}\ a\ \texttt{@throws}} \\ \mathrm{throws}(\texttt{f})=\mathrm{values}(\texttt{f}) \qquad \mathrm{otherwise}\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 does the declaration win over the implementation? The values table holds the @throws on the implementation's let. When the interface has a @throws, that is what callers see, so it counts alone. When it has none, the implementation's counts, so an annotated .res behind an unannotated .resi still works.
  • Why does the inferred signature copy only @throws and @deprecated? A doc comment is an attribute too, and keeping it in the .cmi would make every edit of the comment recompile the module's dependents. A module with a .resi is unaffected, because its .cmi comes from the interface.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

✅ Compiler benchmarks

Allocated words

In total: 655,166,578 → 655,275,138 (+0.02%).

Generated projects: 627,288,916 → 627,288,719 (±0.00%).

Benchmark Base Head Change
packages/@rescript/runtime/Stdlib_JsError.resi (inputs changed) 183,663 188,839 +2.82%
packages/@rescript/belt/src/Belt_MutableQueue.resi (inputs changed) 204,909 207,360 +1.20%
packages/@rescript/runtime/Stdlib_Intl.res (inputs changed) 174,232 176,188 +1.12%
packages/@rescript/runtime/Stdlib_BigInt.resi (inputs changed) 184,957 186,186 +0.66%
packages/@rescript/belt/src/Belt_Result.resi (inputs changed) 237,790 239,365 +0.66%
packages/@rescript/runtime/Stdlib_JSON.resi (inputs changed) 235,028 236,564 +0.65%
packages/@rescript/runtime/Stdlib_Bool.resi (inputs changed) 116,452 117,122 +0.58%
packages/@rescript/belt/src/Belt_Option.resi (inputs changed) 240,005 241,325 +0.55%
packages/@rescript/runtime/Pervasives.res (inputs changed) 237,697 238,986 +0.54%
packages/@rescript/belt/src/Belt_SetString.resi (inputs changed) 257,354 258,694 +0.52%
56 more changes
Benchmark Base Head Change
packages/@rescript/belt/src/Belt_SetInt.resi (inputs changed) 257,481 258,819 +0.52%
packages/@rescript/belt/src/Belt_MutableSetInt.resi (inputs changed) 262,677 264,012 +0.51%
packages/@rescript/belt/src/Belt_MutableSetString.resi (inputs changed) 262,560 263,894 +0.51%
packages/@rescript/belt/src/Belt_List.resi (inputs changed) 741,563 745,162 +0.49%
packages/@rescript/belt/src/Belt_MutableStack.resi (inputs changed) 168,402 169,159 +0.45%
packages/@rescript/runtime/Stdlib_List.resi (inputs changed) 402,079 403,877 +0.45%
packages/@rescript/belt/src/Belt_MutableMapInt.resi (inputs changed) 310,911 312,273 +0.44%
packages/@rescript/belt/src/Belt_MutableMapString.resi (inputs changed) 310,793 312,153 +0.44%
packages/@rescript/belt/src/Belt_MutableMap.resi (inputs changed) 389,518 391,073 +0.40%
packages/@rescript/belt/src/Belt_Array.resi (inputs changed) 638,368 640,855 +0.39%
packages/@rescript/belt/src/Belt_MutableSet.resi (inputs changed) 391,378 392,884 +0.38%
packages/@rescript/runtime/Stdlib_JSON.res (inputs changed) 293,997 295,097 +0.37%
packages/@rescript/belt/src/Belt_Set.resi (inputs changed) 430,814 432,417 +0.37%
packages/@rescript/runtime/Stdlib_Null.resi (inputs changed) 202,541 203,265 +0.36%
packages/@rescript/belt/src/Belt_MapInt.resi (inputs changed) 385,339 386,683 +0.35%
packages/@rescript/belt/src/Belt_MapString.resi (inputs changed) 385,296 386,639 +0.35%
packages/@rescript/runtime/Stdlib_Nullable.resi (inputs changed) 197,831 198,509 +0.34%
packages/@rescript/belt/src/Belt_SetDict.resi (inputs changed) 395,822 397,148 +0.33%
packages/@rescript/runtime/Stdlib_Result.resi (inputs changed) 291,632 292,545 +0.31%
packages/@rescript/runtime/Stdlib_Temporal_Instant.res (inputs changed) 306,238 307,196 +0.31%
packages/@rescript/belt/src/Belt_Map.resi (inputs changed) 568,597 570,201 +0.28%
packages/@rescript/runtime/Stdlib.res (inputs changed) 981,060 983,814 +0.28%
packages/@rescript/runtime/Stdlib_Option.resi (inputs changed) 233,326 233,979 +0.28%
packages/@rescript/belt/src/Belt_MapDict.resi (inputs changed) 503,326 504,665 +0.27%
packages/@rescript/runtime/Stdlib_Temporal_PlainMonthDay.res (inputs changed) 267,009 267,707 +0.26%
packages/@rescript/runtime/Stdlib_JsError.res (inputs changed) 226,382 226,878 +0.22%
packages/@rescript/runtime/Stdlib_Temporal_PlainTime.res (inputs changed) 318,834 319,532 +0.22%
packages/@rescript/belt/src/Belt_internalAVLset.resi (inputs changed) 351,481 352,246 +0.22%
packages/@rescript/runtime/Stdlib_Temporal.res (inputs changed) 224,381 224,829 +0.20%
packages/@rescript/belt/src/Belt_internalSetInt.res (inputs changed) 711,919 713,312 +0.20%
packages/@rescript/belt/src/Belt_internalSetString.res (inputs changed) 713,110 714,501 +0.20%
packages/@rescript/runtime/Stdlib_Temporal_Duration.res (inputs changed) 371,742 372,445 +0.19%
packages/@rescript/runtime/Stdlib_Temporal_PlainYearMonth.res (inputs changed) 380,464 381,163 +0.18%
packages/@rescript/runtime/Stdlib_Temporal_PlainDate.res (inputs changed) 402,162 402,860 +0.17%
packages/@rescript/belt/src/Belt_internalAVLtree.resi (inputs changed) 446,516 447,276 +0.17%
packages/@rescript/runtime/RescriptTools_ExtractCodeBlocks.res (inputs changed) 112,332 112,517 +0.16%
packages/@rescript/runtime/Stdlib_Temporal_PlainDateTime.res (inputs changed) 436,276 436,977 +0.16%
packages/@rescript/belt/src/Belt_internalBucketsType.res (inputs changed) 287,147 287,520 +0.13%
packages/@rescript/belt/src/Belt_Int.resi (inputs changed) 149,248 149,435 +0.13%
packages/@rescript/belt/src/Belt_Float.resi (inputs changed) 150,728 150,915 +0.12%
packages/@rescript/runtime/Stdlib_Temporal_ZonedDateTime.res (inputs changed) 571,658 572,358 +0.12%
packages/@rescript/belt/src/Belt_Float.res (inputs changed) 164,368 164,555 +0.11%
packages/@rescript/belt/src/Belt_internalBucketsType.resi (inputs changed) 164,482 164,669 +0.11%
packages/@rescript/runtime/Stdlib_Int.res (inputs changed) 445,261 445,767 +0.11%
packages/@rescript/belt/src/Belt_Int.res (inputs changed) 165,107 165,294 +0.11%
packages/@rescript/belt/src/Belt_SortArrayString.resi (inputs changed) 168,979 169,166 +0.11%
packages/@rescript/belt/src/Belt_SortArrayInt.resi (inputs changed) 169,097 169,284 +0.11%
packages/@rescript/belt/src/Belt_HashSetString.resi (inputs changed) 174,889 175,076 +0.11%
packages/@rescript/belt/src/Belt_HashSetInt.resi (inputs changed) 175,002 175,189 +0.11%
packages/@rescript/belt/src/Belt_Range.resi (inputs changed) 175,733 175,920 +0.11%
packages/@rescript/runtime/Primitive_list.resi (inputs changed) 92,040 92,136 +0.10%
packages/@rescript/runtime/Primitive_float_extern.res (inputs changed) 93,939 94,035 +0.10%
packages/@rescript/runtime/Stdlib_Blob.res (inputs changed) 94,180 94,276 +0.10%
packages/@rescript/belt/src/Belt_internalMapInt.res (inputs changed) 1,368,882 1,370,271 +0.10%
packages/@rescript/belt/src/Belt_internalMapString.res (inputs changed) 1,370,726 1,372,115 +0.10%
packages/@rescript/runtime/Stdlib_File.res (inputs changed) 95,983 96,079 +0.10%

(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,128,430,307 → 9,128,887,418 (+0.01%).

Benchmark Base Head Change
packages/@rescript/belt/src/Belt_List.resi (inputs changed) 38,769,728 38,925,557 +0.40%
packages/@rescript/runtime/Stdlib_List.resi (inputs changed) 24,444,429 24,514,917 +0.29%
packages/@rescript/belt/src/Belt_Array.resi (inputs changed) 33,598,584 33,687,120 +0.26%
packages/@rescript/runtime/Stdlib_Temporal_PlainDate.res (inputs changed) 24,077,531 24,102,826 +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.

Output size

In total: 27,368,788 → 27,388,490 (+0.07%).

Benchmark Base Head Change
output/belt/*.cmi (inputs changed) 460,980 463,514 +0.55%
output/belt/*.cmti (inputs changed) 980,059 985,003 +0.50%
output/runtime/*.cmti (inputs changed) 1,115,108 1,117,100 +0.18%

(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 d5177af compared with base 4717690 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

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 added a commit that referenced this pull request Nov 23, 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 866c860 to 629ea53 Compare November 23, 2026 06:47
cknitt added a commit that referenced this pull request Nov 23, 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 23, 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 29, 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 added a commit that referenced this pull request Nov 29, 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
cknitt force-pushed the drift-9182-temporal-exn branch from 629ea53 to d19eb02 Compare November 29, 2026 07:11
cknitt added a commit that referenced this pull request Nov 29, 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/projects/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 commented Nov 29, 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: d19eb02243

ℹ️ 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/typing/throws_attribute.ml Resolved
cknitt added a commit that referenced this pull request Nov 29, 2026
Why:
    Codex review on #9198: an exception's identity came from its location,
    which a .cmi built with -no-keep-locs drops but the .cmt keeps. So in
    such a project the compiler recorded `#E` for `@throws(E)` while
    reanalyze computed the file-based identity for `throw(E)`, and an
    annotated function was reported as both missing and redundant.

The type checker now records the identity when it types an exception, in
a generated `@res.exn` attribute on the definition, and everything reads
it from there: the unit and module path, as `Lib.Inner.F`. Attributes
survive -no-keep-locs, and the identity holds no file paths. A rebound
exception (`exception Mine = Lib.E`) carries the identity of the one it
rebinds, so catching `Mine` now catches `Lib.E`. Exceptions of the same
name in different modules of one file no longer share an identity.

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

    // ThrowsLibExnCalls.res
    exception Rebound = ThrowsLibExn.E
    let catchRebound = s =>
      try ThrowsLibExn.parse(s) catch {
      | Rebound => 0
      }
Before (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception/ThrowsLibExnCalls.res
    Exception Analysis
    ThrowsLibExnCalls.res:81:5-16
    catchRebound might throw ThrowsLibExn.E (ThrowsLibExnCalls.res:82:6) and is not annotated with @throws(ThrowsLibExn.E)
After (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception/ThrowsLibExnCalls.res
    Analysis reported no issue for catchRebound

Review: How was the -no-keep-locs case checked? The whole reanalyze test project built with -no-keep-locs gives the same 55 findings as without it, and so does a namespaced build.

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 commented Nov 29, 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: 1656650f46

ℹ️ 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/typing/typemod.ml Resolved
Comment thread compiler/typing/throws_attribute.ml Resolved
@cknitt
cknitt force-pushed the drift-9182-temporal-exn branch from 1656650 to 1feb838 Compare November 29, 2026 07:37
@cknitt
cknitt added this pull request to stack #9477 November 29, 2026 07:38
@cknitt
cknitt force-pushed the drift-9182-temporal-exn branch from 1feb838 to 4bcdd86 Compare November 29, 2026 08:05
cknitt added a commit that referenced this pull request Nov 29, 2026
Why:
    Review on #9198: exception analysis compares exceptions by name, and a
    library's `@throws(E)` reached callers as the bare name `E`, while a
    catch was spelled `Lib.E`. So a correct catch was still reported, and a
    caller's own `E` could hide the library's. Reanalyze cannot resolve the
    names itself, because a .cmt keeps no environments.

The type checker now gives every exception an identity and resolves the
names in a `@throws` where they are written:
- When it types an exception, it records the identity, the unit and
  module path (`Lib.Inner.F`), in a generated `@res.exn` attribute on the
  definition. A rebound exception (`exception Mine = Lib.E`) carries the
  identity of the one it rebinds.
- For a `@throws` on an external, a `let` in a signature or interface, or
  any `let` binding, it looks each name up and adds a generated
  `@res.throws` listing each exception's name and identity. The inferred
  signature keeps it next to `@throws`.
- A name that is not an exception in scope gets the new warning 113 and is
  listed as written; lowercase names, which are never exceptions, do not
  warn. The first exception of that name counts, so a variant constructor
  declared later does not hide it. A payload may be one name or an array,
  tuple or `list{...}` of names.
- `Depend` counts the modules a `@throws` names as dependencies, since the
  type checker loads them.

Exception analysis compares those identities with the constructors that
catches and throws use. A call's exceptions are the declaration's
resolved `@throws`, or, when it has none, the implementation binding's:
the declaration is what callers see. Messages name an exception as the
code they are about would, relative to its enclosing module.

Known limits: an identity belongs to a declaration, and a signature's
`exception E` is a different declaration from the definition it hides.
So when only an implementation sealed by a module type annotates its
`@throws`, callers' catches of the module's `E` do not match it, and
modules sealed by one module type share its exceptions' identities. The
exceptions of two applications of one functor share an identity, and so
do same-named exceptions of a functor's parameter and body, or of a local
module and its enclosing module. A `@throws(X.E)` for an exception that a
functor parameter's module type declares keeps that declaration's
identity.

Reanalyze modified (exceptions of other modules):
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
      }
    exception E
    let catchUnrelatedLocal = s =>
      try ThrowsLibExn.parse(s) catch {
      | 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:29:5-20
    annotatedViaOpen might throw ThrowsErrors.NotFound (ThrowsRepoCalls.res:29:28) and is annotated with redundant @throws(NotFound)

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

    …
After (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception
    Exception Analysis
    ThrowsLibExnCalls.res:42:5-23
    catchUnrelatedLocal might throw ThrowsLibExn.E (ThrowsLibExnCalls.res:43:6) and is not annotated with @throws(ThrowsLibExn.E)

    …

Diagnostic added (warning 113):
Example:
    @throws(Missing)
    let f = () => 1
After (diagnostic): tests/error_tests/single/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.

Review: Why identities in the type checker, not in reanalyze? Only the type checker knows which exception a name means. Two attempts to rebuild the scope in reanalyze kept missing opens in interfaces, includes, functors and aliases.

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 commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 4bcdd86146

ℹ️ 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 added a commit that referenced this pull request Nov 29, 2026
Why:
    Review on #9198: exception analysis compares exceptions by name, and a
    library's `@throws(E)` reached callers as the bare name `E`, while a
    catch was spelled `Lib.E`. So a correct catch was still reported, and a
    caller's own `E` could hide the library's. Reanalyze cannot resolve the
    names itself, because a .cmt keeps no environments.

The type checker now gives every exception an identity and resolves the
names in a `@throws` where they are written:
- When it types an exception, it records the identity, the unit and
  module path (`Lib.Inner.F`), in a generated `@res.exn` attribute on the
  definition. A rebound exception (`exception Mine = Lib.E`) carries the
  identity of the one it rebinds.
- For a `@throws` on an external, a `let` in a signature or interface, or
  any `let` binding, it looks each name up and adds a generated
  `@res.throws` listing each exception's name and identity. The inferred
  signature keeps it next to `@throws`.
- A name that is not an exception in scope gets the new warning 113 and is
  listed as written; lowercase names, which are never exceptions, do not
  warn. The first exception of that name counts, so a variant constructor
  declared later does not hide it. A payload may be one name, as a
  constructor or a string (also a template), or an array, tuple or
  `list{...}` of names, in braces or not.
- `Depend` counts the modules a `@throws` names as dependencies, since the
  type checker loads them.

Exception analysis compares those identities with the constructors that
catches and throws use. A call's exceptions are the declaration's
resolved `@throws`, or, when it has none, the implementation binding's:
the declaration is what callers see. Messages name an exception as the
code they are about would, relative to its enclosing module.

Known limits: an identity belongs to a declaration, and a signature's
`exception E` is a different declaration from the definition it hides.
So when only an implementation sealed by a module type annotates its
`@throws`, callers' catches of the module's `E` do not match it, and
modules sealed by one module type share its exceptions' identities. The
exceptions of two applications of one functor share an identity, and so
do same-named exceptions of a functor's parameter and body, or of a local
module and its enclosing module. A `@throws(X.E)` for an exception that a
functor parameter's module type declares keeps that declaration's
identity.

Reanalyze modified (exceptions of other modules):
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
      }
    exception E
    let catchUnrelatedLocal = s =>
      try ThrowsLibExn.parse(s) catch {
      | 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:29:5-20
    annotatedViaOpen might throw ThrowsErrors.NotFound (ThrowsRepoCalls.res:29:28) and is annotated with redundant @throws(NotFound)

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

    …
After (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception
    Exception Analysis
    ThrowsLibExnCalls.res:42:5-23
    catchUnrelatedLocal might throw ThrowsLibExn.E (ThrowsLibExnCalls.res:43:6) and is not annotated with @throws(ThrowsLibExn.E)

    …

Diagnostic added (warning 113):
Example:
    @throws(Missing)
    let f = () => 1
After (diagnostic): tests/error_tests/single/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.

Review: Why identities in the type checker, not in reanalyze? Only the type checker knows which exception a name means. Two attempts to rebuild the scope in reanalyze kept missing opens in interfaces, includes, functors and aliases.

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 4bcdd86 to aa74ffb Compare November 30, 2026 09:43
cknitt added a commit that referenced this pull request Nov 30, 2026
Why:
    Review on #9198: exception analysis compares exceptions by name, and a
    library's `@throws(E)` reached callers as the bare name `E`, while a
    catch was spelled `Lib.E`. So a correct catch was still reported, and a
    caller's own `E` could hide the library's. Reanalyze cannot resolve the
    names itself, because a .cmt keeps no environments.

The type checker now gives every exception an identity and resolves the
names in a `@throws` where they are written:
- When it types an exception, it records the identity, the unit and
  module path (`Lib.Inner.F`), in a generated `@res.exn` attribute on the
  definition. A rebound exception (`exception Mine = Lib.E`) carries the
  identity of the one it rebinds.
- For a `@throws` on an external, a `let` in a signature or interface, or
  any `let` binding, it looks each name up and adds a generated
  `@res.throws` listing each exception's name and identity. The inferred
  signature keeps it next to `@throws`.
- A name that is not an exception in scope gets the new warning 114 and is
  listed as written; lowercase names, which are never exceptions, do not
  warn. The first exception of that name counts, so a variant constructor
  declared later does not hide it. A payload may be one name, as a
  constructor or a string (also a template), or an array, tuple or
  `list{...}` of names, in braces or not.
- `Depend` counts the modules a `@throws` names as dependencies, since the
  type checker loads them.

Exception analysis compares those identities with the constructors that
catches and throws use. A call's exceptions are the declaration's
resolved `@throws`, or, when it has none, the implementation binding's:
the declaration is what callers see. Messages name an exception as the
code they are about would, relative to its enclosing module.

Known limits: an identity belongs to a declaration, and a signature's
`exception E` is a different declaration from the definition it hides.
So when only an implementation sealed by a module type annotates its
`@throws`, callers' catches of the module's `E` do not match it, and
modules sealed by one module type share its exceptions' identities. The
exceptions of two applications of one functor share an identity, and so
do same-named exceptions of a functor's parameter and body, or of a local
module and its enclosing module. A `@throws(X.E)` for an exception that a
functor parameter's module type declares keeps that declaration's
identity.

Reanalyze modified (exceptions of other modules):
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
      }
    exception E
    let catchUnrelatedLocal = s =>
      try ThrowsLibExn.parse(s) catch {
      | 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:29:5-20
    annotatedViaOpen might throw ThrowsErrors.NotFound (ThrowsRepoCalls.res:29:28) and is annotated with redundant @throws(NotFound)

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

    …
After (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception
    Exception Analysis
    ThrowsLibExnCalls.res:42:5-23
    catchUnrelatedLocal might throw ThrowsLibExn.E (ThrowsLibExnCalls.res:43:6) and is not annotated with @throws(ThrowsLibExn.E)

    …

Diagnostic added (warning 114):
Example:
    @throws(Missing)
    let f = () => 1
After (diagnostic): tests/error_tests/single/fixtures/throws_unbound_warning.res
    Warning number 114
    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.

Review: Why identities in the type checker, not in reanalyze? Only the type checker knows which exception a name means. Two attempts to rebuild the scope in reanalyze kept missing opens in interfaces, includes, functors and aliases.

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 30, 2026
Why:
    Review on #9198: exception analysis compares exceptions by name, and a
    library's `@throws(E)` reached callers as the bare name `E`, while a
    catch was spelled `Lib.E`. So a correct catch was still reported, and a
    caller's own `E` could hide the library's. Reanalyze cannot resolve the
    names itself, because a .cmt keeps no environments.

The type checker now gives every exception an identity and resolves the
names in a `@throws` where they are written:
- When it types an exception, it records the identity, the unit and
  module path (`Lib.Inner.F`), in a generated `@res.exn` attribute on the
  definition. A rebound exception (`exception Mine = Lib.E`) carries the
  identity of the one it rebinds.
- For a `@throws` on an external, a `let` in a signature or interface, or
  any `let` binding, it looks each name up and adds a generated
  `@res.throws` listing each exception's name and identity. The inferred
  signature keeps it next to `@throws`.
- A name that is not an exception in scope gets the new warning 114 and is
  listed as written; lowercase names, which are never exceptions, do not
  warn. The first exception of that name counts, so a variant constructor
  declared later does not hide it. A payload may be one name, as a
  constructor or a string (also a template), or an array, tuple or
  `list{...}` of names, in braces or not.
- `Depend` counts the modules a `@throws` names as dependencies, since the
  type checker loads them.

Exception analysis compares those identities with the constructors that
catches and throws use. A call's exceptions are the declaration's
resolved `@throws`, or, when it has none, the implementation binding's:
the declaration is what callers see. Messages name an exception as the
code they are about would, relative to its enclosing module.

Known limits: an identity belongs to a declaration, and a signature's
`exception E` is a different declaration from the definition it hides.
So when only an implementation sealed by a module type annotates its
`@throws`, callers' catches of the module's `E` do not match it, and
modules sealed by one module type share its exceptions' identities. The
exceptions of two applications of one functor share an identity, and so
do same-named exceptions of a functor's parameter and body, or of a local
module and its enclosing module, or of a module type and a module of the
same name. A `@throws(X.E)` for an exception that a functor parameter's
module type declares keeps that declaration's identity, and messages name
a functor body's exceptions by the functor, not by its application. An
interface whose `@throws` lists fewer exceptions than its implementation's
hides the rest from callers.

Reanalyze modified (exceptions of other modules):
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
      }
    exception E
    let catchUnrelatedLocal = s =>
      try ThrowsLibExn.parse(s) catch {
      | 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:29:5-20
    annotatedViaOpen might throw ThrowsErrors.NotFound (ThrowsRepoCalls.res:29:28) and is annotated with redundant @throws(NotFound)

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

    …
After (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception
    Exception Analysis
    ThrowsLibExnCalls.res:42:5-23
    catchUnrelatedLocal might throw ThrowsLibExn.E (ThrowsLibExnCalls.res:43:6) and is not annotated with @throws(ThrowsLibExn.E)

    …

Diagnostic added (warning 114):
Example:
    @throws(Missing)
    let f = () => 1
After (diagnostic): tests/error_tests/single/fixtures/throws_unbound_warning.res
    Warning number 114
    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.

Review: Why identities in the type checker, not in reanalyze? Only the type checker knows which exception a name means. Two attempts to rebuild the scope in reanalyze kept missing opens in interfaces, includes, functors and aliases.

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 30, 2026
Why:
    Review on #9198: exception analysis compares exceptions by name, and a
    library's `@throws(E)` reached callers as the bare name `E`, while a
    catch was spelled `Lib.E`. So a correct catch was still reported, and a
    caller's own `E` could hide the library's. Reanalyze cannot resolve the
    names itself, because a .cmt keeps no environments.

The type checker now gives every exception an identity and resolves the
names in a `@throws` where they are written:
- When it types an exception, it records the identity, the unit and
  module path (`Lib.Inner.F`), in a generated `@res.exn` attribute on the
  definition. A rebound exception (`exception Mine = Lib.E`) carries the
  identity of the one it rebinds.
- For a `@throws` on an external, a `let` in a signature or interface, or
  any `let` binding, it looks each name up and adds a generated
  `@res.throws` listing each exception's name and identity. The inferred
  signature keeps it next to `@throws`.
- A name that is not an exception in scope gets the new warning 114 and is
  listed as written; lowercase names, which are never exceptions, do not
  warn. The first exception of that name counts, so a variant constructor
  declared later does not hide it. A payload may be one name, as a
  constructor or a string (also a template), or an array, tuple or
  `list{...}` of names, in braces or not.
- `Depend` counts the modules a `@throws` names as dependencies, since the
  type checker loads them.

Exception analysis compares those identities with the constructors that
catches and throws use. A call's exceptions are the declaration's
resolved `@throws`, or, when it has none, the implementation binding's:
the declaration is what callers see. Messages name an exception as the
code they are about would, relative to its enclosing module.

Known limits: an identity belongs to a declaration, and a signature's
`exception E` is a different declaration from the definition it hides.
So when only an implementation sealed by a module type annotates its
`@throws`, callers' catches of the module's `E` do not match it, and
modules sealed by one module type share its exceptions' identities. The
exceptions of two applications of one functor share an identity, and so
do same-named exceptions of a functor's parameter and body, or of a local
module and its enclosing module, or of a module type and a module of the
same name. A `@throws(X.E)` for an exception that a functor parameter's
module type declares keeps that declaration's identity, and messages name
a functor body's exceptions by the functor, not by its application. An
interface whose `@throws` lists fewer exceptions than its implementation's
hides the rest from callers.

Reanalyze modified (exceptions of other modules):
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
      }
    exception E
    let catchUnrelatedLocal = s =>
      try ThrowsLibExn.parse(s) catch {
      | 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:29:5-20
    annotatedViaOpen might throw ThrowsErrors.NotFound (ThrowsRepoCalls.res:29:28) and is annotated with redundant @throws(NotFound)

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

    …
After (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception
    Exception Analysis
    ThrowsLibExnCalls.res:42:5-23
    catchUnrelatedLocal might throw ThrowsLibExn.E (ThrowsLibExnCalls.res:43:6) and is not annotated with @throws(ThrowsLibExn.E)

    …

Diagnostic added (warning 114):
Example:
    @throws(Missing)
    let f = () => 1
After (diagnostic): tests/error_tests/single/fixtures/throws_unbound_warning.res
    Warning number 114
    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.

Review: Why identities in the type checker, not in reanalyze? Only the type checker knows which exception a name means. Two attempts to rebuild the scope in reanalyze kept missing opens in interfaces, includes, functors and aliases.

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>
Why:
    Exception analysis knew which library functions throw only from a
    hand-written table in exn_lib.ml, and the table fell behind. The
    Temporal `fromStringOrThrow` functions were never added (#9182), and
    neither were some Intl and Belt functions. Third-party libraries and a
    project's own externals had no way to declare their exceptions.

The table is gone. At each call, the analysis now reads the `@throws` on
the declaration of the called function. The `.cmi` keeps the attributes
of externals and of `let`s in interfaces, so their `@throws` reaches
calls in other modules and packages.

A `let` in a module without an interface used to lose its attributes in
the inferred signature. The type checker now copies its `@throws` there,
as it already did for `@deprecated`.

The stdlib and Belt annotate their throwing functions themselves. A
guard in the reanalyze tests fails when a stdlib or Belt function named
`*OrThrow` or `*Exn` 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`)   when the declaration has a `@throws`
    throws(`f`) = values(`f`)   otherwise

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 does the declaration win over the implementation? The values table holds the `@throws` on the implementation's `let`. When the interface has a `@throws`, that is what callers see, so it counts alone. When it has none, the implementation's counts, so an annotated `.res` behind an unannotated `.resi` still works.

Review: Why does the inferred signature copy only `@throws` and `@deprecated`? A doc comment is an attribute too, and keeping it in the `.cmi` would make every edit of the comment recompile the module's dependents. A module with a `.resi` is unaffected, because its `.cmi` comes from the interface.

Fixes #9182

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the drift-9182-temporal-exn branch from aa74ffb to d5177af Compare November 30, 2026 19:53
cknitt added a commit that referenced this pull request Nov 30, 2026
Why:
    Exception analysis compares exceptions by name. A library's
    `@throws(E)` reached callers as `E`, while their catch said `Lib.E`, so
    a correct catch was reported and a caller's own `E` could hide the
    library's exception. Which exception a name refers to depends on the
    opens, aliases and includes in scope, and only the type checker knows
    that. Reanalyze can't work it out, because a .cmt keeps no type
    environments. (Review comment on #9198.)

The type checker now resolves the names, and stores the results in typed
fields that reach the .cmi:

- When it defines an exception, it records the module path where the
  exception is defined, for example `Lib.Inner.F`, as the exception's
  identity (`ext_identity`, copied to `cstr_identity`). A rebinding such as
  `exception Mine = Lib.E` gets the identity of `Lib.E`.
- For a `@throws` on an external, a `let` in an interface or module type,
  or any `let`, it looks up each name and stores the exceptions it found
  with their identities (`val_throws`, `vb_throws`, and a third component
  of `Tstr_eval`). The inferred signature keeps them.
- A name that isn't an exception in scope gets the new warning 114. The
  first exception of a name counts, so a variant constructor declared
  later doesn't hide it. Lowercase names never warn.
- The modules a `@throws` names become dependencies, because the type
  checker loads them.

Reanalyze compares these identities with the identity of the constructor
at each catch and throw. Its messages name an exception the way the
surrounding code would, relative to the enclosing module.

Known limits: an identity belongs to a declaration, and a signature's
`exception E` is a separate declaration from the definition it hides. So
when only the implementation of a sealed module annotates `@throws`, a
caller's catch of the module's `E` doesn't match it, and modules sealed by
one module type share its exceptions' identities. In a functor,
`@throws(X.E)` keeps the identity from the parameter's module type.
Exceptions with the same name and module path also share an identity: two
applications of one functor, a functor's parameter and body, a local
module and the module around it, a module type and a module with the same
name.

Reanalyze modified (exceptions of other modules):
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
      }
    exception E
    let catchUnrelatedLocal = s =>
      try ThrowsLibExn.parse(s) catch {
      | 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)

    …
After (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception
    Exception Analysis
    ThrowsLibExnCalls.res:42:5-23
    catchUnrelatedLocal might throw ThrowsLibExn.E (ThrowsLibExnCalls.res:43:6) and is not annotated with @throws(ThrowsLibExn.E)

    …

Diagnostic added (warning 114):
Example:
    @throws(Missing)
    let f = () => 1
After (diagnostic): tests/error_tests/single/fixtures/throws_unbound_warning.res
    Warning number 114
    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.

Review: Why typed fields rather than attributes? The resolved exceptions are data the type checker computes, not something a user writes. Fields keep them out of reach of user attributes and need no encoding as strings. The .cmi format changes, and the magic numbers are bumped at release.

Review: Why not store the exceptions' paths, which the type checker would rewrite when a module is sealed or a functor applied? A catch's path is the path it was reached through, so `Lib.E`, `L.E` with `module L = Lib`, and `Ns.Lib.E` differ, and telling them apart needs the type environment. Making paths work needs changes to strengthening and substitution. Fields with paths could replace these string identities later.

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>
Signed-off-by: Christoph Knittel <ck@cca.io>

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