-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Use the capacity from the entities Vec to initialize Table columns #20528
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
Use the capacity from the entities Vec to initialize Table columns #20528
Conversation
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.
Nit: could this invariant be better documented on Table
's definition, each Table
creation and Table
's realloc
?
Am I understanding this comment correctly that currently |
Unless they change the safety invariants of already established stable APIs, I don't think so. The safety invariant states it just needs to be called with the same Layout that was used to allocate it, and that's what we're already doing / fixing with this PR. |
Upon further inspection, it seems like we weren't actually validating one of the safety invariants of Added the comments @SkiFire13 mentioned. |
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.
Look good, just left a couple of comments for some typos.
Co-authored-by: Giacomo Stevanato <[email protected]>
Objective
When working with
realloc
, it's a safety invariant to pass in the existing layout of the allocation that is being reallocated. This may not be the case with newly createdTable
s.Vec::with_capacity
's documentation states that it will return an allocation with enough space for at leastcapacity
elements, not exactlycapacity
. This means thatentities.capacity()
may be greater than the provided capacity. As theThinColumn
s use this as their capacity, the new Layout fed torealloc
will not match the allocation originally provided toalloc
. This is unsound.While investigating this, I also found that we were not validating that the total capacity of
BlobArray
's layout upon reallocation were less thanisize::MAX
viaarray_layout_unchecked
.Solution
Begin
Table
construction by allocating theentities
Vec, and use it's capacity to allocate the columns instead of directly feeding the provided capacity intoThinColumn::with_capacity
.Replace the
array_layout_unchecked
call with a safe call toarray_layout
, and panic if it fails.Testing
Tested this locally against existing unit tests and miri.