Skip to content

Commit

Permalink
flambda-backend: Move unboxed types modules to `stdlib_upstream_compa…
Browse files Browse the repository at this point in the history
…tible` (#2588)

* Move unboxed types to `stdlib_upstream_compatible`

* Search-and-replace moved modules in tests

* Disable upstream compatibility warnings on external declarations

* Fix includes

* Promote changed tests

* Modify `lib-extensions` tests

---------

Co-authored-by: Diana Kalinichenko <[email protected]>
  • Loading branch information
dkalinichenko-js and d-kalinichenko authored May 23, 2024
1 parent 3d71567 commit 6eba90d
Show file tree
Hide file tree
Showing 58 changed files with 1,479 additions and 1,472 deletions.
8 changes: 0 additions & 8 deletions otherlibs/stable/dune
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,10 @@
(deps
(glob_files ../stdlib_stable/*.{ml,mli}))
(targets
float_u.ml
float_u.mli
iarray.ml
iarray.mli
iarrayLabels.ml
iarrayLabels.mli
int32_u.ml
int32_u.mli
int64_u.ml
int64_u.mli
nativeint_u.ml
nativeint_u.mli
stable.ml
stable.mli)
(action
Expand Down
4 changes: 0 additions & 4 deletions otherlibs/stdlib_stable/stdlib_stable.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
module Float_u = Float_u
module Int32_u = Int32_u
module Int64_u = Int64_u
module Nativeint_u = Nativeint_u
module Iarray = Iarray
module IarrayLabels = IarrayLabels
4 changes: 0 additions & 4 deletions otherlibs/stdlib_stable/stdlib_stable.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
module Float_u = Float_u
module Int32_u = Int32_u
module Int64_u = Int64_u
module Nativeint_u = Nativeint_u
module Iarray = Iarray
module IarrayLabels = IarrayLabels
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ open! Stdlib

type t = float#

external to_float : t -> (float[@local_opt]) = "%box_float"
external to_float : t -> (float[@local_opt]) = "%box_float" [@@warning "-187"]

external of_float : (float[@local_opt]) -> t = "%unbox_float"
external of_float : (float[@local_opt]) -> t = "%unbox_float" [@@warning "-187"]

(* CR layouts: Investigate whether it's worth making these things externals.
Are there situations where the middle-end won't inline them and remove the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ type t = float#
[infinity]) when we we support [float64]s in structures. *)

(* Unboxed-specific stuff at the top. *)
external to_float : t -> (float[@local_opt]) = "%box_float"
external to_float : t -> (float[@local_opt]) = "%box_float" [@@warning "-187"]
(** Box a [float#] *)

external of_float : (float[@local_opt]) -> t = "%unbox_float"
external of_float : (float[@local_opt]) -> t = "%unbox_float" [@@warning "-187"]
(** Unbox a boxed [float] *)

(* Below here, everything also appears in [Float], though most things are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ open! Stdlib

type t = int32#

external to_int32 : t -> (int32[@local_opt]) = "%box_int32"
external to_int32 : t -> (int32[@local_opt]) = "%box_int32" [@@warning "-187"]

external of_int32 : (int32[@local_opt]) -> t = "%unbox_int32"
external of_int32 : (int32[@local_opt]) -> t = "%unbox_int32" [@@warning "-187"]

let[@inline always] neg x = of_int32 (Int32.neg (to_int32 x))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ type t = int32#
*)

(* Unboxed-specific stuff at the top. *)
external to_int32 : t -> (int32[@local_opt]) = "%box_int32"
external to_int32 : t -> (int32[@local_opt]) = "%box_int32" [@@warning "-187"]
(** Box a [int32#] *)

external of_int32 : (int32[@local_opt]) -> t = "%unbox_int32"
external of_int32 : (int32[@local_opt]) -> t = "%unbox_int32" [@@warning "-187"]
(** Unbox a boxed [int32] *)

(* Below here, everything also appears in [Int32], though most things are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ open! Stdlib

type t = int64#

external to_int64 : t -> (int64[@local_opt]) = "%box_int64"
external to_int64 : t -> (int64[@local_opt]) = "%box_int64" [@@warning "-187"]

external of_int64 : (int64[@local_opt]) -> t = "%unbox_int64"
external of_int64 : (int64[@local_opt]) -> t = "%unbox_int64" [@@warning "-187"]

let[@inline always] neg x = of_int64 (Int64.neg (to_int64 x))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ type t = int64#
*)

(* Unboxed-specific stuff at the top. *)
external to_int64 : t -> (int64[@local_opt]) = "%box_int64"
external to_int64 : t -> (int64[@local_opt]) = "%box_int64" [@@warning "-187"]
(** Box a [int64#] *)

external of_int64 : (int64[@local_opt]) -> t = "%unbox_int64"
external of_int64 : (int64[@local_opt]) -> t = "%unbox_int64" [@@warning "-187"]
(** Unbox a boxed [int64] *)

(* Below here, everything also appears in [Int64], though most things are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ open! Stdlib

type t = nativeint#

external to_nativeint : t -> (nativeint[@local_opt]) = "%box_nativeint"
external to_nativeint : t -> (nativeint[@local_opt]) = "%box_nativeint" [@@warning "-187"]

external of_nativeint : (nativeint[@local_opt]) -> t =
"%unbox_nativeint"
"%unbox_nativeint" [@@warning "-187"]

let[@inline always] neg x = of_nativeint (Nativeint.neg (to_nativeint x))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ type t = nativeint#
*)

(* Unboxed-specific stuff at the top. *)
external to_nativeint : t -> (nativeint[@local_opt]) = "%box_nativeint"
external to_nativeint : t -> (nativeint[@local_opt]) = "%box_nativeint" [@@warning "-187"]
(** Box a [nativeint#] *)

external of_nativeint : (nativeint[@local_opt]) -> t =
"%unbox_nativeint"
"%unbox_nativeint" [@@warning "-187"]
(** Unbox a boxed [nativeint] *)

(* Below here, everything also appears in [Nativeint], though most things are
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Float_u = Float_u
module Int32_u = Int32_u
module Int64_u = Int64_u
module Nativeint_u = Nativeint_u
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Float_u = Float_u
module Int32_u = Int32_u
module Int64_u = Int64_u
module Nativeint_u = Nativeint_u
12 changes: 11 additions & 1 deletion otherlibs/upstream_compatible/dune
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,17 @@
(rule
(deps
(glob_files ../stdlib_upstream_compatible/*.{ml,mli}))
(targets upstream_compatible.ml upstream_compatible.mli)
(targets
float_u.ml
float_u.mli
int32_u.ml
int32_u.mli
int64_u.ml
int64_u.mli
nativeint_u.ml
nativeint_u.mli
upstream_compatible.ml
upstream_compatible.mli)
(action
(bash
"cp ../stdlib_upstream_compatible/*.{ml,mli} .; mv stdlib_upstream_compatible.ml upstream_compatible.ml; mv stdlib_upstream_compatible.mli upstream_compatible.mli")))
Expand Down
10 changes: 5 additions & 5 deletions testsuite/tests/mixed-blocks/constructor_args.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
flags = "-extension layouts_beta -extension small_numbers";
include beta;
flambda2;
include stable;
include stdlib_upstream_compatible;
{
native;
}{
Expand All @@ -15,10 +15,10 @@

module Float32_u = Beta.Float32_u
module Float32 = Beta.Float32
module Float_u = Stable.Float_u
module Int32_u = Stable.Int32_u
module Int64_u = Stable.Int64_u
module Nativeint_u = Stable.Nativeint_u
module Float_u = Stdlib_upstream_compatible.Float_u
module Int32_u = Stdlib_upstream_compatible.Int32_u
module Int64_u = Stdlib_upstream_compatible.Int64_u
module Nativeint_u = Stdlib_upstream_compatible.Nativeint_u

let print_floatu prefix x = Printf.printf "%s: %.2f\n" prefix (Float_u.to_float x)
let print_float prefix x = Printf.printf "%s: %.2f\n" prefix x
Expand Down
18 changes: 9 additions & 9 deletions testsuite/tests/mixed-blocks/generate_mixed_blocks_code.ml
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ let type_to_field_integrity_check type_ ~access1 ~access2 ~message =
| Str -> "check_string", None
| Imm -> "check_int", None
| Float -> "check_float", None
| Float64 -> "check_float", Some "Stable.Float_u.to_float"
| Float64 -> "check_float", Some "Stdlib_upstream_compatible.Float_u.to_float"
| Float32 -> "check_float32", Some "Beta.Float32_u.to_float32"
| Bits32 -> "check_int32", Some "Stable.Int32_u.to_int32"
| Bits64 -> "check_int64", Some "Stable.Int64_u.to_int64"
| Word -> "check_int", Some "Stable.Nativeint_u.to_int"
| Bits32 -> "check_int32", Some "Stdlib_upstream_compatible.Int32_u.to_int32"
| Bits64 -> "check_int64", Some "Stdlib_upstream_compatible.Int64_u.to_int64"
| Word -> "check_int", Some "Stdlib_upstream_compatible.Nativeint_u.to_int"
in
let transform access =
match transformation with
Expand Down Expand Up @@ -567,7 +567,7 @@ let main n ~bytecode =
line {|(* TEST
flags = "-extension layouts_beta -extension small_numbers";
include beta;
include stable;|};
include stdlib_upstream_compatible;|};
if bytecode then (
line {| bytecode;|};
) else (
Expand All @@ -582,11 +582,11 @@ let main n ~bytecode =
line {|let create_int () = Random.int 0x3FFF_FFFF|};
line {|let create_float () = Random.float Float.max_float|};
line {|let create_float32 () = Beta.Float32.of_float (Random.float Float.max_float)|};
line {|let create_float_u () = Stable.Float_u.of_float (create_float ())|};
line {|let create_float_u () = Stdlib_upstream_compatible.Float_u.of_float (create_float ())|};
line {|let create_float32_u () = Beta.Float32_u.of_float32 (create_float32 ())|};
line {|let create_int32_u () = Stable.Int32_u.of_int32 (Random.int32 0x7FFF_FFFFl)|};
line {|let create_int64_u () = Stable.Int64_u.of_int64 (Random.int64 0x7FFF_FFFF_FFFF_FFFFL)|};
line {|let create_nativeint_u () = Stable.Nativeint_u.of_nativeint (Random.nativeint 0x7FFF_FFFF_FFFF_FFFFn)|};
line {|let create_int32_u () = Stdlib_upstream_compatible.Int32_u.of_int32 (Random.int32 0x7FFF_FFFFl)|};
line {|let create_int64_u () = Stdlib_upstream_compatible.Int64_u.of_int64 (Random.int64 0x7FFF_FFFF_FFFF_FFFFL)|};
line {|let create_nativeint_u () = Stdlib_upstream_compatible.Nativeint_u.of_nativeint (Random.nativeint 0x7FFF_FFFF_FFFF_FFFFn)|};
line
{|let check_gen ~equal ~to_string ~message y1 y2 =
if equal y1 y2 then () else
Expand Down
Loading

0 comments on commit 6eba90d

Please sign in to comment.