Skip to content

Commit 840d8c5

Browse files
committed
Improve how the MIR dialect/phase index is reported.
The only visible change is to the filenames produce by `-Zdump-mir`. E.g. before and after: ``` h.main.003-000.analysis-post-cleanup.after.mir h.main.2-2-000.analysis-post-cleanup.after.mir ``` It also fixes a FIXME comment.
1 parent 4b1d70b commit 840d8c5

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,13 @@ impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> {
100100
}
101101

102102
impl MirPhase {
103-
/// Gets the index of the current MirPhase within the set of all `MirPhase`s.
104-
///
105-
/// FIXME(JakobDegen): Return a `(usize, usize)` instead.
106-
pub fn phase_index(&self) -> usize {
107-
const BUILT_PHASE_COUNT: usize = 1;
108-
const ANALYSIS_PHASE_COUNT: usize = 2;
109-
match self {
110-
MirPhase::Built => 1,
111-
MirPhase::Analysis(analysis_phase) => {
112-
1 + BUILT_PHASE_COUNT + (*analysis_phase as usize)
113-
}
114-
MirPhase::Runtime(runtime_phase) => {
115-
1 + BUILT_PHASE_COUNT + ANALYSIS_PHASE_COUNT + (*runtime_phase as usize)
116-
}
103+
/// Gets the (dialect, phase) index of the current `MirPhase`. Both numbers
104+
/// are 1-indexed.
105+
pub fn index(&self) -> (usize, usize) {
106+
match *self {
107+
MirPhase::Built => (1, 1),
108+
MirPhase::Analysis(analysis_phase) => (2, 1 + analysis_phase as usize),
109+
MirPhase::Runtime(runtime_phase) => (3, 1 + runtime_phase as usize),
117110
}
118111
}
119112

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ fn dump_path<'tcx>(
231231
let pass_num = if tcx.sess.opts.unstable_opts.dump_mir_exclude_pass_number {
232232
String::new()
233233
} else if pass_num {
234-
format!(".{:03}-{:03}", body.phase.phase_index(), body.pass_count)
234+
let (dialect_index, phase_index) = body.phase.index();
235+
format!(".{}-{}-{:03}", dialect_index, phase_index, body.pass_count)
235236
} else {
236237
".-------".to_string()
237238
};

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use crate::ty::{self, GenericArgsRef, List, Region, Ty, UserTypeAnnotationIndex}
3838
/// those restrictions. I.e. to convert MIR from one phase to the next might require
3939
/// removing/replacing certain MIR constructs.
4040
///
41-
/// When adding dialects or phases, remember to update [`MirPhase::phase_index`].
41+
/// When adding dialects or phases, remember to update [`MirPhase::index`].
4242
#[derive(Copy, Clone, TyEncodable, TyDecodable, Debug, PartialEq, Eq, PartialOrd, Ord)]
4343
#[derive(HashStable)]
4444
pub enum MirPhase {

0 commit comments

Comments
 (0)