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

Convert error propagation to monadic style for Ppxlib 0.28, 0.29 compatibility #413

Merged
merged 3 commits into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
540 changes: 331 additions & 209 deletions src/ppx/instrument.ml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/ppx/instrument.mli
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class instrumenter : object
inherit Ppxlib.Ast_traverse.map_with_expansion_context
inherit Ppxlib.Ast_traverse.map_with_expansion_context_and_errors

method transform_impl_file:
Ppxlib.Expansion_context.Base.t ->
Expand Down
16 changes: 8 additions & 8 deletions test/instrument/apply/and.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ Recursive instrumentation of subexpressions.
> ((bool_of_string "true") & (bool_of_string "false")) [@ocaml.warning "-3"]
> EOF
let _ =
___bisect_post_visit___ 2 (bool_of_string "true")
___bisect_post_visit___ 0 (bool_of_string "true")
&&
(___bisect_visit___ 1;
___bisect_post_visit___ 0 (bool_of_string "false"))
(___bisect_visit___ 2;
___bisect_post_visit___ 1 (bool_of_string "false"))

let _ =
(___bisect_post_visit___ 5 (bool_of_string "true")
(___bisect_post_visit___ 3 (bool_of_string "true")
&
(___bisect_visit___ 4;
___bisect_post_visit___ 3 (bool_of_string "false")))
(___bisect_visit___ 5;
___bisect_post_visit___ 4 (bool_of_string "false")))
[@ocaml.warning "-3"]


