Skip to content

Commit 11b29ce

Browse files
TheNumbatmshinwell
andauthored
flambda-backend: Promote float32 to stable (#2709)
* start * progress * impl * missing fns * bigarrays * tests * fix r5 * move to stable * fix tests * fix cvtsi2ss instruction * promote * fix bounds check tests * address comments * Code review * format --------- Co-authored-by: Mark Shinwell <[email protected]>
1 parent 2752aa7 commit 11b29ce

25 files changed

+242
-236
lines changed
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
beta.mli
2-
beta.ml
3-
float32.mli
4-
float32.ml
1+
stdlib_beta.mli
2+
stdlib_beta.ml
3+

otherlibs/stdlib_beta/stdlib_beta.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
module Float32 = Float32
2-
module Float32_u = Float32_u

otherlibs/stdlib_beta/stdlib_beta.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
module Float32 = Float32
2-
module Float32_u = Float32_u
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
stable.mli
2-
stable.ml
1+
stdlib_stable.mli
2+
stdlib_stable.ml
3+
float32.mli
4+
float32.ml
File renamed without changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
module Iarray = Iarray
22
module IarrayLabels = IarrayLabels
3+
module Float32 = Float32
4+
module Float32_u = Float32_u
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
module Iarray = Iarray
22
module IarrayLabels = IarrayLabels
3+
module Float32 = Float32
4+
module Float32_u = Float32_u
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
upstream_compatible.mli
2-
upstream_compatible.ml
1+
stdlib_upstream_compatible.mli
2+
stdlib_upstream_compatible.ml

testsuite/tests/mixed-blocks/closure_padding_float32.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(* TEST
22
runtime5;
3-
include stdlib_beta;
3+
include stdlib_stable;
44
ocamlopt_flags="-extension layouts_alpha -extension small_numbers";
55
native;
66
*)
@@ -10,7 +10,7 @@
1010
https://github.com/ocaml-flambda/flambda-backend/pull/2763
1111
*)
1212

13-
module Float32_u = Stdlib_beta.Float32_u
13+
module Float32_u = Stdlib_stable.Float32_u
1414

1515
type t =
1616
| Mutable_str of { mutable x : string }

