Skip to content

Commit

Permalink
Apply coercions to both closure types and function declarations (#473)
Browse files Browse the repository at this point in the history
When applying a coercion to the type of a set of closures, we need to
update both the function declarations *and* the types of the closures.
  • Loading branch information
lukemaurer authored Jun 25, 2021
1 parent e9c60d4 commit 1ab581d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
12 changes: 12 additions & 0 deletions middle_end/flambda/types/structures/closures_entry.rec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,15 @@ let map_function_decl_types
}
in
Ok t

let map_closure_types
{ function_decls; closure_types; closure_var_types; }
~(f : Type_grammar.t -> Type_grammar.t Or_bottom.t) : _ Or_bottom.t =
let closure_types =
Product.Closure_id_indexed.map_types closure_types ~f
in
Or_bottom.map closure_types ~f:(fun closure_types ->
{ function_decls;
closure_types;
closure_var_types;
})
5 changes: 5 additions & 0 deletions middle_end/flambda/types/structures/closures_entry.rec.mli
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ val find_function_declaration

val closure_types : t -> Type_grammar.t Closure_id.Map.t

val map_closure_types
: t
-> f:(Type_grammar.t -> Type_grammar.t Or_bottom.t)
-> t Or_bottom.t

val function_decl_types : t -> Function_declaration_type.t Closure_id.Map.t

val closure_var_types : t -> Type_grammar.t Var_within_closure.Map.t
Expand Down
4 changes: 4 additions & 0 deletions middle_end/flambda/types/structures/row_like.rec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,10 @@ struct
map_maps_to t ~f:(fun closures_entry ->
Closures_entry.map_function_decl_types closures_entry ~f)

let map_closure_types t ~f =
map_maps_to t ~f:(fun closures_entry ->
Closures_entry.map_closure_types closures_entry ~f)

let create_exactly
(closure_id : Closure_id.t)
(contents : Set_of_closures_contents.t)
Expand Down
5 changes: 5 additions & 0 deletions middle_end/flambda/types/structures/row_like.rec.mli
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ module For_closures_entry_by_set_of_closures_contents : sig
-> f:(Function_declaration_type.t -> Function_declaration_type.t Or_bottom.t)
-> t Or_bottom.t

val map_closure_types
: t
-> f:(Type_grammar.t -> Type_grammar.t Or_bottom.t)
-> t Or_bottom.t

include Type_structure_intf.S
with type t := t
with type flambda_type := Type_grammar.t
Expand Down
26 changes: 19 additions & 7 deletions middle_end/flambda/types/type_of_kind/type_of_kind_value0.rec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,25 @@ let all_ids_for_export t =
let apply_coercion t coercion : _ Or_bottom.t =
match t with
| Closures { by_closure_id; } ->
Or_bottom.map
(Row_like.For_closures_entry_by_set_of_closures_contents.
map_function_decl_types
by_closure_id
~f:(fun (decl : Function_declaration_type.t) : _ Or_bottom.t ->
Function_declaration_type.apply_coercion decl coercion))
~f:(fun by_closure_id -> Closures { by_closure_id; })
begin match
Row_like.For_closures_entry_by_set_of_closures_contents.
map_function_decl_types
by_closure_id
~f:(fun (decl : Function_declaration_type.t) : _ Or_bottom.t ->
Function_declaration_type.apply_coercion decl coercion)
with
| Bottom -> Bottom
| Ok by_closure_id ->
match
Row_like.For_closures_entry_by_set_of_closures_contents.
map_closure_types
by_closure_id
~f:(fun ty -> Type_grammar.apply_coercion ty coercion)
with
| Bottom -> Bottom
| Ok by_closure_id ->
Ok (Closures { by_closure_id; })
end
| Variant _
| Boxed_float _
| Boxed_int32 _
Expand Down

0 comments on commit 1ab581d

Please sign in to comment.