-
Notifications
You must be signed in to change notification settings - Fork 256
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
wasmparser
: Add no-hash-maps
crate feature & support
#1517
Comments
Thanks for opening an issue for this! How about To ensure that this works well with Cargo features we'll need to change the type aliases for Renaming |
So to answer my question; would
So are you saying that the current |
While implementing the initial parts of this issue I think I just answered one of the questions myself. We indeed want proper types wrapping either |
Yeah cargo features are required to be additive to work and in this case that's not what's being toggled so we need an opaque new type to be able to switch the implementation under the hood. For the feature that was my thinking, it's possible to just trees and std just on an opt-in basis. Not being able to use hash maps I think is relatively niche so I think it's ok to just kinda do whatever works here. Can always change it in the future if necessary |
Okay. I will open a draft PR soon so we can comment there to have some code to work/review. |
High-level API ProposalCurrently the My proposal is to make it look like this: Where each submodule of the
This design also opens doors for future data structures that are often based on hash maps such as string interners. @alexcrichton what do you think about this high-level API design? |
wasmparser
: Add btreemap
-modewasmparser
: Add no-hash-maps
crate feature & support
That seems reasonable to me yeah, thanks! |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
Speaking of which, why doesn't If |
There's some more discussion of that on bytecodealliance/wasmtime#8341, but my personal reasoning is that I'd rather not rock the boat as I don't fully understand the impact of such a change. I don't feel like there's a great sense for precisely what the attack vector is and/or how feasible it is to exploit something in no_std mode vs not. In the abstract I would like to keep no_std as similar to "std mode" as possible since "std mode" is much more heavily tested and divergences are where bugs typically lie. I've wanted to do #1532 for a long time anyway, and while I understand that the more dependencies the less merrier I basically don't personally feel equipped to say whether this is a change that should be made or not. |
@Shnatsel @alexcrichton I use very similar data structures in Wasmi via its Another explanation for the performance difference could be that in |
This issue follows #1493 and is about the implementation proposals introduced in bytecodealliance/wasmtime#8341 (comment) and detailed in bytecodealliance/wasmtime#8341 (comment).
My personal questions about this before I start with the implementation:
btreemap
-based data structures be enabled?#[cfg(feature = "x")]
: Simple design but may be sub-optimal in cases wherestd
is enabled.#[cfg(and(feature = "x", not(feature = "std"))]
: Less transparent design but uses more efficient hashmaps whenever possible. For Wasmi this would be fine I suppose. I think this is the better design since you only really needs to avoid hashmaps forno_std
mode since understd
mode the crate has a proper random source.Currently the type aliases can be found in this file:
https://github.com/bytecodealliance/wasm-tools/blob/main/crates/wasmparser/src/map.rs
So if I understood correctly the PR for
btreemap
-based data structures shall introduce a new type for eachIndexMap
andHashMap
that either wrapshashbrown::HashMap
orBTreeMap
orindexmap::IndexMap
or our custom solution, right?Is this required so that we can have unified trait bounds that require both
T: Ord + Hash
to make uses always compile whatever mode is enabled?Also we may want to rename the
HashMap
andHashSet
type aliases to justMap
andSet
since then they are not necessarily hash based.The text was updated successfully, but these errors were encountered: