Skip to content

Commit c2166ec

Browse files
committed
Don't go through the formatting infrastructure just to get the name of a phase
1 parent 744a97b commit c2166ec

File tree

3 files changed

+15
-25
lines changed

3 files changed

+15
-25
lines changed

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -184,30 +184,7 @@ impl RuntimePhase {
184184

185185
impl Display for MirPhase {
186186
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
187-
match self {
188-
MirPhase::Built => write!(f, "built"),
189-
MirPhase::Analysis(p) => write!(f, "analysis-{}", p),
190-
MirPhase::Runtime(p) => write!(f, "runtime-{}", p),
191-
}
192-
}
193-
}
194-
195-
impl Display for AnalysisPhase {
196-
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
197-
match self {
198-
AnalysisPhase::Initial => write!(f, "initial"),
199-
AnalysisPhase::PostCleanup => write!(f, "post_cleanup"),
200-
}
201-
}
202-
}
203-
204-
impl Display for RuntimePhase {
205-
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
206-
match self {
207-
RuntimePhase::Initial => write!(f, "initial"),
208-
RuntimePhase::PostCleanup => write!(f, "post_cleanup"),
209-
RuntimePhase::Optimized => write!(f, "optimized"),
210-
}
187+
f.write_str(self.name())
211188
}
212189
}
213190

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ pub enum MirPhase {
8989
Runtime(RuntimePhase),
9090
}
9191

92+
impl MirPhase {
93+
pub fn name(&self) -> &'static str {
94+
match *self {
95+
MirPhase::Built => "built",
96+
MirPhase::Analysis(AnalysisPhase::Initial) => "analysis",
97+
MirPhase::Analysis(AnalysisPhase::PostCleanup) => "analysis-post-cleanup",
98+
MirPhase::Runtime(RuntimePhase::Initial) => "runtime",
99+
MirPhase::Runtime(RuntimePhase::PostCleanup) => "runtime-post-cleanup",
100+
MirPhase::Runtime(RuntimePhase::Optimized) => "runtime-optimized",
101+
}
102+
}
103+
}
104+
92105
/// See [`MirPhase::Analysis`].
93106
#[derive(Copy, Clone, TyEncodable, TyDecodable, Debug, PartialEq, Eq, PartialOrd, Ord)]
94107
#[derive(HashStable)]

compiler/rustc_mir_transform/src/pass_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub fn dump_mir_for_phase_change<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
184184
mir::dump_mir(
185185
tcx,
186186
Some(&format_args!("{:03}-000", phase_index)),
187-
&format!("{}", body.phase),
187+
body.phase.name(),
188188
&"after",
189189
body,
190190
|_, _| Ok(()),

0 commit comments

Comments
 (0)