Skip to content

Commit be1d427

Browse files
Rollup merge of rust-lang#126410 - RalfJung:smir-const-operand, r=oli-obk
smir: merge identical Constant and ConstOperand types The first commit renames the const operand visitor functions on regular MIR to match the type name, that was forgotten in the original rename. The second commit changes stable MIR, fixing rust-lang/project-stable-mir#71. Previously there were two different smir types for the MIR type `ConstOperand`, one used in `Operand` and one in `VarDebugInfoContents`. Maybe we should have done this with rust-lang#125967, so there's only a single breaking change... but I saw that PR too late. Fixes rust-lang/project-stable-mir#71
2 parents 709d862 + dcee529 commit be1d427

File tree

16 files changed

+52
-55
lines changed

16 files changed

+52
-55
lines changed

compiler/rustc_borrowck/src/renumber.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for RegionRenumberer<'a, 'tcx> {
113113
}
114114

115115
#[instrument(skip(self), level = "debug")]
116-
fn visit_constant(&mut self, constant: &mut ConstOperand<'tcx>, location: Location) {
116+
fn visit_const_operand(&mut self, constant: &mut ConstOperand<'tcx>, location: Location) {
117117
let const_ = constant.const_;
118118
constant.const_ = self.renumber_regions(const_, || RegionCtxt::Location(location));
119119
debug!("constant: {:#?}", constant);

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,10 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
301301
self.sanitize_place(place, location, context);
302302
}
303303

304-
fn visit_constant(&mut self, constant: &ConstOperand<'tcx>, location: Location) {
305-
debug!(?constant, ?location, "visit_constant");
304+
fn visit_const_operand(&mut self, constant: &ConstOperand<'tcx>, location: Location) {
305+
debug!(?constant, ?location, "visit_const_operand");
306306

307-
self.super_constant(constant, location);
307+
self.super_const_operand(constant, location);
308308
let ty = self.sanitize_type(constant, constant.const_.ty());
309309

310310
self.cx.infcx.tcx.for_each_free_region(&ty, |live_region| {

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ fn use_verbose(ty: Ty<'_>, fn_def: bool) -> bool {
12871287
}
12881288

12891289
impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
1290-
fn visit_constant(&mut self, constant: &ConstOperand<'tcx>, _location: Location) {
1290+
fn visit_const_operand(&mut self, constant: &ConstOperand<'tcx>, _location: Location) {
12911291
let ConstOperand { span, user_ty, const_ } = constant;
12921292
if use_verbose(const_.ty(), true) {
12931293
self.push("mir::ConstOperand");
@@ -1415,7 +1415,7 @@ pub fn write_allocations<'tcx>(
14151415
struct CollectAllocIds(BTreeSet<AllocId>);
14161416

14171417
impl<'tcx> Visitor<'tcx> for CollectAllocIds {
1418-
fn visit_constant(&mut self, c: &ConstOperand<'tcx>, _: Location) {
1418+
fn visit_const_operand(&mut self, c: &ConstOperand<'tcx>, _: Location) {
14191419
match c.const_ {
14201420
Const::Ty(_, _) | Const::Unevaluated(..) => {}
14211421
Const::Val(val, _) => {

compiler/rustc_middle/src/mir/visit.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,12 @@ macro_rules! make_mir_visitor {
184184

185185
/// This is called for every constant in the MIR body and every `required_consts`
186186
/// (i.e., including consts that have been dead-code-eliminated).
187-
fn visit_constant(
187+
fn visit_const_operand(
188188
&mut self,
189189
constant: & $($mutability)? ConstOperand<'tcx>,
190190
location: Location,
191191
) {
192-
self.super_constant(constant, location);
192+
self.super_const_operand(constant, location);
193193
}
194194

195195
fn visit_ty_const(
@@ -597,7 +597,7 @@ macro_rules! make_mir_visitor {
597597
}
598598
InlineAsmOperand::Const { value }
599599
| InlineAsmOperand::SymFn { value } => {
600-
self.visit_constant(value, location);
600+
self.visit_const_operand(value, location);
601601
}
602602
InlineAsmOperand::Out { place: None, .. }
603603
| InlineAsmOperand::SymStatic { def_id: _ }
@@ -788,7 +788,7 @@ macro_rules! make_mir_visitor {
788788
);
789789
}
790790
Operand::Constant(constant) => {
791-
self.visit_constant(constant, location);
791+
self.visit_const_operand(constant, location);
792792
}
793793
}
794794
}
@@ -867,7 +867,7 @@ macro_rules! make_mir_visitor {
867867
}
868868
}
869869
match value {
870-
VarDebugInfoContents::Const(c) => self.visit_constant(c, location),
870+
VarDebugInfoContents::Const(c) => self.visit_const_operand(c, location),
871871
VarDebugInfoContents::Place(place) =>
872872
self.visit_place(
873873
place,
@@ -882,7 +882,7 @@ macro_rules! make_mir_visitor {
882882
_scope: $(& $mutability)? SourceScope
883883
) {}
884884

885-
fn super_constant(
885+
fn super_const_operand(
886886
&mut self,
887887
constant: & $($mutability)? ConstOperand<'tcx>,
888888
location: Location
@@ -1057,7 +1057,7 @@ macro_rules! super_body {
10571057

10581058
for const_ in &$($mutability)? $body.required_consts {
10591059
let location = Location::START;
1060-
$self.visit_constant(const_, location);
1060+
$self.visit_const_operand(const_, location);
10611061
}
10621062
}
10631063
}

compiler/rustc_mir_transform/src/known_panics_lint.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -706,9 +706,9 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
706706
self.super_operand(operand, location);
707707
}
708708

709-
fn visit_constant(&mut self, constant: &ConstOperand<'tcx>, location: Location) {
710-
trace!("visit_constant: {:?}", constant);
711-
self.super_constant(constant, location);
709+
fn visit_const_operand(&mut self, constant: &ConstOperand<'tcx>, location: Location) {
710+
trace!("visit_const_operand: {:?}", constant);
711+
self.super_const_operand(constant, location);
712712
self.eval_constant(constant);
713713
}
714714

compiler/rustc_mir_transform/src/promote_consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> {
956956
}
957957
}
958958

959-
fn visit_constant(&mut self, constant: &mut ConstOperand<'tcx>, _location: Location) {
959+
fn visit_const_operand(&mut self, constant: &mut ConstOperand<'tcx>, _location: Location) {
960960
if constant.const_.is_required_const() {
961961
self.promoted.required_consts.push(*constant);
962962
}

compiler/rustc_mir_transform/src/required_consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl<'a, 'tcx> RequiredConstsVisitor<'a, 'tcx> {
1212
}
1313

1414
impl<'tcx> Visitor<'tcx> for RequiredConstsVisitor<'_, 'tcx> {
15-
fn visit_constant(&mut self, constant: &ConstOperand<'tcx>, _: Location) {
15+
fn visit_const_operand(&mut self, constant: &ConstOperand<'tcx>, _: Location) {
1616
if constant.const_.is_required_const() {
1717
self.required_consts.push(*constant);
1818
}

compiler/rustc_mir_transform/src/reveal_all.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ impl<'tcx> MutVisitor<'tcx> for RevealAllVisitor<'tcx> {
4949
}
5050

5151
#[inline]
52-
fn visit_constant(&mut self, constant: &mut ConstOperand<'tcx>, location: Location) {
52+
fn visit_const_operand(&mut self, constant: &mut ConstOperand<'tcx>, location: Location) {
5353
// We have to use `try_normalize_erasing_regions` here, since it's
5454
// possible that we visit impossible-to-satisfy where clauses here,
5555
// see #91745
5656
if let Ok(c) = self.tcx.try_normalize_erasing_regions(self.param_env, constant.const_) {
5757
constant.const_ = c;
5858
}
59-
self.super_constant(constant, location);
59+
self.super_const_operand(constant, location);
6060
}
6161

6262
#[inline]

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
799799
/// This does not walk the MIR of the constant as that is not needed for codegen, all we need is
800800
/// to ensure that the constant evaluates successfully and walk the result.
801801
#[instrument(skip(self), level = "debug")]
802-
fn visit_constant(&mut self, constant: &mir::ConstOperand<'tcx>, location: Location) {
802+
fn visit_const_operand(&mut self, constant: &mir::ConstOperand<'tcx>, location: Location) {
803803
// No `super_constant` as we don't care about `visit_ty`/`visit_ty_const`.
804804
let Some(val) = self.eval_constant(constant) else { return };
805805
collect_const_value(self.tcx, val, self.used_items);

compiler/rustc_monomorphize/src/polymorphize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
261261
self.super_local_decl(local, local_decl);
262262
}
263263

264-
fn visit_constant(&mut self, ct: &mir::ConstOperand<'tcx>, location: Location) {
264+
fn visit_const_operand(&mut self, ct: &mir::ConstOperand<'tcx>, location: Location) {
265265
match ct.const_ {
266266
mir::Const::Ty(_, c) => {
267267
c.visit_with(self);

0 commit comments

Comments
 (0)