Bytes.blit should work "correctly even if [src] and [dst] are the same byte sequence, and the source and destination intervals overlap".
The BuckleScript implementation does not respect this semantic and therefore creates a bug in perfectly valid OCaml code.
The example below works well with OCaml while fail with BS:
let () =
let b = Bytes.create 3 in
Bytes.set b 0 'a';
Bytes.set b 1 'b';
Bytes.set b 2 'c';
Bytes.blit b 0 b 1 2;
assert('a' = Bytes.get b 0);
assert('a' = Bytes.get b 1);
assert('b' = Bytes.get b 2);
@mransan curious how did you find the cause? will fix it soon.
This is the bug of runtime, seems jsoo has the same bug
@mransan actually it is quite hard to implement memmove semantics since there is no such thing called pointer in JS. however, the good thing is that ocaml does not have pointer either, so we only need do a special handling when src == dst.
we will use the polyfill here
note this will only affect caml_blit_bytes (not caml_blit_string) since it is impossible for string and bytes to have memory overlap
I agree that a src == dst check is the way to go ... this is currently my work around!
src == dst
bug fix for #743
see #744, will make a minor release today