Skip to content

Commit a66d757

Browse files
alanechangccasin
andauthored
Add [@layout_poly] attribute for layout representation polymorphic externals (oxcaml#2229)
* wip fix printing remove Repr_poly from lambda add comments proper jkind reason test update fix typo produce correct error check repr attr earlier and use get_unboxed_type_approximation make more primitives work with non value layout format fix upstream flambda2 only rename tests tests code cleanup more cleanup and an extra test add additional checks around array primitives * remove paren * add test when type constructor constrains layout * rename is_lambda_prim to is_builtin_prim * test&comment about No_native_primitive_with_non_value and Old_style_float_with_non_value * revert indentation change to reduce diff * make ml/mli def of description_gen consistent * fix long lines * comment on make_prim_repr_args * fix module tests * rework jkind checks * add comment on extern_repr * move make_prim_repr_args comment to mli * more comments * prim_is_layout_representation_polymorphic rename * add test about non-explicitly quantify tvars * update type_sort_external comment * test update * rename to layout_poly and improve error messages * fix format * make the repr checks stronger * rename test files * register layout_poly in Builtin_attributes * improve documentation * code cleanup & rename * more tests for instance_prim * more documentation and tests around the jkind check * Formatting and minor edits in comments * make unused layout_poly an error * update error message * fix upstream build and bootstrap --------- Co-authored-by: Chris Casinghino <[email protected]>
1 parent 25dd149 commit a66d757

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1791
-222
lines changed

middle_end/flambda2/from_lambda/closure_conversion.ml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,16 @@ let close_c_call acc env ~loc ~let_bound_ids_with_kinds
450450
prim_coeffects;
451451
prim_native_name;
452452
prim_native_repr_args;
453-
prim_native_repr_res
453+
prim_native_repr_res;
454+
prim_is_layout_poly
454455
} :
455-
Primitive.description) as prim_desc) ~(args : Simple.t list list)
456-
exn_continuation dbg ~current_region
456+
Lambda.external_call_description) as prim_desc)
457+
~(args : Simple.t list list) exn_continuation dbg ~current_region
457458
(k : Acc.t -> Named.t list -> Expr_with_acc.t) : Expr_with_acc.t =
459+
if prim_is_layout_poly
460+
then
461+
Misc.fatal_errorf
462+
"close_c_call: C call primitive %s can't be layout polymorphic." prim_name;
458463
let args =
459464
List.map
460465
(function
@@ -529,8 +534,8 @@ let close_c_call acc env ~loc ~let_bound_ids_with_kinds
529534
Apply_cont_expr.continuation apply_cont, false
530535
| _ -> Continuation.create (), true
531536
in
532-
let kind_of_primitive_native_repr
533-
((_, repr) : Primitive.mode * Primitive.native_repr) =
537+
let kind_of_primitive_extern_repr
538+
((_, repr) : Primitive.mode * Lambda.extern_repr) =
534539
match repr with
535540
| Same_as_ocaml_repr sort ->
536541
K.With_subkind.(
@@ -548,11 +553,11 @@ let close_c_call acc env ~loc ~let_bound_ids_with_kinds
548553
| Unboxed_vector (Pvec128 _) -> K.naked_vec128
549554
in
550555
let param_arity =
551-
List.map kind_of_primitive_native_repr prim_native_repr_args
556+
List.map kind_of_primitive_extern_repr prim_native_repr_args
552557
|> List.map K.With_subkind.anything
553558
|> Flambda_arity.create_singletons
554559
in
555-
let return_kind = kind_of_primitive_native_repr prim_native_repr_res in
560+
let return_kind = kind_of_primitive_extern_repr prim_native_repr_res in
556561
let return_arity =
557562
Flambda_arity.create_singletons [K.With_subkind.anything return_kind]
558563
in
@@ -625,7 +630,7 @@ let close_c_call acc env ~loc ~let_bound_ids_with_kinds
625630
let call : Acc.t -> Expr_with_acc.t =
626631
List.fold_left2
627632
(fun (call : Simple.t list -> Acc.t -> Expr_with_acc.t) arg
628-
(arg_repr : Primitive.mode * Primitive.native_repr) ->
633+
(arg_repr : Primitive.mode * Lambda.extern_repr) ->
629634
let unbox_arg : P.unary_primitive option =
630635
match arg_repr with
631636
| _, Same_as_ocaml_repr _ -> None

middle_end/flambda2/from_lambda/dissect_letrec.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ let lsequence (lam1, lam2) =
171171
[@@ocaml.warning "-fragile-match"]
172172

173173
let caml_update_dummy_prim =
174-
Primitive.simple_on_values ~name:"caml_update_dummy" ~arity:2 ~alloc:true
174+
Lambda.simple_prim_on_values ~name:"caml_update_dummy" ~arity:2 ~alloc:true
175175

176176
let update_dummy var expr =
177177
Lprim (Pccall caml_update_dummy_prim, [Lvar var; expr], Loc_unknown)
@@ -570,7 +570,7 @@ let dissect_letrec ~bindings ~body ~free_vars_kind =
570570
| Normal _tag -> "caml_alloc_dummy"
571571
| Flat_float_record -> "caml_alloc_dummy_float"
572572
in
573-
let desc = Primitive.simple_on_values ~name:fn ~arity:1 ~alloc:true in
573+
let desc = Lambda.simple_prim_on_values ~name:fn ~arity:1 ~alloc:true in
574574
let size : lambda = Lconst (Const_base (Const_int size)) in
575575
id, Lprim (Pccall desc, [size], Loc_unknown))
576576
letrec.blocks

middle_end/flambda2/from_lambda/lambda_to_flambda.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ let transform_primitive env (prim : L.primitive) args loc =
302302
then
303303
let arity = 1 + num_dimensions in
304304
let name = "caml_ba_get_" ^ string_of_int num_dimensions in
305-
let desc = Primitive.simple_on_values ~name ~arity ~alloc:true in
305+
let desc = Lambda.simple_prim_on_values ~name ~arity ~alloc:true in
306306
Primitive (L.Pccall desc, args, loc)
307307
else
308308
Misc.fatal_errorf
@@ -319,7 +319,7 @@ let transform_primitive env (prim : L.primitive) args loc =
319319
then
320320
let arity = 2 + num_dimensions in
321321
let name = "caml_ba_set_" ^ string_of_int num_dimensions in
322-
let desc = Primitive.simple_on_values ~name ~arity ~alloc:true in
322+
let desc = Lambda.simple_prim_on_values ~name ~arity ~alloc:true in
323323
Primitive (L.Pccall desc, args, loc)
324324
else
325325
Misc.fatal_errorf

0 commit comments

Comments
 (0)