Skip to content

Commit 0c9486c

Browse files
authored
Unrolled build for rust-lang#126410
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 92af831 + dcee529 commit 0c9486c

File tree

16 files changed

+52
-55
lines changed

16 files changed

+52
-55
lines changed

compiler/rustc_borrowck/src/renumber.rs

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

+3-3
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

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

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

+3-3
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

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

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

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

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

+1-1
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);

compiler/rustc_smir/src/rustc_smir/builder.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ impl<'tcx> BodyBuilder<'tcx> {
5252
}
5353

5454
impl<'tcx> MutVisitor<'tcx> for BodyBuilder<'tcx> {
55-
fn visit_constant(&mut self, constant: &mut mir::ConstOperand<'tcx>, location: mir::Location) {
55+
fn visit_const_operand(
56+
&mut self,
57+
constant: &mut mir::ConstOperand<'tcx>,
58+
location: mir::Location,
59+
) {
5660
let const_ = constant.const_;
5761
let val = match const_.eval(self.tcx, ty::ParamEnv::reveal_all(), constant.span) {
5862
Ok(v) => v,
@@ -63,7 +67,7 @@ impl<'tcx> MutVisitor<'tcx> for BodyBuilder<'tcx> {
6367
};
6468
let ty = constant.ty();
6569
constant.const_ = mir::Const::Val(val, ty);
66-
self.super_constant(constant, location);
70+
self.super_const_operand(constant, location);
6771
}
6872

6973
fn tcx(&self) -> TyCtxt<'tcx> {

compiler/rustc_smir/src/rustc_smir/convert/mir.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,13 @@ impl<'tcx> Stable<'tcx> for mir::Operand<'tcx> {
328328
}
329329

330330
impl<'tcx> Stable<'tcx> for mir::ConstOperand<'tcx> {
331-
type T = stable_mir::mir::Constant;
331+
type T = stable_mir::mir::ConstOperand;
332332

333333
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
334-
stable_mir::mir::Constant {
334+
stable_mir::mir::ConstOperand {
335335
span: self.span.stable(tables),
336336
user_ty: self.user_ty.map(|u| u.as_usize()).or(None),
337-
literal: self.const_.stable(tables),
337+
const_: self.const_.stable(tables),
338338
}
339339
}
340340
}

compiler/stable_mir/src/mir/body.rs

+10-17
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ pub enum AggregateKind {
637637
pub enum Operand {
638638
Copy(Place),
639639
Move(Place),
640-
Constant(Constant),
640+
Constant(ConstOperand),
641641
}
642642

643643
#[derive(Clone, Eq, PartialEq)]
@@ -653,6 +653,13 @@ impl From<Local> for Place {
653653
}
654654
}
655655

