Skip to content

Commit

Permalink
Add tests for tail position info propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
aantron committed Oct 31, 2020
1 parent c20e076 commit 593a7c2
Show file tree
Hide file tree
Showing 13 changed files with 235 additions and 7 deletions.
9 changes: 7 additions & 2 deletions test/instrument/apply/operator.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ suppressed.
Subexpressions instrumented recursively.

$ bash ../test.sh <<'EOF'
> let _ = String.concat (String.trim "") @@ [];;
> let _ = (fun () -> ()) @@ ();;
> let _ = String.concat (String.trim "") @@ []
> let _ = (fun () -> ()) @@ ()
> let _ = String.concat "" @@ List.append [] []
> EOF
let _ =
___bisect_post_visit___ 1
Expand All @@ -23,3 +24,7 @@ Subexpressions instrumented recursively.
___bisect_visit___ 2;
())
@@ ())

let _ =
___bisect_post_visit___ 5
(String.concat "" @@ ___bisect_post_visit___ 4 (List.append [] []))
8 changes: 8 additions & 0 deletions test/instrument/apply/pipe.t
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ Instrumentation suppressed in tail position.
fun () ->
___bisect_visit___ 0;
"" |> String.trim


Right argument is not in tail position.

$ bash ../test.sh <<'EOF'
> let _ = [] |> List.mem 0
> EOF
let _ = ___bisect_post_visit___ 0 ([] |> List.mem 0)
18 changes: 18 additions & 0 deletions test/instrument/control/for.t
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,21 @@ Recursive instrumentation of subexpressions.
()
done
done


Subexpressions not in tail position.

$ bash ../test.sh <<'EOF'
> let _ =
> for _index = int_of_string "0" to int_of_string "1" do
> print_endline "foo"
> done
> EOF
let _ =
for
_index = ___bisect_post_visit___ 3 (int_of_string "0")
to ___bisect_post_visit___ 2 (int_of_string "1")
do
___bisect_visit___ 1;
___bisect_post_visit___ 0 (print_endline "foo")
done
18 changes: 18 additions & 0 deletions test/instrument/control/fun.t
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,21 @@ https://github.com/aantron/bisect_ppx/issues/319.
let () =
ignore
(___bisect_post_visit___ 2 (List.map (___bisect_post_visit___ 1 (f ())) []))


Expressions in default value are not in tail position; expressions in main
subexpression are.

$ bash ../test.sh <<'EOF'
> [@@@ocaml.warning "-27"]
> let _ =
> fun ?(l = print_endline "foo") () -> print_endline "bar"
> EOF
[@@@ocaml.warning "-27"]

let _ =
fun ?(l =
___bisect_visit___ 1;
___bisect_post_visit___ 0 (print_endline "foo")) () ->
___bisect_visit___ 2;
print_endline "bar"
11 changes: 11 additions & 0 deletions test/instrument/control/function.t
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,14 @@ Instrumentation suppressed "between arguments."
| () ->
___bisect_visit___ 0;
()


Expressions in cases are in tail position.

$ bash ../test.sh <<'EOF'
> let _ = function () -> print_endline "foo"
> EOF
let _ = function
| () ->
___bisect_visit___ 0;
print_endline "foo"
28 changes: 28 additions & 0 deletions test/instrument/control/if.t
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,31 @@ The next expression after if-then is instrumented as if it were an else-case.
());
___bisect_visit___ 0;
()


Condition does not need its out-edge instrumented. Expressions in cases are in
tail position iff the whole if-expression is in tail position.

$ bash ../test.sh <<'EOF'
> let _ =
> if bool_of_string "true" then print_endline "foo" else print_endline "bar"
> let _ = fun () ->
> if bool_of_string "true" then print_endline "foo" else print_endline "bar"
> EOF
let _ =
if bool_of_string "true" then (
___bisect_visit___ 3;
___bisect_post_visit___ 2 (print_endline "foo"))
else (
___bisect_visit___ 1;
___bisect_post_visit___ 0 (print_endline "bar"))

