Skip to content

Remove var_constraint #1880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 2, 2023
Merged
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
Binary file modified ocaml/boot/ocamlc
Binary file not shown.
Binary file modified ocaml/boot/ocamllex
Binary file not shown.
17 changes: 2 additions & 15 deletions ocaml/typing/jkind.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ module Sort = struct

let void = Const Void
let value = Const Value

let float64 = Const Float64

let some_value = Some value
Expand All @@ -59,6 +58,7 @@ module Sort = struct

let new_var () = Var (ref None)

(* Post-condition: If the result is a [Var v], then [!v] is [None]. *)
let rec get : t -> t = function
| Const _ as t -> t
| Var r as t -> begin match !r with
Expand All @@ -70,20 +70,6 @@ module Sort = struct
end
end

(* This is constant-time if [var] was just returned from a previous call to
[get]. That's because [var] will always be [None] in that case.
*)
let var_constraint : var -> const option = fun r ->
match !r with
| None -> None
| Some t -> begin
match get t with
| Const const -> Some const
| Var { contents = None } -> None
| Var _ ->
Misc.fatal_error "[get] should return [Const _] or [Var None]"
end

let default_value : t option = Some (Const Value)
let default_void : t option = Some (Const Void)
let default_float64 : t option = Some (Const Float64)
Expand Down Expand Up @@ -515,6 +501,7 @@ let sub_desc d1 d2 = match d1, d2 with
| Var v1, Var v2 -> if v1 == v2 then Equal else Not_sub
| Const _, Var _ | Var _, Const _ -> Not_sub

(* Post-condition: If the result is [Var v], then [!v] is [None]. *)
let get_internal (lay : internal) : desc = match lay with
| Any -> Const Any
| Immediate -> Const Immediate
Expand Down
5 changes: 0 additions & 5 deletions ocaml/typing/jkind.mli
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ module Sort : sig
(** A sort variable that can be unified during type-checking. *)
type var

(** Return the concrete constraint placed on the variable. This check is
constant-time if [var] was just returned from [Jkind.get].
*)
val var_constraint : var -> const option

(** Create a new sort variable that can be unified. *)
val new_var : unit -> t

Expand Down
10 changes: 3 additions & 7 deletions ocaml/typing/subst.ml
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,7 @@ let with_additional_action (config : additional_action_config) s =
| Const Immediate -> immediate
| Const Immediate64 -> immediate64
| Const Float64 -> float64
| Var var -> begin
match Jkind.Sort.var_constraint var with
| Some Void -> void
| Some Value -> value
| Some Float64 -> float64
| None -> raise(Error (loc, Unconstrained_jkind_variable))
end
| Var _ -> raise(Error (loc, Unconstrained_jkind_variable))
in
Prepare_for_saving prepare_jkind
in
Expand Down Expand Up @@ -228,6 +222,8 @@ let newpersty desc =
create_expr
desc ~level:generic_level ~scope:Btype.lowest_level ~id:!new_id

(* CR layouts: remove this. While we're still developing, though, it might
be nice to get the location of this kind of error. *)
(* We use a ref instead of passing [loc] as an argument to [typexp]
because the ref requires no modifications to the body of [typexp],
reducing the chance of merge conflicts. This location is not critical --
Expand Down