Skip to content

Match @throws exceptions with catches across modules - #9476

Draft
cknitt wants to merge 1 commit into
drift-9182-temporal-exnfrom
throws-exception-identity
Draft

cknitt wants to merge 1 commit into
drift-9182-temporal-exnfrom
throws-exception-identity

Conversation

@cknitt

@cknitt cknitt commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Stacked on #9198, and the follow-up for cristianoc's review there.

Exception analysis compares exceptions by name. 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 these names itself, because a .cmt keeps no environments, so this moves the resolution into the type checker. The stdlib and Belt annotations in #9198 only name predefined exceptions, which need none of this.

How

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

The identity is the compilation unit and module path that define the exception, as Lib.Inner.F. The type checker records it when it types the exception, in a generated @res.exn attribute on the definition, which the .cmi and .cmt keep whatever the flags (also under -no-keep-locs, as the runtime and Belt are built). It is the same through every alias, open, include and functor, and for a module's .res and .resi. A rebound exception (exception Mine = Lib.E) carries the identity of the one it rebinds.

Exception analysis compares these 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 (Inner.F, or F inside Inner), so the annotation a message suggests resolves. An exception of a namespaced dependency is shown without the namespace. For that, Typemod records which module of the current file defines each exception and module.

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

A name that is not an exception in scope gets the new warning 113 (on by default, not an error, once per name) and is listed as written. Lowercase names never are exceptions and do not warn. The first exception of a name counts, so a variant constructor declared later does not hide it, and constructors of other extensible variants are not exceptions. The @throws payload may be one name, or an array, tuple or list{...} of names.

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, a caller's catch of the module's E does not match it (catchSealedPlain), 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 or function and its enclosing module. A @throws(X.E) for an exception that a functor parameter's module type declares keeps that declaration's identity, so a catch of the argument's exception does not match it; on #9198's base the two names did not match either. Following functor substitution would need identities that take part in it, which attributes cannot.

Tests

  • ThrowsLibExn.res/ThrowsLibExnCalls.res, ThrowsErrors.res/ThrowsRepo.res/ThrowsRepoCalls.res and ThrowsReexport.res cover exception names: a library's own exception caught by its qualified name, through open, an alias, a rebind (catchRebound) and an include; a caller's own E not catching the library's E; a @throws naming a third module's exception; and a binding's own @throws written after open or through an alias. UseS calls through a functor parameter.
  • ThrowsScopes.res (with ThrowsIfaceOpen.res/.resi and ThrowsAlias.res) covers an interface whose @throws comes after an open, an alias of an alias in another file, an include of an include, a functor body's own exception, a list{...} payload, Lazy.Undefined from the runtime (no locations), a recursive module's own exception, which a catch of the file's E does not catch, a module sealed by an annotated module type (catchSealed), the signature limit (catchSealedPlain), an exception shadowed by a later variant constructor, and the name a message suggests inside a nested module. uncaughtNested and uncaughtLocal in ThrowsLibExnCalls.res pin the full names in messages, and annotatedLocal follows the suggestion.
  • tests/error_tests/single/fixtures/throws_unbound_warning.res shows warning 113 for an unknown name, a variant constructor and an extensible variant's constructor, once for a destructuring let, and none for a lowercase name, a payload-less @throws or under @warning("-113").
  • tests/build_tests/projects/throws_dependency builds a module that names another only in @throws; before the Depend change the build order left the name unresolved.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gHA54VKxsXvCQyC2vw

@cknitt
cknitt added this pull request to stack #9477 November 29, 2026 07:38
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Changelog

💥 Breaking Change

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

🚀 New Feature

  • The compiler resolves the exceptions a @throws names where it is written, so exception analysis matches them with catches through opens, aliases, includes and functors, and warns (warning 114) about a name that is not an exception in scope.

Semantic Diff

1 commit · Full page

✏️ Resolve the exceptions @throws names in the type checker

1f2a539 · cknitt + Claude · Nov 29, 2026, 07:33 UTC · edited

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)

// 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
  }

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)
 
+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)

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

diagnostic · After · 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.

⚠️ 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.

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.

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

⚠️ Compiler benchmarks

Allocated words

In total: 675,013,527 → 675,958,181 (+0.14%).

