Skip to content

Match @throws exceptions with catches across modules - #9476

Open
cknitt wants to merge 1 commit into
masterfrom
throws-exception-identity
Open

cknitt wants to merge 1 commit into
masterfrom
throws-exception-identity

Conversation

@cknitt

@cknitt cknitt commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Stacked on #9198. This is the follow-up to cristianoc's review comment there.

The problem

Exception analysis compares exceptions by name. That works for the predefined exceptions the stdlib annotates, such as Not_found and JsExn, but not for a library's own exceptions:

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

// App.res
let ok = s =>
  try Lib.parse(s) catch {
  | Lib.E => 0 // reported: "ok might throw E"
  }

exception E
let wrong = s =>
  try Lib.parse(s) catch {
  | E => 0 // not reported, although this is App's E
  }

The analysis sees E in the annotation and Lib.E in the catch, so it reports the correct catch and accepts the wrong one. Which exception a name refers to depends on the opens, aliases and includes in scope. Only the type checker knows that. Reanalyze can't work it out, because a .cmt keeps no type environments.

The fix

The type checker now resolves the names, and reanalyze compares the results.

Every exception gets an identity. When the type checker defines an exception, it records the module path where it is defined, for example Lib.Inner.F, in a new field of the exception's declaration. A .res and its .resi produce the same path. A rebinding such as exception Mine = Lib.E copies the identity of Lib.E.

@throws names are resolved where they are written. For a @throws on an external, on a let in an interface or module type, or on any let binding, the type checker looks up each name and stores the exceptions it found, with their identities, in a new field of the declaration. The inferred signature keeps it. Both fields reach the .cmi, so the format changes; the magic numbers are bumped at release. A @throws can list one name or several (in an array, tuple or list{}), and a name can also be written as a string. The code is in compiler/typing/throws_attribute.ml.

Reanalyze compares identities. A catch or a throw refers to an exception through its constructor, which carries the identity. So Lib.E, E after open Lib, and L.E with module L = Lib are all the same exception, and App's own E is a different one.

New warning 114 for a @throws name that isn't an exception in scope, such as a typo or a variant constructor. It is on by default and not an error. Lowercase names are never reported, because reanalyze itself suggests @throws(genericException) for throw(e).

Modules named in @throws become dependencies. The type checker loads them, so the build has to compile them first. This is the one breaking change: if a module named in @throws itself depends on the annotating module, that is now a dependency cycle.

Decisions to review

Typed fields, with module paths as strings. The type checker computes the resolved exceptions, so they live in fields of its data, not in attributes a user could write. A more ambitious version would store the exceptions' paths, which the type checker already rewrites when a module is sealed by a signature or a functor is applied. That would remove the first group of limits below. But a catch's path is the path it was reached through (Lib.E, L.E with module L = Lib, Ns.Lib.E), and making those agree needs changes to how the type checker adds module paths to a module's members. These fields are where such paths would go later.

Messages name exceptions the way the surrounding code would. Inside Inner, the exception Lib.Inner.F is shown as F; elsewhere in Lib it is Inner.F. That way, the annotation a message suggests usually compiles where it is needed. If two different exceptions would get the same short name, both keep their longer names.

A call's exceptions come from the declaration's @throws when it has one, as #9198 already does, so a module sealed by an annotated module type is caught by the module's own name (catchSealed).

Known limits

An identity belongs to a declaration, and a signature's exception E is a separate declaration from the definition it hides. That leaves these gaps:

  • If a module is sealed by a module type and only its implementation annotates @throws, a caller's catch { | M.E => ... } doesn't match (catchSealedPlain in the tests). Annotating the module type instead works (catchSealed).
  • Modules sealed by the same module type share that module type's exception identities.
  • In a functor F(X: S), @throws(X.E) keeps the identity from S, so catching the argument's exception doesn't match. Fixing this would need identities that follow functor application, as paths would (see above). Read @throws from library declarations in exception analysis #9198 doesn't match them either.

Exceptions with the same name and the same module path also share an identity. That happens for the exceptions of two applications of one functor, for a functor's parameter and its body, for a local module or function and the module around it, and for a module type and a module with the same name.

Finally, messages name a functor body's exceptions after the functor rather than its application, and show a namespaced dependency's exceptions without the namespace.

Cost