let _ =
fun () ->
___bisect_visit___ 6;
if bool_of_string "true" then (
___bisect_visit___ 5;
print_endline "foo")
else (
___bisect_visit___ 4;
print_endline "bar")
11 changes: 11 additions & 0 deletions test/instrument/control/lazy.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@ Recursive instrumentation of subexpression.
lazy
(___bisect_visit___ 0;
()))


Subexpression in tail position.

$ bash ../test.sh <<'EOF'
> let _ = lazy (print_endline "foo")
> EOF
let _ =
lazy
(___bisect_visit___ 0;
print_endline "foo")
24 changes: 24 additions & 0 deletions test/instrument/control/match.t
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,27 @@ Recursive instrumentation of cases.
| () ->
___bisect_visit___ 0;
())


Expressions in selector don't need their out-edge instrumented. Expressions in
cases are in tail position iff the match expression is in tail position.

$ bash ../test.sh <<'EOF'
> let _ =
> match print_endline "foo" with () -> print_endline "bar"
> let _ = fun () ->
> match print_endline "foo" with () -> print_endline "bar"
> EOF
let _ =
match print_endline "foo" with
| () ->
___bisect_visit___ 1;
___bisect_post_visit___ 0 (print_endline "bar")

let _ =
fun () ->
___bisect_visit___ 3;
match print_endline "foo" with
| () ->
___bisect_visit___ 2;
print_endline "bar"
16 changes: 16 additions & 0 deletions test/instrument/control/newtype.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,19 @@ Recursive instrumentation of subexpression.
fun (type _t) x ->
___bisect_visit___ 0;
x


Subexpression in tail position iff whole expression is in tail position.

$ bash ../test.sh <<'EOF'
> let _ =
> fun (type _t) -> print_endline "foo"
> let _ = fun () ->
> fun (type _t) -> print_endline "foo"
> EOF
let _ = fun (type _t) -> print_endline "foo"

let _ =
fun () ->
___bisect_visit___ 0;
fun (type _t) -> print_endline "foo"
24 changes: 24 additions & 0 deletions test/instrument/control/try.t
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,27 @@ Recursive instrumentation of subexpressions.
with _ ->
___bisect_visit___ 0;
())


Main subexpression is not in tail position. Handler is in tail position iff the
whole expression is in tail position.

$ bash ../test.sh <<'EOF'
> let _ =
> try print_endline "foo" with _ -> print_endline "bar"
> let _ = fun () ->
> try print_endline "foo" with _ -> print_endline "bar"
> EOF
let _ =
try ___bisect_post_visit___ 2 (print_endline "foo")
with _ ->
___bisect_visit___ 1;
___bisect_post_visit___ 0 (print_endline "bar")

let _ =
fun () ->
___bisect_visit___ 5;
try ___bisect_post_visit___ 4 (print_endline "foo")
with _ ->
___bisect_visit___ 3;
print_endline "bar"
12 changes: 12 additions & 0 deletions test/instrument/control/while.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,15 @@ Recursive instrumentation of subexpressions.
()
done
done


Subexpressions not in tail position.

$ bash ../test.sh <<'EOF'
> 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")
done
11 changes: 10 additions & 1 deletion test/instrument/recent/let-exception.t
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
$ bash ../test.sh <<'EOF'
> [@@@ocaml.warning "-38"]
> let _ = let exception E in print_endline "foo"
> let _ =
> let exception E in print_endline "foo"
> let _ = fun () ->
> let exception E in print_endline "foo"
> EOF
[@@@ocaml.warning "-38"]

let _ =
let exception E in
___bisect_post_visit___ 0 (print_endline "foo")

let _ =
fun () ->
___bisect_visit___ 1;
let exception E in
print_endline "foo"
52 changes: 48 additions & 4 deletions test/instrument/value.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ No instrumentation is inserted into expressions that are (syntactic) values.
$ bash test.sh <<'EOF'
> let _ = let x = 0 in x
> let _ = let _x = print_endline "foo" in print_endline "bar"
> let _ = fun () -> let _x = print_endline "foo" in print_endline "bar"
> EOF
let _ =
let x = 0 in
Expand All @@ -24,6 +25,12 @@ No instrumentation is inserted into expressions that are (syntactic) values.
let _ =
let _x = ___bisect_post_visit___ 1 (print_endline "foo") in
___bisect_post_visit___ 0 (print_endline "bar")

