Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Miri api refactor #50967

Merged
merged 42 commits into from
May 25, 2018
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9cc5d92
Add constant for `Size::from_bytes(0)`
oli-obk May 20, 2018
1606e13
Rename PrimVal to Scalar
oli-obk May 20, 2018
ef2177c
Rename ByVal(Pair) to Scalar(Pair)
oli-obk May 20, 2018
6436de8
Differentiate between interpret::Scalar and layout::Scalar
oli-obk May 20, 2018
03a92b6
Eliminate the `Pointer` wrapper type
oli-obk May 20, 2018
d732463
Rename MemoryPointer to Pointer
oli-obk May 20, 2018
3bbf2fd
Remove Pointer::zero in favor of Pointer::from
oli-obk May 20, 2018
64a75ec
change `Value::Bytes` to `Value::Bits`
oli-obk May 22, 2018
bf39c7f
Floats are scalars!
oli-obk May 22, 2018
4ca169c
Use the target types bitsize instead of the source type's
oli-obk May 22, 2018
9456ba6
Accidentally used byte-size instead of bit-size
oli-obk May 22, 2018
ea8f544
Rebase fallout
oli-obk May 22, 2018
edbdf3d
Formatting nit
oli-obk May 22, 2018
1550fd2
Use the destination type size instead of the source type size
oli-obk May 22, 2018
f82256e
primval -> scalar rename
oli-obk May 22, 2018
ff652b8
Update outdated comment
oli-obk May 22, 2018
0da702a
Remove an instance of `scalar_size` in a `Debug` impl
oli-obk May 22, 2018
cc60a22
Get rid of `scalar_size`
oli-obk May 23, 2018
c420531
Replace `ScalarKind` with `Primitive`
oli-obk May 23, 2018
97da01f
Remove the last mention of `Undef`
oli-obk May 24, 2018
98e5129
Better variable naming
oli-obk May 24, 2018
09a996b
Printing values should ignore whether bits are undefined
oli-obk May 24, 2018
bc3ba91
Printing a fn definition needs to know nothing about its ZST's value
oli-obk May 24, 2018
ca8c27e
Ensure llvm doesn't trigger an assert for crazy transmutes
oli-obk May 24, 2018
1a2964a
Simplify a ScalarPair creation
oli-obk May 24, 2018
c6d25dc
Don't ICE on horrible transmutes in pattern constants
oli-obk May 24, 2018
50628b7
Only defined bits are relevant
oli-obk May 24, 2018
cfd5fb5
Reuse `to_bits` instead of badly reinventing it
oli-obk May 24, 2018
879d8f7
Properly check defined bits range
oli-obk May 24, 2018
f1ea9ef
Remove `ty_to_primitive`
oli-obk May 24, 2018
1f9fa53
Sanity check the `bits` argument to the `from_bits` function
oli-obk May 24, 2018
569ae80
Wrongly named a closure `clamp` when it was doing truncation
oli-obk May 24, 2018
bdd23bf
`tcx.lift_to_global` > `tcx.global_tcx().lift`
oli-obk May 24, 2018
d0610fd
Add missing newlines
oli-obk May 24, 2018
6d513f7
Remove dead code
oli-obk May 24, 2018
80a1488
Prefer `to_value_with_len` over manual expanison of it
oli-obk May 24, 2018
5c8741f
Use in-band-lifetimes instead of unused explicit lifetimes
oli-obk May 24, 2018
85de4ef
Rename `amt` variables to `shift`
oli-obk May 24, 2018
fb9060a
Revert "Ensure llvm doesn't trigger an assert for crazy transmutes"
oli-obk May 24, 2018
eceeb63
Update comment
oli-obk May 25, 2018
50d3783
Sanity abort `to_bits` if used on zsts
oli-obk May 25, 2018
5f599bb
Adjust test for 32 bit targets
oli-obk May 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Replace ScalarKind with Primitive
  • Loading branch information
oli-obk committed May 24, 2018
commit c420531304c1f02561bae5498d80447097ad5e75
2 changes: 1 addition & 1 deletion src/librustc/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ mod value;

pub use self::error::{EvalError, EvalResult, EvalErrorKind, AssertMessage};

