Skip to content

Commit 4ea4dd2

Browse files
committed
Don't allocate a local array at all if there are no locals
1 parent b18b776 commit 4ea4dd2

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/librustc_mir/interpret/eval_context.rs

+22-16
Original file line numberDiff line numberDiff line change
@@ -383,24 +383,30 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
383383
) -> EvalResult<'tcx> {
384384
::log_settings::settings().indentation += 1;
385385

386-
let mut locals = IndexVec::from_elem(Some(Value::ByVal(PrimVal::Undef)), &mir.local_decls);
387-
match self.tcx.describe_def(instance.def_id()) {
388-
// statics and constants don't have `Storage*` statements, no need to look for them
389-
Some(Def::Static(..)) | Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) => {},
390-
_ => {
391-
trace!("push_stack_frame: {:?}: num_bbs: {}", span, mir.basic_blocks().len());
392-
for block in mir.basic_blocks() {
393-
for stmt in block.statements.iter() {
394-
use rustc::mir::StatementKind::{StorageDead, StorageLive};
395-
match stmt.kind {
396-
StorageLive(local) |
397-
StorageDead(local) => locals[local] = None,
398-
_ => {}
386+
let locals = if mir.local_decls.len() > 1 {
387+
let mut locals = IndexVec::from_elem(Some(Value::ByVal(PrimVal::Undef)), &mir.local_decls);
388+
match self.tcx.describe_def(instance.def_id()) {
389+
// statics and constants don't have `Storage*` statements, no need to look for them
390+
Some(Def::Static(..)) | Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) => {},
391+
_ => {
392+
trace!("push_stack_frame: {:?}: num_bbs: {}", span, mir.basic_blocks().len());
393+
for block in mir.basic_blocks() {
394+
for stmt in block.statements.iter() {
395+
use rustc::mir::StatementKind::{StorageDead, StorageLive};
396+
match stmt.kind {
397+
StorageLive(local) |
398+
StorageDead(local) => locals[local] = None,
399+
_ => {}
400+
}
399401
}
400402
}
401-
}
402-
},
403-
}
403+
},
404+
}
405+
locals
406+
} else {
407+
// don't allocate at all for trivial constants
408+
IndexVec::new()
409+
};
404410

405411
self.stack.push(Frame {
406412
mir,

0 commit comments

Comments
 (0)