]> git.lizzy.rs Git - rust.git/commitdiff
miri: allocation is infallible
authorRalf Jung <post@ralfj.de>
Wed, 19 Dec 2018 13:11:01 +0000 (14:11 +0100)
committerRalf Jung <post@ralfj.de>
Wed, 19 Dec 2018 13:11:01 +0000 (14:11 +0100)
src/librustc_mir/const_eval.rs
src/librustc_mir/interpret/machine.rs
src/librustc_mir/interpret/memory.rs
src/librustc_mir/interpret/operand.rs
src/librustc_mir/interpret/place.rs
src/librustc_mir/interpret/traits.rs
src/librustc_mir/transform/const_prop.rs

index 248c5d2db491748426dc7cedc48c3cc7e3c806cc..6e0f1c8b80c3284a3ad08141ec2b6dd5f74037be 100644 (file)
@@ -187,7 +187,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
     }
     let layout = ecx.layout_of(mir.return_ty().subst(tcx, cid.instance.substs))?;
     assert!(!layout.is_unsized());
-    let ret = ecx.allocate(layout, MemoryKind::Stack)?;
+    let ret = ecx.allocate(layout, MemoryKind::Stack);
 
     let name = ty::tls::with(|tcx| tcx.item_path_str(cid.instance.def_id()));
     let prom = cid.promoted.map_or(String::new(), |p| format!("::promoted[{:?}]", p));
@@ -490,8 +490,8 @@ fn tag_new_allocation(
         _ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
         ptr: Pointer,
         _kind: MemoryKind<Self::MemoryKinds>,
-    ) -> EvalResult<'tcx, Pointer> {
-        Ok(ptr)
+    ) -> Pointer {
+        ptr
     }
 
     #[inline(always)]
index 4c7aa887045c718ef2b2c899e4fc27090ab9fc20..74b633d67956e0c57d15bbf04b18da46e80f14ab 100644 (file)
@@ -185,7 +185,7 @@ fn tag_new_allocation(
         ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
         ptr: Pointer,
         kind: MemoryKind<Self::MemoryKinds>,
-    ) -> EvalResult<'tcx, Pointer<Self::PointerTag>>;
+    ) -> Pointer<Self::PointerTag>;
 
     /// Executed when evaluating the `*` operator: Following a reference.
     /// This has the chance to adjust the tag.  It should not change anything else!
index 420fe26426321909d04583b086cb8aee15a3e6ea..ddecdd44347f6b66e94d323395537b91c7dfbe06 100644 (file)
@@ -131,10 +131,10 @@ pub fn allocate_with(
         &mut self,
         alloc: Allocation<M::PointerTag, M::AllocExtra>,
         kind: MemoryKind<M::MemoryKinds>,
-    ) -> EvalResult<'tcx, AllocId> {
+    ) -> AllocId {
         let id = self.tcx.alloc_map.lock().reserve();
         self.alloc_map.insert(id, (kind, alloc));
-        Ok(id)
+        id
     }
 
     pub fn allocate(
@@ -142,9 +142,9 @@ pub fn allocate(
         size: Size,
         align: Align,
         kind: MemoryKind<M::MemoryKinds>,
-    ) -> EvalResult<'tcx, Pointer> {
+    ) -> Pointer {
         let extra = AllocationExtra::memory_allocated(size, &self.extra);
-        Ok(Pointer::from(self.allocate_with(Allocation::undef(size, align, extra), kind)?))
+        Pointer::from(self.allocate_with(Allocation::undef(size, align, extra), kind))
     }
 
     pub fn reallocate(
@@ -162,7 +162,7 @@ pub fn reallocate(
 
         // For simplicities' sake, we implement reallocate as "alloc, copy, dealloc".
         // This happens so rarely, the perf advantage is outweighed by the maintenance cost.
-        let new_ptr = self.allocate(new_size, new_align, kind)?;
+        let new_ptr = self.allocate(new_size, new_align, kind);
         self.copy(
             ptr.into(),
             old_align,
index 83ceadada65ce68f0e1a62c47a064e6f65a47aee..7143d66ad9246ef190a233d6de9cd24815f620af 100644 (file)
@@ -382,7 +382,7 @@ pub fn uninit_operand(
             _ => {
                 trace!("Forcing allocation for local of type {:?}", layout.ty);
                 Operand::Indirect(
-                    *self.allocate(layout, MemoryKind::Stack)?
+                    *self.allocate(layout, MemoryKind::Stack)
                 )
             }
         })
index bae670bf2b4b3b1b7e6dc6cc67a55b061430d32b..e316b54f8ca7da77424243e9f7e51e20cf04b3ae 100644 (file)
@@ -911,7 +911,7 @@ pub fn force_allocation(
                         // that might e.g., be an inner field of a struct with `Scalar` layout,
                         // that has different alignment than the outer field.
                         let local_layout = self.layout_of_local(&self.stack[frame], local)?;
-                        let ptr = self.allocate(local_layout, MemoryKind::Stack)?;
+                        let ptr = self.allocate(local_layout, MemoryKind::Stack);
                         // We don't have to validate as we can assume the local
                         // was already valid for its type.
                         self.write_immediate_to_mplace_no_validate(value, ptr)?;
@@ -933,15 +933,15 @@ pub fn allocate(
         &mut self,
         layout: TyLayout<'tcx>,
         kind: MemoryKind<M::MemoryKinds>,
-    ) -> EvalResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
+    ) -> MPlaceTy<'tcx, M::PointerTag> {
         if layout.is_unsized() {
             assert!(self.tcx.features().unsized_locals, "cannot alloc memory for unsized type");
             // FIXME: What should we do here? We should definitely also tag!
-            Ok(MPlaceTy::dangling(layout, self))
+            MPlaceTy::dangling(layout, self)
         } else {
-            let ptr = self.memory.allocate(layout.size, layout.align.abi, kind)?;
-            let ptr = M::tag_new_allocation(self, ptr, kind)?;
-            Ok(MPlaceTy::from_aligned_ptr(ptr, layout))
+            let ptr = self.memory.allocate(layout.size, layout.align.abi, kind);
+            let ptr = M::tag_new_allocation(self, ptr, kind);
+            MPlaceTy::from_aligned_ptr(ptr, layout)
         }
     }
 
index bda585b8eda349f82ad817601495994f14af6b55..22936a9b0a0cf795769068998c09ecb6d7968c68 100644 (file)
@@ -54,7 +54,7 @@ pub fn get_vtable(
             ptr_size * (3 + methods.len() as u64),
             ptr_align,
             MemoryKind::Vtable,
-        )?.with_default_tag();
+        ).with_default_tag();
         let tcx = &*self.tcx;
 
         let drop = ::monomorphize::resolve_drop_in_place(*tcx, ty);
index acae03f7f94f5ca05ad6046ddba442fd7faeccb5..cfa899eb5a62a11410e9d34b831bcca263e7eaa2 100644 (file)
@@ -346,7 +346,7 @@ fn const_prop(
             Rvalue::Cast(kind, ref operand, _) => {
                 let (op, span) = self.eval_operand(operand, source_info)?;
                 self.use_ecx(source_info, |this| {
-                    let dest = this.ecx.allocate(place_layout, MemoryKind::Stack)?;
+                    let dest = this.ecx.allocate(place_layout, MemoryKind::Stack);
                     this.ecx.cast(op, kind, dest.into())?;
                     Ok((dest.into(), span))
                 })