From a4a6bf9dc8385c8a6b9e08440b9596d5db129c1c Mon Sep 17 00:00:00 2001 From: HasanA Date: Tue, 11 Jun 2024 17:01:36 +0200 Subject: [PATCH 01/19] Add support for -H Signed-off-by: HasanA --- src/dune_rules/compilation_context.ml | 43 +++++++++++++++-------- src/dune_rules/lib.ml | 9 ++--- src/dune_rules/lib.mli | 2 ++ src/dune_rules/lib_flags.ml | 50 ++++++++++++++++++++------- src/dune_rules/lib_flags.mli | 9 ++++- src/ocaml/version.ml | 1 + src/ocaml/version.mli | 3 ++ 7 files changed, 85 insertions(+), 32 deletions(-) diff --git a/src/dune_rules/compilation_context.ml b/src/dune_rules/compilation_context.ml index 3fdfad25023..9e64b6e22e3 100644 --- a/src/dune_rules/compilation_context.ml +++ b/src/dune_rules/compilation_context.ml @@ -3,24 +3,26 @@ open Import module Includes = struct type t = Command.Args.without_targets Command.Args.t Lib_mode.Cm_kind.Map.t - let make ~project ~opaque ~requires : _ Lib_mode.Cm_kind.Map.t = + let make ~project ~opaque ~requires ~direct : _ Lib_mode.Cm_kind.Map.t = (* TODO : some of the requires can filtered out using [ocamldep] info *) let open Resolve.Memo.O in - let iflags libs mode = Lib_flags.L.include_flags ~project libs mode in + let iflags libs mode direct = Lib_flags.L.include_flags ~project libs mode ~direct in let make_includes_args ~mode groups = Command.Args.memo (Resolve.Memo.args - (let+ libs = requires in + (let+ libs = requires + and+ direct = direct in Command.Args.S - [ iflags libs mode; Hidden_deps (Lib_file_deps.deps libs ~groups) ])) + [ iflags libs mode direct; Hidden_deps (Lib_file_deps.deps libs ~groups) ])) in let cmi_includes = make_includes_args ~mode:(Ocaml Byte) [ Ocaml Cmi ] in let cmx_includes = Command.Args.memo (Resolve.Memo.args - (let+ libs = requires in + (let+ libs = requires + and+ direct = direct in Command.Args.S - [ iflags libs (Ocaml Native) + [ iflags libs (Ocaml Native) direct ; Hidden_deps (if opaque then @@ -139,12 +141,24 @@ let create = let open Memo.O in let project = Scope.project scope in - let requires_compile = + let context = Super_context.context super_context in + let sandbox = Sandbox_config.no_special_requirements in + let* ocaml = Context.ocaml context in + let requires, direct = if Dune_project.implicit_transitive_deps project - then Memo.Lazy.force requires_link - else requires_compile + then Memo.Lazy.force requires_link, Resolve.Memo.return (fun _ -> true) + else if Version.supports_hidden_includes ocaml.version + && Dune_project.dune_version project >= (3, 17) + then ( + let direct = + let open Resolve.Memo.O in + let+ requires = requires_compile in + let requires = Lib.Tbl.of_list_exn (List.map ~f:(fun lib -> lib, ()) requires) in + Lib.Tbl.mem requires + in + Memo.Lazy.force requires_link, direct) + else requires_compile, Resolve.Memo.return (fun _ -> true) in - let sandbox = Sandbox_config.no_special_requirements in let modes = let default = { Lib_mode.Map.ocaml = Mode.Dict.make_both (Some Mode_conf.Kind.Inherited) @@ -153,8 +167,6 @@ let create in Option.value ~default modes |> Lib_mode.Map.map ~f:Option.is_some in - let context = Super_context.context super_context in - let* ocaml = Context.ocaml context in let opaque = let profile = Context.profile context in eval_opaque ocaml profile opaque @@ -182,7 +194,7 @@ let create ; flags ; requires_compile ; requires_link - ; includes = Includes.make ~project ~opaque ~requires:requires_compile + ; includes = Includes.make ~project ~opaque ~requires ~direct ; preprocessing ; opaque ; stdlib @@ -263,8 +275,11 @@ let for_module_generated_at_link_time cctx ~requires ~module_ = their implementation must also be compiled with -opaque *) Ocaml.Version.supports_opaque_for_mli cctx.ocaml.version in + let direct = Resolve.Memo.return (fun _ -> true) in let modules = singleton_modules module_ in - let includes = Includes.make ~project:(Scope.project cctx.scope) ~opaque ~requires in + let includes = + Includes.make ~project:(Scope.project cctx.scope) ~opaque ~requires ~direct + in { cctx with opaque ; flags = Ocaml_flags.empty diff --git a/src/dune_rules/lib.ml b/src/dune_rules/lib.ml index f129465994f..4df810e4745 100644 --- a/src/dune_rules/lib.ml +++ b/src/dune_rules/lib.ml @@ -350,6 +350,10 @@ module T = struct Dyn.record [ "name", Lib_name.to_dyn t.name; "loc", Loc.to_dyn_hum (Lib_info.loc t.info) ] ;; + + (* We can't write a structural equality because of all the lazy fields *) + let equal : t -> t -> bool = phys_equal + let hash = Poly.hash end include T @@ -469,11 +473,8 @@ let wrapped t = | Some (This x) -> Some x) ;; -(* We can't write a structural equality because of all the lazy fields *) -let equal : t -> t -> bool = phys_equal -let hash = Poly.hash - include Comparable.Make (T) +module Tbl = Hashtbl.Make (T) module L = struct let top_closure l ~key ~deps = diff --git a/src/dune_rules/lib.mli b/src/dune_rules/lib.mli index 4952c57067e..9793f5654ec 100644 --- a/src/dune_rules/lib.mli +++ b/src/dune_rules/lib.mli @@ -235,3 +235,5 @@ module Local : sig include Comparable_intf.S with type key := t end + +module Tbl : Hashtbl.S with type key := t diff --git a/src/dune_rules/lib_flags.ml b/src/dune_rules/lib_flags.ml index 3eab4dd2fe8..af8d00fd22f 100644 --- a/src/dune_rules/lib_flags.ml +++ b/src/dune_rules/lib_flags.ml @@ -92,10 +92,17 @@ module L = struct |> List.rev) ;; - let remove_stdlib dirs libs = + let to_flags dirs = + Command.Args.S + (Path.Map.foldi dirs ~init:[] ~f:(fun dir direct acc -> + Command.Args.Path dir :: A (if direct then "-I" else "-H") :: acc) + |> List.rev) + ;; + + let remove_stdlib dirs libs remove = match libs with | [] -> dirs - | lib :: _ -> Path.Set.remove dirs (Lib.lib_config lib).stdlib_dir + | lib :: _ -> remove dirs (Lib.lib_config lib).stdlib_dir ;; type mode = @@ -103,8 +110,8 @@ module L = struct ; melange_emit : bool } - let include_paths = - let add_public_dir ~visible_cmi obj_dir acc mode = + let include_paths_gen ~init ~add ~remove = + let add_public_dir ~visible_cmi obj_dir acc mode add lib = match visible_cmi with | false -> acc | true -> @@ -121,7 +128,7 @@ module L = struct `import` information *) [ Obj_dir.melange_dir; Obj_dir.public_cmi_melange_dir ]) in - List.fold_left public_cmi_dirs ~init:acc ~f:Path.Set.add + List.fold_left public_cmi_dirs ~init:acc ~f:(fun acc path -> add acc path lib) in fun ?project ts mode -> let visible_cmi = @@ -139,24 +146,41 @@ module L = struct | _ -> true) in let dirs = - List.fold_left ts ~init:Path.Set.empty ~f:(fun acc t -> + List.fold_left ts ~init ~f:(fun acc t -> let obj_dir = Lib_info.obj_dir (Lib.info t) in let visible_cmi = visible_cmi t in match mode.lib_mode with - | Melange -> add_public_dir ~visible_cmi obj_dir acc mode + | Melange -> add_public_dir ~visible_cmi obj_dir acc mode add t | Ocaml ocaml_mode -> - let acc = add_public_dir ~visible_cmi obj_dir acc mode in + let acc = add_public_dir ~visible_cmi obj_dir acc mode add t in (match ocaml_mode with | Byte -> acc | Native -> let native_dir = Obj_dir.native_dir obj_dir in - Path.Set.add acc native_dir)) + add acc native_dir t)) in - remove_stdlib dirs ts + remove_stdlib dirs ts remove ;; - let include_flags ?project ts mode = - to_iflags (include_paths ?project ts { lib_mode = mode; melange_emit = false }) + let include_flags ?project ?(direct = fun _ -> true) ts mode = + to_flags + (include_paths_gen + ?project + ts + { lib_mode = mode; melange_emit = false } + ~init:Path.Map.empty + ~add:(fun acc p l -> Path.Map.set acc p (direct l)) + ~remove:Path.Map.remove) + ;; + + let include_paths ?project ts mode = + include_paths_gen + ?project + ts + mode + ~init:Path.Set.empty + ~add:(fun acc p _ -> Path.Set.add acc p) + ~remove:Path.Set.remove ;; let melange_emission_include_flags ?project ts = @@ -173,7 +197,7 @@ module L = struct let src_dir = Lib_info.src_dir (Lib.info t) in Path.Set.add acc src_dir) in - remove_stdlib dirs ts + remove_stdlib dirs ts Path.Set.remove ;; let c_include_flags ts sctx = diff --git a/src/dune_rules/lib_flags.mli b/src/dune_rules/lib_flags.mli index 1faa6dee7b7..d66c7deada5 100644 --- a/src/dune_rules/lib_flags.mli +++ b/src/dune_rules/lib_flags.mli @@ -24,7 +24,14 @@ module L : sig val to_iflags : Path.Set.t -> _ Command.Args.t val include_paths : ?project:Dune_project.t -> t -> Lib_mode.t -> Path.Set.t - val include_flags : ?project:Dune_project.t -> t -> Lib_mode.t -> _ Command.Args.t + + val include_flags + : ?project:Dune_project.t + -> ?direct:(Lib.t -> bool) + -> t + -> Lib_mode.t + -> _ Command.Args.t + val melange_emission_include_flags : ?project:Dune_project.t -> t -> _ Command.Args.t val c_include_flags : t -> Super_context.t -> _ Command.Args.t val toplevel_ld_paths : t -> Path.Set.t diff --git a/src/ocaml/version.ml b/src/ocaml/version.ml index fba7b9e1a25..3caf3c7c444 100644 --- a/src/ocaml/version.ml +++ b/src/ocaml/version.ml @@ -29,3 +29,4 @@ let supports_alerts version = version >= (4, 8, 0) let has_sandboxed_otherlibs version = version >= (5, 0, 0) let has_META_files version = version >= (5, 0, 0) let supports_bin_annot_occurrences version = version >= (5, 2, 0) +let supports_hidden_includes version = version >= (5, 2, 0) diff --git a/src/ocaml/version.mli b/src/ocaml/version.mli index f7da69ad2b1..dc79429144e 100644 --- a/src/ocaml/version.mli +++ b/src/ocaml/version.mli @@ -76,3 +76,6 @@ val has_META_files : t -> bool (** Whether the compiler supports occurrences indexation *) val supports_bin_annot_occurrences : t -> bool + +(** Whether the compiler supports the -H flag *) +val supports_hidden_includes : t -> bool From 663ec11a39766d4968d3b7df353c935f920ed390 Mon Sep 17 00:00:00 2001 From: HasanA Date: Tue, 11 Jun 2024 17:04:46 +0200 Subject: [PATCH 02/19] Add tests Signed-off-by: HasanA --- .../test-cases/hidden-deps.t/bar.ml | 3 ++ .../test-cases/hidden-deps.t/dune | 18 ++++++++++ .../test-cases/hidden-deps.t/foo.ml | 3 ++ .../test-cases/hidden-deps.t/run.ml | 1 + .../test-cases/hidden-deps.t/run.t | 36 +++++++++++++++++++ .../test-cases/hidden-deps.t/runf.ml | 1 + .../test-cases/hidden-deps.t/tyxml/dune | 3 ++ .../hidden-deps.t/tyxml/dune-project | 2 ++ .../test-cases/hidden-deps.t/tyxml/run.ml | 2 ++ .../test-cases/hidden-deps.t/tyxml/run.t | 5 +++ 10 files changed, 74 insertions(+) create mode 100644 test/blackbox-tests/test-cases/hidden-deps.t/bar.ml create mode 100644 test/blackbox-tests/test-cases/hidden-deps.t/dune create mode 100644 test/blackbox-tests/test-cases/hidden-deps.t/foo.ml create mode 100644 test/blackbox-tests/test-cases/hidden-deps.t/run.ml create mode 100644 test/blackbox-tests/test-cases/hidden-deps.t/run.t create mode 100644 test/blackbox-tests/test-cases/hidden-deps.t/runf.ml create mode 100644 test/blackbox-tests/test-cases/hidden-deps.t/tyxml/dune create mode 100644 test/blackbox-tests/test-cases/hidden-deps.t/tyxml/dune-project create mode 100644 test/blackbox-tests/test-cases/hidden-deps.t/tyxml/run.ml create mode 100644 test/blackbox-tests/test-cases/hidden-deps.t/tyxml/run.t diff --git a/test/blackbox-tests/test-cases/hidden-deps.t/bar.ml b/test/blackbox-tests/test-cases/hidden-deps.t/bar.ml new file mode 100644 index 00000000000..e1ca0d9c772 --- /dev/null +++ b/test/blackbox-tests/test-cases/hidden-deps.t/bar.ml @@ -0,0 +1,3 @@ +let x = 5 + +let y = Foo.v \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/hidden-deps.t/dune b/test/blackbox-tests/test-cases/hidden-deps.t/dune new file mode 100644 index 00000000000..1807d44beba --- /dev/null +++ b/test/blackbox-tests/test-cases/hidden-deps.t/dune @@ -0,0 +1,18 @@ +(library + (name foo) + (modules foo)) + +(library + (name bar) + (modules bar) + (libraries foo)) + +(executable + (name run) + (modules run) + (libraries bar)) + + (executable + (name runf) + (modules runf) + (libraries bar)) diff --git a/test/blackbox-tests/test-cases/hidden-deps.t/foo.ml b/test/blackbox-tests/test-cases/hidden-deps.t/foo.ml new file mode 100644 index 00000000000..233654b2d90 --- /dev/null +++ b/test/blackbox-tests/test-cases/hidden-deps.t/foo.ml @@ -0,0 +1,3 @@ +let v = 9 + +let w = 4 \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/hidden-deps.t/run.ml b/test/blackbox-tests/test-cases/hidden-deps.t/run.ml new file mode 100644 index 00000000000..4be93f9760e --- /dev/null +++ b/test/blackbox-tests/test-cases/hidden-deps.t/run.ml @@ -0,0 +1 @@ +let _ = Bar.y \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/hidden-deps.t/run.t b/test/blackbox-tests/test-cases/hidden-deps.t/run.t new file mode 100644 index 00000000000..f058673ff79 --- /dev/null +++ b/test/blackbox-tests/test-cases/hidden-deps.t/run.t @@ -0,0 +1,36 @@ +Should include Foo with -H: + + $ getincludes () { + > dune build --verbose ./run.exe 2>&1 | grep run.ml | grep -E -o "\-$1\s(.foo)\S*" | sed s/\-$1//g | tr -d '[:space:]' + > } + + $ supports_H=$(if ocamlc -H x --help >/dev/null 2>&1; then echo true; else echo false; fi) + $ fooincludes='.foo.objs/byte.foo.objs/byte.foo.objs/native' + $ cat >dune-project < (lang dune 3.17) + > (implicit_transitive_deps true) + > EOF + + $ if $supports_H; then [ "$(getincludes I)" = $fooincludes ]; fi + $ if ! $supports_H; then [ "$(getincludes I)" = $fooincludes ]; fi + + $ cat >dune-project < (lang dune 3.17) + > (implicit_transitive_deps false) + > EOF + + $ if $supports_H; then [ "$(getincludes H)" = $fooincludes ]; fi + $ if ! $supports_H; then [ "$(getincludes I)" = '' ]; fi + + +Test transitive deps can not be directly accessed, both for compiler versions supporting -H or not: + $ cat >dune-project < (lang dune 3.17) + > (implicit_transitive_deps false) + > EOF + + $ dune build ./runf.exe 2>&1 | grep -v ocamlc + File "runf.ml", line 1, characters 16-21: + 1 | let a = Bar.y + Foo.v + ^^^^^ + Error: Unbound module Foo diff --git a/test/blackbox-tests/test-cases/hidden-deps.t/runf.ml b/test/blackbox-tests/test-cases/hidden-deps.t/runf.ml new file mode 100644 index 00000000000..3e7e6b04ba1 --- /dev/null +++ b/test/blackbox-tests/test-cases/hidden-deps.t/runf.ml @@ -0,0 +1 @@ +let a = Bar.y + Foo.v \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/hidden-deps.t/tyxml/dune b/test/blackbox-tests/test-cases/hidden-deps.t/tyxml/dune new file mode 100644 index 00000000000..fd768950796 --- /dev/null +++ b/test/blackbox-tests/test-cases/hidden-deps.t/tyxml/dune @@ -0,0 +1,3 @@ +(executable + (name run) + (libraries tyxml)) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/hidden-deps.t/tyxml/dune-project b/test/blackbox-tests/test-cases/hidden-deps.t/tyxml/dune-project new file mode 100644 index 00000000000..fff9b78b842 --- /dev/null +++ b/test/blackbox-tests/test-cases/hidden-deps.t/tyxml/dune-project @@ -0,0 +1,2 @@ +(lang dune 3.17) +(implicit_transitive_deps false) diff --git a/test/blackbox-tests/test-cases/hidden-deps.t/tyxml/run.ml b/test/blackbox-tests/test-cases/hidden-deps.t/tyxml/run.ml new file mode 100644 index 00000000000..68818fbad58 --- /dev/null +++ b/test/blackbox-tests/test-cases/hidden-deps.t/tyxml/run.ml @@ -0,0 +1,2 @@ +open Tyxml.Html +let _ = p [ a [ txt "a" ] ] \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/hidden-deps.t/tyxml/run.t b/test/blackbox-tests/test-cases/hidden-deps.t/tyxml/run.t new file mode 100644 index 00000000000..35c0613b159 --- /dev/null +++ b/test/blackbox-tests/test-cases/hidden-deps.t/tyxml/run.t @@ -0,0 +1,5 @@ +Test if the issue #274 is solved: the tyxml.functor is included with -H flag in +ITD = false case, and thus no type abstraction happens when it is used. + + $ ocamlc -H x --help > /dev/null + $ if [ $? = 0 ]; then dune build fi From 42f179869a88a9cb8a4fe65e17a588ec184e3939 Mon Sep 17 00:00:00 2001 From: HasanA Date: Fri, 14 Jun 2024 16:17:10 +0200 Subject: [PATCH 03/19] fix: requires_compile returns the correct deps Signed-off-by: HasanA --- src/dune_rules/compilation_context.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dune_rules/compilation_context.ml b/src/dune_rules/compilation_context.ml index 9e64b6e22e3..bdd8f59f3fc 100644 --- a/src/dune_rules/compilation_context.ml +++ b/src/dune_rules/compilation_context.ml @@ -192,7 +192,7 @@ let create ; obj_dir ; modules = { modules; dep_graphs } ; flags - ; requires_compile + ; requires_compile = requires ; requires_link ; includes = Includes.make ~project ~opaque ~requires ~direct ; preprocessing From 1bf8bf8d922e1a7df000680f69b074b41ab7ef8b Mon Sep 17 00:00:00 2001 From: HasanA Date: Tue, 18 Jun 2024 15:06:37 +0200 Subject: [PATCH 04/19] add requires_hidden list + adpat lib_flags to use the new list Signed-off-by: HasanA --- src/dune_rules/compilation_context.ml | 75 +++++++++++++++++--------- src/dune_rules/compilation_context.mli | 1 + src/dune_rules/lib_flags.ml | 57 +++++++++----------- src/dune_rules/lib_flags.mli | 9 +--- 4 files changed, 75 insertions(+), 67 deletions(-) diff --git a/src/dune_rules/compilation_context.ml b/src/dune_rules/compilation_context.ml index bdd8f59f3fc..f65044cd025 100644 --- a/src/dune_rules/compilation_context.ml +++ b/src/dune_rules/compilation_context.ml @@ -3,38 +3,51 @@ open Import module Includes = struct type t = Command.Args.without_targets Command.Args.t Lib_mode.Cm_kind.Map.t - let make ~project ~opaque ~requires ~direct : _ Lib_mode.Cm_kind.Map.t = + let make + ~project + ~opaque + ~direct_requires + ~(hidden_requires : Lib_flags.L.t Resolve.Memo.t) + : _ Lib_mode.Cm_kind.Map.t + = (* TODO : some of the requires can filtered out using [ocamldep] info *) let open Resolve.Memo.O in - let iflags libs mode direct = Lib_flags.L.include_flags ~project libs mode ~direct in + let iflags direct_libs hidden_libs mode = + Lib_flags.L.include_flags ~project direct_libs hidden_libs mode + in let make_includes_args ~mode groups = Command.Args.memo (Resolve.Memo.args - (let+ libs = requires - and+ direct = direct in + (let+ direct_libs = direct_requires + and+ hidden_libs = hidden_requires in Command.Args.S - [ iflags libs mode direct; Hidden_deps (Lib_file_deps.deps libs ~groups) ])) + [ iflags direct_libs hidden_libs mode + ; Hidden_deps + (Lib_file_deps.deps (List.concat [ direct_libs; hidden_libs ]) ~groups) + ])) in let cmi_includes = make_includes_args ~mode:(Ocaml Byte) [ Ocaml Cmi ] in let cmx_includes = Command.Args.memo (Resolve.Memo.args - (let+ libs = requires - and+ direct = direct in + (let+ direct_libs = direct_requires + and+ hidden_libs = hidden_requires in Command.Args.S - [ iflags libs (Ocaml Native) direct + [ iflags direct_libs hidden_libs (Ocaml Native) ; Hidden_deps (if opaque then - List.map libs ~f:(fun lib -> - ( lib - , if Lib.is_local lib - then [ Lib_file_deps.Group.Ocaml Cmi ] - else [ Ocaml Cmi; Ocaml Cmx ] )) + List.map + (List.concat [ direct_libs; hidden_libs ]) + ~f:(fun lib -> + ( lib + , if Lib.is_local lib + then [ Lib_file_deps.Group.Ocaml Cmi ] + else [ Ocaml Cmi; Ocaml Cmx ] )) |> Lib_file_deps.deps_with_exts else Lib_file_deps.deps - libs + (List.concat [ direct_libs; hidden_libs ]) ~groups:[ Lib_file_deps.Group.Ocaml Cmi; Ocaml Cmx ]) ])) in @@ -76,6 +89,7 @@ type t = ; modules : modules ; flags : Ocaml_flags.t ; requires_compile : Lib.t list Resolve.Memo.t + ; requires_hidden : Lib.t list Resolve.Memo.t ; requires_link : Lib.t list Resolve.t Memo.Lazy.t ; includes : Includes.t ; preprocessing : Pp_spec.t @@ -101,6 +115,7 @@ let obj_dir t = t.obj_dir let modules t = t.modules.modules let flags t = t.flags let requires_compile t = t.requires_compile +let requires_hidden t = t.requires_hidden let requires_link t = Memo.Lazy.force t.requires_link let includes t = t.includes let preprocessing t = t.preprocessing @@ -144,20 +159,22 @@ let create let context = Super_context.context super_context in let sandbox = Sandbox_config.no_special_requirements in let* ocaml = Context.ocaml context in - let requires, direct = + let direct_requires, hidden_requires = if Dune_project.implicit_transitive_deps project - then Memo.Lazy.force requires_link, Resolve.Memo.return (fun _ -> true) + then Memo.Lazy.force requires_link, Resolve.Memo.return [] else if Version.supports_hidden_includes ocaml.version && Dune_project.dune_version project >= (3, 17) then ( - let direct = + let requires_hidden = let open Resolve.Memo.O in - let+ requires = requires_compile in - let requires = Lib.Tbl.of_list_exn (List.map ~f:(fun lib -> lib, ()) requires) in - Lib.Tbl.mem requires + let+ requires = requires_compile + and+ requires_link = Memo.Lazy.force requires_link in + let requires_table = Table.create (module Lib) 500 in + let () = List.iter ~f:(fun lib -> Table.set requires_table lib ()) requires in + List.filter requires_link ~f:(fun l -> not (Table.mem requires_table l)) in - Memo.Lazy.force requires_link, direct) - else requires_compile, Resolve.Memo.return (fun _ -> true) + requires_compile, requires_hidden) + else requires_compile, Resolve.Memo.return [] in let modes = let default = @@ -192,9 +209,10 @@ let create ; obj_dir ; modules = { modules; dep_graphs } ; flags - ; requires_compile = requires + ; requires_compile = direct_requires + ; requires_hidden = hidden_requires ; requires_link - ; includes = Includes.make ~project ~opaque ~requires ~direct + ; includes = Includes.make ~project ~opaque ~direct_requires ~hidden_requires ; preprocessing ; opaque ; stdlib @@ -275,10 +293,15 @@ let for_module_generated_at_link_time cctx ~requires ~module_ = their implementation must also be compiled with -opaque *) Ocaml.Version.supports_opaque_for_mli cctx.ocaml.version in - let direct = Resolve.Memo.return (fun _ -> true) in + let direct_requires = requires in + let hidden_requires = Resolve.Memo.return [] in let modules = singleton_modules module_ in let includes = - Includes.make ~project:(Scope.project cctx.scope) ~opaque ~requires ~direct + Includes.make + ~project:(Scope.project cctx.scope) + ~opaque + ~direct_requires + ~hidden_requires in { cctx with opaque diff --git a/src/dune_rules/compilation_context.mli b/src/dune_rules/compilation_context.mli index 643466e623a..9924ea719a6 100644 --- a/src/dune_rules/compilation_context.mli +++ b/src/dune_rules/compilation_context.mli @@ -55,6 +55,7 @@ val obj_dir : t -> Path.Build.t Obj_dir.t val modules : t -> Modules.With_vlib.t val flags : t -> Ocaml_flags.t val requires_link : t -> Lib.t list Resolve.Memo.t +val requires_hidden : t -> Lib.t list Resolve.Memo.t val requires_compile : t -> Lib.t list Resolve.Memo.t val includes : t -> Command.Args.without_targets Command.Args.t Lib_mode.Cm_kind.Map.t val preprocessing : t -> Pp_spec.t diff --git a/src/dune_rules/lib_flags.ml b/src/dune_rules/lib_flags.ml index af8d00fd22f..496f1476ee7 100644 --- a/src/dune_rules/lib_flags.ml +++ b/src/dune_rules/lib_flags.ml @@ -92,17 +92,17 @@ module L = struct |> List.rev) ;; - let to_flags dirs = + let to_hflags dirs = Command.Args.S - (Path.Map.foldi dirs ~init:[] ~f:(fun dir direct acc -> - Command.Args.Path dir :: A (if direct then "-I" else "-H") :: acc) + (Path.Set.fold dirs ~init:[] ~f:(fun dir acc -> + Command.Args.Path dir :: A "-H" :: acc) |> List.rev) ;; - let remove_stdlib dirs libs remove = + let remove_stdlib dirs libs = match libs with | [] -> dirs - | lib :: _ -> remove dirs (Lib.lib_config lib).stdlib_dir + | lib :: _ -> Path.Set.remove dirs (Lib.lib_config lib).stdlib_dir ;; type mode = @@ -110,8 +110,8 @@ module L = struct ; melange_emit : bool } - let include_paths_gen ~init ~add ~remove = - let add_public_dir ~visible_cmi obj_dir acc mode add lib = + let include_paths = + let add_public_dir ~visible_cmi obj_dir acc mode = match visible_cmi with | false -> acc | true -> @@ -128,7 +128,7 @@ module L = struct `import` information *) [ Obj_dir.melange_dir; Obj_dir.public_cmi_melange_dir ]) in - List.fold_left public_cmi_dirs ~init:acc ~f:(fun acc path -> add acc path lib) + List.fold_left public_cmi_dirs ~init:acc ~f:Path.Set.add in fun ?project ts mode -> let visible_cmi = @@ -146,41 +146,32 @@ module L = struct | _ -> true) in let dirs = - List.fold_left ts ~init ~f:(fun acc t -> + List.fold_left ts ~init:Path.Set.empty ~f:(fun acc t -> let obj_dir = Lib_info.obj_dir (Lib.info t) in let visible_cmi = visible_cmi t in match mode.lib_mode with - | Melange -> add_public_dir ~visible_cmi obj_dir acc mode add t + | Melange -> add_public_dir ~visible_cmi obj_dir acc mode | Ocaml ocaml_mode -> - let acc = add_public_dir ~visible_cmi obj_dir acc mode add t in + let acc = add_public_dir ~visible_cmi obj_dir acc mode in (match ocaml_mode with | Byte -> acc | Native -> let native_dir = Obj_dir.native_dir obj_dir in - add acc native_dir t)) + Path.Set.add acc native_dir)) in - remove_stdlib dirs ts remove - ;; - - let include_flags ?project ?(direct = fun _ -> true) ts mode = - to_flags - (include_paths_gen - ?project - ts - { lib_mode = mode; melange_emit = false } - ~init:Path.Map.empty - ~add:(fun acc p l -> Path.Map.set acc p (direct l)) - ~remove:Path.Map.remove) + remove_stdlib dirs ts ;; - let include_paths ?project ts mode = - include_paths_gen - ?project - ts - mode - ~init:Path.Set.empty - ~add:(fun acc p _ -> Path.Set.add acc p) - ~remove:Path.Set.remove + let include_flags ?project ts_direct ts_hidden mode = + let hidden_includes = + to_hflags + (include_paths ?project ts_hidden { lib_mode = mode; melange_emit = false }) + in + let direct_includes = + to_iflags + (include_paths ?project ts_direct { lib_mode = mode; melange_emit = false }) + in + Command.Args.S [ direct_includes; hidden_includes ] ;; let melange_emission_include_flags ?project ts = @@ -197,7 +188,7 @@ module L = struct let src_dir = Lib_info.src_dir (Lib.info t) in Path.Set.add acc src_dir) in - remove_stdlib dirs ts Path.Set.remove + remove_stdlib dirs ts ;; let c_include_flags ts sctx = diff --git a/src/dune_rules/lib_flags.mli b/src/dune_rules/lib_flags.mli index d66c7deada5..5d8a3e3c4d3 100644 --- a/src/dune_rules/lib_flags.mli +++ b/src/dune_rules/lib_flags.mli @@ -24,14 +24,7 @@ module L : sig val to_iflags : Path.Set.t -> _ Command.Args.t val include_paths : ?project:Dune_project.t -> t -> Lib_mode.t -> Path.Set.t - - val include_flags - : ?project:Dune_project.t - -> ?direct:(Lib.t -> bool) - -> t - -> Lib_mode.t - -> _ Command.Args.t - + val include_flags : ?project:Dune_project.t -> t -> t -> Lib_mode.t -> _ Command.Args.t val melange_emission_include_flags : ?project:Dune_project.t -> t -> _ Command.Args.t val c_include_flags : t -> Super_context.t -> _ Command.Args.t val toplevel_ld_paths : t -> Path.Set.t From 18935364a836b631039f3d55367f1d3b22aa6ac7 Mon Sep 17 00:00:00 2001 From: HasanA Date: Tue, 18 Jun 2024 15:12:28 +0200 Subject: [PATCH 05/19] removed Hashtbl from lib.ml + ocaml_index.ml adapted to requires_hidden (to be re-checked) Signed-off-by: HasanA --- src/dune_rules/lib.ml | 9 ++++----- src/dune_rules/lib.mli | 2 -- src/dune_rules/merlin/ocaml_index.ml | 6 ++---- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/dune_rules/lib.ml b/src/dune_rules/lib.ml index 4df810e4745..f129465994f 100644 --- a/src/dune_rules/lib.ml +++ b/src/dune_rules/lib.ml @@ -350,10 +350,6 @@ module T = struct Dyn.record [ "name", Lib_name.to_dyn t.name; "loc", Loc.to_dyn_hum (Lib_info.loc t.info) ] ;; - - (* We can't write a structural equality because of all the lazy fields *) - let equal : t -> t -> bool = phys_equal - let hash = Poly.hash end include T @@ -473,8 +469,11 @@ let wrapped t = | Some (This x) -> Some x) ;; +(* We can't write a structural equality because of all the lazy fields *) +let equal : t -> t -> bool = phys_equal +let hash = Poly.hash + include Comparable.Make (T) -module Tbl = Hashtbl.Make (T) module L = struct let top_closure l ~key ~deps = diff --git a/src/dune_rules/lib.mli b/src/dune_rules/lib.mli index 9793f5654ec..4952c57067e 100644 --- a/src/dune_rules/lib.mli +++ b/src/dune_rules/lib.mli @@ -235,5 +235,3 @@ module Local : sig include Comparable_intf.S with type key := t end - -module Tbl : Hashtbl.S with type key := t diff --git a/src/dune_rules/merlin/ocaml_index.ml b/src/dune_rules/merlin/ocaml_index.ml index 561f6a88099..70fde70d78a 100644 --- a/src/dune_rules/merlin/ocaml_index.ml +++ b/src/dune_rules/merlin/ocaml_index.ml @@ -32,11 +32,9 @@ let cctx_rules cctx = The implicit transitive libs correspond to the set: (requires_link \ req_compile) *) - let* req_link = Compilation_context.requires_link cctx in - let+ req_compile = Compilation_context.requires_compile cctx in - List.filter req_link ~f:(fun l -> not (List.exists req_compile ~f:(Lib.equal l))) + Compilation_context.requires_hidden cctx in - Lib_flags.L.include_flags non_compile_libs (Lib_mode.Ocaml Byte) + Lib_flags.L.include_flags [] non_compile_libs (Lib_mode.Ocaml Byte) in (* Indexing depends (recursively) on [required_compile] libs: - These libs's cmt files should be built before indexing starts From 0c07a7702dcaf7c444078ff86283cabd34c65223 Mon Sep 17 00:00:00 2001 From: HasanA Date: Fri, 21 Jun 2024 11:53:11 +0200 Subject: [PATCH 06/19] some code cleaning Signed-off-by: HasanA --- src/dune_rules/compilation_context.ml | 8 +------- src/dune_rules/lib_flags.ml | 22 ++++++---------------- src/dune_rules/lib_flags.mli | 2 +- 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/dune_rules/compilation_context.ml b/src/dune_rules/compilation_context.ml index f65044cd025..9ac41c1fddb 100644 --- a/src/dune_rules/compilation_context.ml +++ b/src/dune_rules/compilation_context.ml @@ -3,13 +3,7 @@ open Import module Includes = struct type t = Command.Args.without_targets Command.Args.t Lib_mode.Cm_kind.Map.t - let make - ~project - ~opaque - ~direct_requires - ~(hidden_requires : Lib_flags.L.t Resolve.Memo.t) - : _ Lib_mode.Cm_kind.Map.t - = + let make ~project ~opaque ~direct_requires ~hidden_requires : _ Lib_mode.Cm_kind.Map.t = (* TODO : some of the requires can filtered out using [ocamldep] info *) let open Resolve.Memo.O in let iflags direct_libs hidden_libs mode = diff --git a/src/dune_rules/lib_flags.ml b/src/dune_rules/lib_flags.ml index 496f1476ee7..5472843ae4e 100644 --- a/src/dune_rules/lib_flags.ml +++ b/src/dune_rules/lib_flags.ml @@ -85,17 +85,10 @@ let link_deps sctx t mode = module L = struct type nonrec t = Lib.t list - let to_iflags dirs = + let to_iflags ?(flag = "-I") dirs = Command.Args.S (Path.Set.fold dirs ~init:[] ~f:(fun dir acc -> - Command.Args.Path dir :: A "-I" :: acc) - |> List.rev) - ;; - - let to_hflags dirs = - Command.Args.S - (Path.Set.fold dirs ~init:[] ~f:(fun dir acc -> - Command.Args.Path dir :: A "-H" :: acc) + Command.Args.Path dir :: A flag :: acc) |> List.rev) ;; @@ -163,14 +156,11 @@ module L = struct ;; let include_flags ?project ts_direct ts_hidden mode = - let hidden_includes = - to_hflags - (include_paths ?project ts_hidden { lib_mode = mode; melange_emit = false }) - in - let direct_includes = - to_iflags - (include_paths ?project ts_direct { lib_mode = mode; melange_emit = false }) + let include_paths ts = + include_paths ?project ts { lib_mode = mode; melange_emit = false } in + let hidden_includes = to_iflags (include_paths ts_hidden) ~flag:"-H" in + let direct_includes = to_iflags (include_paths ts_direct) in Command.Args.S [ direct_includes; hidden_includes ] ;; diff --git a/src/dune_rules/lib_flags.mli b/src/dune_rules/lib_flags.mli index 5d8a3e3c4d3..16a6bd0f223 100644 --- a/src/dune_rules/lib_flags.mli +++ b/src/dune_rules/lib_flags.mli @@ -22,7 +22,7 @@ end module L : sig type nonrec t = Lib.t list - val to_iflags : Path.Set.t -> _ Command.Args.t + val to_iflags : ?flag:string -> Path.Set.t -> _ Command.Args.t val include_paths : ?project:Dune_project.t -> t -> Lib_mode.t -> Path.Set.t val include_flags : ?project:Dune_project.t -> t -> t -> Lib_mode.t -> _ Command.Args.t val melange_emission_include_flags : ?project:Dune_project.t -> t -> _ Command.Args.t From 366ca5132eae63518054a7eacd43dbc81852d837 Mon Sep 17 00:00:00 2001 From: HasanA Date: Fri, 21 Jun 2024 16:46:16 +0200 Subject: [PATCH 07/19] add to_flags function Signed-off-by: HasanA --- src/dune_rules/lib_flags.ml | 7 +++++-- src/dune_rules/lib_flags.mli | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/dune_rules/lib_flags.ml b/src/dune_rules/lib_flags.ml index 5472843ae4e..87c1569560b 100644 --- a/src/dune_rules/lib_flags.ml +++ b/src/dune_rules/lib_flags.ml @@ -85,13 +85,16 @@ let link_deps sctx t mode = module L = struct type nonrec t = Lib.t list - let to_iflags ?(flag = "-I") dirs = + let to_flags flag dirs = Command.Args.S (Path.Set.fold dirs ~init:[] ~f:(fun dir acc -> Command.Args.Path dir :: A flag :: acc) |> List.rev) ;; + let to_iflags dir = to_flags "-I" dir + let to_hflags dir = to_flags "-H" dir + let remove_stdlib dirs libs = match libs with | [] -> dirs @@ -159,7 +162,7 @@ module L = struct let include_paths ts = include_paths ?project ts { lib_mode = mode; melange_emit = false } in - let hidden_includes = to_iflags (include_paths ts_hidden) ~flag:"-H" in + let hidden_includes = to_hflags (include_paths ts_hidden) in let direct_includes = to_iflags (include_paths ts_direct) in Command.Args.S [ direct_includes; hidden_includes ] ;; diff --git a/src/dune_rules/lib_flags.mli b/src/dune_rules/lib_flags.mli index 16a6bd0f223..670a764584d 100644 --- a/src/dune_rules/lib_flags.mli +++ b/src/dune_rules/lib_flags.mli @@ -22,7 +22,8 @@ end module L : sig type nonrec t = Lib.t list - val to_iflags : ?flag:string -> Path.Set.t -> _ Command.Args.t + val to_iflags : Path.Set.t -> _ Command.Args.t + val to_hflags : Path.Set.t -> _ Command.Args.t val include_paths : ?project:Dune_project.t -> t -> Lib_mode.t -> Path.Set.t val include_flags : ?project:Dune_project.t -> t -> t -> Lib_mode.t -> _ Command.Args.t val melange_emission_include_flags : ?project:Dune_project.t -> t -> _ Command.Args.t From d9df9e4909c775d36972e90c1a2512ad4ac980e2 Mon Sep 17 00:00:00 2001 From: HasanA Date: Fri, 21 Jun 2024 16:46:44 +0200 Subject: [PATCH 08/19] add CHANGES file Signed-off-by: HasanA --- doc/changes/10644.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 doc/changes/10644.md diff --git a/doc/changes/10644.md b/doc/changes/10644.md new file mode 100644 index 00000000000..1fd200e73e1 --- /dev/null +++ b/doc/changes/10644.md @@ -0,0 +1,6 @@ +- Add support for the -H flag (introduced in Ocaml compiler 5.2) in dune + (only supported for lang versions 3.17 and higher). This adaptation gives + the correct semantics for `implicit_transitive_deps = false` mode, since then + transitive dependencies are included with -H flag and so are not directly accessible + but visible for the compiler. (#10644, fixes (#9333, #ocsigen/tyxml#274, #2733, #4963), + @MA0100) \ No newline at end of file From 3607a916cc1824090796ce776d09d6afabbfc91c Mon Sep 17 00:00:00 2001 From: HasanA Date: Mon, 24 Jun 2024 17:25:05 +0200 Subject: [PATCH 09/19] Suggested edits Signed-off-by: HasanA --- doc/changes/10644.md | 10 ++++------ src/dune_rules/compilation_context.ml | 4 ++-- src/dune_rules/lib_flags.mli | 1 - 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/doc/changes/10644.md b/doc/changes/10644.md index 1fd200e73e1..893b0ce4969 100644 --- a/doc/changes/10644.md +++ b/doc/changes/10644.md @@ -1,6 +1,4 @@ -- Add support for the -H flag (introduced in Ocaml compiler 5.2) in dune - (only supported for lang versions 3.17 and higher). This adaptation gives - the correct semantics for `implicit_transitive_deps = false` mode, since then - transitive dependencies are included with -H flag and so are not directly accessible - but visible for the compiler. (#10644, fixes (#9333, #ocsigen/tyxml#274, #2733, #4963), - @MA0100) \ No newline at end of file +- Add support for the -H flag (introduced in OCaml compiler 5.2) in dune + (only supported for lang versions 3.17 and higher). This adaptation gives + the correct semantics for `(implicit_transitive_deps false)`. + (#10644, fixes #9333, ocsigen/tyxml#274, #2733, #4963, @MA0100) \ No newline at end of file diff --git a/src/dune_rules/compilation_context.ml b/src/dune_rules/compilation_context.ml index 9ac41c1fddb..ff12da047f6 100644 --- a/src/dune_rules/compilation_context.ml +++ b/src/dune_rules/compilation_context.ml @@ -151,7 +151,6 @@ let create let open Memo.O in let project = Scope.project scope in let context = Super_context.context super_context in - let sandbox = Sandbox_config.no_special_requirements in let* ocaml = Context.ocaml context in let direct_requires, hidden_requires = if Dune_project.implicit_transitive_deps project @@ -163,13 +162,14 @@ let create let open Resolve.Memo.O in let+ requires = requires_compile and+ requires_link = Memo.Lazy.force requires_link in - let requires_table = Table.create (module Lib) 500 in + let requires_table = Table.create (module Lib) 5 in let () = List.iter ~f:(fun lib -> Table.set requires_table lib ()) requires in List.filter requires_link ~f:(fun l -> not (Table.mem requires_table l)) in requires_compile, requires_hidden) else requires_compile, Resolve.Memo.return [] in + let sandbox = Sandbox_config.no_special_requirements in let modes = let default = { Lib_mode.Map.ocaml = Mode.Dict.make_both (Some Mode_conf.Kind.Inherited) diff --git a/src/dune_rules/lib_flags.mli b/src/dune_rules/lib_flags.mli index 670a764584d..5d8a3e3c4d3 100644 --- a/src/dune_rules/lib_flags.mli +++ b/src/dune_rules/lib_flags.mli @@ -23,7 +23,6 @@ module L : sig type nonrec t = Lib.t list val to_iflags : Path.Set.t -> _ Command.Args.t - val to_hflags : Path.Set.t -> _ Command.Args.t val include_paths : ?project:Dune_project.t -> t -> Lib_mode.t -> Path.Set.t val include_flags : ?project:Dune_project.t -> t -> t -> Lib_mode.t -> _ Command.Args.t val melange_emission_include_flags : ?project:Dune_project.t -> t -> _ Command.Args.t From 923a0bcac40398ae36e10aa36eb5cf2f56306517 Mon Sep 17 00:00:00 2001 From: HasanA Date: Mon, 24 Jun 2024 17:26:16 +0200 Subject: [PATCH 10/19] corrected logic for computing additational_libs; ocaml_index.ml Signed-off-by: HasanA --- src/dune_rules/merlin/ocaml_index.ml | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/dune_rules/merlin/ocaml_index.ml b/src/dune_rules/merlin/ocaml_index.ml index 70fde70d78a..fd0227b77bd 100644 --- a/src/dune_rules/merlin/ocaml_index.ml +++ b/src/dune_rules/merlin/ocaml_index.ml @@ -24,17 +24,23 @@ let cctx_rules cctx = let obj_dir = Compilation_context.obj_dir cctx in let fn = index_path_in_obj_dir obj_dir in let additional_libs = - let open Resolve.Memo.O in - let+ non_compile_libs = - (* The indexer relies on the load_path of cmt files. When - [implicit_transitive_deps] is set to [false] some necessary paths will - be missing.These are passed to the indexer with the `-I` flag. - - The implicit transitive libs correspond to the set: - (requires_link \ req_compile) *) - Compilation_context.requires_hidden cctx - in - Lib_flags.L.include_flags [] non_compile_libs (Lib_mode.Ocaml Byte) + let scope = Compilation_context.scope cctx in + let ocaml = Compilation_context.ocaml cctx in + if (not (Version.supports_hidden_includes ocaml.version)) + || Dune_project.dune_version (Scope.project scope) < (3, 17) + then + let open Resolve.Memo.O in + let+ non_compile_libs = + (* This is only needed for the case where OCaml < 5.2 or the dune language version + < 3.17, since in the latter cases those additional libs will be already included in the compilation + with -H flag.*) + let* req_link = Compilation_context.requires_link cctx in + let+ req_compile = Compilation_context.requires_compile cctx in + List.filter req_link ~f:(fun l -> + not (List.exists req_compile ~f:(Lib.equal l))) + in + Lib_flags.L.include_flags non_compile_libs [] (Lib_mode.Ocaml Byte) + else Resolve.Memo.return Command.Args.empty in (* Indexing depends (recursively) on [required_compile] libs: - These libs's cmt files should be built before indexing starts From 8e1757ffba6f5fff3584fbda94a3e4a7f478bf60 Mon Sep 17 00:00:00 2001 From: HasanA Date: Mon, 24 Jun 2024 17:28:52 +0200 Subject: [PATCH 11/19] ocaml_index: removed ocaml version check Signed-off-by: HasanA --- src/dune_rules/merlin/ocaml_index.ml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/dune_rules/merlin/ocaml_index.ml b/src/dune_rules/merlin/ocaml_index.ml index fd0227b77bd..cfd52439211 100644 --- a/src/dune_rules/merlin/ocaml_index.ml +++ b/src/dune_rules/merlin/ocaml_index.ml @@ -25,9 +25,7 @@ let cctx_rules cctx = let fn = index_path_in_obj_dir obj_dir in let additional_libs = let scope = Compilation_context.scope cctx in - let ocaml = Compilation_context.ocaml cctx in - if (not (Version.supports_hidden_includes ocaml.version)) - || Dune_project.dune_version (Scope.project scope) < (3, 17) + if Dune_project.dune_version (Scope.project scope) < (3, 17) then let open Resolve.Memo.O in let+ non_compile_libs = From cdd08f7bd27502893180214ef2fc41ec17399244 Mon Sep 17 00:00:00 2001 From: HasanA Date: Thu, 27 Jun 2024 11:17:27 +0200 Subject: [PATCH 12/19] style modifications and small corrections Signed-off-by: HasanA --- doc/changes/10644.md | 2 +- src/dune_rules/compilation_context.ml | 10 +++++----- src/dune_rules/lib_flags.ml | 6 +++--- src/dune_rules/lib_flags.mli | 2 +- src/dune_rules/merlin/ocaml_index.ml | 6 ++---- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/doc/changes/10644.md b/doc/changes/10644.md index 893b0ce4969..6b131abb95d 100644 --- a/doc/changes/10644.md +++ b/doc/changes/10644.md @@ -1,4 +1,4 @@ - Add support for the -H flag (introduced in OCaml compiler 5.2) in dune - (only supported for lang versions 3.17 and higher). This adaptation gives + (requires lang versions 3.17). This adaptation gives the correct semantics for `(implicit_transitive_deps false)`. (#10644, fixes #9333, ocsigen/tyxml#274, #2733, #4963, @MA0100) \ No newline at end of file diff --git a/src/dune_rules/compilation_context.ml b/src/dune_rules/compilation_context.ml index ff12da047f6..93395a2da69 100644 --- a/src/dune_rules/compilation_context.ml +++ b/src/dune_rules/compilation_context.ml @@ -7,7 +7,7 @@ module Includes = struct (* TODO : some of the requires can filtered out using [ocamldep] info *) let open Resolve.Memo.O in let iflags direct_libs hidden_libs mode = - Lib_flags.L.include_flags ~project direct_libs hidden_libs mode + Lib_flags.L.include_flags ~project ~direct_libs ~hidden_libs mode in let make_includes_args ~mode groups = Command.Args.memo @@ -17,7 +17,7 @@ module Includes = struct Command.Args.S [ iflags direct_libs hidden_libs mode ; Hidden_deps - (Lib_file_deps.deps (List.concat [ direct_libs; hidden_libs ]) ~groups) + (Lib_file_deps.deps (direct_libs @ hidden_libs) ~groups) ])) in let cmi_includes = make_includes_args ~mode:(Ocaml Byte) [ Ocaml Cmi ] in @@ -32,7 +32,7 @@ module Includes = struct (if opaque then List.map - (List.concat [ direct_libs; hidden_libs ]) + (direct_libs @ hidden_libs) ~f:(fun lib -> ( lib , if Lib.is_local lib @@ -160,10 +160,10 @@ let create then ( let requires_hidden = let open Resolve.Memo.O in - let+ requires = requires_compile + let+ requires_compile = requires_compile and+ requires_link = Memo.Lazy.force requires_link in let requires_table = Table.create (module Lib) 5 in - let () = List.iter ~f:(fun lib -> Table.set requires_table lib ()) requires in + let () = List.iter ~f:(fun lib -> Table.set requires_table lib ()) requires_compile in List.filter requires_link ~f:(fun l -> not (Table.mem requires_table l)) in requires_compile, requires_hidden) diff --git a/src/dune_rules/lib_flags.ml b/src/dune_rules/lib_flags.ml index 87c1569560b..d8e7dabc509 100644 --- a/src/dune_rules/lib_flags.ml +++ b/src/dune_rules/lib_flags.ml @@ -158,12 +158,12 @@ module L = struct remove_stdlib dirs ts ;; - let include_flags ?project ts_direct ts_hidden mode = + let include_flags ?project ~direct_libs ~hidden_libs mode = let include_paths ts = include_paths ?project ts { lib_mode = mode; melange_emit = false } in - let hidden_includes = to_hflags (include_paths ts_hidden) in - let direct_includes = to_iflags (include_paths ts_direct) in + let hidden_includes = to_hflags (include_paths hidden_libs) in + let direct_includes = to_iflags (include_paths direct_libs) in Command.Args.S [ direct_includes; hidden_includes ] ;; diff --git a/src/dune_rules/lib_flags.mli b/src/dune_rules/lib_flags.mli index 5d8a3e3c4d3..5c9460d334b 100644 --- a/src/dune_rules/lib_flags.mli +++ b/src/dune_rules/lib_flags.mli @@ -24,7 +24,7 @@ module L : sig val to_iflags : Path.Set.t -> _ Command.Args.t val include_paths : ?project:Dune_project.t -> t -> Lib_mode.t -> Path.Set.t - val include_flags : ?project:Dune_project.t -> t -> t -> Lib_mode.t -> _ Command.Args.t + val include_flags : ?project:Dune_project.t -> direct_libs:t -> hidden_libs:t -> Lib_mode.t -> _ Command.Args.t val melange_emission_include_flags : ?project:Dune_project.t -> t -> _ Command.Args.t val c_include_flags : t -> Super_context.t -> _ Command.Args.t val toplevel_ld_paths : t -> Path.Set.t diff --git a/src/dune_rules/merlin/ocaml_index.ml b/src/dune_rules/merlin/ocaml_index.ml index cfd52439211..873d41dc7a9 100644 --- a/src/dune_rules/merlin/ocaml_index.ml +++ b/src/dune_rules/merlin/ocaml_index.ml @@ -25,19 +25,17 @@ let cctx_rules cctx = let fn = index_path_in_obj_dir obj_dir in let additional_libs = let scope = Compilation_context.scope cctx in + (* Dune language >= 3.17 correctly passes the `-H` flag to the compiler. *) if Dune_project.dune_version (Scope.project scope) < (3, 17) then let open Resolve.Memo.O in let+ non_compile_libs = - (* This is only needed for the case where OCaml < 5.2 or the dune language version - < 3.17, since in the latter cases those additional libs will be already included in the compilation - with -H flag.*) let* req_link = Compilation_context.requires_link cctx in let+ req_compile = Compilation_context.requires_compile cctx in List.filter req_link ~f:(fun l -> not (List.exists req_compile ~f:(Lib.equal l))) in - Lib_flags.L.include_flags non_compile_libs [] (Lib_mode.Ocaml Byte) + Lib_flags.L.include_flags ~direct_libs:non_compile_libs ~hidden_libs:[] (Lib_mode.Ocaml Byte) else Resolve.Memo.return Command.Args.empty in (* Indexing depends (recursively) on [required_compile] libs: From c8f4f7f4cd197ab718fddb2c1c2030d3e31c96f1 Mon Sep 17 00:00:00 2001 From: HasanA Date: Thu, 27 Jun 2024 11:22:12 +0200 Subject: [PATCH 13/19] separated tests and guarded them by ocaml version Signed-off-by: HasanA --- test/blackbox-tests/test-cases/dune | 10 ++++++++ .../test-cases/hidden-deps-supported.t/bar.ml | 2 ++ .../dune | 0 .../foo.ml | 3 +-- .../run.ml | 0 .../run.t | 23 +++++++++++------ .../hidden-deps-supported.t/runf.ml | 1 + .../tyxml/dune | 0 .../tyxml/dune-project | 0 .../tyxml/run.ml | 0 .../hidden-deps-unsupported.t/bar.ml | 2 ++ .../test-cases/hidden-deps-unsupported.t/dune | 13 ++++++++++ .../hidden-deps-unsupported.t/foo.ml | 2 ++ .../hidden-deps-unsupported.t/run.ml | 2 ++ .../hidden-deps-unsupported.t/run.t | 25 +++++++++++++++++++ .../test-cases/hidden-deps.t/bar.ml | 3 --- .../test-cases/hidden-deps.t/runf.ml | 1 - .../test-cases/hidden-deps.t/tyxml/run.t | 5 ---- 18 files changed, 74 insertions(+), 18 deletions(-) create mode 100644 test/blackbox-tests/test-cases/hidden-deps-supported.t/bar.ml rename test/blackbox-tests/test-cases/{hidden-deps.t => hidden-deps-supported.t}/dune (100%) rename test/blackbox-tests/test-cases/{hidden-deps.t => hidden-deps-supported.t}/foo.ml (50%) rename test/blackbox-tests/test-cases/{hidden-deps.t => hidden-deps-supported.t}/run.ml (100%) rename test/blackbox-tests/test-cases/{hidden-deps.t => hidden-deps-supported.t}/run.t (57%) create mode 100644 test/blackbox-tests/test-cases/hidden-deps-supported.t/runf.ml rename test/blackbox-tests/test-cases/{hidden-deps.t => hidden-deps-supported.t}/tyxml/dune (100%) rename test/blackbox-tests/test-cases/{hidden-deps.t => hidden-deps-supported.t}/tyxml/dune-project (100%) rename test/blackbox-tests/test-cases/{hidden-deps.t => hidden-deps-supported.t}/tyxml/run.ml (100%) create mode 100644 test/blackbox-tests/test-cases/hidden-deps-unsupported.t/bar.ml create mode 100644 test/blackbox-tests/test-cases/hidden-deps-unsupported.t/dune create mode 100644 test/blackbox-tests/test-cases/hidden-deps-unsupported.t/foo.ml create mode 100644 test/blackbox-tests/test-cases/hidden-deps-unsupported.t/run.ml create mode 100644 test/blackbox-tests/test-cases/hidden-deps-unsupported.t/run.t delete mode 100644 test/blackbox-tests/test-cases/hidden-deps.t/bar.ml delete mode 100644 test/blackbox-tests/test-cases/hidden-deps.t/runf.ml delete mode 100644 test/blackbox-tests/test-cases/hidden-deps.t/tyxml/run.t diff --git a/test/blackbox-tests/test-cases/dune b/test/blackbox-tests/test-cases/dune index 5eb82ae6938..0934807c370 100644 --- a/test/blackbox-tests/test-cases/dune +++ b/test/blackbox-tests/test-cases/dune @@ -164,3 +164,13 @@ (cram (applies_to sandboxing-stale-directory-target) (deps %{bin:bash})) + +(cram + (applies_to hidden-deps-supported) + (enabled_if + (>= %{ocaml_version} 5.2.0))) + +(cram + (applies_to hidden-deps-unsupported) + (enabled_if + (< %{ocaml_version} 5.2.0))) diff --git a/test/blackbox-tests/test-cases/hidden-deps-supported.t/bar.ml b/test/blackbox-tests/test-cases/hidden-deps-supported.t/bar.ml new file mode 100644 index 00000000000..98146d7098e --- /dev/null +++ b/test/blackbox-tests/test-cases/hidden-deps-supported.t/bar.ml @@ -0,0 +1,2 @@ +let x = 5 +let y = Foo.v diff --git a/test/blackbox-tests/test-cases/hidden-deps.t/dune b/test/blackbox-tests/test-cases/hidden-deps-supported.t/dune similarity index 100% rename from test/blackbox-tests/test-cases/hidden-deps.t/dune rename to test/blackbox-tests/test-cases/hidden-deps-supported.t/dune diff --git a/test/blackbox-tests/test-cases/hidden-deps.t/foo.ml b/test/blackbox-tests/test-cases/hidden-deps-supported.t/foo.ml similarity index 50% rename from test/blackbox-tests/test-cases/hidden-deps.t/foo.ml rename to test/blackbox-tests/test-cases/hidden-deps-supported.t/foo.ml index 233654b2d90..dfa3cba9d50 100644 --- a/test/blackbox-tests/test-cases/hidden-deps.t/foo.ml +++ b/test/blackbox-tests/test-cases/hidden-deps-supported.t/foo.ml @@ -1,3 +1,2 @@ let v = 9 - -let w = 4 \ No newline at end of file +let w = 4 diff --git a/test/blackbox-tests/test-cases/hidden-deps.t/run.ml b/test/blackbox-tests/test-cases/hidden-deps-supported.t/run.ml similarity index 100% rename from test/blackbox-tests/test-cases/hidden-deps.t/run.ml rename to test/blackbox-tests/test-cases/hidden-deps-supported.t/run.ml diff --git a/test/blackbox-tests/test-cases/hidden-deps.t/run.t b/test/blackbox-tests/test-cases/hidden-deps-supported.t/run.t similarity index 57% rename from test/blackbox-tests/test-cases/hidden-deps.t/run.t rename to test/blackbox-tests/test-cases/hidden-deps-supported.t/run.t index f058673ff79..c4eae7ce6cb 100644 --- a/test/blackbox-tests/test-cases/hidden-deps.t/run.t +++ b/test/blackbox-tests/test-cases/hidden-deps-supported.t/run.t @@ -1,26 +1,26 @@ -Should include Foo with -H: +This test is guarded by ocaml version >= 5.2, so it should include foo with -H when +implicit_transitive_deps is set to false. $ getincludes () { > dune build --verbose ./run.exe 2>&1 | grep run.ml | grep -E -o "\-$1\s(.foo)\S*" | sed s/\-$1//g | tr -d '[:space:]' > } - $ supports_H=$(if ocamlc -H x --help >/dev/null 2>&1; then echo true; else echo false; fi) - $ fooincludes='.foo.objs/byte.foo.objs/byte.foo.objs/native' $ cat >dune-project < (lang dune 3.17) > (implicit_transitive_deps true) > EOF + $ echo "$(getincludes I)" + .foo.objs/byte.foo.objs/byte.foo.objs/native - $ if $supports_H; then [ "$(getincludes I)" = $fooincludes ]; fi - $ if ! $supports_H; then [ "$(getincludes I)" = $fooincludes ]; fi $ cat >dune-project < (lang dune 3.17) > (implicit_transitive_deps false) > EOF - $ if $supports_H; then [ "$(getincludes H)" = $fooincludes ]; fi - $ if ! $supports_H; then [ "$(getincludes I)" = '' ]; fi + $ echo "$(getincludes H)" + .foo.objs/byte.foo.objs/byte.foo.objs/native + Test transitive deps can not be directly accessed, both for compiler versions supporting -H or not: @@ -34,3 +34,12 @@ Test transitive deps can not be directly accessed, both for compiler versions su 1 | let a = Bar.y + Foo.v ^^^^^ Error: Unbound module Foo + +Test if the issue #274 is solved: the tyxml.functor is included with -H flag in +ITD = false case, and thus no type abstraction happens when it is used. + + $ dune build --root=./tyxml + Entering directory 'tyxml' + Leaving directory 'tyxml' + + diff --git a/test/blackbox-tests/test-cases/hidden-deps-supported.t/runf.ml b/test/blackbox-tests/test-cases/hidden-deps-supported.t/runf.ml new file mode 100644 index 00000000000..0d3f1db0e17 --- /dev/null +++ b/test/blackbox-tests/test-cases/hidden-deps-supported.t/runf.ml @@ -0,0 +1 @@ +let a = Bar.y + Foo.v diff --git a/test/blackbox-tests/test-cases/hidden-deps.t/tyxml/dune b/test/blackbox-tests/test-cases/hidden-deps-supported.t/tyxml/dune similarity index 100% rename from test/blackbox-tests/test-cases/hidden-deps.t/tyxml/dune rename to test/blackbox-tests/test-cases/hidden-deps-supported.t/tyxml/dune diff --git a/test/blackbox-tests/test-cases/hidden-deps.t/tyxml/dune-project b/test/blackbox-tests/test-cases/hidden-deps-supported.t/tyxml/dune-project similarity index 100% rename from test/blackbox-tests/test-cases/hidden-deps.t/tyxml/dune-project rename to test/blackbox-tests/test-cases/hidden-deps-supported.t/tyxml/dune-project diff --git a/test/blackbox-tests/test-cases/hidden-deps.t/tyxml/run.ml b/test/blackbox-tests/test-cases/hidden-deps-supported.t/tyxml/run.ml similarity index 100% rename from test/blackbox-tests/test-cases/hidden-deps.t/tyxml/run.ml rename to test/blackbox-tests/test-cases/hidden-deps-supported.t/tyxml/run.ml diff --git a/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/bar.ml b/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/bar.ml new file mode 100644 index 00000000000..98146d7098e --- /dev/null +++ b/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/bar.ml @@ -0,0 +1,2 @@ +let x = 5 +let y = Foo.v diff --git a/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/dune b/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/dune new file mode 100644 index 00000000000..ddbc42cc062 --- /dev/null +++ b/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/dune @@ -0,0 +1,13 @@ +(library + (name foo) + (modules foo)) + +(library + (name bar) + (modules bar) + (libraries foo)) + +(executable + (name run) + (modules run) + (libraries bar)) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/foo.ml b/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/foo.ml new file mode 100644 index 00000000000..dfa3cba9d50 --- /dev/null +++ b/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/foo.ml @@ -0,0 +1,2 @@ +let v = 9 +let w = 4 diff --git a/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/run.ml b/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/run.ml new file mode 100644 index 00000000000..436b88a6649 --- /dev/null +++ b/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/run.ml @@ -0,0 +1,2 @@ +let _ = Bar.y +let _ = print_endline "yes" diff --git a/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/run.t b/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/run.t new file mode 100644 index 00000000000..f3e5b97075e --- /dev/null +++ b/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/run.t @@ -0,0 +1,25 @@ +This test is guarded by ocaml version <= 5.1, so it should not include foo +when implicit_transitive_deps is set to false, i.e. testing backward compatibility of +the new -H feature added. + + $ getincludes () { + > dune build --verbose ./run.exe 2>&1 | grep run.ml | grep -E -o "\-$1\s(.foo)\S*" | sed s/\-$1//g | tr -d '[:space:]' + > } + + $ cat >dune-project < (lang dune 3.17) + > (implicit_transitive_deps true) + > EOF + $ echo "$(getincludes I)" + .foo.objs/byte.foo.objs/byte.foo.objs/native + + + $ cat >dune-project < (lang dune 3.17) + > (implicit_transitive_deps false) + > EOF + + $ echo "$(getincludes I)" + + + diff --git a/test/blackbox-tests/test-cases/hidden-deps.t/bar.ml b/test/blackbox-tests/test-cases/hidden-deps.t/bar.ml deleted file mode 100644 index e1ca0d9c772..00000000000 --- a/test/blackbox-tests/test-cases/hidden-deps.t/bar.ml +++ /dev/null @@ -1,3 +0,0 @@ -let x = 5 - -let y = Foo.v \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/hidden-deps.t/runf.ml b/test/blackbox-tests/test-cases/hidden-deps.t/runf.ml deleted file mode 100644 index 3e7e6b04ba1..00000000000 --- a/test/blackbox-tests/test-cases/hidden-deps.t/runf.ml +++ /dev/null @@ -1 +0,0 @@ -let a = Bar.y + Foo.v \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/hidden-deps.t/tyxml/run.t b/test/blackbox-tests/test-cases/hidden-deps.t/tyxml/run.t deleted file mode 100644 index 35c0613b159..00000000000 --- a/test/blackbox-tests/test-cases/hidden-deps.t/tyxml/run.t +++ /dev/null @@ -1,5 +0,0 @@ -Test if the issue #274 is solved: the tyxml.functor is included with -H flag in -ITD = false case, and thus no type abstraction happens when it is used. - - $ ocamlc -H x --help > /dev/null - $ if [ $? = 0 ]; then dune build fi From 6ef7f54e311e3e1b59425cf9975840b990e816c2 Mon Sep 17 00:00:00 2001 From: HasanA Date: Thu, 27 Jun 2024 11:22:51 +0200 Subject: [PATCH 14/19] formatting Signed-off-by: HasanA --- src/dune_rules/compilation_context.ml | 19 +++++++++---------- src/dune_rules/lib_flags.mli | 9 ++++++++- src/dune_rules/merlin/ocaml_index.ml | 5 ++++- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/dune_rules/compilation_context.ml b/src/dune_rules/compilation_context.ml index 93395a2da69..49113f91c3f 100644 --- a/src/dune_rules/compilation_context.ml +++ b/src/dune_rules/compilation_context.ml @@ -16,8 +16,7 @@ module Includes = struct and+ hidden_libs = hidden_requires in Command.Args.S [ iflags direct_libs hidden_libs mode - ; Hidden_deps - (Lib_file_deps.deps (direct_libs @ hidden_libs) ~groups) + ; Hidden_deps (Lib_file_deps.deps (direct_libs @ hidden_libs) ~groups) ])) in let cmi_includes = make_includes_args ~mode:(Ocaml Byte) [ Ocaml Cmi ] in @@ -31,13 +30,11 @@ module Includes = struct ; Hidden_deps (if opaque then - List.map - (direct_libs @ hidden_libs) - ~f:(fun lib -> - ( lib - , if Lib.is_local lib - then [ Lib_file_deps.Group.Ocaml Cmi ] - else [ Ocaml Cmi; Ocaml Cmx ] )) + List.map (direct_libs @ hidden_libs) ~f:(fun lib -> + ( lib + , if Lib.is_local lib + then [ Lib_file_deps.Group.Ocaml Cmi ] + else [ Ocaml Cmi; Ocaml Cmx ] )) |> Lib_file_deps.deps_with_exts else Lib_file_deps.deps @@ -163,7 +160,9 @@ let create let+ requires_compile = requires_compile and+ requires_link = Memo.Lazy.force requires_link in let requires_table = Table.create (module Lib) 5 in - let () = List.iter ~f:(fun lib -> Table.set requires_table lib ()) requires_compile in + let () = + List.iter ~f:(fun lib -> Table.set requires_table lib ()) requires_compile + in List.filter requires_link ~f:(fun l -> not (Table.mem requires_table l)) in requires_compile, requires_hidden) diff --git a/src/dune_rules/lib_flags.mli b/src/dune_rules/lib_flags.mli index 5c9460d334b..8a65f55a084 100644 --- a/src/dune_rules/lib_flags.mli +++ b/src/dune_rules/lib_flags.mli @@ -24,7 +24,14 @@ module L : sig val to_iflags : Path.Set.t -> _ Command.Args.t val include_paths : ?project:Dune_project.t -> t -> Lib_mode.t -> Path.Set.t - val include_flags : ?project:Dune_project.t -> direct_libs:t -> hidden_libs:t -> Lib_mode.t -> _ Command.Args.t + + val include_flags + : ?project:Dune_project.t + -> direct_libs:t + -> hidden_libs:t + -> Lib_mode.t + -> _ Command.Args.t + val melange_emission_include_flags : ?project:Dune_project.t -> t -> _ Command.Args.t val c_include_flags : t -> Super_context.t -> _ Command.Args.t val toplevel_ld_paths : t -> Path.Set.t diff --git a/src/dune_rules/merlin/ocaml_index.ml b/src/dune_rules/merlin/ocaml_index.ml index 873d41dc7a9..7941191f70e 100644 --- a/src/dune_rules/merlin/ocaml_index.ml +++ b/src/dune_rules/merlin/ocaml_index.ml @@ -35,7 +35,10 @@ let cctx_rules cctx = List.filter req_link ~f:(fun l -> not (List.exists req_compile ~f:(Lib.equal l))) in - Lib_flags.L.include_flags ~direct_libs:non_compile_libs ~hidden_libs:[] (Lib_mode.Ocaml Byte) + Lib_flags.L.include_flags + ~direct_libs:non_compile_libs + ~hidden_libs:[] + (Lib_mode.Ocaml Byte) else Resolve.Memo.return Command.Args.empty in (* Indexing depends (recursively) on [required_compile] libs: From 51d6e2fdf26d7bbcc441d95e65097b9c71377337 Mon Sep 17 00:00:00 2001 From: HasanA Date: Thu, 27 Jun 2024 15:06:24 +0200 Subject: [PATCH 15/19] cosmetic tweaks Signed-off-by: HasanA --- src/dune_rules/compilation_context.ml | 4 +--- test/blackbox-tests/test-cases/hidden-deps-supported.t/run.ml | 2 +- test/blackbox-tests/test-cases/hidden-deps-supported.t/run.t | 4 ---- .../test-cases/hidden-deps-supported.t/tyxml/dune | 3 ++- .../test-cases/hidden-deps-supported.t/tyxml/run.ml | 2 +- test/blackbox-tests/test-cases/hidden-deps-unsupported.t/dune | 3 ++- .../blackbox-tests/test-cases/hidden-deps-unsupported.t/run.t | 3 --- 7 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/dune_rules/compilation_context.ml b/src/dune_rules/compilation_context.ml index 49113f91c3f..ee4cb510600 100644 --- a/src/dune_rules/compilation_context.ml +++ b/src/dune_rules/compilation_context.ml @@ -160,9 +160,7 @@ let create let+ requires_compile = requires_compile and+ requires_link = Memo.Lazy.force requires_link in let requires_table = Table.create (module Lib) 5 in - let () = - List.iter ~f:(fun lib -> Table.set requires_table lib ()) requires_compile - in + List.iter ~f:(fun lib -> Table.set requires_table lib ()) requires_compile; List.filter requires_link ~f:(fun l -> not (Table.mem requires_table l)) in requires_compile, requires_hidden) diff --git a/test/blackbox-tests/test-cases/hidden-deps-supported.t/run.ml b/test/blackbox-tests/test-cases/hidden-deps-supported.t/run.ml index 4be93f9760e..a956be2d6c3 100644 --- a/test/blackbox-tests/test-cases/hidden-deps-supported.t/run.ml +++ b/test/blackbox-tests/test-cases/hidden-deps-supported.t/run.ml @@ -1 +1 @@ -let _ = Bar.y \ No newline at end of file +let _ = Bar.y diff --git a/test/blackbox-tests/test-cases/hidden-deps-supported.t/run.t b/test/blackbox-tests/test-cases/hidden-deps-supported.t/run.t index c4eae7ce6cb..3c6f0e6a5b0 100644 --- a/test/blackbox-tests/test-cases/hidden-deps-supported.t/run.t +++ b/test/blackbox-tests/test-cases/hidden-deps-supported.t/run.t @@ -12,7 +12,6 @@ implicit_transitive_deps is set to false. $ echo "$(getincludes I)" .foo.objs/byte.foo.objs/byte.foo.objs/native - $ cat >dune-project < (lang dune 3.17) > (implicit_transitive_deps false) @@ -22,7 +21,6 @@ implicit_transitive_deps is set to false. .foo.objs/byte.foo.objs/byte.foo.objs/native - Test transitive deps can not be directly accessed, both for compiler versions supporting -H or not: $ cat >dune-project < (lang dune 3.17) @@ -41,5 +39,3 @@ ITD = false case, and thus no type abstraction happens when it is used. $ dune build --root=./tyxml Entering directory 'tyxml' Leaving directory 'tyxml' - - diff --git a/test/blackbox-tests/test-cases/hidden-deps-supported.t/tyxml/dune b/test/blackbox-tests/test-cases/hidden-deps-supported.t/tyxml/dune index fd768950796..14cd546b25b 100644 --- a/test/blackbox-tests/test-cases/hidden-deps-supported.t/tyxml/dune +++ b/test/blackbox-tests/test-cases/hidden-deps-supported.t/tyxml/dune @@ -1,3 +1,4 @@ (executable (name run) - (libraries tyxml)) \ No newline at end of file + (libraries tyxml)) + \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/hidden-deps-supported.t/tyxml/run.ml b/test/blackbox-tests/test-cases/hidden-deps-supported.t/tyxml/run.ml index 68818fbad58..66f0f01edf5 100644 --- a/test/blackbox-tests/test-cases/hidden-deps-supported.t/tyxml/run.ml +++ b/test/blackbox-tests/test-cases/hidden-deps-supported.t/tyxml/run.ml @@ -1,2 +1,2 @@ open Tyxml.Html -let _ = p [ a [ txt "a" ] ] \ No newline at end of file +let _ = p [ a [ txt "a" ] ] diff --git a/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/dune b/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/dune index ddbc42cc062..c5481663927 100644 --- a/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/dune +++ b/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/dune @@ -10,4 +10,5 @@ (executable (name run) (modules run) - (libraries bar)) \ No newline at end of file + (libraries bar)) + \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/run.t b/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/run.t index f3e5b97075e..958af1e7aaf 100644 --- a/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/run.t +++ b/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/run.t @@ -13,7 +13,6 @@ the new -H feature added. $ echo "$(getincludes I)" .foo.objs/byte.foo.objs/byte.foo.objs/native - $ cat >dune-project < (lang dune 3.17) > (implicit_transitive_deps false) @@ -21,5 +20,3 @@ the new -H feature added. $ echo "$(getincludes I)" - - From 83bb651f7dab87fcf04103778edf092044955627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= Date: Thu, 27 Jun 2024 15:03:04 +0200 Subject: [PATCH 16/19] Cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ojeda Bär --- .../test-cases/hidden-deps-supported.t/run.t | 17 +++++++++++------ .../test-cases/hidden-deps-unsupported.t/run.t | 13 ++++++++----- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/test/blackbox-tests/test-cases/hidden-deps-supported.t/run.t b/test/blackbox-tests/test-cases/hidden-deps-supported.t/run.t index 3c6f0e6a5b0..fbcf2f5848d 100644 --- a/test/blackbox-tests/test-cases/hidden-deps-supported.t/run.t +++ b/test/blackbox-tests/test-cases/hidden-deps-supported.t/run.t @@ -2,26 +2,31 @@ This test is guarded by ocaml version >= 5.2, so it should include foo with -H w implicit_transitive_deps is set to false. $ getincludes () { - > dune build --verbose ./run.exe 2>&1 | grep run.ml | grep -E -o "\-$1\s(.foo)\S*" | sed s/\-$1//g | tr -d '[:space:]' + > dune build --verbose ./run.exe 2>&1 | grep run.ml | grep -E -o "\-$1\s(.foo)\S*" > } $ cat >dune-project < (lang dune 3.17) > (implicit_transitive_deps true) > EOF - $ echo "$(getincludes I)" - .foo.objs/byte.foo.objs/byte.foo.objs/native + + $ getincludes I + -I .foo.objs/byte + -I .foo.objs/byte + -I .foo.objs/native $ cat >dune-project < (lang dune 3.17) > (implicit_transitive_deps false) > EOF - $ echo "$(getincludes H)" - .foo.objs/byte.foo.objs/byte.foo.objs/native - + $ getincludes H + -H .foo.objs/byte + -H .foo.objs/byte + -H .foo.objs/native Test transitive deps can not be directly accessed, both for compiler versions supporting -H or not: + $ cat >dune-project < (lang dune 3.17) > (implicit_transitive_deps false) diff --git a/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/run.t b/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/run.t index 958af1e7aaf..d13228b4a3d 100644 --- a/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/run.t +++ b/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/run.t @@ -3,20 +3,23 @@ when implicit_transitive_deps is set to false, i.e. testing backward compatibili the new -H feature added. $ getincludes () { - > dune build --verbose ./run.exe 2>&1 | grep run.ml | grep -E -o "\-$1\s(.foo)\S*" | sed s/\-$1//g | tr -d '[:space:]' + > dune build --verbose ./run.exe 2>&1 | grep run.ml | grep -E -o "\-$1\s(.foo)\S*" > } $ cat >dune-project < (lang dune 3.17) > (implicit_transitive_deps true) > EOF - $ echo "$(getincludes I)" - .foo.objs/byte.foo.objs/byte.foo.objs/native + + $ getincludes I + -I .foo.objs/byte + -I .foo.objs/byte + -I .foo.objs/native $ cat >dune-project < (lang dune 3.17) > (implicit_transitive_deps false) > EOF - $ echo "$(getincludes I)" - + $ getincludes I + [1] From 2812ddb00c7e899aece29afbbd35f7fd8a2932a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= Date: Thu, 27 Jun 2024 15:20:33 +0200 Subject: [PATCH 17/19] Cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ojeda Bär --- .../test-cases/hidden-deps-supported.t/run.t | 21 ++++++++++++++----- .../hidden-deps-unsupported.t/run.t | 19 +++++++++++++---- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/test/blackbox-tests/test-cases/hidden-deps-supported.t/run.t b/test/blackbox-tests/test-cases/hidden-deps-supported.t/run.t index fbcf2f5848d..37c46fa06c4 100644 --- a/test/blackbox-tests/test-cases/hidden-deps-supported.t/run.t +++ b/test/blackbox-tests/test-cases/hidden-deps-supported.t/run.t @@ -2,7 +2,7 @@ This test is guarded by ocaml version >= 5.2, so it should include foo with -H w implicit_transitive_deps is set to false. $ getincludes () { - > dune build --verbose ./run.exe 2>&1 | grep run.ml | grep -E -o "\-$1\s(.foo)\S*" + > dune build --verbose ./run.exe 2>&1 | grep run.ml | grep -Eo '\-[IH] [a-z/.]+' | sort > } $ cat >dune-project < (implicit_transitive_deps true) > EOF - $ getincludes I + $ getincludes + -I .bar.objs/byte + -I .bar.objs/byte + -I .bar.objs/native -I .foo.objs/byte -I .foo.objs/byte -I .foo.objs/native + -I .run.eobjs/byte + -I .run.eobjs/byte + -I .run.eobjs/native $ cat >dune-project < (lang dune 3.17) > (implicit_transitive_deps false) > EOF - $ getincludes H + $ getincludes -H .foo.objs/byte -H .foo.objs/byte -H .foo.objs/native + -I .bar.objs/byte + -I .bar.objs/byte + -I .bar.objs/native + -I .run.eobjs/byte + -I .run.eobjs/byte + -I .run.eobjs/native Test transitive deps can not be directly accessed, both for compiler versions supporting -H or not: @@ -38,8 +50,7 @@ Test transitive deps can not be directly accessed, both for compiler versions su ^^^^^ Error: Unbound module Foo -Test if the issue #274 is solved: the tyxml.functor is included with -H flag in -ITD = false case, and thus no type abstraction happens when it is used. +Test if #274 is fixed: $ dune build --root=./tyxml Entering directory 'tyxml' diff --git a/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/run.t b/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/run.t index d13228b4a3d..c51b4249eae 100644 --- a/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/run.t +++ b/test/blackbox-tests/test-cases/hidden-deps-unsupported.t/run.t @@ -3,7 +3,7 @@ when implicit_transitive_deps is set to false, i.e. testing backward compatibili the new -H feature added. $ getincludes () { - > dune build --verbose ./run.exe 2>&1 | grep run.ml | grep -E -o "\-$1\s(.foo)\S*" + > dune build --verbose ./run.exe 2>&1 | grep run.ml | grep -Eo '\-[IH] [a-z/.]+' | sort > } $ cat >dune-project < (implicit_transitive_deps true) > EOF - $ getincludes I + $ getincludes + -I .bar.objs/byte + -I .bar.objs/byte + -I .bar.objs/native -I .foo.objs/byte -I .foo.objs/byte -I .foo.objs/native + -I .run.eobjs/byte + -I .run.eobjs/byte + -I .run.eobjs/native $ cat >dune-project < (lang dune 3.17) > (implicit_transitive_deps false) > EOF - $ getincludes I - [1] + $ getincludes + -I .bar.objs/byte + -I .bar.objs/byte + -I .bar.objs/native + -I .run.eobjs/byte + -I .run.eobjs/byte + -I .run.eobjs/native From c11722d0dc94d9b5eead0024a736de47436b6497 Mon Sep 17 00:00:00 2001 From: HasanA Date: Thu, 27 Jun 2024 15:49:56 +0200 Subject: [PATCH 18/19] tweaks Signed-off-by: HasanA --- src/dune_rules/compilation_context.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dune_rules/compilation_context.ml b/src/dune_rules/compilation_context.ml index ee4cb510600..a4d69c0b654 100644 --- a/src/dune_rules/compilation_context.ml +++ b/src/dune_rules/compilation_context.ml @@ -38,7 +38,7 @@ module Includes = struct |> Lib_file_deps.deps_with_exts else Lib_file_deps.deps - (List.concat [ direct_libs; hidden_libs ]) + (direct_libs @ hidden_libs) ~groups:[ Lib_file_deps.Group.Ocaml Cmi; Ocaml Cmx ]) ])) in From f1882cc5c4f3b5e09bb95673149a51ba7fea8b75 Mon Sep 17 00:00:00 2001 From: HasanA Date: Thu, 27 Jun 2024 16:01:15 +0200 Subject: [PATCH 19/19] final formatting Signed-off-by: HasanA --- src/dune_rules/compilation_context.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dune_rules/compilation_context.ml b/src/dune_rules/compilation_context.ml index a4d69c0b654..8bb1be96cd0 100644 --- a/src/dune_rules/compilation_context.ml +++ b/src/dune_rules/compilation_context.ml @@ -38,7 +38,7 @@ module Includes = struct |> Lib_file_deps.deps_with_exts else Lib_file_deps.deps - (direct_libs @ hidden_libs) + (direct_libs @ hidden_libs) ~groups:[ Lib_file_deps.Group.Ocaml Cmi; Ocaml Cmx ]) ])) in