Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
553 changes: 431 additions & 122 deletions analysis/reanalyze/src/exception.ml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions analysis/reanalyze/src/exceptions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ let empty = Exn_set.empty
let from_list = Exn_set.of_list
let to_list = Exn_set.elements
let is_empty = Exn_set.is_empty
let mem = Exn_set.mem
let map = Exn_set.map
let iter = Exn_set.iter
let union = Exn_set.union

Expand Down
8 changes: 0 additions & 8 deletions analysis/reanalyze/src/exn.ml
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
type t = string

let compare = String.compare
let decode_error = "DecodeError"
let assert_failure = "Assert_failure"
let division_by_zero = "Division_by_zero"
let invalid_argument = "Invalid_argument"
let js_exn = "JsExn"
let match_failure = "Match_failure"
let not_found = "Not_found"
let from_lid lid = lid |> Longident.flatten |> String.concat "."
let from_string s = s
let to_string s = s
let yojson_json_error = "Yojson.Json_error"
let yojson_type_error = "Yojson.Basic.Util.Type_error"
8 changes: 0 additions & 8 deletions analysis/reanalyze/src/exn.mli
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
type t

val compare : t -> t -> int
val assert_failure : t
val decode_error : t
val division_by_zero : t
val from_lid : Longident.t -> t
val from_string : string -> t
val invalid_argument : t
val js_exn : t
val match_failure : t
val not_found : t
val to_string : t -> string
val yojson_json_error : t
val yojson_type_error : t
200 changes: 0 additions & 200 deletions analysis/reanalyze/src/exn_lib.ml

This file was deleted.

1 change: 1 addition & 0 deletions changes/reanalyze-throws-from-declarations.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Exception analysis reads `@throws` from library and external declarations, including third-party ones, instead of a built-in list, and a `@throws` on a `let` now reaches other modules even without an interface.
17 changes: 13 additions & 4 deletions compiler/ml/typemod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1442,11 +1442,18 @@ and type_structure funct_body anchor env sstr =
in
(* The environment keeps let-bound values without attributes, so uses
in this module do not warn. The signature carries their [deprecated]
attributes, so uses from other modules do. *)
let deprecated =
attributes, so uses from other modules do, and their [throws]
attributes, which reanalyze's exception analysis reads at calls from
other modules. Other attributes stay out: a doc comment in the .cmi
would make editing it recompile the module's dependents. *)
let signature_attributes (attrs : Parsetree.attributes) =
Builtin_attributes.deprecated_attributes attrs
@ List.filter (fun ({txt}, _) -> txt = "throws") attrs
in
let kept_attributes =
List.concat_map
(fun (vb : value_binding) ->
match Builtin_attributes.deprecated_attributes vb.vb_attributes with
match signature_attributes vb.vb_attributes with
| [] -> []
| attrs ->
List.map (fun id -> (id, attrs)) (pat_bound_idents vb.vb_pat))
Expand All @@ -1460,7 +1467,9 @@ and type_structure funct_body anchor env sstr =
let vd = Env.find_value (Pident id) newenv in
let vd =
match
List.find_opt (fun (id', _) -> Ident.same id id') deprecated
List.find_opt
(fun (id', _) -> Ident.same id id')
kept_attributes
with
| None -> vd
| Some (_, attrs) ->
Expand Down
4 changes: 4 additions & 0 deletions packages/@rescript/belt/src/Belt_Array.resi
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ let get: (t<'a>, int) => option<'a>
Throw an exception if `i` is out of range.
Otherwise return the value at index `i` in `arr`.
*/
@throws(Assert_failure)
let getExn: (t<'a>, int) => 'a

/**
Throw an exception if `i` is out of range.
Otherwise return the value at index `i` in `arr`.
*/
@throws(Assert_failure)
let getOrThrow: (t<'a>, int) => 'a

/**
Expand All @@ -68,11 +70,13 @@ let set: (t<'a>, int, 'a) => bool
/**
`setExn(arr, i, x)` throw an exception if `i` is out of range.
*/
@throws(Assert_failure)
let setExn: (t<'a>, int, 'a) => unit

/**
`setOrThrow(arr, i, x)` throw an exception if `i` is out of range.
*/
@throws(Assert_failure)
let setOrThrow: (t<'a>, int, 'a) => unit

external setUnsafe: (t<'a>, int, 'a) => unit = "%array_unsafe_set"
Expand Down
6 changes: 6 additions & 0 deletions packages/@rescript/belt/src/Belt_List.resi
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ switch Belt.List.headExn(list{}) {
}
```
*/
@throws(Not_found)
let headExn: t<'a> => 'a

/**
Expand All @@ -78,6 +79,7 @@ switch Belt.List.headOrThrow(list{}) {
}
```
*/
@throws(Not_found)
let headOrThrow: t<'a> => 'a

/**
Expand Down Expand Up @@ -110,6 +112,7 @@ switch Belt.List.tailExn(list{}) {
}
```
*/
@throws(Not_found)
let tailExn: t<'a> => t<'a>

/**
Expand All @@ -128,6 +131,7 @@ switch Belt.List.tailOrThrow(list{}) {
}
```
*/
@throws(Not_found)
let tailOrThrow: t<'a> => t<'a>

/**
Expand Down Expand Up @@ -177,6 +181,7 @@ switch abc->Belt.List.getExn(4) {
}
```
*/
@throws(Not_found)
let getExn: (t<'a>, int) => 'a

/**
Expand All @@ -197,6 +202,7 @@ switch abc->Belt.List.getOrThrow(4) {
}
```
*/
@throws(Not_found)
let getOrThrow: (t<'a>, int) => 'a

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/@rescript/belt/src/Belt_Map.resi
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ See `Belt.Map.get`

throw when `k` not exist
*/
@throws(Not_found)
let getExn: (t<'k, 'v, 'id>, 'k) => 'v

/**
Expand All @@ -354,6 +355,7 @@ See `Belt.Map.get`

throw when `k` not exist
*/
@throws(Not_found)
let getOrThrow: (t<'k, 'v, 'id>, 'k) => 'v

/* ************************************************************************** */
Expand Down
2 changes: 2 additions & 0 deletions packages/@rescript/belt/src/Belt_MapDict.resi
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ let get: (t<'k, 'a, 'id>, 'k, ~cmp: cmp<'k, 'id>) => option<'a>

let getWithDefault: (t<'k, 'a, 'id>, 'k, 'a, ~cmp: cmp<'k, 'id>) => 'a

@throws(Not_found)
let getExn: (t<'k, 'a, 'id>, 'k, ~cmp: cmp<'k, 'id>) => 'a

@throws(Not_found)
let getOrThrow: (t<'k, 'a, 'id>, 'k, ~cmp: cmp<'k, 'id>) => 'a

let checkInvariantInternal: t<_> => unit
Expand Down
2 changes: 2 additions & 0 deletions packages/@rescript/belt/src/Belt_MapInt.resi
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ let get: (t<'v>, key) => option<'v>

let getWithDefault: (t<'v>, key, 'v) => 'v

@throws(Not_found)
let getExn: (t<'v>, key) => 'v

@throws(Not_found)
let getOrThrow: (t<'v>, key) => 'v

/**
Expand Down
Loading