Skip to content

Commit

Permalink
A more generic way to define elision
Browse files Browse the repository at this point in the history
  • Loading branch information
xvw committed Mar 1, 2024
1 parent 2223d64 commit 2984251
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
11 changes: 9 additions & 2 deletions lib/backend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,12 @@ module Performance = struct
in
let resp =
(* TODO: make a cli-argument out of this instead of doing this always *)
let responses = List.map Merlin.Response.crop_value responses in
let responses =
List.map
(fun resp ->
Merlin.Response.(crop_value @@ crop_heap_and_cache @@ resp))
responses
in
{ Query_response.sample_id = id; cmd; responses }
in
let cmd = { Command.sample_id = id; cmd } in
Expand Down Expand Up @@ -381,7 +386,9 @@ let behavior config =
let responses =
List.map
(fun resp ->
Merlin.Response.(strip_file @@ crop_timing @@ resp))
Merlin.Response.(
strip_file @@ crop_timing @@ crop_heap_and_cache
@@ resp))
responses
in
{ Query_response.sample_id = id; cmd; responses }
Expand Down
32 changes: 18 additions & 14 deletions lib/merlin.ml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,20 @@ module Response = struct

let yojson_of_t x = x

let crop_arbitrary_keys keys = function
| `Assoc answer ->
let cropped_answer =
List.fold_left
(fun answer key -> List.remove_assoc key answer)
answer keys
in
`Assoc cropped_answer
| _ ->
(* Fixme *)
failwith
"Error while cropping merlin response: reponse should be an \
association list."

let get_timing = function
| `Assoc answer -> (
match List.assoc "timing" answer with
Expand All @@ -162,21 +176,11 @@ module Response = struct
| _ -> failwith "merlin gave bad output")
| _ -> failwith "merlin gave bad output"

let crop_timing = function
| `Assoc answer -> `Assoc (List.remove_assoc "timing" answer)
| _ ->
(* Fixme *)
failwith
"Error while cropping merlin response: reponse should have a key \
called timing."
let crop_timing answer = crop_arbitrary_keys [ "timing" ] answer
let crop_value answer = crop_arbitrary_keys [ "value" ] answer

let crop_value = function
| `Assoc answer -> `Assoc (List.remove_assoc "value" answer)
| _ ->
(* Fixme *)
failwith
"Error while cropping merlin response: reponse should have a key \
called value."
let crop_heap_and_cache answer =
crop_arbitrary_keys [ "cache"; "heap_mbytes" ] answer

let strip_file = function
| `Assoc l ->
Expand Down
4 changes: 4 additions & 0 deletions lib/merlin.mli
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ module Response : sig
(** Removes the value field from the merlin response, i.e. the actual response
to the query. *)

val crop_heap_and_cache : t -> t
(** Removes the heap_mbytes and cache field from the merlin response, i.e. the
actual response to the query. *)

val strip_file : t -> t
(** In a Merlin response of the form [{"value":{"file":file_dir, ...}, ...}],
where [file_dir] is a qualified file name, this strips off the directory
Expand Down

0 comments on commit 2984251

Please sign in to comment.