testsuite/tests/mixed-blocks/constructor_args.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(* TEST
2-
flags = "-extension layouts_beta -extension small_numbers";
3-
include stdlib_beta;
2+
flags = "-extension layouts_beta";
43
flambda2;
4+
include stdlib_stable;
55
include stdlib_upstream_compatible;
66
{
77
native;
@@ -13,8 +13,8 @@
1313
(*****************************************)
1414
(* Prelude: Functions on unboxed numbers *)
1515

16-
module Float32_u = Stdlib_beta.Float32_u
17-
module Float32 = Stdlib_beta.Float32
16+
module Float32_u = Stdlib_stable.Float32_u
17+
module Float32 = Stdlib_stable.Float32
1818
module Float_u = Stdlib_upstream_compatible.Float_u
1919
module Int32_u = Stdlib_upstream_compatible.Int32_u
2020
module Int64_u = Stdlib_upstream_compatible.Int64_u

testsuite/tests/mixed-blocks/generate_mixed_blocks_code.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ let type_to_field_integrity_check type_ ~access1 ~access2 ~message =
247247
| Imm -> "check_int", None
248248
| Float -> "check_float", None
249249
| Float64 -> "check_float", Some "Stdlib_upstream_compatible.Float_u.to_float"
250-
| Float32 -> "check_float32", Some "Stdlib_beta.Float32_u.to_float32"
250+
| Float32 -> "check_float32", Some "Stdlib_stable.Float32_u.to_float32"
251251
| Bits32 -> "check_int32", Some "Stdlib_upstream_compatible.Int32_u.to_int32"
252252
| Bits64 -> "check_int64", Some "Stdlib_upstream_compatible.Int64_u.to_int64"
253253
| Word -> "check_int", Some "Stdlib_upstream_compatible.Nativeint_u.to_int"
@@ -612,8 +612,8 @@ let main n ~bytecode =
612612
List.iter2 values (List.tl values @ [ List.hd values]) ~f
613613
in
614614
line {|(* TEST
615-
flags = "-extension layouts_beta -extension small_numbers";
616-
include stdlib_beta;
615+
flags = "-extension layouts_beta";
616+
include stdlib_stable;
617617
include stdlib_upstream_compatible;|};
618618
if bytecode then (
619619
line {| bytecode;|};
@@ -628,9 +628,9 @@ let main n ~bytecode =
628628
line {|let create_string () = String.make (Random.int 100) 'a'|};
629629
line {|let create_int () = Random.int 0x3FFF_FFFF|};
630630
line {|let create_float () = Random.float Float.max_float|};
631-
line {|let create_float32 () = Stdlib_beta.Float32.of_float (Random.float Float.max_float)|};
631+
line {|let create_float32 () = Stdlib_stable.Float32.of_float (Random.float Float.max_float)|};
632632
line {|let create_float_u () = Stdlib_upstream_compatible.Float_u.of_float (create_float ())|};
633-
line {|let create_float32_u () = Stdlib_beta.Float32_u.of_float32 (create_float32 ())|};
633+
line {|let create_float32_u () = Stdlib_stable.Float32_u.of_float32 (create_float32 ())|};
634634
line {|let create_int32_u () = Stdlib_upstream_compatible.Int32_u.of_int32 (Random.int32 0x7FFF_FFFFl)|};
635635
line {|let create_int64_u () = Stdlib_upstream_compatible.Int64_u.of_int64 (Random.int64 0x7FFF_FFFF_FFFF_FFFFL)|};
636636
line {|let create_nativeint_u () = Stdlib_upstream_compatible.Nativeint_u.of_nativeint (Random.nativeint 0x7FFF_FFFF_FFFF_FFFFn)|};
@@ -648,7 +648,7 @@ let main n ~bytecode =
648648
check_gen ~equal:Float.equal ~to_string:Float.to_string|};
649649
line
650650
{|let check_float32 =
651-
check_gen ~equal:Stdlib_beta.Float32.equal ~to_string:Stdlib_beta.Float32.to_string|};
651+
check_gen ~equal:Stdlib_stable.Float32.equal ~to_string:Stdlib_stable.Float32.to_string|};
652652
line
653653
{|let check_int32 =
654654
check_gen ~equal:Int32.equal ~to_string:Int32.to_string|};

testsuite/tests/mixed-blocks/generated_byte_test.ml

Lines changed: 147 additions & 147 deletions
Large diffs are not rendered by default.

testsuite/tests/mixed-blocks/generated_native_test.ml

Lines changed: 34 additions & 34 deletions
Large diffs are not rendered by default.

testsuite/tests/typing-layouts-arrays/test_float32_u_array.ml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
(* TEST
22
readonly_files = "gen_u_array.ml test_gen_u_array.ml";
33
modules = "${readonly_files}";
4-
include stdlib_beta;
4+
include stdlib_stable;
55
flambda2;
66
{
7-
flags = "-extension small_numbers";
87
bytecode;
98
}{
10-
flags = "-extension small_numbers";
119
native;
1210
}{
13-
flags = "-extension layouts_beta -extension small_numbers";
11+
flags = "-extension layouts_beta";
1412
bytecode;
1513
}{
16-
flags = "-extension layouts_beta -extension small_numbers";
14+
flags = "-extension layouts_beta";
1715
native;
1816
}
1917
*)
2018
(* Test compilation correctness for array of unboxed float32s. General
2119
tests around type-checking should go to [basics.ml]. *)
2220

2321
module Float32_I = struct
24-
include Stdlib_beta.Float32
22+
include Stdlib_stable.Float32
2523
let max_val = max_float
2624
let min_val = min_float
2725
let rand f = of_float (Random.float (to_float f))
@@ -66,15 +64,15 @@ module Float32_u_array0 : Gen_u_array.S0
6664
"caml_array_blit" "caml_unboxed_float32_vect_blit"
6765
let empty () = [||]
6866
external to_boxed : ('a : float32) -> (float32[@local_opt]) = "%box_float32"
69-
let compare_element x y = Stdlib_beta.Float32.compare (to_boxed (x ())) (to_boxed (y ()))
67+
let compare_element x y = Stdlib_stable.Float32.compare (to_boxed (x ())) (to_boxed (y ()))
7068
end
7169

7270
module Float32_u_array = Gen_u_array.Make (Float32_u_array0)
7371
module Float32_u_array_boxed : Test_gen_u_array.S with type t = float32# array = Test_gen_u_array.Make_boxed (struct
7472
module M = Float32_u_array
7573
module I = Float32_I
7674
module E = struct
77-
open Stdlib_beta.Float32_u
75+
open Stdlib_stable.Float32_u
7876
let to_boxed x = to_float32 (x ())
7977
let of_boxed x () = of_float32 x
8078
end
@@ -189,7 +187,7 @@ let () =
189187

190188
(* expression and patterns *)
191189
let () =
192-
let ( = ) = Stdlib_beta.Float32_u.equal in
190+
let ( = ) = Stdlib_stable.Float32_u.equal in
193191
(* match statement *)
194192
let d = [| #1.s; #2.s |] in
195193
(match d with

testsuite/tests/typing-layouts-float32/alloc.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
(* TEST
22
flambda2;
33
{
4-
include stdlib_beta;
5-
flags = "-extension-universe beta";
4+
include stdlib_stable;
65
native;
76
}
87
*)
@@ -15,7 +14,7 @@
1514
floats. *)
1615

1716
module Float32_u = struct
18-
include Stdlib_beta.Float32_u
17+
include Stdlib_stable.Float32_u
1918

2019
let ( + ) = add
2120
let ( - ) = sub
@@ -82,12 +81,12 @@ struct
8281
measure_alloc (fun () -> go #0.s #0.s)
8382
in
8483
Printf.printf "Unboxed:\n estimate: %f\n allocations: %s\n"
85-
(Stdlib_beta.Float32.to_float (to_float32 est) *. 4.) (get_allocations ())
84+
(Stdlib_stable.Float32.to_float (to_float32 est) *. 4.) (get_allocations ())
8685
end
8786

8887
module Pi_boxed =
8988
struct
90-
open Stdlib_beta.Float32
89+
open Stdlib_stable.Float32
9190
open Operators
9291

9392
let[@inline never] step n estimate =
@@ -125,8 +124,10 @@ let print_record_and_allocs s r =
125124
Printf.printf
126125
"%s:\n allocated bytes: %.2f\n a: %.2f\n b: %.2f\n c: %.2f\n d: %.2f\n"
127126
s allocs
128-
(Stdlib_beta.Float32.to_float (Float32_u.to_float32 r.a)) (Stdlib_beta.Float32.to_float (Float32_u.to_float32 r.b))
129-
(Stdlib_beta.Float32.to_float (Float32_u.to_float32 r.c)) (Stdlib_beta.Float32.to_float (Float32_u.to_float32 r.d))
127+
(Stdlib_stable.Float32.to_float (Float32_u.to_float32 r.a))
128+
(Stdlib_stable.Float32.to_float (Float32_u.to_float32 r.b))
129+
(Stdlib_stable.Float32.to_float (Float32_u.to_float32 r.c))
130+
(Stdlib_stable.Float32.to_float (Float32_u.to_float32 r.d))
130131

131132
(* Building a record should only allocate the box *)
132133
let[@inline never] build x =

testsuite/tests/typing-layouts-float32/unboxed_float32s.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
(* TEST
22
reference = "${test_source_directory}/unboxed_float32s.reference";
3-
include stdlib_beta;
3+
include stdlib_stable;
44
flambda2;
55
{
6-
flags = "-extension layouts_alpha -extension small_numbers";
6+
flags = "-extension layouts_alpha";
77
native;
88
}{
9-
flags = "-extension layouts_alpha -extension small_numbers";
9+
flags = "-extension layouts_alpha";
1010
bytecode;
1111
}{
12-
flags = "-extension layouts_beta -extension small_numbers";
12+
flags = "-extension layouts_beta";
1313
native;
1414
}{
15-
flags = "-extension layouts_beta -extension small_numbers";
15+
flags = "-extension layouts_beta";
1616
bytecode;
1717
}
1818
*)
@@ -34,7 +34,7 @@
3434
(* Prelude: Functions on unboxed floats. *)
3535

3636
module Float32 = struct
37-
include Stdlib_beta.Float32
37+
include Stdlib_stable.Float32
3838

3939
let ( + ) = add
4040
let ( - ) = sub
@@ -45,7 +45,7 @@ module Float32 = struct
4545
end
4646

4747
module Float32_u = struct
48-
include Stdlib_beta.Float32_u
48+
include Stdlib_stable.Float32_u
4949

5050
let ( + ) = add
5151
let ( - ) = sub

testsuite/tests/typing-simd/test_disabled.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Line 1, characters 9-18:
4444
1 | type t = float32x4;;
4545
^^^^^^^^^
4646
Error: Unbound type constructor float32x4
47+
Hint: Did you mean float32 or float32#?
4748
|}];;
4849

4950
type t = float64x2;;
@@ -52,4 +53,5 @@ Line 1, characters 9-18:
5253
1 | type t = float64x2;;
5354
^^^^^^^^^
5455
Error: Unbound type constructor float64x2
56+
Hint: Did you mean float32?
5557
|}];;

testsuite/tests/typing-small-numbers/test_disabled.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
(* TEST
2+
flags = "-no-extension small_numbers";
23
expect;
34
*)
45

utils/language_extension.ml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ let get_level_ops : type a. a t -> (module Extension_level with type t = a) =
6363
| Layouts -> (module Maturity)
6464
| SIMD -> (module Unit)
6565
| Labeled_tuples -> (module Unit)
66-
| Small_numbers -> (module Unit)
66+
| Small_numbers -> (module Maturity)
6767

6868
module Exist_pair = struct
6969
include Exist_pair
@@ -79,17 +79,19 @@ module Exist_pair = struct
7979
| Pair (Layouts, m) -> m
8080
| Pair (SIMD, ()) -> Stable
8181
| Pair (Labeled_tuples, ()) -> Stable
82-
| Pair (Small_numbers, ()) -> Beta
82+
| Pair (Small_numbers, m) -> m
8383

8484
let is_erasable : t -> bool = function Pair (ext, _) -> is_erasable ext
8585

8686
let to_string = function
8787
| Pair (Layouts, m) -> to_string Layouts ^ "_" ^ maturity_to_string m
8888
| Pair (Mode, m) -> to_string Mode ^ "_" ^ maturity_to_string m
89+
| Pair (Small_numbers, m) ->
90+
to_string Small_numbers ^ "_" ^ maturity_to_string m
8991
| Pair
9092
( (( Comprehensions | Unique | Include_functor | Polymorphic_parameters
91-
| Immutable_arrays | Module_strengthening | SIMD | Labeled_tuples
92-
| Small_numbers ) as ext),
93+
| Immutable_arrays | Module_strengthening | SIMD | Labeled_tuples )
94+
as ext),
9395
_ ) ->
9496
to_string ext
9597
end

