@@ -685,11 +685,38 @@ and value_kind_mixed_block_field env ~loc ~visited ~depth ~num_nodes_visited
685685 | Word -> num_nodes_visited, Word
686686 | Untagged_immediate -> num_nodes_visited, Untagged_immediate
687687 | Product fs ->
688- let num_nodes_visited, kinds =
689- Array.fold_left_map (fun num_nodes_visited field ->
690- value_kind_mixed_block_field env ~loc ~visited ~depth ~num_nodes_visited
691- field None
692- ) num_nodes_visited fs
688+ let unknown () = Array.init (Array.length fs) (fun _ -> None) in
689+ let types =
690+ match ty with
691+ | None -> unknown ()
692+ | Some ty ->
693+ let ty = scrape_ty env ty in
694+ match get_desc ty with
695+ | Tunboxed_tuple fields ->
696+ Misc.Stdlib.Array.of_list_map (fun (_, field) -> Some field) fields
697+ | Tconstr(p, _, _) ->
698+ begin match (Env.find_type p env).type_kind with
699+ | exception Not_found -> unknown ()
700+ | Type_record_unboxed_product (lbls, _, _) ->
701+ Misc.Stdlib.Array.of_list_map (fun {Types.ld_type} -> Some ld_type)
702+ lbls
703+ | Type_variant _ | Type_record _ | Type_abstract _ | Type_open ->
704+ (* We don't need to handle [@@unboxed] records/variants here,
705+ because [scrape_ty] looks though them. *)
706+ unknown ()
707+ end
708+ | Tvar _ | Tarrow _ | Ttuple _ | Tobject _ | Tfield _ | Tnil
709+ | Tlink _ | Tsubst _ | Tvariant _ | Tunivar _ | Tpoly _ | Tpackage _
710+ | Tof_kind _ -> unknown ()
711+ in
712+ let (_, num_nodes_visited), kinds =
713+ Array.fold_left_map (fun (i, num_nodes_visited) field ->
714+ let num_nodes_visited, kind =
715+ value_kind_mixed_block_field env ~loc ~visited ~depth
716+ ~num_nodes_visited field types.(i)
717+ in
718+ (i + 1, num_nodes_visited), kind
719+ ) (0, num_nodes_visited) fs
693720 in
694721 num_nodes_visited, Product kinds
695722 | Void -> num_nodes_visited, Product [||]
@@ -931,6 +958,16 @@ let value_kind env loc ty =
931958 with
932959 | Missing_cmi_fallback -> raise (Error (loc, Non_value_layout (ty, None)))
933960
961+ let transl_mixed_block_element env loc ty mbe =
962+ try
963+ let (_num_nodes_visited, value_kind) =
964+ value_kind_mixed_block_field env ~loc ~visited:Numbers.Int.Set.empty
965+ ~depth:0 ~num_nodes_visited:0 mbe (Some ty)
966+ in
967+ value_kind
968+ with
969+ | Missing_cmi_fallback -> raise (Error (loc, Non_value_layout (ty, None)))
970+
934971let[@inline always] rec layout_of_const_sort_generic ~value_kind ~error
935972 : Jkind.Sort.Const.t -> _ = function
936973 | Base Value -> Lambda.Pvalue (Lazy.force value_kind)
0 commit comments