Skip to content

Commit

Permalink
Inline Ctype.path_and_expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
rtjoa committed Dec 27, 2024
1 parent f2fba07 commit 19f511f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
9 changes: 0 additions & 9 deletions typing/ctype.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2073,15 +2073,6 @@ let try_expand_safe_opt env ty =
with Escape _ ->
Btype.backtrack snap; raise Cannot_expand

let path_and_expansion env ty =
match try_expand_safe_opt env ty with
| ty' ->
begin match get_desc ty with
| Tconstr (path, _, _) -> Some (path, ty')
| _ -> Misc.fatal_error "Ctype.path_and_expansion"
end
| exception Cannot_expand -> None

let expand_head_opt env ty =
try try_expand_head try_expand_safe_opt env ty with Cannot_expand -> ty

Expand Down
3 changes: 0 additions & 3 deletions typing/ctype.mli
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,6 @@ val apply:
val try_expand_once_opt: Env.t -> type_expr -> type_expr
val try_expand_safe_opt: Env.t -> type_expr -> type_expr

val path_and_expansion: Env.t -> type_expr -> (Path.t * type_expr) option
(** Return an option instead of raising, and gives the path of the input type *)

val expand_head_once: Env.t -> type_expr -> type_expr
val expand_head: Env.t -> type_expr -> type_expr
val expand_head_opt: Env.t -> type_expr -> type_expr
Expand Down
14 changes: 10 additions & 4 deletions typing/typedecl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2093,10 +2093,16 @@ let check_unboxed_recursion ~abs_env env loc path0 ty0 to_check =
| _ -> ()
in
let rec expand parents trace ty =
match Ctype.path_and_expansion env ty with
| Some (path, ty') ->
expand (Path.Set.add path parents) (Expands_to (ty, ty') :: trace) ty'
| None ->
match Ctype.try_expand_safe_opt env ty with
| ty' ->
begin match get_desc ty with
| Tconstr (path, _, _) ->
expand (Path.Set.add path parents) (Expands_to (ty, ty') :: trace) ty'
| _ ->
(* Only [Tconstr]s can be expanded *)
Misc.fatal_error "Typedecl.check_unboxed_recursion"
end
| exception Ctype.Cannot_expand ->
parents, trace, ty
in
let rec visit parents trace ty =
Expand Down

0 comments on commit 19f511f

Please sign in to comment.