utils/language_extension.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type 'a t = 'a Language_extension_kernel.t =
2222
| Layouts : maturity t
2323
| SIMD : unit t
2424
| Labeled_tuples : unit t
25-
| Small_numbers : unit t
25+
| Small_numbers : maturity t
2626

2727
(** Existentially packed language extension *)
2828
module Exist : sig

utils/language_extension_kernel.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type _ t =
1212
| Layouts : maturity t
1313
| SIMD : unit t
1414
| Labeled_tuples : unit t
15-
| Small_numbers : unit t
15+
| Small_numbers : maturity t
1616

1717
type 'a language_extension_kernel = 'a t
1818

@@ -72,7 +72,8 @@ let pair_of_string extn_name : Exist_pair.t option =
7272
| "layouts_beta" -> Some (Pair (Layouts, Beta))
7373
| "simd" -> Some (Pair (SIMD, ()))
7474
| "labeled_tuples" -> Some (Pair (Labeled_tuples, ()))
75-
| "small_numbers" -> Some (Pair (Small_numbers, ()))
75+
| "small_numbers" -> Some (Pair (Small_numbers, Stable))
76+
| "small_numbers_beta" -> Some (Pair (Small_numbers, Beta))
7677
| _ -> None
7778

7879
let maturity_to_string = function

utils/language_extension_kernel.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type _ t =
2121
| Layouts : maturity t
2222
| SIMD : unit t
2323
| Labeled_tuples : unit t
24-
| Small_numbers : unit t
24+
| Small_numbers : maturity t
2525

2626
module Exist : sig
2727
type 'a extn = 'a t

0 commit comments

Comments
 (0)