Skip to content

Commit

Permalink
config: remove workspace option
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoos committed Apr 15, 2024
1 parent 1001600 commit cd34ae1
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 146 deletions.
1 change: 0 additions & 1 deletion bin/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,6 @@ let shared_with_config_file =
{ Dune_config.Partial.display
; concurrency
; sandboxing_preference = Option.map sandboxing_preference ~f:(fun x -> [ x ])
; workspace_indexation = None
; terminal_persistence
; cache_enabled
; cache_reproducibility_check =
Expand Down
24 changes: 0 additions & 24 deletions src/dune_config_file/dune_config_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,6 @@ module Dune_config = struct
let decode = enum all
end

module Workspace_indexation = struct
type t =
| Enabled
| Disabled

let all = [ "enabled", Enabled; "disabled", Disabled ]

let to_dyn = function
| Enabled -> Dyn.Variant ("Enabled", [])
| Disabled -> Dyn.Variant ("Disabled", [])
;;

let decode = enum all
end

module Concurrency = struct
type t =
| Fixed of int
Expand Down Expand Up @@ -135,7 +120,6 @@ module Dune_config = struct
{ display : Display.t field
; concurrency : Concurrency.t field
; terminal_persistence : Terminal_persistence.t field
; workspace_indexation : Workspace_indexation.t field
; sandboxing_preference : Sandboxing_preference.t field
; cache_enabled : Config.Toggle.t field
; cache_reproducibility_check : Dune_cache.Config.Reproducibility_check.t field
Expand All @@ -160,7 +144,6 @@ module Dune_config = struct
{ display = field a.display b.display
; concurrency = field a.concurrency b.concurrency
; terminal_persistence = field a.terminal_persistence b.terminal_persistence
; workspace_indexation = field a.workspace_indexation b.workspace_indexation
; sandboxing_preference = field a.sandboxing_preference b.sandboxing_preference
; cache_enabled = field a.cache_enabled b.cache_enabled
; cache_reproducibility_check =
Expand All @@ -187,7 +170,6 @@ module Dune_config = struct
{ M.display
; concurrency
; terminal_persistence
; workspace_indexation
; sandboxing_preference
; cache_enabled
; cache_reproducibility_check
Expand All @@ -201,7 +183,6 @@ module Dune_config = struct
[ "display", field Display.to_dyn display
; "concurrency", field Concurrency.to_dyn concurrency
; "terminal_persistence", field Terminal_persistence.to_dyn terminal_persistence
; "workspace_indexation", field Workspace_indexation.to_dyn workspace_indexation
; ( "sandboxing_preference"
, field (Dyn.list Sandbox_mode.to_dyn) sandboxing_preference )
; "cache_enabled", field Config.Toggle.to_dyn cache_enabled
Expand Down Expand Up @@ -231,7 +212,6 @@ module Dune_config = struct
{ display = None
; concurrency = None
; terminal_persistence = None
; workspace_indexation = None
; sandboxing_preference = None
; cache_enabled = None
; cache_reproducibility_check = None
Expand Down Expand Up @@ -298,7 +278,6 @@ module Dune_config = struct
{ display = Simple { verbosity = Quiet; status_line = not Execution_env.inside_dune }
; concurrency = (if Execution_env.inside_dune then Fixed 1 else Auto)
; terminal_persistence = Clear_on_rebuild
; workspace_indexation = Disabled
; sandboxing_preference = []
; cache_enabled = `Disabled
; cache_reproducibility_check = Skip
Expand All @@ -319,8 +298,6 @@ module Dune_config = struct
and+ concurrency = field_o "jobs" (1, 0) Concurrency.decode
and+ terminal_persistence =
field_o "terminal-persistence" (1, 0) Terminal_persistence.decode
and+ workspace_indexation =
field_o "workspace_indexation" (3, 5) Workspace_indexation.decode
and+ sandboxing_preference =
field_o "sandboxing_preference" (1, 0) Sandboxing_preference.decode
and+ cache_enabled = field_o "cache" (2, 0) (enum Config.Toggle.all)
Expand Down Expand Up @@ -384,7 +361,6 @@ module Dune_config = struct
{ Partial.display
; concurrency
; terminal_persistence
; workspace_indexation
; sandboxing_preference
; cache_enabled
; cache_reproducibility_check
Expand Down
9 changes: 0 additions & 9 deletions src/dune_config_file/dune_config_file.mli
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ module Dune_config : sig
val all : (string * t) list
end

module Workspace_indexation : sig
type t =
| Enabled
| Disabled

val all : (string * t) list
end

module Action_output_on_success : sig
include module type of struct
include Dune_engine.Execution_parameters.Action_output_on_success
Expand All @@ -58,7 +50,6 @@ module Dune_config : sig
{ display : Display.t field
; concurrency : Concurrency.t field
; terminal_persistence : Terminal_persistence.t field
; workspace_indexation : Workspace_indexation.t field
; sandboxing_preference : Sandboxing_preference.t field
; cache_enabled : Config.Toggle.t field
; cache_reproducibility_check : Dune_cache.Config.Reproducibility_check.t field
Expand Down
199 changes: 92 additions & 107 deletions src/dune_rules/merlin/ocaml_index.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ open Import
module CC = Compilation_context
module SC = Super_context

let activated =
let open Memo.O in
let+ workspace = Workspace.workspace () in
workspace.config.workspace_indexation = Enabled
;;

let ocaml_index sctx ~dir =
Super_context.resolve_program_memo ~loc:None ~dir sctx "ocaml-index"
;;
Expand All @@ -25,79 +19,75 @@ let project_index ~build_dir = Path.Build.relative build_dir "project.ocaml-inde

let cctx_rules cctx =
let open Memo.O in
let* activated = activated in
if not activated
then Memo.return ()
else (
(* Indexing is performed by the external binary [ocaml-index] which performs
full shape reduction to compute the actual definition of all the elements in
the typedtree. This step is therefore dependent on all the cmts of those
definitions are used by all the cmts of modules in this cctx. *)
let dir = CC.dir cctx in
let modules =
CC.modules cctx |> Modules.fold_no_vlib ~init:[] ~f:(fun x acc -> x :: acc)
in
let sctx = CC.super_context cctx in
let obj_dir = CC.obj_dir cctx in
let cm_kind = Lib_mode.Cm_kind.(Ocaml Cmi) in
let modules_with_cmts =
List.filter_map
~f:(fun module_ ->
Obj_dir.Module.cmt_file obj_dir ~ml_kind:Impl ~cm_kind module_
|> Option.map ~f:(fun cmt -> Path.build cmt))
modules
in
let modules_with_cmtis =
List.filter_map
~f:(fun module_ ->
Obj_dir.Module.cmt_file obj_dir ~ml_kind:Intf ~cm_kind module_
|> Option.map ~f:(fun cmti -> Path.build cmti))
modules
in
let* ocaml_index = ocaml_index sctx ~dir in
let context_dir =
CC.context cctx |> Context.name |> Context_name.build_dir |> Path.build
in
let* additionnal_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. We pass these explicitely to the index with the `-I` flag.
(* Indexing is performed by the external binary [ocaml-index] which performs
full shape reduction to compute the actual definition of all the elements in
the typedtree. This step is therefore dependent on all the cmts of those
definitions are used by all the cmts of modules in this cctx. *)
let dir = CC.dir cctx in
let modules =
CC.modules cctx |> Modules.fold_no_vlib ~init:[] ~f:(fun x acc -> x :: acc)
in
let sctx = CC.super_context cctx in
let obj_dir = CC.obj_dir cctx in
let cm_kind = Lib_mode.Cm_kind.(Ocaml Cmi) in
let modules_with_cmts =
List.filter_map
~f:(fun module_ ->
Obj_dir.Module.cmt_file obj_dir ~ml_kind:Impl ~cm_kind module_
|> Option.map ~f:(fun cmt -> Path.build cmt))
modules
in
let modules_with_cmtis =
List.filter_map
~f:(fun module_ ->
Obj_dir.Module.cmt_file obj_dir ~ml_kind:Intf ~cm_kind module_
|> Option.map ~f:(fun cmti -> Path.build cmti))
modules
in
let* ocaml_index = ocaml_index sctx ~dir in
let context_dir =
CC.context cctx |> Context.name |> Context_name.build_dir |> Path.build
in
let* additionnal_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 \ requires_link)
*)
let open Resolve.Memo.O in
let* req_link = CC.requires_link cctx in
let+ req_compile = CC.requires_compile cctx in
let a =
List.fold_left req_link ~init:[] ~f:(fun acc l ->
if List.exists req_compile ~f:(Lib.equal l)
then acc
else (
let dir = Lib.info l |> Lib_info.obj_dir |> Obj_dir.byte_dir in
Command.Args.(A "-I" :: Path dir :: acc)))
in
Command.Args.S a
in
let fn = index_path_in_obj_dir obj_dir in
let includes =
Resolve.peek additionnal_libs |> Result.value ~default:Command.Args.empty
The implicit transitive libs correspond to the set:
(requires_link \ requires_link)
*)
let open Resolve.Memo.O in
let* req_link = CC.requires_link cctx in
let+ req_compile = CC.requires_compile cctx in
let a =
List.fold_left req_link ~init:[] ~f:(fun acc l ->
if List.exists req_compile ~f:(Lib.equal l)
then acc
else (
let dir = Lib.info l |> Lib_info.obj_dir |> Obj_dir.byte_dir in
Command.Args.(A "-I" :: Path dir :: acc)))
in
let aggregate =
Command.run
~dir:context_dir
ocaml_index
[ A "aggregate"
; A "--root"
; A Path.(Source.root |> source |> to_absolute_filename)
; A "-o"
; Target fn
; Deps modules_with_cmts
; Deps modules_with_cmtis
; includes
]
in
SC.add_rule sctx ~dir aggregate)
Command.Args.S a
in
let fn = index_path_in_obj_dir obj_dir in
let includes =
Resolve.peek additionnal_libs |> Result.value ~default:Command.Args.empty
in
let aggregate =
Command.run
~dir:context_dir
ocaml_index
[ A "aggregate"
; A "--root"
; A Path.(Source.root |> source |> to_absolute_filename)
; A "-o"
; Target fn
; Deps modules_with_cmts
; Deps modules_with_cmtis
; includes
]
in
SC.add_rule sctx ~dir aggregate
;;

let aggregate sctx ~dir ~target ~indexes =
Expand All @@ -124,34 +114,29 @@ let aggregate sctx ~dir ~target ~indexes =

let project_rule sctx project =
let open Memo.O in
let* activated = activated in
if not activated
then Memo.return ()
else (
let ctx = Super_context.context sctx in
let build_dir = Context.build_dir ctx in
let dir = Path.Build.append_source build_dir @@ Dune_project.root project in
let* stanzas = Dune_load.dune_files (Context.name ctx) in
let indexes =
Dune_file.fold_static_stanzas stanzas ~init:[] ~f:(fun dune_file stanza acc ->
let dir = Path.Build.append_source build_dir (Dune_file.dir dune_file) in
let obj =
match Stanza.repr stanza with
| Executables.T exes | Tests.T { exes; _ } ->
Some (Executables.obj_dir ~dir exes)
| Library.T lib -> Some (Library.obj_dir ~dir lib)
| _ -> None
in
match obj with
| None -> acc
| Some obj_dir -> index_path_in_obj_dir obj_dir :: acc)
in
let target = project_index ~build_dir:dir in
let ocaml_index_alias = Alias.make Alias0.ocaml_index ~dir in
let* () =
Rules.Produce.Alias.add_deps
ocaml_index_alias
(Action_builder.path @@ Path.build target)
in
aggregate sctx ~dir ~target ~indexes)
let ctx = Super_context.context sctx in
let build_dir = Context.build_dir ctx in
let dir = Path.Build.append_source build_dir @@ Dune_project.root project in
let* stanzas = Dune_load.dune_files (Context.name ctx) in
let indexes =
Dune_file.fold_static_stanzas stanzas ~init:[] ~f:(fun dune_file stanza acc ->
let dir = Path.Build.append_source build_dir (Dune_file.dir dune_file) in
let obj =
match Stanza.repr stanza with
| Executables.T exes | Tests.T { exes; _ } -> Some (Executables.obj_dir ~dir exes)
| Library.T lib -> Some (Library.obj_dir ~dir lib)
| _ -> None
in
match obj with
| None -> acc
| Some obj_dir -> index_path_in_obj_dir obj_dir :: acc)
in
let target = project_index ~build_dir:dir in
let ocaml_index_alias = Alias.make Alias0.ocaml_index ~dir in
let* () =
Rules.Produce.Alias.add_deps
ocaml_index_alias
(Action_builder.path @@ Path.build target)
in
aggregate sctx ~dir ~target ~indexes
;;
1 change: 0 additions & 1 deletion src/dune_rules/merlin/ocaml_index.mli
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ open Import
modules in that cctx in the corresponding obj_dir.
- then we aggregate all these separate indexes into a unique one. *)

val activated : bool Memo.t
val project_index : build_dir:Path.Build.t -> Path.Build.t

(** [cctx_rules cctx] sets the rules needed to generate the indexes for every
Expand Down
5 changes: 1 addition & 4 deletions src/dune_rules/module_compilation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ let build_cm
let+ () = copy_interface ~dir ~obj_dir ~sctx ~cm_kind m in
[], [], []))
in
let* with_index = Ocaml_index.activated in
let other_targets =
match cm_kind with
| Ocaml (Cmi | Cmo) | Melange (Cmi | Cmj) -> other_targets
Expand Down Expand Up @@ -192,9 +191,7 @@ let build_cm
let fn =
Option.value_exn (Obj_dir.Module.cmt_file obj_dir m ~cm_kind ~ml_kind)
in
if with_index
then fn :: other_targets, As [ "-bin-annot"; "-bin-annot-occurrences" ]
else fn :: other_targets, A "-bin-annot")
fn :: other_targets, As [ "-bin-annot"; "-bin-annot-occurrences" ])
else other_targets, Command.Args.empty
in
let opaque_arg : _ Command.Args.t =
Expand Down

0 comments on commit cd34ae1

Please sign in to comment.