Skip to content

Commit fa248cd

Browse files
committed
add some comments explaining how the required_consts stuff fits together
1 parent acb7c21 commit fa248cd

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

compiler/rustc_codegen_ssa/src/mir/constant.rs

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
2121
}
2222

2323
pub fn eval_mir_constant(&self, constant: &mir::ConstOperand<'tcx>) -> mir::ConstValue<'tcx> {
24+
// `MirUsedCollector` visited all constants before codegen began, so if we got here there
25+
// can be no more constants that fail to evaluate.
2426
self.monomorphize(constant.const_)
2527
.eval(self.cx.tcx(), ty::ParamEnv::reveal_all(), Some(constant.span))
2628
.expect("erroneous constant not captured by required_consts")

compiler/rustc_codegen_ssa/src/mir/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
209209
caller_location: None,
210210
};
211211

212+
// It may seem like we should iterate over `required_consts` to ensure they all successfully
213+
// evaluate; however, the `MirUsedCollector` already did that during the collection phase of
214+
// monomorphization so we don't have to do it again.
215+
212216
fx.per_local_var_debug_info = fx.compute_per_local_var_debug_info(&mut start_bx);
213217

214218
let memory_locals = analyze::non_ssa_locals(&fx);

compiler/rustc_middle/src/mir/visit.rs

+2
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ macro_rules! make_mir_visitor {
184184

185185
visit_place_fns!($($mutability)?);
186186

187+
/// This is called for every constant in the MIR body and every `required_consts`
188+
/// (i.e., including consts that have been dead-code-eliminated).
187189
fn visit_constant(
188190
&mut self,
189191
constant: & $($mutability)? ConstOperand<'tcx>,

compiler/rustc_monomorphize/src/collector.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,8 @@ fn collect_used_items<'tcx>(
14261426
);
14271427
}
14281428

1429+
// Here we rely on the visitor also visiting `required_consts`, so that we evaluate them
1430+
// and abort compilation if any of them errors.
14291431
MirUsedCollector {
14301432
tcx,
14311433
body: &body,

0 commit comments

Comments
 (0)