From 82c5cdc6b1de77634d63faacd6b606c99e816316 Mon Sep 17 00:00:00 2001 From: wooden-worm <93303706+wooden-worm@users.noreply.github.com> Date: Sun, 23 Jun 2024 22:58:30 -0700 Subject: [PATCH 1/6] wasm64 build with target-feature=+simd128,+atomics --- .../crates/core_simd/src/swizzle_dyn.rs | 2 ++ library/std/src/lib.rs | 1 + library/std/src/sys/pal/wasm/atomics/futex.rs | 17 +++++++++-------- library/std/src/sys/pal/wasm/atomics/thread.rs | 8 ++++++-- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/library/portable-simd/crates/core_simd/src/swizzle_dyn.rs b/library/portable-simd/crates/core_simd/src/swizzle_dyn.rs index 8a1079042f076..3b6388d0f2759 100644 --- a/library/portable-simd/crates/core_simd/src/swizzle_dyn.rs +++ b/library/portable-simd/crates/core_simd/src/swizzle_dyn.rs @@ -30,6 +30,8 @@ where use core::arch::arm::{uint8x8_t, vtbl1_u8}; #[cfg(target_arch = "wasm32")] use core::arch::wasm32 as wasm; + #[cfg(target_arch = "wasm64")] + use core::arch::wasm64 as wasm; #[cfg(target_arch = "x86")] use core::arch::x86; #[cfg(target_arch = "x86_64")] diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 80f67838ac002..f67e4a050cfee 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -266,6 +266,7 @@ )] #![cfg_attr(any(windows, target_os = "uefi"), feature(round_char_boundary))] #![cfg_attr(target_family = "wasm", feature(stdarch_wasm_atomic_wait))] +#![cfg_attr(target_arch = "wasm64", feature(simd_wasm64))] #![cfg_attr( all(any(target_arch = "x86_64", target_arch = "x86"), target_os = "uefi"), feature(stdarch_x86_has_cpuid) diff --git a/library/std/src/sys/pal/wasm/atomics/futex.rs b/library/std/src/sys/pal/wasm/atomics/futex.rs index f4fbe9f48554b..a21b71efbbc69 100644 --- a/library/std/src/sys/pal/wasm/atomics/futex.rs +++ b/library/std/src/sys/pal/wasm/atomics/futex.rs @@ -1,4 +1,8 @@ -use crate::arch::wasm32; +#[cfg(target_arch = "wasm32")] +use core::arch::wasm32 as wasm; +#[cfg(target_arch = "wasm64")] +use core::arch::wasm64 as wasm; + use crate::sync::atomic::AtomicU32; use crate::time::Duration; @@ -10,11 +14,8 @@ use crate::time::Duration; pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option) -> bool { let timeout = timeout.and_then(|t| t.as_nanos().try_into().ok()).unwrap_or(-1); unsafe { - wasm32::memory_atomic_wait32( - futex as *const AtomicU32 as *mut i32, - expected as i32, - timeout, - ) < 2 + wasm::memory_atomic_wait32(futex as *const AtomicU32 as *mut i32, expected as i32, timeout) + < 2 } } @@ -23,12 +24,12 @@ pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option) - /// Returns true if this actually woke up such a thread, /// or false if no thread was waiting on this futex. pub fn futex_wake(futex: &AtomicU32) -> bool { - unsafe { wasm32::memory_atomic_notify(futex as *const AtomicU32 as *mut i32, 1) > 0 } + unsafe { wasm::memory_atomic_notify(futex as *const AtomicU32 as *mut i32, 1) > 0 } } /// Wake up all threads that are waiting on futex_wait on this futex. pub fn futex_wake_all(futex: &AtomicU32) { unsafe { - wasm32::memory_atomic_notify(futex as *const AtomicU32 as *mut i32, i32::MAX as u32); + wasm::memory_atomic_notify(futex as *const AtomicU32 as *mut i32, i32::MAX as u32); } } diff --git a/library/std/src/sys/pal/wasm/atomics/thread.rs b/library/std/src/sys/pal/wasm/atomics/thread.rs index 484bd08495eef..afdb159fe6f8b 100644 --- a/library/std/src/sys/pal/wasm/atomics/thread.rs +++ b/library/std/src/sys/pal/wasm/atomics/thread.rs @@ -19,7 +19,11 @@ impl Thread { pub fn set_name(_name: &CStr) {} pub fn sleep(dur: Duration) { - use crate::arch::wasm32; + #[cfg(target_arch = "wasm32")] + use core::arch::wasm32 as wasm; + #[cfg(target_arch = "wasm64")] + use core::arch::wasm64 as wasm; + use crate::cmp; // Use an atomic wait to block the current thread artificially with a @@ -31,7 +35,7 @@ impl Thread { while nanos > 0 { let amt = cmp::min(i64::MAX as u128, nanos); let mut x = 0; - let val = unsafe { wasm32::memory_atomic_wait32(&mut x, 0, amt as i64) }; + let val = unsafe { wasm::memory_atomic_wait32(&mut x, 0, amt as i64) }; debug_assert_eq!(val, 2); nanos -= amt; } From 9732251e5f36772bb030ec4e3b8f6fc4f8371eec Mon Sep 17 00:00:00 2001 From: B I Mohammed Abbas Date: Mon, 1 Jul 2024 11:13:30 +0530 Subject: [PATCH 2/6] Remove unqualified import io:: Error for vxworks as all Error references are qualified in process_vxworks.rs --- library/std/src/sys/pal/unix/process/process_vxworks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/pal/unix/process/process_vxworks.rs b/library/std/src/sys/pal/unix/process/process_vxworks.rs index 76179e0910d9e..5007dbd34b4ab 100644 --- a/library/std/src/sys/pal/unix/process/process_vxworks.rs +++ b/library/std/src/sys/pal/unix/process/process_vxworks.rs @@ -1,5 +1,5 @@ use crate::fmt; -use crate::io::{self, Error, ErrorKind}; +use crate::io::{self, ErrorKind}; use crate::num::NonZero; use crate::sys; use crate::sys::cvt; From a6c03ae6fe3dd93146be3a1f7fd65ccd58e3ab67 Mon Sep 17 00:00:00 2001 From: B I Mohammed Abbas Date: Mon, 1 Jul 2024 10:33:27 +0530 Subject: [PATCH 3/6] Fall back on remove dir implementation for vxworks --- library/std/src/sys/pal/unix/fs.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/std/src/sys/pal/unix/fs.rs b/library/std/src/sys/pal/unix/fs.rs index 92c76ec4303fe..f9d6b5fbc86a4 100644 --- a/library/std/src/sys/pal/unix/fs.rs +++ b/library/std/src/sys/pal/unix/fs.rs @@ -1976,13 +1976,14 @@ pub fn chroot(dir: &Path) -> io::Result<()> { pub use remove_dir_impl::remove_dir_all; -// Fallback for REDOX, ESP-ID, Horizon, Vita and Miri +// Fallback for REDOX, ESP-ID, Horizon, Vita, Vxworks and Miri #[cfg(any( target_os = "redox", target_os = "espidf", target_os = "horizon", target_os = "vita", target_os = "nto", + target_os = "vxworks", miri ))] mod remove_dir_impl { @@ -1996,6 +1997,7 @@ mod remove_dir_impl { target_os = "horizon", target_os = "vita", target_os = "nto", + target_os = "vxworks", miri )))] mod remove_dir_impl { From ccc8baf08aa5a204a7df55e67022aa6c5254966c Mon Sep 17 00:00:00 2001 From: Alona Enraght-Moony Date: Wed, 3 Jul 2024 19:38:19 +0000 Subject: [PATCH 4/6] jsondocck: Use correct index for error message. If you misused a count command like `@count $some.selector '"T'"`, you would panic with OOB: ``` thread 'main' panicked at src/tools/jsondocck/src/main.rs:76:92: index out of bounds: the len is 2 but the index is 2 ``` Fixing this typo, we now get. ``` Invalid command: Second argument to @count must be a valid usize (got `"T"`) on line 20 ``` As some point I want to rewrite this code to avoid indexing in general, but this is a nice small fix. --- src/tools/jsondocck/src/main.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tools/jsondocck/src/main.rs b/src/tools/jsondocck/src/main.rs index 688b403bf0e0a..429c6151796fe 100644 --- a/src/tools/jsondocck/src/main.rs +++ b/src/tools/jsondocck/src/main.rs @@ -56,6 +56,8 @@ pub enum CommandKind { impl CommandKind { fn validate(&self, args: &[String], lineno: usize) -> bool { + // FIXME(adotinthevoid): We should "parse, don't validate" here, so we avoid ad-hoc + // indexing in check_command. let count = match self { CommandKind::Has => (1..=2).contains(&args.len()), CommandKind::IsMany => args.len() >= 2, @@ -71,7 +73,7 @@ impl CommandKind { if let CommandKind::Count = self { if args[1].parse::().is_err() { print_err( - &format!("Second argument to @count must be a valid usize (got `{}`)", args[2]), + &format!("Second argument to @count must be a valid usize (got `{}`)", args[1]), lineno, ); return false; From 7e8aac553e756b0eb03fe98e1a65ffc47836ec51 Mon Sep 17 00:00:00 2001 From: Alona Enraght-Moony Date: Wed, 3 Jul 2024 19:57:15 +0000 Subject: [PATCH 5/6] rustdoc-json: Better representation of lifetime bounds in where clauses. As suggested [on zulip][1], there's no need to use `GenericBound` here, as the only bound a lifetime can have is that it outlives other lifetimes. While we're making breaking changes here, I also renamed it from using "region" to "lifetime", as this is more user-aligned. See [this comment][2] for details. [1]: https://rust-lang.zulipchat.com/#narrow/stream/266220-t-rustdoc/topic/.60ItemEnum.3A.3AOpaqueTy.60/near/448871430 [2]: https://github.com/rust-lang/rust/issues/100961#issuecomment-2206565556 --- src/librustdoc/clean/types.rs | 2 +- src/librustdoc/json/conversions.rs | 11 +++++++-- src/rustdoc-json-types/lib.rs | 6 ++--- src/tools/jsondoclint/src/validator.rs | 4 ++-- .../lifetime/outlives_in_param.rs | 8 +++++++ .../lifetime/outlives_in_where.rs | 24 +++++++++++++++++++ 6 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 tests/rustdoc-json/lifetime/outlives_in_param.rs create mode 100644 tests/rustdoc-json/lifetime/outlives_in_where.rs diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 9050a1c12078b..6aa3da2719a80 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1286,7 +1286,7 @@ impl GenericBound { } } -#[derive(Clone, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] pub(crate) struct Lifetime(pub Symbol); impl Lifetime { diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index b965ab019cc4f..5111e363c522e 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -10,6 +10,7 @@ use rustc_ast::ast; use rustc_attr::DeprecatedSince; use rustc_hir::{def::CtorKind, def::DefKind, def_id::DefId}; use rustc_metadata::rendered_const; +use rustc_middle::bug; use rustc_middle::ty::{self, TyCtxt}; use rustc_span::symbol::sym; use rustc_span::{Pos, Symbol}; @@ -512,9 +513,15 @@ impl FromWithTcx for WherePredicate { }) .collect(), }, - RegionPredicate { lifetime, bounds } => WherePredicate::RegionPredicate { + RegionPredicate { lifetime, bounds } => WherePredicate::LifetimePredicate { lifetime: convert_lifetime(lifetime), - bounds: bounds.into_tcx(tcx), + outlives: bounds + .iter() + .map(|bound| match bound { + clean::GenericBound::Outlives(lt) => convert_lifetime(*lt), + _ => bug!("found non-outlives-bound on lifetime predicate"), + }) + .collect(), }, EqPredicate { lhs, rhs } => { WherePredicate::EqPredicate { lhs: lhs.into_tcx(tcx), rhs: rhs.into_tcx(tcx) } diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 68030493e9cfd..89115d4d7d667 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use std::path::PathBuf; /// rustdoc format-version. -pub const FORMAT_VERSION: u32 = 30; +pub const FORMAT_VERSION: u32 = 31; /// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information /// about the language items in the local crate, as well as info about external items to allow @@ -511,9 +511,9 @@ pub enum WherePredicate { /// ``` generic_params: Vec, }, - RegionPredicate { + LifetimePredicate { lifetime: String, - bounds: Vec, + outlives: Vec, }, EqPredicate { lhs: Type, diff --git a/src/tools/jsondoclint/src/validator.rs b/src/tools/jsondoclint/src/validator.rs index 1713a4d812c4b..cd011dce7844e 100644 --- a/src/tools/jsondoclint/src/validator.rs +++ b/src/tools/jsondoclint/src/validator.rs @@ -374,8 +374,8 @@ impl<'a> Validator<'a> { bounds.iter().for_each(|b| self.check_generic_bound(b)); generic_params.iter().for_each(|gpd| self.check_generic_param_def(gpd)); } - WherePredicate::RegionPredicate { lifetime: _, bounds } => { - bounds.iter().for_each(|b| self.check_generic_bound(b)); + WherePredicate::LifetimePredicate { lifetime: _, outlives: _ } => { + // nop, all strings. } WherePredicate::EqPredicate { lhs, rhs } => { self.check_type(lhs); diff --git a/tests/rustdoc-json/lifetime/outlives_in_param.rs b/tests/rustdoc-json/lifetime/outlives_in_param.rs new file mode 100644 index 0000000000000..f6db93c918329 --- /dev/null +++ b/tests/rustdoc-json/lifetime/outlives_in_param.rs @@ -0,0 +1,8 @@ +// ignore-tidy-linelength + +// @count '$.index[*][?(@.name=="outlives")].inner.function.generics.params[*]' 2 +// @is '$.index[*][?(@.name=="outlives")].inner.function.generics.params[0].name' \"\'a\" +// @is '$.index[*][?(@.name=="outlives")].inner.function.generics.params[0].kind.lifetime.outlives' [] +// @is '$.index[*][?(@.name=="outlives")].inner.function.generics.params[1].name' '"T"' +// @is '$.index[*][?(@.name=="outlives")].inner.function.generics.params[1].kind.type.bounds' '[{"outlives": "'\''a"}]' +pub fn outlives<'a, T: 'a>() {} diff --git a/tests/rustdoc-json/lifetime/outlives_in_where.rs b/tests/rustdoc-json/lifetime/outlives_in_where.rs new file mode 100644 index 0000000000000..ca3e1a150ce8e --- /dev/null +++ b/tests/rustdoc-json/lifetime/outlives_in_where.rs @@ -0,0 +1,24 @@ +// ignore-tidy-linelength + +// @is '$.index[*][?(@.name=="on_lifetimes")].inner.function.generics.where_predicates' '[{"lifetime_predicate": {"lifetime": "'\''all", "outlives": ["'\''a", "'\''b", "'\''c"]}}]' +pub fn on_lifetimes<'a, 'b, 'c, 'all>() +where + 'all: 'a + 'b + 'c, +{ +} + +// @count '$.index[*][?(@.name=="on_trait")].inner.function.generics.params[*]' 2 +// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.params[0].name' \"\'a\" +// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.params[0].kind.lifetime.outlives' [] +// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.params[1].name' '"T"' +// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.params[1].kind.type.bounds' [] +// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.params[1].kind.type.bounds' [] +// @count '$.index[*][?(@.name=="on_trait")].inner.function.generics.where_predicates[*]' 1 +// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.where_predicates[0].bound_predicate.type.generic' '"T"' +// @count '$.index[*][?(@.name=="on_trait")].inner.function.generics.where_predicates[0].bound_predicate.bounds[*]' 1 +// @is '$.index[*][?(@.name=="on_trait")].inner.function.generics.where_predicates[0].bound_predicate.bounds[0].outlives' \"\'a\" +pub fn on_trait<'a, T>() +where + T: 'a, +{ +} From b50e9155781d767c8edb487fe9d19e5b701961d5 Mon Sep 17 00:00:00 2001 From: cuishuang Date: Thu, 4 Jul 2024 14:56:08 +0800 Subject: [PATCH 6/6] chore: remove repeat words Signed-off-by: cuishuang --- library/core/src/hint.rs | 2 +- library/core/src/slice/sort/stable/drift.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/hint.rs b/library/core/src/hint.rs index 976a6c04ca6fa..b3e36e6fbc4ac 100644 --- a/library/core/src/hint.rs +++ b/library/core/src/hint.rs @@ -189,7 +189,7 @@ pub const unsafe fn unreachable_unchecked() -> ! { /// ``` /// /// This example is quite unlike anything that would be used in the real world: it is redundant -/// to put an an assertion right next to code that checks the same thing, and dereferencing a +/// to put an assertion right next to code that checks the same thing, and dereferencing a /// pointer already has the builtin assumption that it is nonnull. However, it illustrates the /// kind of changes the optimizer can make even when the behavior is less obviously related. #[track_caller] diff --git a/library/core/src/slice/sort/stable/drift.rs b/library/core/src/slice/sort/stable/drift.rs index 4008639095bde..2d9c4ac9fcf7c 100644 --- a/library/core/src/slice/sort/stable/drift.rs +++ b/library/core/src/slice/sort/stable/drift.rs @@ -200,7 +200,7 @@ fn logical_merge bool>( // If one or both of the runs are sorted do a physical merge, using // quicksort to sort the unsorted run if present. We also *need* to // physically merge if the combined runs would not fit in the scratch space - // anymore (as this would mean we are no longer able to to quicksort them). + // anymore (as this would mean we are no longer able to quicksort them). let len = v.len(); let can_fit_in_scratch = len <= scratch.len(); if !can_fit_in_scratch || left.sorted() || right.sorted() {