-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Remove slow HashSet during miri stack frame creation #49274
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.
Looks good to me!
If this is something that is also called for trivial constants, I would suggest adding a fast path for that case, e.g.:
if num_locals == 0 {
vec![]
} else {
// scan blocks and statements
}
r=me with the optimization implemented (if it makes sense). |
Even trivial constants have locals. But you're right, we can add a fast path: Constants and statics don't contain any |
@bors r=michaelwoerister |
📌 Commit 9fa14e4 has been approved by |
let local = mir::Local::new(i + 1); | ||
if !annotated_locals.contains(&local) { | ||
locals[i] = Some(Value::ByVal(PrimVal::Undef)); | ||
let mut locals = vec![Some(Value::ByVal(PrimVal::Undef)); num_locals]; |
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.
Please use IndexVec
here.
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.
The reason we didn't use that is theat we don't actually use the return pointer local at all.
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.
Fixed, the waste of one space is massively outweighted by the many .index() - 1
calls we had.
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.
Are you sure? Now you have to allocate something on the heap even if it's never used.
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.
For truly trivial constants (const FOO: usize = 42;
) that is true, but even const FOO: usize = 40 + 2;
will create that heap alloc.
I added a fast path for trivial constants
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.
👍
fn collect_storage_annotations<'mir, 'tcx>(mir: &'mir mir::Mir<'tcx>) -> HashSet<mir::Local> { | ||
use rustc::mir::StatementKind::*; | ||
|
||
let mut set = HashSet::new(); |
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.
Would be a good idea to check for Hash{Map,Set}
used by miri code: if it needs to be a hash map/set, it should be FxHash{Map,Set}
instead.
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.
Done, found a few in interpret::memory
@bors r- |
let old = self.locals[local.index() - 1]; | ||
self.locals[local.index() - 1] = None; | ||
let old = self.locals[local]; | ||
self.locals[local] = None; | ||
return Ok(old); |
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.
This is just Ok(self.locals[local].take())
@bors r=michaelwoerister,eddyb |
📌 Commit f9019ae has been approved by |
…er,eddyb Remove slow HashSet during miri stack frame creation fixes rust-lang#49237 probably has a major impact on rust-lang#48846 r? @michaelwoerister cc @eddyb I know you kept telling me to use vectors instead of hash containers... Now I know why.
…er,eddyb Remove slow HashSet during miri stack frame creation fixes rust-lang#49237 probably has a major impact on rust-lang#48846 r? @michaelwoerister cc @eddyb I know you kept telling me to use vectors instead of hash containers... Now I know why.
…er,eddyb Remove slow HashSet during miri stack frame creation fixes rust-lang#49237 probably has a major impact on rust-lang#48846 r? @michaelwoerister cc @eddyb I know you kept telling me to use vectors instead of hash containers... Now I know why.
fixes #49237
probably has a major impact on #48846
r? @michaelwoerister
cc @eddyb I know you kept telling me to use vectors instead of hash containers... Now I know why.