Skip to content

Commit

Permalink
Better names, and a comment
Browse files Browse the repository at this point in the history
  • Loading branch information
ccasin committed Apr 24, 2024
1 parent 40d3e9c commit 2f6afd7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
9 changes: 5 additions & 4 deletions ocaml/typing/typedtree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1036,17 +1036,18 @@ let rev_let_bound_idents_full bindings =
!idents_full
let let_bound_idents_with_modes_sorts_and_checks bindings =
let modes_and_sorts = Ident.Tbl.create 3 in
let modes_sorts_and_checks = Ident.Tbl.create 3 in
let f id sloc _ _uid mode sort =
Ident.Tbl.add modes_and_sorts id
Ident.Tbl.add modes_sorts_and_checks id
(sloc.loc, mode, sort, Builtin_attributes.Default_check)
in
List.iter (fun vb ->
iter_pattern_full ~both_sides_of_or:true f vb.vb_sort vb.vb_pat;
match vb.vb_pat.pat_desc, vb.vb_expr.exp_desc with
| Tpat_var (id, _, _, _), Texp_function fn ->
let (loc, mode, sort, _) = Ident.Tbl.find modes_and_sorts id in
Ident.Tbl.replace modes_and_sorts id (loc, mode, sort, fn.zero_alloc)
let (loc, mode, sort, _) = Ident.Tbl.find modes_sorts_and_checks id in
Ident.Tbl.replace modes_sorts_and_checks id
(loc, mode, sort, fn.zero_alloc)
| _ -> ()
)
bindings;
Expand Down
12 changes: 12 additions & 0 deletions ocaml/typing/typedtree.mli
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,18 @@ val exists_pattern: (pattern -> bool) -> pattern -> bool
val let_bound_idents: value_binding list -> Ident.t list
val let_bound_idents_full:
value_binding list -> (Ident.t * string loc * Types.type_expr * Uid.t) list

(* [let_bound_idents_with_modes_sorts_and_checks] finds all the idents in the
let bindings and computes their modes, sorts, and whether they have any check
attributes (zero_alloc).
Note that:
* The list associated with each ident can only have more than one element in
the case of or pattern, where the ident is bound on both sides.
* Check attributes are only supported in the case of a simple variable
pattern bound to a function ([Default_check] will be returned in all other
cases).
*)
val let_bound_idents_with_modes_sorts_and_checks:
value_binding list
-> (Ident.t * (Location.t * Mode.Value.l * Jkind.sort
Expand Down
8 changes: 4 additions & 4 deletions ocaml/typing/typemod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2795,7 +2795,7 @@ and type_structure ?(toplevel = None) funct_body anchor env sstr =
will be marked as being used during the signature inclusion test. *)
let items, shape_map =
List.fold_left
(fun (acc, shape_map) (id, modes) ->
(fun (acc, shape_map) (id, id_info) ->
List.iter
(fun (loc, mode, sort, _) ->
Typecore.escape ~loc ~env:newenv ~reason:Other mode;
Expand All @@ -2806,13 +2806,13 @@ and type_structure ?(toplevel = None) funct_body anchor env sstr =
then raise (Error (loc, env,
Toplevel_nonvalue (Ident.name id,sort)))
)
modes;
id_info;
let zero_alloc =
(* We only allow "Check" attributes in signatures. Here we
convert "Assume"s in structures to the equivalent "Check" for
the signature. *)
let open Builtin_attributes in
match[@warning "+9"] modes with
match[@warning "+9"] id_info with
| [(_, _, _, (Default_check | Ignore_assert_all _))] ->
Default_check
| [(_, _, _, (Check _ as zero_alloc))] -> zero_alloc
Expand All @@ -2821,7 +2821,7 @@ and type_structure ?(toplevel = None) funct_body anchor env sstr =
Check { strict; property; arity; loc; opt = false }
| _ -> Default_check
in
let (first_loc, _, _, _) = List.hd modes in
let (first_loc, _, _, _) = List.hd id_info in
Signature_names.check_value names first_loc id;
let vd = Env.find_value (Pident id) newenv in
let vd = Subst.Lazy.force_value_description vd in
Expand Down

0 comments on commit 2f6afd7

Please sign in to comment.