Skip to content

Commit

Permalink
Merge pull request #515 from hacspec/make-warning-7-an-error
Browse files Browse the repository at this point in the history
refactor(engine): enable OCaml warning `7`
  • Loading branch information
W95Psp authored Feb 19, 2024
2 parents f7c2d5a + d20ac7e commit 37ca073
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 38 deletions.
27 changes: 15 additions & 12 deletions engine/lib/analyses/mutable_variables.ml
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,21 @@ module%inlined_contents Make (F : Features.T) = struct
(* ~f:(fst >> super#visit_pat env))) *)
(* (Option.value_map (Map.find env var) ~default:m#zero ~f:(fun x -> (Set.of_list (module W) x, Map.empty (module LocalIdent)))) *)

method visit_Let env _monadic pat expr body =
let new_set, new_env = super#visit_expr env expr in
m#plus
(super#visit_expr
(m#snd#plus (m#snd#plus env new_env)
(Map.of_alist_exn
(module Local_ident)
(List.map
~f:(fun v -> (v, Set.to_list new_set))
(Set.to_list (U.Reducers.variables_of_pat pat)))))
body)
(new_set, m#snd#zero)
method! visit_expr' env e =
match e with
| Let { lhs = pat; rhs = expr; body; _ } ->
let new_set, new_env = super#visit_expr env expr in
m#plus
(super#visit_expr
(m#snd#plus (m#snd#plus env new_env)
(Map.of_alist_exn
(module Local_ident)
(List.map
~f:(fun v -> (v, Set.to_list new_set))
(Set.to_list (U.Reducers.variables_of_pat pat)))))
body)
(new_set, m#snd#zero)
| _ -> super#visit_expr' env e

method! visit_local_ident (env : W.t list Map.M(Local_ident).t) ident
=
Expand Down
16 changes: 8 additions & 8 deletions engine/lib/ast_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ module Make (F : Features.T) = struct
let regenerate_span_ids =
object
inherit [_] Visitors.map
method visit_span () = Span.refresh_id
method! visit_span () = Span.refresh_id
end

let normalize_borrow_mut =
Expand Down Expand Up @@ -344,10 +344,10 @@ module Make (F : Features.T) = struct
inherit [_] Visitors.reduce as super
inherit [_] Sets.Local_ident.monoid as _m

method visit_arm' env { arm_pat; body } =
method! visit_arm' env { arm_pat; body } =
shadows ~env [ arm_pat ] body super#visit_expr

method visit_expr' env e =
method! visit_expr' env e =
match e with
| Let { monadic = _; lhs; rhs; body } ->
super#visit_expr env rhs
Expand Down Expand Up @@ -378,12 +378,12 @@ module Make (F : Features.T) = struct
shadows ~env params body super#visit_expr
| _ -> super#visit_expr' env e

method visit_impl_item' env ii =
method! visit_impl_item' env ii =
match ii with
| IIFn { body; params } -> self#visit_function_like env body params
| _ -> super#visit_impl_item' env ii

method visit_item' env i =
method! visit_item' env i =
match i with
| Fn { body; params; _ } -> self#visit_function_like env body params
| _ -> super#visit_item' env i
Expand All @@ -392,7 +392,7 @@ module Make (F : Features.T) = struct
let f p = p.pat in
shadows ~env (List.map ~f params) body super#visit_expr

method visit_local_ident env id =
method! visit_local_ident env id =
Set.(if id_shadows ~env id then Fn.flip singleton id else empty)
(module Local_ident)
end
Expand Down Expand Up @@ -490,7 +490,7 @@ module Make (F : Features.T) = struct

(* TODO: loop state *)

method visit_expr' () e =
method! visit_expr' () e =
match e with
| Assign { lhs; e; _ } ->
let rec visit_lhs lhs =
Expand Down Expand Up @@ -531,7 +531,7 @@ module Make (F : Features.T) = struct
(without_vars (self#visit_expr () body) vars))
| _ -> super#visit_expr' () e

method visit_arm' () { arm_pat; body } =
method! visit_arm' () { arm_pat; body } =
without_pat_vars (self#visit_expr () body) arm_pat
end

Expand Down
2 changes: 1 addition & 1 deletion engine/lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@
(env
(_
(flags
(:standard -g -warn-error "+A" -w "-17-7-30-56-32"))))
(:standard -g -warn-error "+A" -w "-17-30-56-32"))))
6 changes: 3 additions & 3 deletions engine/lib/generic_printer/generic_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ module Make (F : Features.T) (View : Concrete_ident.VIEW_API) = struct
separate_map (comma ^^ break 1) (print#ty_at Ty_Tuple)
>> iblock parens

method ty : par_state -> ty fn =
method! ty : par_state -> ty fn =
fun ctx ty ->
match ty with
| TBool -> string "bool"
Expand All @@ -144,7 +144,7 @@ module Make (F : Features.T) (View : Concrete_ident.VIEW_API) = struct
| TOpaque _ -> string "opaque_type!()"
| TApp _ -> super#ty ctx ty

method expr' : par_state -> expr' fn =
method! expr' : par_state -> expr' fn =
fun ctx e ->
let wrap_parens =
group
Expand Down Expand Up @@ -321,7 +321,7 @@ module Make (F : Features.T) (View : Concrete_ident.VIEW_API) = struct

method attr : attr fn = fun _ -> empty

method pat' : par_state -> pat' fn =
method! pat' : par_state -> pat' fn =
fun ctx ->
let wrap_parens =
group
Expand Down
4 changes: 1 addition & 3 deletions engine/lib/phase_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ end = struct
let regenerate_span_ids =
(object
inherit [_] Visitors.map
method visit_t () x = x
method visit_mutability _ () m = m
method visit_span = Fn.const Span.refresh_id
method! visit_span = Fn.const Span.refresh_id
end)
#visit_item
()
Expand Down
24 changes: 13 additions & 11 deletions engine/lib/phases/phase_and_mut_defsite.ml
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ struct
let map_returns ~(f : expr -> expr) : expr -> expr =
let visitor =
object
inherit [_] Visitors.map as _super
method visit_t () x = x
method visit_mutability _ () m = m
method visit_Return () e witness = Return { e = f e; witness }
inherit [_] Visitors.map as super

method! visit_expr' () e =
match e with
| Return { e; witness } -> Return { e = f e; witness }
| _ -> super#visit_expr' () e
end
in
visitor#visit_expr ()
Expand Down Expand Up @@ -146,7 +148,7 @@ struct
object
inherit [_] Visitors.map as super

method visit_expr () e =
method! visit_expr () e =
(let* e = Expect.deref e in
retyped_local_var_in_vars e)
<|?> (fun _ -> retyped_local_var_in_vars e)
Expand Down Expand Up @@ -183,13 +185,13 @@ struct
object
inherit [_] Visitors.map as super

method visit_expr () e =
method! visit_expr () e =
try super#visit_expr () e
with Diagnostics.SpanFreeError.Exn (Data (context, kind)) ->
UB.hax_failure_expr e.span e.typ (context, kind)
(UB.LiftToFullAst.expr e)

method visit_expr' () e =
method! visit_expr' () e =
match e with
| Assign { lhs; e; witness } ->
let span = e.span in
Expand Down Expand Up @@ -243,7 +245,7 @@ struct
object
inherit [_] BVisitors.map as super

method visit_impl_item' () item' =
method! visit_impl_item' () item' =
(match item' with
| IIFn { params; body } ->
let* params, body = rewrite_function params body in
Expand All @@ -252,7 +254,7 @@ struct
|> Option.value_or_thunk
~default:(Fn.flip super#visit_impl_item' item')

method visit_trait_item () item =
method! visit_trait_item () item =
let span = item.ti_span in
let ti_v =
(match item.ti_v with
Expand Down Expand Up @@ -290,7 +292,7 @@ struct
in
{ item with ti_v }

method visit_item () i =
method! visit_item () i =
try super#visit_item () i
with Diagnostics.SpanFreeError.Exn (Data (context, kind)) ->
let error = Diagnostics.pretty_print_context_kind context kind in
Expand All @@ -301,7 +303,7 @@ struct
in
B.make_hax_error_item i.span i.ident msg

method visit_item' () item' =
method! visit_item' () item' =
(match item' with
| Fn { name; generics; body; params } ->
let* params, body = rewrite_function params body in
Expand Down

0 comments on commit 37ca073

Please sign in to comment.