Skip to content

Commit

Permalink
Change the type of state.result to include a bool indicating if the d…
Browse files Browse the repository at this point in the history
…ependency is direct or not.

add -H feature to dune.

_

_

merged the requires_link and requires_compile lists into one list, and removed the forced laziness.

In the process of changing the return type of result from (lib) to (lib * bool). This affects the Vlib module, and edits should be done.

injected the bool inside the lib module and its submodules. Progress: there is still a problem with the type Lib itself; should the bool be inserted there also?

_

Changes concerning the propagation of the new bool in different files

finished refactoring the code. The choice of dropping or maintaining the bool is not final.

_

modified lib_flags.ml to test for hidden deps and adapt the -H flag accordingly.

_

_

_

_

Changed the type of paths container into a map (path * bool)

removed uncessary diff

_

Maintained requires_compile and requires_link in compilation_context.ml. Reduced diff.

_

Added tests for failing when accessing a hidden dep, and for correct use of -H flag. More tests regarding compiler version and legacy mode behaviour to be added.

_

_

_

_

_

_

_

Reduced diff.

_

Edited the hidden-deps test + removed uncessary diffs from lib_flags.mli

Removed unnecessary deps from test dune files.
  • Loading branch information
MA0010 committed Jun 4, 2024
1 parent aef7671 commit 58445e1
Show file tree
Hide file tree
Showing 59 changed files with 365 additions and 254 deletions.
1 change: 0 additions & 1 deletion bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ let all : _ Cmdliner.Cmd.t list =
; Shutdown.command
; Diagnostics.command
; Monitor.command
; Greet.command
]
in
let groups =
Expand Down
6 changes: 1 addition & 5 deletions otherlibs/chrome-trace/test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
chrome_trace
;; This is because of the (implicit_transitive_deps false)
;; in dune-project
ppx_expect.config
ppx_expect.config_types
ppx_expect.common
base
ppx_inline_test.config)
ppx_expect.common)
(preprocess
(pps ppx_expect))
(instrumentation
Expand Down
6 changes: 1 addition & 5 deletions otherlibs/dune-glob/test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
dune_glob
;; This is because of the (implicit_transitive_deps false)
;; in dune-project
ppx_expect.config
ppx_expect.config_types
ppx_expect.common
base
ppx_inline_test.config)
ppx_expect.common)
(preprocess
(pps ppx_expect))
(instrumentation
Expand Down
6 changes: 1 addition & 5 deletions otherlibs/dune-rpc-lwt/test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
dune_rpc_lwt
;; This is because of the (implicit_transitive_deps false)
;; in dune-project
ppx_expect.config
ppx_expect.config_types
ppx_expect.common
base
ppx_inline_test.config)
ppx_expect.common)
(preprocess
(pps ppx_expect)))
2 changes: 1 addition & 1 deletion otherlibs/dune-site/src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
(special_builtin_support
(dune_site
(data_module dune_site_data)))
(libraries dune-private-libs.dune-section dune-site.private)
(libraries (re_export dune-private-libs.dune-section) dune-site.private)
(instrumentation
(backend bisect_ppx)))
2 changes: 0 additions & 2 deletions otherlibs/stdune/src/stdune.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


