Skip to content

Commit 7cd0554

Browse files
Leonidas-from-XIVgridbugs
authored andcommitted
Don't recalculate sctx when we already have it
Signed-off-by: Marek Kubica <[email protected]>
1 parent c55634c commit 7cd0554

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

bin/describe/describe_location.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ let term : unit Term.t =
3636
let open Memo.O in
3737
let* sctx = setup >>| Import.Main.find_scontext_exn ~name:context in
3838
let* prog = Exec.Cmd_arg.expand ~root:(Common.root common) ~sctx prog in
39-
let+ path = Exec.get_path common context ~prog >>| Path.to_string in
39+
let+ path = Exec.get_path common sctx ~prog >>| Path.to_string in
4040
Dune_console.printf "%s" path
4141
;;
4242

bin/exec.ml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,14 @@ let build_prog ~no_rebuild ~prog p =
115115
p
116116
;;
117117

118-
let dir_of_context common context =
119-
let open Memo.O in
120-
let+ sctx = Super_context.find_exn context in
118+
let dir_of_context common sctx =
121119
let context = Dune_rules.Super_context.context sctx in
122120
Path.Build.relative (Context.build_dir context) (Common.prefix_target common "")
123121
;;
124122

125-
let get_path common context ~prog =
123+
let get_path common sctx ~prog =
126124
let open Memo.O in
127-
let* sctx = Super_context.find_exn context
128-
and* dir = dir_of_context common context in
125+
let dir = dir_of_context common sctx in
129126
match Filename.analyze_program_name prog with
130127
| In_path ->
131128
Super_context.resolve_program_memo sctx ~dir ~loc:None prog
@@ -153,9 +150,9 @@ let get_path common context ~prog =
153150
| None -> not_found_with_suggestions ~dir ~prog)
154151
;;
155152

156-
let get_path_and_build_if_necessary common context ~no_rebuild ~prog =
153+
let get_path_and_build_if_necessary common sctx ~no_rebuild ~prog =
157154
let open Memo.O in
158-
let* path = get_path common context ~prog in
155+
let* path = get_path common sctx ~prog in
159156
match Filename.analyze_program_name prog with
160157
| In_path | Relative_to_current_dir -> build_prog ~no_rebuild ~prog path
161158
| Absolute -> Memo.return path
@@ -166,7 +163,7 @@ let step ~prog ~args ~common ~no_rebuild ~context ~on_exit () =
166163
let* sctx = Super_context.find_exn context in
167164
let* path =
168165
let* prog = Cmd_arg.expand ~root:(Common.root common) ~sctx prog in
169-
get_path_and_build_if_necessary common context ~no_rebuild ~prog
166+
get_path_and_build_if_necessary common sctx ~no_rebuild ~prog
170167
and* args =
171168
Memo.parallel_map args ~f:(Cmd_arg.expand ~root:(Common.root common) ~sctx)
172169
in
@@ -282,8 +279,7 @@ let exec_building_directly ~common ~config ~context ~prog ~args ~no_rebuild =
282279
let* env = Super_context.context_env sctx
283280
and* prog =
284281
let* prog = Cmd_arg.expand ~root:(Common.root common) ~sctx prog in
285-
get_path_and_build_if_necessary common context ~no_rebuild ~prog
286-
>>| Path.to_string
282+
get_path_and_build_if_necessary common sctx ~no_rebuild ~prog >>| Path.to_string
287283
and* args =
288284
Memo.parallel_map ~f:(Cmd_arg.expand ~root:(Common.root common) ~sctx) args
289285
in

bin/exec.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ end
1919
- otherwise if [prog] is the name of an executable in one of the directories
2020
listed in the PATH environment variable, the path to that executable will be
2121
returned. *)
22-
val get_path : Common.t -> Context_name.t -> prog:string -> Path.t Memo.t
22+
val get_path : Common.t -> Super_context.t -> prog:string -> Path.t Memo.t
2323

2424
val command : unit Cmd.t

0 commit comments

Comments
 (0)