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

Avoid costly errors in JS witness generation #830

Merged
merged 6 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/base/constraint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ end = struct

let to_basic x = T x

let of_basic = function T x -> x | _ -> failwith "different constructor"
let of_basic = function
| T x ->
x
| _ ->
raise (Failure "different constructor")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm just replacing failwith s with raise (Failure s). This makes a difference because in JS, we use a custom override of the failwith function, to have it throw JS errors instead of strings. This is very important in a couple of circumstances where the error implies an actual failure condition. Here, the error is just used for control flow and always caught a level earlier, so we don't need a pretty error.

Copy link
Member

Choose a reason for hiding this comment

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

If you don't want to pay the cost of the exception here, can you change the code above it to use an val of_basic : ('v, 'f) basic -> ('v, 'f) t option instead.

end

let () = Basic.add_case (module M)
Expand Down
7 changes: 4 additions & 3 deletions src/base/request.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ module Handler = struct
fun stack0 label_stack req0 ->
let rec go req = function
| [] ->
failwith
( "Unhandled request: "
^ Core_kernel.String.concat ~sep:"\n" label_stack )
raise
Copy link
Member

Choose a reason for hiding this comment

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

As above, this should probably return an option, and the caller should handle the error by constructing an appropriate error message instead. This also has the benefit of never constructing this string if it isn't needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point! will change

(Failure
( "Unhandled request: "
^ Core_kernel.String.concat ~sep:"\n" label_stack ) )
| { handle } :: hs -> (
match handle req with
| Provide x ->
Expand Down
Loading