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

ByteArray.copySlice behavior inconsistent with its def #2966

Closed
3 tasks done
JiechengZhao opened this issue Nov 27, 2023 · 0 comments
Closed
3 tasks done

ByteArray.copySlice behavior inconsistent with its def #2966

JiechengZhao opened this issue Nov 27, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@JiechengZhao
Copy link

JiechengZhao commented Nov 27, 2023

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:
    • Check that your issue is not already filed.
    • Reduce the issue to a minimal, self-contained, reproducible test case. Avoid dependencies to mathlib4 or std4.

Description

Hi, found ByteArray.copySlice behavior inconsistent with its def when srcOff + len > src.size

Steps to Reproduce

/--
@[extern "lean_byte_array_copy_slice"]
def copySlice (src : @& ByteArray) (srcOff : Nat) (dest : ByteArray) (destOff len : Nat) (exact : Bool := true) : ByteArray :=
  ⟨dest.data.extract 0 destOff ++ src.data.extract srcOff (srcOff + len) ++ dest.data.extract (destOff + len) dest.data.size⟩
-/

def copySlice_ (src : @& ByteArray) (srcOff : Nat) (dest : ByteArray) (destOff len : Nat) (exact : Bool := true) : ByteArray :=
  ⟨dest.data.extract 0 destOff ++ src.data.extract srcOff (srcOff + len) ++ dest.data.extract (destOff + len) dest.data.size⟩

#eval copySlice_ ⟨#[1, 2, 3]⟩ 1 ⟨#[4, 5, 6, 7 , 8 , 9, 10, 11, 12, 13]⟩ 0 6 -- [2, 3, 10, 11, 12, 13]
#eval ByteArray.copySlice ⟨#[1, 2, 3]⟩ 1 ⟨#[4, 5, 6, 7 , 8 , 9, 10, 11, 12, 13]⟩ 0 6 -- [2, 3, 6, 7, 8, 9, 10, 11, 12, 13]

Expected behavior:

The copySlice_ and ByteArray.copySlice should be same

Actual behavior:
ByteArray.copySlice works like this.

def some_func (src : @& ByteArray) (srcOff : Nat) (dest : ByteArray) (destOff len : Nat) (exact : Bool := true) : ByteArray :=
  let len_ := min (len) (src.size)
  ⟨dest.data.extract 0 destOff ++ src.data.extract srcOff (srcOff + len_) ++ dest.data.extract (destOff + len_) dest.data.size⟩

Versions

"4.3.0-rc2"
Ubuntu 22.04.3 LTS

Additional Information

[Additional information, configuration or data that might be necessary to reproduce the issue]

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

@JiechengZhao JiechengZhao added the bug Something isn't working label Nov 27, 2023
github-merge-queue bot pushed a commit that referenced this issue Dec 16, 2023
Fixes reference implementation of `ByteArray.copySlice`, as reported
#2966.

Adds tests.

---------

Co-authored-by: Joachim Breitner <mail@joachim-breitner.de>
github-merge-queue bot pushed a commit that referenced this issue Dec 21, 2023
#2966 was the `@[extern]` bug that prompted development of the
`test_extern` command, but then we merged the fix to #2966 without
updating the tests to use `test_extern`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant