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 48ad67e commit 8f13fb0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 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 @@ -414,7 +414,11 @@ pub fn report_error<'tcx, 'mir>(

pub fn report_leaks<'mir, 'tcx>(
ecx: &InterpCx<'mir, 'tcx, MiriMachine<'mir, 'tcx>>,
leaks: Vec<(AllocId, MemoryKind<MiriMemoryKind>, Allocation<Provenance, AllocExtra<'tcx>, MiriAllocBytes>)>,
leaks: Vec<(
AllocId,
MemoryKind<MiriMemoryKind>,
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,14 +74,14 @@ extern crate rustc_target;
extern crate rustc_driver;

mod alloc_addresses;
mod alloc_bytes;
mod borrow_tracker;
mod clock;
mod concurrency;
mod diagnostics;
mod eval;
mod helpers;
mod machine;
mod alloc_bytes;
mod mono_hash_map;
mod operator;
mod provenance_gc;
Expand All @@ -104,6 +104,7 @@ pub use crate::shims::time::EvalContextExt as _;
pub use crate::shims::tls::TlsData;

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 All @@ -129,7 +130,6 @@ pub use crate::machine::{
AllocExtra, FrameExtra, 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
3 changes: 2 additions & 1 deletion src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,8 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
id: AllocId,
alloc: Cow<'b, Allocation>,
kind: Option<MemoryKind<Self::MemoryKind>>,
) -> InterpResult<'tcx, Cow<'b, Allocation<Self::Provenance, Self::AllocExtra, Self::Bytes>>> {
) -> 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(
Expand Down

0 comments on commit 8f13fb0

Please sign in to comment.