Skip to content

Commit

Permalink
Merge from rustc
Browse files Browse the repository at this point in the history
  • Loading branch information
The Miri Cronjob Bot committed Jul 24, 2024
2 parents 00b4f61 + eee5bba commit 16450f7
Show file tree
Hide file tree
Showing 46 changed files with 1,898 additions and 275 deletions.
83 changes: 81 additions & 2 deletions alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ impl<T> Box<[T]> {
}

/// Constructs a new boxed slice with uninitialized contents. Returns an error if
/// the allocation fails
/// the allocation fails.
///
/// # Examples
///
Expand Down Expand Up @@ -739,7 +739,7 @@ impl<T> Box<[T]> {
}

/// Constructs a new boxed slice with uninitialized contents, with the memory
/// being filled with `0` bytes. Returns an error if the allocation fails
/// being filled with `0` bytes. Returns an error if the allocation fails.
///
/// See [`MaybeUninit::zeroed`][zeroed] for examples of correct and incorrect usage
/// of this method.
Expand Down Expand Up @@ -831,6 +831,85 @@ impl<T, A: Allocator> Box<[T], A> {
pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit<T>], A> {
unsafe { RawVec::with_capacity_zeroed_in(len, alloc).into_box(len) }
}

/// Constructs a new boxed slice with uninitialized contents in the provided allocator. Returns an error if
/// the allocation fails.
///
/// # Examples
///
/// ```
/// #![feature(allocator_api, new_uninit)]
///
/// use std::alloc::System;
///
/// let mut values = Box::<[u32], _>::try_new_uninit_slice_in(3, System)?;
/// let values = unsafe {
/// // Deferred initialization:
/// values[0].as_mut_ptr().write(1);
/// values[1].as_mut_ptr().write(2);
/// values[2].as_mut_ptr().write(3);
/// values.assume_init()
/// };
///
/// assert_eq!(*values, [1, 2, 3]);
/// # Ok::<(), std::alloc::AllocError>(())
/// ```
#[unstable(feature = "allocator_api", issue = "32838")]
#[inline]
pub fn try_new_uninit_slice_in(
len: usize,
alloc: A,
) -> Result<Box<[mem::MaybeUninit<T>], A>, AllocError> {
let ptr = if T::IS_ZST || len == 0 {
NonNull::dangling()
} else {
let layout = match Layout::array::<mem::MaybeUninit<T>>(len) {
Ok(l) => l,
Err(_) => return Err(AllocError),
};
alloc.allocate(layout)?.cast()
};
unsafe { Ok(RawVec::from_raw_parts_in(ptr.as_ptr(), len, alloc).into_box(len)) }
}

/// Constructs a new boxed slice with uninitialized contents in the provided allocator, with the memory
/// being filled with `0` bytes. Returns an error if the allocation fails.
///
/// See [`MaybeUninit::zeroed`][zeroed] for examples of correct and incorrect usage
/// of this method.
///
/// # Examples
///
/// ```
/// #![feature(allocator_api, new_uninit)]
///
/// use std::alloc::System;
///
/// let values = Box::<[u32], _>::try_new_zeroed_slice_in(3, System)?;
/// let values = unsafe { values.assume_init() };
///
/// assert_eq!(*values, [0, 0, 0]);
/// # Ok::<(), std::alloc::AllocError>(())
/// ```
///
/// [zeroed]: mem::MaybeUninit::zeroed
#[unstable(feature = "allocator_api", issue = "32838")]
#[inline]
pub fn try_new_zeroed_slice_in(
len: usize,
alloc: A,
) -> Result<Box<[mem::MaybeUninit<T>], A>, AllocError> {
let ptr = if T::IS_ZST || len == 0 {
NonNull::dangling()
} else {
let layout = match Layout::array::<mem::MaybeUninit<T>>(len) {
Ok(l) => l,
Err(_) => return Err(AllocError),
};
alloc.allocate_zeroed(layout)?.cast()
};
unsafe { Ok(RawVec::from_raw_parts_in(ptr.as_ptr(), len, alloc).into_box(len)) }
}
}

impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
Expand Down
2 changes: 2 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
#![feature(const_unsafecell_get_mut)]
#![feature(const_waker)]
#![feature(coverage_attribute)]
#![feature(do_not_recommend)]
#![feature(duration_consts_float)]
#![feature(internal_impls_macro)]
#![feature(ip)]
Expand Down Expand Up @@ -248,6 +249,7 @@
#![feature(transparent_unions)]
#![feature(try_blocks)]
#![feature(unboxed_closures)]
#![feature(unsized_const_params)]
#![feature(unsized_fn_params)]
#![feature(with_negative_coherence)]
// tidy-alphabetical-end
Expand Down
56 changes: 49 additions & 7 deletions core/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -975,31 +975,73 @@ pub trait PointerLike {}
/// that all fields are also `ConstParamTy`, which implies that recursively, all fields
/// are `StructuralPartialEq`.
#[lang = "const_param_ty"]
#[unstable(feature = "adt_const_params", issue = "95174")]
#[unstable(feature = "unsized_const_params", issue = "95174")]
#[diagnostic::on_unimplemented(message = "`{Self}` can't be used as a const parameter type")]
#[allow(multiple_supertrait_upcastable)]
pub trait ConstParamTy: StructuralPartialEq + Eq {}
// We name this differently than the derive macro so that the `adt_const_params` can
// be used independently of `unsized_const_params` without requiring a full path
// to the derive macro every time it is used. This should be renamed on stabilization.
pub trait ConstParamTy_: UnsizedConstParamTy + StructuralPartialEq + Eq {}

/// Derive macro generating an impl of the trait `ConstParamTy`.
#[rustc_builtin_macro]
#[allow_internal_unstable(unsized_const_params)]
#[unstable(feature = "adt_const_params", issue = "95174")]
pub macro ConstParamTy($item:item) {
/* compiler built-in */
}

#[cfg_attr(not(bootstrap), lang = "unsized_const_param_ty")]
#[unstable(feature = "unsized_const_params", issue = "95174")]
#[diagnostic::on_unimplemented(message = "`{Self}` can't be used as a const parameter type")]
/// A marker for types which can be used as types of `const` generic parameters.
///
/// Equivalent to [`ConstParamTy_`] except that this is used by
/// the `unsized_const_params` to allow for fake unstable impls.
pub trait UnsizedConstParamTy: StructuralPartialEq + Eq {}

/// Derive macro generating an impl of the trait `ConstParamTy`.
#[cfg(not(bootstrap))]
#[cfg_attr(not(bootstrap), rustc_builtin_macro)]
#[cfg_attr(not(bootstrap), allow_internal_unstable(unsized_const_params))]
#[cfg_attr(not(bootstrap), unstable(feature = "unsized_const_params", issue = "95174"))]
pub macro UnsizedConstParamTy($item:item) {
/* compiler built-in */
}

// FIXME(adt_const_params): handle `ty::FnDef`/`ty::Closure`
marker_impls! {
#[unstable(feature = "adt_const_params", issue = "95174")]
ConstParamTy for
ConstParamTy_ for
usize, u8, u16, u32, u64, u128,
isize, i8, i16, i32, i64, i128,
bool,
char,
(),
{T: ConstParamTy_, const N: usize} [T; N],
}
#[cfg(bootstrap)]
marker_impls! {
#[unstable(feature = "adt_const_params", issue = "95174")]
ConstParamTy_ for
str,
{T: ConstParamTy_} [T],
{T: ConstParamTy_ + ?Sized} &T,
}

marker_impls! {
#[unstable(feature = "unsized_const_params", issue = "95174")]
UnsizedConstParamTy for
usize, u8, u16, u32, u64, u128,
isize, i8, i16, i32, i64, i128,
bool,
char,
str /* Technically requires `[u8]: ConstParamTy` */,
(),
{T: ConstParamTy, const N: usize} [T; N],
{T: ConstParamTy} [T],
{T: ?Sized + ConstParamTy} &T,
{T: UnsizedConstParamTy, const N: usize} [T; N],

str,
{T: UnsizedConstParamTy} [T],
{T: UnsizedConstParamTy + ?Sized} &T,
}

