Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Dolmen in the JS worker #1249

Merged
merged 4 commits into from
Oct 7, 2024
Merged

Conversation

Halbaroth
Copy link
Collaborator

This PR removes the dependency of the Javascript worker to the legacy
frontend in order to remove it completely. In order to avoid code
duplication as it was done with the legacy frontend, we reuse the
Solving_loop module in the worker. This requires some modifications:

  • Add a new argument to the main function of Solving_loop to give
    different kind of sources instead of reading the file at the path
    Options.get_file (). The worker used a raw string as input. I reused
    the type Dolmen_loop.State.source.

  • Add a new argument to the main function of Solving_loop to pass the
    selector hook to the constructor of the environment of the SAT solver.
    This hook is not used by the worker to select instantiations but just to
    record them. I have no strong opinion to preserve this feature but I
    try to keep all the feature of the Javascript worker.

  • Remove the unused sat_env argument of the constructor init_env in
    Frontend. This removal is mostly motivated by the fact the semantic
    of init_env = Some env + selector_inst = Some f is not clear at
    all.

  • Monomophize the status type in Frontend. This status is only used
    for printting purposes but we kept the SAT environment in some of its
    constructors. Unfortunately, the type of the SAT can change at the
    very beginning of the main function of Solving_loop, which means it
    is not easy to add a new argument for the hook_status. This hook is
    required to print the result of AE in the worker.

This PR removes the dependency of the Javascript worker to the legacy
frontend in order to remove it completely. In order to avoid code
duplication as it was done with the legacy frontend, we reuse the
`Solving_loop` module in the worker. This requires some modifications:

- Add a new argument to the main function of `Solving_loop` to give
  different kind of sources instead of reading the file at the path
  `Options.get_file ()`. The worker used a raw string as input. I reused
  the type `Dolmen_loop.State.source`.

- Add a new argument to the main function of `Solving_loop` to pass the
  selector hook to the constructor of the environment of the SAT solver.
  This hook is not used by the worker to select instantiations but just to
  record them. I have no strong opinion to preserve this feature but I
  try to keep all the feature of the Javascript worker.

- Remove the unused `sat_env` argument of the constructor `init_env` in
  `Frontend`. This removal is mostly motivated by the fact the semantic
  of `init_env = Some env` + `selector_inst = Some f` is not clear at
  all.

- Monomophize the `status` type in `Frontend`. This status is only used
  for printting purposes but we kept the SAT environment in some of its
  constructors. Unfortunately, the type of the SAT can change at the
  very beginning of the main function of `Solving_loop`, which means it
  is not easy to add a new argument for the `hook_status`. This hook is
  required to print the result of AE in the worker.
@Halbaroth Halbaroth changed the title Dolmen worker js bis Use Dolmen in the JS worker Oct 7, 2024
Copy link
Collaborator

@bclement-ocp bclement-ocp left a comment

Choose a reason for hiding this comment

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

Overall looks good to me --- I think we can simplify handling of input files with Gbury/dolmen#201 and maybe get rid of Compat.In_channel.input_all entirely. If you have time to look into it it'd be great, but it's not important and I'm OK merging as is as well.

Comment on lines 455 to 459
| `Stdin when is_incremental ->
set_output_format ".smt2";
`Stdin
| `Stdin ->
`Raw (filename, Compat.In_channel.input_all stdin)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this is no longer necessary since Gbury/dolmen#201 and can be replaced with:

Suggested change
| `Stdin when is_incremental ->
set_output_format ".smt2";
`Stdin
| `Stdin ->
`Raw (filename, Compat.In_channel.input_all stdin)
| `Stdin -> `Stdin

(And the definition for is_incremental removed)

Comment on lines 466 to 469
let cin = open_in path in
let content = Compat.In_channel.input_all cin in
close_in cin;
`Raw (filename, content)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note to self: not sure why we had this, I think this can just be `File path (provided that we call set_output_format first)?

let res = Worker_interface.init_results () in
let msg = Fmt.str "Unknown error: %s" (Printexc.to_string exn) in
Copy link
Collaborator

Choose a reason for hiding this comment

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

❤️

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, this is not sufficient to catch some errors because the worker is running into Lwt monad and the backtrace is sometimes lost.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is still better for the ones we do catch — I'll take an improvement over what we had before even if it is not perfect!

Comment on lines +45 to +46
| Sat of Commands.sat_tdecl
| Unknown of Commands.sat_tdecl
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am slightly surprised that we were never using these environments, but if that is the case, there is no point to keep them anyways.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Me too. Our API is such an onion with too many layers, we didn't notice it before.

@@ -153,3 +153,99 @@ module Type = struct
match A.Id with B.Id -> Some Equal | _ -> None
end
end

module In_channel = struct
open In_channel
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah yes unfortunately that one is not going to work since the module itself was added in 4.14; bummer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

outch!

@Halbaroth
Copy link
Collaborator Author

Halbaroth commented Oct 7, 2024

Overall looks good to me --- I think we can simplify handling of input files with Gbury/dolmen#201 and maybe get rid of Compat.In_channel.input_all entirely. If you have time to look into it it'd be great, but it's not important and I'm OK merging as is as well.

Unfortunately, we still need input_all for the zip format. We may create a temporary file and read it instead of loading all the file in a string.

@bclement-ocp
Copy link
Collaborator

Overall looks good to me --- I think we can simplify handling of input files with Gbury/dolmen#201 and maybe get rid of Compat.In_channel.input_all entirely. If you have time to look into it it'd be great, but it's not important and I'm OK merging as is as well.

Unfortunately, we still need input_all for the zip format. We may create a temporary file and read it instead of loading all the file in a string.

I think for the zip format we use My_zip.extract_zip_file which does not use input_all? We are using input_all for the case of non-zip file, but I believe that passing `File path to Dolmen instead of reading the file ourselves should work.

We do not need `In_channel.input_all` too ;)
@Halbaroth Halbaroth merged commit bc49809 into OCamlPro:next Oct 7, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants