Skip to content

Commit 132f477

Browse files
authored
Rollup merge of rust-lang#56981 - RalfJung:miri-infallible-alloc, r=oli-obk
miri: allocation is infallible
2 parents bd12d8f + 81a45e2 commit 132f477

File tree

7 files changed

+18
-18
lines changed

7 files changed

+18
-18
lines changed

src/librustc_mir/const_eval.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
187187
}
188188
let layout = ecx.layout_of(mir.return_ty().subst(tcx, cid.instance.substs))?;
189189
assert!(!layout.is_unsized());
190-
let ret = ecx.allocate(layout, MemoryKind::Stack)?;
190+
let ret = ecx.allocate(layout, MemoryKind::Stack);
191191

192192
let name = ty::tls::with(|tcx| tcx.item_path_str(cid.instance.def_id()));
193193
let prom = cid.promoted.map_or(String::new(), |p| format!("::promoted[{:?}]", p));
@@ -490,8 +490,8 @@ impl<'a, 'mir, 'tcx> interpret::Machine<'a, 'mir, 'tcx>
490490
_ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
491491
ptr: Pointer,
492492
_kind: MemoryKind<Self::MemoryKinds>,
493-
) -> EvalResult<'tcx, Pointer> {
494-
Ok(ptr)
493+
) -> Pointer {
494+
ptr
495495
}
496496

497497
#[inline(always)]

src/librustc_mir/interpret/machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pub trait Machine<'a, 'mir, 'tcx>: Sized {
185185
ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
186186
ptr: Pointer,
187187
kind: MemoryKind<Self::MemoryKinds>,
188-
) -> EvalResult<'tcx, Pointer<Self::PointerTag>>;
188+
) -> Pointer<Self::PointerTag>;
189189

190190
/// Executed when evaluating the `*` operator: Following a reference.
191191
/// This has the chance to adjust the tag. It should not change anything else!

src/librustc_mir/interpret/memory.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,20 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
131131
&mut self,
132132
alloc: Allocation<M::PointerTag, M::AllocExtra>,
133133
kind: MemoryKind<M::MemoryKinds>,
134-
) -> EvalResult<'tcx, AllocId> {
134+
) -> AllocId {
135135
let id = self.tcx.alloc_map.lock().reserve();
136136
self.alloc_map.insert(id, (kind, alloc));
137-
Ok(id)
137+
id
138138
}
139139

140140
pub fn allocate(
141141
&mut self,
142142
size: Size,
143143
align: Align,
144144
kind: MemoryKind<M::MemoryKinds>,
145-
) -> EvalResult<'tcx, Pointer> {
145+
) -> Pointer {
146146
let extra = AllocationExtra::memory_allocated(size, &self.extra);
147-
Ok(Pointer::from(self.allocate_with(Allocation::undef(size, align, extra), kind)?))
147+
Pointer::from(self.allocate_with(Allocation::undef(size, align, extra), kind))
148148
}
149149

150150
pub fn reallocate(
@@ -162,7 +162,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
162162

163163
// For simplicities' sake, we implement reallocate as "alloc, copy, dealloc".
164164
// This happens so rarely, the perf advantage is outweighed by the maintenance cost.
165-
let new_ptr = self.allocate(new_size, new_align, kind)?;
165+
let new_ptr = self.allocate(new_size, new_align, kind);
166166
self.copy(
167167
ptr.into(),
168168
old_align,

src/librustc_mir/interpret/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
382382
_ => {
383383
trace!("Forcing allocation for local of type {:?}", layout.ty);
384384
Operand::Indirect(
385-
*self.allocate(layout, MemoryKind::Stack)?
385+
*self.allocate(layout, MemoryKind::Stack)
386386
)
387387
}
388388
})

src/librustc_mir/interpret/place.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ where
911911
// that might e.g., be an inner field of a struct with `Scalar` layout,
912912
// that has different alignment than the outer field.
913913
let local_layout = self.layout_of_local(&self.stack[frame], local)?;
914-
let ptr = self.allocate(local_layout, MemoryKind::Stack)?;
914+
let ptr = self.allocate(local_layout, MemoryKind::Stack);
915915
// We don't have to validate as we can assume the local
916916
// was already valid for its type.
917917
self.write_immediate_to_mplace_no_validate(value, ptr)?;
@@ -933,15 +933,15 @@ where
933933
&mut self,
934934
layout: TyLayout<'tcx>,
935935
kind: MemoryKind<M::MemoryKinds>,
936-
) -> EvalResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
936+
) -> MPlaceTy<'tcx, M::PointerTag> {
937937
if layout.is_unsized() {
938938
assert!(self.tcx.features().unsized_locals, "cannot alloc memory for unsized type");
939939
// FIXME: What should we do here? We should definitely also tag!
940-
Ok(MPlaceTy::dangling(layout, self))
940+
MPlaceTy::dangling(layout, self)
941941
} else {
942-
let ptr = self.memory.allocate(layout.size, layout.align.abi, kind)?;
943-
let ptr = M::tag_new_allocation(self, ptr, kind)?;
944-
Ok(MPlaceTy::from_aligned_ptr(ptr, layout))
942+
let ptr = self.memory.allocate(layout.size, layout.align.abi, kind);
943+
let ptr = M::tag_new_allocation(self, ptr, kind);
944+
MPlaceTy::from_aligned_ptr(ptr, layout)
945945
}
946946
}
947947

src/librustc_mir/interpret/traits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
5454
ptr_size * (3 + methods.len() as u64),
5555
ptr_align,
5656
MemoryKind::Vtable,
57-
)?.with_default_tag();
57+
).with_default_tag();
5858
let tcx = &*self.tcx;
5959

6060
let drop = ::monomorphize::resolve_drop_in_place(*tcx, ty);

src/librustc_mir/transform/const_prop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
346346
Rvalue::Cast(kind, ref operand, _) => {
347347
let (op, span) = self.eval_operand(operand, source_info)?;
348348
self.use_ecx(source_info, |this| {
349-
let dest = this.ecx.allocate(place_layout, MemoryKind::Stack)?;
349+
let dest = this.ecx.allocate(place_layout, MemoryKind::Stack);
350350
this.ecx.cast(op, kind, dest.into())?;
351351
Ok((dest.into(), span))
352352
})

0 commit comments

Comments
 (0)