Skip to content

Commit f7d63f0

Browse files
committed
Make super context creation pull based
Signed-off-by: Jeremie Dimino <[email protected]>
1 parent 79c9461 commit f7d63f0

File tree

5 files changed

+79
-79
lines changed

5 files changed

+79
-79
lines changed

src/dune_rules/gen_rules.ml

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -387,71 +387,9 @@ let gen_rules ~sctx ~dir components =
387387
Build_system.Subdir_set.union_all
388388
[ subdirs_to_keep1; subdirs_to_keep2; subdirs_to_keep3 ]
389389

390-
let filter_out_stanzas_from_hidden_packages ~visible_pkgs =
391-
List.filter_map ~f:(fun stanza ->
392-
let include_stanza =
393-
match Dune_file.stanza_package stanza with
394-
| None -> true
395-
| Some package ->
396-
let name = Package.name package in
397-
Package.Name.Map.mem visible_pkgs name
398-
in
399-
if include_stanza then
400-
Some stanza
401-
else
402-
match stanza with
403-
| Library l ->
404-
let open Option.O in
405-
let+ redirect = Dune_file.Library_redirect.Local.of_private_lib l in
406-
Dune_file.Library_redirect redirect
407-
| _ -> None)
408-
409-
let init ~contexts conf =
390+
let init () =
410391
let open Fiber.O in
411-
let { Dune_load.dune_files; packages; projects } = conf in
412-
let* only_packages = Memo.Build.run (Only_packages.get ()) in
413-
let packages = Option.value only_packages ~default:packages in
414-
let* sctxs =
415-
let open Memo.Build.O in
416-
Memo.Build.run
417-
(let rec sctxs =
418-
(* This lazy is just here for the need of [let rec]. We force it
419-
straight away, so it is safe regarding [Memo]. *)
420-
lazy
421-
(Context_name.Map.of_list_map_exn contexts ~f:(fun (c : Context.t) ->
422-
(c.name, Memo.Lazy.create (fun () -> make_sctx c))))
423-
and make_sctx (context : Context.t) =
424-
let host () =
425-
match context.for_host with
426-
| None -> Memo.Build.return None
427-
| Some h ->
428-
let+ sctx =
429-
Memo.Lazy.force
430-
(Context_name.Map.find_exn (Lazy.force sctxs) h.name)
431-
in
432-
Some sctx
433-
in
434-
let stanzas () =
435-
let+ stanzas = Dune_load.Dune_files.eval ~context dune_files in
436-
match only_packages with
437-
| None -> stanzas
438-
| Some visible_pkgs ->
439-
List.map stanzas ~f:(fun (dir_conf : Dune_file.t) ->
440-
{ dir_conf with
441-
stanzas =
442-
filter_out_stanzas_from_hidden_packages ~visible_pkgs
443-
dir_conf.stanzas
444-
})
445-
in
446-
let+ host, stanzas = Memo.Build.fork_and_join host stanzas in
447-
Super_context.create ?host ~context ~projects ~packages ~stanzas ()
448-
in
449-
Lazy.force sctxs |> Context_name.Map.to_list
450-
|> Memo.Build.parallel_map ~f:(fun (name, sctx) ->
451-
let+ sctx = Memo.Lazy.force sctx in
452-
(name, sctx))
453-
>>| Context_name.Map.of_list_exn)
454-
in
392+
let* sctxs = Memo.Build.run (Memo.Lazy.force Super_context.all) in
455393
let () =
456394
Build_system.set_packages (fun path ->
457395
match

src/dune_rules/gen_rules.mli

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,4 @@ open! Import
44

55
(* Set the rule generator callback. Returns evaluated Dune files per context
66
names. *)
7-
val init :
8-
contexts:Context.t list
9-
-> Dune_load.conf
10-
-> Super_context.t Context_name.Map.t Fiber.t
7+
val init : unit -> Super_context.t Context_name.Map.t Fiber.t

src/dune_rules/main.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ let init_build_system ~stats ~sandboxing_preference ~caching ~conf ~contexts =
2525
?caching ()
2626
in
2727
List.iter contexts ~f:Context.init_configurator;
28-
let+ scontexts = Gen_rules.init conf ~contexts in
28+
let+ scontexts = Gen_rules.init () in
2929
{ conf; contexts; scontexts }
3030

3131
let find_context_exn t ~name =

src/dune_rules/super_context.ml

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ let create_projects_by_package projects : Dune_project.t Package.Name.Map.t =
514514

515515
let modules_of_lib = Fdecl.create Dyn.Encoder.opaque
516516

517-
let create ~(context : Context.t) ?host ~projects ~packages ~stanzas () =
517+
let create ~(context : Context.t) ~host ~projects ~packages ~stanzas =
518518
let lib_config = Context.lib_config context in
519519
let projects_by_package = create_projects_by_package projects in
520520
let installed_libs =
@@ -686,6 +686,75 @@ let create ~(context : Context.t) ?host ~projects ~packages ~stanzas () =
686686
Fdecl.get modules_of_lib t ~dir ~name);
687687
t
688688

