-
Notifications
You must be signed in to change notification settings - Fork 42
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
refactor: use &'static [PReg]
instead of Vec<PReg>
#208
base: main
Are you sure you want to change the base?
refactor: use &'static [PReg]
instead of Vec<PReg>
#208
Conversation
env.preferred_regs_by_class[RegClass::Int as usize].clone(), | ||
env.preferred_regs_by_class[RegClass::Float as usize].clone(), | ||
env.preferred_regs_by_class[RegClass::Vector as usize].clone(), | ||
Vec::from(env.preferred_regs_by_class[RegClass::Int as usize]), |
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.
don't love this, open for better ideas
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.
Maybe use .to_owned()
instead of Vec::from
?
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.
hmm, yeah doesn't really change anything about it but might look nicer
Co-authored-by: bjorn3 <[email protected]>
Hmm seems libfuzz doesn't like |
interestingly I locally can't replicate the CI fail |
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.
A few comments below -- thanks for working on this! I think the general shape is right, I just have some thoughts on the way the fuzzing testcase generation is working (we need to avoid leaks).
/// will have very few of and generally want to keep around for their entire lifetime. | ||
/// In order to make static initialization easier the registers lists are static slices instead | ||
/// of `Vec`s. If your use case depends on dynamically creating the registers lists, consider | ||
/// [`Vec::leak`]. |
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'd prefer not to give this suggestion in the doc-comment: since it's parameterized on a lifetime (rather than hardcoding 'static
), it's possible to build a MachineEnv
dynamically that is a borrowed view on owned Vec
s, basically giving the same capabilities as before. This is fairly idiomatic in Rust, so I don't think we need a special note or recommendation.
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.
ah yeah good catch, that was from before I allowed any lifetimes. This notice doesn't make much sense anymore
] | ||
}) | ||
.collect(); | ||
let fixed_stack_slots = Vec::leak( |
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 think we need to avoid Vec::leak
here: fuzzing will continually generate new functions with machine envs, and we cannot allocate indefinitely. Can you build a static initializer, since the range (32..63
) is static?
.collect(), | ||
vec![], | ||
vec![], | ||
Vec::leak( |
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.
We definitely can't leak while fuzzing -- can we instead have a few static MachineEnv
s in scope, and pick one of them? We don't necessarily need to fuzz with arbitrary no_of_regs
, just with a few values that are interesting -- the two extremes of its range and a few in the middle, for example.
This PR makes
MachineEnv
use&'static [PReg]
instead ofVec<PReg>
to make it possible to placeMachineEnv
intostatic
s as part of bytecodealliance/wasmtime#8489.Edit: as it turns out serialization makes this not quite as trivial,
serde
can't deserialize into slices (had forgotten that) so I introduced a newSerializableMachineEnv
type in the spirit ofSerializableFunction
to let consumers still serialize a machine env if required.related: #177.