From 9f31715a474147cf722e5f851217aaf9fc89db60 Mon Sep 17 00:00:00 2001 From: adelaett <90894311+adelaett@users.noreply.github.com> Date: Wed, 22 Feb 2023 12:11:42 +0100 Subject: [PATCH] style --- compiler/desugared/disambiguate.ml | 6 +++--- compiler/desugared/from_surface.ml | 5 +++-- compiler/shared_ast/expr.ml | 3 +-- compiler/shared_ast/typing.ml | 12 ++++++------ tests/README.md | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/compiler/desugared/disambiguate.ml b/compiler/desugared/disambiguate.ml index 44ea094c..cc630095 100644 --- a/compiler/desugared/disambiguate.ml +++ b/compiler/desugared/disambiguate.ml @@ -29,9 +29,9 @@ let rule ctx env rule = let env = match rule.rule_parameter with | None -> env - | Some l -> - let vs, tys = List.split l in - ListLabels.fold_right2 vs tys ~init:env ~f:Typing.Env.add_var + | Some vars_and_types -> + ListLabels.fold_right vars_and_types ~init:env ~f:(fun (v, t) -> + Typing.Env.add_var v t) in (* Note: we could use the known rule type here to direct typing. We choose not to because it shouldn't be needed for disambiguation, and we prefer to diff --git a/compiler/desugared/from_surface.ml b/compiler/desugared/from_surface.ml index 5b089e9f..a5790dca 100644 --- a/compiler/desugared/from_surface.ml +++ b/compiler/desugared/from_surface.ml @@ -1205,8 +1205,9 @@ let process_topdef (Marked.get_mark def.S.topdef_name) in let typ = - if List.length arg_types = 0 then body_type - else TArrow (arg_types, body_type), ty_pos + match arg_types with + | [] -> body_type + | _ -> TArrow (arg_types, body_type), ty_pos in { prgm with diff --git a/compiler/shared_ast/expr.ml b/compiler/shared_ast/expr.ml index b781cb71..c6d843f5 100644 --- a/compiler/shared_ast/expr.ml +++ b/compiler/shared_ast/expr.ml @@ -727,8 +727,7 @@ let make_app e args pos = | fty :: argtys -> ( match Marked.unmark fty.ty with | TArrow (tx', tr) -> - assert ( - argtys |> List.map (fun x -> x.ty) |> Type.unifiable_list tx'); + assert (Type.unifiable_list tx' (List.map (fun x -> x.ty) argtys)); tr | TAny -> fty.ty | _ -> assert false)) diff --git a/compiler/shared_ast/typing.ml b/compiler/shared_ast/typing.ml index 5a66f399..7f72d052 100644 --- a/compiler/shared_ast/typing.ml +++ b/compiler/shared_ast/typing.ml @@ -155,13 +155,13 @@ let rec unify let () = match Marked.unmark t1_repr, Marked.unmark t2_repr with | TLit tl1, TLit tl2 -> if tl1 <> tl2 then raise_type_error () - | TArrow (t11, t12), TArrow (t21, t22) -> + | TArrow (t11, t12), TArrow (t21, t22) -> ( unify e t12 t22; - if List.length t11 = List.length t21 then List.iter2 (unify e) t11 t21 - else raise_type_error () - | TTuple ts1, TTuple ts2 -> - if List.length ts1 = List.length ts2 then List.iter2 (unify e) ts1 ts2 - else raise_type_error () + try List.iter2 (unify e) t11 t21 + with Invalid_argument _ -> raise_type_error ()) + | TTuple ts1, TTuple ts2 -> ( + try List.iter2 (unify e) ts1 ts2 + with Invalid_argument _ -> raise_type_error ()) | TStruct s1, TStruct s2 -> if not (A.StructName.equal s1 s2) then raise_type_error () | TEnum e1, TEnum e2 -> diff --git a/tests/README.md b/tests/README.md index 290db0b6..60154668 100644 --- a/tests/README.md +++ b/tests/README.md @@ -48,12 +48,12 @@ If a compiler change causes a lot of regressions (error message formatting chang for instance), you can mass-reset the expected outputs with `make test_suite CLERK_OPTS=--reset`. `git diff` will then allow to check all the changes at once. -**Caution**: It's your responsibility to check all the changes before committing them. +**Caution**: It's your responsability to check all the changes before committing them. ## Tips * Running a single test-file just to check changes when tweaking either the compiler or the test file itself, but without updating or diffing with the reference can be useful when debugging. The following command outputs the result to `stdout` and can be used from within text editors: clerk runtest test-file.catala_en - # Or, to use the current build artifacts, wrap with `dune exec`: + # Or, to use the current build artefacts, wrap with `dune exec`: dune exec --display=quiet --no-build -- clerk runtest -e dune -c "exec --display=quiet --no-build -- catala" test-file.catala_en