From 7b55928fd2dda4b7ebe776242180a5ce50485552 Mon Sep 17 00:00:00 2001 From: Corentin Leruth Date: Wed, 8 Feb 2023 17:09:49 +0100 Subject: [PATCH] implement new module type syntax --- src/ppx_import.ml | 170 ++++++++++++++++++--- src_test/ppx_deriving/errors/run.t | 124 ++++++++------- src_test/ppx_deriving/errors_lte_407/run.t | 118 +++++++------- src_test/ppx_deriving/test_intf.ml | 2 +- src_test/ppx_deriving/test_intf.mli | 2 +- src_test/ppx_deriving/test_ppx_import.ml | 12 +- src_test/ppx_deriving/test_self_import.ml | 2 +- 7 files changed, 275 insertions(+), 155 deletions(-) diff --git a/src/ppx_import.ml b/src/ppx_import.ml index c7700fc..660b65c 100644 --- a/src/ppx_import.ml +++ b/src/ppx_import.ml @@ -508,17 +508,54 @@ let rec psig_of_tsig ~subst (tsig : Compat.signature_item_407 list) : | [] -> [] | _ -> assert false -let module_type ~tool_name ~input_name (package_type : Ppxlib.package_type) = +let subst_of_constraint (const : Ppxlib.with_constraint) = let open Ppxlib in - try - let ({txt = lid; loc} as alias), subst = package_type in + match const with + | Parsetree.Pwith_type (longident, type_decl) -> ( + match type_decl with + | {ptype_manifest = Some core_type; _} -> (longident, core_type) + | {ptype_loc; _} -> + raise_error ~loc:ptype_loc "[%%import]: Not supported type_decl" ) + | Parsetree.Pwith_module ({loc; _}, _) -> + raise_error ~loc "[%%import]: Pwith_module constraint is not supported." + | Parsetree.Pwith_modtype ({loc; _}, _) -> + raise_error ~loc "[%%import]: Pwith_modtype constraint is not supported." + | Parsetree.Pwith_modtypesubst ({loc; _}, _) -> + raise_error ~loc + "[%%import]: Pwith_modtypesubst constraint is not supported." + | Parsetree.Pwith_typesubst ({loc; _}, _) -> + raise_error ~loc "[%%import]: Pwith_typesubst constraint is not supported." + | Parsetree.Pwith_modsubst ({loc; _}, _) -> + raise_error ~loc "[%%import]: Pwith_modsubst constraint is not supported." + +let rec module_type ~tool_name ~input_name ?(subst = []) modtype = + let open Ppxlib in + let {pmty_desc; pmty_loc; _} = modtype in + match pmty_desc with + | Pmty_signature _ -> + (* Ex: module type%import Hashable = sig ... end *) + raise_error ~loc:pmty_loc + "[%%import] inline module type declaration is not supported" + | Pmty_with (modtype, constraints) -> + let subst = constraints |> List.map subst_of_constraint in + module_type ~tool_name ~input_name ~subst modtype + | Pmty_functor (_, _) -> + raise_error ~loc:pmty_loc "[%%import] module type doesn't support functor" + | Pmty_typeof _ -> + raise_error ~loc:pmty_loc "[%%import] module type doesn't support typeof" + | Pmty_extension _ -> + raise_error ~loc:pmty_loc "[%%import] module type doesn't support extension" + | Pmty_alias _ -> + raise_error ~loc:pmty_loc "[%%import] module type doesn't support alias" + | Pmty_ident longident -> + let {txt = lid; loc} = longident in if tool_name = "ocamldep" then if is_self_reference ~input_name ~loc lid then (* Create a dummy module type to break the circular dependency *) Ast_helper.Mty.mk ~attrs:[] (Pmty_signature []) else (* Just put it as alias *) - Ast_helper.Mty.mk ~attrs:[] (Pmty_alias alias) + Ast_helper.Mty.mk ~attrs:[] (Pmty_alias longident) else Ppxlib.Ast_helper.with_default_loc loc (fun () -> let env = Lazy.force lazy_env in @@ -552,6 +589,19 @@ let module_type ~tool_name ~input_name (package_type : Ppxlib.package_type) = | {mtd_type = None; _} -> raise_error ~loc "Imported module is abstract" | _ -> raise_error ~loc "Imported module is indirectly defined" ) + +let module_type_decl ~tool_name ~input_name + (modtype_decl : Ppxlib.module_type_declaration) = + let open Ppxlib in + try + let {pmtd_type; pmtd_loc; _} = modtype_decl in + match pmtd_type with + | None -> + (* when there's nothing after the equal sign. Ex: module type%import Hashable *) + raise_error ~loc:pmtd_loc + "[%%import] module type declaration is missing the module type \ + definition" + | Some modtype -> module_type ~tool_name ~input_name modtype with Error {loc; error} -> let ext = Ppxlib.Location.error_extensionf ~loc "%s" error in Ast_builder.Default.pmty_extension ~loc ext @@ -574,27 +624,105 @@ let type_declaration_expand_intf ~ctxt rec_flag type_decls = in Ppxlib.Ast_builder.Default.(psig_type ~loc rec_flag type_decls) -let module_declaration_expand ~ctxt package_type = +let module_declaration_expand ~ctxt modtype_decl = + let loc = Ppxlib.Expansion_context.Extension.extension_point_loc ctxt in let tool_name = Ppxlib.Expansion_context.Extension.tool_name ctxt in let input_name = Ppxlib.Expansion_context.Extension.input_name ctxt in - module_type ~tool_name ~input_name package_type + let modtype = module_type_decl ~tool_name ~input_name modtype_decl in + let Ppxlib.{pmtd_name; pmtd_attributes; pmtd_loc; _} = modtype_decl in + let md_decl = + Ppxlib.Ast_helper.Mtd.mk ~loc:pmtd_loc ~attrs:pmtd_attributes pmtd_name + ~typ:modtype + in + Ppxlib.{pstr_desc = Pstr_modtype md_decl; pstr_loc = loc} + +let module_declaration_expand_intf ~ctxt modtype_decl = + let loc = Ppxlib.Expansion_context.Extension.extension_point_loc ctxt in + let tool_name = Ppxlib.Expansion_context.Extension.tool_name ctxt in + let input_name = Ppxlib.Expansion_context.Extension.input_name ctxt in + let modtype = module_type_decl ~tool_name ~input_name modtype_decl in + let Ppxlib.{pmtd_name; pmtd_attributes; pmtd_loc; _} = modtype_decl in + let md_decl = + Ppxlib.Ast_helper.Mtd.mk ~loc:pmtd_loc ~attrs:pmtd_attributes pmtd_name + ~typ:modtype + in + Ppxlib.{psig_desc = Psig_modtype md_decl; psig_loc = loc} + +let type_declaration_expander ~ctxt payload = + let return_error e = + let loc = Ppxlib.Expansion_context.Extension.extension_point_loc ctxt in + let ext = Ppxlib.Location.error_extensionf ~loc "%s" e in + Ppxlib.Ast_builder.Default.pstr_extension ext [] ~loc + in + match payload with + | Parsetree.PStr [{pstr_desc = Pstr_type (rec_flag, type_decls); _}] + |Parsetree.PSig [{psig_desc = Psig_type (rec_flag, type_decls); _}] -> + type_declaration_expand ~ctxt rec_flag type_decls + | Parsetree.PStr [{pstr_desc = Pstr_modtype modtype_decl; _}] + |Parsetree.PSig [{psig_desc = Psig_modtype modtype_decl; _}] -> + module_declaration_expand ~ctxt modtype_decl + | Parsetree.PStr [{pstr_desc = _; _}] | Parsetree.PSig [{psig_desc = _; _}] -> + return_error + "[%%import] Expected a type declaration or a module type declaration" + | Parsetree.PStr (_ :: _) | Parsetree.PSig (_ :: _) -> + return_error + "[%%import] Expected exactly one item in the structure or signature, but \ + found multiple items" + | Parsetree.PStr [] | Parsetree.PSig [] -> + return_error + "[%%import] Expected exactly one item in the structure or signature, but \ + found none" + | Parsetree.PTyp _ -> + return_error + "[%%import] Type pattern (PTyp) is not supported, only type and module \ + type declarations are allowed" + | Parsetree.PPat (_, _) -> + return_error + "[%%import] Pattern (PPat) is not supported, only type and module type \ + declarations are allowed" let type_declaration_extension = Ppxlib.Extension.V3.declare "import" Ppxlib.Extension.Context.structure_item - Ppxlib.Ast_pattern.( - psig (psig_type __ __ ^:: nil) ||| pstr (pstr_type __ __ ^:: nil) ) - type_declaration_expand + Ppxlib.Ast_pattern.(__) + type_declaration_expander + +let type_declaration_expander_intf ~ctxt payload = + let return_error e = + let loc = Ppxlib.Expansion_context.Extension.extension_point_loc ctxt in + let ext = Ppxlib.Location.error_extensionf ~loc "%s" e in + Ppxlib.Ast_builder.Default.psig_extension ext [] ~loc + in + match payload with + | Parsetree.PStr [{pstr_desc = Pstr_type (rec_flag, type_decls); _}] + |Parsetree.PSig [{psig_desc = Psig_type (rec_flag, type_decls); _}] -> + type_declaration_expand_intf ~ctxt rec_flag type_decls + | Parsetree.PStr [{pstr_desc = Pstr_modtype modtype_decl; _}] + |Parsetree.PSig [{psig_desc = Psig_modtype modtype_decl; _}] -> + module_declaration_expand_intf ~ctxt modtype_decl + | Parsetree.PStr [{pstr_desc = _; _}] | Parsetree.PSig [{psig_desc = _; _}] -> + return_error + "[%%import] Expected a type declaration or a module type declaration" + | Parsetree.PStr (_ :: _) | Parsetree.PSig (_ :: _) -> + return_error + "[%%import] Expected exactly one item in the structure or signature, but \ + found multiple items" + | Parsetree.PStr [] | Parsetree.PSig [] -> + return_error + "[%%import] Expected exactly one item in the structure or signature, but \ + found none" + | Parsetree.PTyp _ -> + return_error + "[%%import] Type pattern (PTyp) is not supported, only type and module \ + type declarations are allowed" + | Parsetree.PPat (_, _) -> + return_error + "[%%import] Pattern (PPat) is not supported, only type and module type \ + declarations are allowed" let type_declaration_extension_intf = Ppxlib.Extension.V3.declare "import" Ppxlib.Extension.Context.signature_item - Ppxlib.Ast_pattern.( - psig (psig_type __ __ ^:: nil) ||| pstr (pstr_type __ __ ^:: nil) ) - type_declaration_expand_intf - -let module_declaration_extension = - Ppxlib.Extension.V3.declare "import" Ppxlib.Extension.Context.module_type - Ppxlib.Ast_pattern.(ptyp (ptyp_package __)) - module_declaration_expand + Ppxlib.Ast_pattern.(__) + type_declaration_expander_intf let type_declaration_rule = Ppxlib.Context_free.Rule.extension type_declaration_extension @@ -602,13 +730,7 @@ let type_declaration_rule = let type_declaration_rule_intf = Ppxlib.Context_free.Rule.extension type_declaration_extension_intf -let module_declaration_rule = - Ppxlib.Context_free.Rule.extension module_declaration_extension - let () = Ppxlib.Driver.V2.register_transformation - ~rules: - [ type_declaration_rule - ; module_declaration_rule - ; type_declaration_rule_intf ] + ~rules:[type_declaration_rule; type_declaration_rule_intf] "ppx_import" diff --git a/src_test/ppx_deriving/errors/run.t b/src_test/ppx_deriving/errors/run.t index 2578aec..b354522 100644 --- a/src_test/ppx_deriving/errors/run.t +++ b/src_test/ppx_deriving/errors/run.t @@ -38,13 +38,13 @@ Abstract module error > EOF $ cat >test.ml < module type T = [%import: (module Stuff.T)] + > module type%import T = Stuff.T > EOF $ dune build - File "test.ml", line 1, characters 34-41: - 1 | module type T = [%import: (module Stuff.T)] - ^^^^^^^ + File "test.ml", line 1, characters 23-30: + 1 | module type%import T = Stuff.T + ^^^^^^^ Error: Imported module is abstract [1] @@ -92,13 +92,13 @@ Cannot find module error > EOF $ cat >test.ml < module type A = [%import: (module Stuff.S.M)] + > module type%import A = Stuff.S.M > EOF $ dune build - File "test.ml", line 1, characters 34-43: - 1 | module type A = [%import: (module Stuff.S.M)] - ^^^^^^^^^ + File "test.ml", line 1, characters 23-32: + 1 | module type%import A = Stuff.S.M + ^^^^^^^^^ Error: [%import]: cannot find the module type M in Stuff.S [1] @@ -116,7 +116,8 @@ It's been fixed for later versions in https://github.com/ocaml/ocaml/pull/8541 1 | [%%import: 2 | type b = int 3 | type a = string] - Error: [] expected + Error: [%%import] Expected exactly one item in the structure or signature, + but found multiple items Ptyp $ cat >test.ml <test.ml < module type Hashable = [%import: (module sig type t end)] + > module type%import Hashable = sig type t end > EOF $ dune build - File "test.ml", line 1, characters 41-55: - 1 | module type Hashable = [%import: (module sig type t end)] - ^^^^^^^^^^^^^^ - Error: invalid package type: only module type identifier and 'with type' constraints are supported + File "test.ml", line 1, characters 30-44: + 1 | module type%import Hashable = sig type t end + ^^^^^^^^^^^^^^ + Error: [%%import] inline module type declaration is not supported [1] Functor $ cat >test.ml < module type Foo = [%import: (module functor (M : sig end) -> sig end)] + > module type%import Foo = functor (M : sig end) -> sig end > EOF $ dune build - File "test.ml", line 1, characters 44-68: - 1 | module type Foo = [%import: (module functor (M : sig end) -> sig end)] - ^^^^^^^^^^^^^^^^^^^^^^^^ - Error: invalid package type: only module type identifier and 'with type' constraints are supported + File "test.ml", line 1, characters 33-57: + 1 | module type%import Foo = functor (M : sig end) -> sig end + ^^^^^^^^^^^^^^^^^^^^^^^^ + Error: [%%import] module type doesn't support functor [1] Module type of $ cat >test.ml < module type Example = [%import: (module type of A)] + > module type%import Example = module type of A > EOF $ dune build - File "test.ml", line 1, characters 40-44: - 1 | module type Example = [%import: (module type of A)] - ^^^^ - Error: Syntax error + File "test.ml", line 1, characters 29-45: + 1 | module type%import Example = module type of A + ^^^^^^^^^^^^^^^^ + Error: [%%import] module type doesn't support typeof [1] Pmty_extension $ cat >test.ml < module type M = [%import: [%extension]] + > module type%import M = [%extension] > EOF $ dune build - File "test.ml", line 1, characters 26-38: - 1 | module type M = [%import: [%extension]] - ^^^^^^^^^^^^ - Error: package expected + File "test.ml", line 1, characters 23-35: + 1 | module type%import M = [%extension] + ^^^^^^^^^^^^ + Error: [%%import] module type doesn't support extension [1] Pwith_module @@ -192,17 +194,16 @@ Pwith_module > let hash = Hashtbl.hash > end > - > module type HashableWith = [%import: (module sig + > module type%import HashableWith = sig > include module type of StringHashable - > end with module StringHashable = StringHashable)] + > end with module StringHashable = StringHashable > EOF $ dune build - File "test.ml", lines 13-15, characters 45-47: - 13 | .............................................sig - 14 | include module type of StringHashable - 15 | end with module StringHashable = StringHashable.. - Error: invalid package type: only module type identifier and 'with type' constraints are supported + File "test.ml", line 15, characters 16-30: + 15 | end with module StringHashable = StringHashable + ^^^^^^^^^^^^^^ + Error: [%%import]: Pwith_module constraint is not supported. [1] Pwith_modtype @@ -219,29 +220,28 @@ Pwith_modtype > let hash = Hashtbl.hash > end > - > module type HashableWith = [%import: (module sig + > module type%import HashableWith = sig > include module type of StringHashable - > end with module type StringHashable = StringHashable)] + > end with module type StringHashable = StringHashable > EOF $ dune build - File "test.ml", lines 13-15, characters 45-52: - 13 | .............................................sig - 14 | include module type of StringHashable - 15 | end with module type StringHashable = StringHashable.. - Error: invalid package type: only module type identifier and 'with type' constraints are supported + File "test.ml", line 15, characters 21-35: + 15 | end with module type StringHashable = StringHashable + ^^^^^^^^^^^^^^ + Error: [%%import]: Pwith_modtype constraint is not supported. [1] Pwith_typesubst $ cat >test.ml < module type HashableWith = [%import: (module Hashtbl.HashedType with type t := string)] + > module type%import HashableWith = Hashtbl.HashedType with type t := string > EOF $ dune build - File "test.ml", line 1, characters 45-85: - 1 | module type HashableWith = [%import: (module Hashtbl.HashedType with type t := string)] - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - Error: invalid package type: only 'with type t =' constraints are supported + File "test.ml", line 1, characters 63-64: + 1 | module type%import HashableWith = Hashtbl.HashedType with type t := string + ^ + Error: [%%import]: Pwith_typesubst constraint is not supported. [1] Pwith_modtypesubst @@ -258,17 +258,16 @@ Pwith_modtypesubst > let hash = Hashtbl.hash > end > - > module type HashableWith = [%import: (module sig + > module type%import HashableWith = sig > include module type of StringHashable - > end with module type StringHashable := StringHashable)] + > end with module type StringHashable := StringHashable > EOF $ dune build - File "test.ml", lines 13-15, characters 45-53: - 13 | .............................................sig - 14 | include module type of StringHashable - 15 | end with module type StringHashable := StringHashable.. - Error: invalid package type: only module type identifier and 'with type' constraints are supported + File "test.ml", line 15, characters 21-35: + 15 | end with module type StringHashable := StringHashable + ^^^^^^^^^^^^^^ + Error: [%%import]: Pwith_modtypesubst constraint is not supported. [1] Pwith_modsubst @@ -285,15 +284,14 @@ Pwith_modsubst > let hash = Hashtbl.hash > end > - > module type HashableWith = [%import: (module sig + > module type%import HashableWith = sig > include module type of StringHashable - > end with module StringHashable := StringHashable)] + > end with module StringHashable := StringHashable > EOF $ dune build - File "test.ml", lines 13-15, characters 45-48: - 13 | .............................................sig - 14 | include module type of StringHashable - 15 | end with module StringHashable := StringHashable.. - Error: invalid package type: only module type identifier and 'with type' constraints are supported + File "test.ml", line 15, characters 16-30: + 15 | end with module StringHashable := StringHashable + ^^^^^^^^^^^^^^ + Error: [%%import]: Pwith_modsubst constraint is not supported. [1] diff --git a/src_test/ppx_deriving/errors_lte_407/run.t b/src_test/ppx_deriving/errors_lte_407/run.t index 5bd3a80..38be1ec 100644 --- a/src_test/ppx_deriving/errors_lte_407/run.t +++ b/src_test/ppx_deriving/errors_lte_407/run.t @@ -34,11 +34,13 @@ Abstract module error > EOF $ cat >test.ml < module type T = [%import: (module Stuff.T)] + > module type%import T = Stuff.T > EOF $ dune build - File "test.ml", line 1, characters 34-41: + File "test.ml", line 1, characters 23-30: + 1 | module type%import T = Stuff.T + ^^^^^^^ Error: Imported module is abstract [1] @@ -80,11 +82,13 @@ Cannot find module error > EOF $ cat >test.ml < module type A = [%import: (module Stuff.S.M)] + > module type%import A = Stuff.S.M > EOF $ dune build - File "test.ml", line 1, characters 34-43: + File "test.ml", line 1, characters 23-32: + 1 | module type%import A = Stuff.S.M + ^^^^^^^^^ Error: [%import]: cannot find the module type M in Stuff.S [1] @@ -108,55 +112,57 @@ Ptyp File "test.ml", line 1, characters 0-18: 1 | [%%import: string] ^^^^^^^^^^^^^^^^^^ - Error: PSig expected + Error: [%%import] Invalid extension usage. [%%import] only supports structure + items, signatures or type declarations, but a type pattern (PTyp) was + found. [1] Inline module type declaration $ cat >test.ml < module type Hashable = [%import: (module sig type t end)] + > module type%import Hashable = sig type t end > EOF $ dune build - File "test.ml", line 1, characters 41-55: - 1 | module type Hashable = [%import: (module sig type t end)] - ^^^^^^^^^^^^^^ - Error: invalid package type: only module type identifier and 'with type' constraints are supported + File "test.ml", line 1, characters 30-44: + 1 | module type%import Hashable = sig type t end + ^^^^^^^^^^^^^^ + Error: [%%import] inline module type declaration is not supported [1] Functor $ cat >test.ml < module type Foo = [%import: (module functor (M : sig end) -> sig end)] + > module type%import Foo = functor (M : sig end) -> sig end > EOF $ dune build - File "test.ml", line 1, characters 44-68: - 1 | module type Foo = [%import: (module functor (M : sig end) -> sig end)] - ^^^^^^^^^^^^^^^^^^^^^^^^ - Error: invalid package type: only module type identifier and 'with type' constraints are supported + File "test.ml", line 1, characters 33-57: + 1 | module type%import Foo = functor (M : sig end) -> sig end + ^^^^^^^^^^^^^^^^^^^^^^^^ + Error: [%%import] module type doesn't support functor [1] Module type of $ cat >test.ml < module type Example = [%import: (module type of A)] + > module type%import Example = module type of A > EOF $ dune build - File "test.ml", line 1, characters 40-44: - 1 | module type Example = [%import: (module type of A)] - ^^^^ - Error: Syntax error + File "test.ml", line 1, characters 29-45: + 1 | module type%import Example = module type of A + ^^^^^^^^^^^^^^^^ + Error: [%%import] module type doesn't support typeof [1] Pmty_extension $ cat >test.ml < module type M = [%import: [%extension]] + > module type%import M = [%extension] > EOF $ dune build - File "test.ml", line 1, characters 26-38: - 1 | module type M = [%import: [%extension]] - ^^^^^^^^^^^^ - Error: package expected + File "test.ml", line 1, characters 23-35: + 1 | module type%import M = [%extension] + ^^^^^^^^^^^^ + Error: [%%import] module type doesn't support extension [1] Pwith_module @@ -173,17 +179,16 @@ Pwith_module > let hash = Hashtbl.hash > end > - > module type HashableWith = [%import: (module sig + > module type%import HashableWith = sig > include module type of StringHashable - > end with module StringHashable = StringHashable)] + > end with module StringHashable = StringHashable > EOF $ dune build - File "test.ml", lines 13-15, characters 45-47: - 13 | .............................................sig - 14 | include module type of StringHashable - 15 | end with module StringHashable = StringHashable.. - Error: invalid package type: only module type identifier and 'with type' constraints are supported + File "test.ml", line 15, characters 16-30: + 15 | end with module StringHashable = StringHashable + ^^^^^^^^^^^^^^ + Error: [%%import]: Pwith_module constraint is not supported. [1] Pwith_modtype @@ -200,29 +205,28 @@ Pwith_modtype > let hash = Hashtbl.hash > end > - > module type HashableWith = [%import: (module sig + > module type%import HashableWith = sig > include module type of StringHashable - > end with module type StringHashable = StringHashable)] + > end with module type StringHashable = StringHashable > EOF $ dune build - File "test.ml", lines 13-15, characters 45-52: - 13 | .............................................sig - 14 | include module type of StringHashable - 15 | end with module type StringHashable = StringHashable.. - Error: invalid package type: only module type identifier and 'with type' constraints are supported + File "test.ml", line 15, characters 21-35: + 15 | end with module type StringHashable = StringHashable + ^^^^^^^^^^^^^^ + Error: [%%import]: Pwith_modtype constraint is not supported. [1] Pwith_typesubst $ cat >test.ml < module type HashableWith = [%import: (module Hashtbl.HashedType with type t := string)] + > module type%import HashableWith = Hashtbl.HashedType with type t := string > EOF $ dune build - File "test.ml", line 1, characters 45-85: - 1 | module type HashableWith = [%import: (module Hashtbl.HashedType with type t := string)] - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - Error: invalid package type: only 'with type t =' constraints are supported + File "test.ml", line 1, characters 63-64: + 1 | module type%import HashableWith = Hashtbl.HashedType with type t := string + ^ + Error: [%%import]: Pwith_typesubst constraint is not supported. [1] Pwith_modtypesubst @@ -239,17 +243,16 @@ Pwith_modtypesubst > let hash = Hashtbl.hash > end > - > module type HashableWith = [%import: (module sig + > module type%import HashableWith = sig > include module type of StringHashable - > end with module type StringHashable := StringHashable)] + > end with module type StringHashable := StringHashable > EOF $ dune build - File "test.ml", lines 13-15, characters 45-53: - 13 | .............................................sig - 14 | include module type of StringHashable - 15 | end with module type StringHashable := StringHashable.. - Error: invalid package type: only module type identifier and 'with type' constraints are supported + File "test.ml", line 15, characters 21-35: + 15 | end with module type StringHashable := StringHashable + ^^^^^^^^^^^^^^ + Error: [%%import]: Pwith_modtypesubst constraint is not supported. [1] Pwith_modsubst @@ -266,15 +269,14 @@ Pwith_modsubst > let hash = Hashtbl.hash > end > - > module type HashableWith = [%import: (module sig + > module type%import HashableWith = sig > include module type of StringHashable - > end with module StringHashable := StringHashable)] + > end with module StringHashable := StringHashable > EOF $ dune build - File "test.ml", lines 13-15, characters 45-48: - 13 | .............................................sig - 14 | include module type of StringHashable - 15 | end with module StringHashable := StringHashable.. - Error: invalid package type: only module type identifier and 'with type' constraints are supported + File "test.ml", line 15, characters 16-30: + 15 | end with module StringHashable := StringHashable + ^^^^^^^^^^^^^^ + Error: [%%import]: Pwith_modsubst constraint is not supported. [1] diff --git a/src_test/ppx_deriving/test_intf.ml b/src_test/ppx_deriving/test_intf.ml index e5d84e2..e3bedf5 100644 --- a/src_test/ppx_deriving/test_intf.ml +++ b/src_test/ppx_deriving/test_intf.ml @@ -1,5 +1,5 @@ [%%import: type a = Stuff.a] module type Example = sig - module type InnerModule = [%import: (module Stuff.S_optional)] + module type%import InnerModule = Stuff.S_optional end diff --git a/src_test/ppx_deriving/test_intf.mli b/src_test/ppx_deriving/test_intf.mli index e5d84e2..e3bedf5 100644 --- a/src_test/ppx_deriving/test_intf.mli +++ b/src_test/ppx_deriving/test_intf.mli @@ -1,5 +1,5 @@ [%%import: type a = Stuff.a] module type Example = sig - module type InnerModule = [%import: (module Stuff.S_optional)] + module type%import InnerModule = Stuff.S_optional end diff --git a/src_test/ppx_deriving/test_ppx_import.ml b/src_test/ppx_deriving/test_ppx_import.ml index c769a7a..e010c97 100644 --- a/src_test/ppx_deriving/test_ppx_import.ml +++ b/src_test/ppx_deriving/test_ppx_import.ml @@ -16,7 +16,7 @@ module MI = Stuff.MI [%%import: type i = Stuff.i] -module type S_rec = [%import: (module Stuff.S_rec)] +module type%import S_rec = Stuff.S_rec let test_constr _ctxt = ignore [A1; A2 "a"]; @@ -34,7 +34,7 @@ let test_constr _ctxt = let test_deriving _ctxt = assert_equal ~printer:(fun x -> x) "(Stuff.A2 \"a\")" (show_a' (A2 "a")) -module type S_optional = [%import: (module Stuff.S_optional)] +module type%import S_optional = Stuff.S_optional module Test_optional : S_optional = struct let f ?(opt = 0) () = ignore opt @@ -52,10 +52,8 @@ type package_type = Longident.t := (Longident.t [@printer pp_longident])] ) [@@deriving show]] -module type Hashable = [%import: (module Hashtbl.HashedType)] - -module type HashableWith = [%import: -(module Hashtbl.HashedType with type t = string)] +module type%import Hashable = Hashtbl.HashedType +module type%import HashableWith = Hashtbl.HashedType with type t = string module HashableWith : HashableWith = struct type t @@ -70,7 +68,7 @@ let test_self_import _ctxt = let v : self_t = `OptionA in Test_self_import.validate_option v -module type Self_S = [%import: (module Test_self_import.S)] +module type%import Self_S = Test_self_import.S module Self_M : Self_S = struct let test () = "test" diff --git a/src_test/ppx_deriving/test_self_import.ml b/src_test/ppx_deriving/test_self_import.ml index 3f03f3f..8001808 100644 --- a/src_test/ppx_deriving/test_self_import.ml +++ b/src_test/ppx_deriving/test_self_import.ml @@ -1,6 +1,6 @@ [%%import: type t = Test_self_import.t] -module type S = [%import: (module Test_self_import.S)] +module type%import S = Test_self_import.S let validate_option = function | `OptionA -> assert true