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

Support unboxed ints in mixed blocks #2515

Merged
merged 27 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8785b1c
start work
ncik-roberts Apr 30, 2024
616fa0a
Implement support
ncik-roberts Apr 30, 2024
2204bad
Broken attempt to type-check these
ncik-roberts Apr 30, 2024
0a5e876
Fix bugs
ncik-roberts Apr 30, 2024
3037bad
Gets off the ground
ncik-roberts Apr 30, 2024
afdd458
Generate new test cases
ncik-roberts Apr 30, 2024
b3f93f9
A bad attempt to make the testsuite better
ncik-roberts Apr 30, 2024
c2c6de8
Improve generated test
ncik-roberts May 1, 2024
2114432
Self-review
ncik-roberts May 1, 2024
b953951
Clean up unnecessary field
ncik-roberts May 1, 2024
0e6fdf0
Get some layouts tests working
ncik-roberts May 1, 2024
4449a56
Add some mixed block tests and fix bug
ncik-roberts May 1, 2024
df29a37
Move unboxed-float relevant mixed block tests back to typing-layouts-…
ncik-roberts May 1, 2024
adb5c60
Add tests for other kinds of mixed blocks
ncik-roberts May 1, 2024
47470f5
Flesh out constructor arg tests
ncik-roberts May 1, 2024
033e54e
Fix upstream build
ncik-roberts May 1, 2024
4a851c8
Mint separate mixed block shape type for flambda2 (#2530)
ncik-roberts May 3, 2024
0ff67b1
Ban void in mixed products (#2531)
ncik-roberts May 6, 2024
73e90b1
Flesh out constructor arg tests to have more combos of flat suffixes
ncik-roberts May 7, 2024
f9c3456
Review: fix comments; add case for disallowed value in flat suffix
ncik-roberts May 7, 2024
509bf18
Fix up both alpha and beta versions of tests according to review
ncik-roberts May 7, 2024
4fed4da
Review: add and clarify comments
ncik-roberts May 7, 2024
7708375
Remove stale comment (Max confirmed)
ncik-roberts May 7, 2024
f413f7d
Revert unintended change to test from review response
ncik-roberts May 7, 2024
9a26bbb
Disallow big-endian for now
ncik-roberts May 7, 2024
679b7b3
Update comment to clarify why it would be better to use mutability (o…
ncik-roberts May 7, 2024
ff57bdd
make fmt
ncik-roberts May 7, 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
Next Next commit
start work
  • Loading branch information
ncik-roberts committed May 6, 2024
commit 8785b1c6c6d11913065371965d1e15686a2127ba
18 changes: 10 additions & 8 deletions backend/cmm_helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ let caml_black = Nativeint.shift_left (Nativeint.of_int 3) 8

let caml_local =
Nativeint.shift_left (Nativeint.of_int (if Config.runtime5 then 3 else 2)) 8

(* cf. runtime/caml/gc.h *)

(* Loads *)
Expand Down Expand Up @@ -1527,14 +1528,15 @@ let make_mixed_alloc ~mode dbg tag shape args =
| Float | Float64 -> float_array_set arr ofs newval dbg
in
let size =
let values, floats = Lambda.count_mixed_block_values_and_floats shape in
if size_float <> size_addr
then
Misc.fatal_error
"Unable to compile mixed blocks on a platform where a float is not the \
same width as a value.";
values + floats
(* CR layouts 5.1: When we pack int32s more efficiently, this code will need
to change. *)
value_prefix_len + List.length flat_suffix
in
if size_float <> size_addr
then
Misc.fatal_error
"Unable to compile mixed blocks on a platform where a float is not the \
same width as a value.";
make_alloc_generic ~scannable_prefix:(Scan_prefix value_prefix_len) ~mode
set_fn dbg tag size args

Expand Down Expand Up @@ -2404,7 +2406,7 @@ let send kind met obj args args_type result akind dbg =
| _ -> bind "met" (lookup_tag obj met dbg) (call_met obj args args_type))

(*
* CAMLprim value caml_cache_public_method (value meths, value tag,
* CAMLprim value caml_cache_public_method (value meths, value tag,
* value *cache)
* {
* int li = 3, hi = Field(meths,0), mi;
Expand Down
15 changes: 3 additions & 12 deletions ocaml/lambda/lambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ and layout =
and block_shape =
value_kind list option

and flat_element = Types.flat_element = Imm | Float | Float64
and flat_element = Types.flat_element =
Imm | Float | Float64 | Bits32 | Bits64 | Word
and flat_element_read =
| Flat_read_imm
| Flat_read_float of alloc_mode
Expand Down Expand Up @@ -472,13 +473,6 @@ let join_boxed_vector_layout v1 v2 =
match v1, v2 with
| Pvec128 v1, Pvec128 v2 -> Punboxed_vector (Pvec128 (join_vec128_types v1 v2))

let equal_flat_element e1 e2 =
match e1, e2 with
| Imm, Imm -> true
| Float, Float -> true
| Float64, Float64 -> true
| (Imm | Float | Float64), _ -> false

let rec equal_value_kind x y =
match x, y with
| Pgenval, Pgenval -> true
Expand Down Expand Up @@ -513,7 +507,7 @@ and equal_constructor_shape x y =
List.length p1 = List.length p2
&& List.for_all2 equal_value_kind p1 p2
&& List.length s1 = List.length s2
&& List.for_all2 equal_flat_element s1 s2
&& List.for_all2 Types.equal_flat_element s1 s2
| (Constructor_uniform _ | Constructor_mixed _), _ -> false

let equal_layout x y =
Expand Down Expand Up @@ -1246,9 +1240,6 @@ let transl_prim mod_name name =
let transl_mixed_product_shape : Types.mixed_product_shape -> mixed_block_shape =
fun x -> x

let count_mixed_block_values_and_floats =
Types.count_mixed_record_values_and_floats

type mixed_block_element = Types.mixed_product_element =
| Value_prefix
| Flat_suffix of flat_element
Expand Down
4 changes: 2 additions & 2 deletions ocaml/lambda/lambda.mli
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ and layout =
and block_shape =
value_kind list option

and flat_element = Types.flat_element = Imm | Float | Float64
and flat_element = Types.flat_element =
Imm | Float | Float64 | Bits32 | Bits64 | Word
and flat_element_read =
| Flat_read_imm
| Flat_read_float of alloc_mode
Expand Down Expand Up @@ -790,7 +791,6 @@ val transl_extension_path: scoped_location -> Env.t -> Path.t -> lambda
val transl_class_path: scoped_location -> Env.t -> Path.t -> lambda

val transl_mixed_product_shape: Types.mixed_product_shape -> mixed_block_shape
val count_mixed_block_values_and_floats : mixed_block_shape -> int * int

type mixed_block_element =
| Value_prefix
Expand Down
6 changes: 2 additions & 4 deletions ocaml/typing/printtyped.ml
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,8 @@ let variant_representation i ppf = let open Types in function
cstrs
| Variant_extensible -> line i ppf "Variant_inlined\n"

let flat_element i ppf = let open Types in function
| Imm -> line i ppf "Immediate\n"
| Float -> line i ppf "Float\n"
| Float64 -> line i ppf "Float64\n"
let flat_element i ppf flat_element =
line i ppf "%s\n" (Types.flat_element_to_string flat_element)

let record_representation i ppf = let open Types in function
| Record_unboxed ->
Expand Down
25 changes: 13 additions & 12 deletions ocaml/typing/types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ and abstract_reason =
Abstract_def
| Abstract_rec_check_regularity

and flat_element = Imm | Float | Float64
and flat_element = Imm | Float | Float64 | Bits32 | Bits64 | Word
and mixed_product_shape =
{ value_prefix_len : int;
flat_suffix : flat_element array;
Expand Down Expand Up @@ -571,8 +571,10 @@ let equal_tag t1 t2 =

let equal_flat_element e1 e2 =
match e1, e2 with
| Imm, Imm | Float64, Float64 | Float, Float -> true
| (Imm | Float64 | Float), _ -> false
| Imm, Imm | Float64, Float64 | Float, Float
| Word, Word | Bits32, Bits32 | Bits64, Bits64
-> true
| (Imm | Float64 | Float | Word | Bits32 | Bits64), _ -> false

let equal_mixed_product_shape r1 r2 = r1 == r2 ||
(* Warning 9 alerts us if we add another field *)
Expand Down Expand Up @@ -690,15 +692,6 @@ let signature_item_id = function
| Sig_class_type (id, _, _, _)
-> id

let count_mixed_record_values_and_floats { value_prefix_len; flat_suffix } =
Array.fold_left
(fun (values, floats) elem ->
match elem with
| Imm -> (values+1, floats)
| Float | Float64 -> (values, floats+1))
(value_prefix_len, 0)
flat_suffix

type mixed_product_element =
| Value_prefix
| Flat_suffix of flat_element
Expand All @@ -708,6 +701,14 @@ let get_mixed_product_element { value_prefix_len; flat_suffix } i =
if i < value_prefix_len then Value_prefix
else Flat_suffix flat_suffix.(i - value_prefix_len)

let flat_element_to_string = function
| Imm -> "Imm"
| Float -> "Float"
| Float64 -> "Float64"
| Bits32 -> "Bits32"
| Bits64 -> "Bits64"
| Word -> "Word"

(**** Definitions for backtracking ****)

type change =
Expand Down
6 changes: 3 additions & 3 deletions ocaml/typing/types.mli
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ and abstract_reason =
non-empty suffix of "flat" elements. Intuitively, a flat element is one that
need not be scanned by the garbage collector.
*)
and flat_element = Imm | Float | Float64
and flat_element = Imm | Float | Float64 | Bits32 | Bits64 | Word
and mixed_product_shape =
{ value_prefix_len : int;
(* We use an array just so we can index into the middle. *)
Expand Down Expand Up @@ -873,8 +873,6 @@ val bound_value_identifiers: signature -> Ident.t list

val signature_item_id : signature_item -> Ident.t

val count_mixed_record_values_and_floats : mixed_product_shape -> int * int

type mixed_product_element =
| Value_prefix
| Flat_suffix of flat_element
Expand All @@ -883,6 +881,8 @@ type mixed_product_element =
val get_mixed_product_element :
mixed_product_shape -> int -> mixed_product_element

val flat_element_to_string : flat_element -> string

(**** Utilities for backtracking ****)

type snapshot
Expand Down