diff --git a/analysis/src/dune b/analysis/src/dune index d5d073ea1e2..e9a8282c853 100644 --- a/analysis/src/dune +++ b/analysis/src/dune @@ -13,5 +13,4 @@ lsp rescript_printer rescript_parser - outcome_printer reanalyze)) diff --git a/compiler/backend/matching_polyfill.ml b/compiler/backend/matching_polyfill.ml deleted file mode 100644 index 723b7dd4a9e..00000000000 --- a/compiler/backend/matching_polyfill.ml +++ /dev/null @@ -1,49 +0,0 @@ -(* Copyright (C) 2020- Hongbo Zhang, Authors of ReScript - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -(** - Note it is a bit tricky when there is unbound var, - its type will be Tvar which is too complicated to support subtyping -*) -let variant_is_subtype (env : Env.t) (row_desc : Types.row_desc) - (ty : Types.type_expr) : bool = - match row_desc with - | { - row_closed = true; - row_fixed = _; - row_fields = (name, (Rabsent | Rpresent None)) :: rest; - } -> - if Ext_string.is_valid_hash_number name then - Ext_list.for_all rest (function - | name, (Rabsent | Rpresent None) -> - Ext_string.is_valid_hash_number name - | _ -> false) - && Typeopt.is_base_type env ty Predef.path_int - else - Ext_list.for_all rest (function - | name, (Rabsent | Rpresent None) -> - not (Ext_string.is_valid_hash_number name) - | _ -> false) - && Typeopt.is_base_type env ty Predef.path_string - | _ -> false diff --git a/compiler/backend/matching_polyfill.mli b/compiler/backend/matching_polyfill.mli deleted file mode 100644 index 81b1dd433dc..00000000000 --- a/compiler/backend/matching_polyfill.mli +++ /dev/null @@ -1,25 +0,0 @@ -(* Copyright (C) 2020 - Hongbo Zhang, Authors of ReScript - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -val variant_is_subtype : Env.t -> Types.row_desc -> Types.type_expr -> bool diff --git a/compiler/bsc/dune b/compiler/bsc/dune index 77878ff1c54..4176c777793 100644 --- a/compiler/bsc/dune +++ b/compiler/bsc/dune @@ -37,7 +37,6 @@ depends flow_parser gentype - outcome_printer rescript_printer rescript_parser unix)) diff --git a/compiler/bsc/rescript_compiler_driver.ml b/compiler/bsc/rescript_compiler_driver.ml index 76524c0ced0..ef00675b6cd 100644 --- a/compiler/bsc/rescript_compiler_driver.ml +++ b/compiler/bsc/rescript_compiler_driver.ml @@ -56,13 +56,11 @@ let set_abs_input_name sourcefile = in Loc_report.set_input_name sourcefile; sourcefile -let setup_outcome_printer () = Lazy.force Res_outcome_printer.setup let setup_runtime_path path = Runtime_package.set_path path let process_file sourcefile ppf = (* The input name must identify the source when writing the binary AST. *) - setup_outcome_printer (); Error_message_utils_support.setup (); let kind = Ext_file_extensions.classify_input @@ -546,7 +544,6 @@ let file_level_flags_handler (e : Parsetree.expression option) = on a first request. *) let () = Bs_conditional_initial.setup_env (); - setup_outcome_printer (); Error_message_utils_support.install_parser (); let flags = "flags" in Ast_config.add_structure flags file_level_flags_handler; diff --git a/compiler/dune b/compiler/dune index ba5883d4643..8788286e0ac 100644 --- a/compiler/dune +++ b/compiler/dune @@ -10,7 +10,6 @@ gentype jsoo jsx - outcome_printer sync syntax_cli typing) diff --git a/compiler/jsoo/dune b/compiler/jsoo/dune index 0e774b16c6d..2c229afd26d 100644 --- a/compiler/jsoo/dune +++ b/compiler/jsoo/dune @@ -14,5 +14,4 @@ rescript_parser typing gentype - outcome_printer js_of_ocaml)) diff --git a/compiler/jsoo/jsoo_playground_main.ml b/compiler/jsoo/jsoo_playground_main.ml index 0b0a0bc5663..c4e39ebbedb 100644 --- a/compiler/jsoo/jsoo_playground_main.ml +++ b/compiler/jsoo/jsoo_playground_main.ml @@ -228,8 +228,7 @@ end let () = Bs_conditional_initial.setup_env (); (Clflags.current ()).binary_annotations := false; - (Clflags.current ()).color := Some Always; - Lazy.force Res_outcome_printer.setup + (Clflags.current ()).color := Some Always let error_of_exn e = match Loc_report.error_of_exn e with diff --git a/compiler/outcome_printer/dune b/compiler/outcome_printer/dune deleted file mode 100644 index 5e9da39e157..00000000000 --- a/compiler/outcome_printer/dune +++ /dev/null @@ -1,11 +0,0 @@ -; Prints the type checker's outcome trees in ReScript syntax. It reads the -; FFI details of externals, so it cannot live in the printer library. - -(library - (name outcome_printer) - (flags - (:standard -open Rescript_ast -open Rescript_printer)) - (wrapped false) - (instrumentation - (backend bisect_ppx)) - (libraries typing rescript_printer)) diff --git a/compiler/backend/bs_conditional_initial.ml b/compiler/typing/bs_conditional_initial.ml similarity index 76% rename from compiler/backend/bs_conditional_initial.ml rename to compiler/typing/bs_conditional_initial.ml index 98276afcf0a..bedf9d2d869 100644 --- a/compiler/backend/bs_conditional_initial.ml +++ b/compiler/typing/bs_conditional_initial.ml @@ -25,17 +25,8 @@ let setup_env () = Env.Persistent_signature.load := Bs_cmi_load.load_cmi; Build_file_store.set_disk_reader Bs_cmi_load.read_file; - Matching.make_test_sequence_variant_constant := - Polyvar_pattern_match.make_test_sequence_variant_constant; - Matching.call_switcher_variant_constant := - Polyvar_pattern_match.call_switcher_variant_constant; - Matching.call_switcher_variant_constr := - Polyvar_pattern_match.call_switcher_variant_constr; - Ctype.variant_is_subtype := Matching_polyfill.variant_is_subtype; (* bsc's defaults, which differ from OCaml's in [Clflags.create]. *) - Clflags.reset (); - Parmatch.print_res_pat := Pattern_printer.print_pattern; - Printtyp.print_res_poly_identifier := Res_printer.polyvar_ident_to_string + Clflags.reset () (*; Switch.cut := 100*) (* tweakable but not very useful *) diff --git a/compiler/backend/bs_conditional_initial.mli b/compiler/typing/bs_conditional_initial.mli similarity index 100% rename from compiler/backend/bs_conditional_initial.mli rename to compiler/typing/bs_conditional_initial.mli diff --git a/compiler/typing/ctype.ml b/compiler/typing/ctype.ml index cbfae8e1521..eafeae40be1 100644 --- a/compiler/typing/ctype.ml +++ b/compiler/typing/ctype.ml @@ -251,7 +251,6 @@ let unification_settings = let umode () = (Domain.DLS.get unification_settings).mode let generate_equations () = (Domain.DLS.get unification_settings).equations let assume_injective () = (Domain.DLS.get unification_settings).injective -let variant_is_subtype = ref (fun _env _row _p1 -> false) let set_mode_pattern ~generate ~injective f = let old_unification_mode = !(umode ()) and old_gen = !(generate_equations ()) @@ -3639,6 +3638,81 @@ type constructor_coercion = | Fails_with of subtype_context | Fails_unexplained +(* We use the expand_head_opt version of expand_head to get access + to the manifest type of private abbreviations. *) +let rec get_unboxed_type_representation env ty fuel = + if fuel < 0 then None + else + let ty = repr (expand_head_opt env ty) in + match ty.desc with + | Tconstr (p, args, _) -> ( + match Env.find_type p env with + | exception Not_found -> Some ty + | {type_representation = Boxed} -> Some ty + | { + type_params; + type_kind = + ( Type_record ([{ld_type = ty2; _}], _) + | Type_variant ([{cd_args = Cstr_tuple [ty2]; _}], _) + | Type_variant ([{cd_args = Cstr_record [{ld_type = ty2; _}]; _}], _) ); + } -> + get_unboxed_type_representation env + (apply env type_params ty2 args) + (fuel - 1) + | {type_kind = Type_abstract} -> + None + (* This case can occur when checking a recursive unboxed type + declaration. *) + | _ -> assert false (* only the above can be unboxed *)) + | _ -> Some ty + +let get_unboxed_type_representation env ty = + (* Do not give too much fuel: PR#7424 *) + get_unboxed_type_representation env ty 100 + +(* Whether a closed polymorphic variant whose constructors have no payload is + a subtype of [ty]: of int when all constructors are numbers (#1, #2), of + string when none is. A row with type variables is not supported. *) +let variant_is_subtype env (row_desc : row_desc) (ty : type_expr) = + let is_base_type base_ty_path = + let ty = expand_head_opt env (correct_levels ty) in + let ty = + match ty.desc with + | Tconstr (p, _, _) -> ( + match Env.find_type p env with + | {type_representation = Unboxed} -> ( + match get_unboxed_type_representation env ty with + | None -> ty + | Some ty2 -> ty2) + | _ -> ty + | exception Not_found -> ty) + | _ -> ty + in + match ty.desc with + | Tconstr (p, _, _) -> Path.same p base_ty_path + | _ -> false + in + match row_desc with + | {row_closed = true; row_fields = (name, (Rabsent | Rpresent None)) :: rest} + -> + if Ext_string.is_valid_hash_number name then + List.for_all + (function + | name, (Rabsent | Rpresent None) -> + Ext_string.is_valid_hash_number name + | _ -> false) + rest + && is_base_type Predef.path_int + else + List.for_all + (function + | name, (Rabsent | Rpresent None) -> + not (Ext_string.is_valid_hash_number name) + | _ -> false) + rest + && is_base_type Predef.path_string + | _ -> false + let rec subtype_rec env trace t1 t2 cstrs = let t1 = repr t1 in let t2 = repr t2 in @@ -4058,7 +4132,7 @@ let rec subtype_rec env trace t1 t2 cstrs = | Error _ -> (trace, t1, t2, !(current_univar_pairs ()), None) :: cstrs) | _ -> (trace, t1, t2, !(current_univar_pairs ()), None) :: cstrs) - | Tvariant v, _ when !variant_is_subtype env (row_repr v) t2 -> cstrs + | Tvariant v, _ when variant_is_subtype env (row_repr v) t2 -> cstrs | Tpoly (u1, []), Tpoly (u2, []) -> subtype_rec env trace u1 u2 cstrs | Tpoly (u1, tl1), Tpoly (u2, []) -> let _, u1' = instance_poly ~fixed:false tl1 u1 in @@ -4586,35 +4660,3 @@ let get_arity env typ = module For_test = struct let previous_env_is_empty () = !(previous_env ()) == Env.empty end - -(* We use the expand_head_opt version of expand_head to get access - to the manifest type of private abbreviations. *) -let rec get_unboxed_type_representation env ty fuel = - if fuel < 0 then None - else - let ty = repr (expand_head_opt env ty) in - match ty.desc with - | Tconstr (p, args, _) -> ( - match Env.find_type p env with - | exception Not_found -> Some ty - | {type_representation = Boxed} -> Some ty - | { - type_params; - type_kind = - ( Type_record ([{ld_type = ty2; _}], _) - | Type_variant ([{cd_args = Cstr_tuple [ty2]; _}], _) - | Type_variant ([{cd_args = Cstr_record [{ld_type = ty2; _}]; _}], _) ); - } -> - get_unboxed_type_representation env - (apply env type_params ty2 args) - (fuel - 1) - | {type_kind = Type_abstract} -> - None - (* This case can occur when checking a recursive unboxed type - declaration. *) - | _ -> assert false (* only the above can be unboxed *)) - | _ -> Some ty - -let get_unboxed_type_representation env ty = - (* Do not give too much fuel: PR#7424 *) - get_unboxed_type_representation env ty 100 diff --git a/compiler/typing/ctype.mli b/compiler/typing/ctype.mli index 06075c288d0..d60e3a42eb9 100644 --- a/compiler/typing/ctype.mli +++ b/compiler/typing/ctype.mli @@ -344,9 +344,6 @@ val package_subtype : bool) ref -val variant_is_subtype : - (Env.t -> Types.row_desc -> Types.type_expr -> bool) ref - val get_arity : Env.t -> type_expr -> int option module For_test : sig diff --git a/compiler/typing/matching.ml b/compiler/typing/matching.ml index 9d544203da7..6c905efa1bd 100644 --- a/compiler/typing/matching.ml +++ b/compiler/typing/matching.ml @@ -1987,9 +1987,6 @@ let as_interval_ranges fail low high l = | None -> as_interval_nofail l | Some act -> as_interval_canfail act low high l ) -let as_interval fail low high l = - as_interval_ranges fail low high (List.map (fun (i, act) -> (i, i, act)) l) - let call_switcher_ranges fail arg low high range_lambda_list = let edges, (cases, actions) = as_interval_ranges fail low high range_lambda_list @@ -2403,49 +2400,6 @@ let combine_constructor loc arg ex_pat cstr partial ctx def let lambda1 = lower_constructor_matching_plan ~loc ~arg plan in (lambda1, jumps_union local_jumps total1) -let make_test_sequence_variant_constant fail arg int_lambda_list = - let _, (cases, actions) = - as_interval fail int32_low int32_high - (List.map (fun (a, (_, c)) -> (a, c)) int_lambda_list) - in - Switch.test_sequence arg cases actions - -let call_switcher_variant_constant fail arg int_lambda_list = - call_switcher fail arg int32_low int32_high - (List.map (fun (a, (_, c)) -> (a, c)) int_lambda_list) - -let call_switcher_variant_constr loc fail arg int_lambda_list = - let v = Ident.create "variant" in - let_ Alias v - (prim ~primitive:(Pfield (0, Fld_poly_var_tag)) ~args:[arg] loc) - (call_switcher fail (var v) int32_low int32_high - (List.map (fun (a, (_, c)) -> (a, c)) int_lambda_list)) - -let call_switcher_variant_constant : - (Lambda.t option -> - Lambda.t -> - (int * (string * Lambda.t)) list -> - Lambda.t) - ref = - ref call_switcher_variant_constant - -let call_switcher_variant_constr : - (Location.t -> - Lambda.t option -> - Lambda.t -> - (int * (string * Lambda.t)) list -> - Lambda.t) - ref = - ref call_switcher_variant_constr - -let make_test_sequence_variant_constant : - (Lambda.t option -> - Lambda.t -> - (int * (string * Lambda.t)) list -> - Lambda.t) - ref = - ref make_test_sequence_variant_constant - let combine_variant loc row arg partial ctx def (tag_lambda_list, total1, _pats) = let row = Btype.row_repr row in @@ -2484,17 +2438,23 @@ let combine_variant loc row arg partial ctx def (tag_lambda_list, total1, _pats) test_int_or_block arg act1 act2 | _, [] -> (* One can compare integers and pointers *) - !make_test_sequence_variant_constant fail arg consts + Polyvar_pattern_match.make_test_sequence_variant_constant fail arg + consts | [], _ -> ( - let lam = !call_switcher_variant_constr loc fail arg nonconsts in + let lam = + Polyvar_pattern_match.call_switcher_variant_constr loc fail arg + nonconsts + in (* One must not dereference integers *) match fail with | None -> lam | Some fail -> test_int_or_block arg fail lam) | _, _ -> - let lam_const = !call_switcher_variant_constant fail arg consts + let lam_const = + Polyvar_pattern_match.call_switcher_variant_constant fail arg consts and lam_nonconst = - !call_switcher_variant_constr loc fail arg nonconsts + Polyvar_pattern_match.call_switcher_variant_constr loc fail arg + nonconsts in test_int_or_block arg lam_const lam_nonconst) in diff --git a/compiler/typing/matching.mli b/compiler/typing/matching.mli index 9f00480dd7b..b7dfecf700b 100644 --- a/compiler/typing/matching.mli +++ b/compiler/typing/matching.mli @@ -17,22 +17,6 @@ open Typedtree -val call_switcher_variant_constant : - (Lambda.t option -> Lambda.t -> (int * (string * Lambda.t)) list -> Lambda.t) - ref - -val call_switcher_variant_constr : - (Location.t -> - Lambda.t option -> - Lambda.t -> - (int * (string * Lambda.t)) list -> - Lambda.t) - ref - -val make_test_sequence_variant_constant : - (Lambda.t option -> Lambda.t -> (int * (string * Lambda.t)) list -> Lambda.t) - ref - (* A case's right-hand side. The guard is kept apart from the body until the match compiler knows what it falls through to; it is not encoded as a term to be recognized by shape later. *) diff --git a/compiler/typing/oprint.ml b/compiler/typing/oprint.ml deleted file mode 100644 index cedc30ca3db..00000000000 --- a/compiler/typing/oprint.ml +++ /dev/null @@ -1,30 +0,0 @@ -(**************************************************************************) -(* *) -(* OCaml *) -(* *) -(* Projet Cristal, INRIA Rocquencourt *) -(* *) -(* Copyright 2002 Institut National de Recherche en Informatique et *) -(* en Automatique. *) -(* *) -(* All rights reserved. This file is distributed under the terms of *) -(* the GNU Lesser General Public License version 2.1, with the *) -(* special exception on linking described in the file LICENSE. *) -(* *) -(**************************************************************************) - -(* Printers for outcome trees, used by [Printtyp]. The ReScript printer lives in - syntax/printer, which depends on this library, so it is installed into - these hooks by [Res_outcome_printer.setup]. *) - -open Outcometree - -let not_set_up _ _ = failwith "Oprint: Res_outcome_printer.setup was not run" - -let out_type : (Format.formatter -> out_type -> unit) ref = ref not_set_up -let out_module_type : (Format.formatter -> out_module_type -> unit) ref = - ref not_set_up -let out_sig_item : (Format.formatter -> out_sig_item -> unit) ref = - ref not_set_up -let out_signature : (Format.formatter -> out_sig_item list -> unit) ref = - ref not_set_up diff --git a/compiler/typing/oprint.mli b/compiler/typing/oprint.mli deleted file mode 100644 index 8f3b949ce02..00000000000 --- a/compiler/typing/oprint.mli +++ /dev/null @@ -1,22 +0,0 @@ -(**************************************************************************) -(* *) -(* OCaml *) -(* *) -(* Projet Cristal, INRIA Rocquencourt *) -(* *) -(* Copyright 2002 Institut National de Recherche en Informatique et *) -(* en Automatique. *) -(* *) -(* All rights reserved. This file is distributed under the terms of *) -(* the GNU Lesser General Public License version 2.1, with the *) -(* special exception on linking described in the file LICENSE. *) -(* *) -(**************************************************************************) - -open Format -open Outcometree - -val out_type : (formatter -> out_type -> unit) ref -val out_module_type : (formatter -> out_module_type -> unit) ref -val out_sig_item : (formatter -> out_sig_item -> unit) ref -val out_signature : (formatter -> out_sig_item list -> unit) ref diff --git a/compiler/typing/outcometree.ml b/compiler/typing/outcometree.ml index 15e96a7a382..10446d1b488 100644 --- a/compiler/typing/outcometree.ml +++ b/compiler/typing/outcometree.ml @@ -16,10 +16,8 @@ (* Module [Outcometree]: printable representation of types and signature items *) -(* [Printtyp] builds these trees. They are printed through the hooks - [Oprint.out_type], [Oprint.out_sig_item], - [Oprint.out_signature] and related refs, which bsc sets to the ReScript - printer through [Res_outcome_printer.setup]. *) +(* [Printtyp] builds these trees, and [Res_outcome_printer] prints them in + ReScript syntax. *) type out_ident = | Oide_apply of out_ident * out_ident diff --git a/compiler/typing/parmatch.ml b/compiler/typing/parmatch.ml index 048658840b5..d0fa1858dc8 100644 --- a/compiler/typing/parmatch.ml +++ b/compiler/typing/parmatch.ml @@ -415,9 +415,6 @@ let get_type_path ty tenv = (* Values as patterns pretty printer *) (*************************************) -let print_res_pat : (Typedtree.pattern -> string) ref = - ref (fun _ -> assert false) - open Format let is_cons = function @@ -2110,7 +2107,7 @@ let do_check_partial ?partial_match_warning_hint ~pred exhaust loc casel pss = try let buf = Buffer.create 16 in Buffer.add_string buf "| "; - Buffer.add_string buf (!print_res_pat v); + Buffer.add_string buf (Pattern_printer.print_pattern v); (match check_partial_all v casel with | None -> () | Some _ -> diff --git a/compiler/typing/parmatch.mli b/compiler/typing/parmatch.mli index d7ad3627972..bb63c440ad2 100644 --- a/compiler/typing/parmatch.mli +++ b/compiler/typing/parmatch.mli @@ -23,8 +23,6 @@ val pretty_pat : pattern -> unit val pretty_line : pattern list -> unit val pretty_matrix : pattern list list -> unit -val print_res_pat : (Typedtree.pattern -> string) ref - val omega : pattern val omegas : int -> pattern list val omega_list : 'a list -> pattern list diff --git a/compiler/typing/printtyp.ml b/compiler/typing/printtyp.ml index d8e775fbe42..77f637fe25b 100644 --- a/compiler/typing/printtyp.ml +++ b/compiler/typing/printtyp.ml @@ -27,9 +27,6 @@ open Outcometree type printing_context = {inlined_types: type_inlined_type list} -let print_res_poly_identifier : (string -> string) ref = - ref (fun _ -> assert false) - (* Print a long identifier *) let rec longident ppf = function @@ -988,7 +985,8 @@ and tree_of_constraints ~printing_context params = else list) params [] -let typexp sch ppf ty = !Oprint.out_type ppf (tree_of_typexp sch ty) +let typexp sch ppf ty = + Res_outcome_printer.print_out_type ppf (tree_of_typexp sch ty) let type_expr ppf ty = typexp false ppf ty @@ -1007,11 +1005,12 @@ let tree_of_type_declaration id decl rs = Osig_type (tree_of_type_decl id decl, tree_of_rec rs) let type_declaration id ppf decl = - !Oprint.out_sig_item ppf (tree_of_type_declaration id decl Trec_not) + Res_outcome_printer.print_out_sig_item ppf + (tree_of_type_declaration id decl Trec_not) let constructor_arguments ppf a = let tys = tree_of_constructor_arguments a in - !Oprint.out_type ppf (Otyp_tuple tys) + Res_outcome_printer.print_out_type ppf (Otyp_tuple tys) (* Print an extension declaration *) @@ -1063,7 +1062,8 @@ let tree_of_extension_constructor id ext es = Osig_typext (ext, es) let extension_constructor id ppf ext = - !Oprint.out_sig_item ppf (tree_of_extension_constructor id ext Text_first) + Res_outcome_printer.print_out_sig_item ppf + (tree_of_extension_constructor id ext Text_first) (* Print a value declaration *) @@ -1078,7 +1078,7 @@ let tree_of_value_description id decl = Osig_value {oval_name = id; oval_type = ty; oval_prim; oval_attributes = []} let value_description id ppf decl = - !Oprint.out_sig_item ppf (tree_of_value_description id decl) + Res_outcome_printer.print_out_sig_item ppf (tree_of_value_description id decl) (* Print a module type *) @@ -1192,14 +1192,16 @@ and tree_of_modtype_declaration id decl = and tree_of_module id ~ellipsis mty rs = Osig_module (Ident.name id, tree_of_modtype ~ellipsis mty, tree_of_rec rs) -let modtype ppf mty = !Oprint.out_module_type ppf (tree_of_modtype mty) +let modtype ppf mty = + Res_outcome_printer.print_out_module_type ppf (tree_of_modtype mty) let modtype_declaration id ppf decl = - !Oprint.out_sig_item ppf (tree_of_modtype_declaration id decl) + Res_outcome_printer.print_out_sig_item ppf + (tree_of_modtype_declaration id decl) (* Print a signature body (used by -i when compiling a .ml) *) let print_signature ppf tree = - fprintf ppf "@[%a@]" !Oprint.out_signature tree + fprintf ppf "@[%a@]" Res_outcome_printer.print_out_signature tree let signature ppf sg = fprintf ppf "%a" print_signature (tree_of_signature sg) @@ -1292,9 +1294,10 @@ let print_tags ppf fields = match fields with | [] -> () | (t, _) :: fields -> - fprintf ppf "%s" (!print_res_poly_identifier t); + fprintf ppf "%s" (Res_printer.polyvar_ident_to_string t); List.iter - (fun (t, _) -> fprintf ppf ",@ %s" (!print_res_poly_identifier t)) + (fun (t, _) -> + fprintf ppf ",@ %s" (Res_printer.polyvar_ident_to_string t)) fields let has_explanation t3 t4 = @@ -1437,8 +1440,8 @@ let explanation unif t3 t4 ppf = their payload types are incompatible.@,\ Make sure the payload types for @{%s@} match exactly in both \ polymorphic variants." - (!print_res_poly_identifier l1) - (!print_res_poly_identifier l1) + (Res_printer.polyvar_ident_to_string l1) + (Res_printer.polyvar_ident_to_string l1) | _ -> ()) | _ -> () diff --git a/compiler/typing/printtyp.mli b/compiler/typing/printtyp.mli index 39f707a1c3e..1f7387408f4 100644 --- a/compiler/typing/printtyp.mli +++ b/compiler/typing/printtyp.mli @@ -22,7 +22,6 @@ open Outcometree type printing_context = {inlined_types: type_inlined_type list} (** Tracks things like inlined records, to help with printing. *) -val print_res_poly_identifier : (string -> string) ref val longident : formatter -> Longident.t -> unit val ident : formatter -> Ident.t -> unit val path : formatter -> Path.t -> unit diff --git a/compiler/outcome_printer/res_outcome_printer.ml b/compiler/typing/res_outcome_printer.ml similarity index 99% rename from compiler/outcome_printer/res_outcome_printer.ml rename to compiler/typing/res_outcome_printer.ml index da8ddeffe8a..51794ab89ca 100644 --- a/compiler/outcome_printer/res_outcome_printer.ml +++ b/compiler/typing/res_outcome_printer.ml @@ -954,12 +954,3 @@ let print_out_signature fmt signature = let print_out_module_type fmt out_module_type = pp_doc fmt (print_out_module_type_doc out_module_type) - -(* Not supported in ReScript *) -(* Oprint.out_class_type *) -let setup = - lazy - (Oprint.out_type := print_out_type; - Oprint.out_module_type := print_out_module_type; - Oprint.out_sig_item := print_out_sig_item; - Oprint.out_signature := print_out_signature) diff --git a/compiler/outcome_printer/res_outcome_printer.mli b/compiler/typing/res_outcome_printer.mli similarity index 65% rename from compiler/outcome_printer/res_outcome_printer.mli rename to compiler/typing/res_outcome_printer.mli index f874ce66b6d..d57b5eabe7a 100644 --- a/compiler/outcome_printer/res_outcome_printer.mli +++ b/compiler/typing/res_outcome_printer.mli @@ -7,7 +7,12 @@ * * In general it represent messages to show results or errors to the user. *) -val setup : unit lazy_t [@@live] +val print_out_type : Format.formatter -> Outcometree.out_type -> unit +val print_out_module_type : + Format.formatter -> Outcometree.out_module_type -> unit +val print_out_sig_item : Format.formatter -> Outcometree.out_sig_item -> unit +val print_out_signature : + Format.formatter -> Outcometree.out_sig_item list -> unit (* Needed for e.g. the playground to print typedtree data *) val print_out_type_doc : Outcometree.out_type -> Res_doc.t [@@live] diff --git a/compiler/typing/switch.ml b/compiler/typing/switch.ml index 17172c7b846..7b783a2eca2 100644 --- a/compiler/typing/switch.ml +++ b/compiler/typing/switch.ml @@ -705,18 +705,3 @@ let zyva lh arg cases actions = let actions = actions.act_get_shared () in let hs, actions = abstract_shared actions in hs (do_zyva lh arg cases actions) - -and test_sequence arg cases actions = - assert (Array.length cases > 0); - let actions = actions.act_get_shared () in - let hs, actions = abstract_shared actions in - let old_ok = !(ok_inter ()) in - ok_inter () := false; - if !(ok_inter ()) <> old_ok then Hashtbl.clear (cache ()); - let s = {cases; actions = Array.map (fun act _ -> act) actions} in - (* - Printf.eprintf "SEQUENCE: %B\n" !ok_inter ; - pcases stderr cases ; - prerr_endline "" ; -*) - hs (c_test {arg; off = 0} s) diff --git a/compiler/typing/switch.mli b/compiler/typing/switch.mli index 3bac8c7eaef..27208488196 100644 --- a/compiler/typing/switch.mli +++ b/compiler/typing/switch.mli @@ -64,6 +64,3 @@ val zyva : (int * int * int) array -> Lambda.t t_store -> Lambda.t - -val test_sequence : - Lambda.t -> (int * int * int) array -> Lambda.t t_store -> Lambda.t diff --git a/tests/syntax_tests/dune b/tests/syntax_tests/dune index 384f967d462..c030bc4972a 100644 --- a/tests/syntax_tests/dune +++ b/tests/syntax_tests/dune @@ -11,10 +11,4 @@ (package rescript) (enabled_if (<> %{profile} browser)) - (libraries - common - rescript_printer - rescript_parser - backend - jsx - outcome_printer)) + (libraries common rescript_printer rescript_parser backend jsx)) diff --git a/tests/syntax_tests/res_test.ml b/tests/syntax_tests/res_test.ml index 579fad17e89..a2b1cbc56c5 100644 --- a/tests/syntax_tests/res_test.ml +++ b/tests/syntax_tests/res_test.ml @@ -657,7 +657,6 @@ let () = module Outcome_printer_tests = struct let signature_to_outcome structure = - Lazy.force Res_outcome_printer.setup; (* The type checker resolves externals through this hook, which the compiler's drivers register in [Ppx_entry]. This test doesn't link it. *) Primitive.resolve_external := Ast_external.resolve; @@ -670,7 +669,7 @@ module Outcome_printer_tests = struct Typemod.type_structure env structure in signature |> Printtyp.tree_of_signature - |> !Oprint.out_signature Format.str_formatter; + |> Res_outcome_printer.print_out_signature Format.str_formatter; Format.flush_str_formatter () with | Typetexp.Error (_, _, err) ->