Skip to content
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

Make Vector usable when initialized with SpreadAllocate #1070

Closed
wants to merge 10 commits into from

Conversation

HCastano
Copy link
Contributor

@HCastano HCastano commented Dec 7, 2021

At the moment the ink_storage::Vec type is unusable when initialized using
SpreadAllocate::allocate_spread. This is because Vec::len does not account that the
vector can be in a state where the it is initialized but there is nothing in storage.

This creates problems when using Vec::len, such as during Drop (see here),
or Vec::push.

This PR changes the behaviour of Vec::len() to return a 0 length if there is no
length in storage. It also changes all uses of Lazy::get_mut for modifying Vec.len to
use Lazy::set instead since that doesn't panic if no item exists in storage.

Currently a draft since there are some other storage data structures which use Vec
whose tests need to be updated and I'm not quite sure what the best way to fix those
tests is just yet.

@cmichi
Copy link
Collaborator

cmichi commented Dec 9, 2021

@HCastano I can't think of a better approach, so I'm fine with the PR if you fix the other tests.

@ascjones Do you have an opinion?

@HCastano HCastano marked this pull request as ready for review December 9, 2021 21:43
@codecov-commenter
Copy link

Codecov Report

Merging #1070 (6e3b7e3) into master (9b154e8) will decrease coverage by 15.93%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #1070       +/-   ##
===========================================
- Coverage   78.75%   62.82%   -15.94%     
===========================================
  Files         248      248               
  Lines        9371     9371               
===========================================
- Hits         7380     5887     -1493     
- Misses       1991     3484     +1493     
Impacted Files Coverage Δ
crates/storage/src/alloc/tests.rs 100.00% <ø> (ø)
...rates/storage/src/collections/binary_heap/tests.rs 96.96% <ø> (ø)
crates/storage/src/collections/bitstash/tests.rs 100.00% <ø> (ø)
crates/storage/src/collections/bitvec/tests.rs 100.00% <ø> (ø)
crates/storage/src/collections/vec/tests.rs 100.00% <ø> (ø)
crates/storage/src/collections/vec/mod.rs 97.29% <100.00%> (ø)
crates/storage/src/lazy/mod.rs 94.44% <100.00%> (+9.15%) ⬆️
crates/lang/codegen/src/traits.rs 0.00% <0.00%> (-100.00%) ⬇️
crates/lang/ir/src/ir/contract.rs 0.00% <0.00%> (-100.00%) ⬇️
crates/lang/codegen/src/generator/env.rs 0.00% <0.00%> (-100.00%) ⬇️
... and 61 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9b154e8...6e3b7e3. Read the comment docs.

@HCastano
Copy link
Contributor Author

HCastano commented Feb 3, 2022

We got rid of ink_storage::Vec in #1111, so I'm gonna close this

@HCastano HCastano closed this Feb 3, 2022
@HCastano HCastano deleted the hc-fix-spread-alloc-vector branch July 29, 2022 17:01
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.

3 participants