mirror of
https://github.com/CatalaLang/catala.git
synced 2024-09-19 16:28:12 +03:00
Apply suggestions by @altgr
This commit is contained in:
parent
e80143b3ca
commit
d147238088
@ -35,8 +35,8 @@ let detect_empty_definitions (p : program) : unit =
|
||||
then
|
||||
Errors.format_spanned_warning
|
||||
(ScopeDef.get_position scope_def_key)
|
||||
"In scope in scope %a, the variable %a is declared but never \
|
||||
defined; did you forget something?"
|
||||
"In scope %a, the variable %a is declared but never defined; did \
|
||||
you forget something?"
|
||||
(Cli.format_with_style [ANSITerminal.yellow])
|
||||
(Format.asprintf "\"%a\"" ScopeName.format_t scope_name)
|
||||
(Cli.format_with_style [ANSITerminal.yellow])
|
||||
@ -52,7 +52,7 @@ let detect_unused_scope_vars (p : program) : unit =
|
||||
match Marked.unmark e with
|
||||
| ELocation (DesugaredScopeVar (v, _)) ->
|
||||
ScopeVar.Set.add (Marked.unmark v) used_scope_vars
|
||||
| _ -> Expr.deep_fold used_scope_vars_expr e used_scope_vars
|
||||
| _ -> Expr.shallow_fold used_scope_vars_expr e used_scope_vars
|
||||
in
|
||||
used_scope_vars_expr e used_scope_vars)
|
||||
~init:ScopeVar.Set.empty p
|
||||
@ -96,7 +96,7 @@ let detect_unused_struct_fields (p : program) : unit =
|
||||
StructField.Set.add field
|
||||
(structs_fields_used_expr e_field struct_fields_used))
|
||||
fields struct_fields_used
|
||||
| _ -> Expr.deep_fold structs_fields_used_expr e struct_fields_used
|
||||
| _ -> Expr.shallow_fold structs_fields_used_expr e struct_fields_used
|
||||
in
|
||||
structs_fields_used_expr e struct_fields_used)
|
||||
~init:StructField.Set.empty p
|
||||
@ -161,7 +161,8 @@ let detect_unused_enum_constructors (p : program) : unit =
|
||||
(enum_constructors_used_expr e_cons enum_constructors_used))
|
||||
cases enum_constructors_used
|
||||
| _ ->
|
||||
Expr.deep_fold enum_constructors_used_expr e enum_constructors_used
|
||||
Expr.shallow_fold enum_constructors_used_expr e
|
||||
enum_constructors_used
|
||||
in
|
||||
enum_constructors_used_expr e enum_constructors_used)
|
||||
~init:EnumConstructor.Set.empty p
|
||||
|
@ -262,7 +262,9 @@ let shallow_fold
|
||||
| ELit _ | EOp _ | EVar _ | ERaise _ | ELocation _ -> acc
|
||||
| EApp { f = e; args } -> acc |> f e |> lfold args
|
||||
| EArray args -> acc |> lfold args
|
||||
| EAbs _ -> acc
|
||||
| EAbs { binder; tys = _ } ->
|
||||
let _, body = Bindlib.unmbind binder in
|
||||
acc |> f body
|
||||
| EIfThenElse { cond; etrue; efalse } -> acc |> f cond |> f etrue |> f efalse
|
||||
| ETuple args -> acc |> lfold args
|
||||
| ETupleAccess { e; _ } -> acc |> f e
|
||||
@ -278,19 +280,6 @@ let shallow_fold
|
||||
acc |> f e |> EnumConstructor.Map.fold (fun _ -> f) cases
|
||||
| EScopeCall { args; _ } -> acc |> ScopeVar.Map.fold (fun _ -> f) args
|
||||
|
||||
(* Folds the given function on the direct children of the given expression. Open
|
||||
binders. *)
|
||||
let deep_fold
|
||||
(type a)
|
||||
(f : (a, 'm) gexpr -> 'acc -> 'acc)
|
||||
(e : (a, 'm) gexpr)
|
||||
(acc : 'acc) : 'acc =
|
||||
match Marked.unmark e with
|
||||
| EAbs { binder; tys = _ } ->
|
||||
let _, body = Bindlib.unmbind binder in
|
||||
acc |> f body
|
||||
| _ -> shallow_fold f e acc
|
||||
|
||||
(* Like [map], but also allows to gather a result bottom-up. *)
|
||||
let map_gather
|
||||
(type a)
|
||||
|
@ -210,9 +210,9 @@ val map_marks : f:('t1 -> 't2) -> ('a, 't1) gexpr -> ('a, 't2) boxed_gexpr
|
||||
val shallow_fold :
|
||||
(('a, 't) gexpr -> 'acc -> 'acc) -> ('a, 't) gexpr -> 'acc -> 'acc
|
||||
(** Applies a function on all sub-terms of the given expression. Does not
|
||||
recurse, and doesn't open binders. Useful as helper for recursive calls
|
||||
within traversal functions. This can be used to compute free variables with
|
||||
e.g.:
|
||||
recurse. It opens binders unless you avoid sending binders to the function
|
||||
like the example below. Useful as helper for recursive calls within
|
||||
traversal functions. This can be used to compute free variables with e.g.:
|
||||
|
||||
{[
|
||||
let rec free_vars = function
|
||||
@ -224,10 +224,6 @@ val shallow_fold :
|
||||
shallow_fold (fun e -> Var.Set.union (free_vars e)) e Var.Set.empty
|
||||
]} *)
|
||||
|
||||
val deep_fold :
|
||||
(('a, 't) gexpr -> 'acc -> 'acc) -> ('a, 't) gexpr -> 'acc -> 'acc
|
||||
(** Same as [shallow_fold] but opens binders. *)
|
||||
|
||||
val map_gather :
|
||||
acc:'acc ->
|
||||
join:('acc -> 'acc -> 'acc) ->
|
||||
|
@ -249,7 +249,7 @@ $ catala Interpret -s Exemple1 --disable_warnings
|
||||
|
||||
```catala-test-inline
|
||||
$ catala Typecheck
|
||||
[WARNING] In scope in scope "RessourcesAidesPersonnelleLogement", the variable "ressources_ménage_arrondies.seuil" is declared but never defined; did you forget something?
|
||||
[WARNING] In scope "RessourcesAidesPersonnelleLogement", the variable "ressources_ménage_arrondies.seuil" is declared but never defined; did you forget something?
|
||||
|
||||
┌─⯈ examples/aides_logement/tests/../prologue.catala_fr:496.9-14:
|
||||
└───┐
|
||||
@ -258,7 +258,7 @@ $ catala Typecheck
|
||||
└┬ Prologue : aides au logement
|
||||
└┬ Déclarations des champs d'application
|
||||
└─ Prise en compte des ressources pour les aides personnelles au logement
|
||||
[WARNING] In scope in scope "RessourcesAidesPersonnelleLogement", the variable "ressources_forfaitaires_r822_20" is declared but never defined; did you forget something?
|
||||
[WARNING] In scope "RessourcesAidesPersonnelleLogement", the variable "ressources_forfaitaires_r822_20" is declared but never defined; did you forget something?
|
||||
|
||||
┌─⯈ examples/aides_logement/tests/../prologue.catala_fr:504.10-41:
|
||||
└───┐
|
||||
|
@ -7,7 +7,7 @@ declaration scope Foo2:
|
||||
|
||||
```catala-test-inline
|
||||
$ catala Scalc -s Foo2 -O -t
|
||||
[WARNING] In scope in scope "Foo2", the variable "bar" is declared but never defined; did you forget something?
|
||||
[WARNING] In scope "Foo2", the variable "bar" is declared but never defined; did you forget something?
|
||||
|
||||
┌─⯈ tests/test_scope/good/nothing.catala_en:5.9-12:
|
||||
└─┐
|
||||
|
Loading…
Reference in New Issue
Block a user