Generated projects: 630,569,763 → 631,247,572 (+0.11%).

⚠️ Regression: 3 benchmarks allocate more than 1% more.

Benchmark Base Head Change
packages/@rescript/runtime/Stdlib_JsError.resi 189,361 193,520 +2.20%
packages/@rescript/runtime/Stdlib_Intl.res 176,452 178,486 +1.15%
packages/@rescript/belt/src/Belt_MutableQueue.resi 208,599 210,808 +1.06%
build/Namespace/edit 7,943,244 8,005,085 +0.78%
packages/@rescript/runtime/Stdlib_Bool.resi 117,260 118,122 +0.74%
packages/@rescript/runtime/Stdlib_JsError.res 231,417 233,081 +0.72%
packages/@rescript/runtime/Stdlib_BigInt.resi 186,702 187,985 +0.69%
packages/@rescript/runtime/Stdlib_JSON.resi 237,272 238,782 +0.64%
packages/@rescript/belt/src/Belt_MutableStack.resi 169,810 170,853 +0.61%
packages/@rescript/runtime/Stdlib_Temporal.res 225,015 226,376 +0.60%
233 more changes
Benchmark Base Head Change
packages/@rescript/belt/src/Belt_Option.resi 242,978 244,436 +0.60%
packages/@rescript/runtime/Pervasives.res 241,413 242,849 +0.59%
packages/@rescript/belt/src/Belt_Result.resi 240,919 242,346 +0.59%
packages/@rescript/belt/src/Belt_SetString.resi 260,008 261,541 +0.59%
packages/@rescript/belt/src/Belt_SetInt.resi 260,133 261,666 +0.59%
packages/@rescript/belt/src/Belt_MutableSetInt.resi 265,446 266,993 +0.58%
packages/@rescript/belt/src/Belt_MutableSetString.resi 265,328 266,874 +0.58%
packages/@rescript/belt/src/Belt.res 188,988 190,062 +0.57%
packages/@rescript/runtime/Primitive_exceptions.resi 100,633 101,201 +0.56%
packages/@rescript/runtime/Stdlib_Lazy.resi 112,466 113,081 +0.55%
packages/@rescript/runtime/RescriptTools_ExtractCodeBlocks.res 112,607 113,197 +0.52%
packages/@rescript/runtime/Stdlib.res 985,560 990,684 +0.52%
parse/Napkinscript.res 10,732,690 10,787,964 +0.52%
packages/@rescript/runtime/Stdlib_JSON.res 298,832 300,367 +0.51%
packages/@rescript/belt/src/Belt_MutableMapString.resi 315,021 316,569 +0.49%
packages/@rescript/belt/src/Belt_MutableMapInt.resi 315,141 316,689 +0.49%
packages/@rescript/runtime/Stdlib_Null.resi 204,267 205,266 +0.49%
packages/@rescript/belt/src/Belt_MutableMap.resi 395,729 397,662 +0.49%
packages/@rescript/belt/src/Belt_MutableSet.resi 396,544 398,477 +0.49%
packages/@rescript/belt/src/Belt_Set.resi 436,401 438,526 +0.49%
packages/@rescript/runtime/Primitive_list.resi 92,205 92,638 +0.47%
packages/@rescript/runtime/RescriptTools.res 104,965 105,454 +0.47%
packages/@rescript/runtime/Primitive_float_extern.res 94,065 94,498 +0.46%
packages/@rescript/runtime/Stdlib_Nullable.resi 199,514 200,426 +0.46%
packages/@rescript/runtime/Stdlib_Blob.res 94,282 94,710 +0.45%
packages/@rescript/runtime/Primitive_promise.res 97,441 97,879 +0.45%
packages/@rescript/runtime/Stdlib_List.resi 408,233 410,058 +0.45%
packages/@rescript/runtime/Primitive_int_extern.res 98,294 98,732 +0.45%
packages/@rescript/runtime/Stdlib_File.res 96,091 96,519 +0.45%
packages/@rescript/runtime/Primitive_string_extern.res 98,602 99,040 +0.44%
packages/@rescript/runtime/Stdlib_Iterable.resi 98,411 98,844 +0.44%
packages/@rescript/runtime/Stdlib_AsyncIterable.resi 98,560 98,993 +0.44%
packages/@rescript/belt/src/Belt_List.resi 754,021 757,332 +0.44%
packages/@rescript/runtime/Stdlib_Iterable.res 99,322 99,755 +0.44%
packages/@rescript/runtime/Stdlib_AsyncIterable.res 99,393 99,826 +0.44%
packages/@rescript/runtime/Obj.res 99,542 99,975 +0.43%
packages/@rescript/runtime/Primitive_hash.resi 103,050 103,498 +0.43%
packages/@rescript/runtime/Primitive_module.resi 103,492 103,935 +0.43%
packages/@rescript/runtime/Primitive_dict.res 103,094 103,532 +0.42%
packages/@rescript/belt/src/Belt_Int.resi 149,615 150,249 +0.42%
packages/@rescript/belt/src/Belt_Float.resi 151,095 151,729 +0.42%
packages/@rescript/runtime/Stdlib_Bool.res 146,817 147,430 +0.42%
packages/@rescript/runtime/Stdlib_ArrayBuffer.res 107,918 108,366 +0.42%
packages/@rescript/belt/src/Belt_MapString.resi 390,821 392,413 +0.41%
packages/@rescript/runtime/Primitive_object.resi 117,407 117,885 +0.41%
packages/@rescript/runtime/Stdlib_TaggedTemplate.resi 106,376 106,809 +0.41%
packages/@rescript/belt/src/Belt_MapInt.resi 390,865 392,456 +0.41%
packages/@rescript/runtime/Stdlib_ArrayBuffer.resi 111,174 111,622 +0.40%
packages/@rescript/runtime/Primitive_object_extern.res 115,113 115,576 +0.40%
build/Namespace/clean 84,801,406 85,141,838 +0.40%
packages/@rescript/belt/src/Belt_Float.res 165,518 166,182 +0.40%
packages/@rescript/runtime/Stdlib_TaggedTemplate.res 115,856 116,319 +0.40%
packages/@rescript/belt/src/Belt_Int.res 166,257 166,921 +0.40%
packages/@rescript/belt/src/Belt_internalBucketsType.res 292,366 293,525 +0.40%
packages/@rescript/runtime/Stdlib_Ordering.res 155,401 156,016 +0.40%
packages/@rescript/runtime/Primitive_array_extern.res 114,602 115,055 +0.40%
packages/@rescript/belt/src/Belt_Array.resi 647,596 650,143 +0.39%
packages/@rescript/runtime/Stdlib_Global.res 142,210 142,764 +0.39%
packages/@rescript/runtime/Dom_storage2.res 120,567 121,035 +0.39%
packages/@rescript/belt/src/Belt_HashSetString.resi 175,766 176,445 +0.39%
packages/@rescript/belt/src/Belt_HashSetInt.resi 175,879 176,558 +0.39%
packages/@rescript/belt/src/Belt_SetDict.resi 401,576 403,115 +0.38%
packages/@rescript/runtime/Stdlib_JsExn.res 173,717 174,382 +0.38%
packages/@rescript/runtime/Stdlib_Option.resi 235,962 236,865 +0.38%
packages/@rescript/runtime/Stdlib_JsExn.resi 122,583 123,051 +0.38%
packages/@rescript/runtime/Stdlib_Lazy.res 221,752 222,596 +0.38%
packages/@rescript/belt/src/Belt_Map.resi 577,661 579,859 +0.38%
packages/@rescript/runtime/Jsx.res 122,122 122,585 +0.38%
packages/@rescript/runtime/Stdlib_Intl_Segments.res 116,981 117,424 +0.38%
packages/@rescript/belt/src/Belt_internalBucketsType.resi 165,113 165,737 +0.38%
packages/@rescript/runtime/Primitive_exceptions.res 201,670 202,425 +0.37%
packages/@rescript/belt/src/Belt_SortArrayString.resi 169,562 170,196 +0.37%
packages/@rescript/runtime/Primitive_option.resi 122,497 122,955 +0.37%
packages/@rescript/belt/src/Belt_SortArrayInt.resi 169,680 170,314 +0.37%
packages/@rescript/runtime/Stdlib_BigInt.res 207,815 208,578 +0.37%
packages/@rescript/runtime/Stdlib_WeakSet.res 123,554 124,007 +0.37%
packages/@rescript/belt/src/Belt_Range.resi 176,370 177,014 +0.37%
packages/@rescript/runtime/Stdlib_Temporal_PlainMonthDay.res 269,078 270,036 +0.36%
packages/@rescript/runtime/Stdlib_Symbol.res 146,907 147,430 +0.36%
packages/@rescript/runtime/Stdlib_Global.resi 155,520 156,068 +0.35%
packages/@rescript/runtime/Stdlib_Type.resi 136,038 136,511 +0.35%
packages/@rescript/runtime/Stdlib_RegExp.res 164,147 164,713 +0.34%
packages/@rescript/runtime/Dom_storage.res 168,476 169,056 +0.34%
packages/@rescript/runtime/Stdlib_Int.res 456,147 457,706 +0.34%
packages/@rescript/runtime/Primitive_float.res 147,310 147,813 +0.34%
packages/@rescript/runtime/Primitive_bool.res 147,568 148,071 +0.34%
packages/@rescript/runtime/Stdlib_WeakMap.res 135,886 136,344 +0.34%
packages/@rescript/belt/src/Belt_internalSetBuckets.resi 194,635 195,289 +0.34%
packages/@rescript/belt/src/Belt_Id.res 290,757 291,719 +0.33%
packages/@rescript/runtime/Primitive_string.res 159,981 160,509 +0.33%
packages/@rescript/belt/src/Belt_HashMapString.resi 213,775 214,479 +0.33%
packages/@rescript/belt/src/Belt_HashMapInt.resi 213,889 214,593 +0.33%
packages/@rescript/belt/src/Belt_internalAVLset.resi 355,570 356,737 +0.33%
packages/@rescript/belt/src/Belt_HashSet.resi 222,859 223,588 +0.33%
packages/@rescript/runtime/Stdlib_Symbol.resi 160,041 160,564 +0.33%
packages/@rescript/belt/src/Belt_Option.res 390,051 391,314 +0.32%
packages/@rescript/runtime/Primitive_int.res 172,284 172,837 +0.32%
packages/@rescript/runtime/Stdlib_Temporal_Instant.res 308,693 309,682 +0.32%
packages/@rescript/runtime/Stdlib_Temporal_Now.res 143,878 144,336 +0.32%
packages/@rescript/runtime/Primitive_bigint.res 177,758 178,321 +0.32%
packages/@rescript/runtime/Primitive_array.res 192,352 192,960 +0.32%
packages/@rescript/runtime/Stdlib_Temporal_PlainTime.res 321,095 322,104 +0.31%
packages/@rescript/belt/src/Belt_Id.resi 260,503 261,313 +0.31%
packages/@rescript/belt/src/Belt_Set.res 858,303 860,971 +0.31%
packages/@rescript/belt/src/Belt_MapDict.resi 512,873 514,464 +0.31%
packages/@rescript/runtime/Stdlib_IterableIterator.resi 149,259 149,722 +0.31%
packages/@rescript/belt/src/Belt_Range.res 289,382 290,276 +0.31%
packages/@rescript/runtime/Stdlib_Float.resi 193,705 194,303 +0.31%
packages/@rescript/runtime/Stdlib_Float.res 219,408 220,084 +0.31%
packages/@rescript/runtime/Stdlib_Result.resi 295,962 296,873 +0.31%
packages/@rescript/runtime/Stdlib_Pair.res 166,661 167,166 +0.30%
packages/@rescript/belt/src/Belt_Map.res 981,599 984,566 +0.30%
packages/@rescript/runtime/Stdlib_Iterator.resi 158,858 159,336 +0.30%
packages/@rescript/runtime/Primitive_list.res 204,280 204,893 +0.30%
packages/@rescript/runtime/Stdlib_RegExp.resi 187,739 188,302 +0.30%
packages/@rescript/runtime/Stdlib_IterableIterator.res 179,765 180,304 +0.30%
packages/@rescript/belt/src/Belt_internalBuckets.resi 223,415 224,084 +0.30%
packages/@rescript/runtime/Stdlib_Intl_NumberFormat_Grouping.res 159,817 160,288 +0.29%
packages/@rescript/runtime/Stdlib_Intl_Segmenter.res 154,922 155,375 +0.29%
packages/@rescript/runtime/Stdlib_AsyncIterableIterator.resi 159,727 160,190 +0.29%
packages/@rescript/runtime/Stdlib_Generator.resi 160,349 160,812 +0.29%
packages/@rescript/runtime/Stdlib_Null.res 335,672 336,639 +0.29%
packages/@rescript/runtime/Stdlib_Type.res 201,952 202,532 +0.29%
packages/@rescript/belt/src/Belt_SortArray.resi 253,367 254,091 +0.29%
packages/@rescript/runtime/Stdlib_Math.res 328,198 329,134 +0.29%
packages/@rescript/runtime/Stdlib_Iterator.res 235,406 236,074 +0.28%
packages/@rescript/runtime/Stdlib_Temporal_Duration.res 374,452 375,505 +0.28%
packages/@rescript/runtime/Stdlib_Int.resi 205,687 206,265 +0.28%
packages/@rescript/runtime/Stdlib_Generator.res 201,610 202,175 +0.28%
packages/@rescript/runtime/Stdlib_AsyncGenerator.resi 165,727 166,190 +0.28%
packages/@rescript/belt/src/Belt_internalSetInt.res 733,105 735,148 +0.28%
packages/@rescript/belt/src/Belt_internalSetString.res 734,294 736,336 +0.28%
packages/@rescript/runtime/Stdlib_Intl_Common.res 154,737 155,165 +0.28%
packages/@rescript/belt/src/Belt_Result.res 410,634 411,767 +0.28%
packages/@rescript/belt/src/Belt_MutableQueue.res 792,799 794,972 +0.27%
packages/@rescript/runtime/Stdlib_AsyncIterator.resi 177,360 177,843 +0.27%
packages/@rescript/belt/src/Belt_MutableStack.res 388,305 389,360 +0.27%
parse/RedBlackTreeNoComments.res 356,071 357,037 +0.27%
packages/@rescript/runtime/Stdlib_Intl_ListFormat.res 170,208 170,666 +0.27%
packages/@rescript/runtime/Stdlib_Temporal_PlainYearMonth.res 383,128 384,158 +0.27%
packages/@rescript/runtime/Stdlib_Temporal_PlainDate.res 404,759 405,838 +0.27%
packages/@rescript/belt/src/Belt_internalAVLtree.resi 453,153 454,361 +0.27%
parse/RedBlackTree.res 363,784 364,750 +0.27%
packages/@rescript/runtime/Stdlib_Nullable.res 333,128 334,008 +0.26%
packages/@rescript/runtime/Stdlib_AsyncGenerator.res 211,896 212,455 +0.26%
packages/@rescript/runtime/Stdlib_Set.res 211,654 212,210 +0.26%
packages/@rescript/runtime/Stdlib_Math.resi 327,429 328,287 +0.26%
packages/@rescript/belt/src/Belt_MapString.res 1,186,612 1,189,709 +0.26%
packages/@rescript/runtime/Stdlib_Map.res 206,310 206,846 +0.26%
packages/@rescript/belt/src/Belt_HashMap.resi 295,649 296,403 +0.26%
packages/@rescript/belt/src/Belt_HashSetInt.res 852,284 854,456 +0.25%
packages/@rescript/runtime/Stdlib_AsyncIterableIterator.res 229,228 229,812 +0.25%
packages/@rescript/runtime/Stdlib_Temporal_PlainDateTime.res 439,056 440,172 +0.25%
packages/@rescript/belt/src/Belt_MapInt.res 1,186,076 1,189,088 +0.25%
packages/@rescript/belt/src/Belt_Array.res 2,156,112 2,161,579 +0.25%
packages/@rescript/runtime/Stdlib_Intl_RelativeTimeFormat.res 180,847 181,305 +0.25%
packages/@rescript/runtime/Primitive_option.res 298,254 299,009 +0.25%
packages/@rescript/belt/src/Belt_HashSetString.res 852,606 854,764 +0.25%
packages/@rescript/runtime/Stdlib_Intl_Collator.res 179,045 179,498 +0.25%
packages/@rescript/runtime/Stdlib_Intl_Locale.res 198,459 198,957 +0.25%
packages/@rescript/belt/src/Belt_MutableMap.res 1,302,814 1,306,070 +0.25%
packages/@rescript/belt/src/Belt_internalSetBuckets.res 702,518 704,252 +0.25%
packages/@rescript/runtime/Stdlib_DataView.res 230,710 231,273 +0.24%
packages/@rescript/runtime/Stdlib_AsyncIterator.res 295,219 295,937 +0.24%
packages/@rescript/belt/src/Belt_MutableMapInt.res 1,154,757 1,157,549 +0.24%
packages/@rescript/belt/src/Belt_MutableMapString.res 1,155,036 1,157,823 +0.24%
packages/@rescript/runtime/Primitive_module.res 337,298 338,110 +0.24%
packages/@rescript/belt/src/Belt_SetInt.res 1,293,650 1,296,757 +0.24%
packages/@rescript/belt/src/Belt_SetString.res 1,294,380 1,297,485 +0.24%
packages/@rescript/belt/src/Belt_HashSet.res 979,955 982,280 +0.24%
packages/@rescript/runtime/Stdlib_Map.resi 216,934 217,447 +0.24%
packages/@rescript/runtime/Stdlib_Option.res 758,051 759,831 +0.23%
packages/@rescript/runtime/Stdlib_Set.resi 228,713 229,246 +0.23%
packages/@rescript/runtime/Stdlib_Intl_PluralRules.res 202,274 202,742 +0.23%
packages/@rescript/runtime/Stdlib_Dict.resi 240,308 240,851 +0.23%
packages/@rescript/runtime/Stdlib_Dict.res 321,331 322,052 +0.22%
packages/@rescript/belt/src/Belt_HashMapString.res 1,063,416 1,065,783 +0.22%
packages/@rescript/belt/src/Belt_HashMapInt.res 1,062,708 1,065,073 +0.22%
packages/@rescript/belt/src/Belt_MapDict.res 1,635,695 1,639,334 +0.22%
packages/@rescript/runtime/Stdlib_IteratorObject.res 251,562 252,121 +0.22%
packages/@rescript/belt/src/Belt_MutableSetString.res 1,664,665 1,668,353 +0.22%
packages/@rescript/belt/src/Belt_MutableSetInt.res 1,663,426 1,667,104 +0.22%
packages/@rescript/belt/src/Belt_MutableSet.res 1,901,579 1,905,782 +0.22%
packages/@rescript/runtime/Stdlib_IteratorObject.resi 234,090 234,603 +0.22%
packages/@rescript/runtime/Stdlib_Object.res 247,785 248,328 +0.22%
packages/@rescript/runtime/RescriptTools_Docgen.resi 273,931 274,521 +0.22%
packages/@rescript/belt/src/Belt_HashMap.res 1,201,995 1,204,579 +0.21%
packages/@rescript/runtime/Stdlib_Console.res 370,659 371,454 +0.21%
packages/@rescript/belt/src/Belt_SetDict.res 1,449,947 1,453,038 +0.21%
packages/@rescript/runtime/Stdlib_DataView.resi 267,792 268,355 +0.21%
packages/@rescript/belt/src/Belt_SortArray.res 1,449,127 1,452,173 +0.21%
packages/@rescript/runtime/RescriptTools_Docgen.res 284,164 284,754 +0.21%
packages/@rescript/runtime/Primitive_js_extern.res 240,258 240,754 +0.21%
packages/@rescript/belt/src/Belt_internalBuckets.res 970,496 972,474 +0.20%
packages/@rescript/runtime/Stdlib_Temporal_ZonedDateTime.res 575,007 576,172 +0.20%
packages/@rescript/belt/src/Belt_SortArrayInt.res 1,343,768 1,346,401 +0.20%
packages/@rescript/belt/src/Belt_SortArrayString.res 1,345,558 1,348,189 +0.20%
packages/@rescript/runtime/Stdlib_Array.res 1,284,910 1,287,415 +0.19%
packages/@rescript/runtime/Stdlib_Console.resi 410,935 411,730 +0.19%
packages/@rescript/belt/src/Belt_internalMapInt.res 1,411,010 1,413,586 +0.18%
packages/@rescript/belt/src/Belt_internalMapString.res 1,412,854 1,415,430 +0.18%
packages/@rescript/belt/src/Belt_List.res 3,183,325 3,189,087 +0.18%
packages/@rescript/runtime/Stdlib_String.res 506,108 507,021 +0.18%
build/clean 260,352,559 260,808,150 +0.17%
packages/@rescript/runtime/Stdlib_Promise.res 353,549 354,162 +0.17%
packages/@rescript/runtime/Stdlib_Date.res 553,001 553,948 +0.17%
packages/@rescript/belt/src/Belt_internalAVLset.res 2,882,484 2,886,891 +0.15%
packages/@rescript/runtime/Stdlib_Promise.resi 355,790 356,333 +0.15%
packages/@rescript/runtime/Primitive_hash.res 963,973 965,434 +0.15%
packages/@rescript/runtime/Primitive_object.res 1,157,729 1,159,476 +0.15%
packages/@rescript/runtime/Stdlib_List.res 2,693,321 2,697,364 +0.15%
packages/@rescript/runtime/Stdlib_String.resi 496,058 496,801 +0.15%
stress/InlineChain.res 3,560,183 3,565,462 +0.15%
packages/@rescript/belt/src/Belt_internalAVLtree.res 3,510,604 3,515,768 +0.15%
packages/@rescript/runtime/Stdlib_Date.resi 612,826 613,724 +0.15%
packages/@rescript/runtime/Stdlib_Result.res 1,274,379 1,276,227 +0.15%
packages/@rescript/runtime/Stdlib_Int8Array.res 343,927 344,418 +0.14%
packages/@rescript/runtime/Stdlib_Uint8Array.res 343,940 344,431 +0.14%
packages/@rescript/runtime/Stdlib_Float32Array.res 344,047 344,538 +0.14%
packages/@rescript/runtime/Stdlib_Float64Array.res 344,047 344,538 +0.14%
packages/@rescript/runtime/Stdlib_Int16Array.res 344,072 344,563 +0.14%
packages/@rescript/runtime/Stdlib_Int32Array.res 344,074 344,565 +0.14%
packages/@rescript/runtime/Stdlib_Uint16Array.res 344,079 344,570 +0.14%
packages/@rescript/runtime/Stdlib_Uint32Array.res 344,079 344,570 +0.14%
packages/@rescript/runtime/Stdlib_BigInt64Array.res 344,104 344,595 +0.14%
packages/@rescript/runtime/Stdlib_BigUint64Array.res 344,181 344,672 +0.14%
packages/@rescript/runtime/Stdlib_Uint8ClampedArray.res 344,455 344,946 +0.14%
packages/@rescript/runtime/Stdlib_Intl_NumberFormat.res 405,240 405,786 +0.13%
packages/@rescript/runtime/JsxEvent.res 1,092,905 1,094,296 +0.13%
packages/@rescript/runtime/Stdlib_TypedArray.res 786,108 787,074 +0.12%
packages/@rescript/runtime/Stdlib_Array.resi 725,678 726,561 +0.12%
packages/@rescript/runtime/Stdlib_Intl_DateTimeFormat.res 389,984 390,452 +0.12%
packages/@rescript/runtime/Stdlib_Temporal_Common.res 367,045 367,473 +0.12%