Each @throws now costs a constructor lookup, and each value description and let binding carries one more field, also without a @throws. The benchmarks job flags this: allocations grow by 0.19% overall (0.29% on the generated projects) and by 1.1% in Stdlib_JsError.resi, which has many @throws. Instructions grow by 0.09% overall.

Tests

  • In the reanalyze exception tests, ThrowsLibExnCalls.res, ThrowsRepoCalls.res and ThrowsScopes.res call into modules that define their own exceptions, and catch them by qualified name, after open, through aliases, includes and rebinds, and across functors, recursive modules and interfaces. They also pin down the limits above and the names in messages.
  • throws_unbound_warning.res in the single-file error tests covers warning 114, including the cases that must not warn.
  • tests/build_tests/projects/throws_dependency builds a module that names another one only in @throws. Before the dependency change, the build order decided whether the name resolved.

🤖 Generated with Claude Code

@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

Match @throws exceptions with catches across modules

2dac6c7 · cknitt + Claude · Nov 29, 2026, 07:33 UTC

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)

// 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
+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 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.
  • 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.

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

⚠️ Compiler benchmarks

Allocated words

In total: 653,172,803 → 654,417,070 (+0.19%).

Generated projects: 627,289,137 → 629,093,277 (+0.29%).

⚠️ Regression: 1 benchmark allocates more than 1% more.

