Repository navigation
feat[lang]: allow DynArrays of length 0
#5234
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
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
6c7cda6
Allow DynArrays of length 0
Sporarum aeaad84
Make failing test xfail
Sporarum 37f8ce0
Merge branch 'master' into make-0-length
Sporarum 1a34208
Fix test issue
Sporarum 90963b4
Fix missing handling of 0-length arrays
Sporarum 48a1e3a
Update docstring and comments
Sporarum 61288ab
Clean-up SArrayT lenght check
Sporarum 2797260
Add length-0 tests for bytes and strings
Sporarum 59c1d11
Merge branch 'master' into make-0-length
Sporarum 6fb6a66
Revert bad parts of previous commit
Sporarum 61dba4c
Properly fix rounds=bounds=0 infinite loop
Sporarum ad5660a
Even better, wow
Sporarum 187c54a
Oops there was a mistake in the previous one
Sporarum 06d3ae2
Simplicity for the win
Sporarum 0b52720
Explain by refactoring
Sporarum 8faf558
Fix missing typecheck
Sporarum ad8f066
Merge branch 'master' into make-0-length
Sporarum 9d6c27d
Fix nits
Sporarum b9abac0
Update gas heuristic
Sporarum 597311f
Fix typo in comment
Sporarum b4a6165
Simplify condition
Sporarum b652989
Add more comments describing the stack state
Sporarum c46f185
Clarify logic
Sporarum fafb077
Merge branch 'master' into make-0-length
HodanPlodky b4dab57
Merge branch 'master' into make-0-length
HodanPlodky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,32 @@ | ||
| def test_repeat(get_contract_from_ir, assert_compile_failed): | ||
| good_ir = ["repeat", "i", 0, 1, 1, ["seq"]] | ||
| good_ir_2 = ["repeat", "i", 0, 0, 0, ["seq"]] | ||
| bad_ir_1 = ["repeat", 0, 0, 0, 0, ["seq"]] | ||
| bad_ir_2 = ["repeat", 0, 0, -1, -1, ["seq"]] | ||
| get_contract_from_ir(good_ir) | ||
| get_contract_from_ir(good_ir_2) | ||
| assert_compile_failed(lambda: get_contract_from_ir(bad_ir_1), Exception) | ||
| assert_compile_failed(lambda: get_contract_from_ir(bad_ir_2), Exception) | ||
|
|
||
|
|
||
| def test_repeat_bound_zero_runtime_rounds(get_contract_from_ir, tx_failed): | ||
| # bound-0 repeat with non-literal rounds enforces rounds == 0 at runtime | ||
| ir = [ | ||
| "deploy", | ||
| 0, | ||
| ["seq", ["repeat", "i", 0, ["calldataload", 4], 0, ["seq"]], ["return", 0, 0], "stop"], | ||
| 0, | ||
| ] | ||
| abi = [ | ||
| { | ||
| "name": "test", | ||
| "outputs": [], | ||
| "inputs": [{"type": "uint256", "name": "n"}], | ||
| "stateMutability": "nonpayable", | ||
| "type": "function", | ||
| } | ||
| ] | ||
| c = get_contract_from_ir(ir, abi=abi) | ||
| c.test(0) | ||
| with tx_failed(): | ||
| c.test(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we planning to support this in future, since the return of the single of DynArray[Never, 0] will be handled correctly?
And also
would work as I would expect so what is the blocking this one to compile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should
It does work as you would expect (0 -> [], 1 -> [1], 2+ -> reverts)
The issue is that we use the element type's abi to compile even empty lists
With
[[], [1]]we infer typeSArrayT(DArrayT(uint256, 1), 2)for the whole expression, so[]is compiled as aDArrayT(uint256, 2)(or, 0], doesn't matter)But with
[[], []]we infer the type toSArrayT(DArrayT(BottomT, 0), 2), so we don't know how to compile the[]elementsThis can be fixed in two ways:
DArrayT[T, 0], don't fetch the abi-encoding of the elements, just output an empty (discussed in private with @harkal as a possibility)And I think we should do both (but outside of scope for this PR)