-
Notifications
You must be signed in to change notification settings - Fork 125
refactor(bytesview): change bytesview back to concrete type #2104
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
base: main
Are you sure you want to change the base?
Conversation
Direct field access instead of function calls may improve performanceCategory The struct definition comment could be more descriptiveCategory #builtin.valtype
struct View {
/// The underlying bytes buffer
bytes : Bytes
/// Starting offset in the buffer (>= 0)
start : Int
/// Length of the view (>= 0)
len : Int
}```
**Reasoning**
Documenting field invariants helps prevent misuse and makes maintenance easier
</details>
<details>
<summary> No validation of struct field invariants during construction </summary>
**Category**
Correctness
**Code Snippet**
pub fn Bytes::op_as_view(self : Bytes, start~ : Int = 0, end? : Int) -> View {
...
{ bytes: self, start, len: end - start }
}
**Recommendation**
Consider adding runtime checks or making the View constructor private with a validated factory method
**Reasoning**
Invalid field values could lead to out of bounds access. While the public methods do validate, preventing invalid construction would be safer
</details> |
Pull Request Test Coverage Report for Build 7150Details
💛 - Coveralls |
is there any benefit changing it back? Note we still did some magic operations on View, so it may make sense to keep it abstract |
|
db8294b
to
97971fd
Compare
this can also help simplify debug info generation for bytes view in LLVM backend |
The compiler does not need
@bytes.View
to be abstract to perform optimizations. So it's changed back.