Skip to content

Commit

Permalink
merge fixes in type_decl
Browse files Browse the repository at this point in the history
  • Loading branch information
ccasin committed Nov 13, 2023
1 parent 8c4684d commit 911181f
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/ocaml/typing/typedecl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ let update_decls_jkind env decls =
- if -rectypes is not used, we only allow cycles in the type graph
if they go through an object or polymorphic variant type *)

let check_well_founded env loc path to_check visited ty0 =
let check_well_founded ~abs_env env loc path to_check visited ty0 =
let rec check parents trace ty =
if TypeSet.mem ty parents then begin
(*Format.eprintf "@[%a@]@." Printtyp.raw_type_expr ty;*)
Expand All @@ -1378,8 +1378,8 @@ let check_well_founded env loc path to_check visited ty0 =
| trace -> List.rev trace, false
in
if rec_abbrev
then Recursive_abbrev (Path.name path, env, reaching_path)
else Cycle_in_def (Path.name path, env, reaching_path)
then Recursive_abbrev (Path.name path, abs_env, reaching_path)
else Cycle_in_def (Path.name path, abs_env, reaching_path)
in raise (Error (loc, err))
end;
let (fini, parents) =
Expand Down Expand Up @@ -1424,7 +1424,7 @@ let check_well_founded env loc path to_check visited ty0 =
(* Will be detected by check_regularity *)
Btype.backtrack snap

let check_well_founded_manifest env loc path decl =
let check_well_founded_manifest ~abs_env env loc path decl =
if decl.type_manifest = None then () else
let args =
(* The jkinds here shouldn't matter for the purposes of
Expand All @@ -1433,7 +1433,7 @@ let check_well_founded_manifest env loc path decl =
decl.type_params
in
let visited = ref TypeMap.empty in
check_well_founded env loc path (Path.same path) visited
check_well_founded ~abs_env env loc path (Path.same path) visited
(Ctype.newconstr path args)

(* Given a new type declaration [type t = ...] (potentially mutually-recursive),
Expand All @@ -1451,7 +1451,7 @@ let check_well_founded_manifest env loc path decl =
(we don't have an example at hand where it is necessary), but we
are doing it anyway out of caution.
*)
let check_well_founded_decl env loc path decl to_check =
let check_well_founded_decl ~abs_env env loc path decl to_check =
let open Btype in
(* We iterate on all subexpressions of the declaration to check
"in depth" that no ill-founded type exists. *)
Expand All @@ -1470,7 +1470,7 @@ let check_well_founded_decl env loc path decl to_check =
{type_iterators with it_type_expr =
(fun self ty ->
if TypeSet.mem ty !checked then () else begin
check_well_founded env loc path to_check visited ty;
check_well_founded ~abs_env env loc path to_check visited ty;
checked := TypeSet.add ty !checked;
self.it_do_type_expr self ty
end)} in
Expand Down Expand Up @@ -1721,16 +1721,6 @@ let transl_type_decl env rec_flag sdecl_list =
List.map2 (fun (id, _) sdecl -> (id, sdecl.ptype_loc))
ids_list sdecl_list
in
List.iter (fun (id, decl) ->
check_well_founded_manifest new_env (List.assoc id id_loc_list)
(Path.Pident id) decl)
decls;
let to_check =
function Path.Pident id -> List.mem_assoc id id_loc_list | _ -> false in
List.iter (fun (id, decl) ->
check_well_founded_decl new_env (List.assoc id id_loc_list) (Path.Pident id)
decl to_check)
decls;
(* [check_abbrev_regularity] cannot use the new environment, as this might
result in non-termination. Instead we use a completely abstract version
of the temporary environment, giving a reason for why abbreviations
Expand All @@ -1739,6 +1729,17 @@ let transl_type_decl env rec_flag sdecl_list =
List.fold_left2
(enter_type ~abstract_abbrevs:Abstract_rec_check_regularity rec_flag)
env sdecl_list ids_list in
List.iter (fun (id, decl) ->
check_well_founded_manifest ~abs_env new_env (List.assoc id id_loc_list)
(Path.Pident id) decl)
decls;
let to_check =
function Path.Pident id -> List.mem_assoc id id_loc_list | _ -> false in
List.iter (fun (id, decl) ->
check_well_founded_decl ~abs_env new_env (List.assoc id id_loc_list)
(Path.Pident id)
decl to_check)
decls;
List.iter
(check_abbrev_regularity ~abs_env new_env id_loc_list to_check) tdecls;
(* Now that we've ruled out ill-formed types, we can perform the delayed
Expand Down Expand Up @@ -2550,7 +2551,7 @@ let check_recmod_typedecl env loc recmod_ids path decl =
(* recmod_ids is the list of recursively-defined module idents.
(path, decl) is the type declaration to be checked. *)
let to_check path = Path.exists_free recmod_ids path in
check_well_founded_decl env loc path decl to_check;
check_well_founded_decl ~abs_env:env env loc path decl to_check;
check_regularity ~abs_env:env env loc path decl to_check;
(* additional coherence check, as one might build an incoherent signature,
and use it to build an incoherent module, cf. #7851 *)
Expand Down

0 comments on commit 911181f

Please sign in to comment.