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

58 files changed

Lines changed: 143 additions & 162 deletions

Some content is hidden

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

‎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-
staticPASS_NAMES:RefCell<FxHashMap<&'staticstr,&'staticstr>> = {
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-
fnto_profiler_name(type_name:&'staticstr) -> &'staticstr{
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-
}elseif 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-
pubtraitMirPass<'tcx>{
143-
fnname(&self) -> &'staticstr{
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-
fnprofiler_name(&self) -> &'staticstr{
153-
to_profiler_name(self.name())
154-
}
155-
156-
/// Returns `true` if this pass is enabled with the current combination of compiler flags.
157-
fnis_enabled(&self,_sess:&Session) -> bool{
158-
true
159-
}
160-
161-
fnrun_pass(&self,tcx:TyCtxt<'tcx>,body:&mutBody<'tcx>);
162-
163-
fnis_mir_dump_enabled(&self) -> bool{
164-
true
165-
}
166-
}
167-
168106
implMirPhase{
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-
pubconstfnc_name(name:&'staticstr) -> &'staticstr{
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-
letmut 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
pubstructAbortUnwindingCalls;
2424

25-
impl<'tcx>MirPass<'tcx>forAbortUnwindingCalls{
25+
impl<'tcx>crate::MirPass<'tcx>forAbortUnwindingCalls{
2626
fnrun_pass(&self,tcx:TyCtxt<'tcx>,body:&mutBody<'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>forAddCallGuards{
33+
impl<'tcx>crate::MirPass<'tcx>forAddCallGuards{
3434
fnrun_pass(&self,_tcx:TyCtxt<'tcx>,body:&mutBody<'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
pubstructAddMovesForPackedDrops;
3939

40-
impl<'tcx>MirPass<'tcx>forAddMovesForPackedDrops{
40+
impl<'tcx>crate::MirPass<'tcx>forAddMovesForPackedDrops{
4141
fnrun_pass(&self,tcx:TyCtxt<'tcx>,body:&mutBody<'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>forAddRetag{
51+
impl<'tcx>crate::MirPass<'tcx>forAddRetag{
5252
fnis_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>forSubtyper{
65+
impl<'tcx>crate::MirPass<'tcx>forSubtyper{
6666
fnrun_pass(&self,tcx:TyCtxt<'tcx>,body:&mutBody<'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
pubstructCheckAlignment;
1111

12-
impl<'tcx>MirPass<'tcx>forCheckAlignment{
12+
impl<'tcx>crate::MirPass<'tcx>forCheckAlignment{
1313
fnis_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-
usecrate::{errors,MirLint};
9+
usecrate::errors;
1010

1111
pubstructCheckConstItemMutation;
1212

13-
impl<'tcx>MirLint<'tcx>forCheckConstItemMutation{
13+
impl<'tcx>crate::MirLint<'tcx>forCheckConstItemMutation{
1414
fnrun_lint(&self,tcx:TyCtxt<'tcx>,body:&Body<'tcx>){
1515
letmut 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-
usecrate::{errors, util,MirLint};
6+
usecrate::{errors, util};
77

88
pubstructCheckPackedRef;
99

10-
impl<'tcx>MirLint<'tcx>forCheckPackedRef{
10+
impl<'tcx>crate::MirLint<'tcx>forCheckPackedRef{
1111
fnrun_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)