mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Rename uneval_consts to required_consts
This commit is contained in:
parent
da9aa2dd55
commit
c1ed7cc95f
@ -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
|
||||
|
@ -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
|
||||
@ -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(),
|
||||
@ -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(),
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
@ -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(
|
||||
|
23
src/librustc_mir/transform/required_consts.rs
Normal file
23
src/librustc_mir/transform/required_consts.rs
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
use rustc_middle::mir::visit::Visitor;
|
||||
use rustc_middle::mir::{Constant, Location};
|
||||
use rustc_middle::ty::ConstKind;
|
||||
|
||||
pub struct UnevalConstSetVisitor<'a, 'tcx> {
|
||||
uneval_consts: &'a mut Vec<Constant<'tcx>>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> UnevalConstSetVisitor<'a, 'tcx> {
|
||||
pub fn new(uneval_consts: &'a mut Vec<Constant<'tcx>>) -> Self {
|
||||
UnevalConstSetVisitor { uneval_consts }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for UnevalConstSetVisitor<'a, 'tcx> {
|
||||
fn visit_constant(&mut self, constant: &Constant<'tcx>, _: Location) {
|
||||
let const_kind = constant.literal.val;
|
||||
|
||||
if let ConstKind::Unevaluated(_, _, _) = const_kind {
|
||||
self.uneval_consts.push(*constant);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user