From 3a125b8c3c3066a1c1974c6f264ed2793b34342e Mon Sep 17 00:00:00 2001 From: Leandro Ostera Date: Thu, 5 Nov 2020 16:59:15 +0100 Subject: [PATCH 1/9] Expose module signature when typing implementation While working on a new backend for OCaml to generate Erlang sources, I found the need to read the .cmi file back into a `Types.signature` value. @Drup spotted that I was reading the file and pointed out this value was already being read during the type checking process. A quick check at the `Typedtree.module_coercion` showed us that it would be difficul to extract the same information that is readily available in the signature value. This change will expose the signature value directly, so other backends relying on this signature information do not need to do the extra work of reading it again. --- driver/compile.ml | 2 +- driver/compile.mli | 2 +- driver/compile_common.mli | 10 +++++++--- driver/optcompile.ml | 6 ++++-- driver/optcompile.mli | 4 ++-- ocamldoc/odoc_analyse.ml | 3 ++- typing/printtyped.ml | 2 +- typing/printtyped.mli | 2 +- typing/typemod.ml | 6 +++--- typing/typemod.mli | 2 +- 10 files changed, 23 insertions(+), 16 deletions(-) diff --git a/driver/compile.ml b/driver/compile.ml index ead460368..ed395bd23 100644 --- a/driver/compile.ml +++ b/driver/compile.ml @@ -27,7 +27,7 @@ let interface ~source_file ~output_prefix = (** Bytecode compilation backend for .ml files. *) -let to_bytecode i (typedtree, coercion) = +let to_bytecode i (typedtree, coercion, _signature) = (typedtree, coercion) |> Profile.(record transl) (Translmod.transl_implementation i.module_name) diff --git a/driver/compile.mli b/driver/compile.mli index 968955762..1d181e05b 100644 --- a/driver/compile.mli +++ b/driver/compile.mli @@ -25,7 +25,7 @@ val implementation: val to_bytecode : Compile_common.info -> - Typedtree.structure * Typedtree.module_coercion -> + Typedtree.structure * Typedtree.module_coercion * Types.signature -> Instruct.instruction list * Ident.Set.t (** [to_bytecode info typed] takes a typechecked implementation and returns its bytecode. diff --git a/driver/compile_common.mli b/driver/compile_common.mli index b43125d6d..c22c3364e 100644 --- a/driver/compile_common.mli +++ b/driver/compile_common.mli @@ -69,15 +69,19 @@ val parse_impl : info -> Parsetree.structure (** [parse_impl info] parses an implementation (usually an [.ml] file). *) val typecheck_impl : - info -> Parsetree.structure -> Typedtree.structure * Typedtree.module_coercion + info -> + Parsetree.structure -> + Typedtree.structure * Typedtree.module_coercion * Types.signature (** [typecheck_impl info parsetree] typechecks an implementation and returns the typedtree of the associated module, along with a coercion against - its public interface. + its public interface, and its public interface. *) val implementation : info -> - backend:(info -> Typedtree.structure * Typedtree.module_coercion -> unit) -> + backend:(info -> + Typedtree.structure * Typedtree.module_coercion * Types.signature -> + unit) -> unit (** The complete compilation pipeline for implementations. *) diff --git a/driver/optcompile.ml b/driver/optcompile.ml index 693a35f48..7c6e696b9 100644 --- a/driver/optcompile.ml +++ b/driver/optcompile.ml @@ -31,13 +31,14 @@ let (|>>) (x, y) f = (x, f y) (** Native compilation backend for .ml files. *) -let flambda i backend typed = +let flambda i backend (structure, coercion, _signature) = if !Clflags.classic_inlining then begin Clflags.default_simplify_rounds := 1; Clflags.use_inlining_arguments_set Clflags.classic_arguments; Clflags.unbox_free_vars_of_closures := false; Clflags.unbox_specialised_args := false end; + let typed = (structure, coercion) in typed |> Profile.(record transl) (Translmod.transl_implementation_flambda i.module_name) @@ -66,8 +67,9 @@ let flambda i backend typed = program); Compilenv.save_unit_info (cmx i)) -let clambda i backend typed = +let clambda i backend (structure, coercion, _signature) = Clflags.use_inlining_arguments_set Clflags.classic_arguments; + let typed = (structure, coercion) in typed |> Profile.(record transl) (Translmod.transl_store_implementation i.module_name) diff --git a/driver/optcompile.mli b/driver/optcompile.mli index f04e75e62..ee2d18eaa 100644 --- a/driver/optcompile.mli +++ b/driver/optcompile.mli @@ -27,7 +27,7 @@ val implementation: val clambda : Compile_common.info -> (module Backend_intf.S) -> - Typedtree.structure * Typedtree.module_coercion -> unit + Typedtree.structure * Typedtree.module_coercion * Types.signature -> unit (** [clambda info typed] applies the regular compilation pipeline to the given typechecked implementation and outputs the resulting files. *) @@ -35,7 +35,7 @@ val clambda : val flambda : Compile_common.info -> (module Backend_intf.S) -> - Typedtree.structure * Typedtree.module_coercion -> unit + Typedtree.structure * Typedtree.module_coercion * Types.signature -> unit (** [flambda info backend typed] applies the Flambda compilation pipeline to the given typechecked implementation and outputs the resulting files. *) diff --git a/ocamldoc/odoc_analyse.ml b/ocamldoc/odoc_analyse.ml index 79eda876f..5de828a23 100644 --- a/ocamldoc/odoc_analyse.ml +++ b/ocamldoc/odoc_analyse.ml @@ -151,7 +151,8 @@ let process_file sourcefile = match parsetree_typedtree_opt with None -> None - | Some (parsetree, typedtree) -> + | Some (parsetree, (structure, coercion, _signature)) -> + let typedtree = (structure, coercion) in let file_module = Ast_analyser.analyse_typed_tree file input_file parsetree typedtree in diff --git a/typing/printtyped.ml b/typing/printtyped.ml index 15aa09728..2f8718a98 100644 --- a/typing/printtyped.ml +++ b/typing/printtyped.ml @@ -942,4 +942,4 @@ let interface ppf x = list 0 signature_item ppf x.sig_items;; let implementation ppf x = list 0 structure_item ppf x.str_items;; -let implementation_with_coercion ppf (x, _) = implementation ppf x +let implementation_with_coercion ppf (x, _, _) = implementation ppf x diff --git a/typing/printtyped.mli b/typing/printtyped.mli index ded42bb32..f28de6a1c 100644 --- a/typing/printtyped.mli +++ b/typing/printtyped.mli @@ -20,4 +20,4 @@ val interface : formatter -> signature -> unit;; val implementation : formatter -> structure -> unit;; val implementation_with_coercion : - formatter -> (structure * module_coercion) -> unit;; + formatter -> (structure * module_coercion * Types.signature) -> unit;; diff --git a/typing/typemod.ml b/typing/typemod.ml index de937c642..9ed59e4bb 100644 --- a/typing/typemod.ml +++ b/typing/typemod.ml @@ -2637,7 +2637,7 @@ let type_implementation sourcefile outputprefix modulename initial_env ast = (Printtyp.printed_signature sourcefile) simple_sg ); gen_annot outputprefix sourcefile (Cmt_format.Implementation str); - (str, Tcoerce_none) (* result is ignored by Compile.implementation *) + (str, Tcoerce_none, simple_sg) (* result is ignored by Compile.implementation *) end else begin let sourceintf = Filename.remove_extension sourcefile ^ !Config.interface_suffix in @@ -2661,7 +2661,7 @@ let type_implementation sourcefile outputprefix modulename initial_env ast = Cmt_format.save_cmt (outputprefix ^ ".cmt") modulename annots (Some sourcefile) initial_env None; gen_annot outputprefix sourcefile annots; - (str, coercion) + (str, coercion, dclsig) end else begin let coercion = Includemod.compunit initial_env ~mark:Mark_positive @@ -2685,7 +2685,7 @@ let type_implementation sourcefile outputprefix modulename initial_env ast = annots (Some sourcefile) initial_env (Some cmi); gen_annot outputprefix sourcefile annots end; - (str, coercion) + (str, coercion, simple_sg) end end ) diff --git a/typing/typemod.mli b/typing/typemod.mli index c24aa5e2a..381db37cd 100644 --- a/typing/typemod.mli +++ b/typing/typemod.mli @@ -39,7 +39,7 @@ val type_toplevel_phrase: Typedtree.structure * Types.signature * Signature_names.t * Env.t val type_implementation: string -> string -> string -> Env.t -> Parsetree.structure -> - Typedtree.structure * Typedtree.module_coercion + Typedtree.structure * Typedtree.module_coercion * Types.signature val type_interface: Env.t -> Parsetree.signature -> Typedtree.signature val transl_signature: From f6e428acf21e87ec4655a4ad922ca89b101dae77 Mon Sep 17 00:00:00 2001 From: Leandro Ostera Date: Thu, 5 Nov 2020 18:29:45 +0100 Subject: [PATCH 2/9] Introduce typed_impl record --- driver/compile.ml | 4 ++-- driver/compile.mli | 2 +- driver/compile_common.mli | 16 ++++------------ driver/optcompile.ml | 10 ++++------ driver/optcompile.mli | 8 ++------ ocamldoc/odoc_analyse.ml | 2 +- typing/printtyped.ml | 2 +- typing/printtyped.mli | 2 +- typing/typemod.ml | 21 ++++++++++++++++++--- typing/typemod.mli | 9 +++++++-- 10 files changed, 41 insertions(+), 35 deletions(-) diff --git a/driver/compile.ml b/driver/compile.ml index ed395bd23..954956327 100644 --- a/driver/compile.ml +++ b/driver/compile.ml @@ -27,8 +27,8 @@ let interface ~source_file ~output_prefix = (** Bytecode compilation backend for .ml files. *) -let to_bytecode i (typedtree, coercion, _signature) = - (typedtree, coercion) +let to_bytecode i Typemod.{structure; coercion; _} = + (structure, coercion) |> Profile.(record transl) (Translmod.transl_implementation i.module_name) |> Profile.(record ~accumulate:true generate) diff --git a/driver/compile.mli b/driver/compile.mli index 1d181e05b..0256bd43a 100644 --- a/driver/compile.mli +++ b/driver/compile.mli @@ -25,7 +25,7 @@ val implementation: val to_bytecode : Compile_common.info -> - Typedtree.structure * Typedtree.module_coercion * Types.signature -> + Typemod.typed_impl -> Instruct.instruction list * Ident.Set.t (** [to_bytecode info typed] takes a typechecked implementation and returns its bytecode. diff --git a/driver/compile_common.mli b/driver/compile_common.mli index c22c3364e..170cddea8 100644 --- a/driver/compile_common.mli +++ b/driver/compile_common.mli @@ -68,21 +68,13 @@ val interface : info -> unit val parse_impl : info -> Parsetree.structure (** [parse_impl info] parses an implementation (usually an [.ml] file). *) -val typecheck_impl : - info -> - Parsetree.structure -> - Typedtree.structure * Typedtree.module_coercion * Types.signature +val typecheck_impl : info -> Parsetree.structure -> Typemod.typed_impl (** [typecheck_impl info parsetree] typechecks an implementation and returns - the typedtree of the associated module, along with a coercion against - its public interface, and its public interface. + the typedtree of the associated module, its public interface, and a + coercion against that public interface. *) -val implementation : - info -> - backend:(info -> - Typedtree.structure * Typedtree.module_coercion * Types.signature -> - unit) -> - unit +val implementation : info -> backend:(info -> Typemod.typed_impl -> unit) -> unit (** The complete compilation pipeline for implementations. *) (** {2 Build artifacts} *) diff --git a/driver/optcompile.ml b/driver/optcompile.ml index 7c6e696b9..99f2c0751 100644 --- a/driver/optcompile.ml +++ b/driver/optcompile.ml @@ -31,15 +31,14 @@ let (|>>) (x, y) f = (x, f y) (** Native compilation backend for .ml files. *) -let flambda i backend (structure, coercion, _signature) = +let flambda i backend Typemod.{structure; coercion; _} = if !Clflags.classic_inlining then begin Clflags.default_simplify_rounds := 1; Clflags.use_inlining_arguments_set Clflags.classic_arguments; Clflags.unbox_free_vars_of_closures := false; Clflags.unbox_specialised_args := false end; - let typed = (structure, coercion) in - typed + (structure, coercion) |> Profile.(record transl) (Translmod.transl_implementation_flambda i.module_name) |> Profile.(record generate) @@ -67,10 +66,9 @@ let flambda i backend (structure, coercion, _signature) = program); Compilenv.save_unit_info (cmx i)) -let clambda i backend (structure, coercion, _signature) = +let clambda i backend Typemod.{structure; coercion; _} = Clflags.use_inlining_arguments_set Clflags.classic_arguments; - let typed = (structure, coercion) in - typed + (structure, coercion) |> Profile.(record transl) (Translmod.transl_store_implementation i.module_name) |> print_if i.ppf_dump Clflags.dump_rawlambda Printlambda.program diff --git a/driver/optcompile.mli b/driver/optcompile.mli index ee2d18eaa..bc91ac60e 100644 --- a/driver/optcompile.mli +++ b/driver/optcompile.mli @@ -25,17 +25,13 @@ val implementation: (** {2 Internal functions} **) val clambda : - Compile_common.info -> - (module Backend_intf.S) -> - Typedtree.structure * Typedtree.module_coercion * Types.signature -> unit + Compile_common.info -> (module Backend_intf.S) -> Typemod.typed_impl-> unit (** [clambda info typed] applies the regular compilation pipeline to the given typechecked implementation and outputs the resulting files. *) val flambda : - Compile_common.info -> - (module Backend_intf.S) -> - Typedtree.structure * Typedtree.module_coercion * Types.signature -> unit + Compile_common.info -> (module Backend_intf.S) -> Typemod.typed_impl -> unit (** [flambda info backend typed] applies the Flambda compilation pipeline to the given typechecked implementation and outputs the resulting files. *) diff --git a/ocamldoc/odoc_analyse.ml b/ocamldoc/odoc_analyse.ml index 5de828a23..fb30f61dd 100644 --- a/ocamldoc/odoc_analyse.ml +++ b/ocamldoc/odoc_analyse.ml @@ -151,7 +151,7 @@ let process_file sourcefile = match parsetree_typedtree_opt with None -> None - | Some (parsetree, (structure, coercion, _signature)) -> + | Some (parsetree, Typemod.{structure; coercion; _}) -> let typedtree = (structure, coercion) in let file_module = Ast_analyser.analyse_typed_tree file input_file parsetree typedtree diff --git a/typing/printtyped.ml b/typing/printtyped.ml index 2f8718a98..90b8395fe 100644 --- a/typing/printtyped.ml +++ b/typing/printtyped.ml @@ -942,4 +942,4 @@ let interface ppf x = list 0 signature_item ppf x.sig_items;; let implementation ppf x = list 0 structure_item ppf x.str_items;; -let implementation_with_coercion ppf (x, _, _) = implementation ppf x +let implementation_with_coercion ppf Typemod.{structure; _} = implementation ppf structure diff --git a/typing/printtyped.mli b/typing/printtyped.mli index f28de6a1c..3e0e949ca 100644 --- a/typing/printtyped.mli +++ b/typing/printtyped.mli @@ -20,4 +20,4 @@ val interface : formatter -> signature -> unit;; val implementation : formatter -> structure -> unit;; val implementation_with_coercion : - formatter -> (structure * module_coercion * Types.signature) -> unit;; + formatter -> Typemod.typed_impl -> unit;; diff --git a/typing/typemod.ml b/typing/typemod.ml index 9ed59e4bb..7601a321c 100644 --- a/typing/typemod.ml +++ b/typing/typemod.ml @@ -106,6 +106,12 @@ type error = exception Error of Location.t * Env.t * error exception Error_forward of Location.error +type typed_impl = { + structure: Typedtree.structure; + coercion: Typedtree.module_coercion; + signature: Types.signature +} + open Typedtree let rec path_concat head p = @@ -2637,7 +2643,10 @@ let type_implementation sourcefile outputprefix modulename initial_env ast = (Printtyp.printed_signature sourcefile) simple_sg ); gen_annot outputprefix sourcefile (Cmt_format.Implementation str); - (str, Tcoerce_none, simple_sg) (* result is ignored by Compile.implementation *) + { structure = str; + coercion = Tcoerce_none; + signature = simple_sg + } (* result is ignored by Compile.implementation *) end else begin let sourceintf = Filename.remove_extension sourcefile ^ !Config.interface_suffix in @@ -2661,7 +2670,10 @@ let type_implementation sourcefile outputprefix modulename initial_env ast = Cmt_format.save_cmt (outputprefix ^ ".cmt") modulename annots (Some sourcefile) initial_env None; gen_annot outputprefix sourcefile annots; - (str, coercion, dclsig) + { structure = str; + coercion; + signature = dclsig + } end else begin let coercion = Includemod.compunit initial_env ~mark:Mark_positive @@ -2685,7 +2697,10 @@ let type_implementation sourcefile outputprefix modulename initial_env ast = annots (Some sourcefile) initial_env (Some cmi); gen_annot outputprefix sourcefile annots end; - (str, coercion, simple_sg) + { structure = str; + coercion; + signature = simple_sg + } end end ) diff --git a/typing/typemod.mli b/typing/typemod.mli index 381db37cd..5d3420f79 100644 --- a/typing/typemod.mli +++ b/typing/typemod.mli @@ -29,6 +29,12 @@ module Signature_names : sig val simplify: Env.t -> t -> signature -> signature end +type typed_impl = { + structure: Typedtree.structure; + coercion: Typedtree.module_coercion; + signature: Types.signature +} + val type_module: Env.t -> Parsetree.module_expr -> Typedtree.module_expr val type_structure: @@ -38,8 +44,7 @@ val type_toplevel_phrase: Env.t -> Parsetree.structure -> Typedtree.structure * Types.signature * Signature_names.t * Env.t val type_implementation: - string -> string -> string -> Env.t -> Parsetree.structure -> - Typedtree.structure * Typedtree.module_coercion * Types.signature + string -> string -> string -> Env.t -> Parsetree.structure -> typed_impl val type_interface: Env.t -> Parsetree.signature -> Typedtree.signature val transl_signature: From 3be9e19c17328f109b403305d95084fb81936a20 Mon Sep 17 00:00:00 2001 From: Leandro Ostera Date: Thu, 5 Nov 2020 18:49:27 +0100 Subject: [PATCH 3/9] Fix dependency between Printtyped and Typemod --- .depend | 2 ++ typing/printtyped.mli | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.depend b/.depend index 487599130..d6e7fe706 100644 --- a/.depend +++ b/.depend @@ -1010,6 +1010,7 @@ typing/printtyp.cmi : \ parsing/asttypes.cmi typing/printtyped.cmo : \ typing/types.cmi \ + typing/typemod.cmi \ typing/typedtree.cmi \ parsing/printast.cmi \ typing/path.cmi \ @@ -1022,6 +1023,7 @@ typing/printtyped.cmo : \ typing/printtyped.cmi typing/printtyped.cmx : \ typing/types.cmx \ + typing/typemod.cmx \ typing/typedtree.cmx \ parsing/printast.cmx \ typing/path.cmx \ diff --git a/typing/printtyped.mli b/typing/printtyped.mli index 3e0e949ca..951354abf 100644 --- a/typing/printtyped.mli +++ b/typing/printtyped.mli @@ -19,5 +19,4 @@ open Format;; val interface : formatter -> signature -> unit;; val implementation : formatter -> structure -> unit;; -val implementation_with_coercion : - formatter -> Typemod.typed_impl -> unit;; +val implementation_with_coercion : formatter -> Typemod.typed_impl -> unit;; From ee2f3b428c074539f14dacae1faeb07a9de4be77 Mon Sep 17 00:00:00 2001 From: Leandro Ostera Date: Thu, 5 Nov 2020 19:06:12 +0100 Subject: [PATCH 4/9] Move typed_impl to Typedtree.t --- .depend | 2 -- driver/compile.ml | 2 +- driver/compile.mli | 2 +- driver/compile_common.mli | 4 ++-- driver/optcompile.ml | 4 ++-- driver/optcompile.mli | 4 ++-- ocamldoc/odoc_analyse.ml | 2 +- typing/printtyped.ml | 2 +- typing/printtyped.mli | 2 +- typing/typedtree.ml | 7 +++++++ typing/typedtree.mli | 6 ++++++ typing/typemod.ml | 6 ------ typing/typemod.mli | 8 +------- typing/untypeast.ml | 8 ++++---- 14 files changed, 29 insertions(+), 30 deletions(-) diff --git a/.depend b/.depend index d6e7fe706..487599130 100644 --- a/.depend +++ b/.depend @@ -1010,7 +1010,6 @@ typing/printtyp.cmi : \ parsing/asttypes.cmi typing/printtyped.cmo : \ typing/types.cmi \ - typing/typemod.cmi \ typing/typedtree.cmi \ parsing/printast.cmi \ typing/path.cmi \ @@ -1023,7 +1022,6 @@ typing/printtyped.cmo : \ typing/printtyped.cmi typing/printtyped.cmx : \ typing/types.cmx \ - typing/typemod.cmx \ typing/typedtree.cmx \ parsing/printast.cmx \ typing/path.cmx \ diff --git a/driver/compile.ml b/driver/compile.ml index 954956327..7a88388c3 100644 --- a/driver/compile.ml +++ b/driver/compile.ml @@ -27,7 +27,7 @@ let interface ~source_file ~output_prefix = (** Bytecode compilation backend for .ml files. *) -let to_bytecode i Typemod.{structure; coercion; _} = +let to_bytecode i Typedtree.{structure; coercion; _} = (structure, coercion) |> Profile.(record transl) (Translmod.transl_implementation i.module_name) diff --git a/driver/compile.mli b/driver/compile.mli index 0256bd43a..32872b1ea 100644 --- a/driver/compile.mli +++ b/driver/compile.mli @@ -25,7 +25,7 @@ val implementation: val to_bytecode : Compile_common.info -> - Typemod.typed_impl -> + Typedtree.t -> Instruct.instruction list * Ident.Set.t (** [to_bytecode info typed] takes a typechecked implementation and returns its bytecode. diff --git a/driver/compile_common.mli b/driver/compile_common.mli index 170cddea8..6a062aba4 100644 --- a/driver/compile_common.mli +++ b/driver/compile_common.mli @@ -68,13 +68,13 @@ val interface : info -> unit val parse_impl : info -> Parsetree.structure (** [parse_impl info] parses an implementation (usually an [.ml] file). *) -val typecheck_impl : info -> Parsetree.structure -> Typemod.typed_impl +val typecheck_impl : info -> Parsetree.structure -> Typedtree.t (** [typecheck_impl info parsetree] typechecks an implementation and returns the typedtree of the associated module, its public interface, and a coercion against that public interface. *) -val implementation : info -> backend:(info -> Typemod.typed_impl -> unit) -> unit +val implementation : info -> backend:(info -> Typedtree.t -> unit) -> unit (** The complete compilation pipeline for implementations. *) (** {2 Build artifacts} *) diff --git a/driver/optcompile.ml b/driver/optcompile.ml index 99f2c0751..51fc23cfb 100644 --- a/driver/optcompile.ml +++ b/driver/optcompile.ml @@ -31,7 +31,7 @@ let (|>>) (x, y) f = (x, f y) (** Native compilation backend for .ml files. *) -let flambda i backend Typemod.{structure; coercion; _} = +let flambda i backend Typedtree.{structure; coercion; _} = if !Clflags.classic_inlining then begin Clflags.default_simplify_rounds := 1; Clflags.use_inlining_arguments_set Clflags.classic_arguments; @@ -66,7 +66,7 @@ let flambda i backend Typemod.{structure; coercion; _} = program); Compilenv.save_unit_info (cmx i)) -let clambda i backend Typemod.{structure; coercion; _} = +let clambda i backend Typedtree.{structure; coercion; _} = Clflags.use_inlining_arguments_set Clflags.classic_arguments; (structure, coercion) |> Profile.(record transl) diff --git a/driver/optcompile.mli b/driver/optcompile.mli index bc91ac60e..516377798 100644 --- a/driver/optcompile.mli +++ b/driver/optcompile.mli @@ -25,13 +25,13 @@ val implementation: (** {2 Internal functions} **) val clambda : - Compile_common.info -> (module Backend_intf.S) -> Typemod.typed_impl-> unit + Compile_common.info -> (module Backend_intf.S) -> Typedtree.t-> unit (** [clambda info typed] applies the regular compilation pipeline to the given typechecked implementation and outputs the resulting files. *) val flambda : - Compile_common.info -> (module Backend_intf.S) -> Typemod.typed_impl -> unit + Compile_common.info -> (module Backend_intf.S) -> Typedtree.t -> unit (** [flambda info backend typed] applies the Flambda compilation pipeline to the given typechecked implementation and outputs the resulting files. *) diff --git a/ocamldoc/odoc_analyse.ml b/ocamldoc/odoc_analyse.ml index fb30f61dd..f9ec3cb69 100644 --- a/ocamldoc/odoc_analyse.ml +++ b/ocamldoc/odoc_analyse.ml @@ -151,7 +151,7 @@ let process_file sourcefile = match parsetree_typedtree_opt with None -> None - | Some (parsetree, Typemod.{structure; coercion; _}) -> + | Some (parsetree, Typedtree.{structure; coercion; _}) -> let typedtree = (structure, coercion) in let file_module = Ast_analyser.analyse_typed_tree file input_file parsetree typedtree diff --git a/typing/printtyped.ml b/typing/printtyped.ml index 90b8395fe..eb9a06cf5 100644 --- a/typing/printtyped.ml +++ b/typing/printtyped.ml @@ -942,4 +942,4 @@ let interface ppf x = list 0 signature_item ppf x.sig_items;; let implementation ppf x = list 0 structure_item ppf x.str_items;; -let implementation_with_coercion ppf Typemod.{structure; _} = implementation ppf structure +let implementation_with_coercion ppf Typedtree.{structure; _} = implementation ppf structure diff --git a/typing/printtyped.mli b/typing/printtyped.mli index 951354abf..438e2c1de 100644 --- a/typing/printtyped.mli +++ b/typing/printtyped.mli @@ -19,4 +19,4 @@ open Format;; val interface : formatter -> signature -> unit;; val implementation : formatter -> structure -> unit;; -val implementation_with_coercion : formatter -> Typemod.typed_impl -> unit;; +val implementation_with_coercion : formatter -> Typedtree.t -> unit;; diff --git a/typing/typedtree.ml b/typing/typedtree.ml index ca81b0f05..232ecf9d9 100644 --- a/typing/typedtree.ml +++ b/typing/typedtree.ml @@ -613,6 +613,13 @@ and 'a class_infos = ci_attributes: attribute list; } +type t = { + structure: structure; + coercion: module_coercion; + signature: Types.signature +} + + (* Auxiliary functions over the a.s.t. *) let as_computation_pattern (p : pattern) : computation general_pattern = diff --git a/typing/typedtree.mli b/typing/typedtree.mli index 1323505cd..6e2f400e8 100644 --- a/typing/typedtree.mli +++ b/typing/typedtree.mli @@ -752,6 +752,12 @@ and 'a class_infos = ci_attributes: attributes; } +type t = { + structure: structure; + coercion: module_coercion; + signature: Types.signature +} + (* Auxiliary functions over the a.s.t. *) (** [as_computation_pattern p] is a computation pattern with description diff --git a/typing/typemod.ml b/typing/typemod.ml index 7601a321c..fd65179c2 100644 --- a/typing/typemod.ml +++ b/typing/typemod.ml @@ -106,12 +106,6 @@ type error = exception Error of Location.t * Env.t * error exception Error_forward of Location.error -type typed_impl = { - structure: Typedtree.structure; - coercion: Typedtree.module_coercion; - signature: Types.signature -} - open Typedtree let rec path_concat head p = diff --git a/typing/typemod.mli b/typing/typemod.mli index 5d3420f79..89579facb 100644 --- a/typing/typemod.mli +++ b/typing/typemod.mli @@ -29,12 +29,6 @@ module Signature_names : sig val simplify: Env.t -> t -> signature -> signature end -type typed_impl = { - structure: Typedtree.structure; - coercion: Typedtree.module_coercion; - signature: Types.signature -} - val type_module: Env.t -> Parsetree.module_expr -> Typedtree.module_expr val type_structure: @@ -44,7 +38,7 @@ val type_toplevel_phrase: Env.t -> Parsetree.structure -> Typedtree.structure * Types.signature * Signature_names.t * Env.t val type_implementation: - string -> string -> string -> Env.t -> Parsetree.structure -> typed_impl + string -> string -> string -> Env.t -> Parsetree.structure -> Typedtree.t val type_interface: Env.t -> Parsetree.signature -> Typedtree.signature val transl_signature: diff --git a/typing/untypeast.ml b/typing/untypeast.ml index dc36aaf43..1ff4ae6d2 100644 --- a/typing/untypeast.ml +++ b/typing/untypeast.ml @@ -605,7 +605,7 @@ let functor_parameter sub : functor_parameter -> Parsetree.functor_parameter = | Unit -> Unit | Named (_, name, mtype) -> Named (name, sub.module_type sub mtype) -let module_type sub mty = +let module_type (sub : mapper) mty = let loc = sub.location sub mty.mty_loc in let attrs = sub.attributes sub mty.mty_attributes in let desc = match mty.mty_desc with @@ -633,7 +633,7 @@ let with_constraint sub (_path, lid, cstr) = | Twith_modsubst (_path, lid2) -> Pwith_modsubst (map_loc sub lid, map_loc sub lid2) -let module_expr sub mexpr = +let module_expr (sub : mapper) mexpr = let loc = sub.location sub mexpr.mod_loc in let attrs = sub.attributes sub mexpr.mod_attributes in match mexpr.mod_desc with @@ -882,10 +882,10 @@ let default_mapper = object_field = object_field ; } -let untype_structure ?(mapper=default_mapper) structure = +let untype_structure ?(mapper : mapper = default_mapper) structure = mapper.structure mapper structure -let untype_signature ?(mapper=default_mapper) signature = +let untype_signature ?(mapper : mapper = default_mapper) signature = mapper.signature mapper signature let untype_expression ?(mapper=default_mapper) expression = From 1b085d38408bc79073de852f666dcf18c1d82305 Mon Sep 17 00:00:00 2001 From: Leandro Ostera Date: Thu, 5 Nov 2020 21:19:44 +0100 Subject: [PATCH 5/9] Rename Typedtree.t to Typedtree.implementation --- driver/compile.mli | 2 +- driver/compile_common.mli | 4 ++-- driver/optcompile.mli | 8 ++++++-- typing/printtyped.mli | 2 +- typing/typedtree.ml | 2 +- typing/typedtree.mli | 2 +- typing/typemod.mli | 3 ++- 7 files changed, 14 insertions(+), 9 deletions(-) diff --git a/driver/compile.mli b/driver/compile.mli index 32872b1ea..ec54f0708 100644 --- a/driver/compile.mli +++ b/driver/compile.mli @@ -25,7 +25,7 @@ val implementation: val to_bytecode : Compile_common.info -> - Typedtree.t -> + Typedtree.implementation -> Instruct.instruction list * Ident.Set.t (** [to_bytecode info typed] takes a typechecked implementation and returns its bytecode. diff --git a/driver/compile_common.mli b/driver/compile_common.mli index 6a062aba4..e3a890a27 100644 --- a/driver/compile_common.mli +++ b/driver/compile_common.mli @@ -68,13 +68,13 @@ val interface : info -> unit val parse_impl : info -> Parsetree.structure (** [parse_impl info] parses an implementation (usually an [.ml] file). *) -val typecheck_impl : info -> Parsetree.structure -> Typedtree.t +val typecheck_impl : info -> Parsetree.structure -> Typedtree.implementation (** [typecheck_impl info parsetree] typechecks an implementation and returns the typedtree of the associated module, its public interface, and a coercion against that public interface. *) -val implementation : info -> backend:(info -> Typedtree.t -> unit) -> unit +val implementation : info -> backend:(info -> Typedtree.implementation -> unit) -> unit (** The complete compilation pipeline for implementations. *) (** {2 Build artifacts} *) diff --git a/driver/optcompile.mli b/driver/optcompile.mli index 516377798..8f4a3127a 100644 --- a/driver/optcompile.mli +++ b/driver/optcompile.mli @@ -25,13 +25,17 @@ val implementation: (** {2 Internal functions} **) val clambda : - Compile_common.info -> (module Backend_intf.S) -> Typedtree.t-> unit + Compile_common.info -> + (module Backend_intf.S) -> + Typedtree.implementation -> unit (** [clambda info typed] applies the regular compilation pipeline to the given typechecked implementation and outputs the resulting files. *) val flambda : - Compile_common.info -> (module Backend_intf.S) -> Typedtree.t -> unit + Compile_common.info -> + (module Backend_intf.S) -> + Typedtree.implementation -> unit (** [flambda info backend typed] applies the Flambda compilation pipeline to the given typechecked implementation and outputs the resulting files. *) diff --git a/typing/printtyped.mli b/typing/printtyped.mli index 438e2c1de..6799b869d 100644 --- a/typing/printtyped.mli +++ b/typing/printtyped.mli @@ -19,4 +19,4 @@ open Format;; val interface : formatter -> signature -> unit;; val implementation : formatter -> structure -> unit;; -val implementation_with_coercion : formatter -> Typedtree.t -> unit;; +val implementation_with_coercion : formatter -> Typedtree.implementation -> unit;; diff --git a/typing/typedtree.ml b/typing/typedtree.ml index 232ecf9d9..4015ed8e1 100644 --- a/typing/typedtree.ml +++ b/typing/typedtree.ml @@ -613,7 +613,7 @@ and 'a class_infos = ci_attributes: attribute list; } -type t = { +type implementation = { structure: structure; coercion: module_coercion; signature: Types.signature diff --git a/typing/typedtree.mli b/typing/typedtree.mli index 6e2f400e8..4d6b02c29 100644 --- a/typing/typedtree.mli +++ b/typing/typedtree.mli @@ -752,7 +752,7 @@ and 'a class_infos = ci_attributes: attributes; } -type t = { +type implementation = { structure: structure; coercion: module_coercion; signature: Types.signature diff --git a/typing/typemod.mli b/typing/typemod.mli index 89579facb..87ebd8f1f 100644 --- a/typing/typemod.mli +++ b/typing/typemod.mli @@ -38,7 +38,8 @@ val type_toplevel_phrase: Env.t -> Parsetree.structure -> Typedtree.structure * Types.signature * Signature_names.t * Env.t val type_implementation: - string -> string -> string -> Env.t -> Parsetree.structure -> Typedtree.t + string -> string -> string -> Env.t -> + Parsetree.structure -> Typedtree.implementation val type_interface: Env.t -> Parsetree.signature -> Typedtree.signature val transl_signature: From b91a90a4a7bc4cf84ece5c0a712eee81e063c803 Mon Sep 17 00:00:00 2001 From: Leandro Ostera Date: Fri, 6 Nov 2020 09:20:10 +0100 Subject: [PATCH 6/9] Fix linting errors --- driver/compile_common.mli | 3 ++- typing/printtyped.ml | 3 ++- typing/printtyped.mli | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/driver/compile_common.mli b/driver/compile_common.mli index e3a890a27..c2f29cbe3 100644 --- a/driver/compile_common.mli +++ b/driver/compile_common.mli @@ -74,7 +74,8 @@ val typecheck_impl : info -> Parsetree.structure -> Typedtree.implementation coercion against that public interface. *) -val implementation : info -> backend:(info -> Typedtree.implementation -> unit) -> unit +val implementation : + info -> backend:(info -> Typedtree.implementation -> unit) -> unit (** The complete compilation pipeline for implementations. *) (** {2 Build artifacts} *) diff --git a/typing/printtyped.ml b/typing/printtyped.ml index eb9a06cf5..ccf93f1b7 100644 --- a/typing/printtyped.ml +++ b/typing/printtyped.ml @@ -942,4 +942,5 @@ let interface ppf x = list 0 signature_item ppf x.sig_items;; let implementation ppf x = list 0 structure_item ppf x.str_items;; -let implementation_with_coercion ppf Typedtree.{structure; _} = implementation ppf structure +let implementation_with_coercion ppf Typedtree.{structure; _} = + implementation ppf structure diff --git a/typing/printtyped.mli b/typing/printtyped.mli index 6799b869d..538a3faae 100644 --- a/typing/printtyped.mli +++ b/typing/printtyped.mli @@ -19,4 +19,5 @@ open Format;; val interface : formatter -> signature -> unit;; val implementation : formatter -> structure -> unit;; -val implementation_with_coercion : formatter -> Typedtree.implementation -> unit;; +val implementation_with_coercion : + formatter -> Typedtree.implementation -> unit;; From a0b7aff645e10994525215d9a36f706d48d4225d Mon Sep 17 00:00:00 2001 From: Leandro Ostera Date: Fri, 6 Nov 2020 09:24:33 +0100 Subject: [PATCH 7/9] Fix .depend file No change entry needed --- .depend | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.depend b/.depend index 487599130..22aecafee 100644 --- a/.depend +++ b/.depend @@ -5743,6 +5743,7 @@ driver/compenv.cmx : \ driver/compenv.cmi : \ utils/clflags.cmi driver/compile.cmo : \ + typing/typedtree.cmi \ lambda/translmod.cmi \ lambda/simplif.cmi \ utils/profile.cmi \ @@ -5756,6 +5757,7 @@ driver/compile.cmo : \ bytecomp/bytegen.cmi \ driver/compile.cmi driver/compile.cmx : \ + typing/typedtree.cmx \ lambda/translmod.cmx \ lambda/simplif.cmx \ utils/profile.cmx \ @@ -5934,6 +5936,7 @@ driver/makedepend.cmx : \ driver/makedepend.cmi driver/makedepend.cmi : driver/optcompile.cmo : \ + typing/typedtree.cmi \ lambda/translmod.cmi \ lambda/simplif.cmi \ utils/profile.cmi \ @@ -5949,6 +5952,7 @@ driver/optcompile.cmo : \ asmcomp/asmgen.cmi \ driver/optcompile.cmi driver/optcompile.cmx : \ + typing/typedtree.cmx \ lambda/translmod.cmx \ lambda/simplif.cmx \ utils/profile.cmx \ From f4143fd372ebc7d253e702490f1c9e1f22929482 Mon Sep 17 00:00:00 2001 From: Leandro Ostera Date: Fri, 6 Nov 2020 18:25:20 +0100 Subject: [PATCH 8/9] Document Typedtree.implementation --- typing/typedtree.mli | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/typing/typedtree.mli b/typing/typedtree.mli index 4d6b02c29..cbac6f651 100644 --- a/typing/typedtree.mli +++ b/typing/typedtree.mli @@ -757,7 +757,14 @@ type implementation = { coercion: module_coercion; signature: Types.signature } +(** A typechecked implementation including its module structure, its exported + signature, and a coercion of the module against that signature. + + If an .mli file is present, the signature will come from that file and be + the exported signature of the module. + If there isn't one, the signature will be inferred from the module structure. +*) (* Auxiliary functions over the a.s.t. *) (** [as_computation_pattern p] is a computation pattern with description From 5278e3fe3797c00c92b9792abf206dbd28998025 Mon Sep 17 00:00:00 2001 From: Leandro Ostera Date: Fri, 6 Nov 2020 23:49:19 +0100 Subject: [PATCH 9/9] Fix typo checks --- typing/typedtree.mli | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/typing/typedtree.mli b/typing/typedtree.mli index cbac6f651..33cb0591c 100644 --- a/typing/typedtree.mli +++ b/typing/typedtree.mli @@ -759,12 +759,14 @@ type implementation = { } (** A typechecked implementation including its module structure, its exported signature, and a coercion of the module against that signature. - + If an .mli file is present, the signature will come from that file and be the exported signature of the module. - If there isn't one, the signature will be inferred from the module structure. + If there isn't one, the signature will be inferred from the module + structure. *) + (* Auxiliary functions over the a.s.t. *) (** [as_computation_pattern p] is a computation pattern with description