Rollup merge of #137204 - nnethercote:clarify-MIR-dialects-and-phases, r=RalfJung

Clarify MIR dialects and phases

I found the existing code and docs hard to understand.

r? `@Zalathar`
This commit is contained in:
Matthias Krüger 2025-02-21 12:45:23 +01:00 committed by GitHub
commit 15a0403ecf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 62 additions and 58 deletions

View file

@ -98,20 +98,13 @@ impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> {
}
impl MirPhase {
/// Gets the index of the current MirPhase within the set of all `MirPhase`s.
///
/// FIXME(JakobDegen): Return a `(usize, usize)` instead.
pub fn phase_index(&self) -> usize {
const BUILT_PHASE_COUNT: usize = 1;
const ANALYSIS_PHASE_COUNT: usize = 2;
match self {
MirPhase::Built => 1,
MirPhase::Analysis(analysis_phase) => {
1 + BUILT_PHASE_COUNT + (*analysis_phase as usize)
}
MirPhase::Runtime(runtime_phase) => {
1 + BUILT_PHASE_COUNT + ANALYSIS_PHASE_COUNT + (*runtime_phase as usize)
}
/// Gets the (dialect, phase) index of the current `MirPhase`. Both numbers
/// are 1-indexed.
pub fn index(&self) -> (usize, usize) {
match *self {
MirPhase::Built => (1, 1),
MirPhase::Analysis(analysis_phase) => (2, 1 + analysis_phase as usize),
MirPhase::Runtime(runtime_phase) => (3, 1 + runtime_phase as usize),
}
}