Skip to content

Commit c420531

Browse files
committed
Replace ScalarKind with Primitive
1 parent cc60a22 commit c420531

File tree

13 files changed

+83
-213
lines changed

13 files changed

+83
-213
lines changed

src/librustc/mir/interpret/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod value;
1010

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

13-
pub use self::value::{Scalar, ScalarKind, Value, ConstValue};
13+
pub use self::value::{Scalar, Value, ConstValue};
1414

1515
use std::fmt;
1616
use mir;

src/librustc/mir/interpret/value.rs

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,6 @@ pub enum Scalar {
202202
Ptr(Pointer),
203203
}
204204

205-
#[derive(Clone, Copy, Debug, PartialEq)]
206-
pub enum ScalarKind {
207-
I8, I16, I32, I64, I128,
208-
U8, U16, U32, U64, U128,
209-
F32, F64,
210-
Ptr, FnPtr,
211-
Bool,
212-
Char,
213-
}
214-
215205
impl<'tcx> Scalar {
216206
pub fn undef() -> Self {
217207
Scalar::Bits { bits: 0, defined: 0 }
@@ -264,59 +254,3 @@ impl<'tcx> Scalar {
264254
}
265255
}
266256
}
267-
268-
impl ScalarKind {
269-
pub fn is_int(self) -> bool {
270-
use self::ScalarKind::*;
271-
match self {
272-
I8 | I16 | I32 | I64 | I128 | U8 | U16 | U32 | U64 | U128 => true,
273-
_ => false,
274-
}
275-
}
276-
277-
pub fn is_signed_int(self) -> bool {
278-
use self::ScalarKind::*;
279-
match self {
280-
I8 | I16 | I32 | I64 | I128 => true,
281-
_ => false,
282-
}
283-
}
284-
285-
pub fn is_float(self) -> bool {
286-
use self::ScalarKind::*;
287-
match self {
288-
F32 | F64 => true,
289-
_ => false,
290-
}
291-
}
292-
293-
pub fn from_uint_size(size: Size) -> Self {
294-
match size.bytes() {
295-
1 => ScalarKind::U8,
296-
2 => ScalarKind::U16,
297-
4 => ScalarKind::U32,
298-
8 => ScalarKind::U64,
299-
16 => ScalarKind::U128,
300-
_ => bug!("can't make uint with size {}", size.bytes()),
301-
}
302-
}
303-
304-
pub fn from_int_size(size: Size) -> Self {
305-
match size.bytes() {
306-
1 => ScalarKind::I8,
307-
2 => ScalarKind::I16,
308-
4 => ScalarKind::I32,
309-
8 => ScalarKind::I64,
310-
16 => ScalarKind::I128,
311-
_ => bug!("can't make int with size {}", size.bytes()),
312-
}
313-
}
314-
315-
pub fn is_ptr(self) -> bool {
316-
use self::ScalarKind::*;
317-
match self {
318-
Ptr | FnPtr => true,
319-
_ => false,
320-
}
321-
}
322-
}

src/librustc/ty/layout.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use session::{self, DataTypeKind};
1212
use ty::{self, Ty, TyCtxt, TypeFoldable, ReprOptions};
1313

14-
use syntax::ast::{self, FloatTy, IntTy, UintTy};
14+
use syntax::ast::{self, IntTy, UintTy};
1515
use syntax::attr;
1616
use syntax_pos::DUMMY_SP;
1717

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

19091908
impl_stable_hash_for!(enum ::ty::layout::Primitive {
19101909
Int(integer, signed),
1911-
F32,
1912-
F64,
1910+
Float(fty),
19131911
Pointer
19141912
});
19151913

src/librustc_codegen_llvm/type_of.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc::hir;
1515
use rustc::ty::{self, Ty, TypeFoldable};
1616
use rustc::ty::layout::{self, Align, LayoutOf, Size, TyLayout};
1717
use rustc_target::spec::PanicStrategy;
18+
use rustc_target::abi::FloatTy;
1819
use mono_item::DefPathBasedNames;
1920
use type_::Type;
2021

