From 19f511fe942a7cb07a134e26afd2a95f9831693a Mon Sep 17 00:00:00 2001 From: Ryan Tjoa Date: Thu, 26 Dec 2024 18:51:12 -0500 Subject: [PATCH] Inline Ctype.path_and_expansion --- typing/ctype.ml | 9 --------- typing/ctype.mli | 3 --- typing/typedecl.ml | 14 ++++++++++---- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/typing/ctype.ml b/typing/ctype.ml index c36922329f0..547b8f2d62c 100644 --- a/typing/ctype.ml +++ b/typing/ctype.ml @@ -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 diff --git a/typing/ctype.mli b/typing/ctype.mli index 8f2eefd6c93..a5d3460cdd8 100644 --- a/typing/ctype.mli +++ b/typing/ctype.mli @@ -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 diff --git a/typing/typedecl.ml b/typing/typedecl.ml index 04c66f2c7cb..f597c65f5ba 100644 --- a/typing/typedecl.ml +++ b/typing/typedecl.ml @@ -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 =