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

Support for infinitely nesting VarZeroVecs #1065

Merged
merged 18 commits into from
Sep 23, 2021

Conversation

Manishearth
Copy link
Member

@Manishearth Manishearth commented Sep 17, 2021

(this might be getting a little out of hand)

Things I have not done in this PR, but don't plan to do:

@jira-pull-request-webhook
Copy link

Notice: the branch changed across the force-push!

  • utils/zerovec/src/varzerovec/ule.rs is different

View Diff Across Force-Push

~ Your Friendly Jira-GitHub PR Checker Bot

@jira-pull-request-webhook
Copy link

Notice: the branch changed across the force-push!

  • utils/zerovec/src/varzerovec/owned.rs is different

View Diff Across Force-Push

~ Your Friendly Jira-GitHub PR Checker Bot

@Manishearth Manishearth marked this pull request as ready for review September 22, 2021 00:25
@Manishearth Manishearth requested a review from a team as a code owner September 22, 2021 00:25
@Manishearth Manishearth requested a review from sffc September 22, 2021 00:25
@Manishearth Manishearth changed the title WIP support for infinitely nesting VarZeroVecs Support for infinitely nesting VarZeroVecs Sep 22, 2021
utils/zerovec/src/ule/plain.rs Outdated Show resolved Hide resolved
Comment on lines +111 to +114
panic!(
"Called out-of-bounds insert() on VarZeroVec, index {} len {}",
index, len
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I prefer to return an error code than to panic. I know this differs from std::vec, but we have different requirements than std. The function could return Result<(), Error>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really agree; I'd like to match std::vec on behavior here. We can also provide a try_insert but I'd rather track fallible APIs separately? Because adding them would involve ZeroMap changes too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utils/zerovec/src/varzerovec/components.rs Show resolved Hide resolved
utils/zerovec/src/varzerovec/mod.rs Show resolved Hide resolved
utils/zerovec/src/varzerovec/mod.rs Outdated Show resolved Hide resolved
utils/zerovec/src/varzerovec/owned.rs Outdated Show resolved Hide resolved
utils/zerovec/src/varzerovec/ule.rs Show resolved Hide resolved
}

/// Get the number of elements in this vector
pub fn len(&self) -> usize {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grumble: I don't like defining these functions again and again and again.

Can we omit these for the time being and just ask people to call as_varzerovec() ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if this is going to be public we should probably not do that

utils/zerovec/src/varzerovec/ule.rs Show resolved Hide resolved
pub struct VarZeroVecULE<T> {
marker: PhantomData<[T]>,
/// The original slice this was constructed from
entire_slice: [u8],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought: could VarZeroVecOwned be a Box<VarZeroVecULE<T>> ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite because that's not growable. But yes I'd have loved to unify the two, I could use some kind of trait that encapsulates .get_components() but it's not really worth it IMO because that pollutes the public API with a confusing generic type.

@Manishearth Manishearth mentioned this pull request Sep 22, 2021
29 tasks
@Manishearth Manishearth removed the request for review from echeran September 23, 2021 01:11
Comment on lines +192 to +193
/// There must be no padding bytes involved in this type: [`Self::as_byte_slice()`] MUST return
/// a slice of initialized bytes provided that `Self` is initialized.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The safety docs are partly here and partly on the from_byte_slice_unchecked function
  2. Can we / should we say something like, mem::size_of_val(bytes) must equal mem::size_of_val(self) ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Done. I wrote new docs instead of moving them, from_byte_slice_unchecked still has duplicated safety docs, but I think it's good to be redundant for unsafe stuff.
  2. I don't think we need to, everything is totally safe even if the bytes are a subset, it just becomes nearly impossible to implement parse_byte_slice correctly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about equality when I said that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utils/zerovec/src/varzerovec/owned.rs Show resolved Hide resolved
@Manishearth Manishearth requested a review from sffc September 23, 2021 01:24
@Manishearth Manishearth merged commit 877707a into unicode-org:main Sep 23, 2021
@Manishearth Manishearth deleted the vzv-ule branch September 23, 2021 01:55
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.

2 participants