Skip to content

Commit

Permalink
Move promote_consts back to rustc_mir_transform.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Jan 8, 2024
1 parent 75c68cf commit 8356802
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_const_eval/src/transform/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod check_consts;
pub mod promote_consts;
pub mod validate;
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ mod multiple_return_terminators;
mod normalize_array_len;
mod nrvo;
mod prettify;
mod promote_consts;
mod ref_prop;
mod remove_noop_landing_pads;
mod remove_storage_markers;
Expand All @@ -114,7 +115,6 @@ mod uninhabited_enum_branching;
mod unreachable_prop;

use rustc_const_eval::transform::check_consts::{self, ConstCx};
use rustc_const_eval::transform::promote_consts;
use rustc_const_eval::transform::validate;
use rustc_mir_dataflow::rustc_peek;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use rustc_index::{Idx, IndexSlice, IndexVec};
use std::cell::Cell;
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.
///
Expand Down Expand Up @@ -64,7 +64,7 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {

/// State of a temporary during collection and promotion.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum TempState {
enum TempState {
/// No references to this temp.
Undefined,
/// One direct assignment and any number of direct uses.
Expand All @@ -78,18 +78,11 @@ pub enum TempState {
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
/// returned value in a promoted MIR, unless it's a subset
/// of a larger candidate.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct Candidate {
struct Candidate {
location: Location,
}

Expand Down Expand Up @@ -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>,
) -> (IndexVec<Local, TempState>, Vec<Candidate>) {
let mut collector = Collector {
Expand Down Expand Up @@ -676,7 +669,7 @@ impl<'tcx> Validator<'_, 'tcx> {
}

// FIXME(eddyb) remove the differences for promotability in `static`, `const`, `const fn`.
pub fn validate_candidates(
fn validate_candidates(
ccx: &ConstCx<'_, '_>,
temps: &mut IndexSlice<Local, TempState>,
candidates: &[Candidate],
Expand Down Expand Up @@ -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>,
tcx: TyCtxt<'tcx>,
mut temps: IndexVec<Local, TempState>,
Expand Down

0 comments on commit 8356802

Please sign in to comment.