language
stringlengths
0
24
filename
stringlengths
9
214
code
stringlengths
99
9.93M
OCaml
hhvm/hphp/hack/test/ounit/dumper.ml
(* Dump an OCaml value into a printable string. * By Richard W.M. Jones ([email protected]). * dumper.ml 1.2 2005/02/06 12:38:21 rich Exp *) open Obj let rec dump r = if is_int r then string_of_int (magic r : int) else (* Block. *) let rec get_fields acc = function | 0 -> acc | n -> let n = n - 1 in get_fields (field r n :: acc) n in let rec is_list r = if is_int r then if (magic r : int) = 0 then true (* [] *) else false else let s = size r and t = tag r in if t = 0 && s = 2 then is_list (field r 1) (* h :: t *) else false in let rec get_list r = if is_int r then [] else let h = field r 0 and t = get_list (field r 1) in h :: t in let opaque name = (* XXX In future, print the address of value 'r'. Not possible in * pure OCaml at the moment. *) "<" ^ name ^ ">" in let s = size r and t = tag r in (* From the tag, determine the type of block. *) if is_list r then (* List. *) let fields = get_list r in "[" ^ String.concat "; " (List.map dump fields) ^ "]" else if t = 0 then (* Tuple, array, record. *) let fields = get_fields [] s in "(" ^ String.concat ", " (List.map dump fields) ^ ")" (* Note that [lazy_tag .. forward_tag] are < no_scan_tag. Not * clear if very large constructed values could have the same * tag. XXX *) else if t = lazy_tag then opaque "lazy" else if t = closure_tag then opaque "closure" else if t = object_tag then (* Object. *) let fields = get_fields [] s in let (_clasz, id, slots) = match fields with | h :: h' :: t -> (h, h', t) | _ -> assert false in (* No information on decoding the class (first field). So just print * out the ID and the slots. *) "Object #" ^ dump id ^ " (" ^ String.concat ", " (List.map dump slots) ^ ")" else if t = infix_tag then opaque "infix" else if t = forward_tag then opaque "forward" else if t < no_scan_tag then (* Constructed value. *) let fields = get_fields [] s in "Tag" ^ string_of_int t ^ " (" ^ String.concat ", " (List.map dump fields) ^ ")" else if t = string_tag then "\"" ^ String.escaped (magic r : string) ^ "\"" else if t = double_tag then string_of_float (magic r : float) else if t = abstract_tag then opaque "abstract" else if t = custom_tag then opaque "custom" else failwith ("dump: impossible tag (" ^ string_of_int t ^ ")") let dump v = dump (repr v)
OCaml Interface
hhvm/hphp/hack/test/ounit/dumper.mli
(* Dump an OCaml value into a printable string. * By Richard W.M. Jones ([email protected]). * dumper.mli 1.1 2005/02/03 23:07:47 rich Exp *) val dump : 'a -> string
OCaml
hhvm/hphp/hack/test/ounit/oUnit.ml
(***********************************************************************) (* The OUnit library *) (* *) (* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 *) (* Maas-Maarten Zeeman. *) (* The package OUnit is copyright by Maas-Maarten Zeeman. Permission is hereby granted, free of charge, to any person obtaining a copy of this document and the OUnit software ("the Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. The Software is provided ``as is'', without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall Maas-Maarten Zeeman be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the Software or the use or other dealings in the software. *) (***********************************************************************) (* pad: just harmonized some APIs regarding the 'msg' label *) let bracket set_up f tear_down () = let fixture = set_up () in try f fixture; tear_down fixture with | e -> tear_down fixture; raise e exception Skip of string let skip_if b msg = if b then raise (Skip msg) exception Todo of string let todo msg = raise (Todo msg) let assert_failure msg = failwith ("OUnit: " ^ msg) let assert_bool ~msg b = if not b then assert_failure msg let assert_string str = if not (str = "") then assert_failure str let assert_equal ?(cmp = ( = )) ?printer ?msg expected actual = (* pad: better to use dump by default *) let p = Dumper.dump in let get_error_string _ = match (printer, msg) with | (None, None) -> Format.sprintf "expected: %s but got: %s" (p expected) (p actual) | (None, Some s) -> Format.sprintf "%s\nnot equal, expected: %s but got: %s" s (p expected) (p actual) | (Some p, None) -> Format.sprintf "expected: %s but got: %s" (p expected) (p actual) | (Some p, Some s) -> Format.sprintf "%s\nexpected: %s but got: %s" s (p expected) (p actual) in if not (cmp expected actual) then assert_failure (get_error_string ()) let raises f = try f (); None with | e -> Some e let assert_raises ?msg exn (f : unit -> 'a) = let pexn = Printexc.to_string in let get_error_string _ = let str = Format.sprintf "expected exception %s, but no exception was raised." (pexn exn) in match msg with | None -> assert_failure str | Some s -> assert_failure (Format.sprintf "%s\n%s" s str) in match raises f with | None -> assert_failure (get_error_string ()) | Some e -> assert_equal ?msg ~printer:pexn exn e (* Compare floats up to a given relative error *) let cmp_float ?(epsilon = 0.00001) a b = abs_float (a -. b) <= epsilon *. abs_float a || abs_float (a -. b) <= epsilon *. abs_float b (* Now some handy shorthands *) let ( @? ) msg a = assert_bool ~msg a (* The type of test function *) type test_fun = unit -> unit (* The type of tests *) type test = | TestCase of test_fun | TestList of test list | TestLabel of string * test (* Some shorthands which allows easy test construction *) let ( >: ) s t = TestLabel (s, t) (* infix *) let ( >:: ) s f = TestLabel (s, TestCase f) (* infix *) let ( >::: ) s l = TestLabel (s, TestList l) (* infix *) (* Utility function to manipulate test *) let rec test_decorate g tst = match tst with | TestCase f -> TestCase (g f) | TestList tst_lst -> TestList (List.map (test_decorate g) tst_lst) | TestLabel (str, tst) -> TestLabel (str, test_decorate g tst) (* Return the number of available tests *) let rec test_case_count test = match test with | TestCase _ -> 1 | TestLabel (_, t) -> test_case_count t | TestList l -> List.fold_left (fun c t -> c + test_case_count t) 0 l type node = | ListItem of int | Label of string type path = node list let string_of_node node = match node with | ListItem n -> string_of_int n | Label s -> s let string_of_path path = List.fold_left (fun a l -> if a = "" then l else l ^ ":" ^ a) "" (List.map string_of_node path) (* Some helper function, they are generally applicable *) (* Applies function f in turn to each element in list. Function f takes one element, and integer indicating its location in the list *) let mapi f l = let rec rmapi cnt l = match l with | [] -> [] | h :: t -> f h cnt :: rmapi (cnt + 1) t in rmapi 0 l let fold_lefti f accu l = let rec rfold_lefti cnt accup l = match l with | [] -> accup | h :: t -> rfold_lefti (cnt + 1) (f accup h cnt) t in rfold_lefti 0 accu l (* Returns all possible paths in the test. The order is from test case to root *) let test_case_paths test = let rec tcps path test = match test with | TestCase _ -> [path] | TestList tests -> List.concat (mapi (fun t i -> tcps (ListItem i :: path) t) tests) | TestLabel (l, t) -> tcps (Label l :: path) t in tcps [] test (* Test filtering with their path *) module SetTestPath = Set.Make (String) let test_filter only test = let set_test = List.fold_left (fun st str -> SetTestPath.add str st) SetTestPath.empty only in let foldi f acc lst = List.fold_left (fun (i, acc) e -> let nacc = f i acc e in (i + 1, nacc)) acc lst in let rec filter_test path tst = if SetTestPath.mem (string_of_path path) set_test then Some tst else match tst with | TestCase _ -> None | TestList tst_lst -> let (_, ntst_lst) = foldi (fun i ntst_lst tst -> let nntst_lst = match filter_test (ListItem i :: path) tst with | Some tst -> tst :: ntst_lst | None -> ntst_lst in nntst_lst) (0, []) tst_lst in if ntst_lst = [] then None else Some (TestList ntst_lst) | TestLabel (lbl, tst) -> let ntst = filter_test (Label lbl :: path) tst in (match ntst with | Some tst -> Some (TestLabel (lbl, tst)) | None -> None) in filter_test [] test (* The possible test results *) type test_result = | RSuccess of path | RFailure of path * string | RError of path * string | RSkip of path * string | RTodo of path * string let is_success = function | RSuccess _ -> true | RFailure _ | RError _ | RSkip _ | RTodo _ -> false let is_failure = function | RFailure _ -> true | RSuccess _ | RError _ | RSkip _ | RTodo _ -> false let is_error = function | RError _ -> true | RSuccess _ | RFailure _ | RSkip _ | RTodo _ -> false let is_skip = function | RSkip _ -> true | RSuccess _ | RFailure _ | RError _ | RTodo _ -> false let is_todo = function | RTodo _ -> true | RSuccess _ | RFailure _ | RError _ | RSkip _ -> false let result_flavour = function | RError _ -> "Error" | RFailure _ -> "Failure" | RSuccess _ -> "Success" | RSkip _ -> "Skip" | RTodo _ -> "Todo" let result_path = function | RSuccess path | RError (path, _) | RFailure (path, _) | RSkip (path, _) | RTodo (path, _) -> path let result_msg = function | RSuccess _ -> "Success" | RError (_, msg) | RFailure (_, msg) | RSkip (_, msg) | RTodo (_, msg) -> msg (* Returns true if the result list contains successes only *) let rec was_successful results = match results with | [] -> true | RSuccess _ :: t | RSkip _ :: t -> was_successful t | RFailure _ :: _ | RError _ :: _ | RTodo _ :: _ -> false (* Events which can happen during testing *) type test_event = | EStart of path | EEnd of path | EResult of test_result (* Run all tests, report starts, errors, failures, and return the results *) let perform_test report test = let run_test_case f path = try f (); RSuccess path with | Failure s -> RFailure (path, s) | Skip s -> RSkip (path, s) | Todo s -> RTodo (path, s) | s -> let stack = Printexc.get_backtrace () in RError (path, Printexc.to_string s ^ " " ^ stack) in let rec run_test path results test = match test with | TestCase f -> report (EStart path); let result = run_test_case f path in report (EResult result); report (EEnd path); result :: results | TestList tests -> fold_lefti (fun results t cnt -> run_test (ListItem cnt :: path) results t) results tests | TestLabel (label, t) -> run_test (Label label :: path) results t in run_test [] [] test (* Function which runs the given function and returns the running time of the function, and the original result in a tuple *) let time_fun f x y = let begin_time = Unix.gettimeofday () in (Unix.gettimeofday () -. begin_time, f x y) (* A simple (currently too simple) text based test runner *) let run_test_tt ?(verbose = false) test = let printf = Format.printf in let separator1 = "======================================================================" in let separator2 = "----------------------------------------------------------------------" in let string_of_result = function | RSuccess _ -> if verbose then "ok\n" else "." | RFailure (_, _) -> if verbose then "FAIL\n" else "F" | RError (_, _) -> if verbose then "ERROR\n" else "E" | RSkip (_, _) -> if verbose then "SKIP\n" else "S" | RTodo (_, _) -> if verbose then "TODO\n" else "T" in let report_event = function | EStart p -> if verbose then printf "%s ... " (string_of_path p) | EEnd _ -> () | EResult result -> printf "%s@?" (string_of_result result) in let print_result_list results = List.iter (fun result -> printf "%s\n%s: %s\n\n%s\n%s\n" separator1 (result_flavour result) (string_of_path (result_path result)) (result_msg result) separator2) results in (* Now start the test *) let (running_time, results) = time_fun perform_test report_event test in let errors = List.filter is_error results in let failures = List.filter is_failure results in let skips = List.filter is_skip results in let todos = List.filter is_todo results in if not verbose then printf "\n"; (* Print test report *) print_result_list errors; print_result_list failures; printf "Ran: %d tests in: %.2f seconds.\n" (List.length results) running_time; (* Print final verdict *) if was_successful results then if skips = [] then printf "OK" else printf "OK: Cases: %d Skip: %d\n" (test_case_count test) (List.length skips) else printf "FAILED: Cases: %d Tried: %d Errors: %d Failures: %d Skip:%d Todo:%d\n" (test_case_count test) (List.length results) (List.length errors) (List.length failures) (List.length skips) (List.length todos); (* Return the results possibly for further processing *) results (* Call this one from you test suites *) let run_test_tt_main suite = let verbose = ref false in let only_test = ref [] in Arg.parse (Arg.align [ ("-verbose", Arg.Set verbose, " Run the test in verbose mode."); ( "-only-test", Arg.String (fun str -> only_test := str :: !only_test), "path Run only the selected test" ); ]) (fun x -> raise (Arg.Bad ("Bad argument : " ^ x))) ("usage: " ^ Sys.argv.(0) ^ " [-verbose] [-only-test path]*"); let nsuite = if !only_test = [] then suite else match test_filter !only_test suite with | Some tst -> tst | None -> failwith ("Filtering test " ^ String.concat ", " !only_test ^ " lead to no test") in let result = run_test_tt ~verbose:!verbose nsuite in if not (was_successful result) then exit 1 else result
PHP
hhvm/hphp/hack/test/outline/const.php
<?hh abstract class C { const string FOO = "aaaa", FOO2 = "bbbb"; abstract const int BAR; }
PHP
hhvm/hphp/hack/test/outline/docblocks.php
<?hh /* Multi line doc block */ function f1() {} /* Newline between docblock and function */ function f2() {} /* Too many newlines - this is not a docblock*/ function no_docblock1() {} /* Narrow space */ function f4() {} function no_docblock2() {} // line comment class C { /* Property */ public string $x; // multi // line // line comment public function m1() { } }
hhvm/hphp/hack/test/outline/dune
(rule (alias outline) (deps %{exe:../../src/hh_single_type_check.exe} %{project_root}/hack/test/verify.py %{project_root}/hack/test/review.sh (glob_files %{project_root}/hack/test/outline/HH_FLAGS) (glob_files %{project_root}/hack/test/outline/*.php) (glob_files %{project_root}/hack/test/outline/*.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/outline --program %{exe:../../src/hh_single_type_check.exe}))) (alias (name runtest) (deps (alias outline)))
PHP
hhvm/hphp/hack/test/outline/file.php
<?hh function foo() {} function bar() {} class C { public function foo() {} public static function bar() {} }
PHP
hhvm/hphp/hack/test/outline/function_attribute.php
<?hh <<A("I'm an attribute and I'm part of the function")>> function foo() { // multiline function return true; }
PHP
hhvm/hphp/hack/test/outline/method_attribute.php
<?hh class C { <<A("I'm an attribute and I'm part of the method")>> public function methodWithAttribute() { // multiline method return false; } }
PHP
hhvm/hphp/hack/test/outline/modifiers.php
<?hh async function fun() {} abstract class C { abstract const FOO; public static $x1; static public $x2; protected static abstract async function bar1(); protected abstract static async function bar2(); static protected abstract async function bar3(); static abstract protected async function bar4(); abstract static protected async function bar5(); abstract protected static async function bar6(); }
PHP
hhvm/hphp/hack/test/outline/params.php
<?hh function f( $foo, string $bar = 'aaaa', ) { } function g( ...$varargs ) { } class C { public function __construct( public string $x = g(), ) {} public function h(int $method_param) {} }
PHP
hhvm/hphp/hack/test/outline/property.php
<?hh class C { public ?string $foo, $bar = "aaa"; attribute string xhp_property @required, enum {'id', 'name'} xhp_enum_property = 'id'; public function __construct( $not_a_property, public string $implicit_property, public int $implicit_property_with_init = 3, ) { } }
PHP
hhvm/hphp/hack/test/outline/typeconst.php
<?hh abstract class C { const type Ta = string; abstract const type Tb; abstract const type Tc as int; }
TOML
hhvm/hphp/hack/test/package/PACKAGES.toml
[packages] [packages.pkg1] uses = ["a", "b.*"] [packages.pkg2] uses = ["b.b1"] includes = ["pkg1"] [packages.pkg3] uses = ["c"] includes = ["pkg2"] [packages.pkg4] uses = ["d", "d.*"] soft_includes = ["pkg2"]
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_bad1.php
//// modules.php <?hh new module a {} // package pkg1 new module b.b1 {} // package pkg2 (include pkg1) //// a.php <?hh module a; public class A {} public function test(): void { $b = new B1(); // error } //// b.php <?hh module b.b1; public class B1 {}
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_bad2.php
//// modules.php <?hh new module a {} // package pkg1 new module b.b1 {} // package pkg2 (include pkg1) new module c {} // package pkg3 (include pkg2) //// a.php <?hh module a; public class A {} //// b.php <?hh module b.b1; public class B1 {} //// c.php <?hh module c; public class C {} public function test(): void { $b = new B1(); // ok $a = new A(); // error }
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_bad5.php
//// modules.php <?hh new module a {} //// a.php <?hh // package pkg1 module a; public class A {} //// b.php <?hh // default package class B { public function test(): void { $a = new A(); // error } }
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_bad_soft.php
//// modules.php <?hh new module a {} // package pkg1 new module b.b1 {} // package pkg2 (include pkg1) new module d.a {} // package pkg4 (soft include pkg2) //// a.php <?hh module a; public class A {} //// b.php <?hh module b.b1; public class B1 {} //// c.php <?hh module d.a; public class D {} public function test(): void { $b = new B1(); // error $a = new A(); // error }
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_good1.php
//// modules.php <?hh new module a {} // package pkg1 new module b.b1 {} // package pkg2 (include pkg1) //// a.php <?hh module a; public class A {} //// b.php <?hh module b.b1; public class B1 {} public function test(): void { $a = new A(); // ok }
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_with_crosspackage_attr_bad1.php
//// modules.php <?hh new module a {} // package pkg1 //// a.php <?hh <<file:__EnableUnstableFeatures('package')>> module a; class A { <<__CrossPackage("pkg5")>> public function test() : void { } }
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_with_crosspackage_attr_bad2.php
<?hh <<file:__EnableUnstableFeatures('package')>> <<__CrossPackage(123)>> // parse error function test() : void {}
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_with_crosspackage_attr_bad_call.php
//// modules.php <?hh new module a {} // package pkg1 //// a.php <?hh <<file:__EnableUnstableFeatures('package')>> module a; class A { <<__CrossPackage("pkg2")>> public function test() : void { } } function test(): void { $x = new A(); $x->test(); // error }
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_with_crosspackage_attr_bad_call_fun.php
//// modules.php <?hh new module a {} // package pkg1 //// a.php <?hh <<file:__EnableUnstableFeatures('package')>> module a; class A { public function test() : void { test(); // error } } <<__CrossPackage("pkg2")>> function test(): void { }
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_with_crosspackage_attr_complex_inheritance.php
//// modules.php <?hh new module a {} // package pkg1 new module b.b1 {} // package pkg2 //// a.php <?hh <<file:__EnableUnstableFeatures('package')>> module a; class A { public function foo(): void {} } <<__CrossPackage("pkg2")>> function foo(): void {} // can't pass cross package functions here function takes_fun((function(): void) $f) : void { $f(); } function test(): void { if (package pkg2) { takes_fun(foo<>); // error } } //// b.php <?hh module b.b1 class B extends A { // ok because pkg2 includes pkg1 <<__CrossPackage("pkg1")>> // this will unnecessarily error, but it's also redundant: pkg1 is always included public function foo(): void {} // TODO: give a better error message instead of erroring }
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_with_crosspackage_attr_good1.php
//// modules.php <?hh new module a {} // package pkg1 new module c {} // package pkg3 (include pkg2) //// a.php <?hh module a; public function f1(): void {} //// c.php <?hh <<file:__EnableUnstableFeatures('package')>> module c; <<__CrossPackage("pkg1")>> public function test() : void { f1(); }
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_with_crosspackage_attr_good2.php
//// modules.php <?hh new module a {} // package pkg1 new module c {} // package pkg3 //// a.php <?hh <<file:__EnableUnstableFeatures('package')>> module a; public type AInt = int; //// c.php <?hh <<file:__EnableUnstableFeatures('package')>> module c; <<__CrossPackage("pkg1")>> public function test(AInt $a) : void {}
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_with_crosspackage_attr_good_call.php
//// modules.php <?hh new module b.b1 {} // package pkg2 //// a.php <?hh <<file:__EnableUnstableFeatures('package')>> module b.b1; class A { public function test() : void { test_pkg1(); // ok since pkg2 includes pkg1 if(package pkg3) { test_pkg3(); // ok } } } <<__CrossPackage("pkg1")>> function test_pkg1(): void { } <<__CrossPackage("pkg3")>> function test_pkg3(): void { }
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_with_crosspackage_attr_inheritance.php
//// modules.php <?hh new module a {} // package pkg1 new module b.b1 {} // package pkg2 //// a.php <?hh <<file:__EnableUnstableFeatures('package')>> module a; interface IA { <<__CrossPackage("pkg2")>> public function test2(): void; } class A implements IA { <<__CrossPackage("pkg2")>> public function test() : void { } <<__CrossPackage("pkg1")>> // error cross package mismatch public function test2(): void { } } class B extends A implements IA { <<__Override>> public function test(): void {} // ok } class C extends B implements IA { <<__Override, __CrossPackage("pkg2")>> public function test(): void {} // error } class E implements IA { <<__CrossPackage("pkg2")>> // ok public function test2(): void { } } class F implements IA { public function test2(): void { // ok } } //// b.php <?hh <<file:__EnableUnstableFeatures('package')>> module b.b1; // package pkg2 includes pkg1, so this is okay // class D extends A { public function test(): void {} }
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_with_crosspackage_attr_method.php
//// modules.php <?hh new module a {} // package pkg1 new module b.b1 {} // package pkg2 new module c {} // package pkg3 //// b.php <?hh module b.b1; function pkg2_call(): void {} //// c.php <?hh module c; function pkg3_call(): void {} //// a.php <?hh <<file:__EnableUnstableFeatures('package')>> module a; class A { <<__CrossPackage("pkg3")>> public function foo(): void { pkg3_call(); pkg2_call(); // error: pkg3 includes pkg2, but you need to explicitly include it here invariant(package pkg2, ""); pkg2_call(); // ok pkg1_call(); } } <<__CrossPackage("pkg3")>> function foo(): void { pkg3_call(); pkg2_call(); // error: pkg3 includes pkg2, but you need to explicitly include it here invariant(package pkg2, ""); pkg2_call(); // ok pkg1_call(); } function pkg1_call(): void {}
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_with_package_syntax_if_conjunction.php
//// modules.php <?hh new module a {} // package pkg1 new module c {} // package pkg3 (include pkg2) new module d {} // package pkg4 //// a.php <?hh module a; public function f1(): void {} //// d.php <?hh module d; public function f4(): void {} //// c.php <?hh <<file:__EnableUnstableFeatures('package')>> module c; public function test(): void { if (package pkg1 && package pkg4) { // both are allowed f1(); f4(); } }
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_with_package_syntax_if_disjunction.php
//// modules.php <?hh new module a {} // package pkg1 new module c {} // package pkg3 (include pkg2) new module d {} // package pkg4 //// a.php <?hh module a; public function f1(): void {} //// d.php <?hh module d; public function f4(): void {} //// c.php <?hh <<file:__EnableUnstableFeatures('package')>> module c; public function test(): void { if (package pkg1 || package pkg4) { // neither is allowed because disjuction doesn't register package info f1(); f4(); } }
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_with_package_syntax_if_negation.php
//// modules.php <?hh new module a {} // package pkg1 new module c {} // package pkg3 (include pkg2) //// a.php <?hh module a; public function f1(): void {} //// c.php <?hh <<file:__EnableUnstableFeatures('package')>> module c; public function test(): void { if (!(package pkg1)) { f1(); // error; pkg1 is not loaded return; } else { f1(); // ok } f1(); // error; pakcage info unknown outside if/else branches }
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_with_package_syntax_if_nested.php
//// modules.php <?hh new module a {} // package pkg1 new module c {} // package pkg3 (include pkg2) new module d {} // package pkg4 //// a.php <?hh module a; public function f1(): void {} //// d.php <?hh module d; public function f4(): void {} //// c.php <?hh <<file:__EnableUnstableFeatures('package')>> module c; public function test(): void { if (package pkg1) { if (package pkg4) { // both pkg1 and pkg4 are accessible here f1(); f4(); } // only pkg1 is accessible here f1(); // ok f4(); // error } }
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_with_package_syntax_invalid_conds.php
//// modules.php <?hh new module a {} // package pkg1 new module c {} // package pkg3 (include pkg2) new module b.b1 {} // package pkg2 new module d {} // package pkg4 //// a.php <?hh module a; public function f1(): void {} //// d.php <?hh module d; public function f4(): void {} //// c.php <?hh <<file:__EnableUnstableFeatures('package')>> module c; public class C { public function test() : void { if (package pkg1 == package pkg4) { f1(); // error; comparison binops don't register package info } if (package pkg1 is bool) { f1(); // error; type ops don't register package info } if ($this->expect(package pkg1)) { f1(); // error; function calls don't register package info } if ($loaded = package pkg1) { f1(); // error; assignments aren't allowed in conditionals if ($loaded) { f1(); // error; cannot infer $loaded to be a package expression } } } private function expect(bool $x) : bool { return $x; } }
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_with_package_syntax_invariant.php
//// modules.php <?hh new module a {} // package pkg1 new module c {} // package pkg3 (include pkg2) new module d {} // package pkg4 //// a.php <?hh module a; public function f1(): void {} //// d.php <?hh module d; public function f4(): void {} //// c.php <?hh <<file:__EnableUnstableFeatures('package')>> module c; public function test_err() : void { while (true) { invariant(package pkg1, ""); f1(); // ok; pkg1 has been loaded f4(); // error; pkg4 has not yet been loaded invariant(package pkg4, ""); // both calls should be ok here f1(); f4(); break; } // error; access of pkg1 is outside the scope // of invariant(package pkg1, ...) statement f1(); } public function test_ok() : void { invariant(package pkg1 && package pkg4, ""); // both calls should be ok here f1(); f4(); }
PHP
hhvm/hphp/hack/test/package/tests/cross_package_access_with_package_syntax_loop.php
//// modules.php <?hh new module a {} // package pkg1 new module c {} // package pkg3 (include pkg2) new module b.b1 {} // package pkg2 new module d {} // package pkg4 //// a.php <?hh module a; public function f1(): void {} //// b.php <?hh module b.b1; public function f2(): void {} //// d.php <?hh module d; public function f4(): void {} //// c.php <?hh <<file:__EnableUnstableFeatures('package')>> module c; public function f3(): void {} public function test_do_while() : void { do { if (package pkg1) { f1(); } else { f3(); } } while (package pkg1); } public function test_while() : void { while (!(package pkg1)) { f2(); // ok; pkg3 includes pkg2 }; f1(); // error; package info doesn't transfer after while statement }
PHP
hhvm/hphp/hack/test/package/tests/package_access_default.php
//// modules.php <?hh new module x {} // default package new module a {} // pkg1 //// x.php <?hh module x; public type XInt = int; function foo(): void {} //// a.php <?hh module a; public type YInt = XInt; // ok function test(): void { foo(); // ok }
PHP
hhvm/hphp/hack/test/package/tests/package_access_default2.php
//// modules.php <?hh new module x {} // default package new module a {} // pkg1 //// a.php <?hh module a; public type XInt = int; function foo(): void {} //// x.php <?hh <<file:__EnableUnstableFeatures("package")>> module x; public type YInt = XInt; // error function test(): void { if(package pkg1) { foo(); // ok } foo(); // error }
PHP
hhvm/hphp/hack/test/package/tests/same_package_access_bad.php
//// modules.php <?hh new module a {} // package pkg1 new module b.b2 {} // package pkg1 //// a.php <?hh module a; internal type AInt = int; //// b.php <?hh module b.b2; internal type BInt = AInt; // error
PHP
hhvm/hphp/hack/test/package/tests/same_package_access_good1.php
//// modules.php <?hh new module a {} // package pkg1 new module b.b2 {} // package pkg1 //// a.php <?hh module a; public class A {} public function test1(): void { $b = new B2(); // ok } //// b.php <?hh module b.b2; public class B2 {} public function test2(): void { $a = new A(); // ok }
PHP
hhvm/hphp/hack/test/package/tests/same_package_access_good2.php
//// modules.php <?hh new module x {} // default package new module y {} // default package //// x.php <?hh module x; public type XInt = int; //// y.php <?hh module y; public type YInt = XInt; // ok
hhvm/hphp/hack/test/ppx-transform/dune
(executable (name pp) (modules pp) (libraries ppx_transform ppxlib)) (rule (targets test.actual.ml) (deps (:pp pp.exe) (:input test.ml)) (action (progn (with-stdout-to %{targets} (run ./%{pp} --impl %{input} -o %{targets})) (bash "arc f %{targets} > /dev/null 2>&1") ) ) ) (rule (alias runtest) (action (diff test.expected.ml test.actual.ml))) (test (name test) (modules test) (preprocess (pps ppx_transform))) (include dune.inc)
Include
hhvm/hphp/hack/test/ppx-transform/dune.inc
; GENERATED RULES (rule (targets test_constant_ctor_embed_error.actual.ml) (deps (:pp pp.exe) (:input test_constant_ctor_embed_error.ml)) (action (progn (with-stdout-to %{targets} (run ./%{pp} --impl %{input} -o %{targets})) (bash "arc f %{targets} > /dev/null 2>&1") ) ) ) (rule (alias runtest) (action (diff test_constant_ctor_embed_error.expected.ml test_constant_ctor_embed_error.actual.ml))) (rule (targets test_inline_record_embed_error.actual.ml) (deps (:pp pp.exe) (:input test_inline_record_embed_error.ml)) (action (progn (with-stdout-to %{targets} (run ./%{pp} --impl %{input} -o %{targets})) (bash "arc f %{targets} > /dev/null 2>&1") ) ) ) (rule (alias runtest) (action (diff test_inline_record_embed_error.expected.ml test_inline_record_embed_error.actual.ml)))
Shell Script
hhvm/hphp/hack/test/ppx-transform/gen_test_rules.sh
#!/bin/bash DIRECTORY=. out=${1:-dune.inc} echo "; GENERATED RULES" > "$out" for filename in "$DIRECTORY"/test_*_embed_error.ml; do file=$(basename -- "$filename"); pfx="${file%.*}"; echo " (rule (targets $pfx.actual.ml) (deps (:pp pp.exe) (:input $file)) (action (progn (with-stdout-to %{targets} (run ./%{pp} --impl %{input} -o %{targets})) (bash \"arc f %{targets} > /dev/null 2>&1\") ) ) ) (rule (alias runtest) (action (diff $pfx.expected.ml $pfx.actual.ml)))" >> "$out"; done
OCaml
hhvm/hphp/hack/test/ppx-transform/pp.ml
(* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) let () = Ppxlib.Driver.standalone ()
OCaml
hhvm/hphp/hack/test/ppx-transform/test.expected.ml
module Variant : sig type t = | Num of int | Plus of t * t | Leq of t * t | Cond of t * t * t [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type t = | Num of int | Plus of t * t | Leq of t * t | Cond of t * t * t [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; } let identity _ = { on_ty_t = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); } let _ = combine end let rec (traverse : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun t ~ctx ~top_down ~bottom_up -> match t with | Plus (plus_elem_0, plus_elem_1) -> Plus ( transform plus_elem_0 ~ctx ~top_down ~bottom_up, transform plus_elem_1 ~ctx ~top_down ~bottom_up ) | Leq (leq_elem_0, leq_elem_1) -> Leq ( transform leq_elem_0 ~ctx ~top_down ~bottom_up, transform leq_elem_1 ~ctx ~top_down ~bottom_up ) | Cond (cond_elem_0, cond_elem_1, cond_elem_2) -> Cond ( transform cond_elem_0 ~ctx ~top_down ~bottom_up, transform cond_elem_1 ~ctx ~top_down ~bottom_up, transform cond_elem_2 ~ctx ~top_down ~bottom_up ) | t -> t and (transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) let _ = traverse and _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end module Gadt : sig type _ t = | T : bool t | F : bool t | Num : int -> int t | Plus : (int t * int t) -> int t | Leq : (int t * int t) -> bool t | Cond : (bool t * 'a t * 'a t) -> 'a t [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: 'a. ('a t -> ctx:'ctx -> 'ctx * [ `Stop of 'a t | `Continue of 'a t | `Restart of 'a t ]) option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : 'a t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type _ t = | T : bool t | F : bool t | Num : int -> int t | Plus : (int t * int t) -> int t | Leq : (int t * int t) -> bool t | Cond : (bool t * 'a t * 'a t) -> 'a t [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : _ t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: 'a. ('a t -> ctx:'ctx -> 'ctx * [ `Stop of 'a t | `Continue of 'a t | `Restart of 'a t ]) option; } let identity _ = { on_ty_t = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); } let _ = combine end let rec traverse : 'a. 'a t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a t = fun (type a) (t : a t) ~ctx ~top_down ~bottom_up : a t -> match t with | Plus (plus_elem_0, plus_elem_1) -> Plus ( transform plus_elem_0 ~ctx ~top_down ~bottom_up, transform plus_elem_1 ~ctx ~top_down ~bottom_up ) | Leq (leq_elem_0, leq_elem_1) -> Leq ( transform leq_elem_0 ~ctx ~top_down ~bottom_up, transform leq_elem_1 ~ctx ~top_down ~bottom_up ) | Cond (cond_elem_0, cond_elem_1, cond_elem_2) -> Cond ( transform cond_elem_0 ~ctx ~top_down ~bottom_up, transform cond_elem_1 ~ctx ~top_down ~bottom_up, transform cond_elem_2 ~ctx ~top_down ~bottom_up ) | t -> t and transform : 'a. 'a t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a t = fun (type a) (elem : a t) ~ctx ~top_down ~bottom_up : a t -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) let _ = traverse and _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end module Nonregular : sig type 'a term = | Var of 'a | App of 'a term * 'a term | Abs of 'a bind term and 'a bind = | Zero | Succ of 'a [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_bind: 'a. ('a bind -> ctx:'ctx -> 'ctx * [ `Stop of 'a bind | `Continue of 'a bind | `Restart of 'a bind ]) option; on_ty_term: 'a. ('a term -> ctx:'ctx -> 'ctx * [ `Stop of 'a term | `Continue of 'a term | `Restart of 'a term ]) option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform_ty_bind : 'a bind -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a bind val transform_ty_term : 'a term -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a term end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type 'a term = | Var of 'a | App of 'a term * 'a term | Abs of 'a bind term and 'a bind = | Zero | Succ of 'a [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : 'a term) -> ()) let _ = (fun (_ : 'a bind) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_bind: 'a. ('a bind -> ctx:'ctx -> 'ctx * [ `Stop of 'a bind | `Continue of 'a bind | `Restart of 'a bind ]) option; on_ty_term: 'a. ('a term -> ctx:'ctx -> 'ctx * [ `Stop of 'a term | `Continue of 'a term | `Restart of 'a term ]) option; } let identity _ = { on_ty_bind = None; on_ty_term = None } let _ = identity let combine p1 p2 = { on_ty_bind = (match (p1.on_ty_bind, p2.on_ty_bind) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_bind | _ -> p1.on_ty_bind); on_ty_term = (match (p1.on_ty_term, p2.on_ty_term) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_term | _ -> p1.on_ty_term); } let _ = combine end let rec transform_ty_bind : 'a. 'a bind -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a bind = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_bind with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (_ctx, `Continue elem) -> (match bottom_up.Pass.on_ty_bind with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_bind elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform_ty_bind elem ~ctx ~top_down ~bottom_up) | _ -> (match bottom_up.Pass.on_ty_bind with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_bind elem ~ctx ~top_down ~bottom_up)) let _ = transform_ty_bind let rec traverse_ty_term : 'a. 'a term -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a term = fun term ~ctx ~top_down ~bottom_up -> match term with | App (app_elem_0, app_elem_1) -> App ( transform_ty_term app_elem_0 ~ctx ~top_down ~bottom_up, transform_ty_term app_elem_1 ~ctx ~top_down ~bottom_up ) | Abs abs_elem -> Abs (transform_ty_term abs_elem ~ctx ~top_down ~bottom_up) | term -> term and transform_ty_term : 'a. 'a term -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a term = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_term with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse_ty_term elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_term with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_term elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform_ty_term elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse_ty_term elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_term with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_term elem ~ctx ~top_down ~bottom_up)) let _ = traverse_ty_term and _ = transform_ty_term end [@@ocaml.doc "@inline"] [@@merlin.hide] end module Nonregular_mutual : sig type 'a one = | Nil | Two of 'a two and 'a two = MaybeOne of 'a option one [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_two: 'a. ('a two -> ctx:'ctx -> 'ctx * [ `Stop of 'a two | `Continue of 'a two | `Restart of 'a two ]) option; on_ty_one: 'a. ('a one -> ctx:'ctx -> 'ctx * [ `Stop of 'a one | `Continue of 'a one | `Restart of 'a one ]) option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform_ty_two : 'a two -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a two val transform_ty_one : 'a one -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a one end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type 'a one = | Nil | Two of 'a two and 'a two = MaybeOne of 'a option one [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : 'a one) -> ()) let _ = (fun (_ : 'a two) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_two: 'a. ('a two -> ctx:'ctx -> 'ctx * [ `Stop of 'a two | `Continue of 'a two | `Restart of 'a two ]) option; on_ty_one: 'a. ('a one -> ctx:'ctx -> 'ctx * [ `Stop of 'a one | `Continue of 'a one | `Restart of 'a one ]) option; } let identity _ = { on_ty_two = None; on_ty_one = None } let _ = identity let combine p1 p2 = { on_ty_two = (match (p1.on_ty_two, p2.on_ty_two) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_two | _ -> p1.on_ty_two); on_ty_one = (match (p1.on_ty_one, p2.on_ty_one) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_one | _ -> p1.on_ty_one); } let _ = combine end let rec traverse_ty_two : 'a. 'a two -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a two = fun two ~ctx ~top_down ~bottom_up -> match two with | MaybeOne maybeone_elem -> MaybeOne (transform_ty_one maybeone_elem ~ctx ~top_down ~bottom_up) and transform_ty_two : 'a. 'a two -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a two = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_two with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse_ty_two elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_two with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_two elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform_ty_two elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse_ty_two elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_two with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_two elem ~ctx ~top_down ~bottom_up)) and traverse_ty_one : 'a. 'a one -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a one = fun one ~ctx ~top_down ~bottom_up -> match one with | Two two_elem -> Two (transform_ty_two two_elem ~ctx ~top_down ~bottom_up) | one -> one and transform_ty_one : 'a. 'a one -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a one = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_one with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse_ty_one elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_one with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_one elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform_ty_one elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse_ty_one elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_one with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_one elem ~ctx ~top_down ~bottom_up)) let _ = traverse_ty_two and _ = transform_ty_two and _ = traverse_ty_one and _ = transform_ty_one end [@@ocaml.doc "@inline"] [@@merlin.hide] end module Nonregular_mutual_gadt : sig type 'a one = | Nil : 'a one | Two : 'a two -> 'a one and 'a two = MaybeOne of 'a option one [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_two: 'a. ('a two -> ctx:'ctx -> 'ctx * [ `Stop of 'a two | `Continue of 'a two | `Restart of 'a two ]) option; on_ty_one: 'a. ('a one -> ctx:'ctx -> 'ctx * [ `Stop of 'a one | `Continue of 'a one | `Restart of 'a one ]) option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform_ty_two : 'a two -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a two val transform_ty_one : 'a one -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a one end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type 'a one = | Nil : 'a one | Two : 'a two -> 'a one and 'a two = MaybeOne of 'a option one [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : 'a one) -> ()) let _ = (fun (_ : 'a two) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_two: 'a. ('a two -> ctx:'ctx -> 'ctx * [ `Stop of 'a two | `Continue of 'a two | `Restart of 'a two ]) option; on_ty_one: 'a. ('a one -> ctx:'ctx -> 'ctx * [ `Stop of 'a one | `Continue of 'a one | `Restart of 'a one ]) option; } let identity _ = { on_ty_two = None; on_ty_one = None } let _ = identity let combine p1 p2 = { on_ty_two = (match (p1.on_ty_two, p2.on_ty_two) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_two | _ -> p1.on_ty_two); on_ty_one = (match (p1.on_ty_one, p2.on_ty_one) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_one | _ -> p1.on_ty_one); } let _ = combine end let rec traverse_ty_two : 'a. 'a two -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a two = fun two ~ctx ~top_down ~bottom_up -> match two with | MaybeOne maybeone_elem -> MaybeOne (transform_ty_one maybeone_elem ~ctx ~top_down ~bottom_up) and transform_ty_two : 'a. 'a two -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a two = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_two with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse_ty_two elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_two with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_two elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform_ty_two elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse_ty_two elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_two with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_two elem ~ctx ~top_down ~bottom_up)) and traverse_ty_one : 'a. 'a one -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a one = fun (type a) (one : a one) ~ctx ~top_down ~bottom_up : a one -> match one with | Two two_elem -> Two (transform_ty_two two_elem ~ctx ~top_down ~bottom_up) | one -> one and transform_ty_one : 'a. 'a one -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a one = fun (type a) (elem : a one) ~ctx ~top_down ~bottom_up : a one -> match top_down.Pass.on_ty_one with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse_ty_one elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_one with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_one elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform_ty_one elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse_ty_one elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_one with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_one elem ~ctx ~top_down ~bottom_up)) let _ = traverse_ty_two and _ = transform_ty_two and _ = traverse_ty_one and _ = transform_ty_one end [@@ocaml.doc "@inline"] [@@merlin.hide] end module Composed = struct module BinOp : sig type t = | Add | Sub | Mul | Div [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type t = | Add | Sub | Mul | Div [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; } let identity _ = { on_ty_t = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); } let _ = combine end let rec (transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (_ctx, `Continue elem) -> (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up) | _ -> (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) let _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end module RelOp : sig type t = | Eq | Lt | Gt [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type t = | Eq | Lt | Gt [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; } let identity _ = { on_ty_t = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); } let _ = combine end let rec (transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (_ctx, `Continue elem) -> (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up) | _ -> (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) let _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end module ConnOp : sig type t = | And | Or [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type t = | And | Or [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; } let identity _ = { on_ty_t = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); } let _ = combine end let rec (transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (_ctx, `Continue elem) -> (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up) | _ -> (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) let _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end module Expr : sig type t = | Num of int | Bin of BinOp.t * t * t | Rel of RelOp.t * t * t | Conn of ConnOp.t * t * t | Cond of t * t * t [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; on_BinOp: 'ctx BinOp.Pass.t option; on_ConnOp: 'ctx ConnOp.Pass.t option; on_RelOp: 'ctx RelOp.Pass.t option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type t = | Num of int | Bin of BinOp.t * t * t | Rel of RelOp.t * t * t | Conn of ConnOp.t * t * t | Cond of t * t * t [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; on_BinOp: 'ctx BinOp.Pass.t option; on_ConnOp: 'ctx ConnOp.Pass.t option; on_RelOp: 'ctx RelOp.Pass.t option; } let identity _ = { on_ty_t = None; on_BinOp = None; on_ConnOp = None; on_RelOp = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); on_BinOp = (match (p1.on_BinOp, p2.on_BinOp) with | (Some p1, Some p2) -> Some (BinOp.Pass.combine p1 p2) | (Some _, _) -> p1.on_BinOp | _ -> p2.on_BinOp); on_ConnOp = (match (p1.on_ConnOp, p2.on_ConnOp) with | (Some p1, Some p2) -> Some (ConnOp.Pass.combine p1 p2) | (Some _, _) -> p1.on_ConnOp | _ -> p2.on_ConnOp); on_RelOp = (match (p1.on_RelOp, p2.on_RelOp) with | (Some p1, Some p2) -> Some (RelOp.Pass.combine p1 p2) | (Some _, _) -> p1.on_RelOp | _ -> p2.on_RelOp); } let _ = combine end let rec (traverse : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun t ~ctx ~top_down ~bottom_up -> match t with | Bin (bin_elem_0, bin_elem_1, bin_elem_2) -> Bin ( (match (top_down.Pass.on_BinOp, bottom_up.Pass.on_BinOp) with | (Some top_down, Some bottom_up) -> BinOp.transform bin_elem_0 ~ctx ~top_down ~bottom_up | (Some top_down, _) -> BinOp.transform bin_elem_0 ~ctx ~top_down ~bottom_up:(BinOp.Pass.identity ()) | (_, Some bottom_up) -> BinOp.transform bin_elem_0 ~ctx ~top_down:(BinOp.Pass.identity ()) ~bottom_up | _ -> bin_elem_0), transform bin_elem_1 ~ctx ~top_down ~bottom_up, transform bin_elem_2 ~ctx ~top_down ~bottom_up ) | Rel (rel_elem_0, rel_elem_1, rel_elem_2) -> Rel ( (match (top_down.Pass.on_RelOp, bottom_up.Pass.on_RelOp) with | (Some top_down, Some bottom_up) -> RelOp.transform rel_elem_0 ~ctx ~top_down ~bottom_up | (Some top_down, _) -> RelOp.transform rel_elem_0 ~ctx ~top_down ~bottom_up:(RelOp.Pass.identity ()) | (_, Some bottom_up) -> RelOp.transform rel_elem_0 ~ctx ~top_down:(RelOp.Pass.identity ()) ~bottom_up | _ -> rel_elem_0), transform rel_elem_1 ~ctx ~top_down ~bottom_up, transform rel_elem_2 ~ctx ~top_down ~bottom_up ) | Conn (conn_elem_0, conn_elem_1, conn_elem_2) -> Conn ( (match (top_down.Pass.on_ConnOp, bottom_up.Pass.on_ConnOp) with | (Some top_down, Some bottom_up) -> ConnOp.transform conn_elem_0 ~ctx ~top_down ~bottom_up | (Some top_down, _) -> ConnOp.transform conn_elem_0 ~ctx ~top_down ~bottom_up:(ConnOp.Pass.identity ()) | (_, Some bottom_up) -> ConnOp.transform conn_elem_0 ~ctx ~top_down:(ConnOp.Pass.identity ()) ~bottom_up | _ -> conn_elem_0), transform conn_elem_1 ~ctx ~top_down ~bottom_up, transform conn_elem_2 ~ctx ~top_down ~bottom_up ) | Cond (cond_elem_0, cond_elem_1, cond_elem_2) -> Cond ( transform cond_elem_0 ~ctx ~top_down ~bottom_up, transform cond_elem_1 ~ctx ~top_down ~bottom_up, transform cond_elem_2 ~ctx ~top_down ~bottom_up ) | t -> t and (transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) let _ = traverse and _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end module Expr_gadt : sig type _ t = | Num : int -> int t | Bin : (BinOp.t * int t * int t) -> int t | Rel : (RelOp.t * int t * int t) -> bool t | Conn : (ConnOp.t * bool t * bool t) -> bool t | Cond : (bool t * 'a t * 'a t) -> 'a t [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: 'a. ('a t -> ctx:'ctx -> 'ctx * [ `Stop of 'a t | `Continue of 'a t | `Restart of 'a t ]) option; on_BinOp: 'ctx BinOp.Pass.t option; on_ConnOp: 'ctx ConnOp.Pass.t option; on_RelOp: 'ctx RelOp.Pass.t option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : 'a t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type _ t = | Num : int -> int t | Bin : (BinOp.t * int t * int t) -> int t | Rel : (RelOp.t * int t * int t) -> bool t | Conn : (ConnOp.t * bool t * bool t) -> bool t | Cond : (bool t * 'a t * 'a t) -> 'a t [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : _ t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: 'a. ('a t -> ctx:'ctx -> 'ctx * [ `Stop of 'a t | `Continue of 'a t | `Restart of 'a t ]) option; on_BinOp: 'ctx BinOp.Pass.t option; on_ConnOp: 'ctx ConnOp.Pass.t option; on_RelOp: 'ctx RelOp.Pass.t option; } let identity _ = { on_ty_t = None; on_BinOp = None; on_ConnOp = None; on_RelOp = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); on_BinOp = (match (p1.on_BinOp, p2.on_BinOp) with | (Some p1, Some p2) -> Some (BinOp.Pass.combine p1 p2) | (Some _, _) -> p1.on_BinOp | _ -> p2.on_BinOp); on_ConnOp = (match (p1.on_ConnOp, p2.on_ConnOp) with | (Some p1, Some p2) -> Some (ConnOp.Pass.combine p1 p2) | (Some _, _) -> p1.on_ConnOp | _ -> p2.on_ConnOp); on_RelOp = (match (p1.on_RelOp, p2.on_RelOp) with | (Some p1, Some p2) -> Some (RelOp.Pass.combine p1 p2) | (Some _, _) -> p1.on_RelOp | _ -> p2.on_RelOp); } let _ = combine end let rec traverse : 'a. 'a t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a t = fun (type a) (t : a t) ~ctx ~top_down ~bottom_up : a t -> match t with | Bin (bin_elem_0, bin_elem_1, bin_elem_2) -> Bin ( (match (top_down.Pass.on_BinOp, bottom_up.Pass.on_BinOp) with | (Some top_down, Some bottom_up) -> BinOp.transform bin_elem_0 ~ctx ~top_down ~bottom_up | (Some top_down, _) -> BinOp.transform bin_elem_0 ~ctx ~top_down ~bottom_up:(BinOp.Pass.identity ()) | (_, Some bottom_up) -> BinOp.transform bin_elem_0 ~ctx ~top_down:(BinOp.Pass.identity ()) ~bottom_up | _ -> bin_elem_0), transform bin_elem_1 ~ctx ~top_down ~bottom_up, transform bin_elem_2 ~ctx ~top_down ~bottom_up ) | Rel (rel_elem_0, rel_elem_1, rel_elem_2) -> Rel ( (match (top_down.Pass.on_RelOp, bottom_up.Pass.on_RelOp) with | (Some top_down, Some bottom_up) -> RelOp.transform rel_elem_0 ~ctx ~top_down ~bottom_up | (Some top_down, _) -> RelOp.transform rel_elem_0 ~ctx ~top_down ~bottom_up:(RelOp.Pass.identity ()) | (_, Some bottom_up) -> RelOp.transform rel_elem_0 ~ctx ~top_down:(RelOp.Pass.identity ()) ~bottom_up | _ -> rel_elem_0), transform rel_elem_1 ~ctx ~top_down ~bottom_up, transform rel_elem_2 ~ctx ~top_down ~bottom_up ) | Conn (conn_elem_0, conn_elem_1, conn_elem_2) -> Conn ( (match (top_down.Pass.on_ConnOp, bottom_up.Pass.on_ConnOp) with | (Some top_down, Some bottom_up) -> ConnOp.transform conn_elem_0 ~ctx ~top_down ~bottom_up | (Some top_down, _) -> ConnOp.transform conn_elem_0 ~ctx ~top_down ~bottom_up:(ConnOp.Pass.identity ()) | (_, Some bottom_up) -> ConnOp.transform conn_elem_0 ~ctx ~top_down:(ConnOp.Pass.identity ()) ~bottom_up | _ -> conn_elem_0), transform conn_elem_1 ~ctx ~top_down ~bottom_up, transform conn_elem_2 ~ctx ~top_down ~bottom_up ) | Cond (cond_elem_0, cond_elem_1, cond_elem_2) -> Cond ( transform cond_elem_0 ~ctx ~top_down ~bottom_up, transform cond_elem_1 ~ctx ~top_down ~bottom_up, transform cond_elem_2 ~ctx ~top_down ~bottom_up ) | t -> t and transform : 'a. 'a t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a t = fun (type a) (elem : a t) ~ctx ~top_down ~bottom_up : a t -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) let _ = traverse and _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end end module Builtins : sig type 'a t = { prim_ignored: char; ref: 'a t ref; opt: 'a t option; res: ('a t, 'a t) result; list: 'a t list; array: 'a t array; lazy_: 'a t lazy_t; nested: ('a t option list, 'a t array option) result list option lazy_t; } [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: 'a. ('a t -> ctx:'ctx -> 'ctx * [ `Stop of 'a t | `Continue of 'a t | `Restart of 'a t ]) option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : 'a t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type 'a t = { prim_ignored: char; ref: 'a t ref; opt: 'a t option; res: ('a t, 'a t) result; list: 'a t list; array: 'a t array; lazy_: 'a t lazy_t; nested: ('a t option list, 'a t array option) result list option lazy_t; } [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : 'a t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: 'a. ('a t -> ctx:'ctx -> 'ctx * [ `Stop of 'a t | `Continue of 'a t | `Restart of 'a t ]) option; } let identity _ = { on_ty_t = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); } let _ = combine end let rec traverse : 'a. 'a t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a t = fun ({ ref; opt; res; list; array; lazy_; nested; _ } as t) ~ctx ~top_down ~bottom_up -> { t with ref = (let ref_deref = !ref in ref := transform ref_deref ~ctx ~top_down ~bottom_up; ref); opt = (match opt with | Some opt_inner -> Some (transform opt_inner ~ctx ~top_down ~bottom_up) | _ -> None); res = (match res with | Ok res_ok -> Ok (transform res_ok ~ctx ~top_down ~bottom_up) | Error res_err -> Error (transform res_err ~ctx ~top_down ~bottom_up)); list = Stdlib.List.map (fun list -> transform list ~ctx ~top_down ~bottom_up) list; array = Stdlib.Array.map (fun array -> transform array ~ctx ~top_down ~bottom_up) array; lazy_ = (let lazy__force = Lazy.force lazy_ in lazy (transform lazy__force ~ctx ~top_down ~bottom_up)); nested = (let nested_force = Lazy.force nested in lazy (match nested_force with | Some nested_force_inner -> Some (Stdlib.List.map (fun nested_force_inner -> match nested_force_inner with | Ok nested_force_inner_ok -> Ok (Stdlib.List.map (fun nested_force_inner_ok -> match nested_force_inner_ok with | Some nested_force_inner_ok_inner -> Some (transform nested_force_inner_ok_inner ~ctx ~top_down ~bottom_up) | _ -> None) nested_force_inner_ok) | Error nested_force_inner_err -> Error (match nested_force_inner_err with | Some nested_force_inner_err_inner -> Some (Stdlib.Array.map (fun nested_force_inner_err_inner -> transform nested_force_inner_err_inner ~ctx ~top_down ~bottom_up) nested_force_inner_err_inner) | _ -> None)) nested_force_inner) | _ -> None)); } and transform : 'a. 'a t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a t = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) let _ = traverse and _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end module Opaque_annotations : sig type variant = | Opaque_ctor of record [@transform.opaque] | Normal of record | Tuple_with_opaque of (record * (alias[@transform.opaque]) * opaque_decl) and record = { normal: alias; opaque: alias; [@transform.opaque] } and alias = record * (variant[@transform.opaque]) * opaque_decl and opaque_decl = Opaque of variant * record * alias [@@transform.opaque] [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_alias: (alias -> ctx:'ctx -> 'ctx * [ `Stop of alias | `Continue of alias | `Restart of alias ]) option; on_ty_record: (record -> ctx:'ctx -> 'ctx * [ `Stop of record | `Continue of record | `Restart of record ]) option; on_ty_variant: (variant -> ctx:'ctx -> 'ctx * [ `Stop of variant | `Continue of variant | `Restart of variant ]) option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform_ty_alias : alias -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> alias val transform_ty_record : record -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> record val transform_ty_variant : variant -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> variant end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type variant = | Opaque_ctor of record [@transform.opaque] | Normal of record | Tuple_with_opaque of (record * (alias[@transform.opaque]) * opaque_decl) and record = { normal: alias; opaque: alias; [@transform.opaque] } and alias = record * (variant[@transform.opaque]) * opaque_decl and opaque_decl = Opaque of variant * record * alias [@@transform.opaque] [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : variant) -> ()) let _ = (fun (_ : record) -> ()) let _ = (fun (_ : alias) -> ()) let _ = (fun (_ : opaque_decl) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_alias: (alias -> ctx:'ctx -> 'ctx * [ `Stop of alias | `Continue of alias | `Restart of alias ]) option; on_ty_record: (record -> ctx:'ctx -> 'ctx * [ `Stop of record | `Continue of record | `Restart of record ]) option; on_ty_variant: (variant -> ctx:'ctx -> 'ctx * [ `Stop of variant | `Continue of variant | `Restart of variant ]) option; } let identity _ = { on_ty_alias = None; on_ty_record = None; on_ty_variant = None } let _ = identity let combine p1 p2 = { on_ty_alias = (match (p1.on_ty_alias, p2.on_ty_alias) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_alias | _ -> p1.on_ty_alias); on_ty_record = (match (p1.on_ty_record, p2.on_ty_record) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_record | _ -> p1.on_ty_record); on_ty_variant = (match (p1.on_ty_variant, p2.on_ty_variant) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_variant | _ -> p1.on_ty_variant); } let _ = combine end let rec (traverse_ty_alias : alias -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> alias) = fun (alias_0, alias_1, alias_2) ~ctx ~top_down ~bottom_up -> (transform_ty_record alias_0 ~ctx ~top_down ~bottom_up, alias_1, alias_2) and (transform_ty_alias : alias -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> alias) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_alias with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse_ty_alias elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_alias with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_alias elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform_ty_alias elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse_ty_alias elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_alias with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_alias elem ~ctx ~top_down ~bottom_up)) and (traverse_ty_record : record -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> record) = fun ({ normal; _ } as record) ~ctx ~top_down ~bottom_up -> { record with normal = transform_ty_alias normal ~ctx ~top_down ~bottom_up; } and (transform_ty_record : record -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> record) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_record with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse_ty_record elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_record with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_record elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform_ty_record elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse_ty_record elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_record with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_record elem ~ctx ~top_down ~bottom_up)) and (traverse_ty_variant : variant -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> variant) = fun variant ~ctx ~top_down ~bottom_up -> match variant with | Normal normal_elem -> Normal (transform_ty_record normal_elem ~ctx ~top_down ~bottom_up) | Tuple_with_opaque ( tuple_with_opaque_elem_0, tuple_with_opaque_elem_1, tuple_with_opaque_elem_2 ) -> Tuple_with_opaque ( transform_ty_record tuple_with_opaque_elem_0 ~ctx ~top_down ~bottom_up, tuple_with_opaque_elem_1, tuple_with_opaque_elem_2 ) | variant -> variant and (transform_ty_variant : variant -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> variant) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_variant with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse_ty_variant elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_variant with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_variant elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform_ty_variant elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse_ty_variant elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_variant with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_variant elem ~ctx ~top_down ~bottom_up)) let _ = traverse_ty_alias and _ = transform_ty_alias and _ = traverse_ty_record and _ = transform_ty_record and _ = traverse_ty_variant and _ = transform_ty_variant end [@@ocaml.doc "@inline"] [@@merlin.hide] end module Explicit_annotations : sig type variant = | Constant | Inline_record of { a: int; b: record; } | Single of record [@transform.explicit] | Tuple of alias * record [@transform.explicit] and record = { variant: variant [@transform.explicit] } and alias = (record * variant[@transform.explicit]) [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_alias: (alias -> ctx:'ctx -> 'ctx * [ `Stop of alias | `Continue of alias | `Restart of alias ]) option; on_ty_record: (record -> ctx:'ctx -> 'ctx * [ `Stop of record | `Continue of record | `Restart of record ]) option; on_fld_record_variant: (variant -> ctx:'ctx -> 'ctx * [ `Stop of variant | `Continue of variant | `Restart of variant ]) option; on_ty_variant: (variant -> ctx:'ctx -> 'ctx * [ `Stop of variant | `Continue of variant | `Restart of variant ]) option; on_ctor_variant_Single: (record -> ctx:'ctx -> 'ctx * [ `Stop of record | `Continue of record | `Restart of record ]) option; on_ctor_variant_Tuple: (alias * record -> ctx:'ctx -> 'ctx * [ `Stop of alias * record | `Continue of alias * record | `Restart of alias * record ]) option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform_ty_alias : alias -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> alias val transform_ty_record : record -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> record val transform_fld_record_variant : variant -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> variant val transform_ty_variant : variant -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> variant val transform_ctor_variant_Single : record -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> record val transform_ctor_variant_Tuple : alias * record -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> alias * record end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type variant = | Constant | Inline_record of { a: int; b: record; } | Single of record [@transform.explicit] | Tuple of alias * record [@transform.explicit] and record = { variant: variant [@transform.explicit] } and alias = (record * variant[@transform.explicit]) [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : variant) -> ()) let _ = (fun (_ : record) -> ()) let _ = (fun (_ : alias) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_alias: (alias -> ctx:'ctx -> 'ctx * [ `Stop of alias | `Continue of alias | `Restart of alias ]) option; on_ty_record: (record -> ctx:'ctx -> 'ctx * [ `Stop of record | `Continue of record | `Restart of record ]) option; on_fld_record_variant: (variant -> ctx:'ctx -> 'ctx * [ `Stop of variant | `Continue of variant | `Restart of variant ]) option; on_ty_variant: (variant -> ctx:'ctx -> 'ctx * [ `Stop of variant | `Continue of variant | `Restart of variant ]) option; on_ctor_variant_Single: (record -> ctx:'ctx -> 'ctx * [ `Stop of record | `Continue of record | `Restart of record ]) option; on_ctor_variant_Tuple: (alias * record -> ctx:'ctx -> 'ctx * [ `Stop of alias * record | `Continue of alias * record | `Restart of alias * record ]) option; } let identity _ = { on_ty_alias = None; on_ty_record = None; on_fld_record_variant = None; on_ty_variant = None; on_ctor_variant_Single = None; on_ctor_variant_Tuple = None; } let _ = identity let combine p1 p2 = { on_ty_alias = (match (p1.on_ty_alias, p2.on_ty_alias) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_alias | _ -> p1.on_ty_alias); on_ty_record = (match (p1.on_ty_record, p2.on_ty_record) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_record | _ -> p1.on_ty_record); on_fld_record_variant = (match (p1.on_fld_record_variant, p2.on_fld_record_variant) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_fld_record_variant | _ -> p1.on_fld_record_variant); on_ty_variant = (match (p1.on_ty_variant, p2.on_ty_variant) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_variant | _ -> p1.on_ty_variant); on_ctor_variant_Single = (match (p1.on_ctor_variant_Single, p2.on_ctor_variant_Single) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ctor_variant_Single | _ -> p1.on_ctor_variant_Single); on_ctor_variant_Tuple = (match (p1.on_ctor_variant_Tuple, p2.on_ctor_variant_Tuple) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ctor_variant_Tuple | _ -> p1.on_ctor_variant_Tuple); } let _ = combine end let rec (traverse_ty_alias : alias -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> alias) = fun (alias_0, alias_1) ~ctx ~top_down ~bottom_up -> ( transform_ty_record alias_0 ~ctx ~top_down ~bottom_up, transform_ty_variant alias_1 ~ctx ~top_down ~bottom_up ) and (transform_ty_alias : alias -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> alias) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_alias with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse_ty_alias elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_alias with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_alias elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform_ty_alias elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse_ty_alias elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_alias with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_alias elem ~ctx ~top_down ~bottom_up)) and (traverse_ty_record : record -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> record) = fun { variant } ~ctx ~top_down ~bottom_up -> { variant = transform_fld_record_variant variant ~ctx ~top_down ~bottom_up; } and (transform_ty_record : record -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> record) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_record with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse_ty_record elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_record with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_record elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform_ty_record elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse_ty_record elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_record with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_record elem ~ctx ~top_down ~bottom_up)) and (traverse_fld_record_variant : variant -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> variant) = fun record_variant ~ctx ~top_down ~bottom_up -> transform_ty_variant record_variant ~ctx ~top_down ~bottom_up and (transform_fld_record_variant : variant -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> variant) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_fld_record_variant with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse_fld_record_variant elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_fld_record_variant with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_fld_record_variant elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform_fld_record_variant elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse_fld_record_variant elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_fld_record_variant with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_fld_record_variant elem ~ctx ~top_down ~bottom_up)) and (traverse_ty_variant : variant -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> variant) = fun variant ~ctx ~top_down ~bottom_up -> match variant with | Inline_record ({ b; _ } as inline_record) -> Inline_record { inline_record with b = transform_ty_record b ~ctx ~top_down ~bottom_up; } | Single elem -> Single (transform_ctor_variant_Single elem ~ctx ~top_down ~bottom_up) | Tuple (elem_0, elem_1) -> let (elem_0, elem_1) = transform_ctor_variant_Tuple (elem_0, elem_1) ~ctx ~top_down ~bottom_up in Tuple (elem_0, elem_1) | variant -> variant and (transform_ty_variant : variant -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> variant) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_variant with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse_ty_variant elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_variant with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_variant elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform_ty_variant elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse_ty_variant elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_variant with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_variant elem ~ctx ~top_down ~bottom_up)) and (traverse_ctor_variant_Single : record -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> record) = fun variant_Single ~ctx ~top_down ~bottom_up -> transform_ty_record variant_Single ~ctx ~top_down ~bottom_up and (transform_ctor_variant_Single : record -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> record) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ctor_variant_Single with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse_ctor_variant_Single elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ctor_variant_Single with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ctor_variant_Single elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform_ctor_variant_Single elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse_ctor_variant_Single elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ctor_variant_Single with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ctor_variant_Single elem ~ctx ~top_down ~bottom_up)) and (traverse_ctor_variant_Tuple : alias * record -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> alias * record) = fun (variant_Tuple_0, variant_Tuple_1) ~ctx ~top_down ~bottom_up -> ( transform_ty_alias variant_Tuple_0 ~ctx ~top_down ~bottom_up, transform_ty_record variant_Tuple_1 ~ctx ~top_down ~bottom_up ) and (transform_ctor_variant_Tuple : alias * record -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> alias * record) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ctor_variant_Tuple with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse_ctor_variant_Tuple elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ctor_variant_Tuple with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ctor_variant_Tuple elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform_ctor_variant_Tuple elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse_ctor_variant_Tuple elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ctor_variant_Tuple with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ctor_variant_Tuple elem ~ctx ~top_down ~bottom_up)) let _ = traverse_ty_alias and _ = transform_ty_alias and _ = traverse_ty_record and _ = transform_ty_record and _ = traverse_fld_record_variant and _ = transform_fld_record_variant and _ = traverse_ty_variant and _ = transform_ty_variant and _ = traverse_ctor_variant_Single and _ = transform_ctor_variant_Single and _ = traverse_ctor_variant_Tuple and _ = transform_ctor_variant_Tuple end [@@ocaml.doc "@inline"] [@@merlin.hide] end module Explicit_annotations_gadt : sig type z = Z : z and 'n s = S : 'n -> 'n s and ('a, _) gtree = | EmptyG : ('a, z) gtree | TreeG : ('a, 'n) gtree * 'a * ('a, 'n) gtree -> ('a, 'n s) gtree [@transform.explicit] [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_z: (z -> ctx:'ctx -> 'ctx * [ `Stop of z | `Continue of z | `Restart of z ]) option; on_ty_s: 'a. ('a s -> ctx:'ctx -> 'ctx * [ `Stop of 'a s | `Continue of 'a s | `Restart of 'a s ]) option; on_ty_gtree: 'a 'b. (('a, 'b) gtree -> ctx:'ctx -> 'ctx * [ `Stop of ('a, 'b) gtree | `Continue of ('a, 'b) gtree | `Restart of ('a, 'b) gtree ]) option; on_ctor_gtree_TreeG: 'a 'n. (('a, 'n) gtree * 'a * ('a, 'n) gtree -> ctx:'ctx -> 'ctx * [ `Stop of ('a, 'n) gtree * 'a * ('a, 'n) gtree | `Continue of ('a, 'n) gtree * 'a * ('a, 'n) gtree | `Restart of ('a, 'n) gtree * 'a * ('a, 'n) gtree ]) option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform_ty_z : z -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> z val transform_ty_s : 'a s -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a s val transform_ty_gtree : ('a, 'b) gtree -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> ('a, 'b) gtree val transform_ctor_gtree_TreeG : ('a, 'n) gtree * 'a * ('a, 'n) gtree -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> ('a, 'n) gtree * 'a * ('a, 'n) gtree end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type z = Z : z and 'n s = S : 'n -> 'n s and ('a, _) gtree = | EmptyG : ('a, z) gtree | TreeG : ('a, 'n) gtree * 'a * ('a, 'n) gtree -> ('a, 'n s) gtree [@transform.explicit] [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : z) -> ()) let _ = (fun (_ : 'n s) -> ()) let _ = (fun (_ : ('a, _) gtree) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_z: (z -> ctx:'ctx -> 'ctx * [ `Stop of z | `Continue of z | `Restart of z ]) option; on_ty_s: 'a. ('a s -> ctx:'ctx -> 'ctx * [ `Stop of 'a s | `Continue of 'a s | `Restart of 'a s ]) option; on_ty_gtree: 'a 'b. (('a, 'b) gtree -> ctx:'ctx -> 'ctx * [ `Stop of ('a, 'b) gtree | `Continue of ('a, 'b) gtree | `Restart of ('a, 'b) gtree ]) option; on_ctor_gtree_TreeG: 'a 'n. (('a, 'n) gtree * 'a * ('a, 'n) gtree -> ctx:'ctx -> 'ctx * [ `Stop of ('a, 'n) gtree * 'a * ('a, 'n) gtree | `Continue of ('a, 'n) gtree * 'a * ('a, 'n) gtree | `Restart of ('a, 'n) gtree * 'a * ('a, 'n) gtree ]) option; } let identity _ = { on_ty_z = None; on_ty_s = None; on_ty_gtree = None; on_ctor_gtree_TreeG = None; } let _ = identity let combine p1 p2 = { on_ty_z = (match (p1.on_ty_z, p2.on_ty_z) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_z | _ -> p1.on_ty_z); on_ty_s = (match (p1.on_ty_s, p2.on_ty_s) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_s | _ -> p1.on_ty_s); on_ty_gtree = (match (p1.on_ty_gtree, p2.on_ty_gtree) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_gtree | _ -> p1.on_ty_gtree); on_ctor_gtree_TreeG = (match (p1.on_ctor_gtree_TreeG, p2.on_ctor_gtree_TreeG) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ctor_gtree_TreeG | _ -> p1.on_ctor_gtree_TreeG); } let _ = combine end let rec (transform_ty_z : z -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> z) = fun (elem : z) ~ctx ~top_down ~bottom_up : z -> match top_down.Pass.on_ty_z with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (_ctx, `Continue elem) -> (match bottom_up.Pass.on_ty_z with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_z elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform_ty_z elem ~ctx ~top_down ~bottom_up) | _ -> (match bottom_up.Pass.on_ty_z with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_z elem ~ctx ~top_down ~bottom_up)) let _ = transform_ty_z let rec transform_ty_s : 'a. 'a s -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a s = fun (type a) (elem : a s) ~ctx ~top_down ~bottom_up : a s -> match top_down.Pass.on_ty_s with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (_ctx, `Continue elem) -> (match bottom_up.Pass.on_ty_s with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_s elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform_ty_s elem ~ctx ~top_down ~bottom_up) | _ -> (match bottom_up.Pass.on_ty_s with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_s elem ~ctx ~top_down ~bottom_up)) let _ = transform_ty_s let rec traverse_ty_gtree : 'a 'b. ('a, 'b) gtree -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> ('a, 'b) gtree = fun (type a b) (gtree : (a, b) gtree) ~ctx ~top_down ~bottom_up : (a, b) gtree -> match gtree with | TreeG (elem_0, elem_1, elem_2) -> let (elem_0, elem_1, elem_2) = transform_ctor_gtree_TreeG (elem_0, elem_1, elem_2) ~ctx ~top_down ~bottom_up in TreeG (elem_0, elem_1, elem_2) | gtree -> gtree and transform_ty_gtree : 'a 'b. ('a, 'b) gtree -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> ('a, 'b) gtree = fun (type a b) (elem : (a, b) gtree) ~ctx ~top_down ~bottom_up : (a, b) gtree -> match top_down.Pass.on_ty_gtree with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse_ty_gtree elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_gtree with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_gtree elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform_ty_gtree elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse_ty_gtree elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_gtree with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ty_gtree elem ~ctx ~top_down ~bottom_up)) and traverse_ctor_gtree_TreeG : 'a 'n. ('a, 'n) gtree * 'a * ('a, 'n) gtree -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> ('a, 'n) gtree * 'a * ('a, 'n) gtree = fun (gtree_TreeG_0, gtree_TreeG_1, gtree_TreeG_2) ~ctx ~top_down ~bottom_up -> ( transform_ty_gtree gtree_TreeG_0 ~ctx ~top_down ~bottom_up, gtree_TreeG_1, transform_ty_gtree gtree_TreeG_2 ~ctx ~top_down ~bottom_up ) and transform_ctor_gtree_TreeG : 'a 'n. ('a, 'n) gtree * 'a * ('a, 'n) gtree -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> ('a, 'n) gtree * 'a * ('a, 'n) gtree = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ctor_gtree_TreeG with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse_ctor_gtree_TreeG elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ctor_gtree_TreeG with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ctor_gtree_TreeG elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform_ctor_gtree_TreeG elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse_ctor_gtree_TreeG elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ctor_gtree_TreeG with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform_ctor_gtree_TreeG elem ~ctx ~top_down ~bottom_up)) let _ = traverse_ty_gtree and _ = transform_ty_gtree and _ = traverse_ctor_gtree_TreeG and _ = transform_ctor_gtree_TreeG end [@@ocaml.doc "@inline"] [@@merlin.hide] end module No_restart : sig type t = | Num of int | Plus of t * t | Leq of t * t | Cond of t * t * t [@@deriving transform ~restart:(`Disallow `Encode_as_variant)] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t ]) option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type t = | Num of int | Plus of t * t | Leq of t * t | Cond of t * t * t [@@deriving transform ~restart:(`Disallow `Encode_as_variant)] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t ]) option; } let identity _ = { on_ty_t = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); } let _ = combine end let rec (traverse : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun t ~ctx ~top_down ~bottom_up -> match t with | Plus (plus_elem_0, plus_elem_1) -> Plus ( transform plus_elem_0 ~ctx ~top_down ~bottom_up, transform plus_elem_1 ~ctx ~top_down ~bottom_up ) | Leq (leq_elem_0, leq_elem_1) -> Leq ( transform leq_elem_0 ~ctx ~top_down ~bottom_up, transform leq_elem_1 ~ctx ~top_down ~bottom_up ) | Cond (cond_elem_0, cond_elem_1, cond_elem_2) -> Cond ( transform cond_elem_0 ~ctx ~top_down ~bottom_up, transform cond_elem_1 ~ctx ~top_down ~bottom_up, transform cond_elem_2 ~ctx ~top_down ~bottom_up ) | t -> t and (transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem))) | _ -> let elem = traverse elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem)) let _ = traverse and _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end module No_restart_as_result : sig type t = | Num of int | Plus of t * t | Leq of t * t | Cond of t * t * t [@@deriving transform ~restart:(`Disallow `Encode_as_result)] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * (t, t) result) option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type t = | Num of int | Plus of t * t | Leq of t * t | Cond of t * t * t [@@deriving transform ~restart:(`Disallow `Encode_as_result)] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * (t, t) result) option; } let identity _ = { on_ty_t = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, Ok elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); } let _ = combine end let rec (traverse : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun t ~ctx ~top_down ~bottom_up -> match t with | Plus (plus_elem_0, plus_elem_1) -> Plus ( transform plus_elem_0 ~ctx ~top_down ~bottom_up, transform plus_elem_1 ~ctx ~top_down ~bottom_up ) | Leq (leq_elem_0, leq_elem_1) -> Leq ( transform leq_elem_0 ~ctx ~top_down ~bottom_up, transform leq_elem_1 ~ctx ~top_down ~bottom_up ) | Cond (cond_elem_0, cond_elem_1, cond_elem_2) -> Cond ( transform cond_elem_0 ~ctx ~top_down ~bottom_up, transform cond_elem_1 ~ctx ~top_down ~bottom_up, transform cond_elem_2 ~ctx ~top_down ~bottom_up ) | t -> t and (transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, Error elem) -> elem | (td_ctx, Ok elem) -> let elem = traverse elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (Ok elem | Error elem)) -> elem))) | _ -> let elem = traverse elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (Ok elem | Error elem)) -> elem)) let _ = traverse and _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end module Variants = struct module Other : sig type t = { stuff: int } [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type t = { stuff: int } [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; } let identity _ = { on_ty_t = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); } let _ = combine end let rec (transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (_ctx, `Continue elem) -> (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up) | _ -> (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) let _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end module Exactly : sig type t = [ `A of Other.t | `B of Other.t ] [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; on_Other: 'ctx Other.Pass.t option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type t = [ `A of Other.t | `B of Other.t ] [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; on_Other: 'ctx Other.Pass.t option; } let identity _ = { on_ty_t = None; on_Other = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); on_Other = (match (p1.on_Other, p2.on_Other) with | (Some p1, Some p2) -> Some (Other.Pass.combine p1 p2) | (Some _, _) -> p1.on_Other | _ -> p2.on_Other); } let _ = combine end let rec (traverse : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun t ~ctx ~top_down ~bottom_up -> match t with | `A t_elem -> `A (match (top_down.Pass.on_Other, bottom_up.Pass.on_Other) with | (Some top_down, Some bottom_up) -> Other.transform t_elem ~ctx ~top_down ~bottom_up | (Some top_down, _) -> Other.transform t_elem ~ctx ~top_down ~bottom_up:(Other.Pass.identity ()) | (_, Some bottom_up) -> Other.transform t_elem ~ctx ~top_down:(Other.Pass.identity ()) ~bottom_up | _ -> t_elem) | `B t_elem -> `B (match (top_down.Pass.on_Other, bottom_up.Pass.on_Other) with | (Some top_down, Some bottom_up) -> Other.transform t_elem ~ctx ~top_down ~bottom_up | (Some top_down, _) -> Other.transform t_elem ~ctx ~top_down ~bottom_up:(Other.Pass.identity ()) | (_, Some bottom_up) -> Other.transform t_elem ~ctx ~top_down:(Other.Pass.identity ()) ~bottom_up | _ -> t_elem) and (transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) let _ = traverse and _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end module Extend : sig type t = [ `More of Other.t | `Zero | Exactly.t ] [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; on_Exactly: 'ctx Exactly.Pass.t option; on_Other: 'ctx Other.Pass.t option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type t = [ `More of Other.t | `Zero | Exactly.t ] [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; on_Exactly: 'ctx Exactly.Pass.t option; on_Other: 'ctx Other.Pass.t option; } let identity _ = { on_ty_t = None; on_Exactly = None; on_Other = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); on_Exactly = (match (p1.on_Exactly, p2.on_Exactly) with | (Some p1, Some p2) -> Some (Exactly.Pass.combine p1 p2) | (Some _, _) -> p1.on_Exactly | _ -> p2.on_Exactly); on_Other = (match (p1.on_Other, p2.on_Other) with | (Some p1, Some p2) -> Some (Other.Pass.combine p1 p2) | (Some _, _) -> p1.on_Other | _ -> p2.on_Other); } let _ = combine end let rec (traverse : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun t ~ctx ~top_down ~bottom_up -> match t with | `More t_elem -> `More (match (top_down.Pass.on_Other, bottom_up.Pass.on_Other) with | (Some top_down, Some bottom_up) -> Other.transform t_elem ~ctx ~top_down ~bottom_up | (Some top_down, _) -> Other.transform t_elem ~ctx ~top_down ~bottom_up:(Other.Pass.identity ()) | (_, Some bottom_up) -> Other.transform t_elem ~ctx ~top_down:(Other.Pass.identity ()) ~bottom_up | _ -> t_elem) | #Exactly.t as t_extend -> (match (top_down.Pass.on_Exactly, bottom_up.Pass.on_Exactly) with | (Some top_down, Some bottom_up) -> Exactly.transform t_extend ~ctx ~top_down ~bottom_up | (Some top_down, _) -> Exactly.transform t_extend ~ctx ~top_down ~bottom_up:(Exactly.Pass.identity ()) | (_, Some bottom_up) -> Exactly.transform t_extend ~ctx ~top_down:(Exactly.Pass.identity ()) ~bottom_up | _ -> t_extend :> [ `More of Other.t | `Zero | Exactly.t ]) | t -> t and (transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) let _ = traverse and _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end module At_least : sig type 'a t = [> `A of Other.t | `B of Other.t ] as 'a [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: 'a. ('a t -> ctx:'ctx -> 'ctx * [ `Stop of 'a t | `Continue of 'a t | `Restart of 'a t ]) option; on_Other: 'ctx Other.Pass.t option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : 'a t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type 'a t = [> `A of Other.t | `B of Other.t ] as 'a [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : 'a t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: 'a. ('a t -> ctx:'ctx -> 'ctx * [ `Stop of 'a t | `Continue of 'a t | `Restart of 'a t ]) option; on_Other: 'ctx Other.Pass.t option; } let identity _ = { on_ty_t = None; on_Other = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); on_Other = (match (p1.on_Other, p2.on_Other) with | (Some p1, Some p2) -> Some (Other.Pass.combine p1 p2) | (Some _, _) -> p1.on_Other | _ -> p2.on_Other); } let _ = combine end let rec traverse : 'a. 'a t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a t = fun t ~ctx ~top_down ~bottom_up -> match t with | `A t_elem -> `A (match (top_down.Pass.on_Other, bottom_up.Pass.on_Other) with | (Some top_down, Some bottom_up) -> Other.transform t_elem ~ctx ~top_down ~bottom_up | (Some top_down, _) -> Other.transform t_elem ~ctx ~top_down ~bottom_up:(Other.Pass.identity ()) | (_, Some bottom_up) -> Other.transform t_elem ~ctx ~top_down:(Other.Pass.identity ()) ~bottom_up | _ -> t_elem) | `B t_elem -> `B (match (top_down.Pass.on_Other, bottom_up.Pass.on_Other) with | (Some top_down, Some bottom_up) -> Other.transform t_elem ~ctx ~top_down ~bottom_up | (Some top_down, _) -> Other.transform t_elem ~ctx ~top_down ~bottom_up:(Other.Pass.identity ()) | (_, Some bottom_up) -> Other.transform t_elem ~ctx ~top_down:(Other.Pass.identity ()) ~bottom_up | _ -> t_elem) | t -> t and transform : 'a. 'a t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a t = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) let _ = traverse and _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end module At_most : sig type 'a t = [< `A of Other.t | `B of Other.t ] as 'a [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: 'a. ('a t -> ctx:'ctx -> 'ctx * [ `Stop of 'a t | `Continue of 'a t | `Restart of 'a t ]) option; on_Other: 'ctx Other.Pass.t option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : 'a t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type 'a t = [< `A of Other.t | `B of Other.t ] as 'a [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : 'a t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: 'a. ('a t -> ctx:'ctx -> 'ctx * [ `Stop of 'a t | `Continue of 'a t | `Restart of 'a t ]) option; on_Other: 'ctx Other.Pass.t option; } let identity _ = { on_ty_t = None; on_Other = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); on_Other = (match (p1.on_Other, p2.on_Other) with | (Some p1, Some p2) -> Some (Other.Pass.combine p1 p2) | (Some _, _) -> p1.on_Other | _ -> p2.on_Other); } let _ = combine end let rec transform : 'a. 'a t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a t = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (_ctx, `Continue elem) -> (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up) | _ -> (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) let _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end module As_most_and_at_least : sig type 'a t = [< `A of Other.t | `B of Other.t > `A ] as 'a [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: 'a. ('a t -> ctx:'ctx -> 'ctx * [ `Stop of 'a t | `Continue of 'a t | `Restart of 'a t ]) option; on_Other: 'ctx Other.Pass.t option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : 'a t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type 'a t = [< `A of Other.t | `B of Other.t > `A ] as 'a [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : 'a t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: 'a. ('a t -> ctx:'ctx -> 'ctx * [ `Stop of 'a t | `Continue of 'a t | `Restart of 'a t ]) option; on_Other: 'ctx Other.Pass.t option; } let identity _ = { on_ty_t = None; on_Other = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); on_Other = (match (p1.on_Other, p2.on_Other) with | (Some p1, Some p2) -> Some (Other.Pass.combine p1 p2) | (Some _, _) -> p1.on_Other | _ -> p2.on_Other); } let _ = combine end let rec traverse : 'a. 'a t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a t = fun t ~ctx ~top_down ~bottom_up -> match t with | `A t_elem -> `A (match (top_down.Pass.on_Other, bottom_up.Pass.on_Other) with | (Some top_down, Some bottom_up) -> Other.transform t_elem ~ctx ~top_down ~bottom_up | (Some top_down, _) -> Other.transform t_elem ~ctx ~top_down ~bottom_up:(Other.Pass.identity ()) | (_, Some bottom_up) -> Other.transform t_elem ~ctx ~top_down:(Other.Pass.identity ()) ~bottom_up | _ -> t_elem) | t -> t and transform : 'a. 'a t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a t = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) let _ = traverse and _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end end module Polymorphic = struct module Other : sig type 'a t = Self of 'a t option [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: 'a. ('a t -> ctx:'ctx -> 'ctx * [ `Stop of 'a t | `Continue of 'a t | `Restart of 'a t ]) option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : 'a t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type 'a t = Self of 'a t option [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : 'a t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: 'a. ('a t -> ctx:'ctx -> 'ctx * [ `Stop of 'a t | `Continue of 'a t | `Restart of 'a t ]) option; } let identity _ = { on_ty_t = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); } let _ = combine end let rec traverse : 'a. 'a t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a t = fun t ~ctx ~top_down ~bottom_up -> match t with | Self self_elem -> Self (match self_elem with | Some self_elem_inner -> Some (transform self_elem_inner ~ctx ~top_down ~bottom_up) | _ -> None) and transform : 'a. 'a t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> 'a t = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) let _ = traverse and _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end module Quantified : sig type t = { forall: 'a. 'a Other.t } [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; on_Other: 'ctx Other.Pass.t option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type t = { forall: 'a. 'a Other.t } [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; on_Other: 'ctx Other.Pass.t option; } let identity _ = { on_ty_t = None; on_Other = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); on_Other = (match (p1.on_Other, p2.on_Other) with | (Some p1, Some p2) -> Some (Other.Pass.combine p1 p2) | (Some _, _) -> p1.on_Other | _ -> p2.on_Other); } let _ = combine end let rec (traverse : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun { forall } ~ctx ~top_down ~bottom_up -> { forall = (match (top_down.Pass.on_Other, bottom_up.Pass.on_Other) with | (Some top_down, Some bottom_up) -> Other.transform forall ~ctx ~top_down ~bottom_up | (Some top_down, _) -> Other.transform forall ~ctx ~top_down ~bottom_up:(Other.Pass.identity ()) | (_, Some bottom_up) -> Other.transform forall ~ctx ~top_down:(Other.Pass.identity ()) ~bottom_up | _ -> forall); } and (transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) let _ = traverse and _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end end module Recursive_mod = struct module rec One : sig type t = One of Two.t option [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; on_Two: 'ctx Two.Pass.t option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type t = One of Two.t option [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; on_Two: 'ctx Two.Pass.t option; } let identity _ = { on_ty_t = None; on_Two = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); on_Two = (match (p1.on_Two, p2.on_Two) with | (Some p1, Some p2) -> Some (Two.Pass.combine p1 p2) | (Some _, _) -> p1.on_Two | _ -> p2.on_Two); } let _ = combine end let rec (traverse : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun t ~ctx ~top_down ~bottom_up -> match t with | One one_elem -> One (match one_elem with | Some one_elem_inner -> Some (match (top_down.Pass.on_Two, bottom_up.Pass.on_Two) with | (Some top_down, Some bottom_up) -> Two.transform one_elem_inner ~ctx ~top_down ~bottom_up | (Some top_down, _) -> Two.transform one_elem_inner ~ctx ~top_down ~bottom_up:(Two.Pass.identity ()) | (_, Some bottom_up) -> Two.transform one_elem_inner ~ctx ~top_down:(Two.Pass.identity ()) ~bottom_up | _ -> one_elem_inner) | _ -> None) and (transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) let _ = traverse and _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end and Two : sig type t = Two of One.t option [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; on_One: 'ctx One.Pass.t option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type t = Two of One.t option [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; on_One: 'ctx One.Pass.t option; } let identity _ = { on_ty_t = None; on_One = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); on_One = (match (p1.on_One, p2.on_One) with | (Some p1, Some p2) -> Some (One.Pass.combine p1 p2) | (Some _, _) -> p1.on_One | _ -> p2.on_One); } let _ = combine end let rec (traverse : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun t ~ctx ~top_down ~bottom_up -> match t with | Two two_elem -> Two (match two_elem with | Some two_elem_inner -> Some (match (top_down.Pass.on_One, bottom_up.Pass.on_One) with | (Some top_down, Some bottom_up) -> One.transform two_elem_inner ~ctx ~top_down ~bottom_up | (Some top_down, _) -> One.transform two_elem_inner ~ctx ~top_down ~bottom_up:(One.Pass.identity ()) | (_, Some bottom_up) -> One.transform two_elem_inner ~ctx ~top_down:(One.Pass.identity ()) ~bottom_up | _ -> two_elem_inner) | _ -> None) and (transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) let _ = traverse and _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end end
OCaml
hhvm/hphp/hack/test/ppx-transform/test.ml
(* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) module Variant : sig type t = | Num of int | Plus of t * t | Leq of t * t | Cond of t * t * t [@@deriving transform] end = struct type t = | Num of int | Plus of t * t | Leq of t * t | Cond of t * t * t [@@deriving transform] end module Gadt : sig type _ t = | T : bool t | F : bool t | Num : int -> int t | Plus : (int t * int t) -> int t | Leq : (int t * int t) -> bool t | Cond : (bool t * 'a t * 'a t) -> 'a t [@@deriving transform] end = struct type _ t = | T : bool t | F : bool t | Num : int -> int t | Plus : (int t * int t) -> int t | Leq : (int t * int t) -> bool t | Cond : (bool t * 'a t * 'a t) -> 'a t [@@deriving transform] end module Nonregular : sig type 'a term = | Var of 'a | App of 'a term * 'a term | Abs of 'a bind term and 'a bind = | Zero | Succ of 'a [@@deriving transform] end = struct (* de Bruijn notation as a nested datatype *) type 'a term = | Var of 'a | App of 'a term * 'a term | Abs of 'a bind term and 'a bind = | Zero | Succ of 'a [@@deriving transform] end module Nonregular_mutual : sig type 'a one = | Nil | Two of 'a two and 'a two = MaybeOne of 'a option one [@@deriving transform] end = struct type 'a one = | Nil | Two of 'a two and 'a two = MaybeOne of 'a option one [@@deriving transform] end module Nonregular_mutual_gadt : sig type 'a one = | Nil : 'a one | Two : 'a two -> 'a one and 'a two = MaybeOne of 'a option one [@@deriving transform] end = struct type 'a one = | Nil : 'a one | Two : 'a two -> 'a one and 'a two = MaybeOne of 'a option one [@@deriving transform] end module Composed = struct module BinOp : sig type t = | Add | Sub | Mul | Div [@@deriving transform] end = struct type t = | Add | Sub | Mul | Div [@@deriving transform] end module RelOp : sig type t = | Eq | Lt | Gt [@@deriving transform] end = struct type t = | Eq | Lt | Gt [@@deriving transform] end module ConnOp : sig type t = | And | Or [@@deriving transform] end = struct type t = | And | Or [@@deriving transform] end module Expr : sig type t = | Num of int | Bin of BinOp.t * t * t | Rel of RelOp.t * t * t | Conn of ConnOp.t * t * t | Cond of t * t * t [@@deriving transform] end = struct type t = | Num of int | Bin of BinOp.t * t * t | Rel of RelOp.t * t * t | Conn of ConnOp.t * t * t | Cond of t * t * t [@@deriving transform] end module Expr_gadt : sig type _ t = | Num : int -> int t | Bin : (BinOp.t * int t * int t) -> int t | Rel : (RelOp.t * int t * int t) -> bool t | Conn : (ConnOp.t * bool t * bool t) -> bool t | Cond : (bool t * 'a t * 'a t) -> 'a t [@@deriving transform] end = struct type _ t = | Num : int -> int t | Bin : (BinOp.t * int t * int t) -> int t | Rel : (RelOp.t * int t * int t) -> bool t | Conn : (ConnOp.t * bool t * bool t) -> bool t | Cond : (bool t * 'a t * 'a t) -> 'a t [@@deriving transform] end end module Builtins : sig type 'a t = { prim_ignored: char; ref: 'a t ref; opt: 'a t option; res: ('a t, 'a t) result; list: 'a t list; array: 'a t array; lazy_: 'a t lazy_t; nested: ('a t option list, 'a t array option) result list option lazy_t; } [@@deriving transform] end = struct type 'a t = { prim_ignored: char; ref: 'a t ref; opt: 'a t option; res: ('a t, 'a t) result; list: 'a t list; array: 'a t array; lazy_: 'a t lazy_t; nested: ('a t option list, 'a t array option) result list option lazy_t; } [@@deriving transform] end module Opaque_annotations : sig type variant = | Opaque_ctor of record [@transform.opaque] | Normal of record | Tuple_with_opaque of (record * (alias[@transform.opaque]) * opaque_decl) and record = { normal: alias; opaque: alias; [@transform.opaque] } and alias = record * (variant[@transform.opaque]) * opaque_decl and opaque_decl = Opaque of variant * record * alias [@@transform.opaque] [@@deriving transform] end = struct type variant = | Opaque_ctor of record [@transform.opaque] | Normal of record | Tuple_with_opaque of (record * (alias[@transform.opaque]) * opaque_decl) and record = { normal: alias; opaque: alias; [@transform.opaque] } and alias = record * (variant[@transform.opaque]) * opaque_decl and opaque_decl = Opaque of variant * record * alias [@@transform.opaque] [@@deriving transform] end module Explicit_annotations : sig type variant = | Constant (* Doesn't support explicit [@transform.explicit] *) | Inline_record of { a: int; b: record; } (* Doesn't support explicit [@transform.explicit] *) | Single of record [@transform.explicit] | Tuple of alias * record [@transform.explicit] and record = { variant: variant [@transform.explicit] } and alias = (record * variant(* uninterpreted otherwise *) [@transform.explicit]) [@@deriving transform] end = struct type variant = | Constant (* Doesn't support explicit [@transform.explicit] *) | Inline_record of { a: int; b: record; } (* Doesn't support explicit [@transform.explicit] *) | Single of record [@transform.explicit] | Tuple of alias * record [@transform.explicit] and record = { variant: variant [@transform.explicit] } and alias = (record * variant(* uninterpreted otherwise *) [@transform.explicit]) [@@deriving transform] end module Explicit_annotations_gadt : sig type z = Z : z and 'n s = S : 'n -> 'n s and ('a, _) gtree = | EmptyG : ('a, z) gtree | TreeG : ('a, 'n) gtree * 'a * ('a, 'n) gtree -> ('a, 'n s) gtree [@transform.explicit] [@@deriving transform] end = struct type z = Z : z and 'n s = S : 'n -> 'n s and ('a, _) gtree = | EmptyG : ('a, z) gtree | TreeG : ('a, 'n) gtree * 'a * ('a, 'n) gtree -> ('a, 'n s) gtree [@transform.explicit] [@@deriving transform] end module No_restart : sig type t = | Num of int | Plus of t * t | Leq of t * t | Cond of t * t * t [@@deriving transform ~restart:(`Disallow `Encode_as_variant)] end = struct type t = | Num of int | Plus of t * t | Leq of t * t | Cond of t * t * t [@@deriving transform ~restart:(`Disallow `Encode_as_variant)] end module No_restart_as_result : sig type t = | Num of int | Plus of t * t | Leq of t * t | Cond of t * t * t [@@deriving transform ~restart:(`Disallow `Encode_as_result)] end = struct type t = | Num of int | Plus of t * t | Leq of t * t | Cond of t * t * t [@@deriving transform ~restart:(`Disallow `Encode_as_result)] end module Variants = struct module Other : sig type t = { stuff: int } [@@deriving transform] end = struct type t = { stuff: int } [@@deriving transform] end module Exactly : sig type t = [ `A of Other.t | `B of Other.t ] [@@deriving transform] end = struct type t = [ `A of Other.t | `B of Other.t ] [@@deriving transform] end module Extend : sig type t = [ `More of Other.t | `Zero | Exactly.t ] [@@deriving transform] end = struct type t = [ `More of Other.t | `Zero | Exactly.t ] [@@deriving transform] end module At_least : sig type 'a t = [> `A of Other.t | `B of Other.t ] as 'a [@@deriving transform] end = struct type 'a t = [> `A of Other.t | `B of Other.t ] as 'a [@@deriving transform] end module At_most : sig type 'a t = [< `A of Other.t | `B of Other.t ] as 'a [@@deriving transform] end = struct type 'a t = [< `A of Other.t | `B of Other.t ] as 'a [@@deriving transform] end module As_most_and_at_least : sig type 'a t = [< `A of Other.t | `B of Other.t > `A ] as 'a [@@deriving transform] end = struct type 'a t = [< `A of Other.t | `B of Other.t > `A ] as 'a [@@deriving transform] end end module Polymorphic = struct module Other : sig type 'a t = Self of 'a t option [@@deriving transform] end = struct type 'a t = Self of 'a t option [@@deriving transform] end module Quantified : sig type t = { forall: 'a. 'a Other.t } [@@deriving transform] end = struct type t = { forall: 'a. 'a Other.t } [@@deriving transform] end end module Recursive_mod = struct module rec One : sig type t = One of Two.t option [@@deriving transform] end = struct type t = One of Two.t option [@@deriving transform] end and Two : sig type t = Two of One.t option [@@deriving transform] end = struct type t = Two of One.t option [@@deriving transform] end end
OCaml
hhvm/hphp/hack/test/ppx-transform/test_constant_ctor_embed_error.expected.ml
module Constant_ctor_error : sig type t = | Constant [@deriving transform.explicit] | Other of t option [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type t = | Constant [@deriving transform.explicit] | Other of t option [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; } let identity _ = { on_ty_t = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); } let _ = combine end let rec (traverse : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun t ~ctx ~top_down ~bottom_up -> match t with | Other other_elem -> Other (match other_elem with | Some other_elem_inner -> Some (transform other_elem_inner ~ctx ~top_down ~bottom_up) | _ -> None) | t -> t and (transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) let _ = traverse and _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end
OCaml
hhvm/hphp/hack/test/ppx-transform/test_constant_ctor_embed_error.ml
(* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) module Constant_ctor_error : sig type t = | Constant [@deriving transform.explicit] | Other of t option [@@deriving transform] end = struct type t = | Constant [@deriving transform.explicit] | Other of t option [@@deriving transform] end
OCaml
hhvm/hphp/hack/test/ppx-transform/test_inline_record_embed_error.expected.ml
module Inline_record_error : sig type t = | Inline_record of { a: int; b: t option; } [@transform.explicit] | Other of t option [@@deriving transform] include sig [@@@ocaml.warning "-32-60"] module Pass : sig type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; } val combine : 'ctx t -> 'ctx t -> 'ctx t val identity : unit -> 'ctx t end val transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t end [@@ocaml.doc "@inline"] [@@merlin.hide] end = struct type t = | Inline_record of { a: int; b: t option; } [@transform.explicit] | Other of t option [@@deriving transform] include struct [@@@ocaml.warning "-60"] let _ = (fun (_ : t) -> ()) module Pass = struct type nonrec 'ctx t = { on_ty_t: (t -> ctx:'ctx -> 'ctx * [ `Stop of t | `Continue of t | `Restart of t ]) option; } let identity _ = { on_ty_t = None } let _ = identity let combine p1 p2 = { on_ty_t = (match (p1.on_ty_t, p2.on_ty_t) with | (Some t1, Some t2) -> Some (fun elem ~ctx -> match t1 elem ~ctx with | (ctx, `Continue elem) -> t2 elem ~ctx | otherwise -> otherwise) | (None, _) -> p2.on_ty_t | _ -> p1.on_ty_t); } let _ = combine end let rec (traverse : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun t ~ctx ~top_down ~bottom_up -> match t with | Inline_record ({ b; _ } as inline_record) -> [%ocaml.error "Explicit transforms of inline records are not supported by the `ppx_transform` preprocessor"] | Other other_elem -> Other (match other_elem with | Some other_elem_inner -> Some (transform other_elem_inner ~ctx ~top_down ~bottom_up) | _ -> None) and (transform : t -> ctx:'ctx -> top_down:'ctx Pass.t -> bottom_up:'ctx Pass.t -> t) = fun elem ~ctx ~top_down ~bottom_up -> match top_down.Pass.on_ty_t with | Some td -> (match td elem ~ctx with | (_ctx, `Stop elem) -> elem | (td_ctx, `Continue elem) -> let elem = traverse elem ~ctx:td_ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up) | _ -> let elem = traverse elem ~ctx ~top_down ~bottom_up in (match bottom_up.Pass.on_ty_t with | None -> elem | Some bu -> (match bu elem ~ctx with | (_ctx, (`Continue elem | `Stop elem)) -> elem | (_ctx, `Restart elem) -> transform elem ~ctx ~top_down ~bottom_up)) let _ = traverse and _ = transform end [@@ocaml.doc "@inline"] [@@merlin.hide] end
OCaml
hhvm/hphp/hack/test/ppx-transform/test_inline_record_embed_error.ml
(* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) module Inline_record_error : sig type t = | Inline_record of { a: int; b: t option; } [@transform.explicit] | Other of t option [@@deriving transform] end = struct type t = | Inline_record of { a: int; b: t option; } [@transform.explicit] | Other of t option [@@deriving transform] end
OCaml
hhvm/hphp/hack/test/procs/procs_test_utils.ml
open Hh_prelude let entry = WorkerControllerEntryPoint.register ~restore:(fun _ ~(worker_id : int) -> Hh_logger.set_id (Printf.sprintf "procs_test_utils %d" worker_id)) let try_finalize f x finally y = let res = try f x with | exn -> finally y; raise exn in finally y; res let use_worker_clones = Array.length Sys.argv < 2 || not (String.equal Sys.argv.(1) "NO_CLONES") let make_workers n = let handle = SharedMem.init ~num_workers:n SharedMem.default_config in let workers = MultiWorker.make ~longlived_workers:(not use_worker_clones) ~saved_state:handle ~entry n ~gc_control:GlobalConfig.gc_control ~heap_handle:handle in workers let cleanup () = WorkerController.force_quit_all () let run_interrupter limit = let (fd_in, fd_out) = Unix.pipe () in let interrupter_pid = match Unix.fork () with | 0 -> Unix.close fd_in; let rec aux x = match x with | Some 0 -> exit 0 | _ -> let written = Unix.write fd_out (Bytes.of_string "!") 0 1 in assert (written = 1); aux (Option.map x ~f:(fun x -> x - 1)) in aux limit | pid -> pid in Unix.close fd_out; (fd_in, interrupter_pid) let read_exclamation_mark fd = let exclamation_mark = Bytes.create 1 in let read = Unix.read fd exclamation_mark 0 1 in assert (read = 1 && String.equal (Bytes.to_string exclamation_mark) "!")
OCaml
hhvm/hphp/hack/test/procs/procs_unit_test.ml
open Procs_test_utils let sum acc elements = List.fold_left (fun acc elem -> acc + elem) acc elements let multi_worker_list workers () = let work = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13] in let expected = List.length work * (List.length work + 1) / 2 in let result = MultiWorker.call (Some workers) ~job:sum ~merge:( + ) ~neutral:0 ~next:(Bucket.make ~num_workers:20 work) in Printf.printf "Got %d\n" result; result = expected let multi_worker_bucket workers () = let buckets = 20 in let next = let counter = ref 1 in fun () -> let current = !counter in counter := !counter + 1; if current <= buckets then Bucket.Job current else Bucket.Done in let expected = buckets * (buckets + 1) / 2 in let result = MultiWorker.call (Some workers) ~job:( + ) ~merge:( + ) ~neutral:0 ~next in Printf.printf "Got %d\n" result; result = expected let multi_worker_of_n_buckets workers () = let buckets = 20 in let split ~bucket = bucket + 1 in let expected = buckets * (buckets + 1) / 2 in Bucket.( let do_work _ bucket = assert (bucket.work = bucket.bucket + 1); bucket.work in let result = MultiWorker.call (Some workers) ~job:do_work ~merge:( + ) ~neutral:0 ~next:(make_n_buckets ~buckets ~split) in Printf.printf "Got %d\n" result; result = expected) let multi_worker_one_worker_throws _workers () = (* When a worker fails, the rest in the same MultiWorker call can't * be reused right now. So let's use fresh workers for this unit test * instead of corrupted the shared workers. *) let workers = make_workers 10 in let split ~bucket = bucket + 1 in Bucket.( let do_work _ bucket = if bucket.work = 5 then (* Bucket number 5 exits abnormally. *) exit 3 else bucket.work in MultiThreadedCall.( try let _result = MultiWorker.call (Some workers) ~job:do_work ~merge:( + ) ~neutral:0 ~next:(make_n_buckets ~buckets:20 ~split) in false with | Coalesced_failures [WorkerController.Worker_quit (Unix.WEXITED 3)] -> true)) let multi_worker_with_failure_handler _workers () = (* Spawn new workers since some will be failing and the rest non-reusable. *) let workers = make_workers 10 in let split ~bucket = (* * We want the first 5 buckets to all have exited when the MultiWorker result * is merged. Yes, they fail quickly, but it's still racy. We don't want to * see "just 3" failures or something when merging. * * To ensure all 5 have failed, we delay merging. * * To do that, we delay handing out the last 5 buckets. * * To do that, we add a sleep when creating the 6th bucket. * * This works because the result isn't merged until all buckets are handed * out. *) if bucket = 5 then let () = Unix.sleep 10 in bucket + 1 else bucket + 1 in Bucket.( let do_work _ { Bucket.work; _ } = (* First 5 buckets exit abnormally. The rest sleep. *) if work <= 5 then exit 3 else let () = Unix.sleep 60 in work in MultiThreadedCall.( try let _ = MultiWorker.call (Some workers) ~job:do_work ~merge:( + ) ~neutral:0 ~next:(make_n_buckets ~buckets:10 ~split) in Printf.eprintf "Expected MultiWorker.call to throw, but it didn't!\n"; false with | Coalesced_failures failures -> (* The first 5 buckets all failed; Last 5 buckets are still sleeping. *) Printf.eprintf "Got %d failed jobs. Expecting 5." (List.length failures); assert (List.length failures = 5); let sum = List.fold_left (fun acc e -> match e with | WorkerController.Worker_quit (Unix.WEXITED 3) -> acc + 3 | _ -> failwith "Unexpected worker exit") 0 failures in (* Sum of all exit codes (each exit 3) is 15. *) sum = 15)) let tests = [ ("multi_worker_list", multi_worker_list); ("multi_worker_bucket", multi_worker_bucket); ("multi_worker_of_n_buckets", multi_worker_of_n_buckets); ("multi_worker_one_worker_throws", multi_worker_one_worker_throws); ("multi_worker_with_failure_handler", multi_worker_with_failure_handler); ] let () = Daemon.check_entry_point (); (* this call might not return *) let workers = make_workers 10 in try_finalize Unit_test.run_all (List.map (fun (n, t) -> (n, t workers)) tests) cleanup ()
OCaml
hhvm/hphp/hack/test/procs/test_cancel_env.ml
open Procs_test_utils (* create workers and synchronize this global reference from master *) let pipe_path = ref "" let entry = WorkerControllerEntryPoint.register ~restore:(fun s ~(worker_id : int) -> pipe_path := s; Hh_logger.set_id (Printf.sprintf "test_cancel_env %d" worker_id)) let make_workers n = let handle = SharedMem.init ~num_workers:n SharedMem.default_config in let workers = MultiWorker.make ~longlived_workers:(not use_worker_clones) ~saved_state:!pipe_path ~entry n ~gc_control:GlobalConfig.gc_control ~heap_handle:handle in workers module UnitVal = struct type t = unit let description = "Test_UnitVal" end module TestHeap = SharedMem.Heap (SharedMem.ImmediateBackend (SharedMem.NonEvictable)) (StringKey) (UnitVal) (* The tasks will be numbers 1...num_workers_and_jobs, * and the job will be to sum them. Each worker will get one number at a time. *) let num_workers_and_jobs = 10 let max_job_size = 1 let sum acc x = acc + x let loop_until_cancel () = while true do (* interruptions only happen during shared-memory IO *) let (_ : bool) = TestHeap.mem "test" in Unix.sleep 1 done let do_work (acc : int) (jobs : int list) : int = let job = match jobs with | [job] -> job | _ -> assert false (* impossible due to max_job_size = 1 *) in (* Worker number 2 will go to sleep for long * enough that it will be definitely cancelled. *) if job = 2 then loop_until_cancel (); (* Workers number 3 and 7 will sleep long enough to let all the other ones (besides 2) to finish, and then ping the interrupt handler. Interrupt handler will will count the number of interruptions and cancel entire job after second ping (so all the workers beside 2 and 7 should finish) *) if job = 3 || job = 7 then ( Unix.sleep (if job = 3 then 2 else 4); let fd = Unix.openfile !pipe_path [Unix.O_WRONLY] 0o640 in let written = Unix.write fd (Bytes.of_string "!") 0 1 in assert (written = 1); if job = 7 then loop_until_cancel () ); sum acc job let rec make_work acc = function | 0 -> acc | x -> make_work (x :: acc) (x - 1) let make_work () = make_work [] num_workers_and_jobs (* read the pings, count them in env, and cancel after second one *) let interrupt_handler fd env = let exclamation_mark = Bytes.create 1 in let read = Unix.read fd exclamation_mark 0 1 in assert (read = 1 && Bytes.to_string exclamation_mark = "!"); let env = env + 1 in let result = MultiThreadedCall.( if env = 2 then Cancel { MultiThreadedCall.user_message = "c"; log_message = "c1"; timestamp = 0.0; } else Continue) in (env, result) let test_cancel_env () = Tempfile.with_tempdir @@ fun tempdir -> (* must set this before spawning workers *) (pipe_path := Path.(concat tempdir "mypipe" |> to_string)); let workers = make_workers num_workers_and_jobs in let work = make_work () in Unix.mkfifo !pipe_path 0o777; (* Opening as read-only either blocks, or spuriously runs interrupt handler * when workers open it for the first time. *) let interrupt_fd = Unix.openfile !pipe_path [Unix.O_RDWR] 0o640 in let next = Bucket.make ~num_workers:num_workers_and_jobs ~max_size:max_job_size work in let (res, interrupt_env, cancelled) = MultiWorker.call_with_interrupt (Some workers) ~job:do_work ~merge:sum ~neutral:0 ~next ~interrupt: { MultiThreadedCall.handlers = (fun _ -> [(interrupt_fd, interrupt_handler interrupt_fd)]); env = 0 (* counting number of times interrupt handler ran *); } in let total = num_workers_and_jobs * (num_workers_and_jobs + 1) / 2 in assert (interrupt_env = 2); assert (res = total - 7 - 2); begin match cancelled with | Some ([[7]; [2]], _) | Some ([[2]; [7]], _) -> () | _ -> failwith "unexpected cancellation result" end; true let () = Daemon.check_entry_point (); try_finalize Unit_test.run_all [("cancel_env", test_cancel_env)] cleanup ()
OCaml
hhvm/hphp/hack/test/procs/test_cancel_multi_worker.ml
module Hack_bucket = Bucket open Hh_prelude module Bucket = Hack_bucket open Procs_test_utils let num_workers = 10 let num_jobs = 100000 module IntVal = struct type t = int let description = "Test_IntVal" end module TestHeap = SharedMem.Heap (SharedMem.ImmediateBackend (SharedMem.NonEvictable)) (StringKey) (IntVal) let sum acc x = acc + x let do_work (acc : int) (jobs : int list) : int = (* Since worker clones are forked from the same process that doesn't do any calls to * random, the per-clone sequences are not really random without injecting a * bit more of enthropy. *) Random.self_init (); (* Ensure that at least some workers will get killed in the middle of the * job (with high probability) *) if Random.int 100 = 0 then Unix.sleep 1; List.fold_left jobs ~init:acc ~f:(fun acc job -> TestHeap.add (string_of_int job) job; sum acc job) let rec make_work acc = function | 0 -> acc | x -> make_work (x :: acc) (x - 1) let make_work () = make_work [] num_jobs let run_interrupter fd_in fd_out = Unix.close fd_in; while true do Unix.sleepf (0.5 +. Random.float 0.1); let written = Unix.write fd_out (Bytes.of_string "!") 0 1 in assert (written = 1) done; assert false let interrupt_handler fd acc = let exclamation_mark = Bytes.create 1 in (try while true do let (ready, _, _) = Unix.select [fd] [] [] 0.0 in if List.is_empty ready then raise Caml.Not_found; let read = Unix.read fd exclamation_mark 0 1 in assert (read = 1 && String.equal (Bytes.to_string exclamation_mark) "!") done with | Caml.Not_found -> ()); ( acc, MultiThreadedCall.Cancel { MultiThreadedCall.user_message = "cancel"; log_message = ""; timestamp = Unix.gettimeofday (); } ) let rec run_until_done fd_in workers (acc, iterations) = function | [] -> (acc, iterations) | work -> Hh_logger.log "Left: %d" (List.length work); let (result, (), unfinished_and_reason) = MultiWorker.call_with_interrupt (Some workers) ~job:do_work ~merge:sum ~neutral:0 ~next:(Bucket.make ~num_workers ~max_size:10 work) ~interrupt: { MultiThreadedCall.handlers = (fun () -> [(fd_in, interrupt_handler fd_in)]); env = (); } in let unfinished = match unfinished_and_reason with | Some (unfinished, _reason) -> List.concat unfinished | None -> [] in run_until_done fd_in workers (sum acc result, iterations + 1) unfinished (* Might raise because of Option.value_exn *) let rec sum_memory acc = function | [] -> acc | x :: xs -> sum_memory (acc + Option.value_exn (TestHeap.get (string_of_int x))) xs let multi_worker_cancel workers () = let work = make_work () in let (fd_in, fd_out) = Unix.pipe () in let interrupter_pid = match Unix.fork () with | 0 -> run_interrupter fd_in fd_out | pid -> pid in Unix.close fd_out; let t = Unix.gettimeofday () in let (result, iterations) = run_until_done fd_in workers (0, 0) work in let duration = Unix.gettimeofday () -. t in let memory_result = sum_memory 0 work in Unix.close fd_in; ignore @@ Unix.waitpid [] interrupter_pid; let expected = num_jobs * (num_jobs + 1) / 2 in (* behold... MATH! *) Printf.printf "Result: %d, memory result: %d in %f\n" memory_result result duration; (* Check that at least some cancellations have happened *) assert (iterations > 1); assert (result = expected && memory_result = expected); true let tests = [("multi_worker_cancel", multi_worker_cancel)] let () = Daemon.check_entry_point (); let workers = make_workers num_workers in try_finalize Unit_test.run_all (List.map ~f:(fun (n, t) -> (n, t workers)) tests) cleanup ()
OCaml
hhvm/hphp/hack/test/procs/test_interrupt_handler.ml
open Procs_test_utils let do_work () (_ : unit list) : unit = Unix.sleep 3 let handler1 fd (x, y) = let () = read_exclamation_mark fd in ((x + 1, y), MultiThreadedCall.Continue) let handler2 fd (x, y) = let () = read_exclamation_mark fd in ((x, y + 1), MultiThreadedCall.Continue) let configure_handlers fd1 fd2 (x, y) = let handlers = [] in let handlers = if x < 3 then (fd1, handler1 fd1) :: handlers else handlers in let handlers = if y < 4 then (fd2, handler2 fd2) :: handlers else handlers in handlers let test_interrupt_handler () = let next = Bucket.make ~num_workers:1 ~max_size:1 [()] in let workers = Some (make_workers 1) in let merge () _ = () in let (interrupt_fd1, interrupter_pid1) = run_interrupter (Some 10) in let (interrupt_fd2, interrupter_pid2) = run_interrupter (Some 10) in let interrupt = { MultiThreadedCall.handlers = configure_handlers interrupt_fd1 interrupt_fd2; env = (0, 0) (* counting number of times interrupt handlers ran *); } in let ((), (x, y), unfinished_and_reason) = MultiWorker.call_with_interrupt workers ~job:do_work ~merge ~neutral:() ~next ~interrupt in let (_ : int * Unix.process_status) = Unix.waitpid [] interrupter_pid1 in let (_ : int * Unix.process_status) = Unix.waitpid [] interrupter_pid2 in assert (x = 3); assert (y = 4); assert (Option.is_none unfinished_and_reason); true let () = Daemon.check_entry_point (); try_finalize Unit_test.run_all [("test_interrupt_handler", test_interrupt_handler)] cleanup ()
OCaml
hhvm/hphp/hack/test/procs/test_nested_multi_worker.ml
open Procs_test_utils exception MultiWorkerException (* A "regular" multi worker job where workers concatenate "a"-s together. * If ~fail_inner is true, the workers will die with an error. *) let multi_worker_inner workers ~fail_inner = let counter = ref 0 in let next () = incr counter; if !counter < 20 then Bucket.Job "a" else Bucket.Done in let concat acc x = if fail_inner then exit 3; acc ^ x in let result = MultiWorker.call (Some workers) ~job:concat ~merge:( ^ ) ~neutral:"" ~next in Printf.printf "Got %s\n" result; assert (result = "aaaaaaaaaaaaaaaaaaa") (* An interruptible job that will also run multi_worker_inner in the middle of * call_with_interrupt *) let multi_worker_nested workers ?(fail_inner = false) () = (* Custom next() function - keeps producing jobs until number of produced * buckets (counter) is bigger than finish_at *) let counter = ref 0 in let finish_at = ref None in let is_finished () = match !finish_at with | Some x when x > !counter -> true | _ -> false in let next () = if is_finished () then Bucket.Done else Bucket.Job (incr counter) in (* interrupting process - wakes up every second until killed *) let (interrupt_fd1, interrupter_pid1) = run_interrupter None in let kill_interrupter () = Unix.kill interrupter_pid1 Sys.sigkill in (* After processing 100 buckets, perform a nested job, and then process 100 * more buckets to see if the workers are healthy afterwards *) let interrupt_handler fd () = let () = read_exclamation_mark fd in if !counter > 100 then ( (try multi_worker_inner workers ~fail_inner with | _ -> (* Try to ignore the exception that will be thrown when fail_inner is * true - it should be re-raised for the main job anyway *) ()); finish_at := Some (!counter + 100) ); ((), MultiThreadedCall.Continue) in (* The work is just to count amount of buckets processed *) let do_work acc () = acc + 1 in let (result, (), _) = try MultiWorker.call_with_interrupt (Some workers) ~job:do_work ~merge:( + ) ~neutral:0 ~next ~interrupt: { MultiThreadedCall.handlers = (fun () -> [(interrupt_fd1, interrupt_handler interrupt_fd1)]); env = (); } with (* The mechanism to create Coalesced_failures is too flaky to count on it * in tests *) (* MultiThreadedCall.Coalesced_failures *) | _ -> kill_interrupter (); raise MultiWorkerException in kill_interrupter (); result = !counter let multi_worker_nested_exn workers () = let did_throw = ref false in (try assert (multi_worker_nested workers ~fail_inner:true ()) with | MultiWorkerException -> did_throw := true); !did_throw let multi_worker_nested = multi_worker_nested ~fail_inner:false let tests = [ ("multi_worker_nested", multi_worker_nested); ("multi_worker_nested_exn", multi_worker_nested_exn); ] let () = Daemon.check_entry_point (); let workers = make_workers 10 in try_finalize Unit_test.run_all (List.map (fun (n, t) -> (n, t workers)) tests) cleanup ()
PHP
hhvm/hphp/hack/test/quickfixes/add_null_safe_get_method_1.php
<?hh class Thing { public method(): void {} } function foo(): void { if (1 < 2) { $thing = new Thing(); } else { $thing = null; } $thing->method(); }
PHP
hhvm/hphp/hack/test/quickfixes/add_null_safe_get_method_2.php
<?hh class Thing { public method(): void {} } function foo(): void { if (1 < 2) { $thing = new Thing(); } else { $thing = null; } // we don't provide the quickfix because // it's hard to find the arrow location $thing -> method(); }
PHP
hhvm/hphp/hack/test/quickfixes/add_null_safe_get_prop_1.php
<?hh class Thing { public int $value = 3; } function foo(): void { if (1 < 2) { $thing = new Thing(); } else { $thing = null; } $thing->value; }
PHP
hhvm/hphp/hack/test/quickfixes/add_null_safe_get_prop_2.php
<?hh class Thing { public int $value = 3; } function foo(): void { if (1 < 2) { $thing = new Thing(); } else { $thing = null; } // A newline before a property access is rare. // We currently produce an ill-formatted quickfix in such cases because of a lie // about positions in typing_subtype. $thing -> value; }
PHP
hhvm/hphp/hack/test/quickfixes/bad_abstract_static.php
<?hh abstract class MyClass { abstract public static function childImplements(): void; public static function foo(): void { self::childImplements(); } }
PHP
hhvm/hphp/hack/test/quickfixes/bad_method.php
<?hh class Foo { public function instanceMeth(): void {} public static function staticMeth(int $_): void {} } function takes_foo(Foo $f): void { $f->instanceMethOops(); Foo::staticMethOops("stuff"); }
hhvm/hphp/hack/test/quickfixes/dune
(rule (alias quickfixes) (deps %{exe:../../src/hh_single_type_check.exe} %{project_root}/hack/test/verify.py %{project_root}/hack/test/review.sh (glob_files %{project_root}/hack/test/quickfixes/HH_FLAGS) (glob_files %{project_root}/hack/test/quickfixes/*.php) (glob_files %{project_root}/hack/test/quickfixes/*.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/quickfixes --program %{exe:../../src/hh_single_type_check.exe} --flags --fix))) (alias (name runtest) (deps (alias quickfixes)))
PHP
hhvm/hphp/hack/test/quickfixes/dynamic_property_access.php
<?hh class MyClass { public function __construct(public int $x) {} public function getX(): int { // Ensure $x exists, so we only get an error about dynamic method // access. $x = 'whatever'; return $this->$x; } }
PHP
hhvm/hphp/hack/test/quickfixes/expr_tree_forgot_to_splice.php
<?hh function f(int $num): void { DSL`$num + 1`; DSL`{ $NUM = 1; return $nuM + 1; }`; }
PHP
hhvm/hphp/hack/test/quickfixes/fix_misspelled_attribute.php
<?hh class MyParent { public function foo(): void {} } class MyChild extends MyParent { <<__Overide>> public function foo(): void {} }
PHP
hhvm/hphp/hack/test/quickfixes/fun_call_missing_readonly.php
<?hh class Foo { } function returns_readonly(): readonly Foo { return new Foo(); } function call_it(): void { $ro = returns_readonly(); }
PHP
hhvm/hphp/hack/test/quickfixes/missing_enum_label_in_call.php
<?hh enum class E: mixed { int A = 42; } function takes_label(HH\EnumClass\Label<E, int> $_): void {} function call_it(): void { takes_label(#B); }
PHP
hhvm/hphp/hack/test/quickfixes/missing_inout_type_annotation.php
<?hh function takes_param(inout int $x): void {} function call_it(): void { $x = 1; takes_param($x); }
PHP
hhvm/hphp/hack/test/quickfixes/missing_inout_with_fixme.php
<?hh function takes_param(inout int $x): void {} function call_it(): void { $x = 1; /* HH_FIXME[4182] quickfix should still work on next line */ takes_param($x); }
PHP
hhvm/hphp/hack/test/quickfixes/missing_method.php
<?hh interface IFoo { public function bar(): void; public function baz(): void; } class Foo implements IFoo { public function otherMethod(): void {} }
PHP
hhvm/hphp/hack/test/quickfixes/missing_method_anon_namespace.php
<?hh namespace { interface IFoo { public function bar(): void; } class Foo implements IFoo {} }
PHP
hhvm/hphp/hack/test/quickfixes/missing_method_async.php
<?hh interface IFoo { public function genBar(): Awaitable<int>; } class Foo implements IFoo { public function otherMethod(): void {} }
PHP
hhvm/hphp/hack/test/quickfixes/missing_method_class.php
<?hh abstract class FooParent { abstract public function bar(): void; abstract public function baz(): void; } class Foo extends FooParent {}
PHP
hhvm/hphp/hack/test/quickfixes/missing_method_contexts.php
<?hh abstract class FooParent { abstract public function explicitCapabilityMethods()[globals, write_props]: int; } class Foo extends FooParent {}
PHP
hhvm/hphp/hack/test/quickfixes/missing_method_multiple_ancestors.php
<?hh abstract class MyGrandParent { abstract public function methodInGrandParent(): void; } abstract class MyParent extends MyGrandParent { abstract public function methodInParent(): void; } trait MyTrait { abstract public function methodInTrait(): void; } class MyClass extends MyParent { use MyTrait; }
PHP
hhvm/hphp/hack/test/quickfixes/missing_method_namespace.php
<?hh namespace Foo { interface IFoo { public function bar(): void; } class Foo implements IFoo {} }
PHP
hhvm/hphp/hack/test/quickfixes/missing_method_namespace_stmt.php
<?hh namespace Bar; interface IFoo { public function bar(): void; } class Foo implements IFoo {}
PHP
hhvm/hphp/hack/test/quickfixes/missing_method_pure.php
<?hh abstract class FooParent { abstract public function somePureMethod()[]: int; } class Foo extends FooParent {}
PHP
hhvm/hphp/hack/test/quickfixes/missing_method_trait.php
<?hh trait FooTrait { abstract public function bar(): void; abstract public function baz(): void; } class Foo { use FooTrait; }
PHP
hhvm/hphp/hack/test/quickfixes/missing_method_types.php
<?hh interface IFoo { public function bar<T>(int $x, shape('y' => vec<int>) $s, shape(...) $_, IFoo $other, dynamic $d, mixed $m, (float, num) $tuple, T $t, Vector<null> $v, ?arraykey $ak, nothing $_, ?nonnull $_, int ...$args): void; } class Foo implements IFoo { public function otherMethod(): void {} }
PHP
hhvm/hphp/hack/test/quickfixes/missing_shape_field.php
<?hh function takes_s(shape('x' => float, 'y' => string) $_): void {} function foo(): void { takes_s(shape('x' => 1.0)); }
PHP
hhvm/hphp/hack/test/quickfixes/missing_static_async_method.php
<?hh abstract class MyClass { abstract public static function foo(): Awaitable<void>; } class MyChild extends MyClass { }
PHP
hhvm/hphp/hack/test/quickfixes/missing_static_method.php
<?hh interface IFoo { public static function bar(): void; } class Foo implements IFoo { public function other(): void {} }
PHP
hhvm/hphp/hack/test/quickfixes/non-existent-type-const-name-in-params.php
class MyClass { const type TFooBar = int; public function foo(this::TFooBaz $_) { throw new Exception(); } }
PHP
hhvm/hphp/hack/test/quickfixes/non-existent-type-const-names.php
<?hh class MyClass { const type TFooBar = int; const type TFoo = int; public function foo(): MyClass::TFooBaz { throw new Exception(); } }
PHP
hhvm/hphp/hack/test/quickfixes/switch_case_missing_fallthrough_comment.php
<?hh enum MyEnum: int { X = 1; Y = 2; Z = 3; } function foo(MyEnum $me): bool { switch ($me) { case MyEnum::X: return true; case MyEnum::Y: echo ""; case MyEnum::Z: return false; } }
PHP
hhvm/hphp/hack/test/quickfixes/unexpected_inout_type_annotation.php
<?hh function takes_param(int $x): void {} function call_it(): void { $x = 1; takes_param(inout $x); }
PHP
hhvm/hphp/hack/test/quickfix_lint/nested_quickfix.php
<?hh // Currently, the quickfix applying tool cannot handle, nested patches, so it // drops the one that encloses the other. function nested_quickfix(): void { (float) ((float) 42.0 + (float) 24.0); }
PHP
hhvm/hphp/hack/test/quickfix_lint/no_quickfix.php
<?hh // This test is for the quickfix applying tool itself rather than for a // particular quickfix. When there is a lint with no quickfix, we should drop // it, but report that it is dropped. function main(): void {}
PHP
hhvm/hphp/hack/test/quickfix_lint/redundant_as.php
<?hh class C {} class D extends C {} function redundant_as(D $d): void { $d as C; } function non_redundant_as(C $c): void { $c as D; }
PHP
hhvm/hphp/hack/test/quickfix_lint/redundant_as2.php
<?hh function redundant_as2(int $i): void { $i as nonnull; // redundant $i = 1 === 2 ? $i : null; $i as nonnull; // essential $i as nonnull; // redundant }
PHP
hhvm/hphp/hack/test/quickfix_lint/redundant_cast.php
<?hh function redundant_cast(int $i, string $s, float $f, bool $b): void { (bool) $b; (float) $f; (string) $s; (int) $i; }
PHP
hhvm/hphp/hack/test/quickfix_lint/redundant_unsafe_cast.php
<?hh function takes_arraykey(arraykey $_) : void {} function redundant_cast(arraykey $a, int $i): void { takes_arraykey(HH\FIXME\UNSAFE_CAST<mixed, arraykey>($a)); takes_arraykey(HH\FIXME\UNSAFE_CAST<mixed, arraykey>($i)); }
PHP
hhvm/hphp/hack/test/quickfix_lint/redundant_unsafe_nonnull_cast.php
<?hh function redundant_unsafe_casts(?string $str): void { HH\FIXME\UNSAFE_NONNULL_CAST($str); // Not redundant $str as nonnull; HH\FIXME\UNSAFE_NONNULL_CAST($str); // Redundant }
Shell Script
hhvm/hphp/hack/test/quickfix_lint/run.sh
#!/usr/bin/env bash OTHER_ARGS=() while (( "$#" )); do case "$1" in --hhstc-path) HHSTC=$2; shift 2;; --hh-quickfix-lint-path) QUICKFIX_LINT=$2; shift 2;; *) OTHER_ARGS+=("$1"); shift;; esac done set -- "${OTHER_ARGS[@]}" FILE=$1; shift; "$HHSTC" --lint-json "$FILE" "$@" | "$QUICKFIX_LINT"
PHP
hhvm/hphp/hack/test/quickfix_lint/sound_dynamic/redundant_cast.php
<?hh class Box<T> { public function __construct(private T $val): void {} public function getVal(): T { return $this->val; } } <<__SupportDynamicType>> function not_sure_if_redundant_cast(Box<float> $box): void { (float) $box->getVal(); } function redundant_cast(Box<float> $box): void { (float) $box->getVal(); }
PHP
hhvm/hphp/hack/test/quickfix_lint/sound_dynamic/redundant_cast2.php
<?hh <<__SupportDynamicType>> function map<T>(T $_, (function(T): void) $_): void {} <<__SupportDynamicType>> function main1(): void { map(42.0, $f ==> { (float) $f; }); } <<__SupportDynamicType>> function main2(): void { map(42.0, (float $f) ==> { (float) $f; }); }
PHP
hhvm/hphp/hack/test/quickfix_lint/sound_dynamic/redundant_cast3.php
<?hh <<__SupportDynamicType>> function main1(float $f): void { (float) $f; } type Wrap<T> = T; <<__SupportDynamicType>> function main2(Wrap<float> $wf): void { (float) $wf; } <<__SupportDynamicType>> function main3(vec<int> $_): void { (float) 42.0; }