8000 chore(bytes): deprecate Bytes::copy by peter-jerry-ye · Pull Request #2303 · moonbitlang/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chore(bytes): deprecate Bytes::copy #2303

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

Merged
merged 1 commit into from
Jun 22, 2025
Merged

Conversation

peter-jerry-ye
Copy link
Collaborator

Closes #2178

Copy link
peter-jerry-ye-code-review bot commented Jun 20, 2025
The deprecation notice could be more informative

Category
Maintainability
Code Snippet
#deprecated("Bytes are immutable. Use FixedArray::blit_from_bytes if it's really necessary.")
Recommendation
Add more context to the deprecation message. For example: "Bytes are immutable by design. For mutable byte operations, create a FixedArray using FixedArray::blit_from_bytes, modify it, then convert back using Bytes::from_fixedarray."
Reasoning
The current message doesn't provide a complete alternative solution pathway. Users might not know how to properly replace the copy functionality in their codebase.

Test case replacement is more verbose than necessary

Category
Maintainability
Code Snippet
test "op_equal" {
let copy_bytes = FixedArray::make(HELLO_WORLD.length(), Byte::default())
copy_bytes.blit_from_bytes(0, HELLO_WORLD, 0, HELLO_WORLD.length())
let copy_bytes = Bytes::from_fixedarray(copy_bytes)
Recommendation
Consider adding a helper function in the test module or suggesting the addition of a utility function like Bytes::to_fixedarray to reduce verbosity:

fn Bytes::to_fixedarray(self: Bytes) -> FixedArray[Byte] {
  let arr = FixedArray::make(self.length(), Byte::default())
  arr.blit_from_bytes(0, self, 0, self.length())
  arr
}```
**Reasoning**
The new approach requires three lines of code where one was sufficient before. While the deprecated function is being removed, we should maintain code readability by providing convenient alternatives.

</details>
<details>

<summary> Removed test case for copy operation but kept implementation </summary>

**Category**
Correctness
**Code Snippet**
test "copy" { ... } // removed
pub fn Bytes::copy(self : Bytes) -> Bytes { ... } // kept
**Recommendation**
Consider moving the deprecated implementation to a separate deprecated module or marking it as internal if it's still needed by other parts of the codebase. This would help prevent accidental usage.
**Reasoning**
Keeping deprecated implementations in the main module while removing their tests can lead to maintenance issues. The implementation might break in the future without test coverage to catch it.

</details>

@coveralls
Copy link
Collaborator
coveralls commented Jun 20, 2025

Pull Request Test Coverage Report for Build 7422

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.001%) to 90.096%

Totals Coverage Status
Change from base Build 7419: -0.001%
Covered Lines: 8524
Relevant Lines: 9461

💛 - Coveralls

@bobzhang bobzhang force-pushed the zihang/deprecate-bytes-copy branch from e1e2b82 to bdbef4b Compare June 22, 2025 03:07
@bobzhang bobzhang enabled auto-merge (rebase) June 22, 2025 03:09
@bobzhang bobzhang merged commit e9bd1d8 into main Jun 22, 2025
12 checks passed
@bobzhang bobzhang deleted the zihang/deprecate-bytes-copy branch June 22, 2025 03:14
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

Successfully merging this pull request may close these issues.

deprecate Bytes::copy
3 participants
0