mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
smir: merge identical Constant and ConstOperand types
This commit is contained in:
parent
ed1618dedc
commit
dcee529e5c
@ -328,13 +328,13 @@ impl<'tcx> Stable<'tcx> for mir::Operand<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Stable<'tcx> for mir::ConstOperand<'tcx> {
|
impl<'tcx> Stable<'tcx> for mir::ConstOperand<'tcx> {
|
||||||
type T = stable_mir::mir::Constant;
|
type T = stable_mir::mir::ConstOperand;
|
||||||
|
|
||||||
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
|
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
|
||||||
stable_mir::mir::Constant {
|
stable_mir::mir::ConstOperand {
|
||||||
span: self.span.stable(tables),
|
span: self.span.stable(tables),
|
||||||
user_ty: self.user_ty.map(|u| u.as_usize()).or(None),
|
user_ty: self.user_ty.map(|u| u.as_usize()).or(None),
|
||||||
literal: self.const_.stable(tables),
|
const_: self.const_.stable(tables),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -637,7 +637,7 @@ pub enum AggregateKind {
|
|||||||
pub enum Operand {
|
pub enum Operand {
|
||||||
Copy(Place),
|
Copy(Place),
|
||||||
Move(Place),
|
Move(Place),
|
||||||
Constant(Constant),
|
Constant(ConstOperand),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Eq, PartialEq)]
|
#[derive(Clone, Eq, PartialEq)]
|
||||||
@ -653,6 +653,13 @@ impl From<Local> for Place {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
|
pub struct ConstOperand {
|
||||||
|
pub span: Span,
|
||||||
|
pub user_ty: Option<UserTypeAnnotationIndex>,
|
||||||
|
pub const_: MirConst,
|
||||||
|
}
|
||||||
|
|
||||||
/// Debug information pertaining to a user variable.
|
/// Debug information pertaining to a user variable.
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
pub struct VarDebugInfo {
|
pub struct VarDebugInfo {
|
||||||
@ -714,13 +721,6 @@ pub enum VarDebugInfoContents {
|
|||||||
Const(ConstOperand),
|
Const(ConstOperand),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
||||||
pub struct ConstOperand {
|
|
||||||
pub span: Span,
|
|
||||||
pub user_ty: Option<UserTypeAnnotationIndex>,
|
|
||||||
pub const_: MirConst,
|
|
||||||
}
|
|
||||||
|
|
||||||
// In MIR ProjectionElem is parameterized on the second Field argument and the Index argument. This
|
// In MIR ProjectionElem is parameterized on the second Field argument and the Index argument. This
|
||||||
// is so it can be used for both Places (for which the projection elements are of type
|
// is so it can be used for both Places (for which the projection elements are of type
|
||||||
// ProjectionElem<Local, Ty>) and user-provided type annotations (for which the projection elements
|
// ProjectionElem<Local, Ty>) and user-provided type annotations (for which the projection elements
|
||||||
@ -829,13 +829,6 @@ pub type FieldIdx = usize;
|
|||||||
|
|
||||||
type UserTypeAnnotationIndex = usize;
|
type UserTypeAnnotationIndex = usize;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
||||||
pub struct Constant {
|
|
||||||
pub span: Span,
|
|
||||||
pub user_ty: Option<UserTypeAnnotationIndex>,
|
|
||||||
pub literal: MirConst,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The possible branch sites of a [TerminatorKind::SwitchInt].
|
/// The possible branch sites of a [TerminatorKind::SwitchInt].
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
pub struct SwitchTargets {
|
pub struct SwitchTargets {
|
||||||
@ -1001,9 +994,9 @@ impl Operand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Constant {
|
impl ConstOperand {
|
||||||
pub fn ty(&self) -> Ty {
|
pub fn ty(&self) -> Ty {
|
||||||
self.literal.ty()
|
self.const_.ty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,7 +310,7 @@ fn pretty_operand(operand: &Operand) -> String {
|
|||||||
Operand::Move(mv) => {
|
Operand::Move(mv) => {
|
||||||
format!("move {:?}", mv)
|
format!("move {:?}", mv)
|
||||||
}
|
}
|
||||||
Operand::Constant(cnst) => pretty_mir_const(&cnst.literal),
|
Operand::Constant(cnst) => pretty_mir_const(&cnst.const_),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,8 +108,8 @@ pub trait MirVisitor {
|
|||||||
self.super_ty(ty)
|
self.super_ty(ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_constant(&mut self, constant: &Constant, location: Location) {
|
fn visit_const_operand(&mut self, constant: &ConstOperand, location: Location) {
|
||||||
self.super_constant(constant, location)
|
self.super_const_operand(constant, location)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_mir_const(&mut self, constant: &MirConst, location: Location) {
|
fn visit_mir_const(&mut self, constant: &MirConst, location: Location) {
|
||||||
@ -366,7 +366,7 @@ pub trait MirVisitor {
|
|||||||
self.visit_place(place, PlaceContext::NON_MUTATING, location)
|
self.visit_place(place, PlaceContext::NON_MUTATING, location)
|
||||||
}
|
}
|
||||||
Operand::Constant(constant) => {
|
Operand::Constant(constant) => {
|
||||||
self.visit_constant(constant, location);
|
self.visit_const_operand(constant, location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -380,10 +380,10 @@ pub trait MirVisitor {
|
|||||||
let _ = ty;
|
let _ = ty;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn super_constant(&mut self, constant: &Constant, location: Location) {
|
fn super_const_operand(&mut self, constant: &ConstOperand, location: Location) {
|
||||||
let Constant { span, user_ty: _, literal } = constant;
|
let ConstOperand { span, user_ty: _, const_ } = constant;
|
||||||
self.visit_span(span);
|
self.visit_span(span);
|
||||||
self.visit_mir_const(literal, location);
|
self.visit_mir_const(const_, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn super_mir_const(&mut self, constant: &MirConst, location: Location) {
|
fn super_mir_const(&mut self, constant: &MirConst, location: Location) {
|
||||||
|
@ -21,7 +21,7 @@ extern crate stable_mir;
|
|||||||
use rustc_smir::rustc_internal;
|
use rustc_smir::rustc_internal;
|
||||||
use stable_mir::mir::alloc::GlobalAlloc;
|
use stable_mir::mir::alloc::GlobalAlloc;
|
||||||
use stable_mir::mir::mono::Instance;
|
use stable_mir::mir::mono::Instance;
|
||||||
use stable_mir::mir::{Body, Constant, Operand, Rvalue, StatementKind, TerminatorKind};
|
use stable_mir::mir::{Body, ConstOperand, Operand, Rvalue, StatementKind, TerminatorKind};
|
||||||
use stable_mir::ty::{ConstantKind, MirConst};
|
use stable_mir::ty::{ConstantKind, MirConst};
|
||||||
use stable_mir::{CrateDef, CrateItems, ItemKind};
|
use stable_mir::{CrateDef, CrateItems, ItemKind};
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
@ -72,7 +72,7 @@ fn check_msg(body: &Body, expected: &str) {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let ConstantKind::Allocated(alloc) = msg_const.literal.kind() else {
|
let ConstantKind::Allocated(alloc) = msg_const.const_.kind() else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
assert_eq!(alloc.provenance.ptrs.len(), 1);
|
assert_eq!(alloc.provenance.ptrs.len(), 1);
|
||||||
@ -96,8 +96,8 @@ fn change_panic_msg(mut body: Body, new_msg: &str) -> Body {
|
|||||||
match &mut bb.terminator.kind {
|
match &mut bb.terminator.kind {
|
||||||
TerminatorKind::Call { args, .. } => {
|
TerminatorKind::Call { args, .. } => {
|
||||||
let new_const = MirConst::from_str(new_msg);
|
let new_const = MirConst::from_str(new_msg);
|
||||||
args[0] = Operand::Constant(Constant {
|
args[0] = Operand::Constant(ConstOperand {
|
||||||
literal: new_const,
|
const_: new_const,
|
||||||
span: bb.terminator.span,
|
span: bb.terminator.span,
|
||||||
user_ty: None,
|
user_ty: None,
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user