Skip to content

Commit c0f0f45

Browse files
committed
Don't actually create a full MIR stack frame when not needed
1 parent 2442823 commit c0f0f45

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/librustc_mir/const_eval.rs

+27-3
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,36 @@ pub fn mk_eval_cx<'a, 'tcx>(
6868
debug!("mk_eval_cx: {:?}, {:?}", instance, param_env);
6969
let span = tcx.def_span(instance.def_id());
7070
let mut ecx = EvalContext::new(tcx.at(span), param_env, CompileTimeInterpreter::new());
71-
let mir = ecx.load_mir(instance.def)?;
71+
let mir = mir::Mir::new(
72+
::std::iter::once(
73+
mir::BasicBlockData {
74+
statements: Vec::new(),
75+
is_cleanup: false,
76+
terminator: Some(mir::Terminator {
77+
source_info: mir::SourceInfo {
78+
scope: mir::OUTERMOST_SOURCE_SCOPE,
79+
span: DUMMY_SP,
80+
},
81+
kind: mir::TerminatorKind::Return,
82+
}),
83+
}
84+
).collect(), // basic blocks
85+
IndexVec::new(), // source_scopes
86+
mir::ClearCrossCrate::Clear, // source_scope_local_data
87+
IndexVec::new(), // promoted
88+
None, // yield ty
89+
::std::iter::once(mir::LocalDecl::new_return_place(tcx.types.unit, DUMMY_SP)).collect(),
90+
IndexVec::new(), //user_type_annotations
91+
0, // arg_count
92+
Vec::new(), // upvar_decls
93+
DUMMY_SP, // span
94+
Vec::new(), // control_flow_destroyed
95+
);
7296
// insert a stack frame so any queries have the correct substs
7397
ecx.push_stack_frame(
7498
instance,
75-
mir.span,
76-
mir,
99+
span,
100+
tcx.alloc_mir(mir),
77101
None,
78102
StackPopCleanup::Goto(None), // never pop
79103
)?;

0 commit comments

Comments
 (0)