Skip to content

Commit 2aae619

Browse files
committed
Move MirPass to rustc_mir_transform.
Because that's now the only crate that uses it. Moving stuff out of `rustc_middle` is always welcome. I chose to use `impl crate::MirPass`/`impl crate::MirLint` (with explicit `crate::`) everywhere because that's the only mention of `MirPass`/`MirLint` used in all of these files. (Prior to this change, `MirPass` was mostly imported via `use rustc_middle::mir::*` items.)
1 parent 5410900 commit 2aae619

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+143
-162
lines changed

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/mir/index.html
44
55
use std::borrow::Cow;
6-
use std::cell::RefCell;
7-
use std::collections::hash_map::Entry;
86
use std::fmt::{self, Debug, Formatter};
97
use std::ops::{Index, IndexMut};
108
use std::{iter, mem};
@@ -26,7 +24,6 @@ use rustc_index::bit_set::BitSet;
2624
use rustc_index::{Idx, IndexSlice, IndexVec};
2725
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
2826
use rustc_serialize::{Decodable, Encodable};
29-
use rustc_session::Session;
3027
use rustc_span::source_map::Spanned;
3128
use rustc_span::symbol::Symbol;
3229
use rustc_span::{Span, DUMMY_SP};
@@ -106,65 +103,6 @@ impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> {
106103
}
107104
}
108105

