Skip to content

Merge backend and data - #78

Open
PizieDust wants to merge 2 commits into
tarides:mainfrom
PizieDust:merge-backend-data
Open

PizieDust wants to merge 2 commits into
tarides:mainfrom
PizieDust:merge-backend-data

Conversation

@PizieDust

Copy link
Copy Markdown
Collaborator

This Pr tries to answer to the second point on #70

Previously we had a module Backend, and Data was another module which had a functor wrapped around Backend.
the backend was chosen via cli and main.ml will pack them into modules and then workflows.ml will then unpack the value and instantiate the functor.

now, Backend is deleted, and Data is now a single, ordinary module using a variant for the backends and standard functions to achieve the rest.

@lyrm lyrm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! First, a rebase is needed.

Otherwise, I think you can go further and get rid of the closures in the main type t:
(Warning: the following code might contain typos; it is just an example)

type t = {
  init_cache : bool;
  write : sample -> unit;
  persist_logs : log:Logs.t -> unit;
}

and replace it with something like

type t =
  | Perf of Performance.t
  | Behav of Behavior.t
  | Bench of Benchmark.t

This will avoid having to build the closures and make the code cleaner and easier to read. Ideally the with_channels would look like the following (I dropped the unused labelled arguments):

let with_channels backend ~data_dir ~merlin ~proj_paths f =
  match backend with
  | Performance ->
      Performance.with_channels ~data_dir ~merlin ~proj_paths (fun p -> f (Perf p))
  | Behavior config ->
      Behavior.with_channels config ~data_dir (fun b -> f (Behav b))
  | Benchmark ->
      Benchmark.with_channels ~data_dir ~merlin (fun b -> f (Bench b))

and write becomes:

let write t sample =
  match t with
  | Perf p -> Performance.write_analysis_data p sample
  | Behav b -> Behavior.write_analysis_data b sample
  | Bench b -> Benchmark.write_analysis_data b sample

or with the current type of write_analysis_data function (without the useless labelled arguments):

let write t { id; responses; cmd; file; loc; query_type } =
  match t with
  | Perf p -> Performance.write_analysis_data ~id ~responses ~cmd ~file ~loc ~query_type p
  | Behav b -> Behavior.write_analysis_data ~id ~responses ~cmd b
  | Bench b -> Benchmark.write_analysis_data ~id ~responses ~cmd ~query_type b

Also all backends' t have two common fields: commands, logs. Does it simplify the code to put them together ?

Comment thread lib/data.ml Resolved
Comment thread lib/data.ml
Comment on lines +346 to +347
commands : out_channel;
logs : out_channel;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All backends have a commands and a logs field. Could we put them together to make some things cleaner ? I am unsure about that; this needs to be checked and thought through!.

Comment thread lib/data.ml Resolved
Comment thread lib/data.ml Resolved
Comment thread lib/data.ml Resolved
Addresses review feedback on tarides#78:
- Replace closure-based Data.t with variant type (Perf | Behav | Bench)
- Pass sample directly to write_analysis_data instead of individual labelled fields
- Clean up unused labelled arguments in Behavior.with_channels and Benchmark.with_channels
@PizieDust
PizieDust requested a review from lyrm November 5, 2026 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants