mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
s/Scalar::Raw/Scalar::Int
This commit is contained in:
parent
3a7970848c
commit
df4d717d0b
@ -186,7 +186,7 @@ pub(crate) fn codegen_const_value<'tcx>(
|
||||
}
|
||||
|
||||
match x {
|
||||
Scalar::Raw(int) => {
|
||||
Scalar::Int(int) => {
|
||||
CValue::const_val(fx, layout, int)
|
||||
}
|
||||
Scalar::Ptr(ptr) => {
|
||||
|
@ -230,11 +230,11 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
||||
fn scalar_to_backend(&self, cv: Scalar, layout: &abi::Scalar, llty: &'ll Type) -> &'ll Value {
|
||||
let bitsize = if layout.is_bool() { 1 } else { layout.value.size(self).bits() };
|
||||
match cv {
|
||||
Scalar::Raw(ScalarInt::ZST) => {
|
||||
Scalar::Int(ScalarInt::ZST) => {
|
||||
assert_eq!(0, layout.value.size(self).bytes());
|
||||
self.const_undef(self.type_ix(0))
|
||||
}
|
||||
Scalar::Raw(int) => {
|
||||
Scalar::Int(int) => {
|
||||
let data = int.assert_bits(layout.value.size(self));
|
||||
let llval = self.const_uint_big(self.type_ix(bitsize), data);
|
||||
if layout.value == Pointer {
|
||||
|
@ -103,7 +103,7 @@ impl<'tcx> ConstValue<'tcx> {
|
||||
#[derive(HashStable)]
|
||||
pub enum Scalar<Tag = ()> {
|
||||
/// The raw bytes of a simple value.
|
||||
Raw(ScalarInt),
|
||||
Int(ScalarInt),
|
||||
|
||||
/// A pointer into an `Allocation`. An `Allocation` in the `memory` module has a list of
|
||||
/// relocations, but a `Scalar` is only large enough to contain one, so we just represent the
|
||||
@ -120,7 +120,7 @@ impl<Tag: fmt::Debug> fmt::Debug for Scalar<Tag> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Scalar::Ptr(ptr) => write!(f, "{:?}", ptr),
|
||||
Scalar::Raw(int) => write!(f, "{:?}", int),
|
||||
Scalar::Int(int) => write!(f, "{:?}", int),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -129,7 +129,7 @@ impl<Tag: fmt::Debug> fmt::Display for Scalar<Tag> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Scalar::Ptr(ptr) => write!(f, "pointer to {}", ptr),
|
||||
Scalar::Raw { .. } => fmt::Debug::fmt(self, f),
|
||||
Scalar::Int { .. } => fmt::Debug::fmt(self, f),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -156,7 +156,7 @@ impl Scalar<()> {
|
||||
pub fn with_tag<Tag>(self, new_tag: Tag) -> Scalar<Tag> {
|
||||
match self {
|
||||
Scalar::Ptr(ptr) => Scalar::Ptr(ptr.with_tag(new_tag)),
|
||||
Scalar::Raw(int) => Scalar::Raw(int),
|
||||
Scalar::Int(int) => Scalar::Int(int),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -169,18 +169,18 @@ impl<'tcx, Tag> Scalar<Tag> {
|
||||
pub fn erase_tag(self) -> Scalar {
|
||||
match self {
|
||||
Scalar::Ptr(ptr) => Scalar::Ptr(ptr.erase_tag()),
|
||||
Scalar::Raw(int) => Scalar::Raw(int),
|
||||
Scalar::Int(int) => Scalar::Int(int),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn null_ptr(cx: &impl HasDataLayout) -> Self {
|
||||
Scalar::Raw(ScalarInt::null(cx.data_layout().pointer_size))
|
||||
Scalar::Int(ScalarInt::null(cx.data_layout().pointer_size))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn zst() -> Self {
|
||||
Scalar::Raw(ScalarInt::zst())
|
||||
Scalar::Int(ScalarInt::zst())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
@ -191,7 +191,7 @@ impl<'tcx, Tag> Scalar<Tag> {
|
||||
f_ptr: impl FnOnce(Pointer<Tag>) -> InterpResult<'tcx, Pointer<Tag>>,
|
||||
) -> InterpResult<'tcx, Self> {
|
||||
match self {
|
||||
Scalar::Raw(int) => Ok(Scalar::Raw(int.ptr_sized_op(dl, f_int)?)),
|
||||
Scalar::Int(int) => Ok(Scalar::Int(int.ptr_sized_op(dl, f_int)?)),
|
||||
Scalar::Ptr(ptr) => Ok(Scalar::Ptr(f_ptr(ptr)?)),
|
||||
}
|
||||
}
|
||||
@ -232,17 +232,17 @@ impl<'tcx, Tag> Scalar<Tag> {
|
||||
|
||||
#[inline]
|
||||
pub fn from_bool(b: bool) -> Self {
|
||||
Scalar::Raw(b.into())
|
||||
Scalar::Int(b.into())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_char(c: char) -> Self {
|
||||
Scalar::Raw(c.into())
|
||||
Scalar::Int(c.into())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn try_from_uint(i: impl Into<u128>, size: Size) -> Option<Self> {
|
||||
ScalarInt::try_from_uint(i, size).map(Scalar::Raw)
|
||||
ScalarInt::try_from_uint(i, size).map(Scalar::Int)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -254,22 +254,22 @@ impl<'tcx, Tag> Scalar<Tag> {
|
||||
|
||||
#[inline]
|
||||
pub fn from_u8(i: u8) -> Self {
|
||||
Scalar::Raw(i.into())
|
||||
Scalar::Int(i.into())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_u16(i: u16) -> Self {
|
||||
Scalar::Raw(i.into())
|
||||
Scalar::Int(i.into())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_u32(i: u32) -> Self {
|
||||
Scalar::Raw(i.into())
|
||||
Scalar::Int(i.into())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_u64(i: u64) -> Self {
|
||||
Scalar::Raw(i.into())
|
||||
Scalar::Int(i.into())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -279,7 +279,7 @@ impl<'tcx, Tag> Scalar<Tag> {
|
||||
|
||||
#[inline]
|
||||
pub fn try_from_int(i: impl Into<i128>, size: Size) -> Option<Self> {
|
||||
ScalarInt::try_from_int(i, size).map(Scalar::Raw)
|
||||
ScalarInt::try_from_int(i, size).map(Scalar::Int)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -316,12 +316,12 @@ impl<'tcx, Tag> Scalar<Tag> {
|
||||
|
||||
#[inline]
|
||||
pub fn from_f32(f: Single) -> Self {
|
||||
Scalar::Raw(f.into())
|
||||
Scalar::Int(f.into())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_f64(f: Double) -> Self {
|
||||
Scalar::Raw(f.into())
|
||||
Scalar::Int(f.into())
|
||||
}
|
||||
|
||||
/// This is very rarely the method you want! You should dispatch on the type
|
||||
@ -336,7 +336,7 @@ impl<'tcx, Tag> Scalar<Tag> {
|
||||
) -> Result<u128, Pointer<Tag>> {
|
||||
assert_ne!(target_size.bytes(), 0, "you should never look at the bits of a ZST");
|
||||
match self {
|
||||
Scalar::Raw(int) => Ok(int.assert_bits(target_size)),
|
||||
Scalar::Int(int) => Ok(int.assert_bits(target_size)),
|
||||
Scalar::Ptr(ptr) => {
|
||||
assert_eq!(target_size, cx.data_layout().pointer_size);
|
||||
Err(ptr)
|
||||
@ -350,7 +350,7 @@ impl<'tcx, Tag> Scalar<Tag> {
|
||||
fn to_bits(self, target_size: Size) -> InterpResult<'tcx, u128> {
|
||||
assert_ne!(target_size.bytes(), 0, "you should never look at the bits of a ZST");
|
||||
match self {
|
||||
Scalar::Raw(int) => int.to_bits(target_size),
|
||||
Scalar::Int(int) => int.to_bits(target_size),
|
||||
Scalar::Ptr(_) => throw_unsup!(ReadPointerAsBytes),
|
||||
}
|
||||
}
|
||||
@ -364,14 +364,14 @@ impl<'tcx, Tag> Scalar<Tag> {
|
||||
pub fn assert_ptr(self) -> Pointer<Tag> {
|
||||
match self {
|
||||
Scalar::Ptr(p) => p,
|
||||
Scalar::Raw { .. } => bug!("expected a Pointer but got Raw bits"),
|
||||
Scalar::Int { .. } => bug!("expected a Pointer but got Raw bits"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Do not call this method! Dispatch based on the type instead.
|
||||
#[inline]
|
||||
pub fn is_bits(self) -> bool {
|
||||
matches!(self, Scalar::Raw { .. })
|
||||
matches!(self, Scalar::Int { .. })
|
||||
}
|
||||
|
||||
/// Do not call this method! Dispatch based on the type instead.
|
||||
|
@ -1952,7 +1952,7 @@ impl<'tcx> Operand<'tcx> {
|
||||
.unwrap_or_else(|e| panic!("could not compute layout for {:?}: {:?}", ty, e))
|
||||
.size;
|
||||
let scalar_size = match val {
|
||||
Scalar::Raw(int) => int.size(),
|
||||
Scalar::Int(int) => int.size(),
|
||||
_ => panic!("Invalid scalar type {:?}", val),
|
||||
};
|
||||
scalar_size == type_size
|
||||
|
@ -982,27 +982,27 @@ pub trait PrettyPrinter<'tcx>:
|
||||
None => p!("<dangling pointer>"),
|
||||
},
|
||||
// Bool
|
||||
(Scalar::Raw(int), ty::Bool) if int == ScalarInt::FALSE => p!("false"),
|
||||
(Scalar::Raw(int), ty::Bool) if int == ScalarInt::TRUE => p!("true"),
|
||||
(Scalar::Int(int), ty::Bool) if int == ScalarInt::FALSE => p!("false"),
|
||||
(Scalar::Int(int), ty::Bool) if int == ScalarInt::TRUE => p!("true"),
|
||||
// Float
|
||||
(Scalar::Raw(int), ty::Float(ast::FloatTy::F32)) => {
|
||||
(Scalar::Int(int), ty::Float(ast::FloatTy::F32)) => {
|
||||
p!(write("{}f32", Single::try_from(int).unwrap()))
|
||||
}
|
||||
(Scalar::Raw(int), ty::Float(ast::FloatTy::F64)) => {
|
||||
(Scalar::Int(int), ty::Float(ast::FloatTy::F64)) => {
|
||||
p!(write("{}f64", Double::try_from(int).unwrap()))
|
||||
}
|
||||
// Int
|
||||
(Scalar::Raw(int), ty::Uint(_) | ty::Int(_)) => {
|
||||
(Scalar::Int(int), ty::Uint(_) | ty::Int(_)) => {
|
||||
let int =
|
||||
ConstInt::new(int, matches!(ty.kind(), ty::Int(_)), ty.is_ptr_sized_integral());
|
||||
if print_ty { p!(write("{:#?}", int)) } else { p!(write("{:?}", int)) }
|
||||
}
|
||||
// Char
|
||||
(Scalar::Raw(int), ty::Char) if char::try_from(int).is_ok() => {
|
||||
(Scalar::Int(int), ty::Char) if char::try_from(int).is_ok() => {
|
||||
p!(write("{:?}", char::try_from(int).unwrap()))
|
||||
}
|
||||
// Raw pointers
|
||||
(Scalar::Raw(int), ty::RawPtr(_)) => {
|
||||
(Scalar::Int(int), ty::RawPtr(_)) => {
|
||||
let data = int.assert_bits(self.tcx().data_layout.pointer_size);
|
||||
self = self.typed_value(
|
||||
|mut this| {
|
||||
@ -1025,11 +1025,11 @@ pub trait PrettyPrinter<'tcx>:
|
||||
)?;
|
||||
}
|
||||
// For function type zsts just printing the path is enough
|
||||
(Scalar::Raw(int), ty::FnDef(d, s)) if int == ScalarInt::ZST => {
|
||||
(Scalar::Int(int), ty::FnDef(d, s)) if int == ScalarInt::ZST => {
|
||||
p!(print_value_path(*d, s))
|
||||
}
|
||||
// Nontrivial types with scalar bit representation
|
||||
(Scalar::Raw(int), _) => {
|
||||
(Scalar::Int(int), _) => {
|
||||
let print = |mut this: Self| {
|
||||
if int.size() == Size::ZERO {
|
||||
write!(this, "transmute(())")?;
|
||||
|
@ -137,7 +137,7 @@ pub(super) fn op_to_const<'tcx>(
|
||||
let alloc = ecx.tcx.global_alloc(ptr.alloc_id).unwrap_memory();
|
||||
ConstValue::ByRef { alloc, offset: ptr.offset }
|
||||
}
|
||||
Scalar::Raw(int) => {
|
||||
Scalar::Int(int) => {
|
||||
assert!(mplace.layout.is_zst());
|
||||
assert_eq!(
|
||||
int.assert_bits(ecx.tcx.data_layout.pointer_size)
|
||||
@ -162,7 +162,7 @@ pub(super) fn op_to_const<'tcx>(
|
||||
Scalar::Ptr(ptr) => {
|
||||
(ecx.tcx.global_alloc(ptr.alloc_id).unwrap_memory(), ptr.offset.bytes())
|
||||
}
|
||||
Scalar::Raw { .. } => (
|
||||
Scalar::Int { .. } => (
|
||||
ecx.tcx
|
||||
.intern_const_alloc(Allocation::from_byte_aligned_bytes(b"" as &[u8])),
|
||||
0,
|
||||
|
@ -181,9 +181,9 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> {
|
||||
fn guaranteed_eq(&mut self, a: Scalar, b: Scalar) -> bool {
|
||||
match (a, b) {
|
||||
// Comparisons between integers are always known.
|
||||
(Scalar::Raw { .. }, Scalar::Raw { .. }) => a == b,
|
||||
(Scalar::Int { .. }, Scalar::Int { .. }) => a == b,
|
||||
// Equality with integers can never be known for sure.
|
||||
(Scalar::Raw { .. }, Scalar::Ptr(_)) | (Scalar::Ptr(_), Scalar::Raw { .. }) => false,
|
||||
(Scalar::Int { .. }, Scalar::Ptr(_)) | (Scalar::Ptr(_), Scalar::Int { .. }) => false,
|
||||
// FIXME: return `true` for when both sides are the same pointer, *except* that
|
||||
// some things (like functions and vtables) do not have stable addresses
|
||||
// so we need to be careful around them (see e.g. #73722).
|
||||
@ -194,11 +194,11 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> {
|
||||
fn guaranteed_ne(&mut self, a: Scalar, b: Scalar) -> bool {
|
||||
match (a, b) {
|
||||
// Comparisons between integers are always known.
|
||||
(Scalar::Raw(_), Scalar::Raw(_)) => a != b,
|
||||
(Scalar::Int(_), Scalar::Int(_)) => a != b,
|
||||
// Comparisons of abstract pointers with null pointers are known if the pointer
|
||||
// is in bounds, because if they are in bounds, the pointer can't be null.
|
||||
// Inequality with integers other than null can never be known for sure.
|
||||
(Scalar::Raw(int), Scalar::Ptr(ptr)) | (Scalar::Ptr(ptr), Scalar::Raw(int)) => {
|
||||
(Scalar::Int(int), Scalar::Ptr(ptr)) | (Scalar::Ptr(ptr), Scalar::Int(int)) => {
|
||||
int == ScalarInt::null(int.size()) && !self.memory.ptr_may_be_null(ptr)
|
||||
}
|
||||
// FIXME: return `true` for at least some comparisons where we can reliably
|
||||
|
@ -212,7 +212,7 @@ impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> {
|
||||
pub fn to_const_int(self) -> ConstInt {
|
||||
assert!(self.layout.ty.is_integral());
|
||||
let int = match self.to_scalar().expect("to_const_int doesn't work on scalar pairs") {
|
||||
Scalar::Raw(int) => int,
|
||||
Scalar::Int(int) => int,
|
||||
Scalar::Ptr(_) => bug!("to_const_int doesn't work on pointers"),
|
||||
};
|
||||
ConstInt::new(int, self.layout.ty.is_signed(), self.layout.ty.is_ptr_sized_integral())
|
||||
@ -541,7 +541,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
let tag_scalar = |scalar| -> InterpResult<'tcx, _> {
|
||||
Ok(match scalar {
|
||||
Scalar::Ptr(ptr) => Scalar::Ptr(self.global_base_pointer(ptr)?),
|
||||
Scalar::Raw(int) => Scalar::Raw(int),
|
||||
Scalar::Int(int) => Scalar::Int(int),
|
||||
})
|
||||
};
|
||||
// Early-return cases.
|
||||
|
@ -721,7 +721,7 @@ where
|
||||
dest.layout.size,
|
||||
"Size mismatch when writing pointer"
|
||||
),
|
||||
Immediate::Scalar(ScalarMaybeUninit::Scalar(Scalar::Raw(int))) => {
|
||||
Immediate::Scalar(ScalarMaybeUninit::Scalar(Scalar::Int(int))) => {
|
||||
assert_eq!(int.size(), dest.layout.size, "Size mismatch when writing bits")
|
||||
}
|
||||
Immediate::Scalar(ScalarMaybeUninit::Uninit) => {} // uninit can have any size
|
||||
|
@ -40,7 +40,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyComparisonIntegral {
|
||||
let bbs = &mut body.basic_blocks_mut();
|
||||
let bb = &mut bbs[opt.bb_idx];
|
||||
let new_value = match opt.branch_value_scalar {
|
||||
Scalar::Raw(int) => {
|
||||
Scalar::Int(int) => {
|
||||
let layout = tcx
|
||||
.layout_of(param_env.and(opt.branch_value_ty))
|
||||
.expect("if we have an evaluated constant we must know the layout");
|
||||
|
@ -630,7 +630,7 @@ pub fn write_allocations<'tcx>(
|
||||
ConstValue::Scalar(interpret::Scalar::Ptr(ptr)) => {
|
||||
Either::Left(Either::Left(std::iter::once(ptr.alloc_id)))
|
||||
}
|
||||
ConstValue::Scalar(interpret::Scalar::Raw { .. }) => {
|
||||
ConstValue::Scalar(interpret::Scalar::Int { .. }) => {
|
||||
Either::Left(Either::Right(std::iter::empty()))
|
||||
}
|
||||
ConstValue::ByRef { alloc, .. } | ConstValue::Slice { data: alloc, .. } => {
|
||||
|
@ -237,7 +237,7 @@ impl Printer<'tcx> for SymbolPrinter<'tcx> {
|
||||
|
||||
fn print_const(mut self, ct: &'tcx ty::Const<'tcx>) -> Result<Self::Const, Self::Error> {
|
||||
// only print integers
|
||||
if let ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { .. })) = ct.val {
|
||||
if let ty::ConstKind::Value(ConstValue::Scalar(Scalar::Int { .. })) = ct.val {
|
||||
if ct.ty.is_integral() {
|
||||
return self.pretty_print_const(ct, true);
|
||||
}
|
||||
|
@ -503,7 +503,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
|
||||
pub fn miri_to_const(result: &ty::Const<'_>) -> Option<Constant> {
|
||||
use rustc_middle::mir::interpret::{ConstValue};
|
||||
match result.val {
|
||||
ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw(int))) => {
|
||||
ty::ConstKind::Value(ConstValue::Scalar(Scalar::Int(int))) => {
|
||||
match result.ty.kind() {
|
||||
ty::Bool => Some(Constant::Bool(int == ScalarInt::TRUE)),
|
||||
ty::Uint(_) | ty::Int(_) => Some(Constant::Int(int.assert_bits(int.size()))),
|
||||
|
Loading…
Reference in New Issue
Block a user