Expand All @@ -58,7 +58,7 @@ The second subexpression is not post-instrumented if it is in tail position.
> EOF
let f _ =
___bisect_visit___ 2;
___bisect_post_visit___ 1 (bool_of_string "true")
___bisect_post_visit___ 0 (bool_of_string "true")
&&
(___bisect_visit___ 0;
(___bisect_visit___ 1;
bool_of_string "false")
8 changes: 4 additions & 4 deletions test/instrument/apply/or.t
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ Recursive instrumentation of subexpressions.
if ___bisect_post_visit___ 3 (bool_of_string "true") then (
___bisect_visit___ 0;
true)
else if ___bisect_post_visit___ 2 (bool_of_string "false") then (
___bisect_visit___ 1;
else if ___bisect_post_visit___ 1 (bool_of_string "false") then (
___bisect_visit___ 2;
true)
else false

let _ =
if ___bisect_post_visit___ 7 (bool_of_string "true") then (
___bisect_visit___ 4;
true)
else if ___bisect_post_visit___ 6 (bool_of_string "false") then (
___bisect_visit___ 5;
else if ___bisect_post_visit___ 5 (bool_of_string "false") then (
___bisect_visit___ 6;
true)
else false

Expand Down
4 changes: 2 additions & 2 deletions test/instrument/apply/pipe.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Subexpressions instrumented recursively.
> EOF
let _ =
___bisect_post_visit___ 2
( ___bisect_post_visit___ 1 (String.trim "") |> fun s ->
___bisect_visit___ 0;
( ___bisect_post_visit___ 0 (String.trim "") |> fun s ->
___bisect_visit___ 1;
String.trim s )


Expand Down
16 changes: 8 additions & 8 deletions test/instrument/control/for.t
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ Recursive instrumentation of subexpressions.
for
_index =
for _i = 0 to 1 do
___bisect_visit___ 3;
___bisect_visit___ 0;
()
done;
0
to for _i = 0 to 1 do
___bisect_visit___ 2;
___bisect_visit___ 1;
()
done;
1
do
___bisect_visit___ 1;
___bisect_visit___ 3;
for _i = 0 to 1 do
___bisect_visit___ 0;
___bisect_visit___ 2;
()
done
done
Expand All @@ -70,9 +70,9 @@ Subexpressions not in tail position.
> EOF
let _ =
for
_index = ___bisect_post_visit___ 3 (int_of_string "0")
to ___bisect_post_visit___ 2 (int_of_string "1")
_index = ___bisect_post_visit___ 0 (int_of_string "0")
to ___bisect_post_visit___ 1 (int_of_string "1")
do
___bisect_visit___ 1;
___bisect_post_visit___ 0 (print_endline "foo")
___bisect_visit___ 3;
___bisect_post_visit___ 2 (print_endline "foo")
done
22 changes: 11 additions & 11 deletions test/instrument/control/if.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ Recursive instrumentation of subexpressions.
let _ =
if
if true then (
___bisect_visit___ 7;
___bisect_visit___ 1;
true)
else (
___bisect_visit___ 6;
___bisect_visit___ 0;
false)
then (
___bisect_visit___ 5;
___bisect_visit___ 7;
if true then (
___bisect_visit___ 4;
___bisect_visit___ 3;
true)
else (
___bisect_visit___ 3;
___bisect_visit___ 2;
false))
else (
___bisect_visit___ 2;
___bisect_visit___ 6;
if true then (
___bisect_visit___ 1;
___bisect_visit___ 5;
true)
else (
___bisect_visit___ 0;
___bisect_visit___ 4;
false))


Expand Down Expand Up @@ -83,10 +83,10 @@ tail position iff the whole if-expression is in tail position.
let _ =
if bool_of_string "true" then (
___bisect_visit___ 3;
___bisect_post_visit___ 2 (print_endline "foo"))
___bisect_post_visit___ 0 (print_endline "foo"))
else (
___bisect_visit___ 1;
___bisect_post_visit___ 0 (print_endline "bar"))
___bisect_visit___ 2;
___bisect_post_visit___ 1 (print_endline "bar"))

let _ =
fun () ->
Expand Down
12 changes: 6 additions & 6 deletions test/instrument/control/while.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ Recursive instrumentation of subexpressions.
let _ =
while
while true do
___bisect_visit___ 2;
___bisect_visit___ 0;
()
done;
true
do
___bisect_visit___ 1;
___bisect_visit___ 2;
while true do
___bisect_visit___ 0;
___bisect_visit___ 1;
()
done
done
Expand All @@ -42,7 +42,7 @@ Subexpressions not in tail position.
> let _ = while bool_of_string "true" do print_endline "foo" done
> EOF
let _ =
while ___bisect_post_visit___ 2 (bool_of_string "true") do
___bisect_visit___ 1;
___bisect_post_visit___ 0 (print_endline "foo")
while ___bisect_post_visit___ 0 (bool_of_string "true") do
___bisect_visit___ 2;
___bisect_post_visit___ 1 (print_endline "foo")
done
10 changes: 5 additions & 5 deletions test/instrument/recent/letop.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Subexpressions instrumented recursively.
x

let _ =
let* () = ___bisect_post_visit___ 7 (print_endline "foo")
and* () = ___bisect_post_visit___ 6 (print_endline "bar") in
___bisect_visit___ 5;
let* () = ___bisect_post_visit___ 4 (print_endline "baz") in
___bisect_visit___ 3;
let* () = ___bisect_post_visit___ 3 (print_endline "foo")
and* () = ___bisect_post_visit___ 4 (print_endline "bar") in
___bisect_visit___ 7;
let* () = ___bisect_post_visit___ 5 (print_endline "baz") in
___bisect_visit___ 6;
return ()
8 changes: 4 additions & 4 deletions test/instrument/value.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ No instrumentation is inserted into expressions that are (syntactic) values.
x

let _ =
let _x = ___bisect_post_visit___ 1 (print_endline "foo") in
___bisect_post_visit___ 0 (print_endline "bar")
let _x = ___bisect_post_visit___ 0 (print_endline "foo") in
___bisect_post_visit___ 1 (print_endline "bar")

let _ =
fun () ->
Expand Down Expand Up @@ -212,9 +212,9 @@ No instrumentation is inserted into expressions that are (syntactic) values.

let _ =
let module Foo = struct
let () = ___bisect_post_visit___ 1 (print_endline "foo")
let () = ___bisect_post_visit___ 0 (print_endline "foo")
end in
___bisect_post_visit___ 0 (print_endline "bar")
___bisect_post_visit___ 1 (print_endline "bar")

let _ =
fun () ->
Expand Down