656+
#[derive(Clone, Debug, Eq, PartialEq)]
657+
pub struct ConstOperand {
658+
pub span: Span,
659+
pub user_ty: Option<UserTypeAnnotationIndex>,
660+
pub const_: MirConst,
661+
}
662+
656663
/// Debug information pertaining to a user variable.
657664
#[derive(Clone, Debug, Eq, PartialEq)]
658665
pub struct VarDebugInfo {
@@ -714,13 +721,6 @@ pub enum VarDebugInfoContents {
714721
Const(ConstOperand),
715722
}
716723

717-
#[derive(Clone, Debug, Eq, PartialEq)]
718-
pub struct ConstOperand {
719-
pub span: Span,
720-
pub user_ty: Option<UserTypeAnnotationIndex>,
721-
pub const_: MirConst,
722-
}
723-
724724
// In MIR ProjectionElem is parameterized on the second Field argument and the Index argument. This
725725
// is so it can be used for both Places (for which the projection elements are of type
726726
// ProjectionElem<Local, Ty>) and user-provided type annotations (for which the projection elements
@@ -829,13 +829,6 @@ pub type FieldIdx = usize;
829829

830830
type UserTypeAnnotationIndex = usize;
831831

832-
#[derive(Clone, Debug, Eq, PartialEq)]
833-
pub struct Constant {
834-
pub span: Span,
835-
pub user_ty: Option<UserTypeAnnotationIndex>,
836-
pub literal: MirConst,
837-
}
838-
839832
/// The possible branch sites of a [TerminatorKind::SwitchInt].
840833
#[derive(Clone, Debug, Eq, PartialEq)]
841834
pub struct SwitchTargets {
@@ -1001,9 +994,9 @@ impl Operand {
1001994
}
1002995
}
1003996

1004-
impl Constant {
997+
impl ConstOperand {
1005998
pub fn ty(&self) -> Ty {
1006-
self.literal.ty()
999+
self.const_.ty()
10071000
}
10081001
}
10091002

compiler/stable_mir/src/mir/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ fn pretty_operand(operand: &Operand) -> String {
310310
Operand::Move(mv) => {
311311
format!("move {:?}", mv)
312312
}
313-
Operand::Constant(cnst) => pretty_mir_const(&cnst.literal),
313+
Operand::Constant(cnst) => pretty_mir_const(&cnst.const_),
314314
}
315315
}
316316

compiler/stable_mir/src/mir/visit.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ pub trait MirVisitor {
108108
self.super_ty(ty)
109109
}
110110

111-
fn visit_constant(&mut self, constant: &Constant, location: Location) {
112-
self.super_constant(constant, location)
111+
fn visit_const_operand(&mut self, constant: &ConstOperand, location: Location) {
112+
self.super_const_operand(constant, location)
113113
}
114114

115115
fn visit_mir_const(&mut self, constant: &MirConst, location: Location) {
@@ -366,7 +366,7 @@ pub trait MirVisitor {
366366
self.visit_place(place, PlaceContext::NON_MUTATING, location)
367367
}
368368
Operand::Constant(constant) => {
369-
self.visit_constant(constant, location);
369+
self.visit_const_operand(constant, location);
370370
}
371371
}
372372
}
@@ -380,10 +380,10 @@ pub trait MirVisitor {
380380
let _ = ty;
381381
}
382382

383-
fn super_constant(&mut self, constant: &Constant, location: Location) {
384-
let Constant { span, user_ty: _, literal } = constant;
383+
fn super_const_operand(&mut self, constant: &ConstOperand, location: Location) {
384+
let ConstOperand { span, user_ty: _, const_ } = constant;
385385
self.visit_span(span);
386-
self.visit_mir_const(literal, location);
386+
self.visit_mir_const(const_, location);
387387
}
388388

389389
fn super_mir_const(&mut self, constant: &MirConst, location: Location) {

tests/ui-fulldeps/stable-mir/check_transform.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extern crate stable_mir;
2121
use rustc_smir::rustc_internal;
2222
use stable_mir::mir::alloc::GlobalAlloc;
2323
use stable_mir::mir::mono::Instance;
24-
use stable_mir::mir::{Body, Constant, Operand, Rvalue, StatementKind, TerminatorKind};
24+
use stable_mir::mir::{Body, ConstOperand, Operand, Rvalue, StatementKind, TerminatorKind};
2525
use stable_mir::ty::{ConstantKind, MirConst};
2626
use stable_mir::{CrateDef, CrateItems, ItemKind};
2727
use std::convert::TryFrom;
@@ -72,7 +72,7 @@ fn check_msg(body: &Body, expected: &str) {
7272
.unwrap()
7373
}
7474
};
75-
let ConstantKind::Allocated(alloc) = msg_const.literal.kind() else {
75+
let ConstantKind::Allocated(alloc) = msg_const.const_.kind() else {
7676
unreachable!()
7777
};
7878
assert_eq!(alloc.provenance.ptrs.len(), 1);
@@ -96,8 +96,8 @@ fn change_panic_msg(mut body: Body, new_msg: &str) -> Body {
9696
match &mut bb.terminator.kind {
9797
TerminatorKind::Call { args, .. } => {
9898
let new_const = MirConst::from_str(new_msg);
99-
args[0] = Operand::Constant(Constant {
100-
literal: new_const,
99+
args[0] = Operand::Constant(ConstOperand {
100+
const_: new_const,
101101
span: bb.terminator.span,
102102
user_ty: None,
103103
});

0 commit comments

Comments
 (0)