Skip to content

Commit

Permalink
Minor cleanups
Browse files Browse the repository at this point in the history
Label __POS__ argument and use raise instead of raise_notrace.
  • Loading branch information
johnridesabike committed Dec 20, 2023
1 parent 73632f1 commit fca5bac
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ let missing_keys ~fname ~stack ~ty ~keys s =
keys;
|]

let internal (file, lnum, cnum, enum) s =
let internal ~__POS__:(file, lnum, cnum, enum) s =
let s =
F.asprintf
"@[<v>Compile error.@;\
Expand Down
5 changes: 2 additions & 3 deletions lib/error.mli
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ val missing_keys :

(** {1 Internal errors.} *)

val internal : string * int * int * int -> string -> _
val internal : __POS__:string * int * int * int -> string -> _
(** Use this instead of [assert false] when an internal invariant breaks. It
indicates a bug in the compiler. The first argument is the type for
[__POS__]. *)
indicates a bug in the compiler. *)
2 changes: 1 addition & 1 deletion lib/instruct.ml
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ end = struct

let make_exits exit exits f =
match M.Exit.to_seqi exits () with
| Seq.Nil -> Error.internal __POS__ "No exits."
| Seq.Nil -> Error.internal ~__POS__ "No exits."
| Seq.Cons (hd, tl) ->
let rec aux (i, v) seq =
match seq () with
Expand Down
4 changes: 2 additions & 2 deletions lib/matching.ml
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ and merge :
| Int_keys a, Int_keys b -> Int_keys (merge_child a b)
| String_keys a, String_keys b -> String_keys (merge_child a b)
| _ ->
Error.internal __POS__
Error.internal ~__POS__
"Type error between int and string keys. This means the \
typechecker failed."
in
Expand Down Expand Up @@ -564,7 +564,7 @@ and merge :
| ( ( Wildcard _ | Optional _ | Switch _ | Nil _ | Cons _ | Nil_or_cons _
| Nest _ | End _ ),
_ ) ->
Error.internal __POS__
Error.internal ~__POS__
"Tried to merge incompatible trees. Either the typechecker failed or \
the function that constructs trees failed."

Expand Down
10 changes: 5 additions & 5 deletions lib/render.ml
Original file line number Diff line number Diff line change
Expand Up @@ -224,23 +224,23 @@ module Make (M : MONAD) (D : DATA) :

let to_int = function
| Int x -> x
| _ -> Error.internal __POS__ "Expected Int."
| _ -> Error.internal ~__POS__ "Expected Int."

let to_float = function
| Float x -> x
| _ -> Error.internal __POS__ "Expected Float."
| _ -> Error.internal ~__POS__ "Expected Float."

let to_string = function
| String x -> x
| _ -> Error.internal __POS__ "Expected String."
| _ -> Error.internal ~__POS__ "Expected String."

let to_array = function
| Array x -> x
| _ -> Error.internal __POS__ "Expected Array."
| _ -> Error.internal ~__POS__ "Expected Array."

let to_hashtbl = function
| Hashtbl x -> x
| _ -> Error.internal __POS__ "Expected Hashtbl."
| _ -> Error.internal ~__POS__ "Expected Hashtbl."

let rec equal a b =
match (a, b) with
Expand Down
13 changes: 6 additions & 7 deletions lib/typechecker.ml
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ module Type = struct

let subset_enum (type s) (module M : Set.S with type t = s) _ (a : s) (b : s)
=
if not (M.subset b a) then raise_notrace Clash
if not (M.subset b a) then raise Clash

let unify_sum ~unify ~subset mode a b =
match mode with
Expand All @@ -272,15 +272,14 @@ module Type = struct
let cases = unify mode a.cases b.cases in
a.cases <- cases;
b.cases <- cases
| `Closed, `Open -> raise_notrace Clash)
| `Closed, `Open -> raise Clash)

let rec unify mode a b =
match (!a, !b) with
| Int, Int | Float, Float | String, String -> ()
| Nullable a, Nullable b | List a, List b -> unify mode a b
| Tuple a, Tuple b -> (
try List.iter2 (unify mode) a b
with Invalid_argument _ -> raise_notrace Clash)
try List.iter2 (unify mode) a b with Invalid_argument _ -> raise Clash)
| Record a, Record b -> unify_record mode a b
| Dict (a, keys1), Dict (b, keys2) ->
let ks' = Set.String.union !keys1 !keys2 in
Expand Down Expand Up @@ -313,7 +312,7 @@ module Type = struct
a := t
| Unknown _, t -> a := t
| t, Unknown _ -> b := t
| _ -> raise_notrace Clash
| _ -> raise Clash

and unify_record mode a b =
match mode with
Expand All @@ -334,7 +333,7 @@ module Type = struct
(fun _ a b ->
match (a, b) with
| (Some a as x), Some b -> unify mode a b; x
| Some _, None -> raise_notrace Clash
| Some _, None -> raise Clash
| None, _ -> None)
!a !b

Expand All @@ -351,7 +350,7 @@ module Type = struct
match (a, b) with
| (Some _ as x), None -> x
| (Some a as x), Some b -> unify_record mode a b; x
| None, Some _ -> raise_notrace Clash
| None, Some _ -> raise Clash
| None, None -> None)
a b
|> ignore
Expand Down

0 comments on commit fca5bac

Please sign in to comment.