Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4ed0f0d

Browse files
authoredSep 3, 2024
Rollup merge of #129926 - nnethercote:mv-SanityCheck-and-MirPass, r=cjgillot
Move `SanityCheck` and `MirPass` They are currently in `rustc_middle`. This PR moves them to `rustc_mir_transform`, which makes more sense. r? ``@cjgillot``
2 parents 485fd38 + 0b2b03c commit 4ed0f0d

Some content is hidden

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

59 files changed

+201
-211
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-
}

0 commit comments

Comments
 (0)
Please sign in to comment.