]> git.lizzy.rs Git - rust.git/commitdiff
miri: Rename to_{u,i}size to to_machine_{u,i}size
authorRalf Jung <post@ralfj.de>
Wed, 6 Nov 2019 12:00:14 +0000 (13:00 +0100)
committerRalf Jung <post@ralfj.de>
Fri, 8 Nov 2019 08:21:49 +0000 (09:21 +0100)
Having a function `to_usize` that does not return a usize is somewhat confusing

src/librustc/mir/interpret/value.rs
src/librustc_mir/const_eval.rs
src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/interpret/intern.rs
src/librustc_mir/interpret/intrinsics.rs
src/librustc_mir/interpret/memory.rs
src/librustc_mir/interpret/place.rs
src/librustc_mir/interpret/validity.rs

index ac16b8b884c450f9b51b8729e2c051087d056b84..7b29fb26e74f51e0321b49ec61e85ed54bcde0b6 100644 (file)
@@ -439,7 +439,7 @@ pub fn to_u64(self) -> InterpResult<'static, u64> {
         Ok(b as u64)
     }
 
-    pub fn to_usize(self, cx: &impl HasDataLayout) -> InterpResult<'static, u64> {
+    pub fn to_machine_usize(self, cx: &impl HasDataLayout) -> InterpResult<'static, u64> {
         let b = self.to_bits(cx.data_layout().pointer_size)?;
         Ok(b as u64)
     }
@@ -465,7 +465,7 @@ pub fn to_i64(self) -> InterpResult<'static, i64> {
         Ok(b as i64)
     }
 
-    pub fn to_isize(self, cx: &impl HasDataLayout) -> InterpResult<'static, i64> {
+    pub fn to_machine_isize(self, cx: &impl HasDataLayout) -> InterpResult<'static, i64> {
         let sz = cx.data_layout().pointer_size;
         let b = self.to_bits(sz)?;
         let b = sign_extend(b, sz) as i128;
@@ -592,8 +592,8 @@ pub fn to_u64(self) -> InterpResult<'tcx, u64> {
     }
 
     #[inline(always)]
-    pub fn to_usize(self, cx: &impl HasDataLayout) -> InterpResult<'tcx, u64> {
-        self.not_undef()?.to_usize(cx)
+    pub fn to_machine_usize(self, cx: &impl HasDataLayout) -> InterpResult<'tcx, u64> {
+        self.not_undef()?.to_machine_usize(cx)
     }
 
     #[inline(always)]
@@ -612,8 +612,8 @@ pub fn to_i64(self) -> InterpResult<'tcx, i64> {
     }
 
     #[inline(always)]
-    pub fn to_isize(self, cx: &impl HasDataLayout) -> InterpResult<'tcx, i64> {
-        self.not_undef()?.to_isize(cx)
+    pub fn to_machine_isize(self, cx: &impl HasDataLayout) -> InterpResult<'tcx, i64> {
+        self.not_undef()?.to_machine_isize(cx)
     }
 }
 
index 89bdf7391c3e8bd6b6af49064593f71cb1ed3243..707ad1511826a67751d9cc8ceedb0bc0954e05b6 100644 (file)
@@ -118,7 +118,7 @@ fn op_to_const<'tcx>(
                     0,
                 ),
             };
-            let len = b.to_usize(&ecx.tcx.tcx).unwrap();
+            let len = b.to_machine_usize(&ecx.tcx.tcx).unwrap();
             let start = start.try_into().unwrap();
             let len: usize = len.try_into().unwrap();
             ConstValue::Slice {
index d929e958f05d0944b3faaa1b2ca164cb827a95f4..8e901068a8d26f78176b343d7788ffac6a02b6f2 100644 (file)
@@ -447,7 +447,7 @@ pub(super) fn size_and_align_of(
             }
 
             ty::Slice(_) | ty::Str => {
-                let len = metadata.expect("slice fat ptr must have vtable").to_usize(self)?;
+                let len = metadata.expect("slice fat ptr must have length").to_machine_usize(self)?;
                 let elem = layout.field(self, 0)?;
 
                 // Make sure the slice is not too big.
index 2171ceaa452c88f9134901485a9ced9f9f9c3900..a7de533506c01404313d00053ffe6fd082c7e132 100644 (file)
@@ -228,7 +228,7 @@ fn visit_primitive(&mut self, mplace: MPlaceTy<'tcx>) -> InterpResult<'tcx> {
                             ty::Array(_, n)
                                 if n.eval_usize(self.ecx.tcx.tcx, self.ecx.param_env) == 0 => {}
                             ty::Slice(_)
-                                if mplace.meta.unwrap().to_usize(self.ecx)? == 0 => {}
+                                if mplace.meta.unwrap().to_machine_usize(self.ecx)? == 0 => {}
                             _ => bug!("const qualif failed to prevent mutable references"),
                         }
                     },
index 1b5cc2f0948ab5854490e2715ee3cb985e61ddd7..39f10d8e6045dfeb7a731eeefb4b3344eced17a7 100644 (file)
@@ -263,8 +263,8 @@ pub fn emulate_intrinsic(
                 // This is the dual to the special exception for offset-by-0
                 // in the inbounds pointer offset operation (see the Miri code, `src/operator.rs`).
                 if a.is_bits() && b.is_bits() {
-                    let a = a.to_usize(self)?;
-                    let b = b.to_usize(self)?;
+                    let a = a.to_machine_usize(self)?;
+                    let b = b.to_machine_usize(self)?;
                     if a == b && a != 0 {
                         self.write_scalar(Scalar::from_int(0, isize_layout.size), dest)?;
                         return Ok(true);
index 47b918248330abfcda020050b2628c0bbf5126ea..fce2aadd7fe4cca7973bf280b444e6d9134d94fd 100644 (file)
@@ -915,7 +915,7 @@ pub fn force_ptr(
     ) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
         match scalar {
             Scalar::Ptr(ptr) => Ok(ptr),
-            _ => M::int_to_ptr(&self, scalar.to_usize(self)?)
+            _ => M::int_to_ptr(&self, scalar.to_machine_usize(self)?)
         }
     }
 
index 36e58d356d1004b732d078b2bb5853f13a2a8666..d45cb9f7c81977aeba14bb2887874be5fe0eeaab 100644 (file)
@@ -195,7 +195,7 @@ pub(super) fn len(self, cx: &impl HasDataLayout) -> InterpResult<'tcx, u64> {
             // We need to consult `meta` metadata
             match self.layout.ty.kind {
                 ty::Slice(..) | ty::Str =>
-                    return self.mplace.meta.unwrap().to_usize(cx),
+                    return self.mplace.meta.unwrap().to_machine_usize(cx),
                 _ => bug!("len not supported on unsized type {:?}", self.layout.ty),
             }
         } else {
index 8cb2f6c3462cc94083b5a342de4304805db95a29..3eb5fa18f930e79ce64fd0dc4696d16f9b8b4ef6 100644 (file)
@@ -282,7 +282,7 @@ fn check_wide_ptr_meta(
                 // FIXME: More checks for the vtable.
             }
             ty::Slice(..) | ty::Str => {
-                let _len = try_validation!(meta.unwrap().to_usize(self.ecx),
+                let _len = try_validation!(meta.unwrap().to_machine_usize(self.ecx),
                     "non-integer slice length in wide pointer", self.path);
                 // We do not check that `len * elem_size <= isize::MAX`:
                 // that is only required for references, and there it falls out of the