Skip to content

Commit 4ed0f0d

Browse files
authored
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

59 files changed

Lines changed: 201 additions & 211 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_dataflow/src/rustc_peek.rs‎

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_ast::MetaItem;
22
use rustc_hir::def_id::DefId;
33
use rustc_index::bit_set::BitSet;
4-
use rustc_middle::mir::{self,Body,Local,Location,MirPass};
4+
use rustc_middle::mir::{self,Body,Local,Location};
55
use rustc_middle::ty::{self,Ty,TyCtxt};
66
use rustc_span::symbol::{sym,Symbol};
77
use rustc_span::Span;
@@ -18,8 +18,6 @@ use crate::impls::{
1818
usecrate::move_paths::{HasMoveData,LookupResult,MoveData,MovePathIndex};
1919
usecrate::{Analysis,JoinSemiLattice,ResultsCursor};
2020

21-
pubstructSanityCheck;
22-
2321
fnhas_rustc_mir_with(tcx:TyCtxt<'_>,def_id:DefId,name:Symbol) -> Option<MetaItem>{
2422
for attr in tcx.get_attrs(def_id, sym::rustc_mir){
2523
let items = attr.meta_item_list();
@@ -33,53 +31,50 @@ fn has_rustc_mir_with(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol) -> Option<Me
3331
None
3432
}
3533

36-
// FIXME: This should be a `MirLint`, but it needs to be moved back to `rustc_mir_transform` first.
37-
impl<'tcx>MirPass<'tcx>forSanityCheck{
38-
fnrun_pass(&self,tcx:TyCtxt<'tcx>,body:&mutBody<'tcx>){
39-
let def_id = body.source.def_id();
40-
if !tcx.has_attr(def_id, sym::rustc_mir){
41-
debug!("skipping rustc_peek::SanityCheck on {}", tcx.def_path_str(def_id));
42-
return;
43-
}else{
44-
debug!("running rustc_peek::SanityCheck on {}", tcx.def_path_str(def_id));
45-
}
34+
pubfnsanity_check<'tcx>(tcx:TyCtxt<'tcx>,body:&Body<'tcx>){
35+
let def_id = body.source.def_id();
36+
if !tcx.has_attr(def_id, sym::rustc_mir){
37+
debug!("skipping rustc_peek::SanityCheck on {}", tcx.def_path_str(def_id));
38+
return;
39+
}else{
40+
debug!("running rustc_peek::SanityCheck on {}", tcx.def_path_str(def_id));
41+
}
4642

47-
let param_env = tcx.param_env(def_id);
48-
let move_data = MoveData::gather_moves(body, tcx, param_env, |_| true);
43+
let param_env = tcx.param_env(def_id);
44+
let move_data = MoveData::gather_moves(body, tcx, param_env, |_| true);
4945

50-
ifhas_rustc_mir_with(tcx, def_id, sym::rustc_peek_maybe_init).is_some(){
51-
let flow_inits = MaybeInitializedPlaces::new(tcx, body,&move_data)
52-
.into_engine(tcx, body)
53-
.iterate_to_fixpoint();
46+
ifhas_rustc_mir_with(tcx, def_id, sym::rustc_peek_maybe_init).is_some(){
47+
let flow_inits = MaybeInitializedPlaces::new(tcx, body,&move_data)
48+
.into_engine(tcx, body)
49+
.iterate_to_fixpoint();
5450

55-
sanity_check_via_rustc_peek(tcx, flow_inits.into_results_cursor(body));
56-
}
51+
sanity_check_via_rustc_peek(tcx, flow_inits.into_results_cursor(body));
52+
}
5753

58-
ifhas_rustc_mir_with(tcx, def_id, sym::rustc_peek_maybe_uninit).is_some(){
59-
let flow_uninits = MaybeUninitializedPlaces::new(tcx, body,&move_data)
60-
.into_engine(tcx, body)
61-
.iterate_to_fixpoint();
54+
ifhas_rustc_mir_with(tcx, def_id, sym::rustc_peek_maybe_uninit).is_some(){
55+
let flow_uninits = MaybeUninitializedPlaces::new(tcx, body,&move_data)
56+
.into_engine(tcx, body)
57+
.iterate_to_fixpoint();
6258

63-
sanity_check_via_rustc_peek(tcx, flow_uninits.into_results_cursor(body));
64-
}
59+
sanity_check_via_rustc_peek(tcx, flow_uninits.into_results_cursor(body));
60+
}
6561

66-
ifhas_rustc_mir_with(tcx, def_id, sym::rustc_peek_definite_init).is_some(){
67-
let flow_def_inits = DefinitelyInitializedPlaces::new(body,&move_data)
68-
.into_engine(tcx, body)
69-
.iterate_to_fixpoint();
62+
ifhas_rustc_mir_with(tcx, def_id, sym::rustc_peek_definite_init).is_some(){
63+
let flow_def_inits = DefinitelyInitializedPlaces::new(body,&move_data)
64+
.into_engine(tcx, body)
65+
.iterate_to_fixpoint();
7066

71-
sanity_check_via_rustc_peek(tcx, flow_def_inits.into_results_cursor(body));
72-
}
67+
sanity_check_via_rustc_peek(tcx, flow_def_inits.into_results_cursor(body));
68+
}
7369

74-
ifhas_rustc_mir_with(tcx, def_id, sym::rustc_peek_liveness).is_some(){
75-
let flow_liveness = MaybeLiveLocals.into_engine(tcx, body).iterate_to_fixpoint();
70+
ifhas_rustc_mir_with(tcx, def_id, sym::rustc_peek_liveness).is_some(){
71+
let flow_liveness = MaybeLiveLocals.into_engine(tcx, body).iterate_to_fixpoint();
7672

77-
sanity_check_via_rustc_peek(tcx, flow_liveness.into_results_cursor(body));
78-
}
73+
sanity_check_via_rustc_peek(tcx, flow_liveness.into_results_cursor(body));
74+
}
7975

80-
ifhas_rustc_mir_with(tcx, def_id, sym::stop_after_dataflow).is_some(){
81-
tcx.dcx().emit_fatal(StopAfterDataFlowEndedCompilation);
82-
}
76+
ifhas_rustc_mir_with(tcx, def_id, sym::stop_after_dataflow).is_some(){
77+
tcx.dcx().emit_fatal(StopAfterDataFlowEndedCompilation);
8378
}
8479
}
8580

‎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);

0 commit comments

Comments
 (0)