Benchmark Base Head Change
packages/@rescript/runtime/Stdlib_JsError.resi 188,954 191,027 +1.10%
build/Namespace/edit 7,921,510 7,983,278 +0.78%
packages/@rescript/runtime/Stdlib_Intl.res 176,496 177,761 +0.72%
build/Namespace/clean 84,690,875 85,221,191 +0.63%
packages/@rescript/runtime/Stdlib_Bool.resi 117,333 118,029 +0.59%
packages/@rescript/belt/src/Belt_MutableQueue.resi 207,487 208,695 +0.58%
packages/@rescript/runtime/Primitive_list.resi 92,392 92,901 +0.55%
packages/@rescript/belt/src/Belt.res 189,407 190,446 +0.55%
packages/@rescript/runtime/Primitive_float_extern.res 94,291 94,801 +0.54%
packages/@rescript/runtime/RescriptTools.res 105,181 105,749 +0.54%
237 more changes
Benchmark Base Head Change
packages/@rescript/runtime/Primitive_hash.resi 103,174 103,728 +0.54%
packages/@rescript/runtime/Obj.res 99,756 100,288 +0.53%
packages/@rescript/runtime/Stdlib_JsError.res 227,063 228,269 +0.53%
packages/@rescript/runtime/Primitive_exceptions.resi 100,781 101,316 +0.53%
packages/@rescript/runtime/Primitive_promise.res 97,589 98,107 +0.53%
packages/@rescript/runtime/Stdlib_Blob.res 94,526 95,026 +0.53%
packages/@rescript/runtime/Primitive_module.resi 103,601 104,148 +0.53%
packages/@rescript/runtime/Primitive_string_extern.res 98,792 99,313 +0.53%
packages/@rescript/runtime/Primitive_int_extern.res 98,484 99,002 +0.53%
packages/@rescript/runtime/Stdlib_File.res 96,329 96,829 +0.52%
packages/@rescript/runtime/Primitive_object.resi 117,423 118,032 +0.52%
parse/Napkinscript.res 10,732,820 10,788,154 +0.52%
packages/@rescript/runtime/Stdlib_Iterable.resi 98,604 99,112 +0.52%
packages/@rescript/runtime/Stdlib_AsyncIterable.resi 98,753 99,261 +0.51%
packages/@rescript/runtime/Stdlib.res 984,383 989,445 +0.51%
packages/@rescript/runtime/Stdlib_AsyncIterable.res 99,589 100,099 +0.51%
packages/@rescript/runtime/Stdlib_Iterable.res 99,518 100,027 +0.51%
packages/@rescript/runtime/Stdlib_Lazy.resi 112,521 113,096 +0.51%
packages/@rescript/runtime/Stdlib_Temporal.res 225,168 226,310 +0.51%
packages/@rescript/runtime/Primitive_dict.res 103,179 103,698 +0.50%
packages/@rescript/runtime/Stdlib_BigInt.resi 186,298 187,230 +0.50%
packages/@rescript/runtime/RescriptTools_ExtractCodeBlocks.res 112,767 113,331 +0.50%
packages/@rescript/runtime/Stdlib_ArrayBuffer.res 108,054 108,590 +0.50%
packages/@rescript/runtime/Stdlib_JSON.resi 236,673 237,844 +0.49%
packages/@rescript/runtime/Primitive_object_extern.res 115,165 115,732 +0.49%
packages/@rescript/runtime/Primitive_option.resi 122,501 123,099 +0.49%
packages/@rescript/runtime/Stdlib_ArrayBuffer.resi 111,307 111,840 +0.48%
packages/@rescript/runtime/Dom_storage2.res 120,601 121,178 +0.48%
packages/@rescript/runtime/Stdlib_Global.res 142,054 142,733 +0.48%
packages/@rescript/runtime/Primitive_array_extern.res 114,543 115,090 +0.48%
packages/@rescript/runtime/Stdlib_TaggedTemplate.resi 106,479 106,987 +0.48%
packages/@rescript/runtime/Stdlib_Ordering.res 152,972 153,693 +0.47%
packages/@rescript/belt/src/Belt_MutableStack.resi 169,370 170,160 +0.47%
packages/@rescript/runtime/Stdlib_TaggedTemplate.res 115,793 116,332 +0.47%
packages/@rescript/runtime/Pervasives.res 239,218 240,331 +0.47%
packages/@rescript/runtime/Stdlib_Type.resi 136,015 136,647 +0.46%
packages/@rescript/runtime/Jsx.res 122,111 122,678 +0.46%
packages/@rescript/runtime/Stdlib_JsExn.resi 122,596 123,165 +0.46%
packages/@rescript/runtime/Stdlib_Symbol.res 146,833 147,511 +0.46%
packages/@rescript/runtime/Stdlib_JSON.res 295,385 296,737 +0.46%
packages/@rescript/runtime/Stdlib_Intl_Segments.res 117,076 117,605 +0.45%
packages/@rescript/runtime/Stdlib_Bool.res 145,286 145,931 +0.44%
packages/@rescript/runtime/Stdlib_WeakSet.res 123,547 124,095 +0.44%
packages/@rescript/runtime/Stdlib_RegExp.res 163,876 164,597 +0.44%
packages/@rescript/belt/src/Belt_MutableSetInt.resi 264,145 265,283 +0.43%
packages/@rescript/belt/src/Belt_MutableSetString.resi 264,027 265,164 +0.43%
packages/@rescript/belt/src/Belt_SetInt.resi 258,928 260,042 +0.43%
packages/@rescript/belt/src/Belt_SetString.resi 258,803 259,916 +0.43%
packages/@rescript/runtime/Dom_storage.res 166,365 167,080 +0.43%
packages/@rescript/runtime/Stdlib_Global.resi 155,359 156,023 +0.43%
packages/@rescript/runtime/Stdlib_JsExn.res 171,596 172,325 +0.42%
packages/@rescript/runtime/Stdlib_Null.resi 203,422 204,285 +0.42%
packages/@rescript/belt/src/Belt_Int.resi 149,640 150,266 +0.42%
packages/@rescript/runtime/Stdlib_Nullable.resi 198,672 199,499 +0.42%
packages/@rescript/runtime/Stdlib_Symbol.resi 159,964 160,627 +0.41%
packages/@rescript/belt/src/Belt_Float.resi 151,120 151,746 +0.41%
packages/@rescript/runtime/Stdlib_Math.res 324,678 326,017 +0.41%
packages/@rescript/runtime/Stdlib_WeakMap.res 135,699 136,256 +0.41%
packages/@rescript/runtime/Stdlib_Generator.resi 159,801 160,451 +0.41%
packages/@rescript/runtime/Primitive_array.res 184,483 185,233 +0.41%
packages/@rescript/runtime/Stdlib_BigInt.res 206,002 206,836 +0.40%
packages/@rescript/belt/src/Belt_Option.resi 241,452 242,427 +0.40%
packages/@rescript/belt/src/Belt_Float.res 164,808 165,473 +0.40%
packages/@rescript/runtime/Primitive_float.res 145,160 145,744 +0.40%
packages/@rescript/belt/src/Belt_Int.res 165,547 166,212 +0.40%
packages/@rescript/runtime/Primitive_exceptions.res 197,980 198,774 +0.40%
packages/@rescript/belt/src/Belt_HashSetString.resi 175,317 176,020 +0.40%
packages/@rescript/belt/src/Belt_HashSetInt.resi 175,430 176,133 +0.40%
packages/@rescript/runtime/Stdlib_IterableIterator.resi 148,801 149,396 +0.40%
packages/@rescript/runtime/Stdlib_Float.resi 193,376 194,149 +0.40%
packages/@rescript/runtime/Primitive_bool.res 146,639 147,225 +0.40%
packages/@rescript/runtime/Stdlib_Float.res 217,427 218,295 +0.40%
packages/@rescript/runtime/Stdlib_AsyncIterableIterator.resi 159,272 159,902 +0.40%
packages/@rescript/runtime/Primitive_string.res 156,963 157,583 +0.39%
packages/@rescript/runtime/Stdlib_AsyncGenerator.resi 165,155 165,807 +0.39%
packages/@rescript/belt/src/Belt_internalBucketsType.res 287,558 288,687 +0.39%
packages/@rescript/runtime/Stdlib_Type.res 199,232 200,011 +0.39%
packages/@rescript/belt/src/Belt_Result.resi 239,528 240,462 +0.39%
packages/@rescript/belt/src/Belt_internalBucketsType.resi 164,925 165,565 +0.39%
packages/@rescript/runtime/Stdlib_Temporal_Now.res 143,997 144,555 +0.39%
packages/@rescript/runtime/Primitive_int.res 169,043 169,690 +0.38%
packages/@rescript/runtime/Stdlib_Lazy.res 216,334 217,155 +0.38%
packages/@rescript/runtime/Stdlib_Generator.res 198,773 199,526 +0.38%
packages/@rescript/runtime/Stdlib_Iterator.resi 158,169 158,766 +0.38%
packages/@rescript/runtime/Stdlib_IterableIterator.res 178,061 178,733 +0.38%
packages/@rescript/runtime/Primitive_list.res 199,100 199,850 +0.38%
packages/@rescript/runtime/Stdlib_RegExp.resi 187,464 188,168 +0.38%
packages/@rescript/runtime/Primitive_bigint.res 174,457 175,111 +0.37%
packages/@rescript/belt/src/Belt_HashSet.resi 221,762 222,588 +0.37%
packages/@rescript/runtime/Stdlib_Pair.res 164,425 165,035 +0.37%
packages/@rescript/belt/src/Belt_SortArrayString.resi 169,383 170,009 +0.37%
packages/@rescript/belt/src/Belt_SortArrayInt.resi 169,501 170,127 +0.37%
packages/@rescript/runtime/Stdlib_Set.res 210,101 210,874 +0.37%
packages/@rescript/runtime/Stdlib_Int.resi 205,208 205,961 +0.37%
packages/@rescript/runtime/Stdlib_Intl_NumberFormat_Grouping.res 158,858 159,439 +0.37%
packages/@rescript/belt/src/Belt_Range.resi 176,113 176,756 +0.37%
packages/@rescript/belt/src/Belt_MutableMapString.resi 312,271 313,411 +0.37%
packages/@rescript/belt/src/Belt_MutableMapInt.resi 312,391 313,529 +0.36%
packages/@rescript/belt/src/Belt_internalSetBuckets.resi 194,171 194,875 +0.36%
packages/@rescript/runtime/Stdlib_AsyncGenerator.res 208,463 209,217 +0.36%
packages/@rescript/runtime/Stdlib_Map.res 204,784 205,519 +0.36%
packages/@rescript/belt/src/Belt_Id.res 288,971 290,008 +0.36%
packages/@rescript/runtime/JsxEvent.res 1,088,258 1,092,162 +0.36%
packages/@rescript/runtime/Stdlib_Intl_Segmenter.res 154,825 155,379 +0.36%
packages/@rescript/runtime/Stdlib_Int8Array.res 343,901 345,128 +0.36%
packages/@rescript/runtime/Stdlib_Uint8Array.res 343,914 345,141 +0.36%
packages/@rescript/runtime/Stdlib_Float32Array.res 344,021 345,248 +0.36%
packages/@rescript/runtime/Stdlib_Float64Array.res 344,021 345,248 +0.36%
packages/@rescript/runtime/Stdlib_Int16Array.res 344,046 345,273 +0.36%
packages/@rescript/runtime/Stdlib_Uint16Array.res 344,053 345,280 +0.36%
packages/@rescript/runtime/Stdlib_Uint32Array.res 344,053 345,280 +0.36%
packages/@rescript/runtime/Stdlib_BigInt64Array.res 344,078 345,305 +0.36%
packages/@rescript/runtime/Stdlib_AsyncIterableIterator.res 225,806 226,611 +0.36%
packages/@rescript/runtime/Stdlib_Int32Array.res 344,048 345,274 +0.36%
packages/@rescript/runtime/Stdlib_Uint8ClampedArray.res 344,429 345,656 +0.36%
packages/@rescript/runtime/Stdlib_BigUint64Array.res 344,155 345,381 +0.36%
packages/@rescript/runtime/Stdlib_Option.resi 234,106 234,936 +0.35%
packages/@rescript/runtime/Stdlib_AsyncIterator.resi 176,584 177,210 +0.35%
packages/@rescript/belt/src/Belt_HashMapString.resi 212,600 213,346 +0.35%
packages/@rescript/belt/src/Belt_HashMapInt.resi 212,714 213,460 +0.35%
packages/@rescript/runtime/Stdlib_Math.resi 326,302 327,435 +0.35%
packages/@rescript/belt/src/Belt_MutableMap.resi 391,191 392,549 +0.35%
packages/@rescript/belt/src/Belt_Set.resi 432,400 433,899 +0.35%
packages/@rescript/belt/src/Belt_MutableSet.resi 392,885 394,234 +0.34%
packages/@rescript/belt/src/Belt_Id.resi 259,349 260,237 +0.34%
packages/@rescript/runtime/Stdlib_Int.res 444,670 446,190 +0.34%
packages/@rescript/runtime/Stdlib_Iterator.res 232,421 233,207 +0.34%
packages/@rescript/runtime/Stdlib_DataView.res 229,988 230,751 +0.33%
packages/@rescript/belt/src/Belt_internalBuckets.resi 222,429 223,159 +0.33%
packages/@rescript/runtime/Stdlib_Intl_ListFormat.res 169,960 170,517 +0.33%
packages/@rescript/runtime/Stdlib_List.resi 403,815 405,135 +0.33%
packages/@rescript/runtime/Stdlib_Map.resi 215,954 216,656 +0.33%
packages/@rescript/runtime/Stdlib_Intl_Common.res 154,063 154,563 +0.32%
packages/@rescript/runtime/Stdlib_Set.resi 227,712 228,449 +0.32%
packages/@rescript/runtime/Stdlib_Intl_Locale.res 198,044 198,680 +0.32%
packages/@rescript/belt/src/Belt_Range.res 280,039 280,932 +0.32%
packages/@rescript/runtime/Stdlib_Intl_Collator.res 178,707 179,274 +0.32%
packages/@rescript/runtime/Stdlib_Null.res 327,924 328,962 +0.32%
packages/@rescript/runtime/Stdlib_AsyncIterator.res 289,784 290,699 +0.32%
packages/@rescript/belt/src/Belt_internalAVLset.resi 352,484 353,594 +0.31%
packages/@rescript/belt/src/Belt_MapString.resi 386,709 387,924 +0.31%
packages/@rescript/belt/src/Belt_MapInt.resi 386,753 387,968 +0.31%
packages/@rescript/runtime/Primitive_option.res 288,659 289,561 +0.31%
packages/@rescript/runtime/Stdlib_Nullable.res 325,041 326,048 +0.31%
packages/@rescript/runtime/Stdlib_Intl_RelativeTimeFormat.res 180,516 181,074 +0.31%
packages/@rescript/runtime/Stdlib_Object.res 247,174 247,937 +0.31%
packages/@rescript/runtime/Stdlib_Temporal_PlainMonthDay.res 267,864 268,679 +0.30%
packages/@rescript/belt/src/Belt_SortArray.resi 251,370 252,133 +0.30%
packages/@rescript/runtime/Primitive_module.res 327,105 328,097 +0.30%
packages/@rescript/belt/src/Belt_Option.res 380,720 381,864 +0.30%
packages/@rescript/belt/src/Belt_HashMap.resi 293,679 294,558 +0.30%
packages/@rescript/belt/src/Belt_Map.res 954,236 957,092 +0.30%
packages/@rescript/runtime/Stdlib_Console.res 368,881 369,977 +0.30%
packages/@rescript/runtime/Stdlib_IteratorObject.res 249,091 249,829 +0.30%
packages/@rescript/belt/src/Belt_SetDict.resi 397,167 398,335 +0.29%
packages/@rescript/belt/src/Belt_Set.res 834,105 836,551 +0.29%
packages/@rescript/runtime/Stdlib_IteratorObject.resi 232,588 233,270 +0.29%
packages/@rescript/runtime/Stdlib_Dict.resi 239,124 239,824 +0.29%
packages/@rescript/belt/src/Belt_Map.resi 570,124 571,790 +0.29%
packages/@rescript/runtime/Stdlib_Temporal_PlainTime.res 319,635 320,566 +0.29%
packages/@rescript/runtime/Stdlib_Temporal_Instant.res 307,323 308,215 +0.29%
parse/RedBlackTreeNoComments.res 356,201 357,227 +0.29%
packages/@rescript/belt/src/Belt_HashSetInt.res 823,872 826,231 +0.29%
packages/@rescript/belt/src/Belt_HashSetString.res 824,187 826,545 +0.29%
packages/@rescript/runtime/Stdlib_Result.resi 292,663 293,500 +0.29%
packages/@rescript/runtime/Stdlib_Intl_PluralRules.res 201,756 202,333 +0.29%
packages/@rescript/belt/src/Belt_MapString.res 1,161,609 1,164,900 +0.28%
packages/@rescript/runtime/Stdlib_String.res 499,237 500,650 +0.28%
parse/RedBlackTree.res 363,914 364,940 +0.28%
packages/@rescript/belt/src/Belt_MapInt.res 1,161,096 1,164,365 +0.28%
packages/@rescript/runtime/Stdlib_Dict.res 318,111 319,000 +0.28%
packages/@rescript/runtime/Stdlib_DataView.resi 267,067 267,807 +0.28%
packages/@rescript/belt/src/Belt_Array.resi 640,622 642,397 +0.28%
packages/@rescript/belt/src/Belt_HashSet.res 947,029 949,652 +0.28%
packages/@rescript/belt/src/Belt_List.resi 744,863 746,908 +0.27%
packages/@rescript/belt/src/Belt_internalSetBuckets.res 680,575 682,437 +0.27%
packages/@rescript/runtime/Stdlib_Temporal_Duration.res 372,488 373,488 +0.27%
build/clean 254,913,589 255,592,812 +0.27%
packages/@rescript/runtime/Primitive_js_extern.res 239,468 240,103 +0.27%
packages/@rescript/runtime/Stdlib_Temporal_PlainDate.res 402,873 403,939 +0.26%
packages/@rescript/belt/src/Belt_internalAVLtree.resi 447,520 448,701 +0.26%
packages/@rescript/runtime/Stdlib_Date.res 548,548 549,989 +0.26%
packages/@rescript/belt/src/Belt_internalSetInt.res 713,431 715,294 +0.26%
packages/@rescript/belt/src/Belt_internalSetString.res 714,620 716,483 +0.26%
packages/@rescript/runtime/Stdlib_Temporal_PlainDateTime.res 436,954 438,087 +0.26%
packages/@rescript/belt/src/Belt_MutableStack.res 378,903 379,882 +0.26%
packages/@rescript/belt/src/Belt_Array.res 2,035,152 2,040,401 +0.26%
packages/@rescript/runtime/Stdlib_Console.resi 409,154 410,208 +0.26%
packages/@rescript/belt/src/Belt_MutableMapInt.res 1,123,873 1,126,747 +0.26%
packages/@rescript/belt/src/Belt_MutableMapString.res 1,124,152 1,127,020 +0.26%
packages/@rescript/runtime/Stdlib_Temporal_PlainYearMonth.res 381,230 382,200 +0.25%
packages/@rescript/belt/src/Belt_MutableMap.res 1,265,000 1,268,208 +0.25%
packages/@rescript/belt/src/Belt_MutableQueue.res 764,293 766,225 +0.25%
packages/@rescript/belt/src/Belt_SetInt.res 1,264,495 1,267,685 +0.25%
packages/@rescript/belt/src/Belt_MapDict.resi 504,744 506,015 +0.25%
packages/@rescript/belt/src/Belt_SetString.res 1,265,223 1,268,406 +0.25%
packages/@rescript/belt/src/Belt_HashMapInt.res 1,027,997 1,030,582 +0.25%
packages/@rescript/belt/src/Belt_HashMapString.res 1,028,707 1,031,292 +0.25%
packages/@rescript/belt/src/Belt_HashMap.res 1,161,588 1,164,495 +0.25%
packages/@rescript/belt/src/Belt_Result.res 403,523 404,532 +0.25%
packages/@rescript/runtime/Stdlib_Array.res 1,236,407 1,239,482 +0.25%
packages/@rescript/belt/src/Belt_internalBuckets.res 935,493 937,716 +0.24%
packages/@rescript/belt/src/Belt_MapDict.res 1,594,351 1,598,108 +0.24%
packages/@rescript/runtime/Stdlib_String.resi 494,109 495,263 +0.23%
packages/@rescript/belt/src/Belt_MutableSetString.res 1,604,700 1,608,423 +0.23%
packages/@rescript/belt/src/Belt_MutableSetInt.res 1,603,467 1,607,182 +0.23%
build/WideDeps/clean 369,259,162 370,111,108 +0.23%
packages/@rescript/belt/src/Belt_SortArray.res 1,368,157 1,371,308 +0.23%
packages/@rescript/runtime/RescriptTools_Docgen.resi 272,621 273,239 +0.23%
packages/@rescript/belt/src/Belt_SetDict.res 1,416,352 1,419,554 +0.23%
packages/@rescript/runtime/RescriptTools_Docgen.res 282,854 283,486 +0.22%
packages/@rescript/belt/src/Belt_MutableSet.res 1,830,979 1,835,069 +0.22%
packages/@rescript/runtime/Stdlib_Promise.res 349,788 350,561 +0.22%
build/WideDeps/edit 165,417,590 165,777,700 +0.22%
packages/@rescript/runtime/Stdlib_Option.res 741,048 742,649 +0.22%
packages/@rescript/runtime/Stdlib_Temporal_ZonedDateTime.res 572,263 573,494 +0.22%
packages/@rescript/belt/src/Belt_SortArrayInt.res 1,270,587 1,273,308 +0.21%
packages/@rescript/belt/src/Belt_SortArrayString.res 1,272,378 1,275,099 +0.21%
packages/@rescript/runtime/Stdlib_Date.resi 609,929 611,218 +0.21%
packages/@rescript/runtime/Stdlib_Promise.resi 352,998 353,705 +0.20%
packages/@rescript/runtime/Stdlib_TypedArray.res 780,174 781,709 +0.20%
packages/@rescript/runtime/Stdlib_Array.resi 719,070 720,472 +0.19%
packages/@rescript/runtime/Stdlib_Intl_DateTimeFormat.res 388,363 389,110 +0.19%
packages/@rescript/belt/src/Belt_List.res 3,060,851 3,066,601 +0.19%
packages/@rescript/runtime/Primitive_hash.res 922,449 924,130 +0.18%
packages/@rescript/belt/src/Belt_internalMapInt.res 1,370,465 1,372,956 +0.18%
packages/@rescript/belt/src/Belt_internalMapString.res 1,372,309 1,374,786 +0.18%
packages/@rescript/runtime/Primitive_object.res 1,107,736 1,109,707 +0.18%
packages/@rescript/runtime/Stdlib_Intl_NumberFormat.res 403,151 403,867 +0.18%
packages/@rescript/runtime/Stdlib_List.res 2,580,922 2,585,434 +0.17%
packages/@rescript/belt/src/Belt_internalAVLset.res 2,758,234 2,762,739 +0.16%
stress/InlineChain.res 3,385,341 3,390,862 +0.16%
build/shared-edit 84,722,696 84,860,075 +0.16%
packages/@rescript/belt/src/Belt_internalAVLtree.res 3,361,970 3,367,266 +0.16%
packages/@rescript/runtime/Stdlib_Result.res 1,248,443 1,250,160 +0.14%
packages/@rescript/runtime/Stdlib_Temporal_Common.res 365,604 366,104 +0.14%
build/leaf-edit 11,639,147 11,651,585 +0.11%

