Skip to content

Commit f0983b9

Browse files
committed
feat(compat): add compat code for initial breakpoints (2025-01-24 through 2025-03-01)
Add cfg-gated compat code for the first three breakpoints in the detection framework: - smir_has_run_compiler_fn: RunCompiler struct -> run_compiler() fn - smir_has_named_mono_item_partitions: MonoItemPartitions tuple -> named fields - smir_has_raw_ptr_kind: Rvalue::AddressOf Mutability -> RawPtrKind These breakpoints cover nightlies 2025-01-24 through 2025-03-01 and are prerequisites for the per-nightly golden file directories.
1 parent f4f304f commit f0983b9

5 files changed

Lines changed: 50 additions & 15 deletions

File tree

src/compat/mono_collect.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ use stable_mir::mir::mono::MonoItem;
1111

1212
/// Collect all monomorphized items from the compiler.
1313
pub fn mono_collect(tcx: TyCtxt<'_>) -> Vec<MonoItem> {
14+
// In nightlies >= 2025-01-27, MonoItemPartitions changed from a tuple
15+
// to named fields. See build.rs BREAKPOINTS table.
16+
#[cfg(not(smir_has_named_mono_item_partitions))]
1417
let units = tcx.collect_and_partition_mono_items(()).1;
18+
#[cfg(smir_has_named_mono_item_partitions)]
19+
let units = tcx.collect_and_partition_mono_items(()).codegen_units;
1520
units
1621
.iter()
1722
.flat_map(|unit| {

src/driver.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,10 @@ pub fn stable_mir_driver(args_outer: &[String], callback_fn: fn(TyCtxt) -> ()) {
4444
let early_dcx =
4545
rustc_session::EarlyDiagCtxt::new(rustc_session::config::ErrorOutputType::default());
4646
rustc_driver::init_rustc_env_logger(&early_dcx);
47+
// In nightlies >= 2025-01-24, RunCompiler was replaced with a free
48+
// function run_compiler(). See build.rs BREAKPOINTS table.
49+
#[cfg(not(smir_has_run_compiler_fn))]
4750
let _ = rustc_driver::RunCompiler::new(args_outer, &mut callbacks).run();
51+
#[cfg(smir_has_run_compiler_fn)]
52+
rustc_driver::run_compiler(args_outer, &mut callbacks);
4853
}

src/mk_graph/context.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
use std::collections::HashMap;
44

55
use crate::compat::stable_mir;
6+
#[cfg(not(smir_has_raw_ptr_kind))]
7+
use stable_mir::mir::Mutability;
68
use stable_mir::mir::{
7-
BorrowKind, ConstOperand, Mutability, NonDivergingIntrinsic, Operand, Rvalue, Statement,
8-
StatementKind, Terminator, TerminatorKind,
9+
BorrowKind, ConstOperand, NonDivergingIntrinsic, Operand, Rvalue, Statement, StatementKind,
10+
Terminator, TerminatorKind,
911
};
1012
use stable_mir::ty::{ConstantKind, IndexedVal, MirConst, Ty};
1113

@@ -153,19 +155,25 @@ impl GraphContext {
153155
} => format!("Ascribe {}.{}", place.label(), projections.base),
154156
Coverage(_) => "Coverage".to_string(),
155157
Intrinsic(intr) => format!("Intr: {}", self.render_intrinsic(intr)),
156-
ConstEvalCounter {} => "ConstEvalCounter".to_string(),
157-
Nop {} => "Nop".to_string(),
158+
ConstEvalCounter => "ConstEvalCounter".to_string(),
159+
Nop => "Nop".to_string(),
158160
}
159161
}
160162

161163
/// Render rvalue with context
162164
pub fn render_rvalue(&self, v: &Rvalue) -> String {
163165
use Rvalue::*;
164166
match v {
167+
// In nightlies >= 2025-01-28, AddressOf's first field changed from
168+
// Mutability (Mut/Not) to RawPtrKind (Mut/Const/FakeForPtrMetadata).
169+
// See build.rs BREAKPOINTS table.
170+
#[cfg(not(smir_has_raw_ptr_kind))]
165171
AddressOf(mutability, p) => match mutability {
166172
Mutability::Not => format!("&raw {}", p.label()),
167173
Mutability::Mut => format!("&raw mut {}", p.label()),
168174
},
175+
#[cfg(smir_has_raw_ptr_kind)]
176+
AddressOf(kind, p) => format!("&raw {:?} {}", kind, p.label()),
169177
Aggregate(kind, operands) => {
170178
let os: Vec<String> = operands.iter().map(|op| self.render_operand(op)).collect();
171179
format!("{} ({})", kind.label(), os.join(", "))
@@ -227,10 +235,10 @@ impl GraphContext {
227235
match &term.kind {
228236
Goto { .. } => "Goto".to_string(),
229237
SwitchInt { discr, .. } => format!("SwitchInt {}", self.render_operand(discr)),
230-
Resume {} => "Resume".to_string(),
231-
Abort {} => "Abort".to_string(),
232-
Return {} => "Return".to_string(),
233-
Unreachable {} => "Unreachable".to_string(),
238+
Resume => "Resume".to_string(),
239+
Abort => "Abort".to_string(),
240+
Return => "Return".to_string(),
241+
Unreachable => "Unreachable".to_string(),
234242
Drop { place, .. } => format!("Drop {}", place.label()),
235243
Call {
236244
func,

src/mk_graph/output/dot.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,16 @@ impl SmirJson {
125125
.attributes()
126126
.set_label("other");
127127
}
128-
Resume {} => {
128+
Resume => {
129129
label_strs.push("Resume".to_string());
130130
}
131-
Abort {} => {
131+
Abort => {
132132
label_strs.push("Abort".to_string());
133133
}
134-
Return {} => {
134+
Return => {
135135
label_strs.push("Return".to_string());
136136
}
137-
Unreachable {} => {
137+
Unreachable => {
138138
label_strs.push("Unreachable".to_string());
139139
}
140140
TerminatorKind::Drop {

src/mk_graph/util.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,27 @@ impl GraphLabelString for Operand {
4444
}
4545
}
4646
}
47-
47+
/// Some `AggregateKind` variants only exist on certain nightlies (the
48+
/// stable MIR API evolves across compiler versions). Arms gated with
49+
/// `#[cfg(smir_has_*)]` are toggled by `build.rs`, which inspects the
50+
/// active rustc's commit-date and emits the appropriate cfg flags.
51+
/// This keeps the match exhaustive on every supported nightly: without
52+
/// the flag the variant doesn't exist in the enum, so the arm is
53+
/// excluded; with the flag the arm is included to cover the new variant.
4854
impl GraphLabelString for AggregateKind {
4955
fn label(&self) -> String {
5056
use AggregateKind::*;
5157
match &self {
5258
Array(_ty) => "Array".to_string(),
53-
Tuple {} => "Tuple".to_string(),
59+
Tuple => "Tuple".to_string(),
5460
Adt(_, idx, _, _, _) => format!("Adt{{{}}}", idx.to_index()),
5561
Closure(_, _) => "Closure".to_string(),
5662
Coroutine(_, _, _) => "Coroutine".to_string(),
63+
64+
// Added in nightlies >= 2024-12-14; see build.rs BREAKPOINTS table.
65+
#[cfg(smir_has_coroutine_closure)]
66+
CoroutineClosure(_, _) => "CoroutineClosure".to_string(),
67+
5768
RawPtr(ty, Mutability::Mut) => format!("*mut ({})", ty),
5869
RawPtr(ty, Mutability::Not) => format!("*({})", ty),
5970
}
@@ -64,10 +75,16 @@ impl GraphLabelString for Rvalue {
6475
fn label(&self) -> String {
6576
use Rvalue::*;
6677
match &self {
78+
// In nightlies >= 2025-01-28, AddressOf's first field changed from
79+
// Mutability (Mut/Not) to RawPtrKind (Mut/Const/FakeForPtrMetadata).
80+
// See build.rs BREAKPOINTS table.
81+
#[cfg(not(smir_has_raw_ptr_kind))]
6782
AddressOf(mutability, p) => match mutability {
6883
Mutability::Not => format!("&raw {}", p.label()),
6984
Mutability::Mut => format!("&raw mut {}", p.label()),
7085
},
86+
#[cfg(smir_has_raw_ptr_kind)]
87+
AddressOf(kind, p) => format!("&raw {:?} {}", kind, p.label()),
7188
Aggregate(kind, operands) => {
7289
let os: Vec<String> = operands.iter().map(|op| op.label()).collect();
7390
format!("{} ({})", kind.label(), os.join(", "))
@@ -239,7 +256,7 @@ pub fn terminator_targets(term: &Terminator) -> Vec<usize> {
239256
result.push(targets.otherwise());
240257
result
241258
}
242-
Resume {} | Abort {} | Return {} | Unreachable {} => vec![],
259+
Resume | Abort | Return | Unreachable => vec![],
243260
Drop { target, unwind, .. } => {
244261
let mut result = vec![*target];
245262
if let UnwindAction::Cleanup(t) = unwind {

0 commit comments

Comments
 (0)