Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

some improvements to bounded vec API #10590

Merged
merged 8 commits into from
Jan 6, 2022

Conversation

kianenigma
Copy link
Contributor

@kianenigma kianenigma commented Jan 5, 2022

From my work in https://github.com/paritytech/substrate/tree/kiz-multi-block-playground and paritytech/polkadot-sdk#461, I've worked a lot with bounded vec and have found some issues with it. This is bringing some of them back to master.

About the TryCollect, the downside as of now is that this cannot work for something like Filter<_, _>. Instead, we can make a custom marker trait NonIncreasingIter, which will mark all iterator types that cannot increase the size of an iterator (almost all of them, right?). Then we can probably support things like Filter as well by relying on this custom marker instead of the ExactSizeIterator.

As for the equality update, I think the benefit is clear, and I don't see why we should consider two bounded vecs not equal if they have the same bound, expressed as different types.

Lastly, I am also very keen on making a bounded_vec![] macro as well as it is a pure PITA to construct them frequently otherwise. To the best of my knowledge that would require a proc-macro, so I have hesitated from doing it so far.

@kianenigma kianenigma added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. labels Jan 5, 2022
frame/support/src/storage/bounded_vec.rs Outdated Show resolved Hide resolved
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
@kianenigma
Copy link
Contributor Author

TODO: maybe I can add these to WeakBoundedVec and BoundedBTreeMap as well before merge.

@shawntabrizi
Copy link
Member

shawntabrizi commented Jan 5, 2022

Agree about bounded tree map, but probably we should be looking to remove weak bounded vec versus giving it more features. So i would suggest not even adding it right now until we ourselves feel major pain to need it

@kianenigma
Copy link
Contributor Author

added to btree map and set, but not weak bounded vec.

will wait for one of you to merge or approve again, since the code changed a bit.

@kianenigma
Copy link
Contributor Author

bot merge

@paritytech-processbot paritytech-processbot bot merged commit 55f7969 into master Jan 6, 2022
@paritytech-processbot paritytech-processbot bot deleted the kiz-improve-bounded-vec branch January 6, 2022 10:55
grishasobol pushed a commit to gear-tech/substrate that referenced this pull request Mar 28, 2022
* some improvements to bounded vec

* revert license tweak

* more tests

* fix

* Update frame/support/src/storage/bounded_vec.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* add the same stuff for btree map and set as well

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
* some improvements to bounded vec

* revert license tweak

* more tests

* fix

* Update frame/support/src/storage/bounded_vec.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* add the same stuff for btree map and set as well

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants