From 54d956823bdac4774d7cfb9143906691acc9ded9 Mon Sep 17 00:00:00 2001 From: Louis Gesbert Date: Fri, 1 Dec 2023 18:07:16 +0100 Subject: [PATCH] Some module fixes --- build_system/clerk_driver.ml | 18 ++++++++++-------- compiler/desugared/name_resolution.ml | 16 ++++------------ compiler/driver.ml | 2 +- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/build_system/clerk_driver.ml b/build_system/clerk_driver.ml index 2c1b7d84..cb87b5f4 100644 --- a/build_system/clerk_driver.ml +++ b/build_system/clerk_driver.ml @@ -578,8 +578,13 @@ let gen_build_statements ~outputs:[inc srcv] in let module_deps = - Option.map - (fun m -> Nj.build "phony" ~inputs:[inc srcv] ~outputs:[modd m]) + Option.map (fun m -> + Nj.build "phony" + ~inputs:[inc srcv; + (!Var.builddir / src /../ m) ^ ".cmi"; + (!Var.builddir / src /../ m) ^ ".cmxs"; + ] + ~outputs:[modd m]) item.module_def in let ml_file = @@ -604,7 +609,7 @@ let gen_build_statements | Some m -> let target ext = (!Var.builddir / src /../ m) ^ "." ^ ext in Nj.build "ocaml-module" ~inputs:[ml_file] - ~implicit_in:(List.map (modfile ".cmi") modules) + ~implicit_in:(List.map modd modules) ~outputs:[target "cmxs"] ~implicit_out:(List.map target implicit_out_exts) ~vars: @@ -656,6 +661,7 @@ let gen_build_statements ]) include_dirs @ List.map (fun m -> m ^ ".cmx") modules ); + (* FIXME: This doesn't work for module used through file inclusion *) ] in let expose_module = @@ -664,11 +670,7 @@ let gen_build_statements Some (Nj.build "phony" ~outputs:[m ^ "@module"] - ~inputs: - [ - (!Var.builddir / src /../ m) ^ ".cmi"; - (!Var.builddir / src /../ m) ^ ".cmxs"; - ]) + ~inputs:[modd m]) | _ -> None in let interp_deps = diff --git a/compiler/desugared/name_resolution.ml b/compiler/desugared/name_resolution.ml index d47ff646..58b0666c 100644 --- a/compiler/desugared/name_resolution.ml +++ b/compiler/desugared/name_resolution.ml @@ -1013,7 +1013,7 @@ let form_context (surface, mod_uses) surface_modules : context = disambiguation. This is only done towards the root context, because submodules are only interfaces which don't need disambiguation ; and transitive dependencies shouldn't be visible here. *) - let sub_constructor_idmap, sub_field_idmap = + let constructor_idmap, field_idmap = Ident.Map.fold (fun _ m (cmap, fmap) -> let lctx = ModuleName.Map.find m ctxt.modules in @@ -1029,22 +1029,14 @@ let form_context (surface, mod_uses) surface_modules : context = in cmap, fmap) mod_uses - (Ident.Map.empty, Ident.Map.empty) + (ctxt.local.constructor_idmap, ctxt.local.field_idmap) in { ctxt with local = { ctxt.local with - (* In the root context, don't disambiguate on submodules structs/enums - when there is a conflict *) - constructor_idmap = - Ident.Map.union - (fun _ base _ -> Some base) - ctxt.local.constructor_idmap sub_constructor_idmap; - field_idmap = - Ident.Map.union - (fun _ base _ -> Some base) - ctxt.local.field_idmap sub_field_idmap; + constructor_idmap; + field_idmap; }; } diff --git a/compiler/driver.ml b/compiler/driver.ml index a4362364..f5a4da15 100644 --- a/compiler/driver.ml +++ b/compiler/driver.ml @@ -81,7 +81,7 @@ let load_module_interfaces options includes program = "Circular module dependency" | None -> let intf = Surface.Parser_driver.load_interface (Cli.FileName f) in - let modname = ModuleName.fresh use.Surface.Ast.mod_use_name in + let modname = ModuleName.fresh intf.intf_modname in let seen = File.Map.add f None seen in let seen, sub_use_map = aux