pub use self::value::{Scalar, ScalarKind, Value, ConstValue};
pub use self::value::{Scalar, Value, ConstValue};

use std::fmt;
use mir;
66 changes: 0 additions & 66 deletions src/librustc/mir/interpret/value.rs
Original file line number Diff line number Diff line change
@@ -202,16 +202,6 @@ pub enum Scalar {
Ptr(Pointer),
}

#[derive(Clone, Copy, Debug, PartialEq)]
pub enum ScalarKind {
I8, I16, I32, I64, I128,
U8, U16, U32, U64, U128,
F32, F64,
Ptr, FnPtr,
Bool,
Char,
}

impl<'tcx> Scalar {
pub fn undef() -> Self {
Scalar::Bits { bits: 0, defined: 0 }
@@ -264,59 +254,3 @@ impl<'tcx> Scalar {
}
}
}

impl ScalarKind {
pub fn is_int(self) -> bool {
use self::ScalarKind::*;
match self {
I8 | I16 | I32 | I64 | I128 | U8 | U16 | U32 | U64 | U128 => true,
_ => false,
}
}

pub fn is_signed_int(self) -> bool {
use self::ScalarKind::*;
match self {
I8 | I16 | I32 | I64 | I128 => true,
_ => false,
}
}

pub fn is_float(self) -> bool {
use self::ScalarKind::*;
match self {
F32 | F64 => true,
_ => false,
}
}

pub fn from_uint_size(size: Size) -> Self {
match size.bytes() {
1 => ScalarKind::U8,
2 => ScalarKind::U16,
4 => ScalarKind::U32,
8 => ScalarKind::U64,
16 => ScalarKind::U128,
_ => bug!("can't make uint with size {}", size.bytes()),
}
}

pub fn from_int_size(size: Size) -> Self {
match size.bytes() {
1 => ScalarKind::I8,
2 => ScalarKind::I16,
4 => ScalarKind::I32,
8 => ScalarKind::I64,
16 => ScalarKind::I128,
_ => bug!("can't make int with size {}", size.bytes()),
}
}

pub fn is_ptr(self) -> bool {
use self::ScalarKind::*;
match self {
Ptr | FnPtr => true,
_ => false,
}
}
}
12 changes: 5 additions & 7 deletions src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
use session::{self, DataTypeKind};
use ty::{self, Ty, TyCtxt, TypeFoldable, ReprOptions};

use syntax::ast::{self, FloatTy, IntTy, UintTy};
use syntax::ast::{self, IntTy, UintTy};
use syntax::attr;
use syntax_pos::DUMMY_SP;

@@ -130,8 +130,8 @@ impl PrimitiveExt for Primitive {
fn to_ty<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
match *self {
Int(i, signed) => i.to_ty(tcx, signed),
F32 => tcx.types.f32,
F64 => tcx.types.f64,
Float(FloatTy::F32) => tcx.types.f32,
Float(FloatTy::F64) => tcx.types.f64,
Pointer => tcx.mk_mut_ptr(tcx.mk_nil()),
}
}
@@ -488,8 +488,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
ty::TyUint(ity) => {
scalar(Int(Integer::from_attr(dl, attr::UnsignedInt(ity)), false))
}
ty::TyFloat(FloatTy::F32) => scalar(F32),
ty::TyFloat(FloatTy::F64) => scalar(F64),
ty::TyFloat(fty) => scalar(Float(fty)),
ty::TyFnPtr(_) => {
let mut ptr = scalar_unit(Pointer);
ptr.valid_range = 1..=*ptr.valid_range.end();
@@ -1908,8 +1907,7 @@ impl_stable_hash_for!(enum ::ty::layout::Integer {

impl_stable_hash_for!(enum ::ty::layout::Primitive {
Int(integer, signed),
F32,
F64,
Float(fty),
Pointer
});

5 changes: 3 additions & 2 deletions src/librustc_codegen_llvm/type_of.rs
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ use rustc::hir;
use rustc::ty::{self, Ty, TypeFoldable};
use rustc::ty::layout::{self, Align, LayoutOf, Size, TyLayout};
use rustc_target::spec::PanicStrategy;
use rustc_target::abi::FloatTy;
use mono_item::DefPathBasedNames;
use type_::Type;

@@ -324,8 +325,8 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
scalar: &layout::Scalar, offset: Size) -> Type {
match scalar.value {
layout::Int(i, _) => Type::from_integer(cx, i),
layout::F32 => Type::f32(cx),
layout::F64 => Type::f64(cx),
layout::Float(FloatTy::F32) => Type::f32(cx),
layout::Float(FloatTy::F64) => Type::f64(cx),
layout::Pointer => {
// If we know the alignment, pick something better than i8.
let pointee = if let Some(pointee) = self.pointee_info_at(cx, offset) {
81 changes: 7 additions & 74 deletions src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ use rustc::middle::const_val::FrameInfo;
use syntax::codemap::{self, Span};
use syntax::ast::Mutability;
use rustc::mir::interpret::{
GlobalId, Value, Scalar, ScalarKind,
GlobalId, Value, Scalar,
EvalError, EvalResult, EvalErrorKind, Pointer, ConstValue,
};
use std::mem;
@@ -230,13 +230,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M

pub fn str_to_value(&mut self, s: &str) -> EvalResult<'tcx, Value> {
let ptr = self.memory.allocate_bytes(s.as_bytes());
Ok(Value::ScalarPair(
Scalar::Ptr(ptr),
Scalar::Bits {
bits: s.len() as u128,
defined: self.tcx.data_layout.pointer_size.bits() as u8,
},
))
Ok(Scalar::Ptr(ptr).to_value_with_len(s.len() as u64, self.tcx.tcx))
}

pub fn const_value_to_value(
@@ -1271,72 +1265,11 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
}
}

pub fn ty_to_scalar_kind(&self, ty: Ty<'tcx>) -> EvalResult<'tcx, ScalarKind> {
use syntax::ast::FloatTy;

let kind = match ty.sty {
ty::TyBool => ScalarKind::Bool,
ty::TyChar => ScalarKind::Char,

ty::TyInt(int_ty) => {
use syntax::ast::IntTy::*;
let size = match int_ty {
I8 => Size::from_bytes(1),
I16 => Size::from_bytes(2),
I32 => Size::from_bytes(4),
I64 => Size::from_bytes(8),
I128 => Size::from_bytes(16),
Isize => self.memory.pointer_size(),
};
ScalarKind::from_int_size(size)
}

ty::TyUint(uint_ty) => {
use syntax::ast::UintTy::*;
let size = match uint_ty {
U8 => Size::from_bytes(1),
U16 => Size::from_bytes(2),
U32 => Size::from_bytes(4),
U64 => Size::from_bytes(8),
U128 => Size::from_bytes(16),
Usize => self.memory.pointer_size(),
};
ScalarKind::from_uint_size(size)
}

ty::TyFloat(FloatTy::F32) => ScalarKind::F32,
ty::TyFloat(FloatTy::F64) => ScalarKind::F64,

ty::TyFnPtr(_) => ScalarKind::FnPtr,

ty::TyRef(_, ty, _) |
ty::TyRawPtr(ty::TypeAndMut { ty, .. }) if self.type_is_sized(ty) => {
ScalarKind::Ptr
}

ty::TyAdt(def, _) if def.is_box() => ScalarKind::Ptr,

ty::TyAdt(..) => {
match self.layout_of(ty)?.abi {
layout::Abi::Scalar(ref scalar) => {
use rustc::ty::layout::Primitive::*;
match scalar.value {
Int(i, false) => ScalarKind::from_uint_size(i.size()),
Int(i, true) => ScalarKind::from_int_size(i.size()),
F32 => ScalarKind::F32,
F64 => ScalarKind::F64,
Pointer => ScalarKind::Ptr,
}
}

_ => return err!(TypeNotPrimitive(ty)),
}
}

_ => return err!(TypeNotPrimitive(ty)),
};

Ok(kind)
pub fn ty_to_primitive(&self, ty: Ty<'tcx>) -> EvalResult<'tcx, layout::Primitive> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only used in one function, can you inline it there? Seems very niche and potentially misusable.

match self.layout_of(ty)?.abi {
layout::Abi::Scalar(ref scalar) => Ok(scalar.value),
_ => err!(TypeNotPrimitive(ty)),
}
}

fn ensure_valid_value(&self, val: Scalar, ty: Ty<'tcx>) -> EvalResult<'tcx> {
4 changes: 2 additions & 2 deletions src/librustc_mir/interpret/operator.rs
Original file line number Diff line number Diff line change
@@ -68,8 +68,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
) -> EvalResult<'tcx, (Scalar, bool)> {
use rustc::mir::BinOp::*;

let left_kind = self.ty_to_scalar_kind(left_ty)?;
let right_kind = self.ty_to_scalar_kind(right_ty)?;
let left_kind = self.ty_to_primitive(left_ty)?;
let right_kind = self.ty_to_primitive(right_ty)?;
trace!("Running binary op {:?}: {:?} ({:?}), {:?} ({:?})", bin_op, left, left_kind, right, right_kind);

// I: Handle operations that support pointers
6 changes: 3 additions & 3 deletions src/librustc_target/abi/call/mips64.rs
Original file line number Diff line number Diff line change
@@ -33,8 +33,8 @@ fn float_reg<'a, Ty, C>(cx: C, ret: &ArgType<'a, Ty>, i: usize) -> Option<Reg>
{
match ret.layout.field(cx, i).abi {
abi::Abi::Scalar(ref scalar) => match scalar.value {
abi::F32 => Some(Reg::f32()),
abi::F64 => Some(Reg::f64()),
abi::Float(abi::FloatTy::F32) => Some(Reg::f32()),
abi::Float(abi::FloatTy::F64) => Some(Reg::f64()),
_ => None
},
_ => None
@@ -117,7 +117,7 @@ fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>)

// We only care about aligned doubles
if let abi::Abi::Scalar(ref scalar) = field.abi {
if let abi::F64 = scalar.value {
if let abi::Float(abi::FloatTy::F64) = scalar.value {
if offset.is_abi_aligned(dl.f64_align) {
// Insert enough integers to cover [last_offset, offset)
assert!(last_offset.is_abi_aligned(dl.f64_align));
3 changes: 1 addition & 2 deletions src/librustc_target/abi/call/mod.rs
Original file line number Diff line number Diff line change
@@ -256,8 +256,7 @@ impl<'a, Ty> TyLayout<'a, Ty> {
let kind = match scalar.value {
abi::Int(..) |
abi::Pointer => RegKind::Integer,
abi::F32 |
abi::F64 => RegKind::Float
abi::Float(_) => RegKind::Float,
};
Some(Reg {
kind,
7 changes: 1 addition & 6 deletions src/librustc_target/abi/call/s390x.rs
Original file line number Diff line number Diff line change
@@ -29,12 +29,7 @@ fn is_single_fp_element<'a, Ty, C>(cx: C, layout: TyLayout<'a, Ty>) -> bool
C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
{
match layout.abi {
abi::Abi::Scalar(ref scalar) => {
match scalar.value {
abi::F32 | abi::F64 => true,
_ => false
}
}
abi::Abi::Scalar(ref scalar) => scalar.value.is_float(),
abi::Abi::Aggregate { .. } => {
if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 {
is_single_fp_element(cx, layout.field(cx, 0))
7 changes: 1 addition & 6 deletions src/librustc_target/abi/call/x86.rs
Original file line number Diff line number Diff line change
@@ -23,12 +23,7 @@ fn is_single_fp_element<'a, Ty, C>(cx: C, layout: TyLayout<'a, Ty>) -> bool
C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
{
match layout.abi {
abi::Abi::Scalar(ref scalar) => {
match scalar.value {
abi::F32 | abi::F64 => true,
_ => false
}
}
abi::Abi::Scalar(ref scalar) => scalar.value.is_float(),
abi::Abi::Aggregate { .. } => {
if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 {
is_single_fp_element(cx, layout.field(cx, 0))
3 changes: 1 addition & 2 deletions src/librustc_target/abi/call/x86_64.rs
Original file line number Diff line number Diff line change
@@ -55,8 +55,7 @@ fn classify_arg<'a, Ty, C>(cx: C, arg: &ArgType<'a, Ty>)
match scalar.value {
abi::Int(..) |
abi::Pointer => Class::Int,
abi::F32 |
abi::F64 => Class::Sse
abi::Float(_) => Class::Sse
}
}

Loading