Instructions

In total: 9,226,034,780 → 9,231,937,445 (+0.06%).

⚠️ Regression: 1 benchmark executes more than 1% more instructions.

Benchmark Base Head Change
packages/@rescript/belt/src/Belt_Array.resi 33,759,285 34,446,077 +2.03%
packages/@rescript/belt/src/Belt_List.resi 39,035,433 39,264,941 +0.59%
packages/@rescript/runtime/Stdlib_List.resi 24,574,458 24,709,285 +0.55%
packages/@rescript/runtime/Stdlib_Math.resi 21,251,126 21,356,362 +0.50%
packages/@rescript/runtime/Stdlib_Temporal_PlainDate.res 24,137,114 24,250,081 +0.47%
packages/@rescript/runtime/Stdlib_Temporal_PlainDateTime.res 25,575,945 25,692,422 +0.46%
packages/@rescript/runtime/Stdlib_Temporal_ZonedDateTime.res 31,244,969 31,378,016 +0.43%
packages/@rescript/runtime/Stdlib_String.resi 29,396,480 29,498,075 +0.35%
parse/RedBlackTreeNoComments.res 14,510,197 14,554,712 +0.31%
parse/RedBlackTree.res 14,923,361 14,965,208 +0.28%
11 more changes
Benchmark Base Head Change
packages/@rescript/runtime/Stdlib_Date.resi 34,196,438 34,291,852 +0.28%
packages/@rescript/runtime/Stdlib_Array.resi 39,998,711 40,106,067 +0.27%
packages/@rescript/runtime/Stdlib_TypedArray.res 41,348,015 41,454,577 +0.26%
packages/@rescript/belt/src/Belt_List.res 118,265,045 118,484,971 +0.19%
format/RedBlackTreeNoComments.res 24,082,247 24,118,178 +0.15%
packages/@rescript/belt/src/Belt_internalAVLtree.res 136,487,723 136,690,528 +0.15%
format/RedBlackTree.res 24,427,255 24,463,186 +0.15%
parse/Napkinscript.res 333,479,478 333,961,741 +0.14%
packages/@rescript/runtime/JsxDOMStyle.res 95,125,389 95,255,452 +0.14%
stress/ObjectFields.res 946,099,251 947,285,132 +0.13%
stress/InlineChain.res 139,201,493 139,346,166 +0.10%