Instructions

In total: 8,966,820,936 → 8,975,959,869 (+0.10%).

Benchmark Base Head Change
stress/ObjectFields.res 941,853,583 948,651,395 +0.72%
parse/Napkinscript.res 333,476,359 333,924,367 +0.13%
stress/InlineChain.res 136,851,350 137,017,642 +0.12%

Output size

In total: 27,449,936 → 27,519,996 (+0.26%).

Benchmark Base Head Change
output/belt/*.cmi 463,514 465,246 +0.37%
output/tests/*.cmi 2,450,446 2,459,498 +0.37%
output/belt/*.cmt 2,755,115 2,764,924 +0.36%
output/tests/*.cmt 12,495,010 12,528,922 +0.27%
output/tests/*.cmti 175,826 176,288 +0.26%
output/runtime/*.cmt 3,041,525 3,047,910 +0.21%
output/belt/*.cmti 985,003 986,633 +0.17%
output/playground/compiler.js 1,901,187 1,904,285 +0.16%
output/runtime/*.cmi 1,921,294 1,924,162 +0.15%

Pull request 2dac6c7 compared with base 7968a96 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: 2dac6c7

@cknitt
cknitt force-pushed the drift-9182-temporal-exn branch from 1feb838 to 4bcdd86 Compare November 29, 2026 08:05
@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 92.26804% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.57%. Comparing base (7968a96) to head (2dac6c7).

Files with missing lines Patch % Lines
compiler/typing/throws_attribute.ml 86.84% 10 Missing ⚠️
analysis/reanalyze/src/exception.ml 97.91% 1 Missing ⚠️
analysis/reanalyze/src/exn.ml 91.66% 1 Missing ⚠️
compiler/typing/printtyped.ml 0.00% 1 Missing ⚠️
compiler/typing/rec_check.ml 0.00% 1 Missing ⚠️
compiler/typing/typedtree_iter.ml 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9476      +/-   ##
==========================================
+ Coverage   82.54%   82.57%   +0.03%     
==========================================
  Files         468      469       +1     
  Lines       66226    66363     +137     
==========================================
+ Hits        54665    54802     +137     
  Misses      11561    11561              
Files with missing lines Coverage Δ
analysis/reanalyze/src/exceptions.ml 92.85% <ø> (ø)
compiler/typing/ctype.ml 70.73% <ø> (ø)
compiler/typing/datarepr.ml 92.92% <ø> (ø)
compiler/typing/depend.ml 88.23% <100.00%> (+0.28%) ⬆️
compiler/typing/predef.ml 100.00% <ø> (ø)
compiler/typing/subst.ml 85.96% <ø> (ø)
compiler/typing/tast_iterator.ml 87.31% <100.00%> (ø)
compiler/typing/tast_mapper.ml 99.58% <100.00%> (+0.41%) ⬆️
compiler/typing/translmod.ml 95.65% <100.00%> (ø)
compiler/typing/typecore.ml 89.23% <100.00%> (+0.01%) ⬆️
... and 13 more

... 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-30T20:12:08.563838Z da6ef99 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
@cknitt
cknitt force-pushed the drift-9182-temporal-exn branch from 4bcdd86 to aa74ffb Compare November 30, 2026 09:43
@cknitt
cknitt force-pushed the throws-exception-identity branch from 9242898 to 1f2a539 Compare November 30, 2026 09:44
@cknitt

cknitt commented Nov 30, 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: 1f2a539cd7

ℹ️ 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 throws-exception-identity branch from 1f2a539 to 5775b9c Compare November 30, 2026 18:05
@cknitt
cknitt marked this pull request as ready for review November 30, 2026 18:06
@cknitt
cknitt force-pushed the throws-exception-identity branch from 5775b9c to b8a0f62 Compare November 30, 2026 19:18
@cknitt

cknitt commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: b8a0f62c8c

ℹ️ 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 aa74ffb to d5177af Compare November 30, 2026 19:53
@cknitt
cknitt force-pushed the throws-exception-identity branch from b8a0f62 to da6ef99 Compare November 30, 2026 20:08
@cknitt

cknitt commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: da6ef998bc

ℹ️ 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 throws-exception-identity branch from da6ef99 to acd6cb6 Compare December 3, 2026 06:46
@cknitt
cknitt force-pushed the drift-9182-temporal-exn branch from d5177af to d120a7b Compare December 3, 2026 06:46
@cknitt
cknitt removed this pull request from stack #9477 December 3, 2026 15:29
Base automatically changed from drift-9182-temporal-exn to master December 3, 2026 15:29
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.

2 participants