From 01a4471708d44e284ca58d7ec9c9eed248f0c9f4 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Fri, 3 Dec 2021 17:56:59 -0800 Subject: [PATCH 1/6] Fold aarch64 feature +fp into +neon Arm's FEAT_FP and Feat_AdvSIMD describe the same thing on AArch64: The Neon unit, which handles both floating point and SIMD instructions. Moreover, a configuration for AArch64 must include both or neither. Arm says "entirely proprietary" toolchains may omit floating point: https://developer.arm.com/documentation/102374/0101/Data-processing---floating-point In the Programmer's Guide for Armv8-A, Arm says AArch64 can have both FP and Neon or neither in custom implementations: https://developer.arm.com/documentation/den0024/a/AArch64-Floating-point-and-NEON In "Bare metal boot code for Armv8-A", enabling Neon and FP is just disabling the same trap flag: https://developer.arm.com/documentation/dai0527/a In an unlikely future where "Neon and FP" become unrelated, we can add "[+-]fp" as its own feature flag. Until then, we can simplify programming with Rust on AArch64 by folding both into "[+-]neon", which is valid as it supersets both. "[+-]neon" is retained for niche uses such as firmware, kernels, "I just hate floats", and so on. --- compiler/rustc_codegen_llvm/src/llvm_util.rs | 1 - compiler/rustc_codegen_ssa/src/target_features.rs | 4 +--- compiler/rustc_target/src/asm/aarch64.rs | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 3ce594b945ac1..e70866a3b7015 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -187,7 +187,6 @@ pub fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> SmallVec<[&'a str; 2] ("x86", "avx512vaes") => smallvec!["vaes"], ("x86", "avx512gfni") => smallvec!["gfni"], ("x86", "avx512vpclmulqdq") => smallvec!["vpclmulqdq"], - ("aarch64", "fp") => smallvec!["fp-armv8"], ("aarch64", "rcpc2") => smallvec!["rcpc-immo"], ("aarch64", "dpb") => smallvec!["ccpp"], ("aarch64", "dpb2") => smallvec!["ccdp"], diff --git a/compiler/rustc_codegen_ssa/src/target_features.rs b/compiler/rustc_codegen_ssa/src/target_features.rs index ff7415af37339..5711b6366ac92 100644 --- a/compiler/rustc_codegen_ssa/src/target_features.rs +++ b/compiler/rustc_codegen_ssa/src/target_features.rs @@ -43,10 +43,8 @@ const ARM_ALLOWED_FEATURES: &[(&str, Option)] = &[ ]; const AARCH64_ALLOWED_FEATURES: &[(&str, Option)] = &[ - // FEAT_AdvSimd + // FEAT_AdvSimd & FEAT_FP ("neon", None), - // FEAT_FP - ("fp", None), // FEAT_FP16 ("fp16", None), // FEAT_SVE diff --git a/compiler/rustc_target/src/asm/aarch64.rs b/compiler/rustc_target/src/asm/aarch64.rs index 7fb4dbdf2b181..fba8cc6ef8b4a 100644 --- a/compiler/rustc_target/src/asm/aarch64.rs +++ b/compiler/rustc_target/src/asm/aarch64.rs @@ -64,7 +64,7 @@ impl AArch64InlineAsmRegClass { match self { Self::reg => types! { _: I8, I16, I32, I64, F32, F64; }, Self::vreg | Self::vreg_low16 => types! { - fp: I8, I16, I32, I64, F32, F64, + neon: I8, I16, I32, I64, F32, F64, VecI8(8), VecI16(4), VecI32(2), VecI64(1), VecF32(2), VecF64(1), VecI8(16), VecI16(8), VecI32(4), VecI64(2), VecF32(4), VecF64(2); }, From f4e7fde54d244cbd82f4f69add1c1c5dff516d27 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sat, 19 Mar 2022 19:36:42 -0700 Subject: [PATCH 2/6] Flatmap features before comparing to LLVM --- compiler/rustc_codegen_llvm/src/llvm_util.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index e70866a3b7015..19ae991f5191b 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -237,12 +237,11 @@ pub fn target_features(sess: &Session) -> Vec { .filter_map(|&(feature, gate)| { if sess.is_nightly_build() || gate.is_none() { Some(feature) } else { None } }) + .flat_map(|feature| to_llvm_features(sess, feature)) .filter(|feature| { - for llvm_feature in to_llvm_features(sess, feature) { - let cstr = SmallCStr::new(llvm_feature); - if unsafe { llvm::LLVMRustHasFeature(target_machine, cstr.as_ptr()) } { - return true; - } + let cstr = SmallCStr::new(feature); + if unsafe { llvm::LLVMRustHasFeature(target_machine, cstr.as_ptr()) } { + return true; } false }) From ac6996345de2cc482cb164335336b9af1b03a320 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Thu, 17 Mar 2022 12:28:31 +0100 Subject: [PATCH 3/6] Move pthread locks to own module. --- library/std/src/sys/unix/locks/mod.rs | 8 ++++ .../{condvar.rs => locks/pthread_condvar.rs} | 8 ++-- .../unix/{mutex.rs => locks/pthread_mutex.rs} | 44 +----------------- .../std/src/sys/unix/locks/pthread_remutex.rs | 46 +++++++++++++++++++ .../{rwlock.rs => locks/pthread_rwlock.rs} | 0 library/std/src/sys/unix/mod.rs | 4 +- library/std/src/sys_common/condvar.rs | 5 +- library/std/src/sys_common/condvar/check.rs | 8 ++-- library/std/src/sys_common/mutex.rs | 2 +- library/std/src/sys_common/remutex.rs | 2 +- library/std/src/sys_common/rwlock.rs | 2 +- 11 files changed, 69 insertions(+), 60 deletions(-) create mode 100644 library/std/src/sys/unix/locks/mod.rs rename library/std/src/sys/unix/{condvar.rs => locks/pthread_condvar.rs} (95%) rename library/std/src/sys/unix/{mutex.rs => locks/pthread_mutex.rs} (74%) create mode 100644 library/std/src/sys/unix/locks/pthread_remutex.rs rename library/std/src/sys/unix/{rwlock.rs => locks/pthread_rwlock.rs} (100%) diff --git a/library/std/src/sys/unix/locks/mod.rs b/library/std/src/sys/unix/locks/mod.rs new file mode 100644 index 0000000000000..f07a9f93b79a5 --- /dev/null +++ b/library/std/src/sys/unix/locks/mod.rs @@ -0,0 +1,8 @@ +mod pthread_condvar; +mod pthread_mutex; +mod pthread_remutex; +mod pthread_rwlock; +pub use pthread_condvar::{Condvar, MovableCondvar}; +pub use pthread_mutex::{MovableMutex, Mutex}; +pub use pthread_remutex::ReentrantMutex; +pub use pthread_rwlock::{MovableRWLock, RWLock}; diff --git a/library/std/src/sys/unix/condvar.rs b/library/std/src/sys/unix/locks/pthread_condvar.rs similarity index 95% rename from library/std/src/sys/unix/condvar.rs rename to library/std/src/sys/unix/locks/pthread_condvar.rs index 61261c0aa84e3..099aa68706fa3 100644 --- a/library/std/src/sys/unix/condvar.rs +++ b/library/std/src/sys/unix/locks/pthread_condvar.rs @@ -1,5 +1,5 @@ use crate::cell::UnsafeCell; -use crate::sys::mutex::{self, Mutex}; +use crate::sys::locks::{pthread_mutex, Mutex}; use crate::time::Duration; pub struct Condvar { @@ -79,7 +79,7 @@ impl Condvar { #[inline] pub unsafe fn wait(&self, mutex: &Mutex) { - let r = libc::pthread_cond_wait(self.inner.get(), mutex::raw(mutex)); + let r = libc::pthread_cond_wait(self.inner.get(), pthread_mutex::raw(mutex)); debug_assert_eq!(r, 0); } @@ -111,7 +111,7 @@ impl Condvar { let timeout = sec.map(|s| libc::timespec { tv_sec: s, tv_nsec: nsec as _ }).unwrap_or(TIMESPEC_MAX); - let r = libc::pthread_cond_timedwait(self.inner.get(), mutex::raw(mutex), &timeout); + let r = libc::pthread_cond_timedwait(self.inner.get(), pthread_mutex::raw(mutex), &timeout); assert!(r == libc::ETIMEDOUT || r == 0); r == 0 } @@ -169,7 +169,7 @@ impl Condvar { .unwrap_or(TIMESPEC_MAX); // And wait! - let r = libc::pthread_cond_timedwait(self.inner.get(), mutex::raw(mutex), &timeout); + let r = libc::pthread_cond_timedwait(self.inner.get(), pthread_mutex::raw(mutex), &timeout); debug_assert!(r == libc::ETIMEDOUT || r == 0); // ETIMEDOUT is not a totally reliable method of determining timeout due diff --git a/library/std/src/sys/unix/mutex.rs b/library/std/src/sys/unix/locks/pthread_mutex.rs similarity index 74% rename from library/std/src/sys/unix/mutex.rs rename to library/std/src/sys/unix/locks/pthread_mutex.rs index 89c55eb859d09..09cfa2f50eced 100644 --- a/library/std/src/sys/unix/mutex.rs +++ b/library/std/src/sys/unix/locks/pthread_mutex.rs @@ -90,49 +90,7 @@ impl Mutex { } } -pub struct ReentrantMutex { - inner: UnsafeCell, -} - -unsafe impl Send for ReentrantMutex {} -unsafe impl Sync for ReentrantMutex {} - -impl ReentrantMutex { - pub const unsafe fn uninitialized() -> ReentrantMutex { - ReentrantMutex { inner: UnsafeCell::new(libc::PTHREAD_MUTEX_INITIALIZER) } - } - - pub unsafe fn init(&self) { - let mut attr = MaybeUninit::::uninit(); - cvt_nz(libc::pthread_mutexattr_init(attr.as_mut_ptr())).unwrap(); - let attr = PthreadMutexAttr(&mut attr); - cvt_nz(libc::pthread_mutexattr_settype(attr.0.as_mut_ptr(), libc::PTHREAD_MUTEX_RECURSIVE)) - .unwrap(); - cvt_nz(libc::pthread_mutex_init(self.inner.get(), attr.0.as_ptr())).unwrap(); - } - - pub unsafe fn lock(&self) { - let result = libc::pthread_mutex_lock(self.inner.get()); - debug_assert_eq!(result, 0); - } - - #[inline] - pub unsafe fn try_lock(&self) -> bool { - libc::pthread_mutex_trylock(self.inner.get()) == 0 - } - - pub unsafe fn unlock(&self) { - let result = libc::pthread_mutex_unlock(self.inner.get()); - debug_assert_eq!(result, 0); - } - - pub unsafe fn destroy(&self) { - let result = libc::pthread_mutex_destroy(self.inner.get()); - debug_assert_eq!(result, 0); - } -} - -struct PthreadMutexAttr<'a>(&'a mut MaybeUninit); +pub(super) struct PthreadMutexAttr<'a>(pub &'a mut MaybeUninit); impl Drop for PthreadMutexAttr<'_> { fn drop(&mut self) { diff --git a/library/std/src/sys/unix/locks/pthread_remutex.rs b/library/std/src/sys/unix/locks/pthread_remutex.rs new file mode 100644 index 0000000000000..b006181ee3a0d --- /dev/null +++ b/library/std/src/sys/unix/locks/pthread_remutex.rs @@ -0,0 +1,46 @@ +use super::pthread_mutex::PthreadMutexAttr; +use crate::cell::UnsafeCell; +use crate::mem::MaybeUninit; +use crate::sys::cvt_nz; + +pub struct ReentrantMutex { + inner: UnsafeCell, +} + +unsafe impl Send for ReentrantMutex {} +unsafe impl Sync for ReentrantMutex {} + +impl ReentrantMutex { + pub const unsafe fn uninitialized() -> ReentrantMutex { + ReentrantMutex { inner: UnsafeCell::new(libc::PTHREAD_MUTEX_INITIALIZER) } + } + + pub unsafe fn init(&self) { + let mut attr = MaybeUninit::::uninit(); + cvt_nz(libc::pthread_mutexattr_init(attr.as_mut_ptr())).unwrap(); + let attr = PthreadMutexAttr(&mut attr); + cvt_nz(libc::pthread_mutexattr_settype(attr.0.as_mut_ptr(), libc::PTHREAD_MUTEX_RECURSIVE)) + .unwrap(); + cvt_nz(libc::pthread_mutex_init(self.inner.get(), attr.0.as_ptr())).unwrap(); + } + + pub unsafe fn lock(&self) { + let result = libc::pthread_mutex_lock(self.inner.get()); + debug_assert_eq!(result, 0); + } + + #[inline] + pub unsafe fn try_lock(&self) -> bool { + libc::pthread_mutex_trylock(self.inner.get()) == 0 + } + + pub unsafe fn unlock(&self) { + let result = libc::pthread_mutex_unlock(self.inner.get()); + debug_assert_eq!(result, 0); + } + + pub unsafe fn destroy(&self) { + let result = libc::pthread_mutex_destroy(self.inner.get()); + debug_assert_eq!(result, 0); + } +} diff --git a/library/std/src/sys/unix/rwlock.rs b/library/std/src/sys/unix/locks/pthread_rwlock.rs similarity index 100% rename from library/std/src/sys/unix/rwlock.rs rename to library/std/src/sys/unix/locks/pthread_rwlock.rs diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs index 605cc499b3c92..d5250bde75e3b 100644 --- a/library/std/src/sys/unix/mod.rs +++ b/library/std/src/sys/unix/mod.rs @@ -14,7 +14,6 @@ pub mod android; pub mod args; #[path = "../unix/cmath.rs"] pub mod cmath; -pub mod condvar; pub mod env; pub mod fd; pub mod fs; @@ -24,8 +23,8 @@ pub mod io; pub mod kernel_copy; #[cfg(target_os = "l4re")] mod l4re; +pub mod locks; pub mod memchr; -pub mod mutex; #[cfg(not(target_os = "l4re"))] pub mod net; #[cfg(target_os = "l4re")] @@ -36,7 +35,6 @@ pub mod path; pub mod pipe; pub mod process; pub mod rand; -pub mod rwlock; pub mod stack_overflow; pub mod stdio; pub mod thread; diff --git a/library/std/src/sys_common/condvar.rs b/library/std/src/sys_common/condvar.rs index 2c02e1cd33c81..67d4b1262091a 100644 --- a/library/std/src/sys_common/condvar.rs +++ b/library/std/src/sys_common/condvar.rs @@ -1,11 +1,10 @@ -use crate::sys::condvar as imp; -use crate::sys::mutex as mutex_imp; +use crate::sys::locks as imp; use crate::sys_common::mutex::MovableMutex; use crate::time::Duration; mod check; -type CondvarCheck = ::Check; +type CondvarCheck = ::Check; /// An OS-based condition variable. pub struct Condvar { diff --git a/library/std/src/sys_common/condvar/check.rs b/library/std/src/sys_common/condvar/check.rs index 1578a2de60cef..47aff060d6f79 100644 --- a/library/std/src/sys_common/condvar/check.rs +++ b/library/std/src/sys_common/condvar/check.rs @@ -1,5 +1,5 @@ use crate::sync::atomic::{AtomicUsize, Ordering}; -use crate::sys::mutex as mutex_imp; +use crate::sys::locks as imp; use crate::sys_common::mutex::MovableMutex; pub trait CondvarCheck { @@ -8,7 +8,7 @@ pub trait CondvarCheck { /// For boxed mutexes, a `Condvar` will check it's only ever used with the same /// mutex, based on its (stable) address. -impl CondvarCheck for Box { +impl CondvarCheck for Box { type Check = SameMutexCheck; } @@ -22,7 +22,7 @@ impl SameMutexCheck { Self { addr: AtomicUsize::new(0) } } pub fn verify(&self, mutex: &MovableMutex) { - let addr = mutex.raw() as *const mutex_imp::Mutex as usize; + let addr = mutex.raw() as *const imp::Mutex as usize; match self.addr.compare_exchange(0, addr, Ordering::SeqCst, Ordering::SeqCst) { Ok(_) => {} // Stored the address Err(n) if n == addr => {} // Lost a race to store the same address @@ -33,7 +33,7 @@ impl SameMutexCheck { /// Unboxed mutexes may move, so `Condvar` can not require its address to stay /// constant. -impl CondvarCheck for mutex_imp::Mutex { +impl CondvarCheck for imp::Mutex { type Check = NoCheck; } diff --git a/library/std/src/sys_common/mutex.rs b/library/std/src/sys_common/mutex.rs index f3e7efb955a2f..12a09c9860501 100644 --- a/library/std/src/sys_common/mutex.rs +++ b/library/std/src/sys_common/mutex.rs @@ -1,4 +1,4 @@ -use crate::sys::mutex as imp; +use crate::sys::locks as imp; /// An OS-based mutual exclusion lock, meant for use in static variables. /// diff --git a/library/std/src/sys_common/remutex.rs b/library/std/src/sys_common/remutex.rs index 475bfca9b6dcc..801c9c28dd388 100644 --- a/library/std/src/sys_common/remutex.rs +++ b/library/std/src/sys_common/remutex.rs @@ -5,7 +5,7 @@ use crate::marker::PhantomPinned; use crate::ops::Deref; use crate::panic::{RefUnwindSafe, UnwindSafe}; use crate::pin::Pin; -use crate::sys::mutex as sys; +use crate::sys::locks as sys; /// A re-entrant mutual exclusion /// diff --git a/library/std/src/sys_common/rwlock.rs b/library/std/src/sys_common/rwlock.rs index 07ec20f4dc617..eaee631270157 100644 --- a/library/std/src/sys_common/rwlock.rs +++ b/library/std/src/sys_common/rwlock.rs @@ -1,4 +1,4 @@ -use crate::sys::rwlock as imp; +use crate::sys::locks as imp; /// An OS-based reader-writer lock, meant for use in static variables. /// From b92a60586a3f121592bded64a1556fae0f69c302 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 21 Mar 2022 22:33:23 -0400 Subject: [PATCH 4/6] rename LocalState::Uninitialized to Unallocated --- .../src/interpret/eval_context.rs | 22 +++++++++---------- .../rustc_mir_transform/src/const_prop.rs | 8 +++---- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index a8a57e6990ffd..d78c7a9fad983 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -177,11 +177,10 @@ pub struct LocalState<'tcx, Tag: Provenance = AllocId> { pub enum LocalValue { /// This local is not currently alive, and cannot be used at all. Dead, - /// This local is alive but not yet initialized. It can be written to - /// but not read from or its address taken. Locals get initialized on - /// first write because for unsized locals, we do not know their size - /// before that. - Uninitialized, + /// This local is alive but not yet allocated. It cannot be read from or have its address taken, + /// and will be allocated on the first write. This is to support unsized locals, where we cannot + /// know their size in advance. + Unallocated, /// A normal, live local. /// Mostly for convenience, we re-use the `Operand` type here. /// This is an optimization over just always having a pointer here; @@ -198,7 +197,7 @@ impl<'tcx, Tag: Provenance + 'static> LocalState<'tcx, Tag> { pub fn access(&self) -> InterpResult<'tcx, Operand> { match self.value { LocalValue::Dead => throw_ub!(DeadLocal), - LocalValue::Uninitialized => { + LocalValue::Unallocated => { bug!("The type checker should prevent reading from a never-written local") } LocalValue::Live(val) => Ok(val), @@ -216,8 +215,7 @@ impl<'tcx, Tag: Provenance + 'static> LocalState<'tcx, Tag> { match self.value { LocalValue::Dead => throw_ub!(DeadLocal), LocalValue::Live(Operand::Indirect(mplace)) => Ok(Err(mplace)), - ref mut - local @ (LocalValue::Live(Operand::Immediate(_)) | LocalValue::Uninitialized) => { + ref mut local @ (LocalValue::Live(Operand::Immediate(_)) | LocalValue::Unallocated) => { Ok(Ok(local)) } } @@ -752,8 +750,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { })?; } - // Locals are initially uninitialized. - let dummy = LocalState { value: LocalValue::Uninitialized, layout: Cell::new(None) }; + // Locals are initially unallocated. + let dummy = LocalState { value: LocalValue::Unallocated, layout: Cell::new(None) }; let mut locals = IndexVec::from_elem(dummy, &body.local_decls); // Now mark those locals as dead that we do not want to initialize @@ -921,7 +919,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { assert!(local != mir::RETURN_PLACE, "Cannot make return place live"); trace!("{:?} is now live", local); - let local_val = LocalValue::Uninitialized; + let local_val = LocalValue::Unallocated; // StorageLive expects the local to be dead, and marks it live. let old = mem::replace(&mut self.frame_mut().locals[local].value, local_val); if !matches!(old, LocalValue::Dead) { @@ -1025,7 +1023,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> std::fmt::Debug match self.ecx.stack()[frame].locals[local].value { LocalValue::Dead => write!(fmt, " is dead")?, - LocalValue::Uninitialized => write!(fmt, " is uninitialized")?, + LocalValue::Unallocated => write!(fmt, " is unallocated")?, LocalValue::Live(Operand::Indirect(mplace)) => { write!( fmt, diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index 5ed33ab9fec17..c4d15d4d18720 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -244,8 +244,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx> ) -> InterpResult<'tcx, InterpOperand> { let l = &frame.locals[local]; - if l.value == LocalValue::Uninitialized { - throw_machine_stop_str!("tried to access an uninitialized local") + if l.value == LocalValue::Unallocated { + throw_machine_stop_str!("tried to access an unallocated local") } l.access() @@ -442,7 +442,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { /// but not reading from them anymore. fn remove_const(ecx: &mut InterpCx<'mir, 'tcx, ConstPropMachine<'mir, 'tcx>>, local: Local) { ecx.frame_mut().locals[local] = - LocalState { value: LocalValue::Uninitialized, layout: Cell::new(None) }; + LocalState { value: LocalValue::Unallocated, layout: Cell::new(None) }; } fn lint_root(&self, source_info: SourceInfo) -> Option { @@ -1147,7 +1147,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> { let frame = self.ecx.frame_mut(); frame.locals[local].value = if let StatementKind::StorageLive(_) = statement.kind { - LocalValue::Uninitialized + LocalValue::Unallocated } else { LocalValue::Dead }; From 62ded071d588b92b394c4561d19d517d87074728 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Tue, 22 Mar 2022 16:06:56 +0900 Subject: [PATCH 5/6] cancel a not emitted error after parsing const generic args --- compiler/rustc_parse/src/parser/path.rs | 12 ++++++++---- .../ice-const-generic-function-return-ty.rs | 5 +++++ .../ice-const-generic-function-return-ty.stderr | 8 ++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/const-generics/ice-const-generic-function-return-ty.rs create mode 100644 src/test/ui/const-generics/ice-const-generic-function-return-ty.stderr diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index 17c57867cf9cf..07ce879de8f0e 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -630,10 +630,14 @@ impl<'a> Parser<'a> { Ok(ty) => GenericArg::Type(ty), Err(err) => { if is_const_fn { - if let Ok(expr) = (*snapshot).parse_expr_res(Restrictions::CONST_EXPR, None) - { - self.restore_snapshot(snapshot); - return Ok(Some(self.dummy_const_arg_needs_braces(err, expr.span))); + match (*snapshot).parse_expr_res(Restrictions::CONST_EXPR, None) { + Ok(expr) => { + self.restore_snapshot(snapshot); + return Ok(Some(self.dummy_const_arg_needs_braces(err, expr.span))); + } + Err(err) => { + err.cancel(); + } } } // Try to recover from possible `const` arg without braces. diff --git a/src/test/ui/const-generics/ice-const-generic-function-return-ty.rs b/src/test/ui/const-generics/ice-const-generic-function-return-ty.rs new file mode 100644 index 0000000000000..2bf628af8a772 --- /dev/null +++ b/src/test/ui/const-generics/ice-const-generic-function-return-ty.rs @@ -0,0 +1,5 @@ +// #95163 +fn return_ty() -> impl Into<<() as Reexported; +//~^ ERROR expected one of `(`, `::`, `<`, or `>`, found `;` + +fn main() {} diff --git a/src/test/ui/const-generics/ice-const-generic-function-return-ty.stderr b/src/test/ui/const-generics/ice-const-generic-function-return-ty.stderr new file mode 100644 index 0000000000000..a72f5800a07c3 --- /dev/null +++ b/src/test/ui/const-generics/ice-const-generic-function-return-ty.stderr @@ -0,0 +1,8 @@ +error: expected one of `(`, `::`, `<`, or `>`, found `;` + --> $DIR/ice-const-generic-function-return-ty.rs:2:46 + | +LL | fn return_ty() -> impl Into<<() as Reexported; + | ^ expected one of `(`, `::`, `<`, or `>` + +error: aborting due to previous error + From 8ddb34dbe27fa9973959c92cb89f3e2c9ce0962f Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 21 Mar 2022 15:45:51 +0100 Subject: [PATCH 6/6] Move std::sys::{mutex, condvar, rwlock} to std::sys::locks. --- library/std/src/sys/hermit/mod.rs | 13 ++++++++++--- library/std/src/sys/sgx/mod.rs | 13 ++++++++++--- library/std/src/sys/solid/mod.rs | 11 +++++++++-- .../sys/unsupported/{ => locks}/condvar.rs | 2 +- library/std/src/sys/unsupported/locks/mod.rs | 6 ++++++ .../src/sys/unsupported/{ => locks}/mutex.rs | 0 .../src/sys/unsupported/{ => locks}/rwlock.rs | 0 library/std/src/sys/unsupported/mod.rs | 4 +--- library/std/src/sys/wasi/mod.rs | 8 ++------ library/std/src/sys/wasm/mod.rs | 19 ++++++++++--------- .../src/sys/windows/{ => locks}/condvar.rs | 4 ++-- library/std/src/sys/windows/locks/mod.rs | 6 ++++++ .../std/src/sys/windows/{ => locks}/mutex.rs | 0 .../std/src/sys/windows/{ => locks}/rwlock.rs | 0 library/std/src/sys/windows/mod.rs | 4 +--- 15 files changed, 58 insertions(+), 32 deletions(-) rename library/std/src/sys/unsupported/{ => locks}/condvar.rs (95%) create mode 100644 library/std/src/sys/unsupported/locks/mod.rs rename library/std/src/sys/unsupported/{ => locks}/mutex.rs (100%) rename library/std/src/sys/unsupported/{ => locks}/rwlock.rs (100%) rename library/std/src/sys/windows/{ => locks}/condvar.rs (93%) create mode 100644 library/std/src/sys/windows/locks/mod.rs rename library/std/src/sys/windows/{ => locks}/mutex.rs (100%) rename library/std/src/sys/windows/{ => locks}/rwlock.rs (100%) diff --git a/library/std/src/sys/hermit/mod.rs b/library/std/src/sys/hermit/mod.rs index b798c97448b8f..08eca42380204 100644 --- a/library/std/src/sys/hermit/mod.rs +++ b/library/std/src/sys/hermit/mod.rs @@ -22,14 +22,12 @@ pub mod alloc; pub mod args; #[path = "../unix/cmath.rs"] pub mod cmath; -pub mod condvar; pub mod env; pub mod fd; pub mod fs; #[path = "../unsupported/io.rs"] pub mod io; pub mod memchr; -pub mod mutex; pub mod net; pub mod os; #[path = "../unix/os_str.rs"] @@ -40,7 +38,6 @@ pub mod path; pub mod pipe; #[path = "../unsupported/process.rs"] pub mod process; -pub mod rwlock; pub mod stdio; pub mod thread; pub mod thread_local_dtor; @@ -48,6 +45,16 @@ pub mod thread_local_dtor; pub mod thread_local_key; pub mod time; +mod condvar; +mod mutex; +mod rwlock; + +pub mod locks { + pub use super::condvar::*; + pub use super::mutex::*; + pub use super::rwlock::*; +} + use crate::io::ErrorKind; #[allow(unused_extern_crates)] diff --git a/library/std/src/sys/sgx/mod.rs b/library/std/src/sys/sgx/mod.rs index 158c92e7a77d4..1333edb9881a1 100644 --- a/library/std/src/sys/sgx/mod.rs +++ b/library/std/src/sys/sgx/mod.rs @@ -15,7 +15,6 @@ pub mod alloc; pub mod args; #[path = "../unix/cmath.rs"] pub mod cmath; -pub mod condvar; pub mod env; pub mod fd; #[path = "../unsupported/fs.rs"] @@ -23,7 +22,6 @@ pub mod fs; #[path = "../unsupported/io.rs"] pub mod io; pub mod memchr; -pub mod mutex; pub mod net; pub mod os; #[path = "../unix/os_str.rs"] @@ -33,12 +31,21 @@ pub mod path; pub mod pipe; #[path = "../unsupported/process.rs"] pub mod process; -pub mod rwlock; pub mod stdio; pub mod thread; pub mod thread_local_key; pub mod time; +mod condvar; +mod mutex; +mod rwlock; + +pub mod locks { + pub use super::condvar::*; + pub use super::mutex::*; + pub use super::rwlock::*; +} + // SAFETY: must be called only once during runtime initialization. // NOTE: this is not guaranteed to run, for example when Rust code is called externally. pub unsafe fn init(argc: isize, argv: *const *const u8) { diff --git a/library/std/src/sys/solid/mod.rs b/library/std/src/sys/solid/mod.rs index 049460755d65a..492b1a55475a2 100644 --- a/library/std/src/sys/solid/mod.rs +++ b/library/std/src/sys/solid/mod.rs @@ -37,14 +37,21 @@ pub mod path; pub mod pipe; #[path = "../unsupported/process.rs"] pub mod process; -pub mod rwlock; pub mod stdio; -pub use self::itron::{condvar, mutex, thread}; +pub use self::itron::thread; pub mod memchr; pub mod thread_local_dtor; pub mod thread_local_key; pub mod time; +mod rwlock; + +pub mod locks { + pub use super::itron::condvar::*; + pub use super::itron::mutex::*; + pub use super::rwlock::*; +} + // SAFETY: must be called only once during runtime initialization. // NOTE: this is not guaranteed to run, for example when Rust code is called externally. pub unsafe fn init(_argc: isize, _argv: *const *const u8) {} diff --git a/library/std/src/sys/unsupported/condvar.rs b/library/std/src/sys/unsupported/locks/condvar.rs similarity index 95% rename from library/std/src/sys/unsupported/condvar.rs rename to library/std/src/sys/unsupported/locks/condvar.rs index 35d12a69c8aa5..8dbe03bad9b0d 100644 --- a/library/std/src/sys/unsupported/condvar.rs +++ b/library/std/src/sys/unsupported/locks/condvar.rs @@ -1,4 +1,4 @@ -use crate::sys::mutex::Mutex; +use crate::sys::locks::Mutex; use crate::time::Duration; pub struct Condvar {} diff --git a/library/std/src/sys/unsupported/locks/mod.rs b/library/std/src/sys/unsupported/locks/mod.rs new file mode 100644 index 0000000000000..5634f10633963 --- /dev/null +++ b/library/std/src/sys/unsupported/locks/mod.rs @@ -0,0 +1,6 @@ +mod condvar; +mod mutex; +mod rwlock; +pub use condvar::{Condvar, MovableCondvar}; +pub use mutex::{MovableMutex, Mutex, ReentrantMutex}; +pub use rwlock::{MovableRWLock, RWLock}; diff --git a/library/std/src/sys/unsupported/mutex.rs b/library/std/src/sys/unsupported/locks/mutex.rs similarity index 100% rename from library/std/src/sys/unsupported/mutex.rs rename to library/std/src/sys/unsupported/locks/mutex.rs diff --git a/library/std/src/sys/unsupported/rwlock.rs b/library/std/src/sys/unsupported/locks/rwlock.rs similarity index 100% rename from library/std/src/sys/unsupported/rwlock.rs rename to library/std/src/sys/unsupported/locks/rwlock.rs diff --git a/library/std/src/sys/unsupported/mod.rs b/library/std/src/sys/unsupported/mod.rs index a1276193bda37..7bf6d40b76daa 100644 --- a/library/std/src/sys/unsupported/mod.rs +++ b/library/std/src/sys/unsupported/mod.rs @@ -4,11 +4,10 @@ pub mod alloc; pub mod args; #[path = "../unix/cmath.rs"] pub mod cmath; -pub mod condvar; pub mod env; pub mod fs; pub mod io; -pub mod mutex; +pub mod locks; pub mod net; pub mod os; #[path = "../unix/os_str.rs"] @@ -17,7 +16,6 @@ pub mod os_str; pub mod path; pub mod pipe; pub mod process; -pub mod rwlock; pub mod stdio; pub mod thread; #[cfg(target_thread_local)] diff --git a/library/std/src/sys/wasi/mod.rs b/library/std/src/sys/wasi/mod.rs index f878941939ce8..683a07a34dcf9 100644 --- a/library/std/src/sys/wasi/mod.rs +++ b/library/std/src/sys/wasi/mod.rs @@ -22,14 +22,12 @@ pub mod alloc; pub mod args; #[path = "../unix/cmath.rs"] pub mod cmath; -#[path = "../unsupported/condvar.rs"] -pub mod condvar; pub mod env; pub mod fd; pub mod fs; pub mod io; -#[path = "../unsupported/mutex.rs"] -pub mod mutex; +#[path = "../unsupported/locks/mod.rs"] +pub mod locks; pub mod net; pub mod os; #[path = "../unix/os_str.rs"] @@ -40,8 +38,6 @@ pub mod path; pub mod pipe; #[path = "../unsupported/process.rs"] pub mod process; -#[path = "../unsupported/rwlock.rs"] -pub mod rwlock; pub mod stdio; pub mod thread; #[path = "../unsupported/thread_local_dtor.rs"] diff --git a/library/std/src/sys/wasm/mod.rs b/library/std/src/sys/wasm/mod.rs index c81d653a5e38f..9f6700caf14bf 100644 --- a/library/std/src/sys/wasm/mod.rs +++ b/library/std/src/sys/wasm/mod.rs @@ -50,22 +50,23 @@ pub mod time; cfg_if::cfg_if! { if #[cfg(target_feature = "atomics")] { #[path = "atomics/condvar.rs"] - pub mod condvar; + mod condvar; #[path = "atomics/mutex.rs"] - pub mod mutex; + mod mutex; #[path = "atomics/rwlock.rs"] - pub mod rwlock; + mod rwlock; + pub mod locks { + pub use super::condvar::*; + pub use super::mutex::*; + pub use super::rwlock::*; + } #[path = "atomics/futex.rs"] pub mod futex; #[path = "atomics/thread.rs"] pub mod thread; } else { - #[path = "../unsupported/condvar.rs"] - pub mod condvar; - #[path = "../unsupported/mutex.rs"] - pub mod mutex; - #[path = "../unsupported/rwlock.rs"] - pub mod rwlock; + #[path = "../unsupported/locks/mod.rs"] + pub mod locks; #[path = "../unsupported/thread.rs"] pub mod thread; } diff --git a/library/std/src/sys/windows/condvar.rs b/library/std/src/sys/windows/locks/condvar.rs similarity index 93% rename from library/std/src/sys/windows/condvar.rs rename to library/std/src/sys/windows/locks/condvar.rs index 44547a5c51a34..dfd8cfdceee75 100644 --- a/library/std/src/sys/windows/condvar.rs +++ b/library/std/src/sys/windows/locks/condvar.rs @@ -1,6 +1,6 @@ use crate::cell::UnsafeCell; use crate::sys::c; -use crate::sys::mutex::{self, Mutex}; +use crate::sys::locks::{mutex, Mutex}; use crate::sys::os; use crate::time::Duration; @@ -31,7 +31,7 @@ impl Condvar { let r = c::SleepConditionVariableSRW( self.inner.get(), mutex::raw(mutex), - super::dur2timeout(dur), + crate::sys::windows::dur2timeout(dur), 0, ); if r == 0 { diff --git a/library/std/src/sys/windows/locks/mod.rs b/library/std/src/sys/windows/locks/mod.rs new file mode 100644 index 0000000000000..5634f10633963 --- /dev/null +++ b/library/std/src/sys/windows/locks/mod.rs @@ -0,0 +1,6 @@ +mod condvar; +mod mutex; +mod rwlock; +pub use condvar::{Condvar, MovableCondvar}; +pub use mutex::{MovableMutex, Mutex, ReentrantMutex}; +pub use rwlock::{MovableRWLock, RWLock}; diff --git a/library/std/src/sys/windows/mutex.rs b/library/std/src/sys/windows/locks/mutex.rs similarity index 100% rename from library/std/src/sys/windows/mutex.rs rename to library/std/src/sys/windows/locks/mutex.rs diff --git a/library/std/src/sys/windows/rwlock.rs b/library/std/src/sys/windows/locks/rwlock.rs similarity index 100% rename from library/std/src/sys/windows/rwlock.rs rename to library/std/src/sys/windows/locks/rwlock.rs diff --git a/library/std/src/sys/windows/mod.rs b/library/std/src/sys/windows/mod.rs index 6097e62876847..62814eaaa5667 100644 --- a/library/std/src/sys/windows/mod.rs +++ b/library/std/src/sys/windows/mod.rs @@ -16,13 +16,12 @@ pub mod alloc; pub mod args; pub mod c; pub mod cmath; -pub mod condvar; pub mod env; pub mod fs; pub mod handle; pub mod io; +pub mod locks; pub mod memchr; -pub mod mutex; pub mod net; pub mod os; pub mod os_str; @@ -30,7 +29,6 @@ pub mod path; pub mod pipe; pub mod process; pub mod rand; -pub mod rwlock; pub mod thread; pub mod thread_local_dtor; pub mod thread_local_key;