compiler: Use size_of from the prelude instead of imported
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. These functions were added to all preludes in Rust 1.80.
This commit is contained in:
parent
ac951d3799
commit
38fad984c6
30 changed files with 64 additions and 74 deletions
|
@ -93,7 +93,7 @@ impl<T> ArenaChunk<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn end(&mut self) -> *mut T {
|
fn end(&mut self) -> *mut T {
|
||||||
unsafe {
|
unsafe {
|
||||||
if mem::size_of::<T>() == 0 {
|
if size_of::<T>() == 0 {
|
||||||
// A pointer as large as possible for zero-sized elements.
|
// A pointer as large as possible for zero-sized elements.
|
||||||
ptr::without_provenance_mut(!0)
|
ptr::without_provenance_mut(!0)
|
||||||
} else {
|
} else {
|
||||||
|
@ -151,7 +151,7 @@ impl<T> TypedArena<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
if mem::size_of::<T>() == 0 {
|
if size_of::<T>() == 0 {
|
||||||
self.ptr.set(self.ptr.get().wrapping_byte_add(1));
|
self.ptr.set(self.ptr.get().wrapping_byte_add(1));
|
||||||
let ptr = ptr::NonNull::<T>::dangling().as_ptr();
|
let ptr = ptr::NonNull::<T>::dangling().as_ptr();
|
||||||
// Don't drop the object. This `write` is equivalent to `forget`.
|
// Don't drop the object. This `write` is equivalent to `forget`.
|
||||||
|
@ -173,13 +173,13 @@ impl<T> TypedArena<T> {
|
||||||
// FIXME: this should *likely* use `offset_from`, but more
|
// FIXME: this should *likely* use `offset_from`, but more
|
||||||
// investigation is needed (including running tests in miri).
|
// investigation is needed (including running tests in miri).
|
||||||
let available_bytes = self.end.get().addr() - self.ptr.get().addr();
|
let available_bytes = self.end.get().addr() - self.ptr.get().addr();
|
||||||
let additional_bytes = additional.checked_mul(mem::size_of::<T>()).unwrap();
|
let additional_bytes = additional.checked_mul(size_of::<T>()).unwrap();
|
||||||
available_bytes >= additional_bytes
|
available_bytes >= additional_bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn alloc_raw_slice(&self, len: usize) -> *mut T {
|
fn alloc_raw_slice(&self, len: usize) -> *mut T {
|
||||||
assert!(mem::size_of::<T>() != 0);
|
assert!(size_of::<T>() != 0);
|
||||||
assert!(len != 0);
|
assert!(len != 0);
|
||||||
|
|
||||||
// Ensure the current chunk can fit `len` objects.
|
// Ensure the current chunk can fit `len` objects.
|
||||||
|
@ -213,7 +213,7 @@ impl<T> TypedArena<T> {
|
||||||
// So we collect all the elements beforehand, which takes care of reentrancy and panic
|
// So we collect all the elements beforehand, which takes care of reentrancy and panic
|
||||||
// safety. This function is much less hot than `DroplessArena::alloc_from_iter`, so it
|
// safety. This function is much less hot than `DroplessArena::alloc_from_iter`, so it
|
||||||
// doesn't need to be hyper-optimized.
|
// doesn't need to be hyper-optimized.
|
||||||
assert!(mem::size_of::<T>() != 0);
|
assert!(size_of::<T>() != 0);
|
||||||
|
|
||||||
let mut vec: SmallVec<[_; 8]> = iter.into_iter().collect();
|
let mut vec: SmallVec<[_; 8]> = iter.into_iter().collect();
|
||||||
if vec.is_empty() {
|
if vec.is_empty() {
|
||||||
|
@ -236,7 +236,7 @@ impl<T> TypedArena<T> {
|
||||||
unsafe {
|
unsafe {
|
||||||
// We need the element size to convert chunk sizes (ranging from
|
// We need the element size to convert chunk sizes (ranging from
|
||||||
// PAGE to HUGE_PAGE bytes) to element counts.
|
// PAGE to HUGE_PAGE bytes) to element counts.
|
||||||
let elem_size = cmp::max(1, mem::size_of::<T>());
|
let elem_size = cmp::max(1, size_of::<T>());
|
||||||
let mut chunks = self.chunks.borrow_mut();
|
let mut chunks = self.chunks.borrow_mut();
|
||||||
let mut new_cap;
|
let mut new_cap;
|
||||||
if let Some(last_chunk) = chunks.last_mut() {
|
if let Some(last_chunk) = chunks.last_mut() {
|
||||||
|
@ -246,7 +246,7 @@ impl<T> TypedArena<T> {
|
||||||
// FIXME: this should *likely* use `offset_from`, but more
|
// FIXME: this should *likely* use `offset_from`, but more
|
||||||
// investigation is needed (including running tests in miri).
|
// investigation is needed (including running tests in miri).
|
||||||
let used_bytes = self.ptr.get().addr() - last_chunk.start().addr();
|
let used_bytes = self.ptr.get().addr() - last_chunk.start().addr();
|
||||||
last_chunk.entries = used_bytes / mem::size_of::<T>();
|
last_chunk.entries = used_bytes / size_of::<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the previous chunk's len is less than HUGE_PAGE
|
// If the previous chunk's len is less than HUGE_PAGE
|
||||||
|
@ -276,7 +276,7 @@ impl<T> TypedArena<T> {
|
||||||
let end = self.ptr.get().addr();
|
let end = self.ptr.get().addr();
|
||||||
// We then calculate the number of elements to be dropped in the last chunk,
|
// We then calculate the number of elements to be dropped in the last chunk,
|
||||||
// which is the filled area's length.
|
// which is the filled area's length.
|
||||||
let diff = if mem::size_of::<T>() == 0 {
|
let diff = if size_of::<T>() == 0 {
|
||||||
// `T` is ZST. It can't have a drop flag, so the value here doesn't matter. We get
|
// `T` is ZST. It can't have a drop flag, so the value here doesn't matter. We get
|
||||||
// the number of zero-sized values in the last and only chunk, just out of caution.
|
// the number of zero-sized values in the last and only chunk, just out of caution.
|
||||||
// Recall that `end` was incremented for each allocated value.
|
// Recall that `end` was incremented for each allocated value.
|
||||||
|
@ -284,7 +284,7 @@ impl<T> TypedArena<T> {
|
||||||
} else {
|
} else {
|
||||||
// FIXME: this should *likely* use `offset_from`, but more
|
// FIXME: this should *likely* use `offset_from`, but more
|
||||||
// investigation is needed (including running tests in miri).
|
// investigation is needed (including running tests in miri).
|
||||||
(end - start) / mem::size_of::<T>()
|
(end - start) / size_of::<T>()
|
||||||
};
|
};
|
||||||
// Pass that to the `destroy` method.
|
// Pass that to the `destroy` method.
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -329,7 +329,7 @@ fn align_up(val: usize, align: usize) -> usize {
|
||||||
|
|
||||||
// Pointer alignment is common in compiler types, so keep `DroplessArena` aligned to them
|
// Pointer alignment is common in compiler types, so keep `DroplessArena` aligned to them
|
||||||
// to optimize away alignment code.
|
// to optimize away alignment code.
|
||||||
const DROPLESS_ALIGNMENT: usize = mem::align_of::<usize>();
|
const DROPLESS_ALIGNMENT: usize = align_of::<usize>();
|
||||||
|
|
||||||
/// An arena that can hold objects of multiple different types that impl `Copy`
|
/// An arena that can hold objects of multiple different types that impl `Copy`
|
||||||
/// and/or satisfy `!mem::needs_drop`.
|
/// and/or satisfy `!mem::needs_drop`.
|
||||||
|
@ -447,7 +447,7 @@ impl DroplessArena {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn alloc<T>(&self, object: T) -> &mut T {
|
pub fn alloc<T>(&self, object: T) -> &mut T {
|
||||||
assert!(!mem::needs_drop::<T>());
|
assert!(!mem::needs_drop::<T>());
|
||||||
assert!(mem::size_of::<T>() != 0);
|
assert!(size_of::<T>() != 0);
|
||||||
|
|
||||||
let mem = self.alloc_raw(Layout::new::<T>()) as *mut T;
|
let mem = self.alloc_raw(Layout::new::<T>()) as *mut T;
|
||||||
|
|
||||||
|
@ -471,7 +471,7 @@ impl DroplessArena {
|
||||||
T: Copy,
|
T: Copy,
|
||||||
{
|
{
|
||||||
assert!(!mem::needs_drop::<T>());
|
assert!(!mem::needs_drop::<T>());
|
||||||
assert!(mem::size_of::<T>() != 0);
|
assert!(size_of::<T>() != 0);
|
||||||
assert!(!slice.is_empty());
|
assert!(!slice.is_empty());
|
||||||
|
|
||||||
let mem = self.alloc_raw(Layout::for_value::<[T]>(slice)) as *mut T;
|
let mem = self.alloc_raw(Layout::for_value::<[T]>(slice)) as *mut T;
|
||||||
|
@ -546,7 +546,7 @@ impl DroplessArena {
|
||||||
// Warning: this function is reentrant: `iter` could hold a reference to `&self` and
|
// Warning: this function is reentrant: `iter` could hold a reference to `&self` and
|
||||||
// allocate additional elements while we're iterating.
|
// allocate additional elements while we're iterating.
|
||||||
let iter = iter.into_iter();
|
let iter = iter.into_iter();
|
||||||
assert!(mem::size_of::<T>() != 0);
|
assert!(size_of::<T>() != 0);
|
||||||
assert!(!mem::needs_drop::<T>());
|
assert!(!mem::needs_drop::<T>());
|
||||||
|
|
||||||
let size_hint = iter.size_hint();
|
let size_hint = iter.size_hint();
|
||||||
|
|
|
@ -2439,9 +2439,5 @@ fn get_maybe_pointer_size(value: RValue<'_>) -> u32 {
|
||||||
#[cfg(not(feature = "master"))]
|
#[cfg(not(feature = "master"))]
|
||||||
fn get_maybe_pointer_size(value: RValue<'_>) -> u32 {
|
fn get_maybe_pointer_size(value: RValue<'_>) -> u32 {
|
||||||
let type_ = value.get_type();
|
let type_ = value.get_type();
|
||||||
if type_.get_pointee().is_some() {
|
if type_.get_pointee().is_some() { size_of::<*const ()>() as _ } else { type_.get_size() }
|
||||||
std::mem::size_of::<*const ()>() as _
|
|
||||||
} else {
|
|
||||||
type_.get_size()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1177,7 +1177,7 @@ mod win {
|
||||||
let mut cp: u32 = 0;
|
let mut cp: u32 = 0;
|
||||||
// We're using the `LOCALE_RETURN_NUMBER` flag to return a u32.
|
// We're using the `LOCALE_RETURN_NUMBER` flag to return a u32.
|
||||||
// But the API requires us to pass the data as though it's a [u16] string.
|
// But the API requires us to pass the data as though it's a [u16] string.
|
||||||
let len = std::mem::size_of::<u32>() / std::mem::size_of::<u16>();
|
let len = size_of::<u32>() / size_of::<u16>();
|
||||||
let data = std::slice::from_raw_parts_mut(&mut cp as *mut u32 as *mut u16, len);
|
let data = std::slice::from_raw_parts_mut(&mut cp as *mut u32 as *mut u16, len);
|
||||||
let len_written = GetLocaleInfoEx(
|
let len_written = GetLocaleInfoEx(
|
||||||
LOCALE_NAME_SYSTEM_DEFAULT,
|
LOCALE_NAME_SYSTEM_DEFAULT,
|
||||||
|
|
|
@ -2,10 +2,8 @@ use std::ptr::Alignment;
|
||||||
|
|
||||||
/// Returns the ABI-required minimum alignment of a type in bytes.
|
/// Returns the ABI-required minimum alignment of a type in bytes.
|
||||||
///
|
///
|
||||||
/// This is equivalent to [`mem::align_of`], but also works for some unsized
|
/// This is equivalent to [`align_of`], but also works for some unsized
|
||||||
/// types (e.g. slices or rustc's `List`s).
|
/// types (e.g. slices or rustc's `List`s).
|
||||||
///
|
|
||||||
/// [`mem::align_of`]: std::mem::align_of
|
|
||||||
pub const fn align_of<T: ?Sized + Aligned>() -> Alignment {
|
pub const fn align_of<T: ?Sized + Aligned>() -> Alignment {
|
||||||
T::ALIGN
|
T::ALIGN
|
||||||
}
|
}
|
||||||
|
@ -15,10 +13,10 @@ pub const fn align_of<T: ?Sized + Aligned>() -> Alignment {
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// `Self::ALIGN` must be equal to the alignment of `Self`. For sized types it
|
/// `Self::ALIGN` must be equal to the alignment of `Self`. For sized types it
|
||||||
/// is [`mem::align_of<Self>()`], for unsized types it depends on the type, for
|
/// is [`align_of::<Self>()`], for unsized types it depends on the type, for
|
||||||
/// example `[T]` has alignment of `T`.
|
/// example `[T]` has alignment of `T`.
|
||||||
///
|
///
|
||||||
/// [`mem::align_of<Self>()`]: std::mem::align_of
|
/// [`align_of::<Self>()`]: align_of
|
||||||
pub unsafe trait Aligned {
|
pub unsafe trait Aligned {
|
||||||
/// Alignment of `Self`.
|
/// Alignment of `Self`.
|
||||||
const ALIGN: Alignment;
|
const ALIGN: Alignment;
|
||||||
|
|
|
@ -863,15 +863,13 @@ fn get_thread_id() -> u32 {
|
||||||
cfg_match! {
|
cfg_match! {
|
||||||
windows => {
|
windows => {
|
||||||
pub fn get_resident_set_size() -> Option<usize> {
|
pub fn get_resident_set_size() -> Option<usize> {
|
||||||
use std::mem;
|
|
||||||
|
|
||||||
use windows::{
|
use windows::{
|
||||||
Win32::System::ProcessStatus::{K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS},
|
Win32::System::ProcessStatus::{K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS},
|
||||||
Win32::System::Threading::GetCurrentProcess,
|
Win32::System::Threading::GetCurrentProcess,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut pmc = PROCESS_MEMORY_COUNTERS::default();
|
let mut pmc = PROCESS_MEMORY_COUNTERS::default();
|
||||||
let pmc_size = mem::size_of_val(&pmc);
|
let pmc_size = size_of_val(&pmc);
|
||||||
unsafe {
|
unsafe {
|
||||||
K32GetProcessMemoryInfo(
|
K32GetProcessMemoryInfo(
|
||||||
GetCurrentProcess(),
|
GetCurrentProcess(),
|
||||||
|
@ -889,7 +887,7 @@ cfg_match! {
|
||||||
pub fn get_resident_set_size() -> Option<usize> {
|
pub fn get_resident_set_size() -> Option<usize> {
|
||||||
use libc::{c_int, c_void, getpid, proc_pidinfo, proc_taskinfo, PROC_PIDTASKINFO};
|
use libc::{c_int, c_void, getpid, proc_pidinfo, proc_taskinfo, PROC_PIDTASKINFO};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
const PROC_TASKINFO_SIZE: c_int = mem::size_of::<proc_taskinfo>() as c_int;
|
const PROC_TASKINFO_SIZE: c_int = size_of::<proc_taskinfo>() as c_int;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut info: proc_taskinfo = mem::zeroed();
|
let mut info: proc_taskinfo = mem::zeroed();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
use std::collections::hash_map::RawEntryMut;
|
use std::collections::hash_map::RawEntryMut;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::{iter, mem};
|
use std::iter;
|
||||||
|
|
||||||
use either::Either;
|
use either::Either;
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ pub fn make_hash<K: Hash + ?Sized>(val: &K) -> u64 {
|
||||||
/// consistently for each `Sharded` instance.
|
/// consistently for each `Sharded` instance.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_shard_hash(hash: u64) -> usize {
|
fn get_shard_hash(hash: u64) -> usize {
|
||||||
let hash_len = mem::size_of::<usize>();
|
let hash_len = size_of::<usize>();
|
||||||
// Ignore the top 7 bits as hashbrown uses these and get the next SHARD_BITS highest bits.
|
// Ignore the top 7 bits as hashbrown uses these and get the next SHARD_BITS highest bits.
|
||||||
// hashbrown also uses the lowest bits, so we can't use those
|
// hashbrown also uses the lowest bits, so we can't use those
|
||||||
(hash >> (hash_len * 8 - 7 - SHARD_BITS)) as usize
|
(hash >> (hash_len * 8 - 7 - SHARD_BITS)) as usize
|
||||||
|
|
|
@ -490,7 +490,7 @@ pub struct Diag<'a, G: EmissionGuarantee = ErrorGuaranteed> {
|
||||||
// would be bad.
|
// would be bad.
|
||||||
impl<G> !Clone for Diag<'_, G> {}
|
impl<G> !Clone for Diag<'_, G> {}
|
||||||
|
|
||||||
rustc_data_structures::static_assert_size!(Diag<'_, ()>, 3 * std::mem::size_of::<usize>());
|
rustc_data_structures::static_assert_size!(Diag<'_, ()>, 3 * size_of::<usize>());
|
||||||
|
|
||||||
impl<G: EmissionGuarantee> Deref for Diag<'_, G> {
|
impl<G: EmissionGuarantee> Deref for Diag<'_, G> {
|
||||||
type Target = DiagInner;
|
type Target = DiagInner;
|
||||||
|
|
|
@ -429,7 +429,7 @@ pub enum Res<Id = hir::HirId> {
|
||||||
/// mention any generic parameters to allow the following with `min_const_generics`:
|
/// mention any generic parameters to allow the following with `min_const_generics`:
|
||||||
/// ```
|
/// ```
|
||||||
/// # struct Foo;
|
/// # struct Foo;
|
||||||
/// impl Foo { fn test() -> [u8; std::mem::size_of::<Self>()] { todo!() } }
|
/// impl Foo { fn test() -> [u8; size_of::<Self>()] { todo!() } }
|
||||||
///
|
///
|
||||||
/// struct Bar([u8; baz::<Self>()]);
|
/// struct Bar([u8; baz::<Self>()]);
|
||||||
/// const fn baz<T>() -> usize { 10 }
|
/// const fn baz<T>() -> usize { 10 }
|
||||||
|
@ -439,7 +439,7 @@ pub enum Res<Id = hir::HirId> {
|
||||||
/// compat lint:
|
/// compat lint:
|
||||||
/// ```
|
/// ```
|
||||||
/// fn foo<T>() {
|
/// fn foo<T>() {
|
||||||
/// let _bar = [1_u8; std::mem::size_of::<*mut T>()];
|
/// let _bar = [1_u8; size_of::<*mut T>()];
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
// FIXME(generic_const_exprs): Remove this bodge once that feature is stable.
|
// FIXME(generic_const_exprs): Remove this bodge once that feature is stable.
|
||||||
|
|
|
@ -123,7 +123,7 @@ pub(crate) fn read_file(
|
||||||
|
|
||||||
// Check HEADER_FORMAT_VERSION
|
// Check HEADER_FORMAT_VERSION
|
||||||
{
|
{
|
||||||
debug_assert!(::std::mem::size_of_val(&HEADER_FORMAT_VERSION) == 2);
|
debug_assert!(size_of_val(&HEADER_FORMAT_VERSION) == 2);
|
||||||
let mut header_format_version = [0u8; 2];
|
let mut header_format_version = [0u8; 2];
|
||||||
file.read_exact(&mut header_format_version)?;
|
file.read_exact(&mut header_format_version)?;
|
||||||
let header_format_version =
|
let header_format_version =
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
#[cfg(not(feature = "nightly"))]
|
||||||
|
use std::mem;
|
||||||
use std::ops::{BitAnd, BitAndAssign, BitOrAssign, Bound, Not, Range, RangeBounds, Shl};
|
use std::ops::{BitAnd, BitAndAssign, BitOrAssign, Bound, Not, Range, RangeBounds, Shl};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::{fmt, iter, mem, slice};
|
use std::{fmt, iter, slice};
|
||||||
|
|
||||||
use Chunk::*;
|
use Chunk::*;
|
||||||
#[cfg(feature = "nightly")]
|
#[cfg(feature = "nightly")]
|
||||||
|
@ -14,7 +16,7 @@ use crate::{Idx, IndexVec};
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
type Word = u64;
|
type Word = u64;
|
||||||
const WORD_BYTES: usize = mem::size_of::<Word>();
|
const WORD_BYTES: usize = size_of::<Word>();
|
||||||
const WORD_BITS: usize = WORD_BYTES * 8;
|
const WORD_BITS: usize = WORD_BYTES * 8;
|
||||||
|
|
||||||
// The choice of chunk size has some trade-offs.
|
// The choice of chunk size has some trade-offs.
|
||||||
|
|
|
@ -9,8 +9,6 @@ crate::newtype_index! {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn index_size_is_optimized() {
|
fn index_size_is_optimized() {
|
||||||
use std::mem::size_of;
|
|
||||||
|
|
||||||
assert_eq!(size_of::<MyIdx>(), 4);
|
assert_eq!(size_of::<MyIdx>(), 4);
|
||||||
// Uses 0xFFFF_FFFB
|
// Uses 0xFFFF_FFFB
|
||||||
assert_eq!(size_of::<Option<MyIdx>>(), 4);
|
assert_eq!(size_of::<Option<MyIdx>>(), 4);
|
||||||
|
|
|
@ -2711,7 +2711,7 @@ declare_lint! {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// const fn foo<T>() -> usize {
|
/// const fn foo<T>() -> usize {
|
||||||
/// if std::mem::size_of::<*mut T>() < 8 { // size of *mut T does not depend on T
|
/// if size_of::<*mut T>() < 8 { // size of *mut T does not depend on T
|
||||||
/// 4
|
/// 4
|
||||||
/// } else {
|
/// } else {
|
||||||
/// 8
|
/// 8
|
||||||
|
|
|
@ -223,8 +223,8 @@ impl<D: TyDecoder> Decodable<D> for InitMaskMaterialized {
|
||||||
// large.
|
// large.
|
||||||
impl hash::Hash for InitMaskMaterialized {
|
impl hash::Hash for InitMaskMaterialized {
|
||||||
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
||||||
const MAX_BLOCKS_TO_HASH: usize = super::MAX_BYTES_TO_HASH / std::mem::size_of::<Block>();
|
const MAX_BLOCKS_TO_HASH: usize = super::MAX_BYTES_TO_HASH / size_of::<Block>();
|
||||||
const MAX_BLOCKS_LEN: usize = super::MAX_HASHED_BUFFER_LEN / std::mem::size_of::<Block>();
|
const MAX_BLOCKS_LEN: usize = super::MAX_HASHED_BUFFER_LEN / size_of::<Block>();
|
||||||
|
|
||||||
// Partially hash the `blocks` buffer when it is large. To limit collisions with common
|
// Partially hash the `blocks` buffer when it is large. To limit collisions with common
|
||||||
// prefixes and suffixes, we hash the length and some slices of the buffer.
|
// prefixes and suffixes, we hash the length and some slices of the buffer.
|
||||||
|
|
|
@ -573,7 +573,7 @@ pub fn write_target_uint(
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn read_target_uint(endianness: Endian, mut source: &[u8]) -> Result<u128, io::Error> {
|
pub fn read_target_uint(endianness: Endian, mut source: &[u8]) -> Result<u128, io::Error> {
|
||||||
// This u128 holds an "any-size uint" (since smaller uints can fits in it)
|
// This u128 holds an "any-size uint" (since smaller uints can fits in it)
|
||||||
let mut buf = [0u8; std::mem::size_of::<u128>()];
|
let mut buf = [0u8; size_of::<u128>()];
|
||||||
// So we do not read exactly 16 bytes into the u128, just the "payload".
|
// So we do not read exactly 16 bytes into the u128, just the "payload".
|
||||||
let uint = match endianness {
|
let uint = match endianness {
|
||||||
Endian::Little => {
|
Endian::Little => {
|
||||||
|
|
|
@ -332,13 +332,13 @@ pub struct Body<'tcx> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// fn test<T>() {
|
/// fn test<T>() {
|
||||||
/// let _ = [0; std::mem::size_of::<*mut T>()];
|
/// let _ = [0; size_of::<*mut T>()];
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// **WARNING**: Do not change this flags after the MIR was originally created, even if an optimization
|
/// **WARNING**: Do not change this flags after the MIR was originally created, even if an optimization
|
||||||
/// removed the last mention of all generic params. We do not want to rely on optimizations and
|
/// removed the last mention of all generic params. We do not want to rely on optimizations and
|
||||||
/// potentially allow things like `[u8; std::mem::size_of::<T>() * 0]` due to this.
|
/// potentially allow things like `[u8; size_of::<T>() * 0]` due to this.
|
||||||
pub is_polymorphic: bool,
|
pub is_polymorphic: bool,
|
||||||
|
|
||||||
/// The phase at which this MIR should be "injected" into the compilation process.
|
/// The phase at which this MIR should be "injected" into the compilation process.
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub type Erase<T: EraseType> = Erased<impl Copy>;
|
||||||
pub fn erase<T: EraseType>(src: T) -> Erase<T> {
|
pub fn erase<T: EraseType>(src: T) -> Erase<T> {
|
||||||
// Ensure the sizes match
|
// Ensure the sizes match
|
||||||
const {
|
const {
|
||||||
if std::mem::size_of::<T>() != std::mem::size_of::<T::Result>() {
|
if size_of::<T>() != size_of::<T::Result>() {
|
||||||
panic!("size of T must match erased type T::Result")
|
panic!("size of T must match erased type T::Result")
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -370,7 +370,7 @@ macro_rules! define_callbacks {
|
||||||
// Increase this limit if necessary, but do try to keep the size low if possible
|
// Increase this limit if necessary, but do try to keep the size low if possible
|
||||||
#[cfg(target_pointer_width = "64")]
|
#[cfg(target_pointer_width = "64")]
|
||||||
const _: () = {
|
const _: () = {
|
||||||
if mem::size_of::<Key<'static>>() > 88 {
|
if size_of::<Key<'static>>() > 88 {
|
||||||
panic!("{}", concat!(
|
panic!("{}", concat!(
|
||||||
"the query `",
|
"the query `",
|
||||||
stringify!($name),
|
stringify!($name),
|
||||||
|
@ -386,7 +386,7 @@ macro_rules! define_callbacks {
|
||||||
#[cfg(target_pointer_width = "64")]
|
#[cfg(target_pointer_width = "64")]
|
||||||
#[cfg(not(feature = "rustc_randomized_layouts"))]
|
#[cfg(not(feature = "rustc_randomized_layouts"))]
|
||||||
const _: () = {
|
const _: () = {
|
||||||
if mem::size_of::<Value<'static>>() > 64 {
|
if size_of::<Value<'static>>() > 64 {
|
||||||
panic!("{}", concat!(
|
panic!("{}", concat!(
|
||||||
"the query `",
|
"the query `",
|
||||||
stringify!($name),
|
stringify!($name),
|
||||||
|
|
|
@ -408,7 +408,7 @@ macro_rules! from_x_for_scalar_int {
|
||||||
fn from(u: $ty) -> Self {
|
fn from(u: $ty) -> Self {
|
||||||
Self {
|
Self {
|
||||||
data: u128::from(u),
|
data: u128::from(u),
|
||||||
size: NonZero::new(std::mem::size_of::<$ty>() as u8).unwrap(),
|
size: NonZero::new(size_of::<$ty>() as u8).unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -424,7 +424,7 @@ macro_rules! from_scalar_int_for_x {
|
||||||
fn from(int: ScalarInt) -> Self {
|
fn from(int: ScalarInt) -> Self {
|
||||||
// The `unwrap` cannot fail because to_bits (if it succeeds)
|
// The `unwrap` cannot fail because to_bits (if it succeeds)
|
||||||
// is guaranteed to return a value that fits into the size.
|
// is guaranteed to return a value that fits into the size.
|
||||||
int.to_bits(Size::from_bytes(std::mem::size_of::<$ty>()))
|
int.to_bits(Size::from_bytes(size_of::<$ty>()))
|
||||||
.try_into().unwrap()
|
.try_into().unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
use core::intrinsics;
|
use core::intrinsics;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::mem;
|
|
||||||
use std::num::NonZero;
|
use std::num::NonZero;
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
|
@ -176,17 +175,17 @@ impl<'tcx> GenericArgKind<'tcx> {
|
||||||
let (tag, ptr) = match self {
|
let (tag, ptr) = match self {
|
||||||
GenericArgKind::Lifetime(lt) => {
|
GenericArgKind::Lifetime(lt) => {
|
||||||
// Ensure we can use the tag bits.
|
// Ensure we can use the tag bits.
|
||||||
assert_eq!(mem::align_of_val(&*lt.0.0) & TAG_MASK, 0);
|
assert_eq!(align_of_val(&*lt.0.0) & TAG_MASK, 0);
|
||||||
(REGION_TAG, NonNull::from(lt.0.0).cast())
|
(REGION_TAG, NonNull::from(lt.0.0).cast())
|
||||||
}
|
}
|
||||||
GenericArgKind::Type(ty) => {
|
GenericArgKind::Type(ty) => {
|
||||||
// Ensure we can use the tag bits.
|
// Ensure we can use the tag bits.
|
||||||
assert_eq!(mem::align_of_val(&*ty.0.0) & TAG_MASK, 0);
|
assert_eq!(align_of_val(&*ty.0.0) & TAG_MASK, 0);
|
||||||
(TYPE_TAG, NonNull::from(ty.0.0).cast())
|
(TYPE_TAG, NonNull::from(ty.0.0).cast())
|
||||||
}
|
}
|
||||||
GenericArgKind::Const(ct) => {
|
GenericArgKind::Const(ct) => {
|
||||||
// Ensure we can use the tag bits.
|
// Ensure we can use the tag bits.
|
||||||
assert_eq!(mem::align_of_val(&*ct.0.0) & TAG_MASK, 0);
|
assert_eq!(align_of_val(&*ct.0.0) & TAG_MASK, 0);
|
||||||
(CONST_TAG, NonNull::from(ct.0.0).cast())
|
(CONST_TAG, NonNull::from(ct.0.0).cast())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -93,7 +93,7 @@ impl<H, T> RawList<H, T> {
|
||||||
T: Copy,
|
T: Copy,
|
||||||
{
|
{
|
||||||
assert!(!mem::needs_drop::<T>());
|
assert!(!mem::needs_drop::<T>());
|
||||||
assert!(mem::size_of::<T>() != 0);
|
assert!(size_of::<T>() != 0);
|
||||||
assert!(!slice.is_empty());
|
assert!(!slice.is_empty());
|
||||||
|
|
||||||
let (layout, _offset) =
|
let (layout, _offset) =
|
||||||
|
@ -155,7 +155,7 @@ macro_rules! impl_list_empty {
|
||||||
static EMPTY: ListSkeleton<$header_ty, MaxAlign> =
|
static EMPTY: ListSkeleton<$header_ty, MaxAlign> =
|
||||||
ListSkeleton { header: $header_init, len: 0, data: [] };
|
ListSkeleton { header: $header_init, len: 0, data: [] };
|
||||||
|
|
||||||
assert!(mem::align_of::<T>() <= mem::align_of::<MaxAlign>());
|
assert!(align_of::<T>() <= align_of::<MaxAlign>());
|
||||||
|
|
||||||
// SAFETY: `EMPTY` is sufficiently aligned to be an empty list for all
|
// SAFETY: `EMPTY` is sufficiently aligned to be an empty list for all
|
||||||
// types with `align_of(T) <= align_of(MaxAlign)`, which we checked above.
|
// types with `align_of(T) <= align_of(MaxAlign)`, which we checked above.
|
||||||
|
|
|
@ -17,7 +17,7 @@ use std::hash::{Hash, Hasher};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::num::NonZero;
|
use std::num::NonZero;
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
use std::{fmt, mem, str};
|
use std::{fmt, str};
|
||||||
|
|
||||||
pub use adt::*;
|
pub use adt::*;
|
||||||
pub use assoc::*;
|
pub use assoc::*;
|
||||||
|
@ -637,12 +637,12 @@ impl<'tcx> TermKind<'tcx> {
|
||||||
let (tag, ptr) = match self {
|
let (tag, ptr) = match self {
|
||||||
TermKind::Ty(ty) => {
|
TermKind::Ty(ty) => {
|
||||||
// Ensure we can use the tag bits.
|
// Ensure we can use the tag bits.
|
||||||
assert_eq!(mem::align_of_val(&*ty.0.0) & TAG_MASK, 0);
|
assert_eq!(align_of_val(&*ty.0.0) & TAG_MASK, 0);
|
||||||
(TYPE_TAG, NonNull::from(ty.0.0).cast())
|
(TYPE_TAG, NonNull::from(ty.0.0).cast())
|
||||||
}
|
}
|
||||||
TermKind::Const(ct) => {
|
TermKind::Const(ct) => {
|
||||||
// Ensure we can use the tag bits.
|
// Ensure we can use the tag bits.
|
||||||
assert_eq!(mem::align_of_val(&*ct.0.0) & TAG_MASK, 0);
|
assert_eq!(align_of_val(&*ct.0.0) & TAG_MASK, 0);
|
||||||
(CONST_TAG, NonNull::from(ct.0.0).cast())
|
(CONST_TAG, NonNull::from(ct.0.0).cast())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -619,7 +619,7 @@ impl Iterator for TokenTypeSetIter {
|
||||||
type Item = TokenType;
|
type Item = TokenType;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<TokenType> {
|
fn next(&mut self) -> Option<TokenType> {
|
||||||
let num_bits: u32 = (std::mem::size_of_val(&self.0.0) * 8) as u32;
|
let num_bits: u32 = (size_of_val(&self.0.0) * 8) as u32;
|
||||||
assert_eq!(num_bits, 128);
|
assert_eq!(num_bits, 128);
|
||||||
let z = self.0.0.trailing_zeros();
|
let z = self.0.0.trailing_zeros();
|
||||||
if z == num_bits {
|
if z == num_bits {
|
||||||
|
|
|
@ -107,12 +107,12 @@ impl<'k> StatCollector<'k> {
|
||||||
|
|
||||||
let node = self.nodes.entry(label1).or_insert(Node::new());
|
let node = self.nodes.entry(label1).or_insert(Node::new());
|
||||||
node.stats.count += 1;
|
node.stats.count += 1;
|
||||||
node.stats.size = std::mem::size_of_val(val);
|
node.stats.size = size_of_val(val);
|
||||||
|
|
||||||
if let Some(label2) = label2 {
|
if let Some(label2) = label2 {
|
||||||
let subnode = node.subnodes.entry(label2).or_insert(NodeStats::new());
|
let subnode = node.subnodes.entry(label2).or_insert(NodeStats::new());
|
||||||
subnode.count += 1;
|
subnode.count += 1;
|
||||||
subnode.size = std::mem::size_of_val(val);
|
subnode.size = size_of_val(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ impl RWUTable {
|
||||||
/// Size of packed RWU in bits.
|
/// Size of packed RWU in bits.
|
||||||
const RWU_BITS: usize = 4;
|
const RWU_BITS: usize = 4;
|
||||||
/// Size of a word in bits.
|
/// Size of a word in bits.
|
||||||
const WORD_BITS: usize = std::mem::size_of::<u8>() * 8;
|
const WORD_BITS: usize = size_of::<u8>() * 8;
|
||||||
/// Number of packed RWUs that fit into a single word.
|
/// Number of packed RWUs that fit into a single word.
|
||||||
const WORD_RWU_COUNT: usize = Self::WORD_BITS / Self::RWU_BITS;
|
const WORD_RWU_COUNT: usize = Self::WORD_BITS / Self::RWU_BITS;
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ rustc_index::newtype_index! {
|
||||||
pub struct SerializedDepNodeIndex {}
|
pub struct SerializedDepNodeIndex {}
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEP_NODE_SIZE: usize = std::mem::size_of::<SerializedDepNodeIndex>();
|
const DEP_NODE_SIZE: usize = size_of::<SerializedDepNodeIndex>();
|
||||||
/// Amount of padding we need to add to the edge list data so that we can retrieve every
|
/// Amount of padding we need to add to the edge list data so that we can retrieve every
|
||||||
/// SerializedDepNodeIndex with a fixed-size read then mask.
|
/// SerializedDepNodeIndex with a fixed-size read then mask.
|
||||||
const DEP_NODE_PAD: usize = DEP_NODE_SIZE - 1;
|
const DEP_NODE_PAD: usize = DEP_NODE_SIZE - 1;
|
||||||
|
@ -175,7 +175,7 @@ impl EdgeHeader {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn mask(bits: usize) -> usize {
|
fn mask(bits: usize) -> usize {
|
||||||
usize::MAX >> ((std::mem::size_of::<usize>() * 8) - bits)
|
usize::MAX >> ((size_of::<usize>() * 8) - bits)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SerializedDepGraph {
|
impl SerializedDepGraph {
|
||||||
|
@ -208,9 +208,8 @@ impl SerializedDepGraph {
|
||||||
// for a node with length 64, which means the spilled 1-byte leb128 length is 1 byte of at
|
// for a node with length 64, which means the spilled 1-byte leb128 length is 1 byte of at
|
||||||
// least (34 byte header + 1 byte len + 64 bytes edge data), which is ~1%. A 2-byte leb128
|
// least (34 byte header + 1 byte len + 64 bytes edge data), which is ~1%. A 2-byte leb128
|
||||||
// length is about the same fractional overhead and it amortizes for yet greater lengths.
|
// length is about the same fractional overhead and it amortizes for yet greater lengths.
|
||||||
let mut edge_list_data = Vec::with_capacity(
|
let mut edge_list_data =
|
||||||
graph_bytes - node_count * std::mem::size_of::<SerializedNodeHeader<D>>(),
|
Vec::with_capacity(graph_bytes - node_count * size_of::<SerializedNodeHeader<D>>());
|
||||||
);
|
|
||||||
|
|
||||||
for _index in 0..node_count {
|
for _index in 0..node_count {
|
||||||
// Decode the header for this edge; the header packs together as many of the fixed-size
|
// Decode the header for this edge; the header packs together as many of the fixed-size
|
||||||
|
@ -300,7 +299,7 @@ struct Unpacked {
|
||||||
// M..M+N bytes per index
|
// M..M+N bytes per index
|
||||||
// M+N..16 kind
|
// M+N..16 kind
|
||||||
impl<D: Deps> SerializedNodeHeader<D> {
|
impl<D: Deps> SerializedNodeHeader<D> {
|
||||||
const TOTAL_BITS: usize = std::mem::size_of::<DepKind>() * 8;
|
const TOTAL_BITS: usize = size_of::<DepKind>() * 8;
|
||||||
const LEN_BITS: usize = Self::TOTAL_BITS - Self::KIND_BITS - Self::WIDTH_BITS;
|
const LEN_BITS: usize = Self::TOTAL_BITS - Self::KIND_BITS - Self::WIDTH_BITS;
|
||||||
const WIDTH_BITS: usize = DEP_NODE_WIDTH_BITS;
|
const WIDTH_BITS: usize = DEP_NODE_WIDTH_BITS;
|
||||||
const KIND_BITS: usize = Self::TOTAL_BITS - D::DEP_KIND_MAX.leading_zeros() as usize;
|
const KIND_BITS: usize = Self::TOTAL_BITS - D::DEP_KIND_MAX.leading_zeros() as usize;
|
||||||
|
|
|
@ -2994,7 +2994,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// HACK(min_const_generics, generic_const_exprs): We
|
// HACK(min_const_generics, generic_const_exprs): We
|
||||||
// want to keep allowing `[0; std::mem::size_of::<*mut T>()]`
|
// want to keep allowing `[0; size_of::<*mut T>()]`
|
||||||
// with a future compat lint for now. We do this by adding an
|
// with a future compat lint for now. We do this by adding an
|
||||||
// additional special case for repeat expressions.
|
// additional special case for repeat expressions.
|
||||||
//
|
//
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::serialize::Decoder;
|
||||||
/// Returns the length of the longest LEB128 encoding for `T`, assuming `T` is an integer type
|
/// Returns the length of the longest LEB128 encoding for `T`, assuming `T` is an integer type
|
||||||
pub const fn max_leb128_len<T>() -> usize {
|
pub const fn max_leb128_len<T>() -> usize {
|
||||||
// The longest LEB128 encoding for an integer uses 7 bits per byte.
|
// The longest LEB128 encoding for an integer uses 7 bits per byte.
|
||||||
(std::mem::size_of::<T>() * 8 + 6) / 7
|
(size_of::<T>() * 8 + 6) / 7
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the length of the longest LEB128 encoding of all supported integer types.
|
/// Returns the length of the longest LEB128 encoding of all supported integer types.
|
||||||
|
|
|
@ -92,7 +92,7 @@ fn current_dll_path() -> Result<PathBuf, String> {
|
||||||
if libc::loadquery(
|
if libc::loadquery(
|
||||||
libc::L_GETINFO,
|
libc::L_GETINFO,
|
||||||
buffer.as_mut_ptr() as *mut u8,
|
buffer.as_mut_ptr() as *mut u8,
|
||||||
(std::mem::size_of::<libc::ld_info>() * buffer.len()) as u32,
|
(size_of::<libc::ld_info>() * buffer.len()) as u32,
|
||||||
) >= 0
|
) >= 0
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//!
|
//!
|
||||||
//! For concrete constants, this is fairly simple as we can just try and evaluate it.
|
//! For concrete constants, this is fairly simple as we can just try and evaluate it.
|
||||||
//!
|
//!
|
||||||
//! When dealing with polymorphic constants, for example `std::mem::size_of::<T>() - 1`,
|
//! When dealing with polymorphic constants, for example `size_of::<T>() - 1`,
|
||||||
//! this is not as easy.
|
//! this is not as easy.
|
||||||
//!
|
//!
|
||||||
//! In this case we try to build an abstract representation of this constant using
|
//! In this case we try to build an abstract representation of this constant using
|
||||||
|
|
|
@ -58,7 +58,7 @@ impl IndexedVal for AllocId {
|
||||||
|
|
||||||
/// Utility function used to read an allocation data into a unassigned integer.
|
/// Utility function used to read an allocation data into a unassigned integer.
|
||||||
pub(crate) fn read_target_uint(mut bytes: &[u8]) -> Result<u128, Error> {
|
pub(crate) fn read_target_uint(mut bytes: &[u8]) -> Result<u128, Error> {
|
||||||
let mut buf = [0u8; std::mem::size_of::<u128>()];
|
let mut buf = [0u8; size_of::<u128>()];
|
||||||
match MachineInfo::target_endianness() {
|
match MachineInfo::target_endianness() {
|
||||||
Endian::Little => {
|
Endian::Little => {
|
||||||
bytes.read_exact(&mut buf[..bytes.len()])?;
|
bytes.read_exact(&mut buf[..bytes.len()])?;
|
||||||
|
@ -73,7 +73,7 @@ pub(crate) fn read_target_uint(mut bytes: &[u8]) -> Result<u128, Error> {
|
||||||
|
|
||||||
/// Utility function used to read an allocation data into an assigned integer.
|
/// Utility function used to read an allocation data into an assigned integer.
|
||||||
pub(crate) fn read_target_int(mut bytes: &[u8]) -> Result<i128, Error> {
|
pub(crate) fn read_target_int(mut bytes: &[u8]) -> Result<i128, Error> {
|
||||||
let mut buf = [0u8; std::mem::size_of::<i128>()];
|
let mut buf = [0u8; size_of::<i128>()];
|
||||||
match MachineInfo::target_endianness() {
|
match MachineInfo::target_endianness() {
|
||||||
Endian::Little => {
|
Endian::Little => {
|
||||||
bytes.read_exact(&mut buf[..bytes.len()])?;
|
bytes.read_exact(&mut buf[..bytes.len()])?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue