From 484ac196ebbe729fc3b8b18cf1363df2de9ac98f Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Sun, 8 Sep 2024 20:14:50 +0300 Subject: [PATCH 1/7] make dist vendoring configurable Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/dist.rs | 6 +----- src/bootstrap/src/core/config/config.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index b0bd18792beb2..294a56b3e976a 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -1011,11 +1011,7 @@ impl Step for PlainSourceTarball { write_git_info(builder.rust_info().info(), plain_dst_src); write_git_info(builder.cargo_info.info(), &plain_dst_src.join("./src/tools/cargo")); - // If we're building from git or tarball sources, we need to vendor - // a complete distribution. - if builder.rust_info().is_managed_git_subrepository() - || builder.rust_info().is_from_tarball() - { + if builder.config.dist_vendor { builder.require_and_update_all_submodules(); // Vendor all Cargo dependencies diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index f509712730dee..06c63fafad863 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -308,6 +308,7 @@ pub struct Config { pub dist_compression_formats: Option>, pub dist_compression_profile: String, pub dist_include_mingw_linker: bool, + pub dist_vendor: bool, // libstd features pub backtrace: bool, // support for RUST_BACKTRACE @@ -933,6 +934,7 @@ define_config! { compression_formats: Option> = "compression-formats", compression_profile: Option = "compression-profile", include_mingw_linker: Option = "include-mingw-linker", + vendor: Option = "vendor", } } @@ -2028,13 +2030,19 @@ impl Config { compression_formats, compression_profile, include_mingw_linker, + vendor, } = dist; config.dist_sign_folder = sign_folder.map(PathBuf::from); config.dist_upload_addr = upload_addr; config.dist_compression_formats = compression_formats; set(&mut config.dist_compression_profile, compression_profile); set(&mut config.rust_dist_src, src_tarball); - set(&mut config.dist_include_mingw_linker, include_mingw_linker) + set(&mut config.dist_include_mingw_linker, include_mingw_linker); + config.dist_vendor = vendor.unwrap_or_else(|| { + // If we're building from git or tarball sources, enable it by default. + config.rust_info.is_managed_git_subrepository() + || config.rust_info.is_from_tarball() + }); } if let Some(r) = rustfmt { From 7fff69500ae7c8fa1ba9852310bd42f34d62df9d Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Sun, 8 Sep 2024 20:16:25 +0300 Subject: [PATCH 2/7] document `dist.vendor` in `config.example.toml` Signed-off-by: onur-ozkan --- config.example.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config.example.toml b/config.example.toml index 2b5e9ae117db7..c66d65e639aa0 100644 --- a/config.example.toml +++ b/config.example.toml @@ -942,3 +942,6 @@ # Copy the linker, DLLs, and various libraries from MinGW into the Rust toolchain. # Only applies when the host or target is pc-windows-gnu. #include-mingw-linker = true + +# Whether to vendor dependencies for the dist tarball. +#vendor = if "is a tarball source" || "is a git repository" { true } else { false } From 7e0fb6e4d741303daaee8d5879199053fbffdb60 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Tue, 10 Sep 2024 19:18:39 +0300 Subject: [PATCH 3/7] add change entry for `dist.vendor` Signed-off-by: onur-ozkan --- src/bootstrap/src/utils/change_tracker.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs index 99bcc6e0787ff..1b357f77984d1 100644 --- a/src/bootstrap/src/utils/change_tracker.rs +++ b/src/bootstrap/src/utils/change_tracker.rs @@ -255,4 +255,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[ severity: ChangeSeverity::Warning, summary: "`download-ci-llvm = true` now checks if CI llvm is available and has become the default for the compiler profile", }, + ChangeInfo { + change_id: 130110, + severity: ChangeSeverity::Info, + summary: "New option `dist.vendor` added to control whether bootstrap should vendor dependencies for dist tarball.", + }, ]; From 914ccea9f193984601002a074ae2017992524aca Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Fri, 13 Sep 2024 13:36:32 -0700 Subject: [PATCH 4/7] Use -0.0 in `intrinsics::simd::reduce_add_unordered` -0.0 is the actual neutral additive float, not +0.0, and this matters to codegen. --- compiler/rustc_codegen_llvm/src/intrinsic.rs | 4 +-- tests/assembly/simd/reduce-fadd-unordered.rs | 36 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 tests/assembly/simd/reduce-fadd-unordered.rs diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index 05fb77a193af3..b79bfd8a1cdef 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -2090,14 +2090,14 @@ fn generic_simd_intrinsic<'ll, 'tcx>( }; } - arith_red!(simd_reduce_add_ordered: vector_reduce_add, vector_reduce_fadd, true, add, 0.0); + arith_red!(simd_reduce_add_ordered: vector_reduce_add, vector_reduce_fadd, true, add, -0.0); arith_red!(simd_reduce_mul_ordered: vector_reduce_mul, vector_reduce_fmul, true, mul, 1.0); arith_red!( simd_reduce_add_unordered: vector_reduce_add, vector_reduce_fadd_reassoc, false, add, - 0.0 + -0.0 ); arith_red!( simd_reduce_mul_unordered: vector_reduce_mul, diff --git a/tests/assembly/simd/reduce-fadd-unordered.rs b/tests/assembly/simd/reduce-fadd-unordered.rs new file mode 100644 index 0000000000000..25e9ad7dc57c4 --- /dev/null +++ b/tests/assembly/simd/reduce-fadd-unordered.rs @@ -0,0 +1,36 @@ +//@ revisions: x86_64 x86_64-avx2 aarch64 +//@ assembly-output: emit-asm +//@ compile-flags: --crate-type=lib -O +//@[aarch64] only-aarch64 +//@[x86_64] only-x86_64 +//@[x86_64-avx2] only-x86_64 +//@[x86_64-avx2] compile-flags: -Ctarget-cpu=x86-64-v3 +#![feature(portable_simd)] +#![feature(core_intrinsics)] +use std::intrinsics::simd as intrinsics; +use std::simd::*; +// Regression test for https://github.com/rust-lang/rust/issues/130028 +// This intrinsic produces much worse code if you use +0.0 instead of -0.0 because +// +0.0 isn't as easy to algebraically reassociate, even using LLVM's reassoc attribute! +// It would emit about an extra fadd, depending on the architecture. + +// CHECK-LABEL: reduce_fadd_negative_zero +pub unsafe fn reduce_fadd_negative_zero(v: f32x4) -> f32 { + // x86_64: addps + // x86_64-NEXT: movaps + // x86_64-NEXT: shufps + // x86_64-NEXT: addss + // x86_64-NOT: xorps + + // x86_64-avx2: vaddps + // x86_64-avx2-NEXT: vmovshdup + // x86_64-avx2-NEXT: vaddss + // x86_64-avx2-NOT: vxorps + + // aarch64: faddp + // aarch64-NEXT: faddp + + // CHECK-NOT: {{f?}}add{{p?s*}} + // CHECK: ret + intrinsics::simd_reduce_add_unordered(v) +} From c547f51de10ad5e1d45a8b075c9000b1ecf6d5fa Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Sat, 14 Sep 2024 17:30:07 -0400 Subject: [PATCH 5/7] Add a test --- tests/ui/transmutability/enums/niche_optimization.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/ui/transmutability/enums/niche_optimization.rs b/tests/ui/transmutability/enums/niche_optimization.rs index 802d174756868..acb1856d0825a 100644 --- a/tests/ui/transmutability/enums/niche_optimization.rs +++ b/tests/ui/transmutability/enums/niche_optimization.rs @@ -154,3 +154,12 @@ fn no_niche() { assert::is_transmutable::>, OptionLike>(); assert::is_transmutable::>, OptionLike>(); } + +fn niche_fields() { + enum Kind { + A(bool, bool), + B(bool), + } + + assert::is_transmutable::(); +} From 2ac554b73a21c4af8949eac9910f98c74c92cbd5 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Sat, 14 Sep 2024 17:52:03 -0400 Subject: [PATCH 6/7] Correctly account for niche-optimized tags --- compiler/rustc_transmute/src/layout/tree.rs | 35 +++++++++++++------ tests/crashes/123693.rs | 22 ------------ .../enums/niche_optimization.rs | 2 +- 3 files changed, 26 insertions(+), 33 deletions(-) delete mode 100644 tests/crashes/123693.rs diff --git a/compiler/rustc_transmute/src/layout/tree.rs b/compiler/rustc_transmute/src/layout/tree.rs index c3fd771b79734..b5ce465a1739f 100644 --- a/compiler/rustc_transmute/src/layout/tree.rs +++ b/compiler/rustc_transmute/src/layout/tree.rs @@ -175,7 +175,7 @@ pub(crate) mod rustc { use rustc_middle::ty::{self, AdtDef, AdtKind, List, ScalarInt, Ty, TyCtxt, TypeVisitableExt}; use rustc_span::ErrorGuaranteed; use rustc_target::abi::{ - FieldIdx, FieldsShape, Layout, Size, TyAndLayout, VariantIdx, Variants, + FieldIdx, FieldsShape, Layout, Size, TagEncoding, TyAndLayout, VariantIdx, Variants, }; use super::Tree; @@ -319,11 +319,17 @@ pub(crate) mod rustc { assert!(def.is_enum()); // Computes the variant of a given index. - let layout_of_variant = |index| { + let layout_of_variant = |index, encoding: Option>| { let tag = cx.tcx.tag_for_variant((cx.tcx.erase_regions(ty), index)); let variant_def = Def::Variant(def.variant(index)); let variant_layout = ty_variant(cx, (ty, layout), index); - Self::from_variant(variant_def, tag, (ty, variant_layout), layout.size, cx) + Self::from_variant( + variant_def, + tag.map(|tag| (tag, index, encoding.unwrap())), + (ty, variant_layout), + layout.size, + cx, + ) }; // We consider three kinds of enums, each demanding a different @@ -345,9 +351,9 @@ pub(crate) mod rustc { Variants::Single { index } => { // `Variants::Single` on enums with variants denotes that // the enum delegates its layout to the variant at `index`. - layout_of_variant(*index) + layout_of_variant(*index, None) } - Variants::Multiple { tag_field, .. } => { + Variants::Multiple { tag, tag_encoding, tag_field, .. } => { // `Variants::Multiple` denotes an enum with multiple // variants. The layout of such an enum is the disjunction // of the layouts of its tagged variants. @@ -359,7 +365,7 @@ pub(crate) mod rustc { let variants = def.discriminants(cx.tcx()).try_fold( Self::uninhabited(), |variants, (idx, ref discriminant)| { - let variant = layout_of_variant(idx)?; + let variant = layout_of_variant(idx, Some(tag_encoding.clone()))?; Result::::Ok(variants.or(variant)) }, )?; @@ -380,7 +386,7 @@ pub(crate) mod rustc { /// `0`. fn from_variant( def: Def<'tcx>, - tag: Option, + tag: Option<(ScalarInt, VariantIdx, TagEncoding)>, (ty, layout): (Ty<'tcx>, Layout<'tcx>), total_size: Size, cx: LayoutCx<'tcx, TyCtxt<'tcx>>, @@ -400,9 +406,18 @@ pub(crate) mod rustc { let mut struct_tree = Self::def(def); // If a `tag` is provided, place it at the start of the layout. - if let Some(tag) = tag { - size += tag.size(); - struct_tree = struct_tree.then(Self::from_tag(tag, cx.tcx)); + if let Some((tag, index, encoding)) = &tag { + match encoding { + TagEncoding::Direct => { + size += tag.size(); + } + TagEncoding::Niche { niche_variants, .. } => { + if !niche_variants.contains(index) { + size += tag.size(); + } + } + } + struct_tree = struct_tree.then(Self::from_tag(*tag, cx.tcx)); } // Append the fields, in memory order, to the layout. diff --git a/tests/crashes/123693.rs b/tests/crashes/123693.rs deleted file mode 100644 index c3236322c6e2a..0000000000000 --- a/tests/crashes/123693.rs +++ /dev/null @@ -1,22 +0,0 @@ -//@ known-bug: #123693 - -#![feature(transmutability)] - -mod assert { - use std::mem::{Assume, TransmuteFrom}; - - pub fn is_transmutable() - where - Dst: TransmuteFrom, - { - } -} - -enum Lopsided { - Smol(()), - Lorg(bool), -} - -fn should_pad_variants() { - assert::is_transmutable::(); -} diff --git a/tests/ui/transmutability/enums/niche_optimization.rs b/tests/ui/transmutability/enums/niche_optimization.rs index acb1856d0825a..2436be500279f 100644 --- a/tests/ui/transmutability/enums/niche_optimization.rs +++ b/tests/ui/transmutability/enums/niche_optimization.rs @@ -161,5 +161,5 @@ fn niche_fields() { B(bool), } - assert::is_transmutable::(); + assert::is_maybe_transmutable::(); } From 1a0ba0117794bb80e540bb449c4109b8f20060c1 Mon Sep 17 00:00:00 2001 From: Chris Copeland Date: Thu, 12 Sep 2024 23:41:39 -0700 Subject: [PATCH 7/7] Fix target-cpu fpu features on Armv8-R. This is a follow-up to #123159, but applied to Armv8-R. This required https://github.com/llvm/llvm-project/pull/88287 to work properly. Now that this change exists in rustc's llvm, we can fix Armv8-R's default fpu features. In Armv8-R's case, the default features from LLVM for floating-point are sufficient, because there is no integer-only variant of this architecture. --- .../src/spec/targets/armv8r_none_eabihf.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_target/src/spec/targets/armv8r_none_eabihf.rs b/compiler/rustc_target/src/spec/targets/armv8r_none_eabihf.rs index 042a9a140710c..762084291a696 100644 --- a/compiler/rustc_target/src/spec/targets/armv8r_none_eabihf.rs +++ b/compiler/rustc_target/src/spec/targets/armv8r_none_eabihf.rs @@ -21,16 +21,16 @@ pub(crate) fn target() -> Target { linker: Some("rust-lld".into()), relocation_model: RelocModel::Static, panic_strategy: PanicStrategy::Abort, - // The Cortex-R52 has two variants with respect to floating-point support: - // 1. fp-armv8, SP-only, with 16 DP (32 SP) registers - // 2. neon-fp-armv8, SP+DP, with 32 DP registers - // Use the lesser of these two options as the default, as it will produce code - // compatible with either variant. + // Armv8-R requires a minimum set of floating-point features equivalent to: + // fp-armv8, SP-only, with 16 DP (32 SP) registers + // LLVM defines Armv8-R to include these features automatically. + // + // The Cortex-R52 supports these default features and optionally includes: + // neon-fp-armv8, SP+DP, with 32 DP registers // // Reference: // Arm Cortex-R52 Processor Technical Reference Manual // - Chapter 15 Advanced SIMD and floating-point support - features: "+fp-armv8,-fp64,-d32".into(), max_atomic_width: Some(64), emit_debug_gdb_scripts: false, // GCC defaults to 8 for arm-none here.