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

Failing assertion in CCRingBuffer #126

Closed
copy opened this issue May 13, 2017 · 9 comments
Closed

Failing assertion in CCRingBuffer #126

copy opened this issue May 13, 2017 · 9 comments
Assignees
Labels
Milestone

Comments

@copy
Copy link
Contributor

copy commented May 13, 2017

% ocamlbuild -use-ocamlfind -pkg containers.data test.native --
Finished, 4 targets (0 cached) in 00:00:00.
Fatal error: exception Assert_failure("src/data/CCRingBuffer.ml", 330, 6)

It doesn't seem to happen with small buffers, so it's unclear which usage pattern produces this issue. The following reproduces the problem:

module B = CCRingBuffer.Make(struct type t = int end)

let () =
  let b = B.create ~bounded:true 50 in
  while true do
    if Random.float 1.0 < 0.5 then
      B.push_back b 0
    else
      let _ = B.take_front b in ()
  done
@c-cube
Copy link
Owner

c-cube commented May 13, 2017

Thanks for the report, I will look into it.

@c-cube c-cube self-assigned this May 13, 2017
@c-cube c-cube added this to the 1.3 milestone May 13, 2017
@c-cube
Copy link
Owner

c-cube commented May 13, 2017

It's actually possible that I break compatibility a bit, the current code is too complicated…

@copy
Copy link
Contributor Author

copy commented May 13, 2017

It's actually possible that I break compatibility a bit, the current code is too complicated…

That sounds reasonable. I'd suggest also splitting the module into a bounded and an unbounded version during that process.

@c-cube
Copy link
Owner

c-cube commented May 13, 2017

That might be the best, indeed… Or perhaps only split internally but use a phantom type to distinguish:

type 'a t constraints t = [< `bounded|`unbounded]

val capacity : _ t -> int

val max_capacity : [`bounded] t -> int

In any case this is probably the best course of action.

c-cube added a commit that referenced this issue Jun 13, 2017
- add some qcheck test comparing to reference implem
- use bounded buffers only
- use inefficient methods (for now)
@c-cube
Copy link
Owner

c-cube commented Jun 13, 2017

I removed the unbounded API in ff77a6a, added strong tests, and fixed the bug. However, the fix is pretty basic (some functions like blit_from push items one by one instead of using Array.blit). Now that the base implementation works I can more confidently improve performance.

@struktured
Copy link
Contributor

struktured commented Jun 14, 2017 via email

@c-cube
Copy link
Owner

c-cube commented Jun 14, 2017

@struktured you are welcome to try. It would be nice, for measuring performance, to put the current version into the benchmarks (as a reference impl) and iterate from there.

With the new tests I'm a bit more confident in the correctness of the module. I think the tests can still be improved (e.g. by supporting more operations in the last random tests), but they're a big step in the right direction.

@c-cube
Copy link
Owner

c-cube commented Jun 14, 2017

Found an issue in skip. These random tests sure are great.

@c-cube
Copy link
Owner

c-cube commented Jun 14, 2017

I'll close this and move to #134 for further changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants