You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9b3d665
Browse filesBrowse the repository at this point in the historyBrowse files
Read @throws from library declarations in exception analysis
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. The type checker keeps a declaration's attributes
in the `.cmi`, so an external or an interface `let` carries its `@throws`
to calls in other modules and packages, through aliases, `open`,
`include`, functors and first-class modules. The stdlib and Belt now
declare what their throwing functions throw, and the table keeps only
`Stdlib.panic` and `Stdlib.assertEqual`, whose `let`s in Stdlib.res (no
interface) don't keep attributes in the signature, and the Yojson stub
the tests use. 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`) when `f` is in the values table
throws(`f`) = declared(`f`) ∪ table(`f`) otherwise
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: What happens to bs-json users? The bs-json entries are gone, so
calls to `Json.Decode` functions are no longer reported until the library
annotates them; no test covered those entries.
Yojson stays because the tests use an unannotated stub of it.
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>
- Exception analysis reads `@throws` from library and external declarations, including third-party ones, instead of a built-in list of stdlib and Belt functions, which now declare what they throw.
0 commit comments