@@ -324,8 +325,8 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
324325
scalar: &layout::Scalar, offset: Size) -> Type {
325326
match scalar.value {
326327
layout::Int(i, _) => Type::from_integer(cx, i),
327-
layout::F32 => Type::f32(cx),
328-
layout::F64 => Type::f64(cx),
328+
layout::Float(FloatTy::F32) => Type::f32(cx),
329+
layout::Float(FloatTy::F64) => Type::f64(cx),
329330
layout::Pointer => {
330331
// If we know the alignment, pick something better than i8.
331332
let pointee = if let Some(pointee) = self.pointee_info_at(cx, offset) {

src/librustc_mir/interpret/eval_context.rs

Lines changed: 7 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc::middle::const_val::FrameInfo;
1414
use syntax::codemap::{self, Span};
1515
use syntax::ast::Mutability;
1616
use rustc::mir::interpret::{
17-
GlobalId, Value, Scalar, ScalarKind,
17+
GlobalId, Value, Scalar,
1818
EvalError, EvalResult, EvalErrorKind, Pointer, ConstValue,
1919
};
2020
use std::mem;
@@ -230,13 +230,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
230230

231231
pub fn str_to_value(&mut self, s: &str) -> EvalResult<'tcx, Value> {
232232
let ptr = self.memory.allocate_bytes(s.as_bytes());
233-
Ok(Value::ScalarPair(
234-
Scalar::Ptr(ptr),
235-
Scalar::Bits {
236-
bits: s.len() as u128,
237-
defined: self.tcx.data_layout.pointer_size.bits() as u8,
238-
},
239-
))
233+
Ok(Scalar::Ptr(ptr).to_value_with_len(s.len() as u64, self.tcx.tcx))
240234
}
241235

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

1274-
pub fn ty_to_scalar_kind(&self, ty: Ty<'tcx>) -> EvalResult<'tcx, ScalarKind> {
1275-
use syntax::ast::FloatTy;
1276-
1277-
let kind = match ty.sty {
1278-
ty::TyBool => ScalarKind::Bool,
1279-
ty::TyChar => ScalarKind::Char,
1280-
1281-
ty::TyInt(int_ty) => {
1282-
use syntax::ast::IntTy::*;
1283-
let size = match int_ty {
1284-
I8 => Size::from_bytes(1),
1285-
I16 => Size::from_bytes(2),
1286-
I32 => Size::from_bytes(4),
1287-
I64 => Size::from_bytes(8),
1288-
I128 => Size::from_bytes(16),
1289-
Isize => self.memory.pointer_size(),
1290-
};
1291-
ScalarKind::from_int_size(size)
1292-
}
1293-
1294-
ty::TyUint(uint_ty) => {
1295-
use syntax::ast::UintTy::*;
1296-
let size = match uint_ty {
1297-
U8 => Size::from_bytes(1),
1298-
U16 => Size::from_bytes(2),
1299-
U32 => Size::from_bytes(4),
1300-
U64 => Size::from_bytes(8),
1301-
U128 => Size::from_bytes(16),
1302-
Usize => self.memory.pointer_size(),
1303-
};
1304-
ScalarKind::from_uint_size(size)
1305-
}
1306-
1307-
ty::TyFloat(FloatTy::F32) => ScalarKind::F32,
1308-
ty::TyFloat(FloatTy::F64) => ScalarKind::F64,
1309-
1310-
ty::TyFnPtr(_) => ScalarKind::FnPtr,
1311-
1312-
ty::TyRef(_, ty, _) |
1313-
ty::TyRawPtr(ty::TypeAndMut { ty, .. }) if self.type_is_sized(ty) => {
1314-
ScalarKind::Ptr
1315-
}
1316-
1317-
ty::TyAdt(def, _) if def.is_box() => ScalarKind::Ptr,
1318-
1319-
ty::TyAdt(..) => {
1320-
match self.layout_of(ty)?.abi {
1321-
layout::Abi::Scalar(ref scalar) => {
1322-
use rustc::ty::layout::Primitive::*;
1323-
match scalar.value {
1324-
Int(i, false) => ScalarKind::from_uint_size(i.size()),
1325-
Int(i, true) => ScalarKind::from_int_size(i.size()),
1326-
F32 => ScalarKind::F32,
1327-
F64 => ScalarKind::F64,
1328-
Pointer => ScalarKind::Ptr,
1329-
}
1330-
}
1331-
1332-
_ => return err!(TypeNotPrimitive(ty)),
1333-
}
1334-
}
1335-
1336-
_ => return err!(TypeNotPrimitive(ty)),
1337-
};
1338-
1339-
Ok(kind)
1268+
pub fn ty_to_primitive(&self, ty: Ty<'tcx>) -> EvalResult<'tcx, layout::Primitive> {
1269+
match self.layout_of(ty)?.abi {
1270+
layout::Abi::Scalar(ref scalar) => Ok(scalar.value),
1271+
_ => err!(TypeNotPrimitive(ty)),
1272+
}
13401273
}
13411274

13421275
fn ensure_valid_value(&self, val: Scalar, ty: Ty<'tcx>) -> EvalResult<'tcx> {

src/librustc_mir/interpret/operator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
6868
) -> EvalResult<'tcx, (Scalar, bool)> {
6969
use rustc::mir::BinOp::*;
7070

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

7575
// I: Handle operations that support pointers

src/librustc_target/abi/call/mips64.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ fn float_reg<'a, Ty, C>(cx: C, ret: &ArgType<'a, Ty>, i: usize) -> Option<Reg>
3333
{
3434
match ret.layout.field(cx, i).abi {
3535
abi::Abi::Scalar(ref scalar) => match scalar.value {
36-
abi::F32 => Some(Reg::f32()),
37-
abi::F64 => Some(Reg::f64()),
36+
abi::Float(abi::FloatTy::F32) => Some(Reg::f32()),
37+
abi::Float(abi::FloatTy::F64) => Some(Reg::f64()),
3838
_ => None
3939
},
4040
_ => None
@@ -117,7 +117,7 @@ fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>)
117117

118118
// We only care about aligned doubles
119119
if let abi::Abi::Scalar(ref scalar) = field.abi {
120-
if let abi::F64 = scalar.value {
120+
if let abi::Float(abi::FloatTy::F64) = scalar.value {
121121
if offset.is_abi_aligned(dl.f64_align) {
122122
// Insert enough integers to cover [last_offset, offset)
123123
assert!(last_offset.is_abi_aligned(dl.f64_align));

src/librustc_target/abi/call/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,7 @@ impl<'a, Ty> TyLayout<'a, Ty> {
256256
let kind = match scalar.value {
257257
abi::Int(..) |
258258
abi::Pointer => RegKind::Integer,
259-
abi::F32 |
260-
abi::F64 => RegKind::Float
259+
abi::Float(_) => RegKind::Float,
261260
};
262261
Some(Reg {
263262
kind,

src/librustc_target/abi/call/s390x.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ fn is_single_fp_element<'a, Ty, C>(cx: C, layout: TyLayout<'a, Ty>) -> bool
2929
C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
3030
{
3131
match layout.abi {
32-
abi::Abi::Scalar(ref scalar) => {
33-
match scalar.value {
34-
abi::F32 | abi::F64 => true,
35-
_ => false
36-
}
37-
}
32+
abi::Abi::Scalar(ref scalar) => scalar.value.is_float(),
3833
abi::Abi::Aggregate { .. } => {
3934
if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 {
4035
is_single_fp_element(cx, layout.field(cx, 0))

src/librustc_target/abi/call/x86.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@ fn is_single_fp_element<'a, Ty, C>(cx: C, layout: TyLayout<'a, Ty>) -> bool
2323
C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
2424
{
2525
match layout.abi {
26-
abi::Abi::Scalar(ref scalar) => {
27-
match scalar.value {
28-
abi::F32 | abi::F64 => true,
29-
_ => false
30-
}
31-
}
26+
abi::Abi::Scalar(ref scalar) => scalar.value.is_float(),
3227
abi::Abi::Aggregate { .. } => {
3328
if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 {
3429
is_single_fp_element(cx, layout.field(cx, 0))

0 commit comments

Comments
 (0)