689+
let filter_out_stanzas_from_hidden_packages ~visible_pkgs =
690+
List.filter_map ~f:(fun stanza ->
691+
let include_stanza =
692+
match Dune_file.stanza_package stanza with
693+
| None -> true
694+
| Some package ->
695+
let name = Package.name package in
696+
Package.Name.Map.mem visible_pkgs name
697+
in
698+
if include_stanza then
699+
Some stanza
700+
else
701+
match stanza with
702+
| Dune_file.Library l ->
703+
let open Option.O in
704+
let+ redirect = Dune_file.Library_redirect.Local.of_private_lib l in
705+
Dune_file.Library_redirect redirect
706+
| _ -> None)
707+
708+
let all =
709+
Memo.lazy_ (fun () ->
710+
let open Memo.Build.O in
711+
let* { Dune_load.dune_files; packages; projects } = Dune_load.load ()
712+
and* contexts = Context.DB.all ()
713+
and* only_packages = Only_packages.get () in
714+
let packages = Option.value only_packages ~default:packages in
715+
let rec sctxs =
716+
(* This lazy is just here for the need of [let rec]. We force it
717+
straight away, so it is safe regarding [Memo]. *)
718+
lazy
719+
(Context_name.Map.of_list_map_exn contexts ~f:(fun (c : Context.t) ->
720+
(c.name, Memo.Lazy.create (fun () -> make_sctx c))))
721+
and make_sctx (context : Context.t) =
722+
let host () =
723+
match context.for_host with
724+
| None -> Memo.Build.return None
725+
| Some h ->
726+
let+ sctx =
727+
Memo.Lazy.force
728+
(Context_name.Map.find_exn (Lazy.force sctxs) h.name)
729+
in
730+
Some sctx
731+
in
732+
let stanzas () =
733+
let+ stanzas = Dune_load.Dune_files.eval ~context dune_files in
734+
match only_packages with
735+
| None -> stanzas
736+
| Some visible_pkgs ->
737+
List.map stanzas ~f:(fun (dir_conf : Dune_file.t) ->
738+
{ dir_conf with
739+
stanzas =
740+
filter_out_stanzas_from_hidden_packages ~visible_pkgs
741+
dir_conf.stanzas
742+
})
743+
in
744+
let+ host, stanzas = Memo.Build.fork_and_join host stanzas in
745+
create ~host ~context ~projects ~packages ~stanzas
746+
in
747+
Lazy.force sctxs |> Context_name.Map.to_list
748+
|> Memo.Build.parallel_map ~f:(fun (name, sctx) ->
749+
let+ sctx = Memo.Lazy.force sctx in
750+
(name, sctx))
751+
>>| Context_name.Map.of_list_exn)
752+
753+
let find name =
754+
let open Memo.Build.O in
755+
let+ all = Memo.Lazy.force all in
756+
Context_name.Map.find all name
757+
689758
let dir_status_db t = t.dir_status_db
690759

691760
module As_memo_key = struct

src/dune_rules/super_context.mli

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,17 @@ open Import
99

1010
type t
1111

12+
val all : t Context_name.Map.t Memo.Lazy.t
13+
14+
(** Find a super context by name. *)
15+
val find : Context_name.t -> t option Memo.Build.t
16+
1217
val modules_of_lib :
1318
(* to avoid a cycle with [Dir_contents] *)
1419
(t -> dir:Path.Build.t -> name:Lib_name.t -> Modules.t Memo.Build.t) Fdecl.t
1520

1621
val to_dyn : t -> Dyn.t
1722

18-
val create :
19-
context:Context.t
20-
-> ?host:t
21-
-> projects:Dune_project.t list
22-
-> packages:Package.t Package.Name.Map.t
23-
-> stanzas:Dune_file.t list
24-
-> unit
25-
-> t
26-
2723
val context : t -> Context.t
2824

2925
(** Context env with additional variables computed from packages *)

0 commit comments

Comments
 (0)