From 891041fbc994648f3ab771e9e9147a9fddc6006f Mon Sep 17 00:00:00 2001 From: Davis Muro Date: Mon, 30 Dec 2024 08:18:22 -0800 Subject: [PATCH 1/7] deny usage of FileCheck prefixes as revision names --- src/tools/compiletest/src/header.rs | 10 ++++++++++ src/tools/compiletest/src/header/tests.rs | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 48149e3b897e1..3111793ab6a81 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -934,6 +934,9 @@ fn iter_header( impl Config { fn parse_and_update_revisions(&self, testfile: &Path, line: &str, existing: &mut Vec) { + const FORBIDDEN_REVISION_NAMES: [&str; 9] = + ["CHECK", "COM", "NEXT", "SAME", "EMPTY", "NOT", "COUNT", "DAG", "LABEL"]; + if let Some(raw) = self.parse_name_value_directive(line, "revisions") { if self.mode == Mode::RunMake { panic!("`run-make` tests do not support revisions: {}", testfile.display()); @@ -948,6 +951,13 @@ impl Config { raw, testfile.display() ); + } else if FORBIDDEN_REVISION_NAMES.contains(&revision.as_str()) { + panic!( + "invalid revision: `{}` in line `{}`: {}", + revision, + raw, + testfile.display() + ); } existing.push(revision); } diff --git a/src/tools/compiletest/src/header/tests.rs b/src/tools/compiletest/src/header/tests.rs index 618b66dfd4cb6..52bbd0314985f 100644 --- a/src/tools/compiletest/src/header/tests.rs +++ b/src/tools/compiletest/src/header/tests.rs @@ -553,6 +553,21 @@ fn test_duplicate_revisions() { parse_rs(&config, "//@ revisions: rpass1 rpass1"); } +#[test] +fn test_forbidden_revisions() { + let config: Config = cfg().build(); + let revisions = ["CHECK", "COM", "NEXT", "SAME", "EMPTY", "NOT", "COUNT", "DAG", "LABEL"]; + for rev in revisions { + let res = std::panic::catch_unwind(|| { + parse_rs(&config, format!("//@ revisions: {rev}").as_str()); + }); + assert!(res.is_err()); + if let Some(msg) = res.unwrap_err().downcast_ref::() { + assert!(msg.contains(format!("invalid revision: `{rev}` in line ` {rev}`").as_str())) + } + } +} + #[test] fn ignore_arch() { let archs = [ From 4a5e76a70e3d33b0eb4a233f60de5578b22bfba5 Mon Sep 17 00:00:00 2001 From: Davis Muro Date: Thu, 2 Jan 2025 18:27:07 -0800 Subject: [PATCH 2/7] limit special `FileCheck` revision checks --- src/tools/compiletest/src/header.rs | 8 ++-- src/tools/compiletest/src/header/tests.rs | 54 +++++++++++++++++++---- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 3111793ab6a81..8c96554738e68 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -951,10 +951,12 @@ impl Config { raw, testfile.display() ); - } else if FORBIDDEN_REVISION_NAMES.contains(&revision.as_str()) { + } else if matches!(self.mode, Mode::Assembly | Mode::Codegen | Mode::MirOpt) + && FORBIDDEN_REVISION_NAMES.contains(&revision.as_str()) + { panic!( - "invalid revision: `{}` in line `{}`: {}", - revision, + "revision name `{revision}` is not permitted in a test suite that uses `FileCheck` annotations\n\ + as it is confusing when used as custom `FileCheck` prefix: `{revision}` in line `{}`: {}", raw, testfile.display() ); diff --git a/src/tools/compiletest/src/header/tests.rs b/src/tools/compiletest/src/header/tests.rs index 52bbd0314985f..25bb1a5f42882 100644 --- a/src/tools/compiletest/src/header/tests.rs +++ b/src/tools/compiletest/src/header/tests.rs @@ -554,16 +554,54 @@ fn test_duplicate_revisions() { } #[test] -fn test_forbidden_revisions() { - let config: Config = cfg().build(); +#[should_panic( + expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations" +)] +fn test_assembly_mode_forbidden_revisions() { + let config = cfg().mode("assembly").build(); + parse_rs(&config, "//@ revisions: CHECK"); +} + +#[test] +#[should_panic( + expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations" +)] +fn test_codegen_mode_forbidden_revisions() { + let config = cfg().mode("codegen").build(); + parse_rs(&config, "//@ revisions: CHECK"); +} + +#[test] +#[should_panic( + expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations" +)] +fn test_miropt_mode_forbidden_revisions() { + let config = cfg().mode("mir-opt").build(); + parse_rs(&config, "//@ revisions: CHECK"); +} + +#[test] +fn test_forbidden_revisions_allowed_in_non_filecheck_dir() { let revisions = ["CHECK", "COM", "NEXT", "SAME", "EMPTY", "NOT", "COUNT", "DAG", "LABEL"]; + let modes = [ + "pretty", + "debuginfo", + "rustdoc", + "rustdoc-json", + "codegen-units", + "incremental", + "ui", + "js-doc-test", + "coverage-map", + "coverage-run", + "crashes", + ]; + for rev in revisions { - let res = std::panic::catch_unwind(|| { - parse_rs(&config, format!("//@ revisions: {rev}").as_str()); - }); - assert!(res.is_err()); - if let Some(msg) = res.unwrap_err().downcast_ref::() { - assert!(msg.contains(format!("invalid revision: `{rev}` in line ` {rev}`").as_str())) + let content = format!("//@ revisions: {rev}"); + for mode in modes { + let config = cfg().mode(mode).build(); + parse_rs(&config, &content); } } } From 2389daab1b16e75216390063a1c97fccc3e0d2af Mon Sep 17 00:00:00 2001 From: bdbai Date: Fri, 3 Jan 2025 11:14:03 +0800 Subject: [PATCH 3/7] Fix UWP build --- library/std/src/sys/pal/windows/os.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/pal/windows/os.rs b/library/std/src/sys/pal/windows/os.rs index 5231a34469abf..044dc2e8cd8fa 100644 --- a/library/std/src/sys/pal/windows/os.rs +++ b/library/std/src/sys/pal/windows/os.rs @@ -5,8 +5,9 @@ #[cfg(test)] mod tests; -use super::api::{self, WinError}; -use super::to_u16s; +#[cfg(not(target_vendor = "uwp"))] +use super::api::WinError; +use super::{api, to_u16s}; use crate::error::Error as StdError; use crate::ffi::{OsStr, OsString}; use crate::os::windows::ffi::EncodeWide; From 33b0606041a4d73d320c5cf5f7a3deeb87429daf Mon Sep 17 00:00:00 2001 From: bdbai Date: Fri, 3 Jan 2025 11:15:06 +0800 Subject: [PATCH 4/7] Add UWP support page --- src/doc/rustc/src/SUMMARY.md | 1 + src/doc/rustc/src/platform-support.md | 10 ++-- .../src/platform-support/uwp-windows-msvc.md | 52 +++++++++++++++++++ 3 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 src/doc/rustc/src/platform-support/uwp-windows-msvc.md diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index f0c3720eae14f..0f45c9dbd4e33 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -87,6 +87,7 @@ - [*-unknown-openbsd](platform-support/openbsd.md) - [*-unknown-redox](platform-support/redox.md) - [\*-unknown-uefi](platform-support/unknown-uefi.md) + - [\*-uwp-windows-msvc](platform-support/uwp-windows-msvc.md) - [\*-wrs-vxworks](platform-support/vxworks.md) - [wasm32-wasip1](platform-support/wasm32-wasip1.md) - [wasm32-wasip1-threads](platform-support/wasm32-wasip1-threads.md) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 24e9a3c812106..7b07d99199210 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -264,7 +264,7 @@ target | std | host | notes [`aarch64-unknown-redox`](platform-support/redox.md) | ✓ | | ARM64 Redox OS [`aarch64-unknown-teeos`](platform-support/aarch64-unknown-teeos.md) | ? | | ARM64 TEEOS | [`aarch64-unknown-trusty`](platform-support/trusty.md) | ? | | -`aarch64-uwp-windows-msvc` | ✓ | | +[`aarch64-uwp-windows-msvc`](platform-support/uwp-windows-msvc.md) | ✓ | | [`aarch64-wrs-vxworks`](platform-support/vxworks.md) | ✓ | | ARM64 VxWorks OS `aarch64_be-unknown-linux-gnu` | ✓ | ✓ | ARM64 Linux (big-endian) `aarch64_be-unknown-linux-gnu_ilp32` | ✓ | ✓ | ARM64 Linux (big-endian, ILP32 ABI) @@ -312,7 +312,7 @@ target | std | host | notes [`i686-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 32-bit OpenBSD [^x86_32-floats-return-ABI] [`i686-unknown-redox`](platform-support/redox.md) | ✓ | | i686 Redox OS `i686-uwp-windows-gnu` | ✓ | | [^x86_32-floats-return-ABI] -`i686-uwp-windows-msvc` | ✓ | | [^x86_32-floats-return-ABI] +[`i686-uwp-windows-msvc`](platform-support/uwp-windows-msvc.md) | ✓ | | [^x86_32-floats-return-ABI] [`i686-win7-windows-msvc`](platform-support/win7-windows-msvc.md) | ✓ | | 32-bit Windows 7 support [^x86_32-floats-return-ABI] [`i686-wrs-vxworks`](platform-support/vxworks.md) | ✓ | | [^x86_32-floats-return-ABI] [`loongarch64-unknown-linux-ohos`](platform-support/openharmony.md) | ✓ | | LoongArch64 OpenHarmony @@ -383,8 +383,8 @@ target | std | host | notes [`thumbv4t-none-eabi`](platform-support/armv4t-none-eabi.md) | * | | Thumb-mode Bare Armv4T [`thumbv5te-none-eabi`](platform-support/armv5te-none-eabi.md) | * | | Thumb-mode Bare Armv5TE [`thumbv6m-nuttx-eabi`](platform-support/nuttx.md) | * | | ARMv6M with NuttX -`thumbv7a-pc-windows-msvc` | ✓ | | -`thumbv7a-uwp-windows-msvc` | ✓ | | +`thumbv7a-pc-windows-msvc` | | | +[`thumbv7a-uwp-windows-msvc`](platform-support/uwp-windows-msvc.md) | | | [`thumbv7em-nuttx-eabi`](platform-support/nuttx.md) | * | | ARMv7EM with NuttX [`thumbv7em-nuttx-eabihf`](platform-support/nuttx.md) | * | | ARMv7EM with NuttX, hardfloat [`thumbv7m-nuttx-eabi`](platform-support/nuttx.md) | * | | ARMv7M with NuttX @@ -406,7 +406,7 @@ target | std | host | notes [`x86_64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 64-bit OpenBSD [`x86_64-unknown-trusty`](platform-support/trusty.md) | ? | | `x86_64-uwp-windows-gnu` | ✓ | | -`x86_64-uwp-windows-msvc` | ✓ | | +[`x86_64-uwp-windows-msvc`](platform-support/uwp-windows-msvc.md) | ✓ | | [`x86_64-win7-windows-msvc`](platform-support/win7-windows-msvc.md) | ✓ | | 64-bit Windows 7 support [`x86_64-wrs-vxworks`](platform-support/vxworks.md) | ✓ | | [`x86_64h-apple-darwin`](platform-support/x86_64h-apple-darwin.md) | ✓ | ✓ | macOS with late-gen Intel (at least Haswell) diff --git a/src/doc/rustc/src/platform-support/uwp-windows-msvc.md b/src/doc/rustc/src/platform-support/uwp-windows-msvc.md new file mode 100644 index 0000000000000..ce2ebb686fa50 --- /dev/null +++ b/src/doc/rustc/src/platform-support/uwp-windows-msvc.md @@ -0,0 +1,52 @@ +# `x86_64-uwp-windows-msvc`, `i686-uwp-windows-msvc`, `thumbv7a-uwp-windows-msvc` and `aarch64-uwp-windows-msvc` + +**Tier: 3** + +Windows targets for Universal Windows Platform (UWP) applications, using MSVC toolchain. + +## Target maintainers + +- [@bdbai](https://github.com/bdbai) + +## Requirements + +These targets are cross-compiled with std support. The host requirement and +binary format are the same as the corresponding non-UWP targets (i.e. +`x86_64-pc-windows-msvc`, `i686-pc-windows-msvc`, `thumbv7a-pc-windows-msvc` +and `aarch64-pc-windows-msvc`). + +## Building the targets + +The targets can be built by enabling them for a `rustc` build, for example: + +```toml +[build] +build-stage = 1 +target = ["x86_64-uwp-windows-msvc", "aarch64-uwp-windows-msvc"] +``` + +## Building Rust programs + +Rust does not yet ship pre-compiled artifacts for these targets. To compile for +these targets, you will either need to build Rust with the targets enabled (see +"Building the targets" above), or build your own copy of `std` by using +`build-std` or similar. + +Example of building a Rust project for x64 UWP using `build-std`: + +```pwsh +cargo build -Z build-std=std,panic_abort --target x86_64-uwp-windows-msvc +``` + +## Testing + +Currently there is no support to run the rustc test suite for this target. + +## Cross-compilation toolchains and C code + +In general, the toolchain target should match the corresponding non-UWP +targets. Beware that not all Win32 APIs behave the same way in UWP, and some +are restricted in [AppContainer](https://learn.microsoft.com/en-us/windows/win32/secauthz/appcontainer-for-legacy-applications-) +or even not available at all. If the C code being compiled happens to use any +of restricted or unavailable APIs, consider using allowed alternatives or +disable certain feature sets to avoid using them. From 3d871b3ced0af12a84e3d17060399ca1af8d7bc1 Mon Sep 17 00:00:00 2001 From: The 8472 Date: Sat, 4 Jan 2025 19:26:58 +0100 Subject: [PATCH 5/7] do not in-place-iterate over flatmap/flatten The implementation is unsound when a partially consumed iterator has some elements buffered in the front/back parts and cloning the Iterator removes the capacity from the backing vec::IntoIter. --- library/alloc/tests/vec.rs | 25 ++++------------- library/core/src/iter/adapters/flatten.rs | 34 ++--------------------- 2 files changed, 8 insertions(+), 51 deletions(-) diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index 84679827ba1c0..474ea7fe56b8c 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -1204,22 +1204,16 @@ fn test_from_iter_specialization_with_iterator_adapters() { #[test] fn test_in_place_specialization_step_up_down() { fn assert_in_place_trait(_: &T) {} - let src = vec![[0u8; 4]; 256]; + + let src = vec![0u8; 1024]; let srcptr = src.as_ptr(); - let src_cap = src.capacity(); - let iter = src.into_iter().flatten(); + let src_bytes = src.capacity(); + let iter = src.into_iter().array_chunks::<4>(); assert_in_place_trait(&iter); let sink = iter.collect::>(); let sinkptr = sink.as_ptr(); - assert_eq!(srcptr as *const u8, sinkptr); - assert_eq!(src_cap * 4, sink.capacity()); - - let iter = sink.into_iter().array_chunks::<4>(); - assert_in_place_trait(&iter); - let sink = iter.collect::>(); - let sinkptr = sink.as_ptr(); - assert_eq!(srcptr, sinkptr); - assert_eq!(src_cap, sink.capacity()); + assert_eq!(srcptr.addr(), sinkptr.addr()); + assert_eq!(src_bytes, sink.capacity() * 4); let mut src: Vec = Vec::with_capacity(17); let src_bytes = src.capacity(); @@ -1236,13 +1230,6 @@ fn test_in_place_specialization_step_up_down() { let sink: Vec<[u8; 2]> = iter.collect(); assert_eq!(sink.len(), 8); assert!(sink.capacity() <= 25); - - let src = vec![[0u8; 4]; 256]; - let srcptr = src.as_ptr(); - let iter = src.into_iter().flat_map(|a| a.into_iter().map(|b| b.wrapping_add(1))); - assert_in_place_trait(&iter); - let sink = iter.collect::>(); - assert_eq!(srcptr as *const u8, sink.as_ptr()); } #[test] diff --git a/library/core/src/iter/adapters/flatten.rs b/library/core/src/iter/adapters/flatten.rs index 0023b46031f12..9b9353b800a98 100644 --- a/library/core/src/iter/adapters/flatten.rs +++ b/library/core/src/iter/adapters/flatten.rs @@ -1,7 +1,7 @@ use crate::iter::adapters::SourceIter; use crate::iter::{ - Cloned, Copied, Empty, Filter, FilterMap, Fuse, FusedIterator, InPlaceIterable, Map, Once, - OnceWith, TrustedFused, TrustedLen, + Cloned, Copied, Empty, Filter, FilterMap, Fuse, FusedIterator, Map, Once, OnceWith, + TrustedFused, TrustedLen, }; use crate::num::NonZero; use crate::ops::{ControlFlow, Try}; @@ -157,21 +157,6 @@ where { } -#[unstable(issue = "none", feature = "inplace_iteration")] -unsafe impl InPlaceIterable for FlatMap -where - I: InPlaceIterable, - U: BoundedSize + IntoIterator, -{ - const EXPAND_BY: Option> = const { - match (I::EXPAND_BY, U::UPPER_BOUND) { - (Some(m), Some(n)) => m.checked_mul(n), - _ => None, - } - }; - const MERGE_BY: Option> = I::MERGE_BY; -} - #[unstable(issue = "none", feature = "inplace_iteration")] unsafe impl SourceIter for FlatMap where @@ -386,21 +371,6 @@ where { } -#[unstable(issue = "none", feature = "inplace_iteration")] -unsafe impl InPlaceIterable for Flatten -where - I: InPlaceIterable + Iterator, - ::Item: IntoIterator + BoundedSize, -{ - const EXPAND_BY: Option> = const { - match (I::EXPAND_BY, I::Item::UPPER_BOUND) { - (Some(m), Some(n)) => m.checked_mul(n), - _ => None, - } - }; - const MERGE_BY: Option> = I::MERGE_BY; -} - #[unstable(issue = "none", feature = "inplace_iteration")] unsafe impl SourceIter for Flatten where From 1ed0ea459dc5456ebcedb798cc88671014cf0f68 Mon Sep 17 00:00:00 2001 From: The 8472 Date: Sat, 4 Jan 2025 19:44:49 +0100 Subject: [PATCH 6/7] add regression test for unsound Flatten/FlatMap specialization --- library/alloc/tests/vec.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index 474ea7fe56b8c..2e654d3d1ff1e 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -1337,6 +1337,20 @@ fn test_collect_after_iterator_clone() { assert_eq!(v, [1, 1, 1, 1, 1]); assert!(v.len() <= v.capacity()); } + +// regression test for #135103, similar to the one above Flatten/FlatMap had an unsound InPlaceIterable +// implementation. +#[test] +fn test_flatten_clone() { + const S: String = String::new(); + + let v = vec![[S, "Hello World!".into()], [S, S]]; + let mut i = v.into_iter().flatten(); + let _ = i.next(); + let result: Vec = i.clone().collect(); + assert_eq!(result, ["Hello World!", "", ""]); +} + #[test] fn test_cow_from() { let borrowed: &[_] = &["borrowed", "(slice)"]; From e30369fcb4ecef988f90ccbb1e9162c29f3b4542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 5 Jan 2025 01:40:09 +0100 Subject: [PATCH 7/7] library: fix adler{-> 2}.debug Fixes ``` Checking stage0 library artifacts {alloc, core, panic_abort, panic_unwind, proc_macro, std, sysroot, test, unwind} (x86_64-unknown-linux-gnu) warning: profile package spec `adler` in profile `release` did not match any packages Did you mean `adler2`? ``` --- library/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Cargo.toml b/library/Cargo.toml index e744cfe5e0f57..e59aa518804f3 100644 --- a/library/Cargo.toml +++ b/library/Cargo.toml @@ -32,7 +32,7 @@ codegen-units = 10000 [profile.release.package] addr2line.debug = 0 addr2line.opt-level = "s" -adler.debug = 0 +adler2.debug = 0 gimli.debug = 0 gimli.opt-level = "s" miniz_oxide.debug = 0