Skip to content

Commit

Permalink
Auto merge of #131887 - jieyouxu:rollup-ftik4ni, r=jieyouxu
Browse files Browse the repository at this point in the history
Rollup of 9 pull requests

Successful merges:

 - #130136 (Partially stabilize const_pin)
 - #131755 (Regression test for AVR `rjmp` offset)
 - #131774 (Add getentropy for RTEMS)
 - #131802 (Dont ICE when computing coverage of synthetic async closure body)
 - #131809 (Fix predicate signatures in retain_mut docs)
 - #131858 (Remove outdated documentation for `repeat_n`)
 - #131866 (Avoid use imports in `thread_local_inner!`)
 - #131874 (Default to the medium code model on OpenHarmony LoongArch target)
 - #131877 (checktools.sh: add link to issue for more context about disabled Miri tests)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 18, 2024
2 parents acfdb8d + 80a8f7b commit 1350eea
Show file tree
Hide file tree
Showing 26 changed files with 287 additions and 60 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ rustc_queries! {
/// either `#[coverage(on)]` or no coverage attribute was found.
query coverage_attr_on(key: LocalDefId) -> bool {
desc { |tcx| "checking for `#[coverage(..)]` on `{}`", tcx.def_path_str(key) }
feedable
}

/// Summarizes coverage IDs inserted by the `InstrumentCoverage` MIR pass
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_mir_transform/src/coroutine/by_move_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ pub(crate) fn coroutine_by_move_body_def_id<'tcx>(

// Inherited from the by-ref coroutine.
body_def.codegen_fn_attrs(tcx.codegen_fn_attrs(coroutine_def_id).clone());
body_def.coverage_attr_on(tcx.coverage_attr_on(coroutine_def_id));
body_def.constness(tcx.constness(coroutine_def_id));
body_def.coroutine_kind(tcx.coroutine_kind(coroutine_def_id));
body_def.def_ident_span(tcx.def_ident_span(coroutine_def_id));
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_mir_transform/src/coverage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,11 @@ fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHir
// FIXME(#79625): Consider improving MIR to provide the information needed, to avoid going back
// to HIR for it.

// HACK: For synthetic MIR bodies (async closures), use the def id of the HIR body.
if tcx.is_synthetic_mir(def_id) {
return extract_hir_info(tcx, tcx.local_parent(def_id));
}

let hir_node = tcx.hir_node_by_def_id(def_id);
let fn_body_id = hir_node.body_id().expect("HIR node is a function with body");
let hir_body = tcx.hir().body(fn_body_id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::spec::{SanitizerSet, Target, TargetOptions, base};
use crate::spec::{CodeModel, SanitizerSet, Target, TargetOptions, base};

pub(crate) fn target() -> Target {
Target {
Expand All @@ -13,6 +13,7 @@ pub(crate) fn target() -> Target {
data_layout: "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128".into(),
arch: "loongarch64".into(),
options: TargetOptions {
code_model: Some(CodeModel::Medium),
cpu: "generic".into(),
features: "+f,+d".into(),
llvm_abiname: "lp64d".into(),
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/collections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ impl<T, A: Allocator> LinkedList<T, A> {

/// Retains only the elements specified by the predicate.
///
/// In other words, remove all elements `e` for which `f(&e)` returns false.
/// In other words, remove all elements `e` for which `f(&mut e)` returns false.
/// This method operates in place, visiting each element exactly once in the
/// original order, and preserves the order of the retained elements.
///
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2122,7 +2122,7 @@ impl<T, A: Allocator> VecDeque<T, A> {

/// Retains only the elements specified by the predicate.
///
/// In other words, remove all elements `e` for which `f(&e)` returns false.
/// In other words, remove all elements `e` for which `f(&mut e)` returns false.
/// This method operates in place, visiting each element exactly once in the
/// original order, and preserves the order of the retained elements.
///
Expand Down
1 change: 0 additions & 1 deletion library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
#![feature(const_eval_select)]
#![feature(const_heap)]
#![feature(const_maybe_uninit_write)]
#![feature(const_pin)]
#![feature(const_size_of_val)]
#![feature(const_vec_string_slice)]
#![feature(core_intrinsics)]
Expand Down
4 changes: 1 addition & 3 deletions library/core/src/iter/sources/repeat_n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use crate::num::NonZero;
/// The `repeat_n()` function repeats a single value exactly `n` times.
///
/// This is very similar to using [`repeat()`] with [`Iterator::take()`],
/// but there are two differences:
/// - `repeat_n()` can return the original value, rather than always cloning.
/// - `repeat_n()` produces an [`ExactSizeIterator`].
/// but `repeat_n()` can return the original value, rather than always cloning.
///
/// [`repeat()`]: crate::iter::repeat
///
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
#![feature(const_nonnull_new)]
#![feature(const_num_midpoint)]
#![feature(const_option_ext)]
#![feature(const_pin)]
#![feature(const_pin_2)]
#![feature(const_pointer_is_aligned)]
#![feature(const_ptr_is_null)]
#![feature(const_ptr_sub_ptr)]
Expand Down
20 changes: 10 additions & 10 deletions library/core/src/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ impl<Ptr: Deref<Target: Unpin>> Pin<Ptr> {
/// let mut pinned: Pin<&mut u8> = Pin::new(&mut val);
/// ```
#[inline(always)]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "pin", since = "1.33.0")]
pub const fn new(pointer: Ptr) -> Pin<Ptr> {
// SAFETY: the value pointed to is `Unpin`, and so has no requirements
Expand Down Expand Up @@ -1214,7 +1214,7 @@ impl<Ptr: Deref<Target: Unpin>> Pin<Ptr> {
/// assert_eq!(*r, 5);
/// ```
#[inline(always)]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
#[rustc_const_unstable(feature = "const_pin_2", issue = "76654")]
#[stable(feature = "pin_into_inner", since = "1.39.0")]
pub const fn into_inner(pin: Pin<Ptr>) -> Ptr {
pin.__pointer
Expand Down Expand Up @@ -1351,7 +1351,7 @@ impl<Ptr: Deref> Pin<Ptr> {
/// [`pin` module docs]: self
#[lang = "new_unchecked"]
#[inline(always)]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "pin", since = "1.33.0")]
pub const unsafe fn new_unchecked(pointer: Ptr) -> Pin<Ptr> {
Pin { __pointer: pointer }
Expand Down Expand Up @@ -1503,7 +1503,7 @@ impl<Ptr: Deref> Pin<Ptr> {
/// If the underlying data is [`Unpin`], [`Pin::into_inner`] should be used
/// instead.
#[inline(always)]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
#[rustc_const_unstable(feature = "const_pin_2", issue = "76654")]
#[stable(feature = "pin_into_inner", since = "1.39.0")]
pub const unsafe fn into_inner_unchecked(pin: Pin<Ptr>) -> Ptr {
pin.__pointer
Expand Down Expand Up @@ -1559,7 +1559,7 @@ impl<'a, T: ?Sized> Pin<&'a T> {
/// ["pinning projections"]: self#projections-and-structural-pinning
#[inline(always)]
#[must_use]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "pin", since = "1.33.0")]
pub const fn get_ref(self) -> &'a T {
self.__pointer
Expand All @@ -1570,7 +1570,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
/// Converts this `Pin<&mut T>` into a `Pin<&T>` with the same lifetime.
#[inline(always)]
#[must_use = "`self` will be dropped if the result is not used"]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "pin", since = "1.33.0")]
pub const fn into_ref(self) -> Pin<&'a T> {
Pin { __pointer: self.__pointer }
Expand All @@ -1588,7 +1588,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
#[inline(always)]
#[must_use = "`self` will be dropped if the result is not used"]
#[stable(feature = "pin", since = "1.33.0")]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
pub const fn get_mut(self) -> &'a mut T
where
T: Unpin,
Expand All @@ -1609,7 +1609,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
#[inline(always)]
#[must_use = "`self` will be dropped if the result is not used"]
#[stable(feature = "pin", since = "1.33.0")]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
pub const unsafe fn get_unchecked_mut(self) -> &'a mut T {
self.__pointer
}
Expand Down Expand Up @@ -1652,7 +1652,7 @@ impl<T: ?Sized> Pin<&'static T> {
/// This is safe because `T` is borrowed immutably for the `'static` lifetime, which
/// never ends.
#[stable(feature = "pin_static_ref", since = "1.61.0")]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
pub const fn static_ref(r: &'static T) -> Pin<&'static T> {
// SAFETY: The 'static borrow guarantees the data will not be
// moved/invalidated until it gets dropped (which is never).
Expand All @@ -1666,7 +1666,7 @@ impl<T: ?Sized> Pin<&'static mut T> {
/// This is safe because `T` is borrowed for the `'static` lifetime, which
/// never ends.
#[stable(feature = "pin_static_ref", since = "1.61.0")]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
pub const fn static_mut(r: &'static mut T) -> Pin<&'static mut T> {
// SAFETY: The 'static borrow guarantees the data will not be
// moved/invalidated until it gets dropped (which is never).
Expand Down
2 changes: 1 addition & 1 deletion library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#![feature(const_likely)]
#![feature(const_nonnull_new)]
#![feature(const_option_ext)]
#![feature(const_pin)]
#![feature(const_pin_2)]
#![feature(const_pointer_is_aligned)]
#![feature(const_three_way_compare)]
#![feature(const_trait_impl)]
Expand Down
4 changes: 4 additions & 0 deletions library/core/tests/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ fn pin_const() {
const REF: &'static usize = PINNED.get_ref();
assert_eq!(REF, POINTER);

const INT: u8 = 42;
const STATIC_REF: Pin<&'static u8> = Pin::static_ref(&INT);
assert_eq!(*STATIC_REF, INT);

// Note: `pin_mut_const` tests that the methods of `Pin<&mut T>` are usable in a const context.
// A const fn is used because `&mut` is not (yet) usable in constants.
const fn pin_mut_const() {
Expand Down
1 change: 1 addition & 0 deletions library/std/src/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use crate::sys::random as sys;
/// Horizon | `getrandom` shim
/// Hurd, L4Re, QNX | `/dev/urandom`
/// Redox | `/scheme/rand`
/// RTEMS | [`arc4random_buf`](https://docs.rtems.org/branches/master/bsp-howto/getentropy.html)
/// SGX | [`rdrand`](https://en.wikipedia.org/wiki/RDRAND)
/// SOLID | `SOLID_RNG_SampleRandomBytes`
/// TEEOS | `TEE_GenerateRandom`
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/sys/random/arc4random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#[cfg(not(any(
target_os = "haiku",
target_os = "illumos",
target_os = "rtems",
target_os = "solaris",
target_os = "vita",
)))]
Expand All @@ -21,6 +22,7 @@ use libc::arc4random_buf;
#[cfg(any(
target_os = "haiku", // See https://git.haiku-os.org/haiku/tree/headers/compatibility/bsd/stdlib.h
target_os = "illumos", // See https://www.illumos.org/man/3C/arc4random
target_os = "rtems", // See https://docs.rtems.org/branches/master/bsp-howto/getentropy.html
target_os = "solaris", // See https://docs.oracle.com/cd/E88353_01/html/E37843/arc4random-3c.html
target_os = "vita", // See https://github.com/vitasdk/newlib/blob/b89e5bc183b516945f9ee07eef483ecb916e45ff/newlib/libc/include/stdlib.h#L74
))]
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/random/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ cfg_if::cfg_if! {
target_os = "illumos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "rtems",
target_os = "solaris",
target_os = "vita",
))] {
Expand Down
31 changes: 15 additions & 16 deletions library/std/src/sys/thread_local/native/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,21 @@ pub use lazy::Storage as LazyStorage;
#[unstable(feature = "thread_local_internals", issue = "none")]
#[rustc_macro_transparency = "semitransparent"]
pub macro thread_local_inner {
// used to generate the `LocalKey` value for const-initialized thread locals
// NOTE: we cannot import `LocalKey`, `LazyStorage` or `EagerStorage` with a `use` because that
// can shadow user provided type or type alias with a matching name. Please update the shadowing
// test in `tests/thread.rs` if these types are renamed.

// Used to generate the `LocalKey` value for const-initialized thread locals.
(@key $t:ty, const $init:expr) => {{
const __INIT: $t = $init;

unsafe {
use $crate::mem::needs_drop;
use $crate::thread::LocalKey;
use $crate::thread::local_impl::EagerStorage;

LocalKey::new(const {
if needs_drop::<$t>() {
$crate::thread::LocalKey::new(const {
if $crate::mem::needs_drop::<$t>() {
|_| {
#[thread_local]
static VAL: EagerStorage<$t> = EagerStorage::new(__INIT);
static VAL: $crate::thread::local_impl::EagerStorage<$t>
= $crate::thread::local_impl::EagerStorage::new(__INIT);
VAL.get()
}
} else {
Expand All @@ -84,21 +85,19 @@ pub macro thread_local_inner {
}

unsafe {
use $crate::mem::needs_drop;
use $crate::thread::LocalKey;
use $crate::thread::local_impl::LazyStorage;

LocalKey::new(const {
if needs_drop::<$t>() {
$crate::thread::LocalKey::new(const {
if $crate::mem::needs_drop::<$t>() {
|init| {
#[thread_local]
static VAL: LazyStorage<$t, ()> = LazyStorage::new();
static VAL: $crate::thread::local_impl::LazyStorage<$t, ()>
= $crate::thread::local_impl::LazyStorage::new();
VAL.get_or_init(init, __init)
}
} else {
|init| {
#[thread_local]
static VAL: LazyStorage<$t, !> = LazyStorage::new();
static VAL: $crate::thread::local_impl::LazyStorage<$t, !>
= $crate::thread::local_impl::LazyStorage::new();
VAL.get_or_init(init, __init)
}
}
Expand Down
17 changes: 11 additions & 6 deletions library/std/src/sys/thread_local/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,24 @@ pub macro thread_local_inner {
$crate::thread::local_impl::thread_local_inner!(@key $t, { const INIT_EXPR: $t = $init; INIT_EXPR })
},

// used to generate the `LocalKey` value for `thread_local!`
// NOTE: we cannot import `Storage` or `LocalKey` with a `use` because that can shadow user
// provided type or type alias with a matching name. Please update the shadowing test in
// `tests/thread.rs` if these types are renamed.

// used to generate the `LocalKey` value for `thread_local!`.
(@key $t:ty, $init:expr) => {{
#[inline]
fn __init() -> $t { $init }

// NOTE: this cannot import `LocalKey` or `Storage` with a `use` because that can shadow
// user provided type or type alias with a matching name. Please update the shadowing test
// in `tests/thread.rs` if these types are renamed.
unsafe {
use $crate::thread::LocalKey;
use $crate::thread::local_impl::Storage;

// Inlining does not work on windows-gnu due to linking errors around
// dllimports. See https://github.com/rust-lang/rust/issues/109797.
LocalKey::new(#[cfg_attr(windows, inline(never))] |init| {
static VAL: Storage<$t> = Storage::new();
$crate::thread::LocalKey::new(#[cfg_attr(windows, inline(never))] |init| {
static VAL: $crate::thread::local_impl::Storage<$t>
= $crate::thread::local_impl::Storage::new();
VAL.get(init, __init)
})
}
Expand Down
23 changes: 23 additions & 0 deletions library/std/tests/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,29 @@ fn thread_local_containing_const_statements() {
assert_eq!(REFCELL.take(), 1);
}

#[test]
fn thread_local_hygeiene() {
// Previously `thread_local_inner!` had use imports for `LocalKey`, `Storage`, `EagerStorage`
// and `LazyStorage`. The use imports will shadow a user-provided type or type alias if the
// user-provided type or type alias has the same name. Make sure that this does not happen. See
// <https://github.com/rust-lang/rust/issues/131863>.
//
// NOTE: if the internal implementation details change (i.e. get renamed), this test should be
// updated.

#![allow(dead_code)]
type LocalKey = ();
type Storage = ();
type LazyStorage = ();
type EagerStorage = ();
thread_local! {
static A: LocalKey = const { () };
static B: Storage = const { () };
static C: LazyStorage = const { () };
static D: EagerStorage = const { () };
}
}

#[test]
// Include an ignore list on purpose, so that new platforms don't miss it
#[cfg_attr(
Expand Down
2 changes: 2 additions & 0 deletions src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ case $HOST_TARGET in
# "error: cannot produce cdylib for ... as the target ... does not support these crate types".
# Only run "pass" tests, which is quite a bit faster.
#FIXME: Re-enable this once CI issues are fixed
# See <https://github.com/rust-lang/rust/issues/127883>
# For now, these tests are moved to `x86_64-msvc-ext2` in `src/ci/github-actions/jobs.yml`.
#python3 "$X_PY" test --stage 2 src/tools/miri --target aarch64-apple-darwin --test-args pass
#python3 "$X_PY" test --stage 2 src/tools/miri --target i686-pc-windows-gnu --test-args pass
;;
Expand Down
2 changes: 2 additions & 0 deletions src/ci/github-actions/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ auto:
<<: *job-windows-8c

# Temporary builder to workaround CI issues
# See <https://github.com/rust-lang/rust/issues/127883>
#FIXME: Remove this, and re-enable the same tests in `checktools.sh`, once CI issues are fixed.
- image: x86_64-msvc-ext2
env:
SCRIPT: >
Expand Down
Loading

0 comments on commit 1350eea

Please sign in to comment.