Output size

In total: 27,388,120 → 27,428,076 (+0.15%).

Benchmark Base Head Change
output/belt/*.cmi 463,514 467,931 +0.95%
output/belt/*.cmti 985,003 989,134 +0.42%
output/tests/*.cmi 2,445,923 2,452,838 +0.28%
output/playground/compiler.js 1,899,426 1,903,036 +0.19%
output/runtime/*.cmti 1,117,100 1,118,961 +0.17%
output/runtime/*.cmi 1,921,294 1,924,265 +0.15%

Pull request 1f2a539 compared with base e47e23b in this run.

@pkg-pr-new

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

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 1f2a539

@cknitt
cknitt force-pushed the throws-exception-identity branch from 6aa4b1c to 9bcf391 Compare November 29, 2026 08:11
@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.22917% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.51%. Comparing base (aa74ffb) to head (1f2a539).

Files with missing lines Patch % Lines
compiler/typing/throws_attribute.ml 87.87% 12 Missing ⚠️
analysis/reanalyze/src/exn.ml 91.66% 1 Missing ⚠️
Additional details and impacted files
@@                     Coverage Diff                     @@
##           drift-9182-temporal-exn    #9476      +/-   ##
===========================================================
+ Coverage                    82.47%   82.51%   +0.03%     
===========================================================
  Files                          465      466       +1     
  Lines                        66065    66214     +149     
===========================================================
+ Hits                         54488    54634     +146     
- Misses                       11577    11580       +3     
Files with missing lines Coverage Δ
analysis/reanalyze/src/exception.ml 85.33% <100.00%> (+3.82%) ⬆️
analysis/reanalyze/src/exceptions.ml 92.85% <ø> (ø)
compiler/typing/depend.ml 88.23% <100.00%> (+0.28%) ⬆️
compiler/typing/typecore.ml 89.17% <100.00%> (+<0.01%) ⬆️
compiler/typing/typedecl.ml 84.13% <100.00%> (+0.09%) ⬆️
compiler/typing/typemod.ml 78.28% <100.00%> (+0.38%) ⬆️
compiler/typing/warnings.ml 76.51% <100.00%> (+0.19%) ⬆️
analysis/reanalyze/src/exn.ml 91.66% <91.66%> (-8.34%) ⬇️
compiler/typing/throws_attribute.ml 87.87% <87.87%> (ø)

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cknitt

cknitt commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 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:58:07.797794Z 9bcf391 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 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: 9bcf39135f

ℹ️ 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
Comment thread compiler/typing/throws_attribute.ml Resolved
@cknitt
cknitt force-pushed the throws-exception-identity branch from 9bcf391 to 9242898 Compare November 29, 2026 09:02
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
cknitt force-pushed the throws-exception-identity branch from 9242898 to 1f2a539 Compare November 30, 2026 09:44

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant