Skip to content
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

Add [@layout_poly] attribute for layout representation polymorphic externals #2229

Merged
merged 31 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
764fb9b
wip
alanechang Jan 11, 2024
f3edb0f
remove paren
alanechang Feb 7, 2024
cb556b5
add test when type constructor constrains layout
alanechang Feb 7, 2024
fbfcfff
rename is_lambda_prim to is_builtin_prim
alanechang Feb 8, 2024
d0aa0f5
test&comment about No_native_primitive_with_non_value and Old_style_f…
alanechang Feb 8, 2024
cdd961c
revert indentation change to reduce diff
alanechang Feb 8, 2024
b48299c
make ml/mli def of description_gen consistent
alanechang Feb 8, 2024
bf247f2
fix long lines
alanechang Feb 8, 2024
d202213
comment on make_prim_repr_args
alanechang Feb 8, 2024
daa6253
fix module tests
alanechang Feb 8, 2024
ec2c7f0
rework jkind checks
alanechang Feb 12, 2024
791f820
add comment on extern_repr
alanechang Feb 12, 2024
a1d7455
move make_prim_repr_args comment to mli
alanechang Feb 12, 2024
bdf0cd5
more comments
alanechang Feb 12, 2024
0ba1195
prim_is_layout_representation_polymorphic rename
alanechang Feb 12, 2024
2903843
add test about non-explicitly quantify tvars
alanechang Feb 12, 2024
071ec84
update type_sort_external comment
alanechang Feb 12, 2024
bd6d12f
test update
alanechang Feb 12, 2024
42d67c0
rename to layout_poly and improve error messages
alanechang Feb 12, 2024
e11083c
fix format
alanechang Feb 12, 2024
44dee8f
make the repr checks stronger
alanechang Feb 14, 2024
4efe6e1
rename test files
alanechang Feb 14, 2024
42d8375
register layout_poly in Builtin_attributes
alanechang Feb 21, 2024
2159a82
improve documentation
alanechang Feb 21, 2024
4470b55
code cleanup & rename
alanechang Feb 21, 2024
065db36
more tests for instance_prim
alanechang Feb 21, 2024
7a1c8fc
more documentation and tests around the jkind check
alanechang Feb 21, 2024
da9a0dc
Formatting and minor edits in comments
ccasin Feb 26, 2024
1843228
make unused layout_poly an error
alanechang Feb 26, 2024
b4faa52
update error message
alanechang Feb 26, 2024
2216b47
fix upstream build and bootstrap
alanechang Feb 26, 2024
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
21 changes: 13 additions & 8 deletions middle_end/flambda2/from_lambda/closure_conversion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,16 @@ let close_c_call acc env ~loc ~let_bound_ids_with_kinds
prim_coeffects;
prim_native_name;
prim_native_repr_args;
prim_native_repr_res
prim_native_repr_res;
prim_is_layout_poly
} :
Primitive.description) as prim_desc) ~(args : Simple.t list list)
exn_continuation dbg ~current_region
Lambda.external_call_description) as prim_desc)
~(args : Simple.t list list) exn_continuation dbg ~current_region
(k : Acc.t -> Named.t list -> Expr_with_acc.t) : Expr_with_acc.t =
if prim_is_layout_poly
then
Misc.fatal_errorf
"close_c_call: C call primitive %s can't be layout polymorphic." prim_name;
let args =
List.map
(function
Expand Down Expand Up @@ -529,8 +534,8 @@ let close_c_call acc env ~loc ~let_bound_ids_with_kinds
Apply_cont_expr.continuation apply_cont, false
| _ -> Continuation.create (), true
in
let kind_of_primitive_native_repr
((_, repr) : Primitive.mode * Primitive.native_repr) =
let kind_of_primitive_extern_repr
((_, repr) : Primitive.mode * Lambda.extern_repr) =
match repr with
| Same_as_ocaml_repr sort ->
K.With_subkind.(
Expand All @@ -548,11 +553,11 @@ let close_c_call acc env ~loc ~let_bound_ids_with_kinds
| Unboxed_vector (Pvec128 _) -> K.naked_vec128
in
let param_arity =
List.map kind_of_primitive_native_repr prim_native_repr_args
List.map kind_of_primitive_extern_repr prim_native_repr_args
|> List.map K.With_subkind.anything
|> Flambda_arity.create_singletons
in
let return_kind = kind_of_primitive_native_repr prim_native_repr_res in
let return_kind = kind_of_primitive_extern_repr prim_native_repr_res in
let return_arity =
Flambda_arity.create_singletons [K.With_subkind.anything return_kind]
in
Expand Down Expand Up @@ -625,7 +630,7 @@ let close_c_call acc env ~loc ~let_bound_ids_with_kinds
let call : Acc.t -> Expr_with_acc.t =
List.fold_left2
(fun (call : Simple.t list -> Acc.t -> Expr_with_acc.t) arg
(arg_repr : Primitive.mode * Primitive.native_repr) ->
(arg_repr : Primitive.mode * Lambda.extern_repr) ->
let unbox_arg : P.unary_primitive option =
match arg_repr with
| _, Same_as_ocaml_repr _ -> None
Expand Down
4 changes: 2 additions & 2 deletions middle_end/flambda2/from_lambda/dissect_letrec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ let lsequence (lam1, lam2) =
[@@ocaml.warning "-fragile-match"]

let caml_update_dummy_prim =
Primitive.simple_on_values ~name:"caml_update_dummy" ~arity:2 ~alloc:true
Lambda.simple_prim_on_values ~name:"caml_update_dummy" ~arity:2 ~alloc:true

let update_dummy var expr =
Lprim (Pccall caml_update_dummy_prim, [Lvar var; expr], Loc_unknown)
Expand Down Expand Up @@ -570,7 +570,7 @@ let dissect_letrec ~bindings ~body ~free_vars_kind =
| Normal _tag -> "caml_alloc_dummy"
| Flat_float_record -> "caml_alloc_dummy_float"
in
let desc = Primitive.simple_on_values ~name:fn ~arity:1 ~alloc:true in
let desc = Lambda.simple_prim_on_values ~name:fn ~arity:1 ~alloc:true in
let size : lambda = Lconst (Const_base (Const_int size)) in
id, Lprim (Pccall desc, [size], Loc_unknown))
letrec.blocks
Expand Down
4 changes: 2 additions & 2 deletions middle_end/flambda2/from_lambda/lambda_to_flambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ let transform_primitive env (prim : L.primitive) args loc =
then
let arity = 1 + num_dimensions in
let name = "caml_ba_get_" ^ string_of_int num_dimensions in
let desc = Primitive.simple_on_values ~name ~arity ~alloc:true in
let desc = Lambda.simple_prim_on_values ~name ~arity ~alloc:true in
Primitive (L.Pccall desc, args, loc)
else
Misc.fatal_errorf
Expand All @@ -319,7 +319,7 @@ let transform_primitive env (prim : L.primitive) args loc =
then
let arity = 2 + num_dimensions in
let name = "caml_ba_set_" ^ string_of_int num_dimensions in
let desc = Primitive.simple_on_values ~name ~arity ~alloc:true in
let desc = Lambda.simple_prim_on_values ~name ~arity ~alloc:true in
Primitive (L.Pccall desc, args, loc)
else
Misc.fatal_errorf
Expand Down
Loading
Loading