Skip to content

Commit 57b9838

Browse files
authored
Merge pull request rust-lang#98 from oli-obk/rustup
rustup (i128)
2 parents d6e35fe + 3a658e0 commit 57b9838

File tree

14 files changed

+196
-151
lines changed

14 files changed

+196
-151
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
tex/*/out
44
*.dot
55
*.mir
6+
*.rs.bk

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ test = false
1515
test = false
1616

1717
[dependencies]
18-
byteorder = "0.4.2"
18+
#byteorder = "0.4.2"
19+
byteorder = { git = "https://github.com/quininer/byteorder.git", branch = "i128", features = ["i128"]}
1920
env_logger = "0.3.3"
2021
log = "0.3.6"
2122
log_settings = "0.1.1"

src/bin/miri.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(rustc_private)]
1+
#![feature(rustc_private, i128_type)]
22

33
extern crate getopts;
44
extern crate miri;
@@ -51,7 +51,7 @@ fn resource_limits_from_attributes(state: &CompileState) -> miri::ResourceLimits
5151
let mut limits = miri::ResourceLimits::default();
5252
let krate = state.hir_crate.as_ref().unwrap();
5353
let err_msg = "miri attributes need to be in the form `miri(key = value)`";
54-
let extract_int = |lit: &syntax::ast::Lit| -> u64 {
54+
let extract_int = |lit: &syntax::ast::Lit| -> u128 {
5555
match lit.node {
5656
syntax::ast::LitKind::Int(i, _) => i,
5757
_ => state.session.span_fatal(lit.span, "expected an integer literal"),
@@ -64,8 +64,8 @@ fn resource_limits_from_attributes(state: &CompileState) -> miri::ResourceLimits
6464
if let NestedMetaItemKind::MetaItem(ref inner) = item.node {
6565
if let MetaItemKind::NameValue(ref value) = inner.node {
6666
match &inner.name().as_str()[..] {
67-
"memory_size" => limits.memory_size = extract_int(value),
68-
"step_limit" => limits.step_limit = extract_int(value),
67+
"memory_size" => limits.memory_size = extract_int(value) as u64,
68+
"step_limit" => limits.step_limit = extract_int(value) as u64,
6969
"stack_limit" => limits.stack_limit = extract_int(value) as usize,
7070
_ => state.session.span_err(item.span, "unknown miri attribute"),
7171
}

src/cast.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,36 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
2020
F32 => self.cast_float(val.to_f32()? as f64, dest_ty),
2121
F64 => self.cast_float(val.to_f64()?, dest_ty),
2222

23-
I8 | I16 | I32 | I64 => self.cast_signed_int(val.to_i64()?, dest_ty),
23+
I8 | I16 | I32 | I64 | I128 => self.cast_signed_int(val.to_i128()?, dest_ty),
2424

25-
Bool | Char | U8 | U16 | U32 | U64 => self.cast_int(val.to_u64()?, dest_ty, false),
25+
Bool | Char | U8 | U16 | U32 | U64 | U128 => self.cast_int(val.to_u128()?, dest_ty, false),
2626

2727
FnPtr | Ptr => self.cast_ptr(val.to_ptr()?, dest_ty),
2828
}
2929
}
3030

31-
fn cast_signed_int(&self, val: i64, ty: ty::Ty<'tcx>) -> EvalResult<'tcx, PrimVal> {
32-
self.cast_int(val as u64, ty, val < 0)
31+
fn cast_signed_int(&self, val: i128, ty: ty::Ty<'tcx>) -> EvalResult<'tcx, PrimVal> {
32+
self.cast_int(val as u128, ty, val < 0)
3333
}
3434

35-
fn cast_int(&self, v: u64, ty: ty::Ty<'tcx>, negative: bool) -> EvalResult<'tcx, PrimVal> {
35+
fn cast_int(&self, v: u128, ty: ty::Ty<'tcx>, negative: bool) -> EvalResult<'tcx, PrimVal> {
3636
use rustc::ty::TypeVariants::*;
3737
match ty.sty {
3838
TyBool if v == 0 => Ok(PrimVal::from_bool(false)),
3939
TyBool if v == 1 => Ok(PrimVal::from_bool(true)),
4040
TyBool => Err(EvalError::InvalidBool),
4141

42-
TyInt(IntTy::I8) => Ok(PrimVal::Bytes(v as i64 as i8 as u64)),
43-
TyInt(IntTy::I16) => Ok(PrimVal::Bytes(v as i64 as i16 as u64)),
44-
TyInt(IntTy::I32) => Ok(PrimVal::Bytes(v as i64 as i32 as u64)),
45-
TyInt(IntTy::I64) => Ok(PrimVal::Bytes(v as i64 as i64 as u64)),
42+
TyInt(IntTy::I8) => Ok(PrimVal::Bytes(v as i128 as i8 as u128)),
43+
TyInt(IntTy::I16) => Ok(PrimVal::Bytes(v as i128 as i16 as u128)),
44+
TyInt(IntTy::I32) => Ok(PrimVal::Bytes(v as i128 as i32 as u128)),
45+
TyInt(IntTy::I64) => Ok(PrimVal::Bytes(v as i128 as i64 as u128)),
46+
TyInt(IntTy::I128) => Ok(PrimVal::Bytes(v as u128)),
4647

47-
TyUint(UintTy::U8) => Ok(PrimVal::Bytes(v as u8 as u64)),
48-
TyUint(UintTy::U16) => Ok(PrimVal::Bytes(v as u16 as u64)),
49-
TyUint(UintTy::U32) => Ok(PrimVal::Bytes(v as u32 as u64)),
50-
TyUint(UintTy::U64) => Ok(PrimVal::Bytes(v)),
48+
TyUint(UintTy::U8) => Ok(PrimVal::Bytes(v as u8 as u128)),
49+
TyUint(UintTy::U16) => Ok(PrimVal::Bytes(v as u16 as u128)),
50+
TyUint(UintTy::U32) => Ok(PrimVal::Bytes(v as u32 as u128)),
51+
TyUint(UintTy::U64) => Ok(PrimVal::Bytes(v as u64 as u128)),
52+
TyUint(UintTy::U128) => Ok(PrimVal::Bytes(v)),
5153

5254
TyInt(IntTy::Is) => {
5355
let int_ty = self.tcx.sess.target.int_type;
@@ -61,15 +63,15 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
6163
self.cast_int(v, ty, negative)
6264
}
6365

64-
TyFloat(FloatTy::F64) if negative => Ok(PrimVal::from_f64(v as i64 as f64)),
66+
TyFloat(FloatTy::F64) if negative => Ok(PrimVal::from_f64(v as i128 as f64)),
6567
TyFloat(FloatTy::F64) => Ok(PrimVal::from_f64(v as f64)),
66-
TyFloat(FloatTy::F32) if negative => Ok(PrimVal::from_f32(v as i64 as f32)),
68+
TyFloat(FloatTy::F32) if negative => Ok(PrimVal::from_f32(v as i128 as f32)),
6769
TyFloat(FloatTy::F32) => Ok(PrimVal::from_f32(v as f32)),
6870

69-
TyChar if v as u8 as u64 == v => Ok(PrimVal::Bytes(v)),
71+
TyChar if v as u8 as u128 == v => Ok(PrimVal::Bytes(v)),
7072
TyChar => Err(EvalError::InvalidChar(v)),
7173

72-
TyRawPtr(_) => Ok(PrimVal::Ptr(Pointer::from_int(v))),
74+
TyRawPtr(_) => Ok(PrimVal::Ptr(Pointer::from_int(v as u64))),
7375

7476
_ => Err(EvalError::Unimplemented(format!("int to {:?} cast", ty))),
7577
}
@@ -80,9 +82,9 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
8082
match ty.sty {
8183
// Casting negative floats to unsigned integers yields zero.
8284
TyUint(_) if val < 0.0 => self.cast_int(0, ty, false),
83-
TyInt(_) if val < 0.0 => self.cast_int(val as i64 as u64, ty, true),
85+
TyInt(_) if val < 0.0 => self.cast_int(val as i128 as u128, ty, true),
8486

85-
TyInt(_) | ty::TyUint(_) => self.cast_int(val as u64, ty, false),
87+
TyInt(_) | ty::TyUint(_) => self.cast_int(val as u128, ty, false),
8688

8789
TyFloat(FloatTy::F64) => Ok(PrimVal::from_f64(val)),
8890
TyFloat(FloatTy::F32) => Ok(PrimVal::from_f32(val as f32)),

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub enum EvalError<'tcx> {
3131
ExecuteMemory,
3232
ArrayIndexOutOfBounds(Span, u64, u64),
3333
Math(Span, ConstMathErr),
34-
InvalidChar(u64),
34+
InvalidChar(u128),
3535
OutOfMemory {
3636
allocation_size: u64,
3737
memory_size: u64,

src/eval_context.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,15 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
169169
let ptr = self.memory.allocate(s.len() as u64, 1)?;
170170
self.memory.write_bytes(ptr, s.as_bytes())?;
171171
self.memory.freeze(ptr.alloc_id)?;
172-
Ok(Value::ByValPair(PrimVal::Ptr(ptr), PrimVal::from_u64(s.len() as u64)))
172+
Ok(Value::ByValPair(PrimVal::Ptr(ptr), PrimVal::from_u128(s.len() as u128)))
173173
}
174174

175175
pub(super) fn const_to_value(&mut self, const_val: &ConstVal) -> EvalResult<'tcx, Value> {
176176
use rustc::middle::const_val::ConstVal::*;
177177
use rustc_const_math::ConstFloat;
178178

179179
let primval = match *const_val {
180-
Integral(const_int) => PrimVal::Bytes(const_int.to_u64_unchecked()),
180+
Integral(const_int) => PrimVal::Bytes(const_int.to_u128_unchecked()),
181181

182182
Float(ConstFloat::F32(f)) => PrimVal::from_f32(f),
183183
Float(ConstFloat::F64(f)) => PrimVal::from_f64(f),
@@ -429,7 +429,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
429429

430430
General { discr, ref variants, .. } => {
431431
if let mir::AggregateKind::Adt(adt_def, variant, _, _) = *kind {
432-
let discr_val = adt_def.variants[variant].disr_val.to_u64_unchecked();
432+
let discr_val = adt_def.variants[variant].disr_val.to_u128_unchecked();
433433
let discr_size = discr.size().bytes();
434434
let discr_offset = variants[variant].offsets[0].bytes();
435435

@@ -497,7 +497,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
497497
CEnum { .. } => {
498498
assert_eq!(operands.len(), 0);
499499
if let mir::AggregateKind::Adt(adt_def, variant, _, _) = *kind {
500-
let n = adt_def.variants[variant].disr_val.to_u64_unchecked();
500+
let n = adt_def.variants[variant].disr_val.to_u128_unchecked();
501501
self.write_primval(dest, PrimVal::Bytes(n), dest_ty)?;
502502
} else {
503503
bug!("tried to assign {:?} to Layout::CEnum", kind);
@@ -556,7 +556,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
556556
let src = self.eval_lvalue(lvalue)?;
557557
let ty = self.lvalue_ty(lvalue);
558558
let (_, len) = src.elem_ty_and_len(ty);
559-
self.write_primval(dest, PrimVal::from_u64(len), dest_ty)?;
559+
self.write_primval(dest, PrimVal::from_u128(len as u128), dest_ty)?;
560560
}
561561

562562
Ref(_, _, ref lvalue) => {
@@ -566,7 +566,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
566566

567567
let val = match extra {
568568
LvalueExtra::None => Value::ByVal(ptr),
569-
LvalueExtra::Length(len) => Value::ByValPair(ptr, PrimVal::from_u64(len)),
569+
LvalueExtra::Length(len) => Value::ByValPair(ptr, PrimVal::from_u128(len as u128)),
570570
LvalueExtra::Vtable(vtable) => Value::ByValPair(ptr, PrimVal::Ptr(vtable)),
571571
LvalueExtra::DowncastVariant(..) =>
572572
bug!("attempted to take a reference to an enum downcast lvalue"),
@@ -1028,6 +1028,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
10281028
I16 => 2,
10291029
I32 => 4,
10301030
I64 => 8,
1031+
I128 => 16,
10311032
Is => self.memory.pointer_size(),
10321033
};
10331034
PrimValKind::from_int_size(size)
@@ -1040,6 +1041,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
10401041
U16 => 2,
10411042
U32 => 4,
10421043
U64 => 8,
1044+
U128 => 16,
10431045
Us => self.memory.pointer_size(),
10441046
};
10451047
PrimValKind::from_uint_size(size)
@@ -1092,7 +1094,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
10921094
ty::TyBool if val.to_bytes()? > 1 => Err(EvalError::InvalidBool),
10931095

10941096
ty::TyChar if ::std::char::from_u32(val.to_bytes()? as u32).is_none()
1095-
=> Err(EvalError::InvalidChar(val.to_bytes()? as u32 as u64)),
1097+
=> Err(EvalError::InvalidChar(val.to_bytes()? as u32 as u128)),
10961098

10971099
_ => Ok(()),
10981100
}
@@ -1115,7 +1117,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
11151117
let c = self.memory.read_uint(ptr, 4)? as u32;
11161118
match ::std::char::from_u32(c) {
11171119
Some(ch) => PrimVal::from_char(ch),
1118-
None => return Err(EvalError::InvalidChar(c as u64)),
1120+
None => return Err(EvalError::InvalidChar(c as u128)),
11191121
}
11201122
}
11211123

@@ -1126,9 +1128,10 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
11261128
I16 => 2,
11271129
I32 => 4,
11281130
I64 => 8,
1131+
I128 => 16,
11291132
Is => self.memory.pointer_size(),
11301133
};
1131-
PrimVal::from_i64(self.memory.read_int(ptr, size)?)
1134+
PrimVal::from_i128(self.memory.read_int(ptr, size)?)
11321135
}
11331136

11341137
ty::TyUint(uint_ty) => {
@@ -1138,9 +1141,10 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
11381141
U16 => 2,
11391142
U32 => 4,
11401143
U64 => 8,
1144+
U128 => 16,
11411145
Us => self.memory.pointer_size(),
11421146
};
1143-
PrimVal::from_u64(self.memory.read_uint(ptr, size)?)
1147+
PrimVal::from_u128(self.memory.read_uint(ptr, size)?)
11441148
}
11451149

11461150
ty::TyFloat(FloatTy::F32) => PrimVal::from_f32(self.memory.read_f32(ptr)?),
@@ -1159,7 +1163,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
11591163
let extra = match self.tcx.struct_tail(ty).sty {
11601164
ty::TyDynamic(..) => PrimVal::Ptr(self.memory.read_ptr(extra)?),
11611165
ty::TySlice(..) |
1162-
ty::TyStr => PrimVal::from_u64(self.memory.read_usize(extra)?),
1166+
ty::TyStr => PrimVal::from_u128(self.memory.read_usize(extra)? as u128),
11631167
_ => bug!("unsized primval ptr read from {:?}", ty),
11641168
};
11651169
return Ok(Some(Value::ByValPair(PrimVal::Ptr(p), extra)));
@@ -1171,9 +1175,9 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
11711175
if let CEnum { discr, signed, .. } = *self.type_layout(ty)? {
11721176
let size = discr.size().bytes();
11731177
if signed {
1174-
PrimVal::from_i64(self.memory.read_int(ptr, size)?)
1178+
PrimVal::from_i128(self.memory.read_int(ptr, size)?)
11751179
} else {
1176-
PrimVal::from_u64(self.memory.read_uint(ptr, size)?)
1180+
PrimVal::from_u128(self.memory.read_uint(ptr, size)?)
11771181
}
11781182
} else {
11791183
return Ok(None);
@@ -1220,7 +1224,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
12201224
match (&src_pointee_ty.sty, &dest_pointee_ty.sty) {
12211225
(&ty::TyArray(_, length), &ty::TySlice(_)) => {
12221226
let ptr = src.read_ptr(&self.memory)?;
1223-
let len = PrimVal::from_u64(length as u64);
1227+
let len = PrimVal::from_u128(length as u128);
12241228
let ptr = PrimVal::Ptr(ptr);
12251229
self.write_value(Value::ByValPair(ptr, len), dest, dest_ty)?;
12261230
}
@@ -1454,6 +1458,7 @@ impl IntegerExt for layout::Integer {
14541458
I16 => Size::from_bits(16),
14551459
I32 => Size::from_bits(32),
14561460
I64 => Size::from_bits(64),
1461+
I128 => Size::from_bits(128),
14571462
}
14581463
}
14591464
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
collections_bound,
55
pub_restricted,
66
rustc_private,
7+
i128_type,
78
)]
89

910
// From rustc.

0 commit comments

Comments
 (0)