Repository navigation
Conversation
Changelog🚀 New Feature
Semantic Diff1 commit · Full page Read
|
| Before | After |
|---|---|
|
|
|
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 => intReanalyze 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
@throwson the implementation's binding, the declaration the one in its interface. Either can be the only one written, as with an annotated.resiletwhose.resisn't annotated, so the call can throw what either names. - Why does the inferred signature take only the
@throwsfamily and@deprecated, and not every attribute? A doc comment is an attribute too: in the.cmiit would make editing a comment recompile the module's dependents. A module with a.resiis unchanged, since its.cmiholds the interface's declarations. - What does a
@throwswithout a payload mean? Nothing, as on a binding. The guard requires a payload, and the stdlib's two payload-less@throwsin Stdlib_JSON.res now nameJsExn.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #9198 +/- ##
==========================================
+ Coverage 82.21% 82.22% +0.01%
==========================================
Files 460 460
Lines 65551 65660 +109
==========================================
+ Hits 53891 53989 +98
- Misses 11660 11671 +11
🚀 New features to boost your workflow:
|
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-9198 |
0a37396 to
9b3d665
Compare
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
9b3d665 to
76f8a78
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
68c774c to
1d38461
Compare
1d38461 to
18ed190
Compare
Changelog💥 Breaking Change
🚀 New Feature
Semantic Diff5 commits · Full page Read
|
| Before | After |
|---|---|
|
|
|
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 => intReanalyze 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
@throwson the implementation's binding, the declaration the one in its interface. Either can be the only one written, as with an annotated.resiletwhose.resisn't annotated, so the call can throw what either names. - Why does the inferred signature take only the
@throwsfamily and@deprecated, and not every attribute? A doc comment is an attribute too: in the.cmiit would make editing a comment recompile the module's dependents. A module with a.resiis unchanged, since its.cmiholds the interface's declarations. - What does a
@throwswithout a payload mean? Nothing, as on a binding. The guard requires a payload, and the stdlib's two payload-less@throwsin Stdlib_JSON.res now nameJsExn.
Drop the empty BsJson module from the deadcode debug snapshot
2293610 · cknitt + Claude · Nov 10, 2026, 17:30 UTC
Why
Since #9245 every .cmt lands in the flat lib/rescript, so the empty src/exception/BsJson.res logged "Implementation 0" in the deadcode debug output. This PR deletes that file, so the line goes away.
Resolve the exceptions @throws names in the type checker
172814c · cknitt + Claude · Nov 19, 2026, 08:01 UTC
Why
Review on #9198: a library's
@throws(E)reached callers as the bare nameE, while a catch was compared as written (Lib.E), so a correct catch was still reported and a caller's ownEcould hide the library's. Reanalyze cannot resolve names itself, because a .cmt keeps no environments; two attempts to guess the scope from the file still got opens in interfaces, functors, includes and aliases wrong.
The type checker now looks up each name in a @throws where it is written, for externals, lets in signatures and interfaces, and every let binding. It adds a generated @res.throws that lists each exception's readable name and identity, and the inferred signature keeps it next to @throws. The identity is the defining file without its extension and the exception's name (src/Lib#E), so a module's .res and .resi agree and moving a definition within its file changes nothing. Exception analysis compares these identities with the constructors that catches and throws name.
A name that is not an exception in scope gets the new warning 113 and is listed as written. A rebinding (exception Mine = Lib.E) is a new definition, so catching Mine does not catch Lib.E, as before. Two exceptions with the same name in one file share an identity.
Typedtree modified (@throws resolved where it is written)
module Errors = {
exception NotFound
}
open Errors
@throws(NotFound)
external find: int => int = "find"typed
Tstr_primitive
value_description find/1003
attribute "throws"
structure_item
Pstr_eval
expression
Pexp_construct "NotFound"
[]
+ attribute "res.throws"
+ structure_item
+ Pstr_eval
+ expression
+ Pexp_array
+ expression
+ Pexp_tuple
+ expression
+ Pexp_constant PConst_string (source="Repo.Errors.NotFound", semantic="Repo.Errors.NotFound")
+ expression
+ Pexp_constant PConst_string (source="Repo#NotFound", semantic="Repo#NotFound")Diagnostic added (warning 113)
@throws(Missing)
let f = () => 1diagnostic · After · tests/build_tests/super_errors/fixtures/throws_unbound_warning.res
Warning number 113
throws_unbound_warning.res:3:9-15
@throws names Missing, which is not an exception in scope here. Exception analysis cannot match it with the exceptions callers catch.
Reanalyze modified (catches of another module's exceptions)
// ThrowsLibExn.res
exception E
@throws(E)
external parse: string => int = "parseThrowing"
// ThrowsLibExnCalls.res
let catchExternal = s =>
try ThrowsLibExn.parse(s) catch {
| ThrowsLibExn.E => 0
}reanalyze · tests/analysis_tests/tests-reanalyze/deadcode/src/exception
-Exception Analysis
-ThrowsLibExnCalls.res:4:5-17
-catchExternal might throw E (ThrowsLibExnCalls.res:5:6) and is not annotated with @throws(E)
-Exception Analysis
-ThrowsRepoCalls.res:18:5-16
-catchViaOpen might throw Bad (ThrowsRepoCalls.res:19:6) and is not annotated with @throws(Bad)
-Exception Analysis
-ThrowsScopes.res:2:5-18
-catchIfaceOpen might throw NotFound (ThrowsScopes.res:3:6) and is not annotated with @throws(NotFound)
-Exception Analysis
-ThrowsLibExnCalls.res:103:7-12
-caught might throw E (ThrowsLibExnCalls.res:104:8) and is not annotated with @throws(E)
…
-Exception Analysis
-ThrowsLibExnCalls.res:81:5-16
-catchRebound might throw E (ThrowsLibExnCalls.res:82:6) and is not annotated with @throws(E)
+Exception Analysis
+ThrowsLibExnCalls.res:81:5-16
+catchRebound might throw ThrowsLibExn.E (ThrowsLibExnCalls.res:82:6) and is not annotated with @throws(ThrowsLibExn.E)Review
- Why an identity from the file and name instead of the path? The type checker has no module prefix for a file's own exceptions, and a path changes with aliases and namespaces. The file and name are the same through every alias, open, include and functor, and in the .res and .resi.
- Does this recompile more? Only the attribute is new, and it holds names, not positions, so it changes only when the exception is renamed or moves to another file.
Read list payloads in @throws and name location-less exceptions explicitly
60f3830 · cknitt + Claude · Nov 19, 2026, 19:04 UTC
Why
Codex review on #9198: the compiler's new
@throwsreader droppedlist{A, B}payloads and constructors written with arguments, which reanalyze's old reader accepted, so such annotations silently stopped declaring anything. It also derived an exception's identity from a location that a .cmi built with -no-keep-locs (the runtime's and Belt's) does not keep.
The reader again takes list{...} and M.E(...) as before. An exception whose .cmi has no locations is now identified as #Name on purpose, rather than through the placeholder file name _none_. Codex's crash report for that case does not hold, since Filename.remove_extension does not raise on _none_, but the identity was accidental.
AST modified (res.throws for a list payload)
exception E
@throws(list{E, Not_found})
let f = () => throw(E)text · number of res.throws attributes in bsc -dtypedtree
-0
+1Make modules named in @throws dependencies and name nested exceptions exactly
629ea53 · cknitt + Claude · Nov 19, 2026, 19:19 UTC
Why
Review of #9198: the type checker loads the module a
@throwsnames, but the dependency scanner skipped attributes. A module named only there was built in any order, so the name resolved or got warning 113 depending on the build, and a later edit could fail with "inconsistent assumptions". Messages also named an exception defined in a nested module without that module, so the annotation they suggested did not resolve. And a library built with -no-keep-locs recorded its own exceptions with its file, while its users see them without one.
Depend now adds the modules a @throws names, like any other use, so they are built first. A module that is both named in @throws and depends on the annotating module now gives a dependency cycle error.
Typemod records which module of the current file defines each exception and module, so a file's own exception is named Lib.Inner.F. Under -no-keep-locs a file's own exceptions are identified by name alone also while it is compiled. Warning 113 is shown once for a let that destructures a tuple.
Diagnostic modified (an exception of a nested module)
// ThrowsLibExn.res
module Inner = {
exception F
@throws(F)
external find: int => int = "findThrowing"
}
// ThrowsLibExnCalls.res
let uncaughtNested = x => ThrowsLibExn.Inner.find(x)reanalyze · tests/analysis_tests/tests-reanalyze/deadcode/src/exception/ThrowsLibExnCalls.res
-Exception Analysis
-ThrowsLibExnCalls.res:110:5-18
-uncaughtNested might throw ThrowsLibExn.F (ThrowsLibExnCalls.res:110:26) and is not annotated with @throws(ThrowsLibExn.F)
+Exception Analysis
+ThrowsLibExnCalls.res:110:5-18
+uncaughtNested might throw ThrowsLibExn.Inner.F (ThrowsLibExnCalls.res:110:26) and is not annotated with @throws(ThrowsLibExn.Inner.F)Diagnostic modified (a module named only in @throws, tests/build_tests/throws_dependency)
// A.res
@throws(Z.E)
external find: int => int = "find"
// Z.res
exception Ediagnostic · Before: A.res built before Z.res
-Warning number 113
-@throws names Z.E, which is not an exception in scope here. Exception analysis cannot match it with the exceptions callers catch.
+Z.res built first, no warning
⚠️ Breaking: A module named in@throwsthat itself depends on the annotating module is now a dependency cycle. Move the exception to a module of its own.
✅ Compiler benchmarksAllocated wordsIn total: 636,516,783 → 637,517,152 (+0.16%). Generated projects: 629,041,764 → 629,721,508 (+0.11%).
234 more changes
(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. InstructionsIn total: 9,221,447,599 → 9,225,751,340 (+0.05%).
4 more changes
(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 sizeIn total: 25,962,507 → 26,011,644 (+0.19%).
(inputs changed): this pull request changes runtime or Belt sources, so these benchmarks compile different code than on the base, and their changes don't count as regressions. Pull request 629ea53 compared with base 643e9c0 in this run. |
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-9198 |
cristianoc
left a comment
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
[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.
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>
bd4a722 to
9be7aca
Compare
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>
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>
9be7aca to
0786ca1
Compare
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>
0786ca1 to
b0666ce
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b0666ce189
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…citly
Why:
Codex review on #9198: the compiler's new @throws reader dropped
`list{A, B}` payloads and constructors written with arguments, which
reanalyze's old reader accepted, so such annotations silently stopped
declaring anything. It also derived an exception's identity from a
location that a .cmi built with -no-keep-locs (the runtime's and
Belt's) does not keep.
The reader again takes `list{...}` and `M.E(...)` as before. An exception
whose .cmi has no locations is now identified as `#Name` on purpose,
rather than through the placeholder file name `_none_`. Codex's crash
report for that case does not hold, since `Filename.remove_extension`
does not raise on `_none_`, but the identity was accidental.
AST modified (res.throws for a list payload):
Example:
exception E
@throws(list{E, Not_found})
let f = () => throw(E)
Before (text): number of res.throws attributes in bsc -dtypedtree
0
After (text): number of res.throws attributes in bsc -dtypedtree
1
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHA54VKxsXvCQyC2vw
Signed-off-by: Christoph Knittel <ck@cca.io>
… exactly
Why:
Review of #9198: the type checker loads the module a @throws names, but
the dependency scanner skipped attributes. A module named only there was
built in any order, so the name resolved or got warning 113 depending
on the build, and a later edit could fail with "inconsistent
assumptions". Messages also named an exception defined in a nested
module without that module, so the annotation they suggested did not
resolve. And a library built with -no-keep-locs recorded its own
exceptions with its file, while its users see them without one.
`Depend` now adds the modules a @throws names, like any other use, so
they are built first. A module that is both named in @throws and depends
on the annotating module now gives a dependency cycle error.
`Typemod` records which module of the current file defines each
exception and module, so a file's own exception is named `Lib.Inner.F`.
Under -no-keep-locs a file's own exceptions are identified by name alone
also while it is compiled. Warning 113 is shown once for a `let` that
destructures a tuple.
Diagnostic modified (an exception of a nested module):
Example:
// ThrowsLibExn.res
module Inner = {
exception F
@throws(F)
external find: int => int = "findThrowing"
}
// ThrowsLibExnCalls.res
let uncaughtNested = x => ThrowsLibExn.Inner.find(x)
Before (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception/ThrowsLibExnCalls.res
Exception Analysis
ThrowsLibExnCalls.res:110:5-18
uncaughtNested might throw ThrowsLibExn.F (ThrowsLibExnCalls.res:110:26) and is not annotated with @throws(ThrowsLibExn.F)
After (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception/ThrowsLibExnCalls.res
Exception Analysis
ThrowsLibExnCalls.res:110:5-18
uncaughtNested might throw ThrowsLibExn.Inner.F (ThrowsLibExnCalls.res:110:26) and is not annotated with @throws(ThrowsLibExn.Inner.F)
Diagnostic modified (a module named only in @throws, tests/build_tests/throws_dependency):
Example:
// A.res
@throws(Z.E)
external find: int => int = "find"
// Z.res
exception E
Before (diagnostic): A.res built before Z.res
Warning number 113
@throws names Z.E, which is not an exception in scope here. Exception analysis cannot match it with the exceptions callers catch.
After (diagnostic): Z.res built first, no warning
Breaking: A module named in @throws that itself depends on the annotating module is now a dependency cycle. Move the exception to a module of its own.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHA54VKxsXvCQyC2vw
Signed-off-by: Christoph Knittel <ck@cca.io>
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>
52da1a6 to
866c860
Compare
…citly
Why:
Codex review on #9198: the compiler's new @throws reader dropped
`list{A, B}` payloads and constructors written with arguments, which
reanalyze's old reader accepted, so such annotations silently stopped
declaring anything. It also derived an exception's identity from a
location that a .cmi built with -no-keep-locs (the runtime's and
Belt's) does not keep.
The reader again takes `list{...}` and `M.E(...)` as before. An exception
whose .cmi has no locations is now identified as `#Name` on purpose,
rather than through the placeholder file name `_none_`. Codex's crash
report for that case does not hold, since `Filename.remove_extension`
does not raise on `_none_`, but the identity was accidental.
AST modified (res.throws for a list payload):
Example:
exception E
@throws(list{E, Not_found})
let f = () => throw(E)
Before (text): number of res.throws attributes in bsc -dtypedtree
0
After (text): number of res.throws attributes in bsc -dtypedtree
1
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHA54VKxsXvCQyC2vw
Signed-off-by: Christoph Knittel <ck@cca.io>
… exactly
Why:
Review of #9198: the type checker loads the module a @throws names, but
the dependency scanner skipped attributes. A module named only there was
built in any order, so the name resolved or got warning 113 depending
on the build, and a later edit could fail with "inconsistent
assumptions". Messages also named an exception defined in a nested
module without that module, so the annotation they suggested did not
resolve. And a library built with -no-keep-locs recorded its own
exceptions with its file, while its users see them without one.
`Depend` now adds the modules a @throws names, like any other use, so
they are built first. A module that is both named in @throws and depends
on the annotating module now gives a dependency cycle error.
`Typemod` records which module of the current file defines each
exception and module, so a file's own exception is named `Lib.Inner.F`.
Under -no-keep-locs a file's own exceptions are identified by name alone
also while it is compiled. Warning 113 is shown once for a `let` that
destructures a tuple.
Diagnostic modified (an exception of a nested module):
Example:
// ThrowsLibExn.res
module Inner = {
exception F
@throws(F)
external find: int => int = "findThrowing"
}
// ThrowsLibExnCalls.res
let uncaughtNested = x => ThrowsLibExn.Inner.find(x)
Before (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception/ThrowsLibExnCalls.res
Exception Analysis
ThrowsLibExnCalls.res:110:5-18
uncaughtNested might throw ThrowsLibExn.F (ThrowsLibExnCalls.res:110:26) and is not annotated with @throws(ThrowsLibExn.F)
After (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception/ThrowsLibExnCalls.res
Exception Analysis
ThrowsLibExnCalls.res:110:5-18
uncaughtNested might throw ThrowsLibExn.Inner.F (ThrowsLibExnCalls.res:110:26) and is not annotated with @throws(ThrowsLibExn.Inner.F)
Diagnostic modified (a module named only in @throws, tests/build_tests/throws_dependency):
Example:
// A.res
@throws(Z.E)
external find: int => int = "find"
// Z.res
exception E
Before (diagnostic): A.res built before Z.res
Warning number 113
@throws names Z.E, which is not an exception in scope here. Exception analysis cannot match it with the exceptions callers catch.
After (diagnostic): Z.res built first, no warning
Breaking: A module named in @throws that itself depends on the annotating module is now a dependency cycle. Move the exception to a module of its own.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHA54VKxsXvCQyC2vw
Signed-off-by: Christoph Knittel <ck@cca.io>
Why:
The exception analysis knew what library functions throw only from a
table kept by hand in exn_lib.ml. The table drifted: the Temporal
`fromStringOrThrow` functions were never added (#9182), and neither
were a few Intl and Belt ones. Third-party libraries and a project's
own externals had no way to say what they throw.
A call now takes the exceptions named by the `@throws` on the declaration
of the value it calls, and the table is gone. The `.cmi` keeps the
attributes of externals and interface declarations, so their `@throws`
reaches calls in other modules and packages, through aliases, `open`,
`include`, functors and first-class modules. For a `let` in a module
without an interface, the type checker now copies the binding's `@throws`
into the inferred signature, as it already did for `@deprecated`. The
stdlib and Belt declare what their throwing functions throw, and a guard
in the reanalyze tests fails when a stdlib or Belt `*OrThrow` or `*Exn`
declaration has no `@throws(...)`.
Analysis modified (exceptions of a call to `f`, `Exception.Event` loop):
Before (rule):
throws(`f`) = values(`f`) when `f` is in the values table
throws(`f`) = table(`f`) otherwise
After (rule):
throws(`f`) = declared(`f`) ∪ values(`f`)
Signature modified (inferred signature of a module without an interface, `Typemod.type_structure`):
Example:
/** Finds the value. */
@throws(Not_found)
let find = x => x > 0 ? x : throw(Not_found)
Before (rescript): the signature in the .cmi
let find: int => int
After (rescript):
@throws(Not_found)
let find: int => int
Reanalyze modified (calls to annotated externals):
Example:
// Lib.res
@throws(JsExn)
external parse: string => int = "parseInt"
// App.res
let parse = s => Lib.parse(s)
@throws(JsExn)
let parseAnnotated = s => Lib.parse(s)
let date = () => Temporal.PlainDate.fromStringOrThrow("x")
Before (reanalyze):
Exception Analysis
App.res:4:5-18
parseAnnotated throws nothing and is annotated with redundant @throws(JsExn)
Analysis reported 1 issues (Exception Analysis:1)
After (reanalyze):
Exception Analysis
App.res:1:5-9
parse might throw JsExn (App.res:1:17) and is not annotated with @throws(JsExn)
Exception Analysis
App.res:6:5-8
date might throw JsExn (App.res:6:17) and is not annotated with @throws(JsExn)
Analysis reported 2 issues (Exception Analysis:2)
Review: Why the union of the declaration and the values table, rather than
one winning? The values table holds the `@throws` on the implementation's
binding, the declaration the one in its interface. Either can be the only
one written, as with an annotated `.resi` `let` whose `.res` isn't
annotated, so the call can throw what either names.
Review: Why does the inferred signature take only the `@throws` family and
`@deprecated`, and not every attribute? A doc comment is an attribute too:
in the `.cmi` it would make editing a comment recompile the module's
dependents. A module with a `.resi` is unchanged, since its `.cmi` holds
the interface's declarations.
Review: What does a `@throws` without a payload mean? Nothing, as on a
binding. The guard requires a payload, and the stdlib's two payload-less
`@throws` in Stdlib_JSON.res now name `JsExn`.
Fixes #9182
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gGhHjzBTXqSo8Dckpb
Signed-off-by: Christoph Knittel <ck@cca.io>
Why:
Since #9245 every .cmt lands in the flat lib/rescript, so the empty
src/exception/BsJson.res logged "Implementation 0" in the deadcode
debug output. This PR deletes that file, so the line goes away.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHi59ptFC3WWfiDQH4
Signed-off-by: Christoph Knittel <ck@cca.io>
Why:
Review on #9198: a library's `@throws(E)` reached callers as the bare
name `E`, while a catch was compared as written (`Lib.E`), so a correct
catch was still reported and a caller's own `E` could hide the
library's. Reanalyze cannot resolve names itself, because a .cmt keeps
no environments; two attempts to guess the scope from the file still
got opens in interfaces, functors, includes and aliases wrong.
The type checker now looks up each name in a `@throws` where it is
written, for externals, `let`s in signatures and interfaces, and every
`let` binding. It adds a generated `@res.throws` that lists each
exception's readable name and identity, and the inferred signature keeps
it next to `@throws`. The identity is the defining file without its
extension and the exception's name (`src/Lib#E`), so a module's .res and
.resi agree and moving a definition within its file changes nothing.
Exception analysis compares these identities with the constructors that
catches and throws name.
A name that is not an exception in scope gets the new warning 113 and is
listed as written. A rebinding (`exception Mine = Lib.E`) is a new
definition, so catching `Mine` does not catch `Lib.E`, as before. Two
exceptions with the same name in one file share an identity.
Typedtree modified (@throws resolved where it is written):
Example:
module Errors = {
exception NotFound
}
open Errors
@throws(NotFound)
external find: int => int = "find"
Before (typed):
Tstr_primitive
value_description find/1003
attribute "throws"
[
structure_item
Pstr_eval
expression
Pexp_construct "NotFound"
[]
]
After (typed):
Tstr_primitive
value_description find/1003
attribute "throws"
[
structure_item
Pstr_eval
expression
Pexp_construct "NotFound"
[]
]
attribute "res.throws"
[
structure_item
Pstr_eval
expression
Pexp_array
[
expression
Pexp_tuple
[
expression
Pexp_constant PConst_string (source="Repo.Errors.NotFound", semantic="Repo.Errors.NotFound")
expression
Pexp_constant PConst_string (source="Repo#NotFound", semantic="Repo#NotFound")
]
]
]
Diagnostic added (warning 113):
Example:
@throws(Missing)
let f = () => 1
After (diagnostic): tests/build_tests/super_errors/fixtures/throws_unbound_warning.res
Warning number 113
throws_unbound_warning.res:3:9-15
@throws names Missing, which is not an exception in scope here. Exception analysis cannot match it with the exceptions callers catch.
Reanalyze modified (catches of another module's exceptions):
Example:
// ThrowsLibExn.res
exception E
@throws(E)
external parse: string => int = "parseThrowing"
// ThrowsLibExnCalls.res
let catchExternal = s =>
try ThrowsLibExn.parse(s) catch {
| ThrowsLibExn.E => 0
}
Before (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception
Exception Analysis
ThrowsLibExnCalls.res:4:5-17
catchExternal might throw E (ThrowsLibExnCalls.res:5:6) and is not annotated with @throws(E)
Exception Analysis
ThrowsRepoCalls.res:18:5-16
catchViaOpen might throw Bad (ThrowsRepoCalls.res:19:6) and is not annotated with @throws(Bad)
Exception Analysis
ThrowsScopes.res:2:5-18
catchIfaceOpen might throw NotFound (ThrowsScopes.res:3:6) and is not annotated with @throws(NotFound)
Exception Analysis
ThrowsLibExnCalls.res:103:7-12
caught might throw E (ThrowsLibExnCalls.res:104:8) and is not annotated with @throws(E)
…
Exception Analysis
ThrowsLibExnCalls.res:81:5-16
catchRebound might throw E (ThrowsLibExnCalls.res:82:6) and is not annotated with @throws(E)
After (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception
Exception Analysis
ThrowsLibExnCalls.res:81:5-16
catchRebound might throw ThrowsLibExn.E (ThrowsLibExnCalls.res:82:6) and is not annotated with @throws(ThrowsLibExn.E)
Review: Why an identity from the file and name instead of the path? The type checker has no module prefix for a file's own exceptions, and a path changes with aliases and namespaces. The file and name are the same through every alias, open, include and functor, and in the .res and .resi.
Review: Does this recompile more? Only the attribute is new, and it holds names, not positions, so it changes only when the exception is renamed or moves to another file.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHA54VKxsXvCQyC2vw
Signed-off-by: Christoph Knittel <ck@cca.io>
…citly
Why:
Codex review on #9198: the compiler's new @throws reader dropped
`list{A, B}` payloads and constructors written with arguments, which
reanalyze's old reader accepted, so such annotations silently stopped
declaring anything. It also derived an exception's identity from a
location that a .cmi built with -no-keep-locs (the runtime's and
Belt's) does not keep.
The reader again takes `list{...}` and `M.E(...)` as before. An exception
whose .cmi has no locations is now identified as `#Name` on purpose,
rather than through the placeholder file name `_none_`. Codex's crash
report for that case does not hold, since `Filename.remove_extension`
does not raise on `_none_`, but the identity was accidental.
AST modified (res.throws for a list payload):
Example:
exception E
@throws(list{E, Not_found})
let f = () => throw(E)
Before (text): number of res.throws attributes in bsc -dtypedtree
0
After (text): number of res.throws attributes in bsc -dtypedtree
1
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHA54VKxsXvCQyC2vw
Signed-off-by: Christoph Knittel <ck@cca.io>
… exactly
Why:
Review of #9198: the type checker loads the module a @throws names, but
the dependency scanner skipped attributes. A module named only there was
built in any order, so the name resolved or got warning 113 depending
on the build, and a later edit could fail with "inconsistent
assumptions". Messages also named an exception defined in a nested
module without that module, so the annotation they suggested did not
resolve. And a library built with -no-keep-locs recorded its own
exceptions with its file, while its users see them without one.
`Depend` now adds the modules a @throws names, like any other use, so
they are built first. A module that is both named in @throws and depends
on the annotating module now gives a dependency cycle error.
`Typemod` records which module of the current file defines each
exception and module, so a file's own exception is named `Lib.Inner.F`.
Under -no-keep-locs a file's own exceptions are identified by name alone
also while it is compiled. Warning 113 is shown once for a `let` that
destructures a tuple.
Diagnostic modified (an exception of a nested module):
Example:
// ThrowsLibExn.res
module Inner = {
exception F
@throws(F)
external find: int => int = "findThrowing"
}
// ThrowsLibExnCalls.res
let uncaughtNested = x => ThrowsLibExn.Inner.find(x)
Before (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception/ThrowsLibExnCalls.res
Exception Analysis
ThrowsLibExnCalls.res:110:5-18
uncaughtNested might throw ThrowsLibExn.F (ThrowsLibExnCalls.res:110:26) and is not annotated with @throws(ThrowsLibExn.F)
After (reanalyze): tests/analysis_tests/tests-reanalyze/deadcode/src/exception/ThrowsLibExnCalls.res
Exception Analysis
ThrowsLibExnCalls.res:110:5-18
uncaughtNested might throw ThrowsLibExn.Inner.F (ThrowsLibExnCalls.res:110:26) and is not annotated with @throws(ThrowsLibExn.Inner.F)
Diagnostic modified (a module named only in @throws, tests/build_tests/throws_dependency):
Example:
// A.res
@throws(Z.E)
external find: int => int = "find"
// Z.res
exception E
Before (diagnostic): A.res built before Z.res
Warning number 113
@throws names Z.E, which is not an exception in scope here. Exception analysis cannot match it with the exceptions callers catch.
After (diagnostic): Z.res built first, no warning
Breaking: A module named in @throws that itself depends on the annotating module is now a dependency cycle. Move the exception to a module of its own.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHA54VKxsXvCQyC2vw
Signed-off-by: Christoph Knittel <ck@cca.io>
866c860 to
629ea53
Compare
The exception analysis knew what library functions throw only from a hand-kept table in
analysis/reanalyze/src/exn_lib.ml, and that table drifted. #9182 is the example: the eight TemporalfromStringOrThrowfunctions were never added, sorescript-tools reanalyze -exceptiontreatedTemporal.PlainDate.fromStringOrThrow("x")as throwing nothing. A few Intl and Belt functions were missing as well. Third-party libraries, and a project's own externals, had no way to declare their exceptions at all.Fixes #9182
The new rule
At each call, the analysis reads
@throws(...)from the declaration of the value being called. The.cmikeeps the attributes of externals and interface declarations, so their@throwsreaches calls from other modules and packages. It also survives module aliases,open,include, functor results and first-class modules.A call's exceptions are
declared(f) ∪ values(f): the declaration's@throws, together with the values-table entry (the@throwson the implementation's own binding, as before). There is no table any more. I chose the union over letting one source win because either source can be the only one written down. An annotated.resiletwhose.resbinding isn't annotated is a common case, and a call can throw whatever either source names.A
@throwswithout a payload still means nothing, as it always has on bindings.Compiler: resolving the names in
@throwsA
@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.cmtkeeps 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 everyletbinding. It adds a generated@res.throwsattribute listing each exception's readable name and identity, and the inferred signature keeps it next to@throws. The new module iscompiler/ml/throws_attribute.ml.The identity is the path of the defining source file as the compiler was given it (absolute in a rewatch build), without the extension, plus the exception's name, as
src/Lib#E. It is the same through every alias,open,includeand functor, and for a module's.resand.resi. A file compiled with-no-keep-locs, as the runtime and Belt are, keeps no locations in its.cmi, so its exceptions are identified by name alone (#Undefined), also while that file itself is compiled.Exception analysis compares these identities with the constructors that catches and throws use. Messages name an exception by its full path (
Lib.Inner.F), leaving out the current file's name for its own, so the annotation a message suggests resolves. For that,Typemodrecords which module of the current file defines each exception and module.The type checker loads the modules a
@throwsnames, soDependnow counts them as dependencies, like any other use, and the build compiles them first. This is the one breaking change: a module named in@throwsthat itself depends on the annotating module is now a dependency cycle.A name that is not an exception in scope gets the new warning 113 (on by default, not an error, once per name) and is listed as written. The
@throwspayload may be one name, or an array, tuple orlist{...}of names.Known limits: a rebinding (
exception Mine = Lib.E) is a new definition, so catchingMinedoes not catchLib.E, as on master. Exceptions with the same name in one file share an identity, as do the exceptions of two applications of one functor and same-named exceptions of-no-keep-locsfiles.Compiler:
@throwsin inferred signaturesA
letin a module without an interface used to lose its attributes in the inferred signature, so its@throwscouldn't reach other modules. That is whyStdlib.panicneeded the table.Typemod.type_structurealready copied a binding's@deprecatedinto the signature item (#8924). It now copies the@throwsattributes the same way, into the signature only. Only@throwsis copied: #9210 removed the other spellings (@throw,@raises,@raise) from reanalyze.Other attributes stay out on purpose. A doc comment is an attribute, and having it in the
.cmiwould make editing a comment recompile the module's dependents. A module with a.resiis unaffected, because its.cmiholds the interface's declarations. The test below checks that an annotated binding behind an unannotated.resiis still not reported through the signature. The.cmiformat and magic numbers are unchanged.What moved into the sources
Every stdlib and Belt declaration the table listed now carries its own annotation, in its
.resior, where a module has none, in the.res:getExn/getOrThrowfamily across Belt's collections (including the.res-only internal ones),OptionandResultBelt.Array.getExn/setExn(Assert_failure)List,Null,Nullable,Option,Result,BoolandBigInt*OrThrowJSON.parseOrThrowandstringifyAnyJsErrorthrowers/andmod(Division_by_zero)Stdlib.panicandStdlib.assertEqualThe functions #9182 found missing are annotated too: the Temporal
fromStringOrThrow, the Intl*Exnexternals,Belt.MutableStack.popOrThrow, andBelt.Map.Dict/Belt.Set.DictgetOrThrow.One correction: the old table said
assertEqualthrowsJsExn, but it is implemented withassert(false), which throwsAssert_failure. The annotation now saysAssert_failure. The two payload-less@throwsinStdlib_JSON.resnow nameJsExn.The only change to generated JavaScript is the line number inside
assertEqual'sAssert_failureinStdlib.mjs/Stdlib.cjs, which moved because a line was added above it.I deliberately left unannotated the functions that throw only for some arguments and whose names don't say so: Temporal constructors and arithmetic,
Int.rangewith step 0, andDate.toTemporalInstanton an invalid date. Annotating them would flag every call to them. The%operator, the same primitive asmod, was never in the table, and I've left it as it was.exn_lib.mlis deleted, along with the Yojson stub, its test and the emptyBsJson.res. Calls to bs-json or Yojson functions are reported only if those libraries annotate their declarations.Guard
tests/analysis_tests/tests-reanalyze/checkThrowsAnnotations.mjsruns at the start of the reanalyzetest.sh. It fails when a stdlib or Belt value named*OrThrowor*Exnhas no@throws(...)with a payload. It checks the module's.resi, or everyletand external of a.resthat has no interface.JsError.toJsExnis allowlisted because it converts a value and throws nothing. Removing a single annotation makes the guard fail.Tests
src/exception/ThrowsDecl.res,ThrowsIface.res/.resiandThrowsDeclCalls.resare new. Calls from another module to an annotated external, a nested external, an annotated.resilet(whose.resbinding is unannotated), a.resiexternal, and a module type'sletreached through a functor and a first-class module are reported. So are calls made through a pipe, an alias,openandinclude.callViaLetIncludedcalls an annotatedletin a.reswithout an interface, through aninclude, so the values table can't see it. It is reported only because of the typemod change.callImplOnlyIncludedshows that a.resiwithout@throwsstill wins over an annotated.resbinding.StdlibTest.resandBeltTest.reskeep the cases from the first version of this PR. They also coverpanicandassertEqual, which reach calls through the new signature attributes, plusJsError.RangeError.throwWithMessage,List.headOrThrow,Bool.fromStringOrThrow,Nullable.getOrThrow,JSON.stringifyAny,Belt.Array.getExnandBelt.MutableQueue.popOrThrow.ThrowsLibExn.res/ThrowsLibExnCalls.res,ThrowsErrors.res/ThrowsRepo.res/ThrowsRepoCalls.resandThrowsReexport.rescover exception names: a library's own exception caught by its qualified name, throughopen, an alias, a rebind and aninclude; a caller's ownEnot catching the library'sE; a@throwsnaming a third module's exception; and a binding's own@throwswritten afteropenor through an alias.UseScalls through a functor parameter, andcatchReboundshows the rebinding limit.ThrowsScopes.res(withThrowsIfaceOpen.res/.resiandThrowsAlias.res) covers an interface whose@throwscomes after anopen, an alias of an alias in another file, an include of an include, a functor body's own exception, alist{...}payload, andLazy.Undefinedfrom the runtime (no locations).uncaughtNestedanduncaughtLocalinThrowsLibExnCalls.respin the full names in messages, andannotatedLocalfollows the suggestion.tests/build_tests/super_errors/fixtures/throws_unbound_warning.resshows warning 113 for an unknown name and for a constructor that is not an exception, once for a destructuringlet, and none for a payload-less@throwsor under@warning("-113").tests/build_tests/throws_dependencybuilds a module that names another only in@throws; before theDependchange the build order left the name unresolved.ExnPayloadGuard.restakes overTestYojson.res's case: catching an exception with a payload pattern and a guard, using its own exception.🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gGhHjzBTXqSo8Dckpb