/// A common trait implemented by all function pointers.
Expand Down
6 changes: 4 additions & 2 deletions core/src/mem/transmutability.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::marker::ConstParamTy;
use crate::marker::{ConstParamTy_, UnsizedConstParamTy};

/// Are values of a type transmutable into values of another type?
///
Expand Down Expand Up @@ -39,7 +39,9 @@ pub struct Assume {
}

#[unstable(feature = "transmutability", issue = "99571")]
impl ConstParamTy for Assume {}
impl ConstParamTy_ for Assume {}
#[unstable(feature = "transmutability", issue = "99571")]
impl UnsizedConstParamTy for Assume {}

impl Assume {
/// Do not assume that *you* have ensured any safety properties are met.
Expand Down
1 change: 1 addition & 0 deletions core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2507,6 +2507,7 @@ impl<T> ops::FromResidual for Option<T> {
}
}

#[diagnostic::do_not_recommend]
#[unstable(feature = "try_trait_v2_yeet", issue = "96374")]
impl<T> ops::FromResidual<ops::Yeet<()>> for Option<T> {
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion core/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1990,7 +1990,7 @@ impl<T, E, F: From<E>> ops::FromResidual<Result<convert::Infallible, E>> for Res
}
}
}

#[diagnostic::do_not_recommend]
#[unstable(feature = "try_trait_v2_yeet", issue = "96374")]
impl<T, E, F: From<E>> ops::FromResidual<ops::Yeet<E>> for Result<T, F> {
#[inline]
Expand Down
14 changes: 11 additions & 3 deletions core/src/tuple.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// See core/src/primitive_docs.rs for documentation.

use crate::cmp::Ordering::{self, *};
use crate::marker::ConstParamTy;
use crate::marker::ConstParamTy_;
use crate::marker::StructuralPartialEq;
use crate::marker::UnsizedConstParamTy;

// Recursive macro for implementing n-ary tuple functions and operations
//
Expand Down Expand Up @@ -49,8 +50,15 @@ macro_rules! tuple_impls {

maybe_tuple_doc! {
$($T)+ @
#[unstable(feature = "structural_match", issue = "31434")]
impl<$($T: ConstParamTy),+> ConstParamTy for ($($T,)+)
#[unstable(feature = "adt_const_params", issue = "95174")]
impl<$($T: ConstParamTy_),+> ConstParamTy_ for ($($T,)+)
{}
}

maybe_tuple_doc! {
$($T)+ @
#[unstable(feature = "unsized_const_params", issue = "95174")]
impl<$($T: UnsizedConstParamTy),+> UnsizedConstParamTy for ($($T,)+)
{}
}

Expand Down
6 changes: 6 additions & 0 deletions panic_unwind/src/seh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ mod imp {
// going to be cross-lang LTOed anyway. However, using expose is shorter and
// requires less unsafe.
let addr: usize = ptr.expose_provenance();
#[cfg(bootstrap)]
let image_base = unsafe { addr_of!(__ImageBase) }.addr();
#[cfg(not(bootstrap))]
let image_base = addr_of!(__ImageBase).addr();
let offset: usize = addr - image_base;
Self(offset as u32)
}
Expand Down Expand Up @@ -250,7 +253,10 @@ extern "C" {
// This is fine since the MSVC runtime uses string comparison on the type name
// to match TypeDescriptors rather than pointer equality.
static mut TYPE_DESCRIPTOR: _TypeDescriptor = _TypeDescriptor {
#[cfg(bootstrap)]
pVFTable: unsafe { addr_of!(TYPE_INFO_VTABLE) } as *const _,
#[cfg(not(bootstrap))]
pVFTable: addr_of!(TYPE_INFO_VTABLE) as *const _,
spare: core::ptr::null_mut(),
name: TYPE_NAME,
};
Expand Down
58 changes: 45 additions & 13 deletions std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ core = { path = "../core", public = true }
compiler_builtins = { version = "0.1.105" }
profiler_builtins = { path = "../profiler_builtins", optional = true }
unwind = { path = "../unwind" }
hashbrown = { version = "0.14", default-features = false, features = ['rustc-dep-of-std'] }
std_detect = { path = "../stdarch/crates/std_detect", default-features = false, features = ['rustc-dep-of-std'] }
hashbrown = { version = "0.14", default-features = false, features = [
'rustc-dep-of-std',
] }
std_detect = { path = "../stdarch/crates/std_detect", default-features = false, features = [
'rustc-dep-of-std',
] }

# Dependencies of the `backtrace` crate
rustc-demangle = { version = "0.1.24", features = ['rustc-dep-of-std'] }
Expand All @@ -31,13 +35,27 @@ miniz_oxide = { version = "0.7.0", optional = true, default-features = false }
addr2line = { version = "0.22.0", optional = true, default-features = false }

[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
libc = { version = "0.2.153", default-features = false, features = ['rustc-dep-of-std'], public = true }
libc = { version = "0.2.153", default-features = false, features = [
'rustc-dep-of-std',
], public = true }

[target.'cfg(all(not(target_os = "aix"), not(all(windows, target_env = "msvc", not(target_vendor = "uwp")))))'.dependencies]
object = { version = "0.36.0", default-features = false, optional = true, features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive'] }
object = { version = "0.36.0", default-features = false, optional = true, features = [
'read_core',
'elf',
'macho',
'pe',
'unaligned',
'archive',
] }

[target.'cfg(target_os = "aix")'.dependencies]
object = { version = "0.36.0", default-features = false, optional = true, features = ['read_core', 'xcoff', 'unaligned', 'archive'] }
object = { version = "0.36.0", default-features = false, optional = true, features = [
'read_core',
'xcoff',
'unaligned',
'archive',
] }

[dev-dependencies]
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
Expand All @@ -47,23 +65,29 @@ rand_xorshift = "0.3.0"
dlmalloc = { version = "0.2.4", features = ['rustc-dep-of-std'] }

[target.x86_64-fortanix-unknown-sgx.dependencies]
fortanix-sgx-abi = { version = "0.5.0", features = ['rustc-dep-of-std'], public = true }
fortanix-sgx-abi = { version = "0.5.0", features = [
'rustc-dep-of-std',
], public = true }

[target.'cfg(target_os = "hermit")'.dependencies]
hermit-abi = { version = "0.4.0", features = ['rustc-dep-of-std'], public = true }
hermit-abi = { version = "0.4.0", features = [
'rustc-dep-of-std',
], public = true }

[target.'cfg(target_os = "wasi")'.dependencies]
wasi = { version = "0.11.0", features = ['rustc-dep-of-std'], default-features = false }
wasi = { version = "0.11.0", features = [
'rustc-dep-of-std',
], default-features = false }

[target.'cfg(target_os = "uefi")'.dependencies]
r-efi = { version = "4.2.0", features = ['rustc-dep-of-std'] }
r-efi = { version = "4.5.0", features = ['rustc-dep-of-std'] }
r-efi-alloc = { version = "1.0.0", features = ['rustc-dep-of-std'] }

[features]
backtrace = [
'addr2line/rustc-dep-of-std',
'object/rustc-dep-of-std',
'miniz_oxide/rustc-dep-of-std',
'addr2line/rustc-dep-of-std',
'object/rustc-dep-of-std',
'miniz_oxide/rustc-dep-of-std',
]

panic-unwind = ["panic_unwind"]
Expand All @@ -77,7 +101,10 @@ llvm-libunwind = ["unwind/llvm-libunwind"]
system-llvm-libunwind = ["unwind/system-llvm-libunwind"]

# Make panics and failed asserts immediately abort without formatting any message
panic_immediate_abort = ["core/panic_immediate_abort", "alloc/panic_immediate_abort"]
panic_immediate_abort = [
"core/panic_immediate_abort",
"alloc/panic_immediate_abort",
]
# Choose algorithms that are optimized for binary size instead of runtime performance
optimize_for_size = ["core/optimize_for_size", "alloc/optimize_for_size"]

Expand All @@ -97,6 +124,11 @@ threads = 125
# Maximum heap size
heap_size = 0x8000000

[[test]]
name = "pipe-subprocess"
path = "tests/pipe_subprocess.rs"
harness = false

[[bench]]
name = "stdbenches"
path = "benches/lib.rs"
Expand Down
Loading

0 comments on commit 16450f7

Please sign in to comment.