Skip to content

Commit

Permalink
_
Browse files Browse the repository at this point in the history
  • Loading branch information
MA0010 committed Jun 4, 2024
1 parent f4939a4 commit aef7671
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 20 deletions.
1 change: 1 addition & 0 deletions bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ let all : _ Cmdliner.Cmd.t list =
; Shutdown.command
; Diagnostics.command
; Monitor.command
; Greet.command
]
in
let groups =
Expand Down
3 changes: 1 addition & 2 deletions otherlibs/stdune/src/stdune.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[@@@alert unstable "The API of this library is not stable and may change without notice."]
[@@@alert "-unstable"]


module Appendable_list = Appendable_list
module Nonempty_list = Nonempty_list
Expand Down
11 changes: 7 additions & 4 deletions src/dune_rules/compilation_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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
Expand All @@ -18,7 +19,7 @@ module Includes = struct
let cmx_includes =
Command.Args.memo
(Resolve.Memo.args
(let+ libs = requires in
(let+ libs = requires in (* requires here represents the list of deps of the target library; it is equal to requires_compile 1.1*)
Command.Args.S
[ iflags libs (Ocaml Native)
; Hidden_deps
Expand All @@ -43,6 +44,7 @@ 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 @@ -74,7 +76,7 @@ type 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
; requires_link : Lib.t list Resolve.t Memo.Lazy.t (*list of libraries: the type here consists of a path and a library name*)
; includes : Includes.t
; preprocessing : Pp_spec.t
; opaque : bool
Expand Down Expand Up @@ -142,8 +144,9 @@ let create
let requires_compile =
if Dune_project.implicit_transitive_deps project
then Memo.Lazy.force requires_link
else requires_compile
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 Down Expand Up @@ -189,7 +192,7 @@ let create
; flags
; requires_compile
; requires_link
; includes = Includes.make ~project ~opaque ~requires:requires_compile
; includes = Includes.make ~project ~opaque ~requires:requires_compile (*it is finally added in making the includes in the compilation context 1.3*)
; preprocessing
; opaque
; stdlib
Expand Down
39 changes: 27 additions & 12 deletions src/dune_rules/lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ module Vlib : sig
Additionally, if linking is [true], ensures that every virtual library as
an implementation and re-arrange the list so that implementations replaces
virtual libraries. *)
val associate : (t * Dep_stack.t) list -> linking:bool -> t list Resolve.Memo.t
val associate : (t * bool * Dep_stack.t) list -> linking:bool -> t list Resolve.Memo.t

module Unimplemented : sig
(** set of unimplemented libraries*)
Expand Down Expand Up @@ -713,7 +713,7 @@ end = struct
module Partial = struct
type vlib_status =
| No_impl of Dep_stack.t
| Impl of lib * Dep_stack.t
| Impl of lib * bool * Dep_stack.t

type t = vlib_status Map.t

Expand All @@ -722,7 +722,7 @@ end = struct
let make closure : t Resolve.Memo.t =
let rec loop acc = function
| [] -> Resolve.Memo.return acc
| (lib, stack) :: libs ->
| (lib, _direct, stack) :: libs ->
let virtual_ = Lib_info.virtual_ lib.info in
(match lib.implements, virtual_ with
| None, None -> loop acc libs
Expand All @@ -735,8 +735,8 @@ end = struct
(* we've already traversed the virtual library because it must
have occurred earlier in the closure *)
assert false
| Some (No_impl _) -> loop (Map.set acc vlib (Impl (lib, stack))) libs
| Some (Impl (lib', stack')) ->
| Some (No_impl _) -> loop (Map.set acc vlib (Impl (lib, _direct, stack))) libs
| Some (Impl (lib', _direct, stack')) ->
let req_by' = Dep_stack.to_required_by stack' in
let req_by = Dep_stack.to_required_by stack in
Error.double_implementation
Expand All @@ -756,7 +756,7 @@ end = struct
| (vlib, Partial.No_impl stack) :: _ ->
let rb = Dep_stack.to_required_by stack in
Error.no_implementation (vlib.info, rb)
| (vlib, Impl (impl, _stack)) :: libs -> loop (Map.set acc vlib impl) libs
| (vlib, Impl (impl, _direct, _stack)) :: libs -> loop (Map.set acc vlib impl) libs
in
loop Map.empty (Map.to_list impls)
;;
Expand Down Expand Up @@ -795,7 +795,7 @@ end = struct

let associate closure ~linking =
let* impls = Table.Partial.make closure in
let closure = List.map closure ~f:fst in
let closure = List.map closure ~f:(fun (lib, _direct, _stack) -> lib) in
if linking && not (Table.Partial.is_empty impls)
then
let* impls = Table.make impls in
Expand Down Expand Up @@ -1641,7 +1641,7 @@ end = struct

module R = struct
type state =
{ result : (lib * Dep_stack.t) list
{ result : (lib * bool * Dep_stack.t) list
; visited : Set.t
; unimplemented : Vlib.Unimplemented.t
}
Expand All @@ -1663,12 +1663,18 @@ end = struct

let result computation ~linking =
let* state, () = R.run computation R.empty_state in
(*print_endline "-------------------";
List.iter ~f:(fun (lib, _deps) ->
print_endline (Lib_name.to_string lib.name)
) state.result;*) (*R.run? 1.2*)
Vlib.associate (List.rev state.result) ~linking
;;

let rec visit (t : t) ~stack (implements_via, lib) =
let open R.O in
let* state = R.get in
let () = print_endline "visit"
in
if Set.mem state.visited lib
then R.return ()
else (
Expand Down Expand Up @@ -1714,19 +1720,27 @@ end = struct
R.modify (fun state -> { state with unimplemented = unimplemented' })
in
let* () = R.List.iter deps ~f:(fun l -> visit t (None, l) ~stack:new_stack) in
R.modify (fun state -> { state with result = (lib, stack) :: state.result }))
R.modify (fun state -> { state with result = (lib, true, stack) :: state.result }))
;;
end

let step1_closure db ts ~forbidden_libraries =
let closure = Closure.make ~db ~forbidden_libraries in

( closure
, Closure.R.List.iter ts ~f:(fun lib ->
Closure.visit closure ~stack:Dep_stack.empty (None, lib)) )
Closure.visit closure ~stack:Dep_stack.empty (None, lib)
))
;;

(*function to a state with the booleans set right*)
let set_direct_deps ~result ts =
List.map result ~f:(fun (lib, _direct, stack) ->
(lib, (List.mem ts lib ~equal:(fun lib t -> lib = t)), stack))

let compile_closure_with_overlap_checks db ts ~forbidden_libraries =
let _closure, state = step1_closure db ts ~forbidden_libraries in
let* state = Closure.R.modify (fun state -> {state with result = set_direct_deps ~result:state.result ts}) in
Closure.result state ~linking:false
;;

Expand Down Expand Up @@ -1759,6 +1773,7 @@ end

let closure l ~linking =
let forbidden_libraries = Map.empty in

if linking
then Resolve_names.linking_closure_with_overlap_checks None l ~forbidden_libraries
else Resolve_names.compile_closure_with_overlap_checks None l ~forbidden_libraries
Expand Down Expand Up @@ -1829,7 +1844,7 @@ module Compile = struct
let db = Option.some_if (not allow_overlaps) db in
Memo.lazy_ (fun () ->
requires
>>= Resolve_names.compile_closure_with_overlap_checks
>>= Resolve_names.compile_closure_with_overlap_checks (*1.5*)
db
~forbidden_libraries:Map.empty)
in
Expand Down Expand Up @@ -2044,7 +2059,7 @@ module DB = struct
~private_deps:Allow_all
~dune_version:(Some dune_version))
in
let requires_link =
let requires_link = (*here is the definition of requires_link 1.1*)
Memo.Lazy.create (fun () ->
let* forbidden_libraries =
Resolve.Memo.List.map forbidden_libraries ~f:(fun (loc, name) ->
Expand Down
8 changes: 6 additions & 2 deletions src/dune_rules/module_compilation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ let build_cm
let+ src = Module.file m ~ml_kind in
let dst = Obj_dir.Module.cm_file_exn obj_dir m ~kind:cm_kind in
let obj =
Obj_dir.Module.obj_file obj_dir m ~kind:(Ocaml Cmx) ~ext:ocaml.lib_config.ext_obj
Obj_dir.Module.obj_file obj_dir m ~kind:(Ocaml Cmx) ~ext:ocaml.lib_config.ext_obj (*here*)
in

let open Memo.O in
let* extra_args, extra_deps, other_targets =
if precompiled_cmi
Expand Down Expand Up @@ -230,7 +231,7 @@ let build_cm
in
let obj_dirs =
Obj_dir.all_obj_dirs obj_dir ~mode
|> List.concat_map ~f:(fun p -> [ Command.Args.A "-I"; Path (Path.build p) ])
|> List.concat_map ~f:(fun p -> [ Command.Args.A "-I"; Path (Path.build p) ]) (*function to construct the set of -I statements on the commandline, given the set of includes 1.1*)
in
Super_context.add_rule
sctx
Expand Down Expand Up @@ -289,6 +290,7 @@ let build_module ?(force_write_cmi = false) ?(precompiled_cmi = false) cctx m =
Ocaml.Version.supports_split_at_emit ocaml.version
|| Ocaml_config.is_dev_version ocaml.ocaml_config
in

match Context.fdo_target_exe ctx, can_split with
| None, _ -> build_cm ~cm_kind:(Ocaml Cmx) ~phase:None
| Some _, false -> build_cm ~cm_kind:(Ocaml Cmx) ~phase:(Some All)
Expand Down Expand Up @@ -479,6 +481,8 @@ let build_root_module cctx root_module =
let sctx = Compilation_context.super_context cctx in
let file = Option.value_exn (Module.file root_module ~ml_kind:Impl) in
let dir = Compilation_context.dir cctx in


let open Memo.O in
let* () =
Super_context.add_rule
Expand Down

0 comments on commit aef7671

Please sign in to comment.