feat[lang]: allow DynArrays of length 0 - #5234
Conversation
Gas ChangesNo changes detected. Summary
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6c7cda67d1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| assert ( | ||
| isinstance(repeat_bound.value, int) and repeat_bound.value > 0 | ||
| ), f"repeat bound must be a compile-time positive integer: {self.args[2]}" | ||
| isinstance(repeat_bound.value, int) and repeat_bound.value >= 0 | ||
| ), f"repeat bound must be a compile-time non-negative integer: {repeat_bound}" |
There was a problem hiding this comment.
Preserve zero-iteration semantics for VyperIR repeats
Allowing a zero repeat_bound here accepts valid VyperIR such as repeat(i, 0, 0, 0, body), but the legacy lowerer only emits its zero-rounds exit jump when rounds != rounds_bound in vyper/ir/compile_ir.py. For equal literal zero values it enters the do-while body once, so contracts compiled through the documented direct VyperIR path (vyper-ir) execute a zero-iteration loop unexpectedly. Retain the rejection for this form or make the lowerer skip zero rounds unconditionally.
Useful? React with 👍 / 👎.
📊 Bytecode Size Changes (venom)No changes detected. Full bytecode sizes
|
|
@Sporarum tests seem to fail under venom |
What I did
Allow
DynArrays of length 0, including in user-written annotationsChange the type of
[]toDynArray[Never, 0](wasDynArray[Never, 1])Note: Does not allow
Bytes[0]andString[0](a different PR can do that).How I did it
Change bounds check on lengths for DynArrays from
>to>=How to verify it
pytest, also see new testsCommit message
Description for the changelog
Allow
DynArray[T, 0]type (which is only inhabited by[])Cute Animal Picture