Skip to content

Commit 83a7fb6

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 c039533 commit 83a7fb6

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

compiler/rustc_middle/src/mir/mod.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,13 @@ impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> {
9999
}
100100

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

compiler/rustc_middle/src/mir/pretty.rs

+2-1
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

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

0 commit comments

Comments
 (0)