let _ =
fun () ->
___bisect_visit___ 3;
let _x = ___bisect_post_visit___ 2 (print_endline "foo") in
print_endline "bar"


$ bash test.sh <<'EOF'
Expand Down Expand Up @@ -141,6 +148,7 @@ No instrumentation is inserted into expressions that are (syntactic) values.
$ bash test.sh <<'EOF'
> let _ = (); 0
> let _ = print_endline "foo"; print_endline "bar"
> let _ = fun () -> print_endline "foo"; print_endline "bar"
> EOF
let _ =
();
Expand All @@ -149,33 +157,54 @@ No instrumentation is inserted into expressions that are (syntactic) values.
let _ =
___bisect_post_visit___ 1 (print_endline "foo");
___bisect_post_visit___ 0 (print_endline "bar")

let _ =
fun () ->
___bisect_visit___ 3;
___bisect_post_visit___ 2 (print_endline "foo");
print_endline "bar"


$ bash test.sh <<'EOF'
> let _ = (0 : int)
> let _ = (print_endline "foo" : unit)
> let _ = fun () -> (print_endline "foo" : unit)
> EOF
let _ = (0 : int)

let _ = (___bisect_post_visit___ 0 (print_endline "foo") : unit)

let _ =
fun () : unit ->
___bisect_visit___ 1;
print_endline "foo"


$ bash test.sh <<'EOF'
> let _ = (`Foo :> [ `Foo | `Bar ])
> let _ = (`Foo (print_endline "foo") :> [ `Foo of unit | `Bar ])
> let f () = `Foo
> let _ = (f () :> [ `Foo | `Bar ])
> let _ = fun () -> (f () :> [ `Foo | `Bar ])
> EOF
let _ = (`Foo :> [ `Foo | `Bar ])

let _ =
(`Foo (___bisect_post_visit___ 0 (print_endline "foo"))
:> [ `Foo of unit | `Bar ])
let f () =
___bisect_visit___ 0;
`Foo

let _ = (___bisect_post_visit___ 1 (f ()) :> [ `Foo | `Bar ])

let _ = fun () -> (f () :> [ `Foo | `Bar ])


$ bash test.sh <<'EOF'
> let _ = let module Foo = struct end in 0
> let _ =
> let module Foo = struct let () = print_endline "foo" end in
> print_endline "bar"
> let _ = fun () ->
> let module Foo = struct let () = print_endline "foo" end in
> print_endline "bar"
> EOF
let _ =
let module Foo = struct end in
Expand All @@ -186,6 +215,14 @@ No instrumentation is inserted into expressions that are (syntactic) values.
let () = ___bisect_post_visit___ 1 (print_endline "foo")
end in
___bisect_post_visit___ 0 (print_endline "bar")

let _ =
fun () ->
___bisect_visit___ 3;
let module Foo = struct
let () = ___bisect_post_visit___ 2 (print_endline "foo")
end in
print_endline "bar"


$ bash test.sh <<'EOF'
Expand All @@ -212,6 +249,7 @@ No instrumentation is inserted into expressions that are (syntactic) values.
> [@@@ocaml.warning "-33"]
> let _ = let open List in ignore
> let _ = let open List in print_endline "foo"
> let _ = fun () -> let open List in print_endline "foo"
> EOF
[@@@ocaml.warning "-33"]

Expand All @@ -222,3 +260,9 @@ No instrumentation is inserted into expressions that are (syntactic) values.
let _ =
let open List in
___bisect_post_visit___ 0 (print_endline "foo")

let _ =
fun () ->
___bisect_visit___ 1;
let open List in
print_endline "foo"

0 comments on commit 593a7c2

Please sign in to comment.