109-
thread_local! {
110-
static PASS_NAMES: RefCell<FxHashMap<&'static str, &'static str>> = {
111-
RefCell::new(FxHashMap::default())
112-
};
113-
}
114-
115-
/// Converts a MIR pass name into a snake case form to match the profiling naming style.
116-
fn to_profiler_name(type_name: &'static str) -> &'static str {
117-
PASS_NAMES.with(|names| match names.borrow_mut().entry(type_name) {
118-
Entry::Occupied(e) => *e.get(),
119-
Entry::Vacant(e) => {
120-
let snake_case: String = type_name
121-
.chars()
122-
.flat_map(|c| {
123-
if c.is_ascii_uppercase() {
124-
vec!['_', c.to_ascii_lowercase()]
125-
} else if c == '-' {
126-
vec!['_']
127-
} else {
128-
vec![c]
129-
}
130-
})
131-
.collect();
132-
let result = &*String::leak(format!("mir_pass{}", snake_case));
133-
e.insert(result);
134-
result
135-
}
136-
})
137-
}
138-
139-
/// A streamlined trait that you can implement to create a pass; the
140-
/// pass will be named after the type, and it will consist of a main
141-
/// loop that goes over each available MIR and applies `run_pass`.
142-
pub trait MirPass<'tcx> {
143-
fn name(&self) -> &'static str {
144-
// FIXME Simplify the implementation once more `str` methods get const-stable.
145-
// See copypaste in `MirLint`
146-
const {
147-
let name = std::any::type_name::<Self>();
148-
crate::util::common::c_name(name)
149-
}
150-
}
151-
152-
fn profiler_name(&self) -> &'static str {
153-
to_profiler_name(self.name())
154-
}
155-
156-
/// Returns `true` if this pass is enabled with the current combination of compiler flags.
157-
fn is_enabled(&self, _sess: &Session) -> bool {
158-
true
159-
}
160-
161-
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>);
162-
163-
fn is_mir_dump_enabled(&self) -> bool {
164-
true
165-
}
166-
}
167-
168106
impl MirPhase {
169107
/// Gets the index of the current MirPhase within the set of all `MirPhase`s.
170108
///

compiler/rustc_middle/src/util/common.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,3 @@ pub fn to_readable_str(mut val: usize) -> String {
2020

2121
groups.join("_")
2222
}
23-
24-
// const wrapper for `if let Some((_, tail)) = name.rsplit_once(':') { tail } else { name }`
25-
pub const fn c_name(name: &'static str) -> &'static str {
26-
// FIXME Simplify the implementation once more `str` methods get const-stable.
27-
// and inline into call site
28-
let bytes = name.as_bytes();
29-
let mut i = bytes.len();
30-
while i > 0 && bytes[i - 1] != b':' {
31-
i = i - 1;
32-
}
33-
let (_, bytes) = bytes.split_at(i);
34-
match std::str::from_utf8(bytes) {
35-
Ok(name) => name,
36-
Err(_) => name,
37-
}
38-
}

compiler/rustc_mir_transform/src/abort_unwinding_calls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_target::spec::PanicStrategy;
2222
#[derive(PartialEq)]
2323
pub struct AbortUnwindingCalls;
2424

25-
impl<'tcx> MirPass<'tcx> for AbortUnwindingCalls {
25+
impl<'tcx> crate::MirPass<'tcx> for AbortUnwindingCalls {
2626
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
2727
let def_id = body.source.def_id();
2828
let kind = tcx.def_kind(def_id);

compiler/rustc_mir_transform/src/add_call_guards.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub use self::AddCallGuards::*;
3030
*
3131
*/
3232

33-
impl<'tcx> MirPass<'tcx> for AddCallGuards {
33+
impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
3434
fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
3535
self.add_call_guards(body);
3636
}

compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::util;
3737
/// blowup.
3838
pub struct AddMovesForPackedDrops;
3939

40-
impl<'tcx> MirPass<'tcx> for AddMovesForPackedDrops {
40+
impl<'tcx> crate::MirPass<'tcx> for AddMovesForPackedDrops {
4141
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4242
debug!("add_moves_for_packed_drops({:?} @ {:?})", body.source, body.span);
4343
add_moves_for_packed_drops(tcx, body);

compiler/rustc_mir_transform/src/add_retag.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn may_contain_reference<'tcx>(ty: Ty<'tcx>, depth: u32, tcx: TyCtxt<'tcx>) -> b
4848
}
4949
}
5050

51-
impl<'tcx> MirPass<'tcx> for AddRetag {
51+
impl<'tcx> crate::MirPass<'tcx> for AddRetag {
5252
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
5353
sess.opts.unstable_opts.mir_emit_retag
5454
}

compiler/rustc_mir_transform/src/add_subtyping_projections.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn subtype_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
6262
checker.patcher.apply(body);
6363
}
6464

65-
impl<'tcx> MirPass<'tcx> for Subtyper {
65+
impl<'tcx> crate::MirPass<'tcx> for Subtyper {
6666
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
6767
subtype_finder(tcx, body);
6868
}

compiler/rustc_mir_transform/src/check_alignment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use tracing::{debug, trace};
99

1010
pub struct CheckAlignment;
1111

12-
impl<'tcx> MirPass<'tcx> for CheckAlignment {
12+
impl<'tcx> crate::MirPass<'tcx> for CheckAlignment {
1313
fn is_enabled(&self, sess: &Session) -> bool {
1414
// FIXME(#112480) MSVC and rustc disagree on minimum stack alignment on x86 Windows
1515
if sess.target.llvm_target == "i686-pc-windows-msvc" {

compiler/rustc_mir_transform/src/check_const_item_mutation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use rustc_session::lint::builtin::CONST_ITEM_MUTATION;
66
use rustc_span::def_id::DefId;
77
use rustc_span::Span;
88

9-
use crate::{errors, MirLint};
9+
use crate::errors;
1010

1111
pub struct CheckConstItemMutation;
1212

13-
impl<'tcx> MirLint<'tcx> for CheckConstItemMutation {
13+
impl<'tcx> crate::MirLint<'tcx> for CheckConstItemMutation {
1414
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
1515
let mut checker = ConstMutationChecker { body, tcx, target_local: None };
1616
checker.visit_body(body);

compiler/rustc_mir_transform/src/check_packed_ref.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use rustc_middle::mir::*;
33
use rustc_middle::span_bug;
44
use rustc_middle::ty::{self, TyCtxt};
55

6-
use crate::{errors, util, MirLint};
6+
use crate::{errors, util};
77

88
pub struct CheckPackedRef;
99

10-
impl<'tcx> MirLint<'tcx> for CheckPackedRef {
10+
impl<'tcx> crate::MirLint<'tcx> for CheckPackedRef {
1111
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
1212
let param_env = tcx.param_env(body.source.def_id());
1313
let source_info = SourceInfo::outermost(body.span);

0 commit comments

Comments
 (0)