Skip to content

Commit e35c046

Browse files
authored
flambda-backend: Minor cleanup of kind checking in ctype (#2679)
Clean up in ctype
1 parent c4a2bad commit e35c046

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

typing/ctype.ml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,10 +2136,11 @@ type type_jkind_sub_result =
21362136
| Missing_cmi of Jkind.t * Path.t
21372137
| Failure of Jkind.t
21382138

2139-
let type_jkind_sub env ty ~check_sub =
2139+
let type_jkind_sub env ty jkind =
21402140
let shallow_check ty =
21412141
match estimate_type_jkind env ty with
2142-
| Jkind ty_jkind -> if check_sub ty_jkind then Success else Failure ty_jkind
2142+
| Jkind ty_jkind ->
2143+
if Jkind.sub ty_jkind jkind then Success else Failure ty_jkind
21432144
| TyVar (ty_jkind, ty) -> Type_var (ty_jkind, ty)
21442145
in
21452146
(* The "fuel" argument here is used because we're duplicating the loop of
@@ -2165,7 +2166,7 @@ let type_jkind_sub env ty ~check_sub =
21652166
try (Env.find_type p env).type_jkind
21662167
with Not_found -> Jkind.any ~why:(Missing_cmi p)
21672168
in
2168-
if check_sub jkind_bound
2169+
if Jkind.sub jkind_bound jkind
21692170
then Success
21702171
else if fuel < 0 then Failure jkind_bound
21712172
else begin match unbox_once env ty with
@@ -2188,8 +2189,7 @@ let type_jkind_sub env ty ~check_sub =
21882189
correct on [any].)
21892190
*)
21902191
let constrain_type_jkind ~fixed env ty jkind =
2191-
match type_jkind_sub env ty
2192-
~check_sub:(fun ty_jkind -> Jkind.sub ty_jkind jkind) with
2192+
match type_jkind_sub env ty jkind with
21932193
| Success -> Ok ()
21942194
| Type_var (ty_jkind, ty) ->
21952195
if fixed then Jkind.sub_or_error ty_jkind jkind else
@@ -2221,14 +2221,12 @@ let () =
22212221
Env.constrain_type_jkind := constrain_type_jkind
22222222

22232223
let check_type_externality env ty ext =
2224-
let check_sub ty_jkind =
2225-
Jkind.(Externality.le (get_externality_upper_bound ty_jkind) ext)
2224+
let upper_bound =
2225+
Jkind.set_externality_upper_bound (Jkind.any ~why:Dummy_jkind) ext
22262226
in
2227-
match type_jkind_sub env ty ~check_sub with
2228-
| Success -> true
2229-
| Type_var (ty_jkind, _) -> check_sub ty_jkind
2230-
| Missing_cmi _ -> false (* safe answer *)
2231-
| Failure _ -> false
2227+
match check_type_jkind env ty upper_bound with
2228+
| Ok () -> true
2229+
| Error _ -> false
22322230

22332231
let check_decl_jkind env decl jkind =
22342232
match Jkind.sub_or_error decl.type_jkind jkind with

typing/jkind.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,9 @@ let get_modal_upper_bounds jk = jk.jkind.modes_upper_bounds
701701

702702
let get_externality_upper_bound jk = jk.jkind.externality_upper_bound
703703

704+
let set_externality_upper_bound jk externality_upper_bound =
705+
{ jk with jkind = { jk.jkind with externality_upper_bound } }
706+
704707
(*********************************)
705708
(* pretty printing *)
706709

typing/jkind.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ val get_modal_upper_bounds : t -> Mode.Alloc.Const.t
279279
(** Gets the maximum mode on the externality axis for types of this jkind. *)
280280
val get_externality_upper_bound : t -> Externality.t
281281

282+
(** Computes a jkind that is the same as the input but with an updated maximum
283+
mode for the externality axis *)
284+
val set_externality_upper_bound : t -> Externality.t -> t
285+
282286
(*********************************)
283287
(* pretty printing *)
284288

0 commit comments

Comments
 (0)