Skip to content

Use the right kinds when building shapes for unboxed variants #2735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions middle_end/flambda2/simplify/unboxing/build_unboxing_denv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,11 @@ let rec denv_of_decision denv ~param_var (decision : U.decision) : DE.t =
Tag.Scannable.Map.map
(fun (shape, block_fields) ->
( shape,
List.map
(fun (field : U.field_decision) ->
T.alias_type_of K.value (Simple.var field.epa.param))
List.mapi
(fun i (field : U.field_decision) ->
T.alias_type_of
(K.Block_shape.element_kind shape i)
(Simple.var field.epa.param))
block_fields ))
fields_by_tag
in
Expand Down
28 changes: 28 additions & 0 deletions ocaml/testsuite/tests/mixed-blocks/variant_unboxing.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(* TEST
flags = "-extension layouts_beta";
native;
*)

(* Unboxing of variants with mixed constructors *)

type t =
| Const_t
| Boxed of Float.t

type u =
| Const_u
| Unboxed of float#

external unbox : float -> float# = "%unbox_float"

let t_to_u (t : t) : u =
match t with
| Const_t -> Const_u
| Boxed field -> Unboxed (unbox field)
;;

let f t =
(* The result of [t_to_u] is speculatively unboxed *)
let _ = t_to_u t in
()
;;
Loading