Skip to content

Commit cb5533c

Browse files
committed
remove some functions that were only used by Miri
1 parent 44ec846 commit cb5533c

File tree

2 files changed

+0
-98
lines changed

2 files changed

+0
-98
lines changed

compiler/rustc_middle/src/mir/interpret/allocation.rs

-23
Original file line numberDiff line numberDiff line change
@@ -276,29 +276,6 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
276276

277277
/// Reading and writing.
278278
impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
279-
/// Reads bytes until a `0` is encountered. Will error if the end of the allocation is reached
280-
/// before a `0` is found.
281-
///
282-
/// Most likely, you want to call `Memory::read_c_str` instead of this method.
283-
pub fn read_c_str(
284-
&self,
285-
cx: &impl HasDataLayout,
286-
ptr: Pointer<Tag>,
287-
) -> InterpResult<'tcx, &[u8]> {
288-
let offset = ptr.offset.bytes_usize();
289-
Ok(match self.bytes[offset..].iter().position(|&c| c == 0) {
290-
Some(size) => {
291-
let size_with_null = Size::from_bytes(size) + Size::from_bytes(1);
292-
// Go through `get_bytes` for checks and AllocationExtra hooks.
293-
// We read the null, so we include it in the request, but we want it removed
294-
// from the result, so we do subslicing.
295-
&self.get_bytes(cx, ptr, size_with_null)?[..size]
296-
}
297-
// This includes the case where `offset` is out-of-bounds to begin with.
298-
None => throw_ub!(UnterminatedCString(ptr.erase_tag())),
299-
})
300-
}
301-
302279
/// Validates that `ptr.offset` and `ptr.offset + size` do not point to the middle of a
303280
/// relocation. If `allow_uninit_and_ptr` is `false`, also enforces that the memory in the
304281
/// given range contains neither relocations nor uninitialized bytes.

compiler/rustc_mir/src/interpret/memory.rs

-75
Original file line numberDiff line numberDiff line change
@@ -804,41 +804,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
804804
self.get_raw(ptr.alloc_id)?.get_bytes(self, ptr, size)
805805
}
806806

807-
/// Reads a 0-terminated sequence of bytes from memory. Returns them as a slice.
808-
///
809-
/// Performs appropriate bounds checks.
810-
pub fn read_c_str(&self, ptr: Scalar<M::PointerTag>) -> InterpResult<'tcx, &[u8]> {
811-
let ptr = self.force_ptr(ptr)?; // We need to read at least 1 byte, so we *need* a ptr.
812-
self.get_raw(ptr.alloc_id)?.read_c_str(self, ptr)
813-
}
814-
815-
/// Reads a 0x0000-terminated u16-sequence from memory. Returns them as a Vec<u16>.
816-
/// Terminator 0x0000 is not included in the returned Vec<u16>.
817-
///
818-
/// Performs appropriate bounds checks.
819-
pub fn read_wide_str(&self, ptr: Scalar<M::PointerTag>) -> InterpResult<'tcx, Vec<u16>> {
820-
let size_2bytes = Size::from_bytes(2);
821-
let align_2bytes = Align::from_bytes(2).unwrap();
822-
// We need to read at least 2 bytes, so we *need* a ptr.
823-
let mut ptr = self.force_ptr(ptr)?;
824-
let allocation = self.get_raw(ptr.alloc_id)?;
825-
let mut u16_seq = Vec::new();
826-
827-
loop {
828-
ptr = self
829-
.check_ptr_access(ptr.into(), size_2bytes, align_2bytes)?
830-
.expect("cannot be a ZST");
831-
let single_u16 = allocation.read_scalar(self, ptr, size_2bytes)?.to_u16()?;
832-
if single_u16 != 0x0000 {
833-
u16_seq.push(single_u16);
834-
ptr = ptr.offset(size_2bytes, self)?;
835-
} else {
836-
break;
837-
}
838-
}
839-
Ok(u16_seq)
840-
}
841-
842807
/// Writes the given stream of bytes into memory.
843808
///
844809
/// Performs appropriate bounds checks.
@@ -866,46 +831,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
866831
self.get_raw_mut(ptr.alloc_id)?.write_bytes(&tcx, ptr, src)
867832
}
868833

869-
/// Writes the given stream of u16s into memory.
870-
///
871-
/// Performs appropriate bounds checks.
872-
pub fn write_u16s(
873-
&mut self,
874-
ptr: Scalar<M::PointerTag>,
875-
src: impl IntoIterator<Item = u16>,
876-
) -> InterpResult<'tcx> {
877-
let mut src = src.into_iter();
878-
let (lower, upper) = src.size_hint();
879-
let len = upper.expect("can only write bounded iterators");
880-
assert_eq!(lower, len, "can only write iterators with a precise length");
881-
882-
let size = Size::from_bytes(lower);
883-
let ptr = match self.check_ptr_access(ptr, size, Align::from_bytes(2).unwrap())? {
884-
Some(ptr) => ptr,
885-
None => {
886-
// zero-sized access
887-
assert_matches!(
888-
src.next(),
889-
None,
890-
"iterator said it was empty but returned an element"
891-
);
892-
return Ok(());
893-
}
894-
};
895-
let tcx = self.tcx;
896-
let allocation = self.get_raw_mut(ptr.alloc_id)?;
897-
898-
for idx in 0..len {
899-
let val = Scalar::from_u16(
900-
src.next().expect("iterator was shorter than it said it would be"),
901-
);
902-
let offset_ptr = ptr.offset(Size::from_bytes(idx) * 2, &tcx)?; // `Size` multiplication
903-
allocation.write_scalar(&tcx, offset_ptr, val.into(), Size::from_bytes(2))?;
904-
}
905-
assert_matches!(src.next(), None, "iterator was longer than it said it would be");
906-
Ok(())
907-
}
908-
909834
/// Expects the caller to have checked bounds and alignment.
910835
pub fn copy(
911836
&mut self,

0 commit comments

Comments
 (0)