Skip to content

Commit

Permalink
Rename uneval_consts to required_consts
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Apr 23, 2020
1 parent da9aa2d commit c1ed7cc
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/mod.rs
Expand Up @@ -191,7 +191,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(

fx.per_local_var_debug_info = fx.compute_per_local_var_debug_info();

for const_ in &mir.uneval_consts {
for const_ in &mir.required_consts {
if let Err(err) = fx.eval_mir_constant(const_) {
match err {
// errored or at least linted
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_middle/mir/mod.rs
Expand Up @@ -156,8 +156,9 @@ pub struct Body<'tcx> {
/// A span representing this MIR, for error reporting.
pub span: Span,

/// Unevaluated consts to evaluate them regardless of being optimized out
pub uneval_consts: Vec<Constant<'tcx>>,
/// Constants that are required to evaluate successfully for this MIR to be well-formed.
/// We hold in this field all the constants we are not able to evaluate yet.
pub required_consts: Vec<Constant<'tcx>>,

/// The user may be writing e.g. &[(SOME_CELL, 42)][i].1 and this would get promoted, because
/// we'd statically know that no thing with interior mutability will ever be available to the
Expand Down Expand Up @@ -206,7 +207,7 @@ impl<'tcx> Body<'tcx> {
spread_arg: None,
var_debug_info,
span,
uneval_consts: Vec::new(),
required_consts: Vec::new(),
ignore_interior_mut_in_const_validation: false,
control_flow_destroyed,
predecessor_cache: PredecessorCache::new(),
Expand All @@ -231,7 +232,7 @@ impl<'tcx> Body<'tcx> {
arg_count: 0,
spread_arg: None,
span: DUMMY_SP,
uneval_consts: Vec::new(),
required_consts: Vec::new(),
control_flow_destroyed: Vec::new(),
generator_kind: None,
var_debug_info: Vec::new(),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_middle/mir/visit.rs
Expand Up @@ -289,7 +289,7 @@ macro_rules! make_mir_visitor {

self.visit_span(&$($mutability)? body.span);

for const_ in &$($mutability)? body.uneval_consts {
for const_ in &$($mutability)? body.required_consts {
let location = START_BLOCK.start_location();
self.visit_constant(const_, location);
}
Expand Down
14 changes: 8 additions & 6 deletions src/librustc_mir/transform/inline.rs
Expand Up @@ -124,12 +124,14 @@ impl Inliner<'tcx> {
};

// Copy only unevaluated constants from the callee_body into the caller_body.
// Although we are only pushing `ConstKind::Unevaluated` consts to uneval_consts,
// here we may not only have `ConstKind::Unevaluated` because we are calling
// `subst_and_normalize_erasing_regions`.
caller_body.uneval_consts.extend(callee_body.uneval_consts.iter().copied().filter(
|&constant| matches!(constant.literal.val, ConstKind::Unevaluated(_, _, _)),
));
// Although we are only pushing `ConstKind::Unevaluated` consts to
// `required_consts`, here we may not only have `ConstKind::Unevaluated`
// because we are calling `subst_and_normalize_erasing_regions`.
caller_body.required_consts.extend(
callee_body.required_consts.iter().copied().filter(|&constant| {
matches!(constant.literal.val, ConstKind::Unevaluated(_, _, _))
}),
);

let start = caller_body.basic_blocks().len();
debug!("attempting to inline callsite {:?} - body={:?}", callsite, callee_body);
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_mir/transform/mod.rs
Expand Up @@ -30,11 +30,11 @@ pub mod no_landing_pads;
pub mod promote_consts;
pub mod qualify_min_const_fn;
pub mod remove_noop_landing_pads;
pub mod required_consts;
pub mod rustc_peek;
pub mod simplify;
pub mod simplify_branches;
pub mod simplify_try;
pub mod uneval_const_set;
pub mod uninhabited_enum_branching;
pub mod unreachable_prop;

Expand Down Expand Up @@ -240,13 +240,13 @@ fn mir_validated(

let mut body = tcx.mir_const(def_id).steal();

let mut uneval_consts = Vec::new();
let mut uneval_const_visitor =
self::uneval_const_set::UnevalConstSetVisitor::new(&mut uneval_consts);
let mut required_consts = Vec::new();
let mut required_consts_visitor =
self::required_consts::RequiredConstsVisitor::new(&mut required_consts);
for (bb, bb_data) in traversal::reverse_postorder(&body) {
uneval_const_visitor.visit_basic_block_data(bb, bb_data);
required_consts_visitor.visit_basic_block_data(bb, bb_data);
}
body.uneval_consts = uneval_consts;
body.required_consts = required_consts;

let promote_pass = promote_consts::PromoteTemps::default();
run_passes(
Expand Down
23 changes: 23 additions & 0 deletions src/librustc_mir/transform/required_consts.rs
@@ -0,0 +1,23 @@
use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::{Constant, Location};
use rustc_middle::ty::ConstKind;

pub struct RequiredConstsVisitor<'a, 'tcx> {
required_consts: &'a mut Vec<Constant<'tcx>>,
}

impl<'a, 'tcx> RequiredConstsVisitor<'a, 'tcx> {
pub fn new(required_consts: &'a mut Vec<Constant<'tcx>>) -> Self {
RequiredConstsVisitor { required_consts }
}
}

impl<'a, 'tcx> Visitor<'tcx> for RequiredConstsVisitor<'a, 'tcx> {
fn visit_constant(&mut self, constant: &Constant<'tcx>, _: Location) {
let const_kind = constant.literal.val;

if let ConstKind::Unevaluated(_, _, _) = const_kind {
self.required_consts.push(*constant);
}
}
}
23 changes: 0 additions & 23 deletions src/librustc_mir/transform/uneval_const_set.rs

This file was deleted.

0 comments on commit c1ed7cc

Please sign in to comment.