-
Notifications
You must be signed in to change notification settings - Fork 455
Implement storage::vec::Slice #852
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
Conversation
@Robbepop do you have some preliminary feedback? |
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.
So far I think it's looking alright.
I know it's early, but I still want to make sure it's said: make sure errors are correctly instead of unwrap()
-ing 😄
Totally agree :) |
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 haven't been able to look at everything just yet, mainly went through the Slice
/SlideMut
impls today
Switching reviewers from Robin to Michi since Robin is on vacation |
Co-authored-by: Hernando Castano <[email protected]>
Co-authored-by: Hernando Castano <[email protected]>
Most of the tests have been ported from Aside from that, spell-check seems to trip over some symbols. These doc comments mirror standard, so do I add those to the config? |
Yeah, just add the words which you think are OK to the |
I need to implement some tests which verify that compilation fails. Is there a policy on including (test) dependencies? I was thinking of using https://github.com/Manishearth/compiletest-rs. |
@KaiserKarel nope, no policies here. However, if you try and introduce a |
But then how will we know if a 'bool-is-true' 😄 |
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.
Sorry for the late reply.
I have trouble with this PR since it looks to me as if the author simply copy'n'pasted a huge amount of code from the Rust standard library and fiddled around with it until it compiled again without making proper ink! specific design considerations whether the Rust standard library design is actually applicable to ink! itself.
One example for this is the ContiguousStorage
trait which totally makes sense in Rust standard library means but I do not currently fully understand what the needs and reasoning for it is with respect to ink! storage model.
I do see the need for storage slices for storage vectors although I believe we need a more thorough approach that respects ink!'s very special storage model in all details.
I find this comment a bit attacking, as I went through quite some iterations, attempting to deduplicate a lot of code to abstract over mutable iterators etc, before then copying code from the stdlib to provide an almost identical interface. Spent a few evenings looking through this, and I believe that This PR is of course a proposal implementation (although I have been a bit too busy lately to finish it up). I'd love some feedback on why it does not work for Ink's storage models. I feel like the trait is a bit verbose and a lot of code gets added to the codebase, but couldn't find a simpler implementation. |
Sorry, I did not want to sound attacking towards you since you obviously put a lot of effort into the PR. My critique is more seen from 10k feet above point of view since the whole code in the PR looks a lot just like copy'n'pasted (which it is) and there is a natural aversion against copy'n'pasted code for me since there are often just way too many things you can oversee while doing so, even if done very cautiously. However, if you view this on a more high-level point of view where you view storage cells as memory cells you could definitely apply contiguous storage notation to them and instead of pointer arithmetic you could use storage key arithmetic. So you actually got a point there! |
No problem :). With the copying, I attempted to find a balance with mimicking the stdlib as much as possible, as it seems to me that ink attempts to make the storage types mimick the regular stdlib collections with a drop in replacement. I can of course remove some/all of the helper functions if that is desirable. In this case, ContiguousStorage might be half-appropriately named, if your first indication is pointer-arithmetic. Naming is of course the hardest problem. Perhaps renaming it to However there is a class of collections which can safely provide multiple mutable references/slices, in the case of |
I think
Yeah that bridge between |
Aside from the feedback needing to be added, I feel uncomfortable merging this without #853. Not intending to be the one to introduce UB in |
@KaiserKarel We've decided to close this PR. The reasoning is that we're looking to migrate all our data structures away from caching based to something more lightweight (see #945). While it would be nice to have a Thanks for spending time working on this, we appreciate it! |
I cannot follow how a |
Sure, maybe I didn't think through all the technical nuances here, but point is we are looking to move to a more lightweight data-structure based world. What specific building blocks we use is kinda irrelevant, but either way I think we'd need to have big changes to this PR (or other PRs, like to introduce a non-caching |
Initial possible design for slices in storage::vec::Vec. If this design is safe and agreed upon, I'll add useful traits such as Iterator and co.
Due to the index trait returning a reference, we cannot slice like so:
as the implementation creates owned slices. I've not found a way around this yet.