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

Bug with CCVector of Int32 #454

Closed
RafaelBocquet opened this issue Jun 27, 2024 · 2 comments
Closed

Bug with CCVector of Int32 #454

RafaelBocquet opened this issue Jun 27, 2024 · 2 comments

Comments

@RafaelBocquet
Copy link

The following code

let () =
  let arr : Int32.t CCVector.vector = CCVector.create () in
  CCVector.push arr (Int32.of_int 123456);
  Format.printf "%d\n" (Int32.to_int (CCVector.get arr 0));
  let x = CCVector.get arr 0 in
  Format.printf "%d\n" (Int32.to_int x)

produces the following output:

123456
1024

when compiled to native code (ocamlfind ocamlopt -linkpkg -package containers -o main main.ml).

It produces the expected output when compiled to bytecode (ocamlfind ocamlc -linkpkg -package containers -o main main.ml).

@c-cube c-cube closed this as completed in c959e39 Sep 17, 2024
@c-cube
Copy link
Owner

c-cube commented Sep 17, 2024

Sorry it took me so long to look at this. I think it's a compiler issue, I got a small repro that only requires this from the Vec module:

type 'a t = { mutable vec: 'a array }

let push self x = self.vec <- [|x|]

let[@inline] get self i =
  if i >= Array.length self.vec then invalid_arg "ohno";
  Array.unsafe_get self.vec i

so I think inlining across module must lose some information. Please try the main branch to see if my fix works for you too!

@c-cube
Copy link
Owner

c-cube commented Sep 17, 2024

ocaml/ocaml#13448 I opened an upstream bug report btw, thank you @RafaelBocquet :)

c-cube added a commit that referenced this issue Nov 18, 2024
this is required to be able to repro #454
c-cube added a commit that referenced this issue Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants