Skip to content

Commit 9839e5f

Browse files
committed
Remove slow HashSet during miri stack frame creation
1 parent b176285 commit 9839e5f

File tree

1 file changed

+11
-29
lines changed

1 file changed

+11
-29
lines changed

src/librustc_mir/interpret/eval_context.rs

+11-29
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::collections::HashSet;
21
use std::fmt::Write;
32

43
use rustc::hir::def_id::DefId;
@@ -383,40 +382,23 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
383382
) -> EvalResult<'tcx> {
384383
::log_settings::settings().indentation += 1;
385384

386-
/// Return the set of locals that have a storage annotation anywhere
387-
fn collect_storage_annotations<'mir, 'tcx>(mir: &'mir mir::Mir<'tcx>) -> HashSet<mir::Local> {
388-
use rustc::mir::StatementKind::*;
389-
390-
let mut set = HashSet::new();
391-
for block in mir.basic_blocks() {
392-
for stmt in block.statements.iter() {
393-
match stmt.kind {
394-
StorageLive(local) |
395-
StorageDead(local) => {
396-
set.insert(local);
397-
}
398-
_ => {}
399-
}
400-
}
401-
}
402-
set
403-
}
404-
405385
// Subtract 1 because `local_decls` includes the ReturnMemoryPointer, but we don't store a local
406386
// `Value` for that.
407387
let num_locals = mir.local_decls.len() - 1;
408388

409-
let locals = {
410-
let annotated_locals = collect_storage_annotations(mir);
411-
let mut locals = vec![None; num_locals];
412-
for i in 0..num_locals {
413-
let local = mir::Local::new(i + 1);
414-
if !annotated_locals.contains(&local) {
415-
locals[i] = Some(Value::ByVal(PrimVal::Undef));
389+
let mut locals = vec![Some(Value::ByVal(PrimVal::Undef)); num_locals];
390+
trace!("push_stack_frame: {:?}: num_bbs: {}", span, mir.basic_blocks().len());
391+
for block in mir.basic_blocks() {
392+
for stmt in block.statements.iter() {
393+
use rustc::mir::StatementKind::{StorageDead, StorageLive};
394+
match stmt.kind {
395+
StorageLive(local) | StorageDead(local) => if local.index() > 0 {
396+
locals[local.index() - 1] = None;
397+
},
398+
_ => {}
416399
}
417400
}
418-
locals
419-
};
401+
}
420402

421403
self.stack.push(Frame {
422404
mir,

0 commit comments

Comments
 (0)