Skip to content

Commit

Permalink
remove derive(PartialEq,Eq,Hash), fix fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Strophox committed May 16, 2024
1 parent 567d18a commit 0003957
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
19 changes: 10 additions & 9 deletions src/alloc_bytes.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use std::alloc;
use std::alloc::Layout;
use std::slice;
use std::borrow::Cow;
use std::slice;

use rustc_target::abi::{Align, Size};
use rustc_middle::mir::interpret::AllocBytes;
use rustc_target::abi::{Align, Size};

/// The bytes of a Miri allocation, allocated using the size and alignment requested
/// by the interpreted program.
/// This is necessary to interface with native code that exchanges pointers with the
/// interpreted program.
/// Allocation bytes that explicitly handle the layout of the data they're storing.
/// This is necessary to interface with native code that accesses the program store in Miri.
#[derive(Debug)]
#[derive(PartialEq, Eq, Hash)] // TODO Necessary?
pub struct MiriAllocBytes {
/// Stored layout information about the allocation.
layout: alloc::Layout,
Expand Down Expand Up @@ -63,7 +60,11 @@ impl MiriAllocBytes {
/// specifically given an allocation function `alloc_fn`.
/// `alloc_fn` is only used if `size != 0`.
/// Returns `Err(layout)` if the allocation function returns a `ptr` that is `ptr.is_null()`.
fn alloc_with(size: usize, align: usize, alloc_fn: impl FnOnce(Layout) -> *mut u8) -> Result<MiriAllocBytes, Layout> {
fn alloc_with(
size: usize,
align: usize,
alloc_fn: impl FnOnce(Layout) -> *mut u8,
) -> Result<MiriAllocBytes, Layout> {
let layout = Layout::from_size_align(size, align).unwrap();
let ptr = if size == 0 {
align as *mut u8 // std::ptr::without_provenance_mut(align) : "use of unstable library feature 'strict_provenance'"
Expand Down Expand Up @@ -106,4 +107,4 @@ impl AllocBytes for MiriAllocBytes {
fn as_mut_ptr(&mut self) -> *mut u8 {
self.ptr
}
}
}
6 changes: 5 additions & 1 deletion src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,11 @@ pub fn report_error<'tcx, 'mir>(

pub fn report_leaks<'mir, 'tcx>(
ecx: &InterpCx<'mir, 'tcx, MiriMachine<'mir, 'tcx>>,
leaks: Vec<(AllocId, MemoryKind, Allocation<Provenance, AllocExtra<'tcx>, MiriAllocBytes>)>,
leaks: Vec<(
AllocId,
MemoryKind,
Allocation<Provenance, AllocExtra<'tcx>, MiriAllocBytes>,
)>,
) {
let mut any_pruned = false;
for (id, kind, mut alloc) in leaks {
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ extern crate rustc_target;
extern crate rustc_driver;

mod alloc_addresses;
mod alloc_bytes;
mod borrow_tracker;
mod clock;
mod concurrency;
Expand All @@ -82,7 +83,6 @@ mod eval;
mod helpers;
mod intrinsics;
mod machine;
mod alloc_bytes;
mod mono_hash_map;
mod operator;
mod provenance_gc;
Expand All @@ -108,6 +108,7 @@ pub use crate::shims::tls::TlsData;
pub use crate::shims::EmulateItemResult;

pub use crate::alloc_addresses::{EvalContextExt as _, ProvenanceMode};
pub use crate::alloc_bytes::MiriAllocBytes;
pub use crate::borrow_tracker::stacked_borrows::{
EvalContextExt as _, Item, Permission, Stack, Stacks,
};
Expand Down Expand Up @@ -135,7 +136,6 @@ pub use crate::machine::{
AllocExtra, FrameExtra, MemoryKind, MiriInterpCx, MiriInterpCxExt, MiriMachine, MiriMemoryKind,
PrimitiveLayouts, Provenance, ProvenanceExtra,
};
pub use crate::alloc_bytes::MiriAllocBytes;
pub use crate::mono_hash_map::MonoHashMap;
pub use crate::operator::EvalContextExt as _;
pub use crate::provenance_gc::{EvalContextExt as _, LiveAllocs, VisitProvenance, VisitWith};
Expand Down
5 changes: 3 additions & 2 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,8 +1088,9 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
id: AllocId,
alloc: Cow<'b, Allocation>,
kind: Option<MemoryKind>,
) -> InterpResult<'tcx, Cow<'b, Allocation<Self::Provenance, Self::AllocExtra, Self::Bytes>>> {
let kind = kind.expect("we set our GLOBAL_KIND so this cannot be None");
) -> InterpResult<'tcx, Cow<'b, Allocation<Self::Provenance, Self::AllocExtra, Self::Bytes>>>
{
let kind = kind.expect("we set our STATIC_KIND so this cannot be None");
if ecx.machine.tracked_alloc_ids.contains(&id) {
ecx.emit_diagnostic(NonHaltingDiagnostic::CreatedAlloc(
id,
Expand Down

0 comments on commit 0003957

Please sign in to comment.