module Appendable_list = Appendable_list
module Nonempty_list = Nonempty_list
module Ansi_color = Ansi_color
Expand Down
6 changes: 1 addition & 5 deletions otherlibs/stdune/test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
unix
;; This is because of the (implicit_transitive_deps false)
;; in dune-project
ppx_expect.config
ppx_expect.config_types
ppx_expect.common
base
ppx_inline_test.config)
ppx_expect.common)
(preprocess
(pps ppx_expect)))
57 changes: 37 additions & 20 deletions src/dune_rules/compilation_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,34 @@ module Includes = struct
(* 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 make_includes_args ~mode groups =
Command.Args.memo
(Resolve.Memo.args
(let+ libs = requires in
Command.Args.S
[ iflags libs mode; Hidden_deps (Lib_file_deps.deps libs ~groups) ]))
[ iflags libs mode
; Hidden_deps (Lib_file_deps.deps (List.map ~f:fst 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 (* requires here represents the list of deps of the target library; it is equal to requires_compile 1.1*)
(let+ libs = requires in
Command.Args.S
[ iflags libs (Ocaml Native)
; Hidden_deps
(if opaque
then
List.map libs ~f:(fun lib ->
List.map 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.map ~f:fst libs)
~groups:[ Lib_file_deps.Group.Ocaml Cmi; Ocaml Cmx ])
]))
in
Expand All @@ -44,7 +45,6 @@ module Includes = struct
{ ocaml = { cmi = cmi_includes; cmo = cmi_includes; cmx = cmx_includes }
; melange = { cmi = melange_cmi_includes; cmj = melange_cmj_includes }
}

;;

let empty = Lib_mode.Cm_kind.Map.make_all Command.Args.empty
Expand Down Expand Up @@ -75,8 +75,9 @@ type t =
; obj_dir : Path.Build.t Obj_dir.t
; modules : modules
; flags : Ocaml_flags.t
; requires_compile : Lib.t list Resolve.Memo.t
; requires_link : Lib.t list Resolve.t Memo.Lazy.t (*list of libraries: the type here consists of a path and a library name*)
; requires_compile : (Lib.t * bool) list Resolve.Memo.t
(*list of libraries: the type here consists of a path and a library name*)
; requires_link : Lib.t list Resolve.t Memo.Lazy.t
; includes : Includes.t
; preprocessing : Pp_spec.t
; opaque : bool
Expand Down Expand Up @@ -141,12 +142,6 @@ let create
=
let open Memo.O in
let project = Scope.project scope in
let requires_compile =
if Dune_project.implicit_transitive_deps project
then Memo.Lazy.force requires_link
else requires_compile (*here, we test for ITD: if it is true, then the all deps required for linking are added; if false only those specified in the library stanza 1.2*)
in

let sandbox =
(* With sandboxing, there are a few build errors in ocaml platform 1162238ae
like: File "ocaml_modules/ocamlgraph/src/pack.ml", line 1: Error: The
Expand All @@ -155,6 +150,25 @@ let create
ocaml_modules/ocamlgraph/src/.graph.objs/byte/graph__Pack.cmi: *)
Sandbox_config.no_sandboxing
in
let context = Super_context.context super_context in
let* ocaml = Context.ocaml context in
let _dune_version = Dune_project.dune_version project in
let requires_compile =
let requires_link = Memo.Lazy.force requires_link in
if Dune_project.implicit_transitive_deps project
then Resolve.Memo.map ~f:(List.map ~f:(fun lib -> lib, true)) requires_link
else if Version.supports_hidden_includes ocaml.version
then
let open Resolve.Memo.O in
let* requires_compile = requires_compile in
let requires_compile =
Lib.Tbl.of_list_exn (List.map ~f:(fun lib -> lib, ()) requires_compile)
in
Resolve.Memo.map
~f:(List.map ~f:(fun lib -> lib, Lib.Tbl.mem requires_compile lib))
requires_link
else Resolve.Memo.map ~f:(List.map ~f:(fun lib -> lib, true)) requires_compile
in
let modes =
let default =
{ Lib_mode.Map.ocaml = Mode.Dict.make_both (Some Mode_conf.Kind.Inherited)
Expand All @@ -163,8 +177,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
Expand Down Expand Up @@ -192,7 +204,7 @@ let create
; flags
; requires_compile
; requires_link
; includes = Includes.make ~project ~opaque ~requires:requires_compile (*it is finally added in making the includes in the compilation context 1.3*)
; includes = Includes.make ~project ~opaque ~requires:requires_compile
; preprocessing
; opaque
; stdlib
Expand Down Expand Up @@ -273,13 +285,18 @@ 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 requires_compile =
Resolve.Memo.map ~f:(List.map ~f:(fun lib -> lib, true)) requires
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:requires_compile
in
{ cctx with
opaque
; flags = Ocaml_flags.empty
; requires_link = Memo.lazy_ (fun () -> requires)
; requires_compile = requires
; requires_compile
; includes
; modules
}
Expand Down Expand Up @@ -312,7 +329,7 @@ let root_module_entries t =
let open Action_builder.O in
let* requires = Resolve.Memo.read t.requires_compile in
let* l =
Action_builder.List.map requires ~f:(fun lib ->
Action_builder.List.map requires ~f:(fun (lib, _) ->
Action_builder.of_memo (entry_module_names t.super_context lib) >>= Resolve.read)
in
Action_builder.return (List.concat l)
Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/compilation_context.mli
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +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_compile : t -> Lib.t list Resolve.Memo.t
val requires_compile : t -> (Lib.t * bool) 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
val opaque : t -> bool
Expand Down
4 changes: 3 additions & 1 deletion src/dune_rules/exe_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ let executables_rules
let lib_config = ocaml.lib_config in
let stdlib_dir = lib_config.stdlib_dir in
let* requires_compile = Compilation_context.requires_compile cctx in
let requires_compile = Resolve.map ~f:(List.map ~f:fst) requires_compile in
let* requires_link = Compilation_context.requires_link cctx in
let* dep_graphs =
(* Building an archive for foreign stubs, we link the corresponding object
files directly to improve perf. *)
Expand Down Expand Up @@ -265,7 +267,7 @@ let executables_rules
in
( cctx
, Merlin.make
~requires:requires_compile
~requires:requires_link
~stdlib_dir
~flags
~modules
Expand Down
Loading

0 comments on commit 58445e1

Please sign in to comment.