Move promote_consts back to rustc_mir_transform.
This commit is contained in:
parent
75c68cfd2b
commit
8356802862
3 changed files with 7 additions and 15 deletions
|
@ -1,3 +1,2 @@
|
||||||
pub mod check_consts;
|
pub mod check_consts;
|
||||||
pub mod promote_consts;
|
|
||||||
pub mod validate;
|
pub mod validate;
|
||||||
|
|
|
@ -93,6 +93,7 @@ mod multiple_return_terminators;
|
||||||
mod normalize_array_len;
|
mod normalize_array_len;
|
||||||
mod nrvo;
|
mod nrvo;
|
||||||
mod prettify;
|
mod prettify;
|
||||||
|
mod promote_consts;
|
||||||
mod ref_prop;
|
mod ref_prop;
|
||||||
mod remove_noop_landing_pads;
|
mod remove_noop_landing_pads;
|
||||||
mod remove_storage_markers;
|
mod remove_storage_markers;
|
||||||
|
@ -114,7 +115,6 @@ mod uninhabited_enum_branching;
|
||||||
mod unreachable_prop;
|
mod unreachable_prop;
|
||||||
|
|
||||||
use rustc_const_eval::transform::check_consts::{self, ConstCx};
|
use rustc_const_eval::transform::check_consts::{self, ConstCx};
|
||||||
use rustc_const_eval::transform::promote_consts;
|
|
||||||
use rustc_const_eval::transform::validate;
|
use rustc_const_eval::transform::validate;
|
||||||
use rustc_mir_dataflow::rustc_peek;
|
use rustc_mir_dataflow::rustc_peek;
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ use rustc_index::{Idx, IndexSlice, IndexVec};
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::{cmp, iter, mem};
|
use std::{cmp, iter, mem};
|
||||||
|
|
||||||
use crate::transform::check_consts::{qualifs, ConstCx};
|
use rustc_const_eval::transform::check_consts::{qualifs, ConstCx};
|
||||||
|
|
||||||
/// A `MirPass` for promotion.
|
/// A `MirPass` for promotion.
|
||||||
///
|
///
|
||||||
|
@ -64,7 +64,7 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {
|
||||||
|
|
||||||
/// State of a temporary during collection and promotion.
|
/// State of a temporary during collection and promotion.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||||
pub enum TempState {
|
enum TempState {
|
||||||
/// No references to this temp.
|
/// No references to this temp.
|
||||||
Undefined,
|
Undefined,
|
||||||
/// One direct assignment and any number of direct uses.
|
/// One direct assignment and any number of direct uses.
|
||||||
|
@ -78,18 +78,11 @@ pub enum TempState {
|
||||||
PromotedOut,
|
PromotedOut,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TempState {
|
|
||||||
pub fn is_promotable(&self) -> bool {
|
|
||||||
debug!("is_promotable: self={:?}", self);
|
|
||||||
matches!(self, TempState::Defined { .. })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A "root candidate" for promotion, which will become the
|
/// A "root candidate" for promotion, which will become the
|
||||||
/// returned value in a promoted MIR, unless it's a subset
|
/// returned value in a promoted MIR, unless it's a subset
|
||||||
/// of a larger candidate.
|
/// of a larger candidate.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||||
pub struct Candidate {
|
struct Candidate {
|
||||||
location: Location,
|
location: Location,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +155,7 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collect_temps_and_candidates<'tcx>(
|
fn collect_temps_and_candidates<'tcx>(
|
||||||
ccx: &ConstCx<'_, 'tcx>,
|
ccx: &ConstCx<'_, 'tcx>,
|
||||||
) -> (IndexVec<Local, TempState>, Vec<Candidate>) {
|
) -> (IndexVec<Local, TempState>, Vec<Candidate>) {
|
||||||
let mut collector = Collector {
|
let mut collector = Collector {
|
||||||
|
@ -676,7 +669,7 @@ impl<'tcx> Validator<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(eddyb) remove the differences for promotability in `static`, `const`, `const fn`.
|
// FIXME(eddyb) remove the differences for promotability in `static`, `const`, `const fn`.
|
||||||
pub fn validate_candidates(
|
fn validate_candidates(
|
||||||
ccx: &ConstCx<'_, '_>,
|
ccx: &ConstCx<'_, '_>,
|
||||||
temps: &mut IndexSlice<Local, TempState>,
|
temps: &mut IndexSlice<Local, TempState>,
|
||||||
candidates: &[Candidate],
|
candidates: &[Candidate],
|
||||||
|
@ -930,7 +923,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn promote_candidates<'tcx>(
|
fn promote_candidates<'tcx>(
|
||||||
body: &mut Body<'tcx>,
|
body: &mut Body<'tcx>,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
mut temps: IndexVec<Local, TempState>,
|
mut temps: IndexVec<Local, TempState>,
|
Loading…
Add table
Add a link
Reference in a new issue