Skip to content

Commit

Permalink
flambda-backend: Remove var_constraint (#1880)
Browse files Browse the repository at this point in the history
* Remove [var_constraint], which was redundant

* bootstrap
  • Loading branch information
goldfirere authored Oct 2, 2023
1 parent b1962fa commit 5e50edf
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 27 deletions.
Binary file modified boot/ocamlc
Binary file not shown.
Binary file modified boot/ocamllex
Binary file not shown.
17 changes: 2 additions & 15 deletions 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 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 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

0 comments on commit 5e50edf

Please sign in to comment.