diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 024624cd3bb87..71ec1c5042fda 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -120,8 +120,8 @@ impl PartialEq<&[Symbol]> for Path { } } -impl HashStable for Path { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { +impl HashStable for Path { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.segments.len().hash_stable(hcx, hasher); for segment in &self.segments { segment.ident.hash_stable(hcx, hasher); diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index 8d8e8ffc562f8..8953391ac58bf 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -138,8 +138,8 @@ impl Decodable for LazyAttrTokenStream { } } -impl HashStable for LazyAttrTokenStream { - fn hash_stable(&self, _hcx: &mut CTX, _hasher: &mut StableHasher) { +impl HashStable for LazyAttrTokenStream { + fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) { panic!("Attempted to compute stable hash for LazyAttrTokenStream"); } } @@ -824,11 +824,11 @@ impl FromIterator for TokenStream { } } -impl HashStable for TokenStream +impl HashStable for TokenStream where - CTX: crate::HashStableContext, + Hcx: crate::HashStableContext, { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { for sub_tt in self.iter() { sub_tt.hash_stable(hcx, hasher); } diff --git a/compiler/rustc_codegen_cranelift/src/driver/aot.rs b/compiler/rustc_codegen_cranelift/src/driver/aot.rs index 79a3214568082..b855e1fa4b780 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/aot.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/aot.rs @@ -45,8 +45,8 @@ enum OngoingModuleCodegen { Async(JoinHandle>), } -impl HashStable for OngoingModuleCodegen { - fn hash_stable(&self, _: &mut HCX, _: &mut StableHasher) { +impl HashStable for OngoingModuleCodegen { + fn hash_stable(&self, _: &mut Hcx, _: &mut StableHasher) { // do nothing } } diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index f300ee5d4c991..1f59d250e08a0 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -3,16 +3,17 @@ use rustc_hir::attrs::{InlineAttr, InstructionSetAttr, OptimizeAttr, RtsanSettin use rustc_hir::def_id::DefId; use rustc_hir::find_attr; use rustc_middle::middle::codegen_fn_attrs::{ - CodegenFnAttrFlags, CodegenFnAttrs, PatchableFunctionEntry, SanitizerFnAttrs, + CodegenFnAttrFlags, CodegenFnAttrs, PatchableFunctionEntry, SanitizerFnAttrs, TargetFeature, }; use rustc_middle::ty::{self, TyCtxt}; use rustc_session::config::{BranchProtection, FunctionReturn, OptLevel, PAuthKey, PacRet}; +use rustc_span::sym; use rustc_symbol_mangling::mangle_internal_symbol; use rustc_target::spec::{Arch, FramePointer, SanitizerSet, StackProbeType, StackProtector}; use smallvec::SmallVec; use crate::context::SimpleCx; -use crate::errors::SanitizerMemtagRequiresMte; +use crate::errors::{PackedStackBackchainNeedsSoftfloat, SanitizerMemtagRequiresMte}; use crate::llvm::AttributePlace::Function; use crate::llvm::{ self, AllocKindFlags, Attribute, AttributeKind, AttributePlace, MemoryEffects, Value, @@ -302,6 +303,36 @@ fn stackprotector_attr<'ll>(cx: &SimpleCx<'ll>, sess: &Session) -> Option<&'ll A Some(sspattr.create_attr(cx.llcx)) } +fn packed_stack_attr<'ll>( + cx: &SimpleCx<'ll>, + sess: &Session, + function_attributes: &Vec, +) -> Option<&'ll Attribute> { + if sess.target.arch != Arch::S390x { + return None; + } + if !sess.opts.unstable_opts.packed_stack { + return None; + } + + // The backchain and softfloat flags can be set via -Ctarget-features=... + // or via #[target_features(enable = ...)] so we have to check both possibilities + let have_backchain = sess.unstable_target_features.contains(&sym::backchain) + || function_attributes.iter().any(|feature| feature.name == sym::backchain); + let have_softfloat = sess.unstable_target_features.contains(&sym::soft_float) + || function_attributes.iter().any(|feature| feature.name == sym::soft_float); + + // If both, backchain and packedstack, are enabled LLVM cannot generate valid function entry points + // with the default ABI. However if the softfloat flag is set LLVM will switch to the softfloat + // ABI, where this works. + if have_backchain && !have_softfloat { + sess.dcx().emit_err(PackedStackBackchainNeedsSoftfloat); + return None; + } + + Some(llvm::CreateAttrString(cx.llcx, "packed-stack")) +} + pub(crate) fn target_cpu_attr<'ll>(cx: &SimpleCx<'ll>, sess: &Session) -> &'ll Attribute { let target_cpu = llvm_util::target_cpu(sess); llvm::CreateAttrStringValue(cx.llcx, "target-cpu", target_cpu) @@ -517,6 +548,9 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>( if let Some(align) = codegen_fn_attrs.alignment { llvm::set_alignment(llfn, align); } + if let Some(packed_stack) = packed_stack_attr(cx, sess, &codegen_fn_attrs.target_features) { + to_add.push(packed_stack); + } to_add.extend(patchable_function_entry_attrs( cx, sess, diff --git a/compiler/rustc_codegen_llvm/src/errors.rs b/compiler/rustc_codegen_llvm/src/errors.rs index 880abb3fbc248..caec20db4c2db 100644 --- a/compiler/rustc_codegen_llvm/src/errors.rs +++ b/compiler/rustc_codegen_llvm/src/errors.rs @@ -204,3 +204,10 @@ pub(crate) struct MismatchedDataLayout<'a> { pub(crate) struct FixedX18InvalidArch<'a> { pub arch: &'a str, } + +#[derive(Diagnostic)] +#[diag("`-Zpacked-stack` is incompatible with `backchain` target feature")] +#[note( + "enabling both `-Zpacked-stack` and the `backchain` target feature is incompatible with the default s390x ABI. Switch to s390x-unknown-none-softfloat if you need both attributes" +)] +pub(crate) struct PackedStackBackchainNeedsSoftfloat; diff --git a/compiler/rustc_codegen_ssa/src/common.rs b/compiler/rustc_codegen_ssa/src/common.rs index fe4d1da4329d8..de79acd165f0f 100644 --- a/compiler/rustc_codegen_ssa/src/common.rs +++ b/compiler/rustc_codegen_ssa/src/common.rs @@ -102,8 +102,8 @@ mod temp_stable_hash_impls { use crate::ModuleCodegen; - impl HashStable for ModuleCodegen { - fn hash_stable(&self, _: &mut HCX, _: &mut StableHasher) { + impl HashStable for ModuleCodegen { + fn hash_stable(&self, _: &mut Hcx, _: &mut StableHasher) { // do nothing } } diff --git a/compiler/rustc_data_structures/src/intern.rs b/compiler/rustc_data_structures/src/intern.rs index 8079212fac551..e196ff0941594 100644 --- a/compiler/rustc_data_structures/src/intern.rs +++ b/compiler/rustc_data_structures/src/intern.rs @@ -103,11 +103,11 @@ where } } -impl HashStable for Interned<'_, T> +impl HashStable for Interned<'_, T> where - T: HashStable, + T: HashStable, { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.0.hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_data_structures/src/packed.rs b/compiler/rustc_data_structures/src/packed.rs index c8921536530a2..eef25331987da 100644 --- a/compiler/rustc_data_structures/src/packed.rs +++ b/compiler/rustc_data_structures/src/packed.rs @@ -60,10 +60,10 @@ impl fmt::UpperHex for Pu128 { } } -impl HashStable for Pu128 { +impl HashStable for Pu128 { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - { self.0 }.hash_stable(ctx, hasher) + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + { self.0 }.hash_stable(hcx, hasher) } } diff --git a/compiler/rustc_data_structures/src/sorted_map.rs b/compiler/rustc_data_structures/src/sorted_map.rs index 15e3e6ea4c329..49c5272bd8568 100644 --- a/compiler/rustc_data_structures/src/sorted_map.rs +++ b/compiler/rustc_data_structures/src/sorted_map.rs @@ -347,10 +347,10 @@ impl FromIterator<(K, V)> for SortedMap { } } -impl + StableOrd, V: HashStable, CTX> HashStable for SortedMap { +impl + StableOrd, V: HashStable, Hcx> HashStable for SortedMap { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - self.data.hash_stable(ctx, hasher); + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + self.data.hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_data_structures/src/stable_hasher.rs b/compiler/rustc_data_structures/src/stable_hasher.rs index f8e72d66d07ef..c9993d106d6d3 100644 --- a/compiler/rustc_data_structures/src/stable_hasher.rs +++ b/compiler/rustc_data_structures/src/stable_hasher.rs @@ -15,7 +15,7 @@ pub use rustc_stable_hash::{ FromStableHash, SipHasher128Hash as StableHasherHash, StableSipHasher128 as StableHasher, }; -/// Something that implements `HashStable` can be hashed in a way that is +/// Something that implements `HashStable` can be hashed in a way that is /// stable across multiple compilation sessions. /// /// Note that `HashStable` imposes rather more strict requirements than usual @@ -41,16 +41,16 @@ pub use rustc_stable_hash::{ /// - `hash_stable()` must be independent of the host architecture. The /// `StableHasher` takes care of endianness and `isize`/`usize` platform /// differences. -pub trait HashStable { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher); +pub trait HashStable { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher); } /// Implement this for types that can be turned into stable keys like, for /// example, for DefId that can be converted to a DefPathHash. This is used for /// bringing maps into a predictable order before hashing them. -pub trait ToStableHashKey { - type KeyType: Ord + Sized + HashStable; - fn to_stable_hash_key(&self, hcx: &HCX) -> Self::KeyType; +pub trait ToStableHashKey { + type KeyType: Ord + Sized + HashStable; + fn to_stable_hash_key(&self, hcx: &Hcx) -> Self::KeyType; } /// Trait for marking a type as having a sort order that is @@ -136,9 +136,9 @@ impl StableCompare for T { /// Use `#[derive(HashStable_Generic)]` instead. macro_rules! impl_stable_traits_for_trivial_type { ($t:ty) => { - impl $crate::stable_hasher::HashStable for $t { + impl $crate::stable_hasher::HashStable for $t { #[inline] - fn hash_stable(&self, _: &mut CTX, hasher: &mut $crate::stable_hasher::StableHasher) { + fn hash_stable(&self, _: &mut Hcx, hasher: &mut $crate::stable_hasher::StableHasher) { ::std::hash::Hash::hash(self, hasher); } } @@ -177,9 +177,9 @@ impl_stable_traits_for_trivial_type!(Hash64); // We need a custom impl as the default hash function will only hash half the bits. For stable // hashing we want to hash the full 128-bit hash. -impl HashStable for Hash128 { +impl HashStable for Hash128 { #[inline] - fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, _: &mut Hcx, hasher: &mut StableHasher) { self.as_u128().hash(hasher); } } @@ -192,64 +192,64 @@ impl StableOrd for Hash128 { const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = (); } -impl HashStable for ! { - fn hash_stable(&self, _ctx: &mut CTX, _hasher: &mut StableHasher) { +impl HashStable for ! { + fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) { unreachable!() } } -impl HashStable for PhantomData { - fn hash_stable(&self, _ctx: &mut CTX, _hasher: &mut StableHasher) {} +impl HashStable for PhantomData { + fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) {} } -impl HashStable for NonZero { +impl HashStable for NonZero { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - self.get().hash_stable(ctx, hasher) + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + self.get().hash_stable(hcx, hasher) } } -impl HashStable for NonZero { +impl HashStable for NonZero { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - self.get().hash_stable(ctx, hasher) + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + self.get().hash_stable(hcx, hasher) } } -impl HashStable for f32 { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { +impl HashStable for f32 { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { let val: u32 = self.to_bits(); - val.hash_stable(ctx, hasher); + val.hash_stable(hcx, hasher); } } -impl HashStable for f64 { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { +impl HashStable for f64 { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { let val: u64 = self.to_bits(); - val.hash_stable(ctx, hasher); + val.hash_stable(hcx, hasher); } } -impl HashStable for ::std::cmp::Ordering { +impl HashStable for ::std::cmp::Ordering { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - (*self as i8).hash_stable(ctx, hasher); + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + (*self as i8).hash_stable(hcx, hasher); } } -impl, CTX> HashStable for (T1,) { +impl, Hcx> HashStable for (T1,) { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { let (ref _0,) = *self; - _0.hash_stable(ctx, hasher); + _0.hash_stable(hcx, hasher); } } -impl, T2: HashStable, CTX> HashStable for (T1, T2) { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { +impl, T2: HashStable, Hcx> HashStable for (T1, T2) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { let (ref _0, ref _1) = *self; - _0.hash_stable(ctx, hasher); - _1.hash_stable(ctx, hasher); + _0.hash_stable(hcx, hasher); + _1.hash_stable(hcx, hasher); } } @@ -261,17 +261,17 @@ impl StableOrd for (T1, T2) { const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = (); } -impl HashStable for (T1, T2, T3) +impl HashStable for (T1, T2, T3) where - T1: HashStable, - T2: HashStable, - T3: HashStable, + T1: HashStable, + T2: HashStable, + T3: HashStable, { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { let (ref _0, ref _1, ref _2) = *self; - _0.hash_stable(ctx, hasher); - _1.hash_stable(ctx, hasher); - _2.hash_stable(ctx, hasher); + _0.hash_stable(hcx, hasher); + _1.hash_stable(hcx, hasher); + _2.hash_stable(hcx, hasher); } } @@ -284,19 +284,19 @@ impl StableOrd for (T1, T2, T3) { const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = (); } -impl HashStable for (T1, T2, T3, T4) +impl HashStable for (T1, T2, T3, T4) where - T1: HashStable, - T2: HashStable, - T3: HashStable, - T4: HashStable, + T1: HashStable, + T2: HashStable, + T3: HashStable, + T4: HashStable, { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { let (ref _0, ref _1, ref _2, ref _3) = *self; - _0.hash_stable(ctx, hasher); - _1.hash_stable(ctx, hasher); - _2.hash_stable(ctx, hasher); - _3.hash_stable(ctx, hasher); + _0.hash_stable(hcx, hasher); + _1.hash_stable(hcx, hasher); + _2.hash_stable(hcx, hasher); + _3.hash_stable(hcx, hasher); } } @@ -311,93 +311,93 @@ impl StableOrd for ( const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = (); } -impl, CTX> HashStable for [T] { - default fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - self.len().hash_stable(ctx, hasher); +impl, Hcx> HashStable for [T] { + default fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + self.len().hash_stable(hcx, hasher); for item in self { - item.hash_stable(ctx, hasher); + item.hash_stable(hcx, hasher); } } } -impl HashStable for [u8] { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - self.len().hash_stable(ctx, hasher); +impl HashStable for [u8] { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + self.len().hash_stable(hcx, hasher); hasher.write(self); } } -impl, CTX> HashStable for Vec { +impl, Hcx> HashStable for Vec { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - self[..].hash_stable(ctx, hasher); + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + self[..].hash_stable(hcx, hasher); } } -impl HashStable for indexmap::IndexMap +impl HashStable for indexmap::IndexMap where - K: HashStable + Eq + Hash, - V: HashStable, + K: HashStable + Eq + Hash, + V: HashStable, R: BuildHasher, { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - self.len().hash_stable(ctx, hasher); + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + self.len().hash_stable(hcx, hasher); for kv in self { - kv.hash_stable(ctx, hasher); + kv.hash_stable(hcx, hasher); } } } -impl HashStable for indexmap::IndexSet +impl HashStable for indexmap::IndexSet where - K: HashStable + Eq + Hash, + K: HashStable + Eq + Hash, R: BuildHasher, { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - self.len().hash_stable(ctx, hasher); + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + self.len().hash_stable(hcx, hasher); for key in self { - key.hash_stable(ctx, hasher); + key.hash_stable(hcx, hasher); } } } -impl HashStable for SmallVec<[A; N]> +impl HashStable for SmallVec<[A; N]> where - A: HashStable, + A: HashStable, { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - self[..].hash_stable(ctx, hasher); + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + self[..].hash_stable(hcx, hasher); } } -impl, CTX> HashStable for Box { +impl, Hcx> HashStable for Box { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - (**self).hash_stable(ctx, hasher); + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + (**self).hash_stable(hcx, hasher); } } -impl, CTX> HashStable for ::std::rc::Rc { +impl, Hcx> HashStable for ::std::rc::Rc { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - (**self).hash_stable(ctx, hasher); + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + (**self).hash_stable(hcx, hasher); } } -impl, CTX> HashStable for ::std::sync::Arc { +impl, Hcx> HashStable for ::std::sync::Arc { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - (**self).hash_stable(ctx, hasher); + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + (**self).hash_stable(hcx, hasher); } } -impl HashStable for str { +impl HashStable for str { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - self.as_bytes().hash_stable(ctx, hasher); + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + self.as_bytes().hash_stable(hcx, hasher); } } @@ -409,9 +409,9 @@ impl StableOrd for &str { const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = (); } -impl HashStable for String { +impl HashStable for String { #[inline] - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self[..].hash_stable(hcx, hasher); } } @@ -424,26 +424,26 @@ impl StableOrd for String { const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = (); } -impl ToStableHashKey for String { +impl ToStableHashKey for String { type KeyType = String; #[inline] - fn to_stable_hash_key(&self, _: &HCX) -> Self::KeyType { + fn to_stable_hash_key(&self, _: &Hcx) -> Self::KeyType { self.clone() } } -impl, T2: ToStableHashKey> ToStableHashKey for (T1, T2) { +impl, T2: ToStableHashKey> ToStableHashKey for (T1, T2) { type KeyType = (T1::KeyType, T2::KeyType); #[inline] - fn to_stable_hash_key(&self, hcx: &HCX) -> Self::KeyType { + fn to_stable_hash_key(&self, hcx: &Hcx) -> Self::KeyType { (self.0.to_stable_hash_key(hcx), self.1.to_stable_hash_key(hcx)) } } -impl HashStable for bool { +impl HashStable for bool { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - (if *self { 1u8 } else { 0u8 }).hash_stable(ctx, hasher); + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + (if *self { 1u8 } else { 0u8 }).hash_stable(hcx, hasher); } } @@ -454,17 +454,17 @@ impl StableOrd for bool { const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = (); } -impl HashStable for Option +impl HashStable for Option where - T: HashStable, + T: HashStable, { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { if let Some(ref value) = *self { - 1u8.hash_stable(ctx, hasher); - value.hash_stable(ctx, hasher); + 1u8.hash_stable(hcx, hasher); + value.hash_stable(hcx, hasher); } else { - 0u8.hash_stable(ctx, hasher); + 0u8.hash_stable(hcx, hasher); } } } @@ -476,81 +476,81 @@ impl StableOrd for Option { const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = (); } -impl HashStable for Result +impl HashStable for Result where - T1: HashStable, - T2: HashStable, + T1: HashStable, + T2: HashStable, { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(ctx, hasher); + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + mem::discriminant(self).hash_stable(hcx, hasher); match *self { - Ok(ref x) => x.hash_stable(ctx, hasher), - Err(ref x) => x.hash_stable(ctx, hasher), + Ok(ref x) => x.hash_stable(hcx, hasher), + Err(ref x) => x.hash_stable(hcx, hasher), } } } -impl<'a, T, CTX> HashStable for &'a T +impl<'a, T, Hcx> HashStable for &'a T where - T: HashStable + ?Sized, + T: HashStable + ?Sized, { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - (**self).hash_stable(ctx, hasher); + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + (**self).hash_stable(hcx, hasher); } } -impl HashStable for ::std::mem::Discriminant { +impl HashStable for ::std::mem::Discriminant { #[inline] - fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, _: &mut Hcx, hasher: &mut StableHasher) { ::std::hash::Hash::hash(self, hasher); } } -impl HashStable for ::std::ops::RangeInclusive +impl HashStable for ::std::ops::RangeInclusive where - T: HashStable, + T: HashStable, { #[inline] - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - self.start().hash_stable(ctx, hasher); - self.end().hash_stable(ctx, hasher); + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + self.start().hash_stable(hcx, hasher); + self.end().hash_stable(hcx, hasher); } } -impl HashStable for IndexSlice +impl HashStable for IndexSlice where - T: HashStable, + T: HashStable, { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - self.len().hash_stable(ctx, hasher); + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + self.len().hash_stable(hcx, hasher); for v in &self.raw { - v.hash_stable(ctx, hasher); + v.hash_stable(hcx, hasher); } } } -impl HashStable for IndexVec +impl HashStable for IndexVec where - T: HashStable, + T: HashStable, { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - self.len().hash_stable(ctx, hasher); + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + self.len().hash_stable(hcx, hasher); for v in &self.raw { - v.hash_stable(ctx, hasher); + v.hash_stable(hcx, hasher); } } } -impl HashStable for DenseBitSet { - fn hash_stable(&self, _ctx: &mut CTX, hasher: &mut StableHasher) { +impl HashStable for DenseBitSet { + fn hash_stable(&self, _hcx: &mut Hcx, hasher: &mut StableHasher) { ::std::hash::Hash::hash(self, hasher); } } -impl HashStable for bit_set::BitMatrix { - fn hash_stable(&self, _ctx: &mut CTX, hasher: &mut StableHasher) { +impl HashStable for bit_set::BitMatrix { + fn hash_stable(&self, _hcx: &mut Hcx, hasher: &mut StableHasher) { ::std::hash::Hash::hash(self, hasher); } } @@ -563,15 +563,15 @@ impl_stable_traits_for_trivial_type!(::std::path::PathBuf); // It is not safe to implement HashStable for HashSet, HashMap or any other collection type // with unstable but observable iteration order. // See https://github.com/rust-lang/compiler-team/issues/533 for further information. -impl !HashStable for std::collections::HashSet {} -impl !HashStable for std::collections::HashMap {} +impl !HashStable for std::collections::HashSet {} +impl !HashStable for std::collections::HashMap {} -impl HashStable for ::std::collections::BTreeMap +impl HashStable for ::std::collections::BTreeMap where - K: HashStable + StableOrd, - V: HashStable, + K: HashStable + StableOrd, + V: HashStable, { - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.len().hash_stable(hcx, hasher); for entry in self.iter() { entry.hash_stable(hcx, hasher); @@ -579,11 +579,11 @@ where } } -impl HashStable for ::std::collections::BTreeSet +impl HashStable for ::std::collections::BTreeSet where - K: HashStable + StableOrd, + K: HashStable + StableOrd, { - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.len().hash_stable(hcx, hasher); for entry in self.iter() { entry.hash_stable(hcx, hasher); diff --git a/compiler/rustc_data_structures/src/stable_hasher/tests.rs b/compiler/rustc_data_structures/src/stable_hasher/tests.rs index 635f241847c43..55a666d2d0fc2 100644 --- a/compiler/rustc_data_structures/src/stable_hasher/tests.rs +++ b/compiler/rustc_data_structures/src/stable_hasher/tests.rs @@ -44,8 +44,8 @@ fn test_attribute_permutation() { b: $ty, } - impl HashStable for Foo { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + impl HashStable for Foo { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.a.hash_stable(hcx, hasher); self.b.hash_stable(hcx, hasher); } diff --git a/compiler/rustc_data_structures/src/steal.rs b/compiler/rustc_data_structures/src/steal.rs index afa9bc36f2c5e..184acfe8ca1a6 100644 --- a/compiler/rustc_data_structures/src/steal.rs +++ b/compiler/rustc_data_structures/src/steal.rs @@ -71,8 +71,8 @@ impl Steal { } } -impl> HashStable for Steal { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { +impl> HashStable for Steal { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.borrow().hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_data_structures/src/tagged_ptr.rs b/compiler/rustc_data_structures/src/tagged_ptr.rs index 71e5e0b412e8a..32f8138110895 100644 --- a/compiler/rustc_data_structures/src/tagged_ptr.rs +++ b/compiler/rustc_data_structures/src/tagged_ptr.rs @@ -262,12 +262,12 @@ impl Hash for TaggedRef<'_, P, T> { } } -impl<'a, P, T, HCX> HashStable for TaggedRef<'a, P, T> +impl<'a, P, T, Hcx> HashStable for TaggedRef<'a, P, T> where - P: HashStable + Aligned + ?Sized, - T: Tag + HashStable, + P: HashStable + Aligned + ?Sized, + T: Tag + HashStable, { - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.pointer().hash_stable(hcx, hasher); self.tag().hash_stable(hcx, hasher); } diff --git a/compiler/rustc_data_structures/src/tagged_ptr/tests.rs b/compiler/rustc_data_structures/src/tagged_ptr/tests.rs index 85b21a7c8ecdf..e663df5105f95 100644 --- a/compiler/rustc_data_structures/src/tagged_ptr/tests.rs +++ b/compiler/rustc_data_structures/src/tagged_ptr/tests.rs @@ -32,8 +32,8 @@ unsafe impl Tag for Tag2 { } } -impl crate::stable_hasher::HashStable for Tag2 { - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut crate::stable_hasher::StableHasher) { +impl crate::stable_hasher::HashStable for Tag2 { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut crate::stable_hasher::StableHasher) { (*self as u8).hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_data_structures/src/unord.rs b/compiler/rustc_data_structures/src/unord.rs index eb29ef3b4d0a5..8a3b3e2e98cd5 100644 --- a/compiler/rustc_data_structures/src/unord.rs +++ b/compiler/rustc_data_structures/src/unord.rs @@ -143,9 +143,9 @@ impl<'a, T: Copy + 'a, I: Iterator> UnordItems<&'a T, I> { impl> UnordItems { #[inline] - pub fn into_sorted(self, hcx: &HCX) -> Vec + pub fn into_sorted(self, hcx: &Hcx) -> Vec where - T: ToStableHashKey, + T: ToStableHashKey, { self.collect_sorted(hcx, true) } @@ -168,9 +168,9 @@ impl> UnordItems { } #[inline] - pub fn collect_sorted(self, hcx: &HCX, cache_sort_key: bool) -> C + pub fn collect_sorted(self, hcx: &Hcx, cache_sort_key: bool) -> C where - T: ToStableHashKey, + T: ToStableHashKey, C: FromIterator + BorrowMut<[T]>, { let mut items: C = self.0.collect(); @@ -315,9 +315,9 @@ impl UnordSet { /// `cache_sort_key` when the [ToStableHashKey::to_stable_hash_key] implementation /// for `V` is expensive (e.g. a `DefId -> DefPathHash` lookup). #[inline] - pub fn to_sorted(&self, hcx: &HCX, cache_sort_key: bool) -> Vec<&V> + pub fn to_sorted(&self, hcx: &Hcx, cache_sort_key: bool) -> Vec<&V> where - V: ToStableHashKey, + V: ToStableHashKey, { to_sorted_vec(hcx, self.inner.iter(), cache_sort_key, |&x| x) } @@ -357,9 +357,9 @@ impl UnordSet { /// `cache_sort_key` when the [ToStableHashKey::to_stable_hash_key] implementation /// for `V` is expensive (e.g. a `DefId -> DefPathHash` lookup). #[inline] - pub fn into_sorted(self, hcx: &HCX, cache_sort_key: bool) -> Vec + pub fn into_sorted(self, hcx: &Hcx, cache_sort_key: bool) -> Vec where - V: ToStableHashKey, + V: ToStableHashKey, { to_sorted_vec(hcx, self.inner.into_iter(), cache_sort_key, |x| x) } @@ -415,9 +415,9 @@ impl> From> for UnordSet } } -impl> HashStable for UnordSet { +impl> HashStable for UnordSet { #[inline] - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { hash_iter_order_independent(self.inner.iter(), hcx, hasher); } } @@ -555,9 +555,9 @@ impl UnordMap { /// `cache_sort_key` when the [ToStableHashKey::to_stable_hash_key] implementation /// for `K` is expensive (e.g. a `DefId -> DefPathHash` lookup). #[inline] - pub fn to_sorted(&self, hcx: &HCX, cache_sort_key: bool) -> Vec<(&K, &V)> + pub fn to_sorted(&self, hcx: &Hcx, cache_sort_key: bool) -> Vec<(&K, &V)> where - K: ToStableHashKey, + K: ToStableHashKey, { to_sorted_vec(hcx, self.inner.iter(), cache_sort_key, |&(k, _)| k) } @@ -582,9 +582,9 @@ impl UnordMap { /// `cache_sort_key` when the [ToStableHashKey::to_stable_hash_key] implementation /// for `K` is expensive (e.g. a `DefId -> DefPathHash` lookup). #[inline] - pub fn into_sorted(self, hcx: &HCX, cache_sort_key: bool) -> Vec<(K, V)> + pub fn into_sorted(self, hcx: &Hcx, cache_sort_key: bool) -> Vec<(K, V)> where - K: ToStableHashKey, + K: ToStableHashKey, { to_sorted_vec(hcx, self.inner.into_iter(), cache_sort_key, |(k, _)| k) } @@ -610,9 +610,9 @@ impl UnordMap { /// `cache_sort_key` when the [ToStableHashKey::to_stable_hash_key] implementation /// for `K` is expensive (e.g. a `DefId -> DefPathHash` lookup). #[inline] - pub fn values_sorted(&self, hcx: &HCX, cache_sort_key: bool) -> impl Iterator + pub fn values_sorted(&self, hcx: &Hcx, cache_sort_key: bool) -> impl Iterator where - K: ToStableHashKey, + K: ToStableHashKey, { to_sorted_vec(hcx, self.inner.iter(), cache_sort_key, |&(k, _)| k) .into_iter() @@ -638,9 +638,9 @@ where } } -impl, V: HashStable> HashStable for UnordMap { +impl, V: HashStable> HashStable for UnordMap { #[inline] - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { hash_iter_order_independent(self.inner.iter(), hcx, hasher); } } @@ -701,23 +701,23 @@ impl> From> for UnordBag { } } -impl> HashStable for UnordBag { +impl> HashStable for UnordBag { #[inline] - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { hash_iter_order_independent(self.inner.iter(), hcx, hasher); } } #[inline] -fn to_sorted_vec( - hcx: &HCX, +fn to_sorted_vec( + hcx: &Hcx, iter: I, cache_sort_key: bool, extract_key: fn(&T) -> &K, ) -> Vec where I: Iterator, - K: ToStableHashKey, + K: ToStableHashKey, { let mut items: Vec = iter.collect(); if cache_sort_key { @@ -730,12 +730,12 @@ where } fn hash_iter_order_independent< - HCX, - T: HashStable, + Hcx, + T: HashStable, I: Iterator + ExactSizeIterator, >( mut it: I, - hcx: &mut HCX, + hcx: &mut Hcx, hasher: &mut StableHasher, ) { let len = it.len(); diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index 2156c987906c6..78bd709dd4844 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -712,11 +712,11 @@ impl IntoDiagArg for Namespace { } } -impl ToStableHashKey for Namespace { +impl ToStableHashKey for Namespace { type KeyType = Namespace; #[inline] - fn to_stable_hash_key(&self, _: &CTX) -> Namespace { + fn to_stable_hash_key(&self, _: &Hcx) -> Namespace { *self } } diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 80f0af9d663cb..c144f0b7dbc5b 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -144,8 +144,8 @@ macro_rules! language_item_table { } } -impl HashStable for LangItem { - fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher) { +impl HashStable for LangItem { + fn hash_stable(&self, _: &mut Hcx, hasher: &mut StableHasher) { ::std::hash::Hash::hash(self, hasher); } } diff --git a/compiler/rustc_hir_id/src/lib.rs b/compiler/rustc_hir_id/src/lib.rs index d6deed59b625d..ffff3f979f9e3 100644 --- a/compiler/rustc_hir_id/src/lib.rs +++ b/compiler/rustc_hir_id/src/lib.rs @@ -54,18 +54,18 @@ impl rustc_index::Idx for OwnerId { } } -impl HashStable for OwnerId { +impl HashStable for OwnerId { #[inline] - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.to_stable_hash_key(hcx).hash_stable(hcx, hasher); } } -impl ToStableHashKey for OwnerId { +impl ToStableHashKey for OwnerId { type KeyType = DefPathHash; #[inline] - fn to_stable_hash_key(&self, hcx: &CTX) -> DefPathHash { + fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash { hcx.def_path_hash(self.to_def_id()) } } @@ -176,21 +176,21 @@ pub const CRATE_HIR_ID: HirId = pub const CRATE_OWNER_ID: OwnerId = OwnerId { def_id: CRATE_DEF_ID }; -impl ToStableHashKey for HirId { +impl ToStableHashKey for HirId { type KeyType = (DefPathHash, ItemLocalId); #[inline] - fn to_stable_hash_key(&self, hcx: &CTX) -> (DefPathHash, ItemLocalId) { + fn to_stable_hash_key(&self, hcx: &Hcx) -> (DefPathHash, ItemLocalId) { let def_path_hash = self.owner.def_id.to_stable_hash_key(hcx); (def_path_hash, self.local_id) } } -impl ToStableHashKey for ItemLocalId { +impl ToStableHashKey for ItemLocalId { type KeyType = ItemLocalId; #[inline] - fn to_stable_hash_key(&self, _: &CTX) -> ItemLocalId { + fn to_stable_hash_key(&self, _: &Hcx) -> ItemLocalId { *self } } diff --git a/compiler/rustc_index_macros/src/newtype.rs b/compiler/rustc_index_macros/src/newtype.rs index 282403294db95..b6ee283e736c4 100644 --- a/compiler/rustc_index_macros/src/newtype.rs +++ b/compiler/rustc_index_macros/src/newtype.rs @@ -174,8 +174,8 @@ impl Parse for Newtype { } else if stable_hash_generic || stable_hash_no_context { quote! { #gate_rustc_only - impl ::rustc_data_structures::stable_hasher::HashStable for #name { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) { + impl ::rustc_data_structures::stable_hasher::HashStable for #name { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) { self.as_u32().hash_stable(hcx, hasher) } } diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 0528a0d69324a..af1d1854fa5a0 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -138,9 +138,9 @@ impl LintExpectationId { } } -impl HashStable for LintExpectationId { +impl HashStable for LintExpectationId { #[inline] - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { match self { LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => { hir_id.hash_stable(hcx, hasher); @@ -156,11 +156,11 @@ impl HashStable for LintExpectationId { } } -impl ToStableHashKey for LintExpectationId { +impl ToStableHashKey for LintExpectationId { type KeyType = (DefPathHash, ItemLocalId, u16, u16); #[inline] - fn to_stable_hash_key(&self, hcx: &HCX) -> Self::KeyType { + fn to_stable_hash_key(&self, hcx: &Hcx) -> Self::KeyType { match self { LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => { let (def_path_hash, lint_idx) = hir_id.to_stable_hash_key(hcx); @@ -621,18 +621,18 @@ impl LintId { } } -impl HashStable for LintId { +impl HashStable for LintId { #[inline] - fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.lint_name_raw().hash_stable(hcx, hasher); } } -impl ToStableHashKey for LintId { +impl ToStableHashKey for LintId { type KeyType = &'static str; #[inline] - fn to_stable_hash_key(&self, _: &HCX) -> &'static str { + fn to_stable_hash_key(&self, _: &Hcx) -> &'static str { self.lint_name_raw() } } diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index b5f0692b61ceb..987aa3e2a2c2e 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -251,10 +251,10 @@ impl WorkProductId { WorkProductId { hash: hasher.finish() } } } -impl ToStableHashKey for WorkProductId { +impl ToStableHashKey for WorkProductId { type KeyType = Fingerprint; #[inline] - fn to_stable_hash_key(&self, _: &HCX) -> Self::KeyType { + fn to_stable_hash_key(&self, _: &Hcx) -> Self::KeyType { self.hash } } diff --git a/compiler/rustc_middle/src/mir/basic_blocks.rs b/compiler/rustc_middle/src/mir/basic_blocks.rs index bd8c022ef42a6..1d394525c0f73 100644 --- a/compiler/rustc_middle/src/mir/basic_blocks.rs +++ b/compiler/rustc_middle/src/mir/basic_blocks.rs @@ -171,7 +171,7 @@ impl Decodable for Cache { } } -impl HashStable for Cache { +impl HashStable for Cache { #[inline] - fn hash_stable(&self, _: &mut CTX, _: &mut StableHasher) {} + fn hash_stable(&self, _: &mut Hcx, _: &mut StableHasher) {} } diff --git a/compiler/rustc_middle/src/ty/consts/int.rs b/compiler/rustc_middle/src/ty/consts/int.rs index 180ccd9301c49..25ad8a5e0820d 100644 --- a/compiler/rustc_middle/src/ty/consts/int.rs +++ b/compiler/rustc_middle/src/ty/consts/int.rs @@ -151,8 +151,8 @@ pub struct ScalarInt { // Cannot derive these, as the derives take references to the fields, and we // can't take references to fields of packed structs. -impl crate::ty::HashStable for ScalarInt { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut crate::ty::StableHasher) { +impl crate::ty::HashStable for ScalarInt { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut crate::ty::StableHasher) { // Using a block `{self.data}` here to force a copy instead of using `self.data` // directly, because `hash_stable` takes `&self` and would thus borrow `self.data`. // Since `Self` is a packed struct, that would create a possibly unaligned reference, diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 28688bcbfafc4..a81697cc96dbb 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -607,7 +607,7 @@ pub struct TyCtxtFeed<'tcx, KEY: Copy> { /// Never return a `Feed` from a query. Only queries that create a `DefId` are /// allowed to feed queries for that `DefId`. -impl !HashStable for TyCtxtFeed<'_, KEY> {} +impl !HashStable for TyCtxtFeed<'_, KEY> {} /// The same as `TyCtxtFeed`, but does not contain a `TyCtxt`. /// Use this to pass around when you have a `TyCtxt` elsewhere. @@ -622,7 +622,7 @@ pub struct Feed<'tcx, KEY: Copy> { /// Never return a `Feed` from a query. Only queries that create a `DefId` are /// allowed to feed queries for that `DefId`. -impl !HashStable for Feed<'_, KEY> {} +impl !HashStable for Feed<'_, KEY> {} impl fmt::Debug for Feed<'_, T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 42d5a50df699f..e37247d7dd837 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -636,10 +636,10 @@ macro_rules! define_output_types { const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = (); } - impl ToStableHashKey for OutputType { + impl ToStableHashKey for OutputType { type KeyType = Self; - fn to_stable_hash_key(&self, _: &HCX) -> Self::KeyType { + fn to_stable_hash_key(&self, _: &Hcx) -> Self::KeyType { *self } } diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs index d1899de067b4f..295d9c3617778 100644 --- a/compiler/rustc_session/src/errors.rs +++ b/compiler/rustc_session/src/errors.rs @@ -530,3 +530,7 @@ pub(crate) struct UnexpectedBuiltinCfg { #[derive(Diagnostic)] #[diag("ThinLTO is not supported by the codegen backend, using fat LTO instead")] pub(crate) struct ThinLtoNotSupportedByBackend; + +#[derive(Diagnostic)] +#[diag("`-Zpacked-stack` is only supported on s390x")] +pub(crate) struct UnsupportedPackedStack; diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 8771dbd05c494..027a7045791e4 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2557,6 +2557,8 @@ options! { "pass `-install_name @rpath/...` to the macOS linker (default: no)"), packed_bundled_libs: bool = (false, parse_bool, [TRACKED], "change rlib format to store native libraries as archives"), + packed_stack: bool = (false, parse_bool, [TRACKED], + "use packed stack frames (s390x only) (default: no)"), panic_abort_tests: bool = (false, parse_bool, [TRACKED], "support compiling tests with panic=abort (default: no)"), panic_in_drop: PanicStrategy = (PanicStrategy::Unwind, parse_panic_strategy, [TRACKED], diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 53eae0d87328b..a9e7f1503b9ca 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1363,6 +1363,12 @@ fn validate_commandline_args_with_session_available(sess: &Session) { } } } + + if sess.opts.unstable_opts.packed_stack { + if sess.target.arch != Arch::S390x { + sess.dcx().emit_err(errors::UnsupportedPackedStack); + } + } } /// Holds data on the current incremental compilation session, if there is one. diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index 82d455ab54f0f..8c313c7f8b3a3 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -402,59 +402,59 @@ rustc_data_structures::define_id_collections!( LocalDefId ); -impl HashStable for DefId { +impl HashStable for DefId { #[inline] - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { hcx.def_path_hash(*self).hash_stable(hcx, hasher); } } -impl HashStable for LocalDefId { +impl HashStable for LocalDefId { #[inline] - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { hcx.def_path_hash(self.to_def_id()).local_hash().hash_stable(hcx, hasher); } } -impl HashStable for CrateNum { +impl HashStable for CrateNum { #[inline] - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.as_def_id().to_stable_hash_key(hcx).stable_crate_id().hash_stable(hcx, hasher); } } -impl ToStableHashKey for DefId { +impl ToStableHashKey for DefId { type KeyType = DefPathHash; #[inline] - fn to_stable_hash_key(&self, hcx: &CTX) -> DefPathHash { + fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash { hcx.def_path_hash(*self) } } -impl ToStableHashKey for LocalDefId { +impl ToStableHashKey for LocalDefId { type KeyType = DefPathHash; #[inline] - fn to_stable_hash_key(&self, hcx: &CTX) -> DefPathHash { + fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash { hcx.def_path_hash(self.to_def_id()) } } -impl ToStableHashKey for CrateNum { +impl ToStableHashKey for CrateNum { type KeyType = DefPathHash; #[inline] - fn to_stable_hash_key(&self, hcx: &CTX) -> DefPathHash { + fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash { self.as_def_id().to_stable_hash_key(hcx) } } -impl ToStableHashKey for DefPathHash { +impl ToStableHashKey for DefPathHash { type KeyType = DefPathHash; #[inline] - fn to_stable_hash_key(&self, _: &CTX) -> DefPathHash { + fn to_stable_hash_key(&self, _: &Hcx) -> DefPathHash { *self } } diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs index 25834f03af5e7..e7b98cc910973 100644 --- a/compiler/rustc_span/src/hygiene.rs +++ b/compiler/rustc_span/src/hygiene.rs @@ -207,9 +207,9 @@ impl LocalExpnId { }) } - pub fn fresh(mut expn_data: ExpnData, ctx: impl HashStableContext) -> LocalExpnId { + pub fn fresh(mut expn_data: ExpnData, hcx: impl HashStableContext) -> LocalExpnId { debug_assert_eq!(expn_data.parent.krate, LOCAL_CRATE); - let expn_hash = update_disambiguator(&mut expn_data, ctx); + let expn_hash = update_disambiguator(&mut expn_data, hcx); HygieneData::with(|data| { let expn_id = data.local_expn_data.push(Some(expn_data)); let _eid = data.local_expn_hashes.push(expn_hash); @@ -231,9 +231,9 @@ impl LocalExpnId { } #[inline] - pub fn set_expn_data(self, mut expn_data: ExpnData, ctx: impl HashStableContext) { + pub fn set_expn_data(self, mut expn_data: ExpnData, hcx: impl HashStableContext) { debug_assert_eq!(expn_data.parent.krate, LOCAL_CRATE); - let expn_hash = update_disambiguator(&mut expn_data, ctx); + let expn_hash = update_disambiguator(&mut expn_data, hcx); HygieneData::with(|data| { let old_expn_data = &mut data.local_expn_data[self]; assert!(old_expn_data.is_none(), "expansion data is reset for an expansion ID"); @@ -950,13 +950,13 @@ impl Span { allow_internal_unstable: Option>, reason: DesugaringKind, edition: Edition, - ctx: impl HashStableContext, + hcx: impl HashStableContext, ) -> Span { let expn_data = ExpnData { allow_internal_unstable, ..ExpnData::default(ExpnKind::Desugaring(reason), self, edition, None, None) }; - let expn_id = LocalExpnId::fresh(expn_data, ctx); + let expn_id = LocalExpnId::fresh(expn_data, hcx); self.apply_mark(expn_id.to_expn_id(), Transparency::Transparent) } } @@ -1102,9 +1102,9 @@ impl ExpnData { } #[inline] - fn hash_expn(&self, ctx: &mut impl HashStableContext) -> Hash64 { + fn hash_expn(&self, hcx: &mut impl HashStableContext) -> Hash64 { let mut hasher = StableHasher::new(); - self.hash_stable(ctx, &mut hasher); + self.hash_stable(hcx, &mut hasher); hasher.finish() } } @@ -1482,11 +1482,11 @@ pub fn raw_encode_syntax_context( /// `set_expn_data`). It is *not* called for foreign `ExpnId`s deserialized /// from another crate's metadata - since `ExpnHash` includes the stable crate id, /// collisions are only possible between `ExpnId`s within the same crate. -fn update_disambiguator(expn_data: &mut ExpnData, mut ctx: impl HashStableContext) -> ExpnHash { +fn update_disambiguator(expn_data: &mut ExpnData, mut hcx: impl HashStableContext) -> ExpnHash { // This disambiguator should not have been set yet. assert_eq!(expn_data.disambiguator, 0, "Already set disambiguator for ExpnData: {expn_data:?}"); - ctx.assert_default_hashing_controls("ExpnData (disambiguator)"); - let mut expn_hash = expn_data.hash_expn(&mut ctx); + hcx.assert_default_hashing_controls("ExpnData (disambiguator)"); + let mut expn_hash = expn_data.hash_expn(&mut hcx); let disambiguator = HygieneData::with(|data| { // If this is the first ExpnData with a given hash, then keep our @@ -1501,7 +1501,7 @@ fn update_disambiguator(expn_data: &mut ExpnData, mut ctx: impl HashStableContex debug!("Set disambiguator for expn_data={:?} expn_hash={:?}", expn_data, expn_hash); expn_data.disambiguator = disambiguator; - expn_hash = expn_data.hash_expn(&mut ctx); + expn_hash = expn_data.hash_expn(&mut hcx); // Verify that the new disambiguator makes the hash unique #[cfg(debug_assertions)] @@ -1514,28 +1514,28 @@ fn update_disambiguator(expn_data: &mut ExpnData, mut ctx: impl HashStableContex }); } - ExpnHash::new(ctx.def_path_hash(LOCAL_CRATE.as_def_id()).stable_crate_id(), expn_hash) + ExpnHash::new(hcx.def_path_hash(LOCAL_CRATE.as_def_id()).stable_crate_id(), expn_hash) } -impl HashStable for SyntaxContext { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { +impl HashStable for SyntaxContext { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { const TAG_EXPANSION: u8 = 0; const TAG_NO_EXPANSION: u8 = 1; if self.is_root() { - TAG_NO_EXPANSION.hash_stable(ctx, hasher); + TAG_NO_EXPANSION.hash_stable(hcx, hasher); } else { - TAG_EXPANSION.hash_stable(ctx, hasher); + TAG_EXPANSION.hash_stable(hcx, hasher); let (expn_id, transparency) = self.outer_mark(); - expn_id.hash_stable(ctx, hasher); - transparency.hash_stable(ctx, hasher); + expn_id.hash_stable(hcx, hasher); + transparency.hash_stable(hcx, hasher); } } } -impl HashStable for ExpnId { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - ctx.assert_default_hashing_controls("ExpnId"); +impl HashStable for ExpnId { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + hcx.assert_default_hashing_controls("ExpnId"); let hash = if *self == ExpnId::root() { // Avoid fetching TLS storage for a trivial often-used value. Fingerprint::ZERO @@ -1543,12 +1543,12 @@ impl HashStable for ExpnId { self.expn_hash().0 }; - hash.hash_stable(ctx, hasher); + hash.hash_stable(hcx, hasher); } } -impl HashStable for LocalExpnId { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { +impl HashStable for LocalExpnId { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.to_expn_id().hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index d7d2ecb5bbe79..6794ffb311e32 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -2812,13 +2812,13 @@ pub trait HashStableContext { fn assert_default_hashing_controls(&self, msg: &str); } -impl HashStable for Span +impl HashStable for Span where - CTX: HashStableContext, + Hcx: HashStableContext, { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { // `span_hash_stable` does all the work. - ctx.span_hash_stable(*self, hasher) + hcx.span_hash_stable(*self, hasher) } } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 7b359dcd6b252..30bf8dd7c2206 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -505,6 +505,7 @@ symbols! { avx512bw, avx512f, await_macro, + backchain, bang, begin_panic, bench, @@ -1919,6 +1920,7 @@ symbols! { slice_len_fn, slice_patterns, slicing_syntax, + soft_float: "soft-float", sparc, sparc64, sparc_target_feature, @@ -2599,17 +2601,17 @@ impl fmt::Display for Symbol { } } -impl HashStable for Symbol { +impl HashStable for Symbol { #[inline] - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.as_str().hash_stable(hcx, hasher); } } -impl ToStableHashKey for Symbol { +impl ToStableHashKey for Symbol { type KeyType = String; #[inline] - fn to_stable_hash_key(&self, _: &CTX) -> String { + fn to_stable_hash_key(&self, _: &Hcx) -> String { self.as_str().to_string() } } @@ -2659,9 +2661,9 @@ impl fmt::Debug for ByteSymbol { } } -impl HashStable for ByteSymbol { +impl HashStable for ByteSymbol { #[inline] - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { self.as_byte_str().hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_type_ir/src/const_kind.rs b/compiler/rustc_type_ir/src/const_kind.rs index 49fb94c830e24..9786608ab4bc0 100644 --- a/compiler/rustc_type_ir/src/const_kind.rs +++ b/compiler/rustc_type_ir/src/const_kind.rs @@ -117,8 +117,8 @@ impl fmt::Debug for InferConst { } #[cfg(feature = "nightly")] -impl HashStable for InferConst { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { +impl HashStable for InferConst { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { match self { InferConst::Var(_) => { panic!("const variables should not be hashed: {self:?}") diff --git a/compiler/rustc_type_ir/src/fast_reject.rs b/compiler/rustc_type_ir/src/fast_reject.rs index ed6416a7f55f2..5e24e53c62d9a 100644 --- a/compiler/rustc_type_ir/src/fast_reject.rs +++ b/compiler/rustc_type_ir/src/fast_reject.rs @@ -50,13 +50,13 @@ pub enum SimplifiedType { } #[cfg(feature = "nightly")] -impl> ToStableHashKey for SimplifiedType { +impl> ToStableHashKey for SimplifiedType { type KeyType = Fingerprint; #[inline] - fn to_stable_hash_key(&self, hcx: &HCX) -> Fingerprint { + fn to_stable_hash_key(&self, hcx: &Hcx) -> Fingerprint { let mut hasher = StableHasher::new(); - let mut hcx: HCX = hcx.clone(); + let mut hcx: Hcx = hcx.clone(); self.hash_stable(&mut hcx, &mut hasher); hasher.finish() } diff --git a/compiler/rustc_type_ir/src/region_kind.rs b/compiler/rustc_type_ir/src/region_kind.rs index 4c1b0700da58d..d1076be20bae2 100644 --- a/compiler/rustc_type_ir/src/region_kind.rs +++ b/compiler/rustc_type_ir/src/region_kind.rs @@ -217,15 +217,15 @@ impl fmt::Debug for RegionKind { #[cfg(feature = "nightly")] // This is not a derived impl because a derive would require `I: HashStable` -impl HashStable for RegionKind +impl HashStable for RegionKind where - I::EarlyParamRegion: HashStable, - I::LateParamRegion: HashStable, - I::DefId: HashStable, - I::Symbol: HashStable, + I::EarlyParamRegion: HashStable, + I::LateParamRegion: HashStable, + I::DefId: HashStable, + I::Symbol: HashStable, { #[inline] - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { std::mem::discriminant(self).hash_stable(hcx, hasher); match self { ReErased | ReStatic | ReError(_) => { diff --git a/compiler/rustc_type_ir/src/ty_info.rs b/compiler/rustc_type_ir/src/ty_info.rs index 53994b5dbf637..5e297a51f0ce7 100644 --- a/compiler/rustc_type_ir/src/ty_info.rs +++ b/compiler/rustc_type_ir/src/ty_info.rs @@ -97,8 +97,8 @@ impl Hash for WithCachedTypeInfo { } #[cfg(feature = "nightly")] -impl, CTX> HashStable for WithCachedTypeInfo { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { +impl, Hcx> HashStable for WithCachedTypeInfo { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { if self.stable_hash == Fingerprint::ZERO || cfg!(debug_assertions) { // No cached hash available. This can only mean that incremental is disabled. // We don't cache stable hashes in non-incremental mode, because they are used diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs index 983d8f0820b6b..9afd39e2c7627 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -687,15 +687,15 @@ impl UnifyKey for FloatVid { } #[cfg(feature = "nightly")] -impl HashStable for InferTy { - fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { +impl HashStable for InferTy { + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { use InferTy::*; - std::mem::discriminant(self).hash_stable(ctx, hasher); + std::mem::discriminant(self).hash_stable(hcx, hasher); match self { TyVar(_) | IntVar(_) | FloatVar(_) => { panic!("type variables should not be hashed: {self:?}") } - FreshTy(v) | FreshIntTy(v) | FreshFloatTy(v) => v.hash_stable(ctx, hasher), + FreshTy(v) | FreshIntTy(v) | FreshFloatTy(v) => v.hash_stable(hcx, hasher), } } } diff --git a/library/Cargo.lock b/library/Cargo.lock index 4801f92c63e5a..ffa9a6302ef84 100644 --- a/library/Cargo.lock +++ b/library/Cargo.lock @@ -146,9 +146,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.178" +version = "0.2.183" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091" +checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" dependencies = [ "rustc-std-workspace-core", ] diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index 7a8ccdbc5043b..f7bc729598cd3 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -33,7 +33,7 @@ miniz_oxide = { version = "0.8.0", optional = true, default-features = false } addr2line = { version = "0.25.0", optional = true, default-features = false } [target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies] -libc = { version = "0.2.178", default-features = false, features = [ +libc = { version = "0.2.183", default-features = false, features = [ 'rustc-dep-of-std', ], public = true } diff --git a/library/std/src/sys/fs/unix.rs b/library/std/src/sys/fs/unix.rs index 2a8571871b732..9b0ef5539d32b 100644 --- a/library/std/src/sys/fs/unix.rs +++ b/library/std/src/sys/fs/unix.rs @@ -1872,7 +1872,12 @@ fn file_time_to_timespec(time: Option) -> io::Result io::ErrorKind::InvalidInput, "timestamp is too small to set as a file time", )), - None => Ok(libc::timespec { tv_sec: 0, tv_nsec: libc::UTIME_OMIT as _ }), + None => Ok({ + let mut ts = libc::timespec::default(); + ts.tv_sec = 0; + ts.tv_nsec = libc::UTIME_OMIT as _; + ts + }), } } diff --git a/library/std/src/sys/pal/unix/time.rs b/library/std/src/sys/pal/unix/time.rs index 9acc7786b2edd..26fb6d3d7cf2d 100644 --- a/library/std/src/sys/pal/unix/time.rs +++ b/library/std/src/sys/pal/unix/time.rs @@ -1,3 +1,4 @@ +use core::mem; use core::num::niche_types::Nanoseconds; use crate::io; @@ -6,8 +7,12 @@ use crate::time::Duration; const NSEC_PER_SEC: u64 = 1_000_000_000; #[allow(dead_code)] // Used for pthread condvar timeouts -pub const TIMESPEC_MAX: libc::timespec = - libc::timespec { tv_sec: ::MAX, tv_nsec: 1_000_000_000 - 1 }; +pub const TIMESPEC_MAX: libc::timespec = { + let mut ts = unsafe { mem::zeroed::() }; + ts.tv_sec = ::MAX; + ts.tv_nsec = 1_000_000_000 - 1; + ts +}; // This additional constant is only used when calling // `libc::pthread_cond_timedwait`. @@ -164,9 +169,11 @@ impl Timespec { #[allow(dead_code)] pub fn to_timespec(&self) -> Option { - Some(libc::timespec { - tv_sec: self.tv_sec.try_into().ok()?, - tv_nsec: self.tv_nsec.as_inner().try_into().ok()?, + Some({ + let mut ts = libc::timespec::default(); + ts.tv_sec = self.tv_sec.try_into().ok()?; + ts.tv_nsec = self.tv_nsec.as_inner().try_into().ok()?; + ts }) } diff --git a/library/std/src/sys/thread/unix.rs b/library/std/src/sys/thread/unix.rs index 5d4eabc226ed7..2f3ef1741cdfc 100644 --- a/library/std/src/sys/thread/unix.rs +++ b/library/std/src/sys/thread/unix.rs @@ -570,10 +570,10 @@ pub fn sleep(dur: Duration) { // nanosleep will fill in `ts` with the remaining time. unsafe { while secs > 0 || nsecs > 0 { - let mut ts = libc::timespec { - tv_sec: cmp::min(libc::time_t::MAX as u64, secs) as libc::time_t, - tv_nsec: nsecs, - }; + let mut ts = libc::timespec::default(); + ts.tv_sec = cmp::min(libc::time_t::MAX as u64, secs) as libc::time_t; + ts.tv_nsec = nsecs; + secs -= ts.tv_sec as u64; let ts_ptr = &raw mut ts; let r = nanosleep(ts_ptr, ts_ptr); diff --git a/src/bootstrap/src/core/build_steps/run.rs b/src/bootstrap/src/core/build_steps/run.rs index 2079f3a190198..897e03ce71813 100644 --- a/src/bootstrap/src/core/build_steps/run.rs +++ b/src/bootstrap/src/core/build_steps/run.rs @@ -180,6 +180,10 @@ impl Step for Miri { // Forward arguments. This may contain further arguments to the program // after another --, so this must be at the end. miri.args(builder.config.args()); + // Add default edition for Miri tests (2021); defaulting to 2015 is often confusing. + if !builder.config.args().iter().any(|arg| arg.starts_with("--edition")) { + miri.arg("--edition=2021"); + } miri.into_cmd().run(builder); } diff --git a/tests/assembly-llvm/s390x-packedstack-toggle.rs b/tests/assembly-llvm/s390x-packedstack-toggle.rs new file mode 100644 index 0000000000000..d53f98baaeebe --- /dev/null +++ b/tests/assembly-llvm/s390x-packedstack-toggle.rs @@ -0,0 +1,37 @@ +//@ add-minicore +//@ revisions: enable-packedstack default-packedstack +//@ assembly-output: emit-asm +//@ compile-flags: -Copt-level=3 --crate-type=lib --target=s390x-unknown-linux-gnu -Cforce-unwind-tables=no +//@ needs-llvm-components: systemz +//@[enable-packedstack] compile-flags: -Zpacked-stack +#![feature(no_core, lang_items)] +#![no_std] +#![no_core] + +extern crate minicore; +use minicore::*; + +extern "C" { + fn extern_func() -> i32; +} + +// CHECK-LABEL: test_packedstack +#[no_mangle] +extern "C" fn test_packedstack() -> i32 { + // test the creation of call stack with and without packed-stack + + // without packed-stack we always reserve a least the maximal space of 160 bytes + // default-packedstack: stmg %r14, %r15, 112(%r15) + // default-packedstack-NEXT: aghi %r15, -160 + // default-packedstack-NEXT: brasl %r14, extern_func + + // with packed-stack only the actually needed registers are reserved on the stack + // enable-packedstack: stmg %r14, %r15, 144(%r15) + // enable-packedstack-NEXT: aghi %r15, -16 + // enable-packedstack-NEXT: brasl %r14, extern_func + unsafe { + extern_func(); + } + 1 + // CHECK: br %r{{.*}} +} diff --git a/tests/codegen-llvm/packedstack.rs b/tests/codegen-llvm/packedstack.rs new file mode 100644 index 0000000000000..11a01e60f8d40 --- /dev/null +++ b/tests/codegen-llvm/packedstack.rs @@ -0,0 +1,18 @@ +//@ add-minicore +//@ compile-flags: -Copt-level=3 --crate-type=lib --target=s390x-unknown-none-softfloat -Zpacked-stack +//@ needs-llvm-components: systemz +#![feature(s390x_target_feature)] +#![crate_type = "lib"] +#![feature(no_core, lang_items)] +#![no_core] + +extern crate minicore; +use minicore::*; + +#[no_mangle] + +pub fn test_packedstack() { + // CHECK: @test_packedstack() unnamed_addr #0 +} + +// CHECK: attributes #0 = { {{.*}}"packed-stack"{{.*}} } diff --git a/tests/ui/target-feature/packedstack-combinations.backchain_attr.stderr b/tests/ui/target-feature/packedstack-combinations.backchain_attr.stderr new file mode 100644 index 0000000000000..6270e43e93255 --- /dev/null +++ b/tests/ui/target-feature/packedstack-combinations.backchain_attr.stderr @@ -0,0 +1,6 @@ +error: `-Zpacked-stack` is incompatible with `backchain` target feature + | + = note: enabling both `-Zpacked-stack` and the `backchain` target feature is incompatible with the default s390x ABI. Switch to s390x-unknown-none-softfloat if you need both attributes + +error: aborting due to 1 previous error + diff --git a/tests/ui/target-feature/packedstack-combinations.need_softfloat.stderr b/tests/ui/target-feature/packedstack-combinations.need_softfloat.stderr new file mode 100644 index 0000000000000..6f4531945ee07 --- /dev/null +++ b/tests/ui/target-feature/packedstack-combinations.need_softfloat.stderr @@ -0,0 +1,10 @@ +warning: unstable feature specified for `-Ctarget-feature`: `backchain` + | + = note: this feature is not stably supported; its behavior can change in the future + +error: packedstack with backchain needs softfloat + | + = note: enabling both `-Zpacked-stack` and the `backchain` target feature is incompatible with the default s390x ABI. Switch to s390x-unknown-none-softfloat if you need both attributes + +error: aborting due to 1 previous error; 1 warning emitted + diff --git a/tests/ui/target-feature/packedstack-combinations.rs b/tests/ui/target-feature/packedstack-combinations.rs new file mode 100644 index 0000000000000..5dc0f6adf812e --- /dev/null +++ b/tests/ui/target-feature/packedstack-combinations.rs @@ -0,0 +1,44 @@ +//@ add-minicore +//@ revisions: wrong_arch only_packedstack backchain_attr backchain_cli with_softfloat +//@ compile-flags: -Zpacked-stack --crate-type=rlib +//@ ignore-backends: gcc + +//@ [wrong_arch] compile-flags: --target=x86_64-unknown-linux-gnu +//@ [wrong_arch] should-fail +//@ [wrong_arch] needs-llvm-components: x86 + +//@ [only_packedstack] compile-flags: --target=s390x-unknown-linux-gnu +//@ [only_packedstack] build-pass +//@ [only_packedstack] needs-llvm-components: systemz + +//@ [backchain_attr] compile-flags: --target=s390x-unknown-linux-gnu +//@ [backchain_attr] build-fail +//@ [backchain_attr] needs-llvm-components: systemz + +//@ [backchain_cli] compile-flags: -Ctarget-feature=+backchain --target=s390x-unknown-linux-gnu +//@ [backchain_cli] should-fail +//@ [backchain_cli] needs-llvm-components: systemz + +//@ [with_softfloat] compile-flags: -Ctarget-feature=+backchain +//@ [with_softfloat] compile-flags: --target=s390x-unknown-none-softfloat +//@ [with_softfloat] build-pass +//@ [with_softfloat] needs-llvm-components: systemz + +#![feature(s390x_target_feature)] +#![crate_type = "rlib"] +#![feature(no_core,lang_items)] +#![no_core] + +extern crate minicore; +use minicore::*; + +#[no_mangle] +#[cfg_attr(backchain_attr,target_feature(enable = "backchain"))] +pub fn test() { +} + +//[wrong_arch]~? ERROR `-Zpacked-stack` is only supported on s390x +//[backchain_cli]~? WARN unstable feature specified for `-Ctarget-feature`: `backchain` +//[backchain_cli]~? ERROR `-Zpacked-stack` is incompatible with `backchain` target feature +//[backchain_attr]~? ERROR `-Zpacked-stack` is incompatible with `backchain` target feature +//[with_softfloat]~? WARN unstable feature specified for `-Ctarget-feature`: `backchain` diff --git a/tests/ui/target-feature/packedstack-combinations.with_softfloat.stderr b/tests/ui/target-feature/packedstack-combinations.with_softfloat.stderr new file mode 100644 index 0000000000000..b8c06fc57a448 --- /dev/null +++ b/tests/ui/target-feature/packedstack-combinations.with_softfloat.stderr @@ -0,0 +1,6 @@ +warning: unstable feature specified for `-Ctarget-feature`: `backchain` + | + = note: this feature is not stably supported; its behavior can change in the future + +warning: 1 warning emitted + diff --git a/tests/ui/target-feature/packedstack-combinations.wrong_arch.stderr b/tests/ui/target-feature/packedstack-combinations.wrong_arch.stderr new file mode 100644 index 0000000000000..aa178ad69c627 --- /dev/null +++ b/tests/ui/target-feature/packedstack-combinations.wrong_arch.stderr @@ -0,0 +1,4 @@ +error: `-Zpacked-stack` is only supported on s390x + +error: aborting due to 1 previous error +