mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-05 19:00:31 -05:00
fix #454: work around a weird miscompilation
This commit is contained in:
parent
6ab811f79b
commit
c959e396b3
2 changed files with 19 additions and 3 deletions
|
|
@ -176,7 +176,8 @@ let append a b =
|
||||||
|
|
||||||
let[@inline] get v i =
|
let[@inline] get v i =
|
||||||
if i < 0 || i >= v.size then invalid_arg "CCVector.get";
|
if i < 0 || i >= v.size then invalid_arg "CCVector.get";
|
||||||
Array.unsafe_get v.vec i
|
(* NOTE: over eager inlining seems to miscompile for int32 at least (#454) *)
|
||||||
|
Sys.opaque_identity (Array.unsafe_get v.vec i)
|
||||||
|
|
||||||
let[@inline] set v i x =
|
let[@inline] set v i x =
|
||||||
if i < 0 || i >= v.size then invalid_arg "CCVector.set";
|
if i < 0 || i >= v.size then invalid_arg "CCVector.set";
|
||||||
|
|
@ -282,7 +283,8 @@ let[@inline] top v =
|
||||||
|
|
||||||
let[@inline] top_exn v =
|
let[@inline] top_exn v =
|
||||||
if v.size = 0 then raise Empty;
|
if v.size = 0 then raise Empty;
|
||||||
Array.unsafe_get v.vec (v.size - 1)
|
(* NOTE: over eager inlining seems to miscompile for int32 at least (#454) *)
|
||||||
|
Sys.opaque_identity (Array.unsafe_get v.vec (v.size - 1))
|
||||||
|
|
||||||
let[@inline] copy v = { size = v.size; vec = Array.sub v.vec 0 v.size }
|
let[@inline] copy v = { size = v.size; vec = Array.sub v.vec 0 v.size }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
module T = (val Containers_testlib.make ~__FILE__ ())
|
module T = (val Containers_testlib.make ~__FILE__ ())
|
||||||
include T
|
include T
|
||||||
open CCVector;;
|
open CCVector
|
||||||
|
|
||||||
|
let spf = Printf.sprintf;;
|
||||||
|
|
||||||
t @@ fun () -> create_with ~capacity:200 1 |> capacity >= 200;;
|
t @@ fun () -> create_with ~capacity:200 1 |> capacity >= 200;;
|
||||||
t @@ fun () -> return 42 |> to_list = [ 42 ];;
|
t @@ fun () -> return 42 |> to_list = [ 42 ];;
|
||||||
|
|
@ -751,3 +753,15 @@ push v 0;
|
||||||
push v 0;
|
push v 0;
|
||||||
push v 0;
|
push v 0;
|
||||||
6 = foldi (fun i acc _ -> acc + i) 0 v
|
6 = foldi (fun i acc _ -> acc + i) 0 v
|
||||||
|
;;
|
||||||
|
|
||||||
|
t ~name:"reg454" @@ fun () ->
|
||||||
|
let arr : Int32.t vector = create () in
|
||||||
|
CCVector.push arr (Int32.of_int 123456);
|
||||||
|
let s = spf "%d\n" (Int32.to_int (CCVector.get arr 0)) in
|
||||||
|
Printf.eprintf "%d\n" (Int32.to_int (CCVector.get arr 0));
|
||||||
|
let x = CCVector.get arr 0 in
|
||||||
|
let s2 = spf "%d\n" (Int32.to_int x) in
|
||||||
|
Printf.eprintf "%d\n" (Int32.to_int x);
|
||||||
|
assert_equal ~printer:(spf "%S") s s2;
|
||||||
|
true
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue