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

PartialSumMap refactor #136

Merged
merged 4 commits into from
Jun 17, 2022
Merged

PartialSumMap refactor #136

merged 4 commits into from
Jun 17, 2022

Conversation

Ekleog
Copy link

@Ekleog Ekleog commented Jun 16, 2022

As promised, the PartialSumMap refactor that gets rid of the sealed trait and the need for an explicit panic. Runtime drawback is one additional u32 being stored, which is negligible as it's not even a linear addition.

I also added a (bolero-based as we're not fuzzing this on nayduck yet anyway) fuzzer so that there's a good chance we detect regressions in this code just by running tests (bolero runs the fuzzer 1024 times by default when running tests)

Copy link
Collaborator

@nagisa nagisa left a comment

Choose a reason for hiding this comment

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

Overall LGTM.

@@ -16,9 +16,18 @@ name = "wasmer_types"
[dependencies]
thiserror = "1.0"
indexmap = { version = "1.6" }
num-traits = "0.2.15"
Copy link
Collaborator

Choose a reason for hiding this comment

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

My intuition here would be to “just” hard code the u32 key instead, over bringing in this dependency. OTOH, num-traits is already in the dep-graph so 🤷.

Copy link
Author

Choose a reason for hiding this comment

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

My thoughts are, with num-traits we get the same benefits as with the sealed trait previously, aka being able to open-source PartialSumMap as a split crate easily :)

/// Get the current (virtual) size of this map. This is the sum of all `count` arguments passed to `push` until now.
///
/// `O(1)`
pub fn size(&self) -> K {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I’m torn on the K return type here. Intuitively I’d expect this to return usize like the len functions for other datastructures do, even if this one isn’t really limited to usize elements. So probably:

Suggested change
pub fn size(&self) -> K {
pub fn len(&self) -> usize {

Copy link
Author

Choose a reason for hiding this comment

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

I've just pushed a commit documenting why I'm not returning usize here: basically, if K is a BigInt type, it could go overboard just by having a few really large intervals of BigInts.

And that's also the reason why I didn't pick len(), because len() is usually used with an usize return, and so I thought it'd be confusing. That said I feel much less strongly about this one, WDYT?

@Ekleog
Copy link
Author

Ekleog commented Jun 17, 2022

I've also pushed a commit removing the clone() in size(), but I'm much less sure about it (it basically forces our impl to keep a size member forever if we were to open-source it separately). WDYT?

@nagisa
Copy link
Collaborator

nagisa commented Jun 17, 2022

it basically forces our impl to keep a size member forever

Fortunately this is not libstd and we don’t need to worry about never publishing a major version bump ^^


And that's also the reason why I didn't pick len(), because len() is usually used with an usize return, and so I thought it'd be confusing. That said I feel much less strongly about this one, WDYT?

Ah, well, I guess this will work out okay.

@Ekleog
Copy link
Author

Ekleog commented Jun 17, 2022

Fortunately this is not libstd and we don’t need to worry about never publishing a major version bump ^^

Gud point 😅

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