diff --git a/Cargo.lock b/Cargo.lock index b8dfdd7cae290..857a93d23080b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3902,7 +3902,6 @@ dependencies = [ "rustc_mir_dataflow", "rustc_session", "rustc_span", - "rustc_target", "rustc_trait_selection", "tracing", ] @@ -4670,7 +4669,6 @@ dependencies = [ "rustc_middle", "rustc_session", "rustc_span", - "rustc_target", ] [[package]] @@ -4813,6 +4811,7 @@ version = "0.0.0" dependencies = [ "arrayvec", "bitflags", + "derive-where", "object 0.37.3", "rustc_abi", "rustc_data_structures", @@ -4821,6 +4820,7 @@ dependencies = [ "rustc_macros", "rustc_serialize", "rustc_span", + "rustc_type_ir", "schemars", "serde", "serde_derive", diff --git a/compiler/rustc_abi/src/callconv.rs b/compiler/rustc_abi/src/callconv.rs index 41e87caf40c7d..83485bc1258f9 100644 --- a/compiler/rustc_abi/src/callconv.rs +++ b/compiler/rustc_abi/src/callconv.rs @@ -1,6 +1,3 @@ -#[cfg(feature = "nightly")] -use crate::{BackendRepr, FieldsShape, Primitive, Size, TyAbiInterface, TyAndLayout, Variants}; - mod reg; pub use reg::{Reg, RegKind}; @@ -35,8 +32,7 @@ impl HomogeneousAggregate { /// Try to combine two `HomogeneousAggregate`s, e.g. from two fields in /// the same `struct`. Only succeeds if only one of them has any data, /// or both units are identical. - #[cfg(feature = "nightly")] - fn merge(self, other: HomogeneousAggregate) -> Result { + pub fn merge(self, other: HomogeneousAggregate) -> Result { match (self, other) { (x, HomogeneousAggregate::NoData) | (HomogeneousAggregate::NoData, x) => Ok(x), @@ -49,145 +45,3 @@ impl HomogeneousAggregate { } } } - -#[cfg(feature = "nightly")] -impl<'a, Ty> TyAndLayout<'a, Ty> { - /// Returns `Homogeneous` if this layout is an aggregate containing fields of - /// only a single type (e.g., `(u32, u32)`). Such aggregates are often - /// special-cased in ABIs. - /// - /// Note: We generally ignore 1-ZST fields when computing this value (see #56877). - /// - /// This is public so that it can be used in unit tests, but - /// should generally only be relevant to the ABI details of - /// specific targets. - #[tracing::instrument(skip(cx), level = "debug")] - pub fn homogeneous_aggregate(&self, cx: &C) -> Result - where - Ty: TyAbiInterface<'a, C> + Copy, - { - match self.backend_repr { - // The primitive for this algorithm. - BackendRepr::Scalar(scalar) => { - let kind = match scalar.primitive() { - Primitive::Int(..) | Primitive::Pointer(_) => RegKind::Integer, - Primitive::Float(_) => RegKind::Float, - }; - Ok(HomogeneousAggregate::Homogeneous(Reg { kind, size: self.size })) - } - - BackendRepr::SimdVector { element, count: _ } => { - assert!(!self.is_zst()); - - Ok(HomogeneousAggregate::Homogeneous(Reg { - kind: RegKind::Vector { hint_vector_elem: element.primitive() }, - size: self.size, - })) - } - - BackendRepr::SimdScalableVector { .. } => { - unreachable!("`homogeneous_aggregate` should not be called for scalable vectors") - } - - BackendRepr::ScalarPair(..) | BackendRepr::Memory { sized: true } => { - // Helper for computing `homogeneous_aggregate`, allowing a custom - // starting offset (used below for handling variants). - let from_fields_at = - |layout: Self, - start: Size| - -> Result<(HomogeneousAggregate, Size), Heterogeneous> { - let is_union = match layout.fields { - FieldsShape::Primitive => { - unreachable!("aggregates can't have `FieldsShape::Primitive`") - } - FieldsShape::Array { count, .. } => { - assert_eq!(start, Size::ZERO); - - let result = if count > 0 { - layout.field(cx, 0).homogeneous_aggregate(cx)? - } else { - HomogeneousAggregate::NoData - }; - return Ok((result, layout.size)); - } - FieldsShape::Union(_) => true, - FieldsShape::Arbitrary { .. } => false, - }; - - let mut result = HomogeneousAggregate::NoData; - let mut total = start; - - for i in 0..layout.fields.count() { - let field = layout.field(cx, i); - if field.is_1zst() { - // No data here and no impact on layout, can be ignored. - // (We might be able to also ignore all aligned ZST but that's less clear.) - continue; - } - - if !is_union && total != layout.fields.offset(i) { - // This field isn't just after the previous one we considered, abort. - return Err(Heterogeneous); - } - - result = result.merge(field.homogeneous_aggregate(cx)?)?; - - // Keep track of the offset (without padding). - let size = field.size; - if is_union { - total = total.max(size); - } else { - total += size; - } - } - - Ok((result, total)) - }; - - let (mut result, mut total) = from_fields_at(*self, Size::ZERO)?; - - match &self.variants { - Variants::Single { .. } | Variants::Empty => {} - Variants::Multiple { variants, .. } => { - // Treat enum variants like union members. - // HACK(eddyb) pretend the `enum` field (discriminant) - // is at the start of every variant (otherwise the gap - // at the start of all variants would disqualify them). - // - // NB: for all tagged `enum`s (which include all non-C-like - // `enum`s with defined FFI representation), this will - // match the homogeneous computation on the equivalent - // `struct { tag; union { variant1; ... } }` and/or - // `union { struct { tag; variant1; } ... }` - // (the offsets of variant fields should be identical - // between the two for either to be a homogeneous aggregate). - let variant_start = total; - for variant_idx in variants.indices() { - let (variant_result, variant_total) = - from_fields_at(self.for_variant(cx, variant_idx), variant_start)?; - - result = result.merge(variant_result)?; - total = total.max(variant_total); - } - } - } - - // There needs to be no padding. - if total != self.size { - Err(Heterogeneous) - } else { - match result { - HomogeneousAggregate::Homogeneous(_) => { - assert_ne!(total, Size::ZERO); - } - HomogeneousAggregate::NoData => { - assert_eq!(total, Size::ZERO); - } - } - Ok(result) - } - } - BackendRepr::Memory { sized: false } => Err(Heterogeneous), - } - } -} diff --git a/compiler/rustc_abi/src/layout.rs b/compiler/rustc_abi/src/layout.rs index 7b68fbc9e77b0..b5bed9da26bde 100644 --- a/compiler/rustc_abi/src/layout.rs +++ b/compiler/rustc_abi/src/layout.rs @@ -18,12 +18,6 @@ use crate::{ mod coroutine; mod simple; -#[cfg(feature = "nightly")] -mod ty; - -#[cfg(feature = "nightly")] -pub use ty::{Layout, TyAbiInterface, TyAndLayout}; - rustc_index::newtype_index! { /// The *source-order* index of a field in a variant. /// @@ -86,11 +80,11 @@ rustc_index::newtype_index! { // but *not* an encoding of the discriminant (e.g., a tag value). // See issue #49298 for more details on the need to leave space // for non-ZST uninhabited data (mostly partial initialization). -fn absent<'a, FieldIdx, VariantIdx, F>(fields: &IndexSlice) -> bool +fn absent(fields: &IndexSlice) -> bool where FieldIdx: Idx, VariantIdx: Idx, - F: Deref> + fmt::Debug, + F: Deref> + fmt::Debug, { let uninhabited = fields.iter().any(|f| f.is_uninhabited()); // We cannot ignore alignment; that might lead us to entirely discard a variant and @@ -240,8 +234,7 @@ impl LayoutCalculator { /// This uses dedicated code instead of [`Self::layout_of_struct_or_enum`], as coroutine /// fields may be shared between multiple variants (see the [`coroutine`] module for details). pub fn coroutine< - 'a, - F: Deref> + fmt::Debug + Copy, + F: Deref> + fmt::Debug + Copy, VariantIdx: Idx, FieldIdx: Idx, LocalIdx: Idx, @@ -264,10 +257,9 @@ impl LayoutCalculator { } pub fn univariant< - 'a, FieldIdx: Idx, VariantIdx: Idx, - F: Deref> + fmt::Debug + Copy, + F: Deref> + fmt::Debug + Copy, >( &self, fields: &IndexSlice, @@ -339,10 +331,9 @@ impl LayoutCalculator { } pub fn layout_of_struct_or_enum< - 'a, FieldIdx: Idx, VariantIdx: Idx, - F: Deref> + fmt::Debug + Copy, + F: Deref> + fmt::Debug + Copy, >( &self, repr: &ReprOptions, @@ -393,10 +384,9 @@ impl LayoutCalculator { } pub fn layout_of_union< - 'a, FieldIdx: Idx, VariantIdx: Idx, - F: Deref> + fmt::Debug + Copy, + F: Deref> + fmt::Debug + Copy, >( &self, repr: &ReprOptions, @@ -519,10 +509,9 @@ impl LayoutCalculator { /// single-variant enums are just structs, if you think about it fn layout_of_struct< - 'a, FieldIdx: Idx, VariantIdx: Idx, - F: Deref> + fmt::Debug + Copy, + F: Deref> + fmt::Debug + Copy, >( &self, repr: &ReprOptions, @@ -572,10 +561,9 @@ impl LayoutCalculator { } fn layout_of_enum< - 'a, FieldIdx: Idx, VariantIdx: Idx, - F: Deref> + fmt::Debug + Copy, + F: Deref> + fmt::Debug + Copy, >( &self, repr: &ReprOptions, @@ -1092,10 +1080,9 @@ impl LayoutCalculator { } fn univariant_biased< - 'a, FieldIdx: Idx, VariantIdx: Idx, - F: Deref> + fmt::Debug + Copy, + F: Deref> + fmt::Debug + Copy, >( &self, fields: &IndexSlice, @@ -1433,10 +1420,9 @@ impl LayoutCalculator { } fn format_field_niches< - 'a, FieldIdx: Idx, VariantIdx: Idx, - F: Deref> + fmt::Debug, + F: Deref> + fmt::Debug, >( &self, layout: &LayoutData, diff --git a/compiler/rustc_abi/src/layout/coroutine.rs b/compiler/rustc_abi/src/layout/coroutine.rs index fd68d06c93829..e630717dd1b37 100644 --- a/compiler/rustc_abi/src/layout/coroutine.rs +++ b/compiler/rustc_abi/src/layout/coroutine.rs @@ -137,8 +137,7 @@ fn coroutine_saved_local_eligibility> + core::fmt::Debug + Copy, + F: core::ops::Deref> + core::fmt::Debug + Copy, VariantIdx: Idx, FieldIdx: Idx, LocalIdx: Idx, diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index a5a4411146c44..6142f6c78240a 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -71,8 +71,6 @@ pub use canon_abi::{ArmCall, CanonAbi, InterruptKind, X86Call}; pub use extern_abi::CVariadicStatus; pub use extern_abi::{ExternAbi, all_names}; pub use layout::{FIRST_VARIANT, FieldIdx, LayoutCalculator, LayoutCalculatorError, VariantIdx}; -#[cfg(feature = "nightly")] -pub use layout::{Layout, TyAbiInterface, TyAndLayout}; #[derive(Clone, Copy, PartialEq, Eq, Default)] #[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, StableHash))] @@ -1150,7 +1148,7 @@ impl Align { /// /// An example of a rare thing actually affected by preferred alignment is aligning of statics. /// It is of effectively no consequence for layout in structs and on the stack. -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Encodable_NoContext, Decodable_NoContext)] #[cfg_attr(feature = "nightly", derive(StableHash))] pub struct AbiAlign { pub abi: Align, @@ -1342,7 +1340,18 @@ impl Integer { } /// Floating-point types. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive( + Copy, + Clone, + PartialEq, + Eq, + PartialOrd, + Ord, + Hash, + Debug, + Encodable_NoContext, + Decodable_NoContext +)] #[cfg_attr(feature = "nightly", derive(StableHash))] pub enum Float { F16, @@ -1377,7 +1386,7 @@ impl Float { } /// Fundamental unit of memory access and layout. -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Encodable_NoContext, Decodable_NoContext)] #[cfg_attr(feature = "nightly", derive(StableHash))] pub enum Primitive { /// The `bool` is the signedness of the `Integer` type. @@ -1425,7 +1434,7 @@ impl Primitive { /// 254 (-2), 255 (-1), 0, 1, 2 /// /// This is intended specifically to mirror LLVM’s `!range` metadata semantics. -#[derive(Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable_NoContext, Decodable_NoContext)] #[cfg_attr(feature = "nightly", derive(StableHash))] pub struct WrappingRange { pub start: u128, @@ -1537,7 +1546,7 @@ impl fmt::Debug for WrappingRange { } /// Information about one scalar component of a Rust type. -#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Encodable_NoContext, Decodable_NoContext)] #[cfg_attr(feature = "nightly", derive(StableHash))] pub enum Scalar { Initialized { @@ -1641,7 +1650,7 @@ impl Scalar { // NOTE: This struct is generic over the FieldIdx for rust-analyzer usage. /// Describes how the fields of a type are located in memory. -#[derive(PartialEq, Eq, Hash, Clone, Debug)] +#[derive(PartialEq, Eq, Hash, Clone, Debug, Encodable_NoContext, Decodable_NoContext)] #[cfg_attr(feature = "nightly", derive(StableHash))] pub enum FieldsShape { /// Scalar primitives and `!`, which never have fields. @@ -1726,7 +1735,18 @@ impl FieldsShape { /// An identifier that specifies the address space that some operation /// should operate on. Special address spaces have an effect on code generation, /// depending on the target and the address spaces it implements. -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive( + Copy, + Clone, + Debug, + PartialEq, + Eq, + PartialOrd, + Ord, + Hash, + Encodable_NoContext, + Decodable_NoContext +)] #[cfg_attr(feature = "nightly", derive(StableHash))] pub struct AddressSpace(pub u32); @@ -1739,7 +1759,7 @@ impl AddressSpace { } /// How many scalable vectors are in a `BackendRepr::ScalableVector`? -#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Encodable_NoContext, Decodable_NoContext)] #[cfg_attr(feature = "nightly", derive(StableHash))] pub struct NumScalableVectors(pub u8); @@ -1788,7 +1808,7 @@ impl IntoDiagArg for NumScalableVectors { /// /// Generally, a codegen backend will prefer to handle smaller values as a scalar or short vector, /// and larger values will usually prefer to be represented as memory. -#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Encodable_NoContext, Decodable_NoContext)] #[cfg_attr(feature = "nightly", derive(StableHash))] pub enum BackendRepr { Scalar(Scalar), @@ -1932,7 +1952,7 @@ impl BackendRepr { } // NOTE: This struct is generic over the FieldIdx and VariantIdx for rust-analyzer usage. -#[derive(PartialEq, Eq, Hash, Clone, Debug)] +#[derive(PartialEq, Eq, Hash, Clone, Debug, Encodable_NoContext, Decodable_NoContext)] #[cfg_attr(feature = "nightly", derive(StableHash))] pub enum Variants { /// A type with no valid variants. Must be uninhabited. @@ -1959,7 +1979,7 @@ pub enum Variants { } // NOTE: This struct is generic over the VariantIdx for rust-analyzer usage. -#[derive(PartialEq, Eq, Hash, Copy, Clone, Debug)] +#[derive(PartialEq, Eq, Hash, Copy, Clone, Debug, Encodable_NoContext, Decodable_NoContext)] #[cfg_attr(feature = "nightly", derive(StableHash))] pub enum TagEncoding { /// The tag directly stores the discriminant, but possibly with a smaller layout @@ -2000,7 +2020,7 @@ pub enum TagEncoding { }, } -#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Encodable_NoContext, Decodable_NoContext)] #[cfg_attr(feature = "nightly", derive(StableHash))] pub struct Niche { pub offset: Size, @@ -2097,7 +2117,7 @@ impl Niche { } // NOTE: This struct is generic over the FieldIdx and VariantIdx for rust-analyzer usage. -#[derive(PartialEq, Eq, Hash, Clone)] +#[derive(PartialEq, Eq, Hash, Clone, Encodable_NoContext, Decodable_NoContext)] #[cfg_attr(feature = "nightly", derive(StableHash))] pub struct LayoutData { /// Says where the fields are located within the layout. @@ -2322,7 +2342,7 @@ pub enum AbiFromStrErr { } // NOTE: This struct is generic over the FieldIdx and VariantIdx for rust-analyzer usage. -#[derive(PartialEq, Eq, Hash, Clone, Debug)] +#[derive(PartialEq, Eq, Hash, Clone, Debug, Encodable_NoContext, Decodable_NoContext)] #[cfg_attr(feature = "nightly", derive(StableHash))] pub struct VariantLayout { pub size: Size, diff --git a/compiler/rustc_codegen_cranelift/src/abi/mod.rs b/compiler/rustc_codegen_cranelift/src/abi/mod.rs index 012951098fa15..523543cea99a0 100644 --- a/compiler/rustc_codegen_cranelift/src/abi/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/abi/mod.rs @@ -18,10 +18,10 @@ use rustc_codegen_ssa::errors::CompilerBuiltinsCannotCall; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::ty::layout::FnAbiOf; use rustc_middle::ty::print::with_no_trimmed_paths; -use rustc_middle::ty::{ShimKind, TypeVisitableExt}; +use rustc_middle::ty::{FnAbi, ShimKind, TypeVisitableExt}; use rustc_session::Session; use rustc_span::Spanned; -use rustc_target::callconv::{FnAbi, PassMode}; +use rustc_target::callconv::PassMode; use rustc_target::spec::Arch; use smallvec::{SmallVec, smallvec}; @@ -39,7 +39,7 @@ struct ArgValue<'tcx> { fn clif_sig_from_fn_abi<'tcx>( tcx: TyCtxt<'tcx>, default_call_conv: CallConv, - fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &FnAbi<'tcx>, ) -> Signature { let call_conv = conv_to_call_conv(tcx.sess, fn_abi.conv, default_call_conv); @@ -621,7 +621,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( fn adjust_call_for_c_variadic<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, - fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &FnAbi<'tcx>, source_info: mir::SourceInfo, target: CallTarget, call_args: &mut Vec, diff --git a/compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs b/compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs index 612f89e6a4217..c0551ba6d1a18 100644 --- a/compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs +++ b/compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs @@ -2,8 +2,9 @@ use cranelift_codegen::ir::ArgumentPurpose; use rustc_abi::{Reg, RegKind}; +use rustc_middle::ty::ArgAbi; use rustc_target::callconv::{ - ArgAbi, ArgAttributes, ArgExtension as RustcArgExtension, CastTarget, PassMode, + ArgAttributes, ArgExtension as RustcArgExtension, CastTarget, PassMode, }; use smallvec::{SmallVec, smallvec}; @@ -96,7 +97,7 @@ fn cast_target_to_abi_params(cast: &CastTarget) -> SmallVec<[(Size, AbiParam); 2 res } -impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> { +impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx> { fn get_abi_param(&self, tcx: TyCtxt<'tcx>) -> SmallVec<[AbiParam; 2]> { match self.mode { PassMode::Ignore => smallvec![], @@ -248,7 +249,7 @@ pub(super) fn from_casted_value<'tcx>( pub(super) fn adjust_arg_for_abi<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, arg: CValue<'tcx>, - arg_abi: &ArgAbi<'tcx, Ty<'tcx>>, + arg_abi: &ArgAbi<'tcx>, is_owned: bool, ) -> SmallVec<[Value; 2]> { assert_assignable(fx, arg.layout().ty, arg_abi.layout.ty, 16); @@ -284,7 +285,7 @@ pub(super) fn cvalue_for_param<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, local: Option, local_field: Option, - arg_abi: &ArgAbi<'tcx, Ty<'tcx>>, + arg_abi: &ArgAbi<'tcx>, block_params_iter: &mut impl Iterator, ) -> Option> { let block_params = arg_abi diff --git a/compiler/rustc_codegen_cranelift/src/abi/returning.rs b/compiler/rustc_codegen_cranelift/src/abi/returning.rs index 36087f96dd776..631ac14b0f95b 100644 --- a/compiler/rustc_codegen_cranelift/src/abi/returning.rs +++ b/compiler/rustc_codegen_cranelift/src/abi/returning.rs @@ -1,6 +1,7 @@ //! Return value handling -use rustc_target::callconv::{ArgAbi, PassMode}; +use rustc_middle::ty::ArgAbi; +use rustc_target::callconv::PassMode; use smallvec::{SmallVec, smallvec}; use crate::prelude::*; @@ -44,7 +45,7 @@ pub(super) fn codegen_return_param<'tcx>( /// returns the call return value(s) if any are written to the correct place. pub(super) fn codegen_with_call_return_arg<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, - ret_arg_abi: &ArgAbi<'tcx, Ty<'tcx>>, + ret_arg_abi: &ArgAbi<'tcx>, ret_place: CPlace<'tcx>, f: impl FnOnce(&mut FunctionCx<'_, '_, 'tcx>, Option) -> SmallVec<[Value; 2]>, ) { diff --git a/compiler/rustc_codegen_cranelift/src/common.rs b/compiler/rustc_codegen_cranelift/src/common.rs index 69e472b33abac..907bc94880aac 100644 --- a/compiler/rustc_codegen_cranelift/src/common.rs +++ b/compiler/rustc_codegen_cranelift/src/common.rs @@ -2,12 +2,11 @@ use cranelift_codegen::isa::TargetFrontendConfig; use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable}; use rustc_abi::{Float, Integer, Primitive}; use rustc_index::IndexVec; -use rustc_middle::ty::TypeFoldable; use rustc_middle::ty::layout::{ self, FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, }; +use rustc_middle::ty::{FnAbi, TypeFoldable}; use rustc_span::{Spanned, Symbol}; -use rustc_target::callconv::FnAbi; use rustc_target::spec::{Arch, HasTargetSpec, Target}; use crate::constant::ConstantCx; @@ -280,7 +279,7 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> { pub(crate) instance: Instance<'tcx>, pub(crate) symbol_name: String, pub(crate) mir: &'tcx Body<'tcx>, - pub(crate) fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>, + pub(crate) fn_abi: &'tcx FnAbi<'tcx>, pub(crate) bcx: FunctionBuilder<'clif>, pub(crate) block_map: IndexVec, diff --git a/compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs b/compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs index 6ab5c5088e55a..0e5bec2560e82 100644 --- a/compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs @@ -19,11 +19,10 @@ use indexmap::IndexSet; use rustc_codegen_ssa::debuginfo::type_names; use rustc_hir::def::DefKind; use rustc_hir::def_id::DefIdMap; -use rustc_middle::ty::Unnormalized; +use rustc_middle::ty::{FnAbi, Unnormalized}; use rustc_session::Session; use rustc_session::config::DebugInfo; use rustc_span::{RemapPathScopeComponents, SourceFileHash, StableSourceFileId}; -use rustc_target::callconv::FnAbi; pub(crate) use self::emit::{DebugReloc, DebugRelocName}; pub(crate) use self::types::TypeDebugContext; @@ -215,7 +214,7 @@ impl DebugContext { tcx: TyCtxt<'tcx>, type_dbg: &mut TypeDebugContext<'tcx>, instance: Instance<'tcx>, - fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &'tcx FnAbi<'tcx>, linkage_name: &str, function_span: Span, ) -> FunctionDebugContext { diff --git a/compiler/rustc_codegen_cranelift/src/pretty_clif.rs b/compiler/rustc_codegen_cranelift/src/pretty_clif.rs index 918fe3d2a3895..9626ac6063baa 100644 --- a/compiler/rustc_codegen_cranelift/src/pretty_clif.rs +++ b/compiler/rustc_codegen_cranelift/src/pretty_clif.rs @@ -62,10 +62,10 @@ use std::io::Write; use cranelift_codegen::entity::SecondaryMap; use cranelift_codegen::ir::entities::AnyEntity; use cranelift_codegen::write::{FuncWriter, PlainWriter}; +use rustc_middle::ty::FnAbi; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_session::Session; use rustc_session::config::{OutputFilenames, OutputType}; -use rustc_target::callconv::FnAbi; use crate::prelude::*; @@ -81,7 +81,7 @@ impl CommentWriter { pub(crate) fn new<'tcx>( tcx: TyCtxt<'tcx>, instance: Instance<'tcx>, - fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &'tcx FnAbi<'tcx>, ) -> Self { let enabled = should_write_ir(tcx.sess); let global_comments = if enabled { diff --git a/compiler/rustc_codegen_gcc/src/abi.rs b/compiler/rustc_codegen_gcc/src/abi.rs index 1b7bb8c907735..5b5e2ebe7529b 100644 --- a/compiler/rustc_codegen_gcc/src/abi.rs +++ b/compiler/rustc_codegen_gcc/src/abi.rs @@ -7,11 +7,11 @@ use rustc_abi::{Reg, RegKind}; use rustc_codegen_ssa::traits::{AbiBuilderMethods, BaseTypeCodegenMethods}; use rustc_data_structures::fx::FxHashSet; use rustc_middle::bug; -use rustc_middle::ty::Ty; use rustc_middle::ty::layout::LayoutOf; +use rustc_middle::ty::{FnAbi, Ty}; #[cfg(feature = "master")] use rustc_session::{Session, config}; -use rustc_target::callconv::{ArgAttributes, CastTarget, FnAbi, PassMode}; +use rustc_target::callconv::{ArgAttributes, CastTarget, PassMode}; #[cfg(feature = "master")] use rustc_target::spec::Arch; @@ -114,7 +114,7 @@ pub trait FnAbiGccExt<'gcc, 'tcx> { fn gcc_cconv(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Option>; } -impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { +impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx> { fn gcc_type(&self, cx: &CodegenCx<'gcc, 'tcx>) -> FnAbiGcc<'gcc> { let mut on_stack_param_indices = FxHashSet::default(); diff --git a/compiler/rustc_codegen_gcc/src/builder.rs b/compiler/rustc_codegen_gcc/src/builder.rs index 6cbc0054cc015..b70e97ff12342 100644 --- a/compiler/rustc_codegen_gcc/src/builder.rs +++ b/compiler/rustc_codegen_gcc/src/builder.rs @@ -27,10 +27,9 @@ use rustc_middle::ty::layout::{ FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError, LayoutOfHelpers, TyAndLayout, }; -use rustc_middle::ty::{self, AtomicOrdering, Instance, Ty, TyCtxt}; +use rustc_middle::ty::{self, AtomicOrdering, FnAbi, Instance, Ty, TyCtxt}; use rustc_span::Span; use rustc_span::def_id::DefId; -use rustc_target::callconv::FnAbi; use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, Target, X86Abi}; use crate::abi::FnAbiGccExt; @@ -348,7 +347,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> { fn function_ptr_call( &mut self, typ: Type<'gcc>, - fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, + fn_abi: Option<&FnAbi<'tcx>>, mut func_ptr: RValue<'gcc>, args: &[RValue<'gcc>], _funclet: Option<&Funclet>, @@ -601,7 +600,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { &mut self, typ: Type<'gcc>, fn_attrs: Option<&CodegenFnAttrs>, - fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, + fn_abi: Option<&FnAbi<'tcx>>, func: RValue<'gcc>, args: &[RValue<'gcc>], then: Block<'gcc>, @@ -639,7 +638,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { &mut self, typ: Type<'gcc>, fn_attrs: Option<&CodegenFnAttrs>, - fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, + fn_abi: Option<&FnAbi<'tcx>>, func: RValue<'gcc>, args: &[RValue<'gcc>], then: Block<'gcc>, @@ -1770,7 +1769,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { &mut self, typ: Type<'gcc>, _fn_attrs: Option<&CodegenFnAttrs>, - fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, + fn_abi: Option<&FnAbi<'tcx>>, func: RValue<'gcc>, args: &[RValue<'gcc>], funclet: Option<&Funclet>, @@ -1796,7 +1795,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { &mut self, _llty: Self::Type, _fn_attrs: Option<&CodegenFnAttrs>, - _fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + _fn_abi: &FnAbi<'tcx>, _llfn: Self::Value, _args: &[Self::Value], _funclet: Option<&Self::Funclet>, diff --git a/compiler/rustc_codegen_gcc/src/debuginfo.rs b/compiler/rustc_codegen_gcc/src/debuginfo.rs index 8907d8a42b38f..da579bf887595 100644 --- a/compiler/rustc_codegen_gcc/src/debuginfo.rs +++ b/compiler/rustc_codegen_gcc/src/debuginfo.rs @@ -5,9 +5,8 @@ use gccjit::{Function, Location, RValue}; use rustc_abi::Size; use rustc_codegen_ssa::mir::debuginfo::VariableKind; use rustc_codegen_ssa::traits::{DebugInfoBuilderMethods, DebugInfoCodegenMethods}; -use rustc_middle::ty::{ExistentialTraitRef, Instance, Ty}; +use rustc_middle::ty::{ExistentialTraitRef, FnAbi, Instance, Ty}; use rustc_span::{BytePos, Pos, SourceFile, SourceFileAndLine, Span, Symbol}; -use rustc_target::callconv::FnAbi; use crate::builder::Builder; use crate::context::CodegenCx; @@ -155,7 +154,7 @@ impl<'gcc, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> { fn dbg_scope_fn( &self, _instance: Instance<'tcx>, - _fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + _fn_abi: &FnAbi<'tcx>, _maybe_definition_llfn: Option>, ) -> Self::DIScope { // FIXME(antoyo): implement. diff --git a/compiler/rustc_codegen_gcc/src/declare.rs b/compiler/rustc_codegen_gcc/src/declare.rs index 4174eebcf7b02..6f0f454762cf3 100644 --- a/compiler/rustc_codegen_gcc/src/declare.rs +++ b/compiler/rustc_codegen_gcc/src/declare.rs @@ -2,9 +2,8 @@ use gccjit::{FnAttribute, ToRValue}; use gccjit::{Function, FunctionType, GlobalKind, LValue, RValue, Type}; use rustc_codegen_ssa::traits::BaseTypeCodegenMethods; -use rustc_middle::ty::Ty; +use rustc_middle::ty::FnAbi; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; use crate::abi::{FnAbiGcc, FnAbiGccExt}; use crate::context::CodegenCx; @@ -109,7 +108,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { ) } - pub fn declare_fn(&self, name: &str, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Function<'gcc> { + pub fn declare_fn(&self, name: &str, fn_abi: &FnAbi<'tcx>) -> Function<'gcc> { let FnAbiGcc { return_type, arguments_type, diff --git a/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs b/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs index 78a4c7e88c895..befa81d6d0164 100644 --- a/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs +++ b/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs @@ -23,10 +23,10 @@ use rustc_data_structures::fx::FxHashSet; #[cfg(feature = "master")] use rustc_middle::ty::layout::FnAbiOf; use rustc_middle::ty::layout::LayoutOf; -use rustc_middle::ty::{self, Instance, Ty}; +use rustc_middle::ty::{self, ArgAbi, Instance, Ty}; use rustc_middle::{bug, span_bug}; use rustc_span::{Span, Symbol, sym}; -use rustc_target::callconv::{ArgAbi, PassMode}; +use rustc_target::callconv::PassMode; #[cfg(feature = "master")] use crate::abi::FnAbiGccExt; @@ -718,7 +718,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc impl<'a, 'gcc, 'tcx> ArgAbiBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> { fn store_fn_arg( &mut self, - arg_abi: &ArgAbi<'tcx, Ty<'tcx>>, + arg_abi: &ArgAbi<'tcx>, idx: &mut usize, dst: PlaceRef<'tcx, Self::Value>, ) { @@ -727,7 +727,7 @@ impl<'a, 'gcc, 'tcx> ArgAbiBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> { fn store_arg( &mut self, - arg_abi: &ArgAbi<'tcx, Ty<'tcx>>, + arg_abi: &ArgAbi<'tcx>, val: RValue<'gcc>, dst: PlaceRef<'tcx, RValue<'gcc>>, ) { @@ -750,7 +750,7 @@ pub trait ArgAbiExt<'gcc, 'tcx> { ); } -impl<'gcc, 'tcx> ArgAbiExt<'gcc, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> { +impl<'gcc, 'tcx> ArgAbiExt<'gcc, 'tcx> for ArgAbi<'tcx> { /// Stores a direct/indirect value described by this ArgAbi into a /// place for the original Rust type of this argument/return. /// Can be used for both storing formal arguments into Rust variables diff --git a/compiler/rustc_codegen_gcc/src/type_of.rs b/compiler/rustc_codegen_gcc/src/type_of.rs index 5b198eeaf0182..718e2d143aa52 100644 --- a/compiler/rustc_codegen_gcc/src/type_of.rs +++ b/compiler/rustc_codegen_gcc/src/type_of.rs @@ -3,17 +3,15 @@ use std::fmt::Write; use gccjit::{Struct, Type}; use rustc_abi as abi; use rustc_abi::Primitive::*; -use rustc_abi::{ - BackendRepr, FieldsShape, Integer, PointeeInfo, Reg, Size, TyAbiInterface, Variants, -}; +use rustc_abi::{BackendRepr, FieldsShape, Integer, PointeeInfo, Reg, Size, Variants}; use rustc_codegen_ssa::traits::{ BaseTypeCodegenMethods, DerivedTypeCodegenMethods, LayoutTypeCodegenMethods, }; use rustc_middle::bug; use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; use rustc_middle::ty::print::with_no_trimmed_paths; -use rustc_middle::ty::{self, CoroutineArgsExt, Ty, TypeVisitableExt}; -use rustc_target::callconv::{CastTarget, FnAbi}; +use rustc_middle::ty::{self, CoroutineArgsExt, FnAbi, TypeVisitableExt}; +use rustc_target::callconv::CastTarget; use crate::abi::{FnAbiGcc, FnAbiGccExt, GccType}; use crate::context::CodegenCx; @@ -334,7 +332,7 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> { return pointee; } - let result = Ty::ty_and_layout_pointee_info_at(*self, cx, offset); + let result = TyAndLayout::pointee_info_at(*self, cx, offset); cx.pointee_infos.borrow_mut().insert((self.ty, offset), result); result @@ -371,7 +369,7 @@ impl<'gcc, 'tcx> LayoutTypeCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> { ty.gcc_type(self) } - fn fn_ptr_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Type<'gcc> { + fn fn_ptr_backend_type(&self, fn_abi: &FnAbi<'tcx>) -> Type<'gcc> { fn_abi.ptr_to_gcc_type(self) } @@ -379,7 +377,7 @@ impl<'gcc, 'tcx> LayoutTypeCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> { unimplemented!(); } - fn fn_decl_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Type<'gcc> { + fn fn_decl_backend_type(&self, fn_abi: &FnAbi<'tcx>) -> Type<'gcc> { // FIXME(antoyo): Should we do something with `FnAbiGcc::fn_attributes`? let FnAbiGcc { return_type, arguments_type, is_c_variadic, .. } = fn_abi.gcc_type(self); self.context.new_function_pointer_type(None, return_type, &arguments_type, is_c_variadic) diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index bdaf72cb17ce6..094cb46724b67 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -9,13 +9,11 @@ use rustc_codegen_ssa::MemFlags; use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue}; use rustc_codegen_ssa::mir::place::{PlaceRef, PlaceValue}; use rustc_codegen_ssa::traits::*; -use rustc_middle::ty::Ty; use rustc_middle::ty::layout::LayoutOf; +use rustc_middle::ty::{ArgAbi, FnAbi, Ty}; use rustc_middle::{bug, ty}; use rustc_session::{Session, config}; -use rustc_target::callconv::{ - ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, CastTarget, FnAbi, PassMode, -}; +use rustc_target::callconv::{ArgAttribute, ArgAttributes, ArgExtension, CastTarget, PassMode}; use rustc_target::spec::{Arch, SanitizerSet}; use smallvec::SmallVec; @@ -227,7 +225,7 @@ trait ArgAbiExt<'ll, 'tcx> { ); } -impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> { +impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx> { /// Stores a direct/indirect value described by this ArgAbi into a /// place for the original Rust type of this argument/return. /// Can be used for both storing formal arguments into Rust variables @@ -318,7 +316,7 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> { impl<'ll, 'tcx> ArgAbiBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { fn store_fn_arg( &mut self, - arg_abi: &ArgAbi<'tcx, Ty<'tcx>>, + arg_abi: &ArgAbi<'tcx>, idx: &mut usize, dst: PlaceRef<'tcx, Self::Value>, ) { @@ -326,7 +324,7 @@ impl<'ll, 'tcx> ArgAbiBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { } fn store_arg( &mut self, - arg_abi: &ArgAbi<'tcx, Ty<'tcx>>, + arg_abi: &ArgAbi<'tcx>, val: &'ll Value, dst: PlaceRef<'tcx, &'ll Value>, ) { @@ -351,7 +349,7 @@ pub(crate) trait FnAbiLlvmExt<'ll, 'tcx> { fn apply_attrs_callsite(&self, bx: &mut Builder<'_, 'll, 'tcx>, callsite: &'ll Value); } -impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { +impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx> { fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type { // Ignore "extra" args from the call site for C variadic functions. // Only the "fixed" args are part of the LLVM function signature. diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 58a62145d576e..8e143faada68f 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -21,11 +21,11 @@ use rustc_middle::ty::layout::{ FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTypingEnv, LayoutError, LayoutOfHelpers, TyAndLayout, }; -use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; +use rustc_middle::ty::{self, FnAbi, Instance, Ty, TyCtxt}; use rustc_sanitizers::{cfi, kcfi}; use rustc_session::config::OptLevel; use rustc_span::Span; -use rustc_target::callconv::{FnAbi, PassMode}; +use rustc_target::callconv::PassMode; use rustc_target::spec::{Arch, HasTargetSpec, LlvmAbi, SanitizerSet, Target}; use smallvec::SmallVec; use tracing::{debug, instrument}; @@ -449,7 +449,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { &mut self, llty: &'ll Type, fn_attrs: Option<&CodegenFnAttrs>, - fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, + fn_abi: Option<&FnAbi<'tcx>>, llfn: &'ll Value, args: &[&'ll Value], then: &'ll BasicBlock, @@ -1453,7 +1453,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { &mut self, llty: &'ll Type, caller_attrs: Option<&CodegenFnAttrs>, - fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, + fn_abi: Option<&FnAbi<'tcx>>, llfn: &'ll Value, args: &[&'ll Value], funclet: Option<&Funclet<'ll>>, @@ -1520,7 +1520,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { &mut self, llty: Self::Type, caller_attrs: Option<&CodegenFnAttrs>, - fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &FnAbi<'tcx>, llfn: Self::Value, args: &[Self::Value], funclet: Option<&Self::Funclet>, @@ -1886,7 +1886,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { &mut self, llty: &'ll Type, fn_attrs: Option<&CodegenFnAttrs>, - fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, + fn_abi: Option<&FnAbi<'tcx>>, llfn: &'ll Value, args: &[&'ll Value], default_dest: &'ll BasicBlock, @@ -1942,7 +1942,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { fn cfi_type_test( &mut self, fn_attrs: Option<&CodegenFnAttrs>, - fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, + fn_abi: Option<&FnAbi<'tcx>>, instance: Option>, llfn: &'ll Value, ) { @@ -2000,7 +2000,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { fn kcfi_operand_bundle( &mut self, fn_attrs: Option<&CodegenFnAttrs>, - fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, + fn_abi: Option<&FnAbi<'tcx>>, instance: Option>, llfn: &'ll Value, ) -> Option> { @@ -2040,7 +2040,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { fn ptrauth_operand_bundle( &mut self, llfn: &'ll Value, - fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, + fn_abi: Option<&FnAbi<'tcx>>, ) -> Option> { if self.sess().target.llvm_abiname != LlvmAbi::Pauthtest { return None; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 26d98ec13cc2b..6e2256069b6c1 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -5,7 +5,7 @@ use std::path::PathBuf; use std::{assert_matches, iter, ptr}; use libc::{c_longlong, c_uint}; -use rustc_abi::{Align, Layout, NumScalableVectors, Size}; +use rustc_abi::{Align, NumScalableVectors, Size}; use rustc_codegen_ssa::debuginfo::type_names::{VTableNameKind, cpp_like_debuginfo}; use rustc_codegen_ssa::traits::*; use rustc_hir::def::{CtorKind, DefKind}; @@ -15,7 +15,7 @@ use rustc_middle::ty::layout::{ HasTypingEnv, LayoutOf, TyAndLayout, WIDE_PTR_ADDR, WIDE_PTR_EXTRA, }; use rustc_middle::ty::{ - self, AdtDef, AdtKind, CoroutineArgsExt, ExistentialTraitRef, Instance, Ty, TyCtxt, + self, AdtDef, AdtKind, CoroutineArgsExt, ExistentialTraitRef, Instance, Layout, Ty, TyCtxt, Unnormalized, Visibility, }; use rustc_session::config::{self, DebugInfo, Lto}; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index d8d529fee6f8b..e058146dfbb1d 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -15,13 +15,12 @@ use rustc_codegen_ssa::traits::*; use rustc_data_structures::unord::UnordMap; use rustc_hir::def_id::{DefId, DefIdMap}; use rustc_middle::ty::layout::{HasTypingEnv, LayoutOf}; -use rustc_middle::ty::{self, GenericArgsRef, Instance, Ty, TypeVisitableExt, Unnormalized}; +use rustc_middle::ty::{self, FnAbi, GenericArgsRef, Instance, Ty, TypeVisitableExt, Unnormalized}; use rustc_session::Session; use rustc_session::config::{self, DebugInfo}; use rustc_span::{ BytePos, Pos, SourceFile, SourceFileAndLine, SourceFileHash, Span, StableSourceFileId, Symbol, }; -use rustc_target::callconv::FnAbi; use rustc_target::spec::DebuginfoKind; use smallvec::SmallVec; use tracing::debug; @@ -419,7 +418,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { fn dbg_scope_fn( &self, instance: Instance<'tcx>, - fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &FnAbi<'tcx>, maybe_definition_llfn: Option<&'ll Value>, ) -> &'ll DIScope { let tcx = self.tcx; @@ -522,7 +521,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { fn get_function_signature<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, - fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &FnAbi<'tcx>, ) -> Vec> { if cx.sess().opts.debuginfo != DebugInfo::Full { return vec![]; diff --git a/compiler/rustc_codegen_llvm/src/declare.rs b/compiler/rustc_codegen_llvm/src/declare.rs index 419d38f95e595..b64cd5949ce45 100644 --- a/compiler/rustc_codegen_llvm/src/declare.rs +++ b/compiler/rustc_codegen_llvm/src/declare.rs @@ -17,9 +17,8 @@ use itertools::Itertools; use rustc_abi::AddressSpace; use rustc_codegen_ssa::traits::{MiscCodegenMethods, TypeMembershipCodegenMethods}; use rustc_data_structures::fx::FxIndexSet; -use rustc_middle::ty::{Instance, Ty}; +use rustc_middle::ty::{FnAbi, Instance}; use rustc_sanitizers::{cfi, kcfi}; -use rustc_target::callconv::FnAbi; use smallvec::SmallVec; use tracing::debug; @@ -173,7 +172,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { pub(crate) fn declare_fn( &self, name: &str, - fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &FnAbi<'tcx>, instance: Option>, ) -> &'ll Value { debug!("declare_rust_fn(name={:?}, fn_abi={:?})", name, fn_abi); diff --git a/compiler/rustc_codegen_llvm/src/mono_item.rs b/compiler/rustc_codegen_llvm/src/mono_item.rs index b746bab643a34..ab6a319a533a9 100644 --- a/compiler/rustc_codegen_llvm/src/mono_item.rs +++ b/compiler/rustc_codegen_llvm/src/mono_item.rs @@ -10,9 +10,9 @@ use rustc_middle::bug; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; use rustc_middle::mono::Visibility; use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv, LayoutOf}; -use rustc_middle::ty::{self, Instance, Ty, TypeVisitableExt}; +use rustc_middle::ty::{self, FnAbi, Instance, TypeVisitableExt}; use rustc_session::config::CrateType; -use rustc_target::callconv::{FnAbi, PassMode}; +use rustc_target::callconv::PassMode; use rustc_target::spec::{Arch, RelocModel}; use tracing::debug; @@ -84,7 +84,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { visibility: Visibility, symbol_name: &str, ) -> &'ll llvm::Value { - let fn_abi: &FnAbi<'tcx, Ty<'tcx>> = self.fn_abi_of_instance(instance, ty::List::empty()); + let fn_abi: &FnAbi<'tcx> = self.fn_abi_of_instance(instance, ty::List::empty()); let lldecl = self.declare_fn(symbol_name, fn_abi, Some(instance)); llvm::set_linkage(lldecl, base::linkage_to_llvm(linkage)); base::set_link_section(lldecl, attrs); @@ -184,8 +184,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { symbol_name.name, ); - let fn_abi: &FnAbi<'tcx, Ty<'tcx>> = - self.fn_abi_of_instance(aliasee_instance, ty::List::empty()); + let fn_abi: &FnAbi<'tcx> = self.fn_abi_of_instance(aliasee_instance, ty::List::empty()); // both the alias and the aliasee have the same ty let fn_ty = fn_abi.llvm_type(self); diff --git a/compiler/rustc_codegen_llvm/src/type_.rs b/compiler/rustc_codegen_llvm/src/type_.rs index 0d49971f52533..788d743b049cf 100644 --- a/compiler/rustc_codegen_llvm/src/type_.rs +++ b/compiler/rustc_codegen_llvm/src/type_.rs @@ -9,8 +9,8 @@ use rustc_codegen_ssa::traits::*; use rustc_data_structures::small_c_str::SmallCStr; use rustc_middle::bug; use rustc_middle::ty::layout::TyAndLayout; -use rustc_middle::ty::{self, Ty}; -use rustc_target::callconv::{CastTarget, FnAbi}; +use rustc_middle::ty::{self, FnAbi}; +use rustc_target::callconv::CastTarget; use crate::abi::{FnAbiLlvmExt, LlvmType}; use crate::common; @@ -313,10 +313,10 @@ impl<'ll, 'tcx> LayoutTypeCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { fn cast_backend_type(&self, ty: &CastTarget) -> &'ll Type { ty.llvm_type(self) } - fn fn_decl_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> &'ll Type { + fn fn_decl_backend_type(&self, fn_abi: &FnAbi<'tcx>) -> &'ll Type { fn_abi.llvm_type(self) } - fn fn_ptr_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> &'ll Type { + fn fn_ptr_backend_type(&self, fn_abi: &FnAbi<'tcx>) -> &'ll Type { fn_abi.ptr_to_llvm_type(self) } fn reg_backend_type(&self, ty: &Reg) -> &'ll Type { diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index dfc8c8be5c03f..5dbe29ce9547d 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -618,7 +618,7 @@ pub(crate) fn symbol_name_for_instance_in_crate<'tcx>( fn calling_convention_for_symbol<'tcx>( tcx: TyCtxt<'tcx>, symbol: ExportedSymbol<'tcx>, -) -> (CanonAbi, &'tcx [rustc_target::callconv::ArgAbi<'tcx, Ty<'tcx>>]) { +) -> (CanonAbi, &'tcx [ty::ArgAbi<'tcx>]) { let instance = match symbol { ExportedSymbol::NonGeneric(def_id) | ExportedSymbol::Generic(def_id, _) if tcx.is_static(def_id) => diff --git a/compiler/rustc_codegen_ssa/src/meth.rs b/compiler/rustc_codegen_ssa/src/meth.rs index b87034f9b33b7..ac3ae6d25da8d 100644 --- a/compiler/rustc_codegen_ssa/src/meth.rs +++ b/compiler/rustc_codegen_ssa/src/meth.rs @@ -1,8 +1,7 @@ use rustc_middle::bug; -use rustc_middle::ty::{self, GenericArgKind, Ty, TyCtxt}; +use rustc_middle::ty::{self, FnAbi, GenericArgKind, Ty, TyCtxt}; use rustc_session::config::Lto; use rustc_symbol_mangling::typeid_for_trait_ref; -use rustc_target::callconv::FnAbi; use tracing::{debug, instrument}; use crate::traits::*; @@ -20,7 +19,7 @@ impl<'a, 'tcx> VirtualIndex { bx: &mut Bx, llvtable: Bx::Value, ty: Ty<'tcx>, - fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &FnAbi<'tcx>, nonnull: bool, ) -> Bx::Value { // Load the function pointer from the object. @@ -38,7 +37,7 @@ impl<'a, 'tcx> VirtualIndex { bx: &mut Bx, llvtable: Bx::Value, ty: Ty<'tcx>, - fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &FnAbi<'tcx>, ) -> Bx::Value { self.get_fn_inner(bx, llvtable, ty, fn_abi, false) } @@ -48,7 +47,7 @@ impl<'a, 'tcx> VirtualIndex { bx: &mut Bx, llvtable: Bx::Value, ty: Ty<'tcx>, - fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &FnAbi<'tcx>, ) -> Bx::Value { self.get_fn_inner(bx, llvtable, ty, fn_abi, true) } diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 0173b84a4d9a1..8126d0a5f78e8 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -13,11 +13,11 @@ use rustc_lint_defs::builtin::TAIL_CALL_TRACK_CALLER; use rustc_middle::mir::{self, AssertKind, InlineAsmMacro, SwitchTargets, UnwindTerminateReason}; use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, ValidityRequirement}; use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths}; -use rustc_middle::ty::{self, Instance, Ty, TypeVisitableExt}; +use rustc_middle::ty::{self, ArgAbi, FnAbi, Instance, Ty, TypeVisitableExt}; use rustc_middle::{bug, span_bug}; use rustc_session::config::OptLevel; use rustc_span::{Span, Spanned}; -use rustc_target::callconv::{ArgAbi, ArgAttributes, CastTarget, FnAbi, PassMode}; +use rustc_target::callconv::{ArgAttributes, CastTarget, PassMode}; use tracing::{debug, info}; use super::operand::OperandRef; @@ -167,7 +167,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> { &self, fx: &mut FunctionCx<'a, 'tcx, Bx>, bx: &mut Bx, - fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &'tcx FnAbi<'tcx>, fn_ptr: Bx::Value, llargs: &[Bx::Value], destination: Option<(ReturnDest<'tcx, Bx::Value>, mir::BasicBlock)>, @@ -1745,7 +1745,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { op: OperandRef<'tcx, Bx::Value>, by_move: bool, llargs: &mut Vec, - arg: &ArgAbi<'tcx, Ty<'tcx>>, + arg: &ArgAbi<'tcx>, lifetime_ends_after_call: &mut Vec<(Bx::Value, Size)>, ) { match arg.mode { @@ -1911,7 +1911,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { conv: CanonAbi, operand: &mir::Operand<'tcx>, llargs: &mut Vec, - args: &[ArgAbi<'tcx, Ty<'tcx>>], + args: &[ArgAbi<'tcx>], lifetime_ends_after_call: &mut Vec<(Bx::Value, Size)>, ) -> usize { let tuple = self.codegen_operand(bx, operand); @@ -2213,7 +2213,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { &mut self, bx: &mut Bx, dest: mir::Place<'tcx>, - fn_ret: &ArgAbi<'tcx, Ty<'tcx>>, + fn_ret: &ArgAbi<'tcx>, llargs: &mut Vec, ) -> ReturnDest<'tcx, Bx::Value> { // If the return is ignored, we can just return a do-nothing `ReturnDest`. @@ -2267,7 +2267,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { &mut self, bx: &mut Bx, dest: ReturnDest<'tcx, Bx::Value>, - ret_abi: &ArgAbi<'tcx, Ty<'tcx>>, + ret_abi: &ArgAbi<'tcx>, llval: Bx::Value, ) { use self::ReturnDest::*; diff --git a/compiler/rustc_codegen_ssa/src/mir/mod.rs b/compiler/rustc_codegen_ssa/src/mir/mod.rs index 68fed6c867fa5..dda72bd1b8a25 100644 --- a/compiler/rustc_codegen_ssa/src/mir/mod.rs +++ b/compiler/rustc_codegen_ssa/src/mir/mod.rs @@ -5,10 +5,10 @@ use rustc_index::bit_set::DenseBitSet; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::{Body, Local, UnwindTerminateReason, traversal}; use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, HasTypingEnv, TyAndLayout}; -use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable, TypeVisitableExt}; +use rustc_middle::ty::{self, FnAbi, Instance, TyCtxt, TypeFoldable, TypeVisitableExt}; use rustc_middle::{bug, mir, span_bug}; use rustc_span::ErrorGuaranteed; -use rustc_target::callconv::{FnAbi, PassMode}; +use rustc_target::callconv::PassMode; use tracing::{debug, instrument}; use crate::base; @@ -60,7 +60,7 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> { cx: &'a Bx::CodegenCx, - fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &'tcx FnAbi<'tcx>, /// When unwinding is initiated, we have to store this personality /// value somewhere so that we can load it and re-use it in the diff --git a/compiler/rustc_codegen_ssa/src/mir/naked_asm.rs b/compiler/rustc_codegen_ssa/src/mir/naked_asm.rs index 0b00b22b1a992..8b52089870812 100644 --- a/compiler/rustc_codegen_ssa/src/mir/naked_asm.rs +++ b/compiler/rustc_codegen_ssa/src/mir/naked_asm.rs @@ -4,10 +4,10 @@ use rustc_hir::def_id::LOCAL_CRATE; use rustc_middle::mir::{InlineAsmOperand, START_BLOCK}; use rustc_middle::mono::{MonoItemData, Visibility}; use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout}; -use rustc_middle::ty::{Instance, Ty, TyCtxt, TypeVisitableExt}; +use rustc_middle::ty::{ArgAbi, FnAbi, Instance, TyCtxt, TypeVisitableExt}; use rustc_middle::{bug, ty}; use rustc_span::sym; -use rustc_target::callconv::{ArgAbi, FnAbi, PassMode}; +use rustc_target::callconv::PassMode; use rustc_target::spec::{Arch, BinaryFormat, Env, Os}; use crate::common; @@ -18,7 +18,7 @@ pub fn codegen_naked_asm< 'a, 'tcx, Cx: LayoutOf<'tcx, LayoutOfResult = TyAndLayout<'tcx>> - + FnAbiOf<'tcx, FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>> + + FnAbiOf<'tcx, FnAbiOfResult = &'tcx FnAbi<'tcx>> + AsmCodegenMethods<'tcx>, >( cx: &'a mut Cx, @@ -120,7 +120,7 @@ fn prefix_and_suffix<'tcx>( instance: Instance<'tcx>, asm_name: &str, item_data: MonoItemData, - fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &FnAbi<'tcx>, ) -> (String, String) { use std::fmt::Write; @@ -389,7 +389,7 @@ fn prefix_and_suffix<'tcx>( /// The webassembly type signature for the given function. /// /// Used by the `.functype` directive on wasm targets. -fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> String { +fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx>) -> String { let mut signature = String::with_capacity(64); let ptr_type = match tcx.data_layout.pointer_size().bits() { @@ -428,7 +428,7 @@ fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Str signature } -fn wasm_type<'tcx>(signature: &mut String, arg_abi: &ArgAbi<'_, Ty<'tcx>>, ptr_type: &'static str) { +fn wasm_type(signature: &mut String, arg_abi: &ArgAbi<'_>, ptr_type: &'static str) { match arg_abi.mode { PassMode::Ignore => { /* do nothing */ } PassMode::Direct(_) => { diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 49f03fe1376e2..08f7525753cdd 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -260,7 +260,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // `Layout` is interned, so we can do a cheap check for things that are // exactly the same and thus don't need any handling. - if abi::Layout::eq(&operand.layout.layout, &cast.layout) { + if ty::Layout::eq(&operand.layout.layout, &cast.layout) { return operand.val; } diff --git a/compiler/rustc_codegen_ssa/src/traits/builder.rs b/compiler/rustc_codegen_ssa/src/traits/builder.rs index 39c2529152566..e91006cbcd640 100644 --- a/compiler/rustc_codegen_ssa/src/traits/builder.rs +++ b/compiler/rustc_codegen_ssa/src/traits/builder.rs @@ -6,10 +6,9 @@ use rustc_hir::attrs::AttributeKind; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; use rustc_middle::mir; use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout}; -use rustc_middle::ty::{AtomicOrdering, Instance, Ty}; +use rustc_middle::ty::{AtomicOrdering, FnAbi, Instance, Ty}; use rustc_session::config::OptLevel; use rustc_span::Span; -use rustc_target::callconv::FnAbi; use super::abi::AbiBuilderMethods; use super::asm::AsmBuilderMethods; @@ -35,7 +34,7 @@ pub enum OverflowOp { pub trait BuilderMethods<'a, 'tcx>: Sized + LayoutOf<'tcx, LayoutOfResult = TyAndLayout<'tcx>> - + FnAbiOf<'tcx, FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>> + + FnAbiOf<'tcx, FnAbiOfResult = &'tcx FnAbi<'tcx>> + Deref + CoverageInfoBuilderMethods<'tcx> + DebugInfoBuilderMethods<'tcx> @@ -131,7 +130,7 @@ pub trait BuilderMethods<'a, 'tcx>: &mut self, llty: Self::FunctionSignature, fn_attrs: Option<&CodegenFnAttrs>, - fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, + fn_abi: Option<&FnAbi<'tcx>>, llfn: Self::Value, args: &[Self::Value], then: Self::BasicBlock, @@ -640,7 +639,7 @@ pub trait BuilderMethods<'a, 'tcx>: &mut self, llty: Self::FunctionSignature, caller_attrs: Option<&CodegenFnAttrs>, - fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, + fn_abi: Option<&FnAbi<'tcx>>, fn_val: Self::Value, args: &[Self::Value], funclet: Option<&Self::Funclet>, @@ -651,7 +650,7 @@ pub trait BuilderMethods<'a, 'tcx>: &mut self, llty: Self::FunctionSignature, caller_attrs: Option<&CodegenFnAttrs>, - fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &FnAbi<'tcx>, llfn: Self::Value, args: &[Self::Value], funclet: Option<&Self::Funclet>, diff --git a/compiler/rustc_codegen_ssa/src/traits/debuginfo.rs b/compiler/rustc_codegen_ssa/src/traits/debuginfo.rs index d3af9e52f1b91..13fe92db27b56 100644 --- a/compiler/rustc_codegen_ssa/src/traits/debuginfo.rs +++ b/compiler/rustc_codegen_ssa/src/traits/debuginfo.rs @@ -1,9 +1,8 @@ use std::ops::Range; use rustc_abi::Size; -use rustc_middle::ty::{ExistentialTraitRef, Instance, Ty}; +use rustc_middle::ty::{ExistentialTraitRef, FnAbi, Instance, Ty}; use rustc_span::{BytePos, SourceFile, Span, Symbol}; -use rustc_target::callconv::FnAbi; use super::BackendTypes; use crate::mir::debuginfo::VariableKind; @@ -29,7 +28,7 @@ pub trait DebugInfoCodegenMethods<'tcx>: BackendTypes { fn dbg_scope_fn( &self, instance: Instance<'tcx>, - fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &FnAbi<'tcx>, maybe_definition_llfn: Option, ) -> Self::DIScope; diff --git a/compiler/rustc_codegen_ssa/src/traits/mod.rs b/compiler/rustc_codegen_ssa/src/traits/mod.rs index ed2dad5a510cd..a607cc1db4e41 100644 --- a/compiler/rustc_codegen_ssa/src/traits/mod.rs +++ b/compiler/rustc_codegen_ssa/src/traits/mod.rs @@ -27,9 +27,8 @@ mod write; use std::fmt; -use rustc_middle::ty::Ty; +use rustc_middle::ty::FnAbi; use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout}; -use rustc_target::callconv::FnAbi; pub use self::abi::AbiBuilderMethods; pub use self::asm::{ @@ -53,7 +52,7 @@ pub use self::write::{ModuleBufferMethods, WriteBackendMethods}; pub trait CodegenObject = Copy + fmt::Debug; pub trait CodegenMethods<'tcx> = LayoutOf<'tcx, LayoutOfResult = TyAndLayout<'tcx>> - + FnAbiOf<'tcx, FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>> + + FnAbiOf<'tcx, FnAbiOfResult = &'tcx FnAbi<'tcx>> + TypeCodegenMethods<'tcx> + ConstCodegenMethods + StaticCodegenMethods diff --git a/compiler/rustc_codegen_ssa/src/traits/type_.rs b/compiler/rustc_codegen_ssa/src/traits/type_.rs index 45ea8384b2d46..76de3a45fa592 100644 --- a/compiler/rustc_codegen_ssa/src/traits/type_.rs +++ b/compiler/rustc_codegen_ssa/src/traits/type_.rs @@ -1,8 +1,8 @@ use rustc_abi::{AddressSpace, Float, Integer, Primitive, Reg, Scalar}; use rustc_middle::bug; -use rustc_middle::ty::Ty; use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, TyAndLayout}; -use rustc_target::callconv::{ArgAbi, CastTarget, FnAbi}; +use rustc_middle::ty::{ArgAbi, FnAbi, Ty}; +use rustc_target::callconv::CastTarget; use super::BackendTypes; use super::misc::MiscCodegenMethods; @@ -114,8 +114,8 @@ pub trait LayoutTypeCodegenMethods<'tcx>: BackendTypes { /// such as when it's stack-allocated or when it's being loaded or stored. fn backend_type(&self, layout: TyAndLayout<'tcx>) -> Self::Type; fn cast_backend_type(&self, ty: &CastTarget) -> Self::Type; - fn fn_decl_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Self::FunctionSignature; - fn fn_ptr_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Self::Type; + fn fn_decl_backend_type(&self, fn_abi: &FnAbi<'tcx>) -> Self::FunctionSignature; + fn fn_ptr_backend_type(&self, fn_abi: &FnAbi<'tcx>) -> Self::Type; fn reg_backend_type(&self, ty: &Reg) -> Self::Type; /// The backend type used for a rust type when it's in an SSA register. /// @@ -163,13 +163,13 @@ pub trait TypeMembershipCodegenMethods<'tcx>: BackendTypes { pub trait ArgAbiBuilderMethods<'tcx>: BackendTypes { fn store_fn_arg( &mut self, - arg_abi: &ArgAbi<'tcx, Ty<'tcx>>, + arg_abi: &ArgAbi<'tcx>, idx: &mut usize, dst: PlaceRef<'tcx, Self::Value>, ); fn store_arg( &mut self, - arg_abi: &ArgAbi<'tcx, Ty<'tcx>>, + arg_abi: &ArgAbi<'tcx>, val: Self::Value, dst: PlaceRef<'tcx, Self::Value>, ); diff --git a/compiler/rustc_const_eval/Cargo.toml b/compiler/rustc_const_eval/Cargo.toml index aa013cf61f483..43c26c2701919 100644 --- a/compiler/rustc_const_eval/Cargo.toml +++ b/compiler/rustc_const_eval/Cargo.toml @@ -19,7 +19,6 @@ rustc_middle = { path = "../rustc_middle" } rustc_mir_dataflow = { path = "../rustc_mir_dataflow" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } -rustc_target = { path = "../rustc_target" } rustc_trait_selection = { path = "../rustc_trait_selection" } tracing = "0.1" # tidy-alphabetical-end diff --git a/compiler/rustc_const_eval/src/const_eval/dummy_machine.rs b/compiler/rustc_const_eval/src/const_eval/dummy_machine.rs index 7c5f867929f04..a06a93d35b03e 100644 --- a/compiler/rustc_const_eval/src/const_eval/dummy_machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/dummy_machine.rs @@ -1,11 +1,10 @@ use rustc_middle::mir::interpret::{AllocId, ConstAllocation, InterpResult}; use rustc_middle::mir::*; use rustc_middle::query::TyCtxtAt; -use rustc_middle::ty::Ty; +use rustc_middle::ty::FnAbi; use rustc_middle::ty::layout::TyAndLayout; use rustc_middle::{bug, span_bug, ty}; use rustc_span::def_id::DefId; -use rustc_target::callconv::FnAbi; use crate::interpret::{ self, HasStaticRootDefId, ImmTy, Immediate, InterpCx, PointerArithmetic, interp_ok, @@ -78,7 +77,7 @@ impl<'tcx> interpret::Machine<'tcx> for DummyMachine { fn find_mir_or_eval_fn( _ecx: &mut InterpCx<'tcx, Self>, _instance: ty::Instance<'tcx>, - _abi: &FnAbi<'tcx, Ty<'tcx>>, + _abi: &FnAbi<'tcx>, _args: &[interpret::FnArg<'tcx, Self::Provenance>], _destination: &interpret::PlaceTy<'tcx, Self::Provenance>, _target: Option, diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index b4a97c0b137c9..8aec0b73e3652 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -11,10 +11,9 @@ use rustc_middle::mir::AssertMessage; use rustc_middle::mir::interpret::ReportedErrorInfo; use rustc_middle::query::TyCtxtAt; use rustc_middle::ty::layout::{HasTypingEnv, TyAndLayout, ValidityRequirement}; -use rustc_middle::ty::{self, FieldInfo, ScalarInt, Ty, TyCtxt}; +use rustc_middle::ty::{self, FieldInfo, FnAbi, ScalarInt, Ty, TyCtxt}; use rustc_middle::{bug, mir, span_bug}; use rustc_span::{Span, Symbol, sym}; -use rustc_target::callconv::FnAbi; use tracing::debug; use super::error::*; @@ -424,7 +423,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> { fn find_mir_or_eval_fn( ecx: &mut InterpCx<'tcx, Self>, orig_instance: ty::Instance<'tcx>, - _abi: &FnAbi<'tcx, Ty<'tcx>>, + _abi: &FnAbi<'tcx>, args: &[FnArg<'tcx>], dest: &PlaceTy<'tcx>, ret: Option, diff --git a/compiler/rustc_const_eval/src/interpret/call.rs b/compiler/rustc_const_eval/src/interpret/call.rs index e2fe8c3a79690..8c2622520cf61 100644 --- a/compiler/rustc_const_eval/src/interpret/call.rs +++ b/compiler/rustc_const_eval/src/interpret/call.rs @@ -9,9 +9,8 @@ use rustc_abi::{self as abi, ExternAbi, FieldIdx, Integer, VariantIdx}; use rustc_hir::def_id::DefId; use rustc_hir::find_attr; use rustc_middle::ty::layout::{IntegerExt, TyAndLayout}; -use rustc_middle::ty::{self, AdtDef, Instance, Ty, VariantDef}; +use rustc_middle::ty::{self, AdtDef, ArgAbi, FnAbi, Instance, Ty, VariantDef}; use rustc_middle::{bug, mir, span_bug}; -use rustc_target::callconv::{ArgAbi, FnAbi}; use tracing::field::Empty; use tracing::{info, instrument, trace}; @@ -247,8 +246,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { /// Returns a `bool` saying whether the two arguments are ABI-compatible. pub fn check_argument_compat( &self, - caller_abi: &ArgAbi<'tcx, Ty<'tcx>>, - callee_abi: &ArgAbi<'tcx, Ty<'tcx>>, + caller_abi: &ArgAbi<'tcx>, + callee_abi: &ArgAbi<'tcx>, ) -> InterpResult<'tcx, bool> { // We do not want to accept things as ABI-compatible that just "happen to be" compatible on the current target, // so we implement a type-based check that reflects the guaranteed rules for ABI compatibility. @@ -269,10 +268,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { /// Initialize a single callee argument, checking the types for compatibility. fn pass_argument<'x, 'y>( &mut self, - caller_args: &mut impl Iterator< - Item = (&'x FnArg<'tcx, M::Provenance>, &'y ArgAbi<'tcx, Ty<'tcx>>), - >, - callee_args_abis: &mut impl Iterator>)>, + caller_args: &mut impl Iterator, &'y ArgAbi<'tcx>)>, + callee_args_abis: &mut impl Iterator)>, callee_arg: &mir::Place<'tcx>, callee_ty: Ty<'tcx>, already_live: bool, @@ -335,7 +332,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { &mut self, instance: Instance<'tcx>, body: &'tcx mir::Body<'tcx>, - caller_fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + caller_fn_abi: &FnAbi<'tcx>, args: &[FnArg<'tcx, M::Provenance>], with_caller_location: bool, destination: &PlaceTy<'tcx, M::Provenance>, @@ -599,7 +596,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { pub(super) fn init_fn_call( &mut self, fn_val: FnVal<'tcx, M::ExtraFnVal>, - (caller_abi, caller_fn_abi): (ExternAbi, &FnAbi<'tcx, Ty<'tcx>>), + (caller_abi, caller_fn_abi): (ExternAbi, &FnAbi<'tcx>), args: &[FnArg<'tcx, M::Provenance>], with_caller_location: bool, destination: &PlaceTy<'tcx, M::Provenance>, @@ -839,7 +836,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { pub(super) fn init_fn_tail_call( &mut self, fn_val: FnVal<'tcx, M::ExtraFnVal>, - (caller_abi, caller_fn_abi): (ExternAbi, &FnAbi<'tcx, Ty<'tcx>>), + (caller_abi, caller_fn_abi): (ExternAbi, &FnAbi<'tcx>), args: &[FnArg<'tcx, M::Provenance>], with_caller_location: bool, ) -> InterpResult<'tcx> { diff --git a/compiler/rustc_const_eval/src/interpret/discriminant.rs b/compiler/rustc_const_eval/src/interpret/discriminant.rs index a1776c6ba3d13..62796ebddedaf 100644 --- a/compiler/rustc_const_eval/src/interpret/discriminant.rs +++ b/compiler/rustc_const_eval/src/interpret/discriminant.rs @@ -64,7 +64,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { // declared list of variants -- they can differ with explicitly assigned discriminants. // We use "tag" to refer to how the discriminant is encoded in memory, which can be either // straight-forward (`TagEncoding::Direct`) or with a niche (`TagEncoding::Niche`). - let (tag_scalar_layout, tag_encoding, tag_field) = match op.layout().variants { + let op_layout = op.layout(); + let (tag_scalar_layout, tag_encoding, tag_field) = match op_layout.variants { Variants::Empty => { throw_ub!(UninhabitedEnumVariantRead(None)); } diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 855ff1a318ed6..7be632761fd68 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -13,11 +13,10 @@ use rustc_middle::ty::layout::{ LayoutOfHelpers, TyAndLayout, }; use rustc_middle::ty::{ - self, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, TypingEnv, Variance, + self, FnAbi, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, TypingEnv, Variance, }; use rustc_middle::{mir, span_bug}; use rustc_span::Span; -use rustc_target::callconv::FnAbi; use tracing::{debug, trace}; use super::{ @@ -43,7 +42,7 @@ pub struct InterpCx<'tcx, M: Machine<'tcx>> { pub(super) typing_env: ty::TypingEnv<'tcx>, /// The query cache is slow so we have our own cache in front of it. - pub(super) layout_cache: RefCell, rustc_abi::Layout<'tcx>>>, + pub(super) layout_cache: RefCell, ty::Layout<'tcx>>>, /// The virtual memory system. pub memory: Memory<'tcx, M>, @@ -119,7 +118,7 @@ impl<'tcx, M: Machine<'tcx>> LayoutOfHelpers<'tcx> for InterpCx<'tcx, M> { } impl<'tcx, M: Machine<'tcx>> FnAbiOfHelpers<'tcx> for InterpCx<'tcx, M> { - type FnAbiOfResult = Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, InterpErrorKind<'tcx>>; + type FnAbiOfResult = Result<&'tcx FnAbi<'tcx>, InterpErrorKind<'tcx>>; fn handle_fn_abi_err( &self, diff --git a/compiler/rustc_const_eval/src/interpret/machine.rs b/compiler/rustc_const_eval/src/interpret/machine.rs index debcc2ac338b5..bd51b29fec865 100644 --- a/compiler/rustc_const_eval/src/interpret/machine.rs +++ b/compiler/rustc_const_eval/src/interpret/machine.rs @@ -9,11 +9,10 @@ use std::hash::Hash; use rustc_abi::{Align, Size}; use rustc_apfloat::{Float, FloatConvert}; use rustc_middle::query::TyCtxtAt; -use rustc_middle::ty::Ty; use rustc_middle::ty::layout::TyAndLayout; +use rustc_middle::ty::{FnAbi, Ty}; use rustc_middle::{mir, ty}; use rustc_span::def_id::DefId; -use rustc_target::callconv::FnAbi; use super::{ AllocBytes, AllocId, AllocKind, AllocRange, Allocation, CTFE_ALLOC_SALT, ConstAllocation, @@ -214,7 +213,7 @@ pub trait Machine<'tcx>: Sized { fn find_mir_or_eval_fn( ecx: &mut InterpCx<'tcx, Self>, instance: ty::Instance<'tcx>, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[FnArg<'tcx, Self::Provenance>], destination: &PlaceTy<'tcx, Self::Provenance>, target: Option, @@ -226,7 +225,7 @@ pub trait Machine<'tcx>: Sized { fn call_extra_fn( ecx: &mut InterpCx<'tcx, Self>, fn_val: Self::ExtraFnVal, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[FnArg<'tcx, Self::Provenance>], destination: &PlaceTy<'tcx, Self::Provenance>, target: Option, @@ -684,7 +683,7 @@ pub macro compile_time_machine(<$tcx: lifetime>) { fn call_extra_fn( _ecx: &mut InterpCx<$tcx, Self>, fn_val: !, - _abi: &FnAbi<$tcx, Ty<$tcx>>, + _abi: &FnAbi<$tcx>, _args: &[FnArg<$tcx>], _destination: &PlaceTy<$tcx, Self::Provenance>, _target: Option, diff --git a/compiler/rustc_const_eval/src/interpret/stack.rs b/compiler/rustc_const_eval/src/interpret/stack.rs index 3e7c57a439c67..e4a93134bb136 100644 --- a/compiler/rustc_const_eval/src/interpret/stack.rs +++ b/compiler/rustc_const_eval/src/interpret/stack.rs @@ -8,11 +8,10 @@ use rustc_hir as hir; use rustc_hir::definitions::DefPathData; use rustc_index::IndexVec; use rustc_middle::ty::layout::TyAndLayout; -use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::ty::{self, ArgAbi, Ty, TyCtxt}; use rustc_middle::{bug, mir}; use rustc_mir_dataflow::impls::always_storage_live_locals; use rustc_span::Span; -use rustc_target::callconv::ArgAbi; use tracing::field::Empty; use tracing::{info_span, instrument, trace}; @@ -640,8 +639,8 @@ impl<'a, 'tcx: 'a, M: Machine<'tcx>> InterpCx<'tcx, M> { mut callee_abis: J, ) -> InterpResult<'tcx, Vec>> where - I: Iterator, &'a ArgAbi<'tcx, Ty<'tcx>>)>, - J: Iterator>)>, + I: Iterator, &'a ArgAbi<'tcx>)>, + J: Iterator)>, { // Consume the remaining arguments and store them in fresh allocations. let mut varargs = Vec::new(); diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs index 1aeaaee3a251c..86a06e91f3096 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -8,10 +8,9 @@ use either::Either; use rustc_abi::{FIRST_VARIANT, FieldIdx}; use rustc_data_structures::fx::FxHashSet; use rustc_index::IndexSlice; -use rustc_middle::ty::{self, Instance, Ty}; +use rustc_middle::ty::{self, FnAbi, Instance}; use rustc_middle::{bug, mir, span_bug}; use rustc_span::Spanned; -use rustc_target::callconv::FnAbi; use tracing::field::Empty; use tracing::{info, instrument, trace}; @@ -25,7 +24,7 @@ struct EvaluatedCalleeAndArgs<'tcx, M: Machine<'tcx>> { callee: FnVal<'tcx, M::ExtraFnVal>, args: Vec>, fn_sig: ty::FnSig<'tcx>, - fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &'tcx FnAbi<'tcx>, /// True if the function is marked as `#[track_caller]` ([`ty::InstanceKind::requires_caller_location`]) with_caller_location: bool, } diff --git a/compiler/rustc_const_eval/src/util/check_validity_requirement.rs b/compiler/rustc_const_eval/src/util/check_validity_requirement.rs index 00835a3cc990a..463779b14e2ca 100644 --- a/compiler/rustc_const_eval/src/util/check_validity_requirement.rs +++ b/compiler/rustc_const_eval/src/util/check_validity_requirement.rs @@ -26,7 +26,7 @@ pub fn check_validity_requirement<'tcx>( tcx: TyCtxt<'tcx>, kind: ValidityRequirement, input: PseudoCanonicalInput<'tcx, Ty<'tcx>>, -) -> Result> { +) -> Result> { let layout = tcx.layout_of(input)?; // There is nothing strict or lax about inhabitedness. @@ -92,7 +92,7 @@ fn check_validity_requirement_lax<'tcx>( this: TyAndLayout<'tcx>, cx: &LayoutCx<'tcx>, init_kind: ValidityRequirement, -) -> Result> { +) -> Result> { let scalar_allows_raw_init = move |s: Scalar| -> bool { match init_kind { ValidityRequirement::Inhabited => { diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs index e4874c41d5cdd..ef63a843c90c2 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs @@ -77,7 +77,7 @@ fn is_valid_cmse_inputs<'tcx>( fn_sig: ty::PolyFnSig<'tcx>, fn_decl: &hir::FnDecl<'tcx>, abi: ExternAbi, -) -> Result<(), (Span, &'tcx LayoutError<'tcx>)> { +) -> Result<(), (Span, LayoutError<'tcx>)> { let mut accum = 0u64; let mut excess_argument_spans = Vec::new(); @@ -88,7 +88,7 @@ fn is_valid_cmse_inputs<'tcx>( for (ty, hir_ty) in fn_sig.inputs().iter().zip(fn_decl.inputs) { if ty.has_infer_types() { let err = LayoutError::Unknown(*ty); - return Err((hir_ty.span, tcx.arena.alloc(err))); + return Err((hir_ty.span, err)); } let layout = tcx @@ -123,7 +123,7 @@ fn is_valid_cmse_output<'tcx>( fn_sig: ty::PolyFnSig<'tcx>, fn_decl: &hir::FnDecl<'tcx>, abi: ExternAbi, -) -> Result<(), &'tcx LayoutError<'tcx>> { +) -> Result<(), LayoutError<'tcx>> { // this type is only used for layout computation, which does not rely on regions let fn_sig = tcx.instantiate_bound_regions_with_erased(fn_sig); let fn_sig = tcx.erase_and_anonymize_regions(fn_sig); @@ -145,7 +145,7 @@ fn is_valid_cmse_output<'tcx>( if return_type.has_infer_types() { let err = LayoutError::Unknown(return_type); - return Err(tcx.arena.alloc(err)); + return Err(err); } let typing_env = ty::TypingEnv::fully_monomorphized(); @@ -176,7 +176,7 @@ fn is_valid_cmse_output_layout<'tcx>(cx: LayoutCx<'tcx>, layout: TyAndLayout<'tc ) } -fn should_emit_layout_error<'tcx>(abi: ExternAbi, layout_err: &'tcx LayoutError<'tcx>) -> bool { +fn should_emit_layout_error<'tcx>(abi: ExternAbi, layout_err: LayoutError<'tcx>) -> bool { use LayoutError::*; match layout_err { diff --git a/compiler/rustc_hir_typeck/src/intrinsicck.rs b/compiler/rustc_hir_typeck/src/intrinsicck.rs index 430f4d828b91f..9c7be37a3df26 100644 --- a/compiler/rustc_hir_typeck/src/intrinsicck.rs +++ b/compiler/rustc_hir_typeck/src/intrinsicck.rs @@ -42,7 +42,7 @@ fn unpack_option_like<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { /// Try to display a sensible error with as much information as possible. fn skeleton_string<'tcx>( ty: Ty<'tcx>, - sk: Result, &'tcx LayoutError<'tcx>>, + sk: Result, LayoutError<'tcx>>, ) -> String { match sk { Ok(SizeSkeleton::Pointer { tail, .. }) => format!("pointer to `{tail}`"), @@ -57,7 +57,7 @@ fn skeleton_string<'tcx>( } } Err(LayoutError::TooGeneric(bad)) => { - if *bad == ty { + if bad == ty { "this type does not have a fixed size".to_owned() } else { format!("size can vary because of {bad}") diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs index 87e19fafc0e22..4d93809b6598a 100644 --- a/compiler/rustc_middle/src/arena.rs +++ b/compiler/rustc_middle/src/arena.rs @@ -8,7 +8,7 @@ macro_rules! arena_types { $macro!([ [] layout: rustc_abi::LayoutData, [] proxy_coroutine_layout: rustc_middle::mir::CoroutineLayout<'tcx>, - [] fn_abi: rustc_target::callconv::FnAbi<'tcx, rustc_middle::ty::Ty<'tcx>>, + [] fn_abi: rustc_middle::ty::FnAbi<'tcx>, [] adt_def: rustc_middle::ty::AdtDefData, [] steal_thir: rustc_data_structures::steal::Steal>, [] steal_mir: rustc_data_structures::steal::Steal>, diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index f0557c3d3381a..8189864a66745 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -1736,10 +1736,11 @@ rustc_queries! { /// executes in `TypingMode::PostAnalysis`, and will normalize the input type. query layout_of( key: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>> - ) -> Result, &'tcx ty::layout::LayoutError<'tcx>> { + ) -> Result, ty::layout::LayoutError<'tcx>> { depth_limit desc { "computing layout of `{}`", key.value } handle_cycle_error + cache_on_disk } /// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers. @@ -1748,7 +1749,7 @@ rustc_queries! { /// instead, where the instance is an `InstanceKind::Virtual`. query fn_abi_of_fn_ptr( key: ty::PseudoCanonicalInput<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List>)> - ) -> Result<&'tcx rustc_target::callconv::FnAbi<'tcx, Ty<'tcx>>, &'tcx ty::layout::FnAbiError<'tcx>> { + ) -> Result<&'tcx rustc_middle::ty::FnAbi<'tcx>, &'tcx ty::layout::FnAbiError<'tcx>> { desc { "computing call ABI of `{}` function pointers", key.value.0 } } @@ -1765,7 +1766,7 @@ rustc_queries! { /// `InstanceKind::Virtual` instance (of `::fn`). query fn_abi_of_instance_no_deduced_attrs( key: ty::PseudoCanonicalInput<'tcx, (ty::Instance<'tcx>, &'tcx ty::List>)> - ) -> Result<&'tcx rustc_target::callconv::FnAbi<'tcx, Ty<'tcx>>, &'tcx ty::layout::FnAbiError<'tcx>> { + ) -> Result<&'tcx rustc_middle::ty::FnAbi<'tcx>, &'tcx ty::layout::FnAbiError<'tcx>> { desc { "computing unadjusted call ABI of `{}`", key.value.0 } } @@ -1785,7 +1786,7 @@ rustc_queries! { /// `InstanceKind::Virtual` instance (of `::fn`). query fn_abi_of_instance_raw( key: ty::PseudoCanonicalInput<'tcx, (ty::Instance<'tcx>, &'tcx ty::List>)> - ) -> Result<&'tcx rustc_target::callconv::FnAbi<'tcx, Ty<'tcx>>, &'tcx ty::layout::FnAbiError<'tcx>> { + ) -> Result<&'tcx rustc_middle::ty::FnAbi<'tcx>, &'tcx ty::layout::FnAbiError<'tcx>> { desc { "computing call ABI of `{}`", key.value.0 } } @@ -2644,7 +2645,7 @@ rustc_queries! { desc { "computing the backend features for CLI flags" } } - query check_validity_requirement(key: (ValidityRequirement, ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>)) -> Result> { + query check_validity_requirement(key: (ValidityRequirement, ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>)) -> Result> { desc { "checking validity requirement for `{}`: {}", key.1.value, key.0 } } diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs index a5fb77ced7656..33cba322cdc99 100644 --- a/compiler/rustc_middle/src/query/erase.rs +++ b/compiler/rustc_middle/src/query/erase.rs @@ -197,7 +197,7 @@ impl_erasable_for_types_with_no_type_params! { Option>, Option, Result<&'_ TokenStream, ()>, - Result<&'_ rustc_target::callconv::FnAbi<'_, Ty<'_>>, &'_ ty::layout::FnAbiError<'_>>, + Result<&'_ rustc_middle::ty::FnAbi<'_>, &'_ ty::layout::FnAbiError<'_>>, Result<&'_ traits::ImplSource<'_, ()>, traits::CodegenObligationError>, Result<&'_ ty::List>, ty::util::AlwaysRequiresDrop>, Result<(&'_ Steal>, thir::ExprId), ErrorGuaranteed>, @@ -205,12 +205,12 @@ impl_erasable_for_types_with_no_type_params! { Result<(), ErrorGuaranteed>, Result>>, ErrorGuaranteed>, Result>, ErrorGuaranteed>, - Result>, + Result>, Result, mir::interpret::ErrorHandled>, Result, - Result>, &ty::layout::LayoutError<'_>>, Result, Result, + Result>, ty::layout::LayoutError<'_>>, Result, traits::query::NoSolution>, Ty<'_>, bool, diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 8b1e812582783..fc793bb4b9425 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -164,6 +164,12 @@ impl<'tcx, E: TyEncoder<'tcx>> Encodable for ty::Region<'tcx> { } } +impl<'tcx, E: TyEncoder<'tcx>> Encodable for ty::Layout<'tcx> { + fn encode(&self, e: &mut E) { + self.0.0.encode(e); + } +} + impl<'tcx, E: TyEncoder<'tcx>> Encodable for ty::Const<'tcx> { fn encode(&self, e: &mut E) { self.0.0.encode(e); @@ -368,6 +374,14 @@ impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> } } +impl<'tcx, D: TyDecoder<'tcx>> Decodable for ty::Layout<'tcx> { + fn decode(decoder: &mut D) -> Self { + let data: rustc_abi::LayoutData = + Decodable::decode(decoder); + decoder.interner().mk_layout(data) + } +} + impl<'tcx, D: TyDecoder<'tcx>> Decodable for ty::Const<'tcx> { fn decode(decoder: &mut D) -> Self { let kind: ty::ConstKind<'tcx> = Decodable::decode(decoder); diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 3d7aef0b273f1..c7c0c1e5ff2dc 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -15,7 +15,7 @@ use std::ops::Deref; use std::sync::{Arc, OnceLock}; use std::{fmt, iter, mem}; -use rustc_abi::{ExternAbi, FieldIdx, Layout, LayoutData, TargetDataLayout, VariantIdx}; +use rustc_abi::{ExternAbi, FieldIdx, LayoutData, TargetDataLayout, VariantIdx}; use rustc_ast as ast; use rustc_data_structures::defer; use rustc_data_structures::fx::FxHashMap; @@ -68,10 +68,10 @@ use crate::traits::solve::{ExternalConstraints, ExternalConstraintsData, Predefi use crate::ty::predicate::ExistentialPredicateStableCmpExt as _; use crate::ty::{ self, AdtDef, AdtDefData, AdtKind, Binder, Clause, Clauses, Const, FnSigKind, GenericArg, - GenericArgs, GenericArgsRef, GenericParamDefKind, List, ListWithCachedTypeInfo, ParamConst, - Pattern, PatternKind, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind, - PredicatePolarity, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyVid, - ValTree, ValTreeKind, Visibility, + GenericArgs, GenericArgsRef, GenericParamDefKind, Layout, List, ListWithCachedTypeInfo, + ParamConst, Pattern, PatternKind, PolyExistentialPredicate, PolyFnSig, Predicate, + PredicateKind, PredicatePolarity, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, + TyKind, TyVid, ValTree, ValTreeKind, Visibility, }; impl<'tcx> rustc_type_ir::inherent::DefId> for DefId { diff --git a/compiler/rustc_middle/src/ty/context/impl_interner.rs b/compiler/rustc_middle/src/ty/context/impl_interner.rs index ada3298a6ca6e..4bc3de11e51e0 100644 --- a/compiler/rustc_middle/src/ty/context/impl_interner.rs +++ b/compiler/rustc_middle/src/ty/context/impl_interner.rs @@ -107,6 +107,9 @@ impl<'tcx> Interner for TyCtxt<'tcx> { type Pat = Pattern<'tcx>; type PatList = &'tcx List>; type Safety = hir::Safety; + type Layout = ty::Layout<'tcx>; + type FieldsShapeRef = &'tcx rustc_abi::FieldsShape; + type VariantsRef = &'tcx rustc_abi::Variants; type Const = ty::Const<'tcx>; type Consts = &'tcx List; diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 1f3d4e32714a0..b8041820fc23b 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -1,11 +1,11 @@ use std::{cmp, fmt}; -use rustc_abi as abi; use rustc_abi::{ - AddressSpace, Align, ExternAbi, FieldIdx, FieldsShape, HasDataLayout, LayoutData, PointeeInfo, - PointerKind, Primitive, ReprFlags, ReprOptions, Scalar, Size, TagEncoding, TargetDataLayout, - TyAbiInterface, VariantIdx, Variants, + self as abi, AbiAlign, AddressSpace, Align, BackendRepr, ExternAbi, FieldIdx, FieldsShape, + HasDataLayout, LayoutData, Niche, PointeeInfo, PointerKind, Primitive, ReprFlags, ReprOptions, + Scalar, Size, TagEncoding, TargetDataLayout, VariantIdx, Variants, }; +use rustc_data_structures::intern::Interned; use rustc_errors::{ Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg, Level, }; @@ -15,8 +15,8 @@ use rustc_hir::def_id::DefId; use rustc_macros::{StableHash, TyDecodable, TyEncodable, extension}; use rustc_session::config::OptLevel; use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym}; -use rustc_target::callconv::FnAbi; use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, Target, X86Abi}; +use rustc_type_ir::TyAbiInterface; use tracing::debug; use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; @@ -333,7 +333,7 @@ impl<'tcx> SizeSkeleton<'tcx> { tcx: TyCtxt<'tcx>, typing_env: ty::TypingEnv<'tcx>, span: Span, - ) -> Result, &'tcx LayoutError<'tcx>> { + ) -> Result, LayoutError<'tcx>> { Self::compute_inner(ty, tcx, typing_env, span, 0) } @@ -343,7 +343,7 @@ impl<'tcx> SizeSkeleton<'tcx> { typing_env: ty::TypingEnv<'tcx>, span: Span, depth: usize, - ) -> Result, &'tcx LayoutError<'tcx>> { + ) -> Result, LayoutError<'tcx>> { debug_assert!(!ty.has_non_region_infer()); // Bail out if we've recursed too deeply (issue #156137); a cyclic type @@ -361,7 +361,7 @@ impl<'tcx> SizeSkeleton<'tcx> { ty, suggested_limit, }); - return Err(tcx.arena.alloc(LayoutError::ReferencesError(reported))); + return Err(LayoutError::ReferencesError(reported)); } // First try computing a static layout. @@ -371,7 +371,7 @@ impl<'tcx> SizeSkeleton<'tcx> { return Ok(SizeSkeleton::Known(layout.size, Some(layout.align.abi))); } else { // Just to be safe, don't claim a known layout for unsized types. - return Err(tcx.arena.alloc(LayoutError::Unknown(ty))); + return Err(LayoutError::Unknown(ty)); } } Err(err @ LayoutError::TooGeneric(_)) => err, @@ -423,7 +423,7 @@ impl<'tcx> SizeSkeleton<'tcx> { } ty::Error(guar) => { // Fixes ICE #124031 - return Err(tcx.arena.alloc(LayoutError::ReferencesError(*guar))); + return Err(LayoutError::ReferencesError(*guar)); } _ => bug!( "SizeSkeleton::compute({ty}): layout errored ({err:?}), yet \ @@ -445,7 +445,7 @@ impl<'tcx> SizeSkeleton<'tcx> { let size = s .bytes() .checked_mul(c) - .ok_or_else(|| &*tcx.arena.alloc(LayoutError::SizeOverflow(ty)))?; + .ok_or_else(|| LayoutError::SizeOverflow(ty))?; // Alignment is unchanged by arrays. return Ok(SizeSkeleton::Known(Size::from_bytes(size), a)); } @@ -705,8 +705,6 @@ impl MaybeResult for Result { } } -pub type TyAndLayout<'tcx> = rustc_abi::TyAndLayout<'tcx, Ty<'tcx>>; - /// Trait for contexts that want to be able to compute layouts of types. /// This automatically gives access to `LayoutOf`, through a blanket `impl`. pub trait LayoutOfHelpers<'tcx>: HasDataLayout + HasTyCtxt<'tcx> + HasTypingEnv<'tcx> { @@ -756,7 +754,7 @@ pub trait LayoutOf<'tcx>: LayoutOfHelpers<'tcx> { MaybeResult::from( tcx.layout_of(self.typing_env().as_query_input(ty)) - .map_err(|err| self.handle_layout_err(*err, span, ty)), + .map_err(|err| self.handle_layout_err(err, span, ty)), ) } } @@ -764,20 +762,105 @@ pub trait LayoutOf<'tcx>: LayoutOfHelpers<'tcx> { impl<'tcx, C: LayoutOfHelpers<'tcx>> LayoutOf<'tcx> for C {} impl<'tcx> LayoutOfHelpers<'tcx> for LayoutCx<'tcx> { - type LayoutOfResult = Result, &'tcx LayoutError<'tcx>>; + type LayoutOfResult = Result, LayoutError<'tcx>>; #[inline] - fn handle_layout_err( - &self, - err: LayoutError<'tcx>, - _: Span, - _: Ty<'tcx>, - ) -> &'tcx LayoutError<'tcx> { - self.tcx().arena.alloc(err) + fn handle_layout_err(&self, err: LayoutError<'tcx>, _: Span, _: Ty<'tcx>) -> LayoutError<'tcx> { + err + } +} + +pub type TyAndLayout<'tcx> = rustc_type_ir::TyAndLayout>; +pub type ArgAbi<'tcx> = rustc_target::callconv::ArgAbi>; +pub type FnAbi<'tcx> = rustc_target::callconv::FnAbi>; + +#[derive(Copy, Clone, PartialEq, Eq, Hash, StableHash)] +#[rustc_pass_by_value] +pub struct Layout<'tcx>(pub Interned<'tcx, LayoutData>); + +impl<'tcx> fmt::Debug for Layout<'tcx> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // See comment on `::fmt` above. + self.0.0.fmt(f) + } +} + +impl<'tcx> std::ops::Deref for Layout<'tcx> { + type Target = LayoutData; + fn deref(&self) -> &LayoutData { + self.0.0 } } -impl<'tcx, C> TyAbiInterface<'tcx, C> for Ty<'tcx> +impl<'tcx> Layout<'tcx> { + pub fn fields(self) -> &'tcx FieldsShape { + &self.0.0.fields + } + + pub fn variants(self) -> &'tcx Variants { + &self.0.0.variants + } + + pub fn backend_repr(self) -> BackendRepr { + self.0.0.backend_repr + } + + pub fn largest_niche(self) -> Option { + self.0.0.largest_niche + } + + pub fn align(self) -> AbiAlign { + self.0.0.align + } + + pub fn size(self) -> Size { + self.0.0.size + } + + pub fn max_repr_align(self) -> Option { + self.0.0.max_repr_align + } + + pub fn unadjusted_abi_align(self) -> Align { + self.0.0.unadjusted_abi_align + } +} + +impl<'tcx> rustc_type_ir::inherent::Layout> for Layout<'tcx> { + fn fields(self) -> &'tcx FieldsShape { + self.fields() + } + + fn variants(self) -> &'tcx Variants { + self.variants() + } + + fn backend_repr(self) -> BackendRepr { + self.backend_repr() + } + + fn largest_niche(self) -> Option { + self.largest_niche() + } + + fn align(self) -> AbiAlign { + self.align() + } + + fn size(self) -> Size { + self.size() + } + + fn max_repr_align(self) -> Option { + self.max_repr_align() + } + + fn unadjusted_abi_align(self) -> Align { + self.unadjusted_abi_align() + } +} + +impl<'tcx, C> TyAbiInterface for TyCtxt<'tcx> where C: HasTyCtxt<'tcx> + HasTypingEnv<'tcx>, { @@ -1346,7 +1429,7 @@ pub enum FnAbiRequest<'tcx> { pub trait FnAbiOfHelpers<'tcx>: LayoutOfHelpers<'tcx> { /// The `&FnAbi`-wrapping type (or `&FnAbi` itself), which will be /// returned from `fn_abi_of_*` (see also `handle_fn_abi_err`). - type FnAbiOfResult: MaybeResult<&'tcx FnAbi<'tcx, Ty<'tcx>>> = &'tcx FnAbi<'tcx, Ty<'tcx>>; + type FnAbiOfResult: MaybeResult<&'tcx FnAbi<'tcx>> = &'tcx FnAbi<'tcx>; /// Helper used for `fn_abi_of_*`, to adapt `tcx.fn_abi_of_*(...)` into a /// `Self::FnAbiOfResult` (which does not need to be a `Result<...>`). @@ -1360,7 +1443,7 @@ pub trait FnAbiOfHelpers<'tcx>: LayoutOfHelpers<'tcx> { err: FnAbiError<'tcx>, span: Span, fn_abi_request: FnAbiRequest<'tcx>, - ) -> >>>::Error; + ) -> >>::Error; } /// Blanket extension trait for contexts that can compute `FnAbi`s. @@ -1467,3 +1550,17 @@ pub trait FnAbiOf<'tcx>: FnAbiOfHelpers<'tcx> { } impl<'tcx, C: FnAbiOfHelpers<'tcx>> FnAbiOf<'tcx> for C {} + +// Some types are used a lot. Make sure they don't unintentionally get bigger. +#[cfg(target_pointer_width = "64")] +mod size_asserts { + use rustc_data_structures::static_assert_size; + + use super::*; + // FIXME: ideally these asserts would be at the definitions for ArgAbi and FnAbi, + // but they need an I: Interner, so we have to do it here + // tidy-alphabetical-start + static_assert_size!(ArgAbi<'_>, 56); + static_assert_size!(FnAbi<'_>, 80); + // tidy-alphabetical-end +} diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 98b44f072075a..49a4123d89462 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -52,7 +52,6 @@ use rustc_session::config::OptLevel; pub use rustc_session::lint::RegisteredTools; use rustc_span::hygiene::MacroKind; use rustc_span::{DUMMY_SP, ExpnId, ExpnKind, Ident, Span, Symbol}; -use rustc_target::callconv::FnAbi; pub use rustc_type_ir::data_structures::{DelayedMap, DelayedSet}; pub use rustc_type_ir::fast_reject::DeepRejectCtxt; #[allow( @@ -85,6 +84,7 @@ pub use self::context::{ }; pub use self::fold::*; pub use self::instance::{Instance, InstanceKind, ReifyReason, ShimKind}; +pub use self::layout::{ArgAbi, FnAbi, Layout, TyAndLayout}; pub(crate) use self::list::RawList; pub use self::list::{List, ListWithCachedTypeInfo}; pub use self::opaque_types::OpaqueTypeKey; @@ -1886,8 +1886,8 @@ impl<'tcx> TyCtxt<'tcx> { } /// Arena-alloc of LayoutError for coroutine layout - fn layout_error(self, err: LayoutError<'tcx>) -> &'tcx LayoutError<'tcx> { - self.arena.alloc(err) + fn layout_error(self, err: LayoutError<'tcx>) -> LayoutError<'tcx> { + err } /// Returns layout of a non-async-drop coroutine. Layout might be unavailable if the @@ -1899,7 +1899,7 @@ impl<'tcx> TyCtxt<'tcx> { self, def_id: DefId, args: GenericArgsRef<'tcx>, - ) -> Result<&'tcx CoroutineLayout<'tcx>, &'tcx LayoutError<'tcx>> { + ) -> Result<&'tcx CoroutineLayout<'tcx>, LayoutError<'tcx>> { let coroutine_kind_ty = args.as_coroutine().kind_ty(); let mir = self.optimized_mir(def_id); let ty = || Ty::new_coroutine(self, def_id, args); @@ -1940,7 +1940,7 @@ impl<'tcx> TyCtxt<'tcx> { self, def_id: DefId, args: GenericArgsRef<'tcx>, - ) -> Result<&'tcx CoroutineLayout<'tcx>, &'tcx LayoutError<'tcx>> { + ) -> Result<&'tcx CoroutineLayout<'tcx>, LayoutError<'tcx>> { let ty = || Ty::new_coroutine(self, def_id, args); if args[0].has_placeholders() || args[0].has_non_region_param() { return Err(self.layout_error(LayoutError::TooGeneric(ty()))); @@ -1957,7 +1957,7 @@ impl<'tcx> TyCtxt<'tcx> { self, def_id: DefId, args: GenericArgsRef<'tcx>, - ) -> Result<&'tcx CoroutineLayout<'tcx>, &'tcx LayoutError<'tcx>> { + ) -> Result<&'tcx CoroutineLayout<'tcx>, LayoutError<'tcx>> { if self.is_async_drop_in_place_coroutine(def_id) { // layout of `async_drop_in_place::{closure}` in case, // when T is a coroutine, contains this internal coroutine's ptr in upvars @@ -2291,7 +2291,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn fn_abi_of_instance( self, query: ty::PseudoCanonicalInput<'tcx, (ty::Instance<'tcx>, &'tcx ty::List>)>, - ) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> { + ) -> Result<&'tcx FnAbi<'tcx>, &'tcx FnAbiError<'tcx>> { // Only deduce attrs in full, optimized builds. Otherwise, avoid the query system overhead // of ever invoking the `fn_abi_of_instance_raw` query. if self.sess.opts.optimize != OptLevel::No && self.sess.opts.incremental.is_none() { diff --git a/compiler/rustc_middle/src/ty/offload_meta.rs b/compiler/rustc_middle/src/ty/offload_meta.rs index 9d0fcc50ef224..6c1be7cf857fc 100644 --- a/compiler/rustc_middle/src/ty/offload_meta.rs +++ b/compiler/rustc_middle/src/ty/offload_meta.rs @@ -1,8 +1,8 @@ use bitflags::bitflags; -use rustc_abi::{BackendRepr, TyAbiInterface}; -use rustc_target::callconv::ArgAbi; +use rustc_abi::BackendRepr; -use crate::ty::{self, PseudoCanonicalInput, Ty, TyCtxt, TypingEnv}; +use crate::ty::layout::{HasTyCtxt, HasTypingEnv}; +use crate::ty::{self, ArgAbi, PseudoCanonicalInput, Ty, TyCtxt, TypingEnv}; #[derive(Debug, Copy, Clone)] pub struct OffloadMetadata { @@ -70,10 +70,10 @@ impl OffloadMetadata { cx: &C, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, - arg_abi: &ArgAbi<'tcx, Ty<'tcx>>, + arg_abi: &ArgAbi<'tcx>, ) -> Vec<(Self, Ty<'tcx>)> where - Ty<'tcx>: TyAbiInterface<'tcx, C>, + C: HasTyCtxt<'tcx> + HasTypingEnv<'tcx>, { match arg_abi.layout.backend_repr { BackendRepr::ScalarPair(_, _) => (0..2) diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 49bac6a130231..1b9956cd5a6fe 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -5,7 +5,6 @@ use std::fmt::{self, Debug}; -use rustc_abi::TyAndLayout; use rustc_hir::def::Namespace; use rustc_hir::def_id::LocalDefId; use rustc_span::Spanned; @@ -15,8 +14,8 @@ use super::{GenericArg, GenericArgKind, Pattern, Region}; use crate::mir::PlaceElem; use crate::ty::print::{FmtPrinter, Printer, with_no_trimmed_paths}; use crate::ty::{ - self, FallibleTypeFolder, Lift, Term, TermKind, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, - TypeSuperVisitable, TypeVisitable, TypeVisitor, + self, FallibleTypeFolder, Lift, Term, TermKind, Ty, TyAndLayout, TyCtxt, TypeFoldable, + TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitor, }; impl fmt::Debug for ty::TraitDef { @@ -733,7 +732,7 @@ impl<'tcx> TypeFoldable> for rustc_span::ErrorGuaranteed { } } -impl<'tcx> TypeVisitable> for TyAndLayout<'tcx, Ty<'tcx>> { +impl<'tcx> TypeVisitable> for TyAndLayout<'tcx> { fn visit_with>>(&self, visitor: &mut V) -> V::Result { visitor.visit_ty(self.ty) } diff --git a/compiler/rustc_monomorphize/src/mono_checks/abi_check.rs b/compiler/rustc_monomorphize/src/mono_checks/abi_check.rs index 0e30f1f3828e6..f905d2c764d66 100644 --- a/compiler/rustc_monomorphize/src/mono_checks/abi_check.rs +++ b/compiler/rustc_monomorphize/src/mono_checks/abi_check.rs @@ -3,10 +3,10 @@ use rustc_abi::{BackendRepr, CanonAbi, ExternAbi, RegKind, X86Call}; use rustc_hir::{CRATE_HIR_ID, HirId}; use rustc_middle::mir::{self, Location, traversal}; -use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TyCtxt}; +use rustc_middle::ty::{self, FnAbi, Instance, InstanceKind, Ty, TyCtxt}; use rustc_span::def_id::DefId; use rustc_span::{DUMMY_SP, Span, Symbol, sym}; -use rustc_target::callconv::{FnAbi, PassMode}; +use rustc_target::callconv::PassMode; use crate::diagnostics; @@ -50,7 +50,7 @@ fn passes_vectors_by_value(mode: &PassMode, repr: &BackendRepr) -> UsesVectorReg /// this is only relevant for the wording in the emitted error. fn do_check_simd_vector_abi<'tcx>( tcx: TyCtxt<'tcx>, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, def_id: DefId, is_call: bool, loc: impl Fn() -> (Span, HirId), @@ -130,7 +130,7 @@ fn do_check_simd_vector_abi<'tcx>( /// this is only relevant for the wording in the emitted error. fn do_check_unsized_params<'tcx>( tcx: TyCtxt<'tcx>, - fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &FnAbi<'tcx>, is_call: bool, loc: impl Fn() -> (Span, HirId), ) { diff --git a/compiler/rustc_passes/src/abi_test.rs b/compiler/rustc_passes/src/abi_test.rs index d60f826c0ac2b..472eb10e74490 100644 --- a/compiler/rustc_passes/src/abi_test.rs +++ b/compiler/rustc_passes/src/abi_test.rs @@ -4,9 +4,8 @@ use rustc_hir::def_id::LocalDefId; use rustc_hir::find_attr; use rustc_middle::span_bug; use rustc_middle::ty::layout::{FnAbiError, LayoutError}; -use rustc_middle::ty::{self, GenericArgs, Instance, Ty, TyCtxt}; +use rustc_middle::ty::{self, FnAbi, GenericArgs, Instance, TyCtxt}; use rustc_span::Span; -use rustc_target::callconv::FnAbi; use super::layout_test::ensure_wf; use crate::diagnostics::{AbiInvalidAttribute, AbiNe, AbiOf, UnrecognizedArgument}; @@ -37,10 +36,10 @@ pub fn test_abi(tcx: TyCtxt<'_>) { } fn unwrap_fn_abi<'tcx>( - abi: Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>>, + abi: Result<&'tcx FnAbi<'tcx>, &'tcx FnAbiError<'tcx>>, tcx: TyCtxt<'tcx>, item_def_id: LocalDefId, -) -> &'tcx FnAbi<'tcx, Ty<'tcx>> { +) -> &'tcx FnAbi<'tcx> { match abi { Ok(abi) => abi, Err(FnAbiError::Layout(layout_error)) => { @@ -92,7 +91,7 @@ fn dump_abi_of_fn_item( } } -fn test_abi_eq<'tcx>(abi1: &'tcx FnAbi<'tcx, Ty<'tcx>>, abi2: &'tcx FnAbi<'tcx, Ty<'tcx>>) -> bool { +fn test_abi_eq<'tcx>(abi1: &'tcx FnAbi<'tcx>, abi2: &'tcx FnAbi<'tcx>) -> bool { if abi1.conv != abi2.conv || abi1.args.len() != abi2.args.len() || abi1.c_variadic != abi2.c_variadic diff --git a/compiler/rustc_passes/src/layout_test.rs b/compiler/rustc_passes/src/layout_test.rs index 19f2ca3af9232..e6e28e319ff4f 100644 --- a/compiler/rustc_passes/src/layout_test.rs +++ b/compiler/rustc_passes/src/layout_test.rs @@ -7,6 +7,7 @@ use rustc_middle::span_bug; use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutError, LayoutOfHelpers}; use rustc_middle::ty::{self, Ty, TyCtxt, Unnormalized}; use rustc_span::Span; +use rustc_target::callconv::homogeneous_aggregate; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::infer::TyCtxtInferExt; use rustc_trait_selection::traits; @@ -82,7 +83,7 @@ fn dump_layout_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId, kinds: &[RustcDumpLa } RustcDumpLayoutKind::HomogenousAggregate => { let data = - ty_layout.homogeneous_aggregate(&UnwrapLayoutCx { tcx, typing_env }); + homogeneous_aggregate(&UnwrapLayoutCx { tcx, typing_env }, ty_layout); format!("homogeneous_aggregate: {data:?}") } RustcDumpLayoutKind::Size => format!("size: {:?}", ty_layout.size), diff --git a/compiler/rustc_public/src/unstable/convert/internal.rs b/compiler/rustc_public/src/unstable/convert/internal.rs index 181498443073d..efff2fa2bae89 100644 --- a/compiler/rustc_public/src/unstable/convert/internal.rs +++ b/compiler/rustc_public/src/unstable/convert/internal.rs @@ -683,7 +683,7 @@ impl RustcInternal for Span { } impl RustcInternal for Layout { - type T<'tcx> = rustc_abi::Layout<'tcx>; + type T<'tcx> = rustc_middle::ty::Layout<'tcx>; fn internal<'tcx>( &self, diff --git a/compiler/rustc_public/src/unstable/convert/stable/abi.rs b/compiler/rustc_public/src/unstable/convert/stable/abi.rs index 7e0b04f8a7f61..9eda280749a47 100644 --- a/compiler/rustc_public/src/unstable/convert/stable/abi.rs +++ b/compiler/rustc_public/src/unstable/convert/stable/abi.rs @@ -38,7 +38,7 @@ impl<'tcx> Stable<'tcx> for rustc_abi::Endian { } } -impl<'tcx> Stable<'tcx> for rustc_abi::TyAndLayout<'tcx, ty::Ty<'tcx>> { +impl<'tcx> Stable<'tcx> for ty::TyAndLayout<'tcx> { type T = TyAndLayout; fn stable<'cx>( @@ -50,7 +50,7 @@ impl<'tcx> Stable<'tcx> for rustc_abi::TyAndLayout<'tcx, ty::Ty<'tcx>> { } } -impl<'tcx> Stable<'tcx> for rustc_abi::Layout<'tcx> { +impl<'tcx> Stable<'tcx> for ty::Layout<'tcx> { type T = Layout; fn stable<'cx>( @@ -80,7 +80,7 @@ impl<'tcx> Stable<'tcx> for rustc_abi::LayoutData Stable<'tcx> for callconv::FnAbi<'tcx, ty::Ty<'tcx>> { +impl<'tcx> Stable<'tcx> for ty::FnAbi<'tcx> { type T = FnAbi; fn stable<'cx>( @@ -100,7 +100,7 @@ impl<'tcx> Stable<'tcx> for callconv::FnAbi<'tcx, ty::Ty<'tcx>> { } } -impl<'tcx> Stable<'tcx> for callconv::ArgAbi<'tcx, ty::Ty<'tcx>> { +impl<'tcx> Stable<'tcx> for ty::ArgAbi<'tcx> { type T = ArgAbi; fn stable<'cx>( diff --git a/compiler/rustc_public_bridge/Cargo.toml b/compiler/rustc_public_bridge/Cargo.toml index 918de4a393cff..11c436743bf03 100644 --- a/compiler/rustc_public_bridge/Cargo.toml +++ b/compiler/rustc_public_bridge/Cargo.toml @@ -12,5 +12,4 @@ rustc_hir_pretty = { path = "../rustc_hir_pretty" } rustc_middle = { path = "../rustc_middle" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } -rustc_target = { path = "../rustc_target" } # tidy-alphabetical-end diff --git a/compiler/rustc_public_bridge/src/alloc.rs b/compiler/rustc_public_bridge/src/alloc.rs index 7e6af3425465a..379821b523b00 100644 --- a/compiler/rustc_public_bridge/src/alloc.rs +++ b/compiler/rustc_public_bridge/src/alloc.rs @@ -4,11 +4,11 @@ //! the actual memory allocations. The stable interface in `rustc_public::alloc` //! delegates all query-related operations to this implementation. -use rustc_abi::{Size, TyAndLayout}; +use rustc_abi::Size; use rustc_middle::mir::interpret::{ AllocId, AllocInit, AllocRange, Allocation, ConstAllocation, Pointer, Scalar, alloc_range, }; -use rustc_middle::ty::{Ty, layout}; +use rustc_middle::ty::{Ty, TyAndLayout, layout}; use super::{CompilerCtxt, Tables}; use crate::bridge::Allocation as _; @@ -17,13 +17,13 @@ use crate::{Bridge, Error}; pub fn create_ty_and_layout<'tcx, B: Bridge>( cx: &CompilerCtxt<'tcx, B>, ty: Ty<'tcx>, -) -> Result>, &'tcx layout::LayoutError<'tcx>> { +) -> Result, layout::LayoutError<'tcx>> { use crate::context::TypingEnvHelpers; cx.tcx.layout_of(cx.fully_monomorphized().as_query_input(ty)) } pub fn try_new_scalar<'tcx, B: Bridge>( - layout: TyAndLayout<'tcx, Ty<'tcx>>, + layout: TyAndLayout<'tcx>, scalar: Scalar, cx: &CompilerCtxt<'tcx, B>, ) -> Result { @@ -37,7 +37,7 @@ pub fn try_new_scalar<'tcx, B: Bridge>( } pub fn try_new_slice<'tcx, B: Bridge>( - layout: TyAndLayout<'tcx, Ty<'tcx>>, + layout: TyAndLayout<'tcx>, alloc_id: AllocId, meta: u64, cx: &CompilerCtxt<'tcx, B>, diff --git a/compiler/rustc_public_bridge/src/context/impls.rs b/compiler/rustc_public_bridge/src/context/impls.rs index 87a8661edeb65..7519e1a1c9096 100644 --- a/compiler/rustc_public_bridge/src/context/impls.rs +++ b/compiler/rustc_public_bridge/src/context/impls.rs @@ -4,7 +4,7 @@ use std::iter; -use rustc_abi::{Endian, Layout, ReprOptions}; +use rustc_abi::{Endian, ReprOptions}; use rustc_hir::def::DefKind; use rustc_hir::{Attribute, LangItem}; use rustc_middle::mir::interpret::{AllocId, ConstAllocation, ErrorHandled, GlobalAlloc, Scalar}; @@ -16,15 +16,14 @@ use rustc_middle::ty::print::{ use rustc_middle::ty::util::Discr; use rustc_middle::ty::{ AdtDef, AdtKind, AssocItem, Binder, ClosureKind, CoroutineArgsExt, EarlyBinder, - ExistentialTraitRef, FnSig, GenericArgsRef, Instance, InstanceKind, IntrinsicDef, List, - PolyFnSig, ScalarInt, TraitDef, TraitRef, Ty, TyCtxt, TyKind, TypeVisitableExt, UintTy, - ValTree, VariantDef, VtblEntry, + ExistentialTraitRef, FnAbi, FnSig, GenericArgsRef, Instance, InstanceKind, IntrinsicDef, + Layout, List, PolyFnSig, ScalarInt, TraitDef, TraitRef, Ty, TyCtxt, TyKind, TypeVisitableExt, + UintTy, ValTree, VariantDef, VtblEntry, }; use rustc_middle::{mir, ty}; use rustc_session::cstore::ForeignModule; use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_span::{Span, Symbol}; -use rustc_target::callconv::FnAbi; use super::{AllocRangeHelpers, CompilerCtxt, TyHelpers, TypingEnvHelpers}; use crate::builder::BodyBuilder; @@ -616,15 +615,12 @@ impl<'tcx, B: Bridge> CompilerCtxt<'tcx, B> { } /// Get an instance ABI. - pub fn instance_abi( - &self, - instance: ty::Instance<'tcx>, - ) -> Result<&FnAbi<'tcx, Ty<'tcx>>, B::Error> { + pub fn instance_abi(&self, instance: ty::Instance<'tcx>) -> Result<&FnAbi<'tcx>, B::Error> { Ok(self.fn_abi_of_instance(instance, List::empty())?) } /// Get the ABI of a function pointer. - pub fn fn_ptr_abi(&self, sig: PolyFnSig<'tcx>) -> Result<&FnAbi<'tcx, Ty<'tcx>>, B::Error> { + pub fn fn_ptr_abi(&self, sig: PolyFnSig<'tcx>) -> Result<&FnAbi<'tcx>, B::Error> { Ok(self.fn_abi_of_fn_ptr(sig, List::empty())?) } diff --git a/compiler/rustc_public_bridge/src/context/mod.rs b/compiler/rustc_public_bridge/src/context/mod.rs index 857a2d4e26bce..a97a29881ce7c 100644 --- a/compiler/rustc_public_bridge/src/context/mod.rs +++ b/compiler/rustc_public_bridge/src/context/mod.rs @@ -33,7 +33,7 @@ impl<'tcx, B: Bridge> CompilerCtxt<'tcx, B> { /// Implement error handling for extracting function ABI information. impl<'tcx, B: Bridge> FnAbiOfHelpers<'tcx> for CompilerCtxt<'tcx, B> { - type FnAbiOfResult = Result<&'tcx rustc_target::callconv::FnAbi<'tcx, Ty<'tcx>>, B::Error>; + type FnAbiOfResult = Result<&'tcx rustc_middle::ty::FnAbi<'tcx>, B::Error>; #[inline] fn handle_fn_abi_err( diff --git a/compiler/rustc_public_bridge/src/lib.rs b/compiler/rustc_public_bridge/src/lib.rs index d598f88a00d27..715588f842289 100644 --- a/compiler/rustc_public_bridge/src/lib.rs +++ b/compiler/rustc_public_bridge/src/lib.rs @@ -49,7 +49,7 @@ pub struct Tables<'tcx, B: Bridge> { pub instances: IndexMap, B::InstanceDef>, pub ty_consts: IndexMap, B::TyConstId>, pub mir_consts: IndexMap, B::MirConstId>, - pub layouts: IndexMap, B::Layout>, + pub layouts: IndexMap, B::Layout>, } impl<'tcx, B: Bridge> Default for Tables<'tcx, B> { @@ -105,7 +105,7 @@ impl<'tcx, B: Bridge> Tables<'tcx, B> { self.instances.create_or_fetch(instance) } - pub fn layout_id(&mut self, layout: rustc_abi::Layout<'tcx>) -> B::Layout { + pub fn layout_id(&mut self, layout: ty::Layout<'tcx>) -> B::Layout { self.layouts.create_or_fetch(layout) } diff --git a/compiler/rustc_query_impl/src/handle_cycle_error.rs b/compiler/rustc_query_impl/src/handle_cycle_error.rs index 7e7ed3ab3b525..8999176437669 100644 --- a/compiler/rustc_query_impl/src/handle_cycle_error.rs +++ b/compiler/rustc_query_impl/src/handle_cycle_error.rs @@ -133,7 +133,7 @@ pub(crate) fn layout_of<'tcx>( _key: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>, cycle: Cycle<'tcx>, err: Diag<'_>, -) -> Result, &'tcx ty::layout::LayoutError<'tcx>> { +) -> Result, ty::layout::LayoutError<'tcx>> { let _guar = err.delay_as_bug(); let diag = search_for_cycle_permutation( &cycle.frames, diff --git a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/mod.rs b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/mod.rs index 82e18ad497b0a..bef31222c3e67 100644 --- a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/mod.rs +++ b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/mod.rs @@ -7,8 +7,8 @@ use rustc_abi::CanonAbi; use rustc_data_structures::fx::FxHashMap; use rustc_middle::bug; -use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable, TypeVisitableExt}; -use rustc_target::callconv::{FnAbi, PassMode}; +use rustc_middle::ty::{self, FnAbi, Instance, TyCtxt, TypeFoldable, TypeVisitableExt}; +use rustc_target::callconv::PassMode; use tracing::instrument; mod encode; @@ -24,7 +24,7 @@ use crate::cfi::typeid::itanium_cxx_abi::transform::{ #[instrument(level = "trace", skip(tcx))] pub fn typeid_for_fnabi<'tcx>( tcx: TyCtxt<'tcx>, - fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &FnAbi<'tcx>, options: TypeIdOptions, ) -> String { // A name is mangled by prefixing "_Z" to an encoding of its name, and in the case of functions diff --git a/compiler/rustc_sanitizers/src/cfi/typeid/mod.rs b/compiler/rustc_sanitizers/src/cfi/typeid/mod.rs index 3de0c31212568..b0050d38ccf0e 100644 --- a/compiler/rustc_sanitizers/src/cfi/typeid/mod.rs +++ b/compiler/rustc_sanitizers/src/cfi/typeid/mod.rs @@ -5,8 +5,7 @@ //! see design document in the tracking issue #89653. use bitflags::bitflags; -use rustc_middle::ty::{Instance, Ty, TyCtxt}; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::{FnAbi, Instance, TyCtxt}; bitflags! { /// Options for typeid_for_fnabi. @@ -39,7 +38,7 @@ pub mod itanium_cxx_abi; /// Returns a type metadata identifier for the specified FnAbi. pub fn typeid_for_fnabi<'tcx>( tcx: TyCtxt<'tcx>, - fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &FnAbi<'tcx>, options: TypeIdOptions, ) -> String { itanium_cxx_abi::typeid_for_fnabi(tcx, fn_abi, options) diff --git a/compiler/rustc_sanitizers/src/kcfi/typeid/mod.rs b/compiler/rustc_sanitizers/src/kcfi/typeid/mod.rs index 23aa088c68ffa..03e0862d22668 100644 --- a/compiler/rustc_sanitizers/src/kcfi/typeid/mod.rs +++ b/compiler/rustc_sanitizers/src/kcfi/typeid/mod.rs @@ -6,8 +6,7 @@ use std::hash::Hasher; -use rustc_middle::ty::{Instance, InstanceKind, ReifyReason, ShimKind, Ty, TyCtxt}; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::{FnAbi, Instance, InstanceKind, ReifyReason, ShimKind, TyCtxt}; use twox_hash::XxHash64; pub use crate::cfi::typeid::{TypeIdOptions, itanium_cxx_abi}; @@ -15,7 +14,7 @@ pub use crate::cfi::typeid::{TypeIdOptions, itanium_cxx_abi}; /// Returns a KCFI type metadata identifier for the specified FnAbi. pub fn typeid_for_fnabi<'tcx>( tcx: TyCtxt<'tcx>, - fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &FnAbi<'tcx>, options: TypeIdOptions, ) -> u32 { // A KCFI type metadata identifier is a 32-bit constant produced by taking the lower half of the diff --git a/compiler/rustc_serialize/src/serialize.rs b/compiler/rustc_serialize/src/serialize.rs index 1cb09e8a1ee2e..a1f09bf9b5328 100644 --- a/compiler/rustc_serialize/src/serialize.rs +++ b/compiler/rustc_serialize/src/serialize.rs @@ -7,6 +7,7 @@ use std::hash::{BuildHasher, Hash}; use std::marker::{PhantomData, PointeeSized}; use std::num::NonZero; use std::path; +use std::range::RangeInclusive; use std::rc::Rc; use std::sync::Arc; @@ -253,6 +254,33 @@ impl Decodable for NonZero { } } +impl Encodable for NonZero { + fn encode(&self, s: &mut S) { + s.emit_usize(self.get()); + } +} + +impl Decodable for NonZero { + fn decode(d: &mut D) -> Self { + NonZero::new(d.read_usize()).unwrap() + } +} + +impl> Encodable for RangeInclusive { + fn encode(&self, s: &mut S) { + self.start.encode(s); + self.last.encode(s); + } +} + +impl> Decodable for RangeInclusive { + fn decode(d: &mut D) -> Self { + let start = I::decode(d); + let last = I::decode(d); + Self { start, last } + } +} + impl Encodable for str { fn encode(&self, s: &mut S) { s.emit_str(self); diff --git a/compiler/rustc_target/Cargo.toml b/compiler/rustc_target/Cargo.toml index d399bfcda50b5..a319e31661e43 100644 --- a/compiler/rustc_target/Cargo.toml +++ b/compiler/rustc_target/Cargo.toml @@ -7,6 +7,7 @@ edition = "2024" # tidy-alphabetical-start arrayvec = { version = "0.7", default-features = false } bitflags = "2.4.1" +derive-where = "1.6.1" object = { version = "0.37.0", default-features = false, features = ["elf", "macho"] } rustc_abi = { path = "../rustc_abi" } rustc_data_structures = { path = "../rustc_data_structures" } @@ -15,6 +16,7 @@ rustc_fs_util = { path = "../rustc_fs_util" } rustc_macros = { path = "../rustc_macros" } rustc_serialize = { path = "../rustc_serialize" } rustc_span = { path = "../rustc_span" } +rustc_type_ir = { path = "../rustc_type_ir" } schemars = "1.0.4" serde = "1.0.219" serde_derive = "1.0.219" diff --git a/compiler/rustc_target/src/callconv/aarch64.rs b/compiler/rustc_target/src/callconv/aarch64.rs index ce69427cbdd59..700762dadc5c1 100644 --- a/compiler/rustc_target/src/callconv/aarch64.rs +++ b/compiler/rustc_target/src/callconv/aarch64.rs @@ -1,8 +1,9 @@ use std::iter; -use rustc_abi::{BackendRepr, HasDataLayout, Primitive, TyAbiInterface}; +use rustc_abi::{BackendRepr, HasDataLayout, Primitive, Reg, RegKind}; +use rustc_type_ir::{Interner, TyAbiInterface}; -use crate::callconv::{ArgAbi, FnAbi, Reg, RegKind, Uniform}; +use crate::callconv::{ArgAbi, FnAbi, Uniform, homogeneous_aggregate}; use crate::spec::{HasTargetSpec, RustcAbi, Target}; /// Indicates the variant of the AArch64 ABI we are compiling for. @@ -17,12 +18,13 @@ pub(crate) enum AbiKind { } #[tracing::instrument(skip(cx), level = "debug")] -fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option +fn is_homogeneous_aggregate(cx: &C, arg: &mut ArgAbi) -> Option where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, + I::Ty: std::fmt::Display, C: HasDataLayout + HasTargetSpec, { - arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { + homogeneous_aggregate(cx, arg.layout).ok().and_then(|ha| ha.unit()).and_then(|unit| { let size = arg.layout.size; // Ensure we have at most four uniquely addressable members. @@ -42,7 +44,7 @@ where }) } -fn softfloat_float_abi(target: &Target, arg: &mut ArgAbi<'_, Ty>) { +fn softfloat_float_abi(target: &Target, arg: &mut ArgAbi) { if target.rustc_abi != Some(RustcAbi::Softfloat) { return; } @@ -75,9 +77,9 @@ fn softfloat_float_abi(target: &Target, arg: &mut ArgAbi<'_, Ty>) { } #[tracing::instrument(skip(cx), level = "debug")] -fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, kind: AbiKind) +fn classify_ret(cx: &C, ret: &mut ArgAbi, kind: AbiKind) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout + HasTargetSpec, { if !ret.layout.is_sized() || ret.layout.is_scalable_vector() { @@ -108,9 +110,9 @@ where } #[tracing::instrument(skip(cx), level = "debug")] -fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, kind: AbiKind) +fn classify_arg(cx: &C, arg: &mut ArgAbi, kind: AbiKind) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout + HasTargetSpec, { if !arg.layout.is_sized() || arg.layout.is_scalable_vector() { @@ -157,9 +159,9 @@ where arg.make_indirect(); } -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>, kind: AbiKind) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi, kind: AbiKind) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout + HasTargetSpec, { if !fn_abi.ret.is_ignore() { @@ -174,9 +176,9 @@ where } } -pub(crate) fn compute_rust_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_rust_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout + HasTargetSpec, { for arg in fn_abi.args.iter_mut().chain(iter::once(&mut fn_abi.ret)) { diff --git a/compiler/rustc_target/src/callconv/amdgpu.rs b/compiler/rustc_target/src/callconv/amdgpu.rs index 98ab3ce8eb746..8d2845eed5e1a 100644 --- a/compiler/rustc_target/src/callconv/amdgpu.rs +++ b/compiler/rustc_target/src/callconv/amdgpu.rs @@ -1,18 +1,19 @@ -use rustc_abi::{HasDataLayout, TyAbiInterface}; +use rustc_abi::HasDataLayout; +use rustc_type_ir::{Interner, TyAbiInterface}; use crate::callconv::{ArgAbi, FnAbi}; -fn classify_ret<'a, Ty, C>(_cx: &C, ret: &mut ArgAbi<'a, Ty>) +fn classify_ret(_cx: &C, ret: &mut ArgAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { ret.extend_integer_width_to(32); } -fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) +fn classify_arg(cx: &C, arg: &mut ArgAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { if arg.layout.pass_indirectly_in_non_rustic_abis(cx) { @@ -22,9 +23,9 @@ where arg.extend_integer_width_to(32); } -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/callconv/arm.rs b/compiler/rustc_target/src/callconv/arm.rs index 41c3a0a0210fb..e9f90e6259158 100644 --- a/compiler/rustc_target/src/callconv/arm.rs +++ b/compiler/rustc_target/src/callconv/arm.rs @@ -1,14 +1,15 @@ -use rustc_abi::{ArmCall, CanonAbi, HasDataLayout, TyAbiInterface}; +use rustc_abi::{ArmCall, CanonAbi, HasDataLayout, Reg, RegKind}; +use rustc_type_ir::{Interner, TyAbiInterface}; -use crate::callconv::{ArgAbi, FnAbi, Reg, RegKind, Uniform}; +use crate::callconv::{ArgAbi, FnAbi, Uniform, homogeneous_aggregate}; use crate::spec::HasTargetSpec; -fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option +fn is_homogeneous_aggregate(cx: &C, arg: &mut ArgAbi) -> Option where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { - arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { + homogeneous_aggregate(cx, arg.layout).ok().and_then(|ha| ha.unit()).and_then(|unit| { let size = arg.layout.size; // Ensure we have at most four uniquely addressable members. @@ -26,9 +27,9 @@ where }) } -fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, vfp: bool) +fn classify_ret(cx: &C, ret: &mut ArgAbi, vfp: bool) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { if !ret.layout.is_sized() { @@ -56,9 +57,9 @@ where ret.make_indirect(); } -fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, vfp: bool) +fn classify_arg(cx: &C, arg: &mut ArgAbi, vfp: bool) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { if !arg.layout.is_sized() { @@ -86,9 +87,9 @@ where arg.cast_to(Uniform::consecutive(if align <= 4 { Reg::i32() } else { Reg::i64() }, total)); } -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout + HasTargetSpec, { // If this is a target with a hard-float ABI, and the function is not explicitly diff --git a/compiler/rustc_target/src/callconv/avr.rs b/compiler/rustc_target/src/callconv/avr.rs index 0646d3c8ea1a4..e77d012da4326 100644 --- a/compiler/rustc_target/src/callconv/avr.rs +++ b/compiler/rustc_target/src/callconv/avr.rs @@ -30,19 +30,19 @@ //! compatible with AVR-GCC - Rust and AVR-GCC only differ in the small amount //! of compiler frontend specific calling convention logic implemented here. -use rustc_abi::TyAbiInterface; +use rustc_type_ir::{Interner, TyAbiInterface}; use crate::callconv::{ArgAbi, FnAbi}; -fn classify_ret_ty(ret: &mut ArgAbi<'_, Ty>) { +fn classify_ret_ty(ret: &mut ArgAbi) { if ret.layout.is_aggregate() { ret.make_indirect(); } } -fn classify_arg_ty<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) +fn classify_arg_ty(cx: &C, arg: &mut ArgAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if arg.layout.pass_indirectly_in_non_rustic_abis(cx) { arg.make_indirect(); @@ -53,9 +53,9 @@ where } } -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fty: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fty: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if !fty.ret.is_ignore() { classify_ret_ty(&mut fty.ret); diff --git a/compiler/rustc_target/src/callconv/bpf.rs b/compiler/rustc_target/src/callconv/bpf.rs index 3624f406704e9..ebb5f840fa2e4 100644 --- a/compiler/rustc_target/src/callconv/bpf.rs +++ b/compiler/rustc_target/src/callconv/bpf.rs @@ -1,9 +1,9 @@ // see https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/BPF/BPFCallingConv.td -use rustc_abi::TyAbiInterface; +use rustc_type_ir::{Interner, TyAbiInterface}; use crate::callconv::{ArgAbi, FnAbi}; -fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { +fn classify_ret(ret: &mut ArgAbi) { if ret.layout.is_aggregate() || ret.layout.size.bits() > 64 { ret.make_indirect(); } else { @@ -11,9 +11,9 @@ fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { } } -fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) +fn classify_arg(cx: &C, arg: &mut ArgAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if arg.layout.pass_indirectly_in_non_rustic_abis(cx) { arg.make_indirect(); @@ -26,9 +26,9 @@ where } } -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if !fn_abi.ret.is_ignore() { classify_ret(&mut fn_abi.ret); @@ -42,7 +42,7 @@ where } } -pub(crate) fn compute_rust_abi_info(fn_abi: &mut FnAbi<'_, Ty>) { +pub(crate) fn compute_rust_abi_info(fn_abi: &mut FnAbi) { if !fn_abi.ret.is_ignore() { classify_ret(&mut fn_abi.ret); } diff --git a/compiler/rustc_target/src/callconv/csky.rs b/compiler/rustc_target/src/callconv/csky.rs index 95741f137feab..a9c0a613c7a31 100644 --- a/compiler/rustc_target/src/callconv/csky.rs +++ b/compiler/rustc_target/src/callconv/csky.rs @@ -4,11 +4,12 @@ // Reference: Clang CSKY lowering code // https://github.com/llvm/llvm-project/blob/4a074f32a6914f2a8d7215d78758c24942dddc3d/clang/lib/CodeGen/Targets/CSKY.cpp#L76-L162 -use rustc_abi::TyAbiInterface; +use rustc_abi::Reg; +use rustc_type_ir::{Interner, TyAbiInterface}; -use crate::callconv::{ArgAbi, FnAbi, Reg, Uniform}; +use crate::callconv::{ArgAbi, FnAbi, Uniform}; -fn classify_ret(arg: &mut ArgAbi<'_, Ty>) { +fn classify_ret(arg: &mut ArgAbi) { if !arg.layout.is_sized() { // Not touching this... return; @@ -29,9 +30,9 @@ fn classify_ret(arg: &mut ArgAbi<'_, Ty>) { } } -fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) +fn classify_arg(cx: &C, arg: &mut ArgAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if !arg.layout.is_sized() { // Not touching this... @@ -56,9 +57,9 @@ where } } -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if !fn_abi.ret.is_ignore() { classify_ret(&mut fn_abi.ret); diff --git a/compiler/rustc_target/src/callconv/hexagon.rs b/compiler/rustc_target/src/callconv/hexagon.rs index 1e0f1f769c3b0..08f6d0daf8ee3 100644 --- a/compiler/rustc_target/src/callconv/hexagon.rs +++ b/compiler/rustc_target/src/callconv/hexagon.rs @@ -1,10 +1,11 @@ -use rustc_abi::{HasDataLayout, TyAbiInterface}; +use rustc_abi::{HasDataLayout, Reg}; +use rustc_type_ir::{Interner, TyAbiInterface}; -use crate::callconv::{ArgAbi, FnAbi, Reg, Uniform}; +use crate::callconv::{ArgAbi, FnAbi, Uniform}; -fn classify_ret<'a, Ty, C>(_cx: &C, ret: &mut ArgAbi<'a, Ty>) +fn classify_ret(_cx: &C, ret: &mut ArgAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { if !ret.layout.is_sized() { @@ -31,9 +32,9 @@ where } } -fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) +fn classify_arg(cx: &C, arg: &mut ArgAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { if !arg.layout.is_sized() { @@ -64,9 +65,9 @@ where } } -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/callconv/loongarch.rs b/compiler/rustc_target/src/callconv/loongarch.rs index 6d3826abf27a8..fb14c4c2ebd96 100644 --- a/compiler/rustc_target/src/callconv/loongarch.rs +++ b/compiler/rustc_target/src/callconv/loongarch.rs @@ -1,7 +1,5 @@ -use rustc_abi::{ - BackendRepr, FieldsShape, HasDataLayout, Primitive, Reg, RegKind, Size, TyAbiInterface, - TyAndLayout, Variants, -}; +use rustc_abi::{BackendRepr, FieldsShape, HasDataLayout, Primitive, Reg, RegKind, Size, Variants}; +use rustc_type_ir::{Interner, TyAbiInterface, TyAndLayout}; use crate::callconv::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Uniform}; use crate::spec::{HasTargetSpec, LlvmAbi}; @@ -23,16 +21,16 @@ enum FloatConv { #[derive(Copy, Clone)] struct CannotUseFpConv; -fn is_loongarch_aggregate(arg: &ArgAbi<'_, Ty>) -> bool { +fn is_loongarch_aggregate(arg: &ArgAbi) -> bool { match arg.layout.backend_repr { BackendRepr::SimdVector { .. } => true, _ => arg.layout.is_aggregate(), } } -fn should_use_fp_conv_helper<'a, Ty, C>( +fn should_use_fp_conv_helper( cx: &C, - arg_layout: &TyAndLayout<'a, Ty>, + arg_layout: &TyAndLayout, xlen: u64, flen: u64, field1_kind: &mut RegPassKind, @@ -40,7 +38,7 @@ fn should_use_fp_conv_helper<'a, Ty, C>( offset_from_start: Size, ) -> Result<(), CannotUseFpConv> where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { match arg_layout.backend_repr { BackendRepr::Scalar(scalar) => match scalar.primitive() { @@ -147,14 +145,14 @@ where Ok(()) } -fn should_use_fp_conv<'a, Ty, C>( +fn should_use_fp_conv( cx: &C, - arg: &TyAndLayout<'a, Ty>, + arg: &TyAndLayout, xlen: u64, flen: u64, ) -> Option where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { let mut field1_kind = RegPassKind::Unknown; let mut field2_kind = RegPassKind::Unknown; @@ -208,9 +206,9 @@ where } } -fn classify_ret<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, xlen: u64, flen: u64) -> bool +fn classify_ret(cx: &C, arg: &mut ArgAbi, xlen: u64, flen: u64) -> bool where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if !arg.layout.is_sized() { // Not touching this... @@ -275,16 +273,16 @@ where false } -fn classify_arg<'a, Ty, C>( +fn classify_arg( cx: &C, - arg: &mut ArgAbi<'a, Ty>, + arg: &mut ArgAbi, xlen: u64, flen: u64, is_vararg: bool, avail_gprs: &mut u64, avail_fprs: &mut u64, ) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if !arg.layout.is_sized() { // Not touching this... @@ -394,7 +392,7 @@ fn classify_arg<'a, Ty, C>( } } -fn extend_integer_width(arg: &mut ArgAbi<'_, Ty>, xlen: u64) { +fn extend_integer_width(arg: &mut ArgAbi, xlen: u64) { if let BackendRepr::Scalar(scalar) = arg.layout.backend_repr && let Primitive::Int(i, _) = scalar.primitive() && i.size().bits() == 32 @@ -409,9 +407,9 @@ fn extend_integer_width(arg: &mut ArgAbi<'_, Ty>, xlen: u64) { arg.extend_integer_width_to(xlen); } -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout + HasTargetSpec, { let xlen = cx.data_layout().pointer_size().bits(); @@ -444,9 +442,9 @@ where } } -pub(crate) fn compute_rust_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_rust_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout + HasTargetSpec, { let grlen = cx.data_layout().pointer_size().bits(); diff --git a/compiler/rustc_target/src/callconv/m68k.rs b/compiler/rustc_target/src/callconv/m68k.rs index f4668b4afbd20..2c9a6cc6cdd94 100644 --- a/compiler/rustc_target/src/callconv/m68k.rs +++ b/compiler/rustc_target/src/callconv/m68k.rs @@ -1,8 +1,8 @@ -use rustc_abi::TyAbiInterface; +use rustc_type_ir::{Interner, TyAbiInterface}; use crate::callconv::{ArgAbi, FnAbi}; -fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { +fn classify_ret(ret: &mut ArgAbi) { if ret.layout.is_aggregate() { ret.make_indirect(); } else { @@ -10,9 +10,9 @@ fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { } } -fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) +fn classify_arg(cx: &C, arg: &mut ArgAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if !arg.layout.is_sized() { // Not touching this... @@ -29,9 +29,9 @@ where } } -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if !fn_abi.ret.is_ignore() { classify_ret(&mut fn_abi.ret); diff --git a/compiler/rustc_target/src/callconv/mips.rs b/compiler/rustc_target/src/callconv/mips.rs index d2572cc035c1c..cdd65318109c3 100644 --- a/compiler/rustc_target/src/callconv/mips.rs +++ b/compiler/rustc_target/src/callconv/mips.rs @@ -1,8 +1,9 @@ -use rustc_abi::{HasDataLayout, Size, TyAbiInterface}; +use rustc_abi::{HasDataLayout, Reg, Size}; +use rustc_type_ir::{Interner, TyAbiInterface}; -use crate::callconv::{ArgAbi, FnAbi, Reg, Uniform}; +use crate::callconv::{ArgAbi, FnAbi, Uniform}; -fn classify_ret(cx: &C, ret: &mut ArgAbi<'_, Ty>, offset: &mut Size) +fn classify_ret(cx: &C, ret: &mut ArgAbi, offset: &mut Size) where C: HasDataLayout, { @@ -14,9 +15,9 @@ where } } -fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, offset: &mut Size) +fn classify_arg(cx: &C, arg: &mut ArgAbi, offset: &mut Size) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { if !arg.layout.is_sized() { @@ -44,9 +45,9 @@ where *offset = offset.align_to(align) + size.align_to(align); } -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { let mut offset = Size::ZERO; diff --git a/compiler/rustc_target/src/callconv/mips64.rs b/compiler/rustc_target/src/callconv/mips64.rs index f17e59c12e57e..a592fbfa94df2 100644 --- a/compiler/rustc_target/src/callconv/mips64.rs +++ b/compiler/rustc_target/src/callconv/mips64.rs @@ -1,11 +1,10 @@ use arrayvec::ArrayVec; -use rustc_abi::{ - BackendRepr, FieldsShape, Float, HasDataLayout, Primitive, Reg, Size, TyAbiInterface, -}; +use rustc_abi::{BackendRepr, FieldsShape, Float, HasDataLayout, Primitive, Reg, Size}; +use rustc_type_ir::{Interner, TyAbiInterface}; use crate::callconv::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Uniform}; -fn extend_integer_width_mips(arg: &mut ArgAbi<'_, Ty>, bits: u64) { +fn extend_integer_width_mips(arg: &mut ArgAbi, bits: u64) { // Always sign extend u32 values on 64-bit mips if let BackendRepr::Scalar(scalar) = arg.layout.backend_repr && let Primitive::Int(i, signed) = scalar.primitive() @@ -20,9 +19,9 @@ fn extend_integer_width_mips(arg: &mut ArgAbi<'_, Ty>, bits: u64) { arg.extend_integer_width_to(bits); } -fn float_reg<'a, Ty, C>(cx: &C, ret: &ArgAbi<'a, Ty>, i: usize) -> Option +fn float_reg(cx: &C, ret: &ArgAbi, i: usize) -> Option where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { match ret.layout.field(cx, i).backend_repr { @@ -35,9 +34,9 @@ where } } -fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, offset: &mut Size) +fn classify_ret(cx: &C, ret: &mut ArgAbi, offset: &mut Size) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { if !ret.layout.is_aggregate() { @@ -75,9 +74,9 @@ where } } -fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, offset: &mut Size) +fn classify_arg(cx: &C, arg: &mut ArgAbi, offset: &mut Size) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { let dl = cx.data_layout(); @@ -144,9 +143,9 @@ where *offset = offset.align_to(align) + size.align_to(align); } -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { // mips64 argument passing is also affected by the alignment of aggregates. diff --git a/compiler/rustc_target/src/callconv/mod.rs b/compiler/rustc_target/src/callconv/mod.rs index 30d16b5c7b1c9..e7a0a85692033 100644 --- a/compiler/rustc_target/src/callconv/mod.rs +++ b/compiler/rustc_target/src/callconv/mod.rs @@ -1,11 +1,15 @@ +#![allow(rustc::direct_use_of_rustc_type_ir)] + use std::{fmt, iter}; use arrayvec::ArrayVec; +use derive_where::derive_where; use rustc_abi::{ - AddressSpace, Align, BackendRepr, CanonAbi, ExternAbi, FieldsShape, HasDataLayout, Primitive, - Reg, RegKind, Scalar, Size, TyAbiInterface, TyAndLayout, Variants, + AddressSpace, Align, BackendRepr, CanonAbi, ExternAbi, FieldsShape, HasDataLayout, + Heterogeneous, HomogeneousAggregate, Primitive, Reg, RegKind, Scalar, Size, Variants, }; -use rustc_macros::StableHash; +use rustc_macros::{StableHash, StableHash_NoContext}; +use rustc_type_ir::{Interner, TyAbiInterface, TyAndLayout}; pub use crate::spec::AbiMap; use crate::spec::{Arch, HasTargetSpec, HasX86AbiOpt}; @@ -373,25 +377,29 @@ impl CastTarget { /// Information about how to pass an argument to, /// or return a value from, a function, under some ABI. -#[derive(Clone, PartialEq, Eq, Hash, StableHash)] -pub struct ArgAbi<'a, Ty> { - pub layout: TyAndLayout<'a, Ty>, +#[derive_where(Clone, PartialEq, Eq, Hash; I: Interner)] +#[derive(StableHash_NoContext)] +pub struct ArgAbi { + pub layout: TyAndLayout, pub mode: PassMode, } // Needs to be a custom impl because of the bounds on the `TyAndLayout` debug impl. -impl<'a, Ty: fmt::Display> fmt::Debug for ArgAbi<'a, Ty> { +impl fmt::Debug for ArgAbi +where + I::Ty: fmt::Display, +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let ArgAbi { layout, mode } = self; f.debug_struct("ArgAbi").field("layout", layout).field("mode", mode).finish() } } -impl<'a, Ty> ArgAbi<'a, Ty> { +impl ArgAbi { /// This defines the "default ABI" for that type, that is then later adjusted in `fn_abi_adjust_for_abi`. pub fn new( cx: &impl HasDataLayout, - layout: TyAndLayout<'a, Ty>, + layout: TyAndLayout, scalar_attrs: impl Fn(Scalar, Size) -> ArgAttributes, ) -> Self { let mode = match layout.backend_repr { @@ -408,7 +416,7 @@ impl<'a, Ty> ArgAbi<'a, Ty> { ArgAbi { layout, mode } } - fn indirect_pass_mode(layout: &TyAndLayout<'a, Ty>) -> PassMode { + fn indirect_pass_mode(layout: &TyAndLayout) -> PassMode { let mut attrs = ArgAttributes::new(); // For non-immediate arguments the callee gets its own copy of @@ -553,10 +561,7 @@ impl<'a, Ty> ArgAbi<'a, Ty> { /// Checks if these two `ArgAbi` are equal enough to be considered "the same for all /// function call ABIs". - pub fn eq_abi(&self, other: &Self) -> bool - where - Ty: PartialEq, - { + pub fn eq_abi(&self, other: &Self) -> bool { // Ideally we'd just compare the `mode`, but that is not enough -- for some modes LLVM will look // at the type. self.layout.eq_abi(&other.layout) && self.mode.eq_abi(&other.mode) && { @@ -600,13 +605,14 @@ impl RiscvInterruptKind { /// /// I will do my best to describe this structure, but these /// comments are reverse-engineered and may be inaccurate. -NDM -#[derive(Clone, PartialEq, Eq, Hash, StableHash)] -pub struct FnAbi<'a, Ty> { +#[derive_where(Clone, PartialEq, Eq, Hash; I: Interner)] +#[derive(StableHash_NoContext)] +pub struct FnAbi { /// The type, layout, and information about how each argument is passed. - pub args: Box<[ArgAbi<'a, Ty>]>, + pub args: Box<[ArgAbi]>, /// The layout, type, and the way a value is returned from this function. - pub ret: ArgAbi<'a, Ty>, + pub ret: ArgAbi, /// Marks this function as variadic (accepting a variable number of arguments). pub c_variadic: bool, @@ -623,7 +629,7 @@ pub struct FnAbi<'a, Ty> { } // Needs to be a custom impl because of the bounds on the `TyAndLayout` debug impl. -impl<'a, Ty: fmt::Display> fmt::Debug for FnAbi<'a, Ty> { +impl fmt::Debug for FnAbi { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let FnAbi { args, ret, c_variadic, fixed_count, conv, can_unwind } = self; f.debug_struct("FnAbi") @@ -637,10 +643,10 @@ impl<'a, Ty: fmt::Display> fmt::Debug for FnAbi<'a, Ty> { } } -impl<'a, Ty> FnAbi<'a, Ty> { +impl FnAbi { pub fn adjust_for_foreign_abi(&mut self, cx: &C, abi: ExternAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface + Copy, C: HasDataLayout + HasTargetSpec + HasX86AbiOpt, { if abi == ExternAbi::X86Interrupt { @@ -727,7 +733,7 @@ impl<'a, Ty> FnAbi<'a, Ty> { pub fn adjust_for_rust_abi(&mut self, cx: &C) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout + HasTargetSpec, { let spec = cx.target_spec(); @@ -864,15 +870,158 @@ impl<'a, Ty> FnAbi<'a, Ty> { } } +/// Returns `Homogeneous` if this layout is an aggregate containing fields of +/// only a single type (e.g., `(u32, u32)`). Such aggregates are often +/// special-cased in ABIs. +/// +/// Note: We generally ignore 1-ZST fields when computing this value (see #56877). +/// +/// This is public so that it can be used in unit tests, but +/// should generally only be relevant to the ABI details of +/// specific targets. +#[tracing::instrument(skip(cx), level = "debug")] +pub fn homogeneous_aggregate( + cx: &C, + layout: TyAndLayout, +) -> Result +where + I: TyAbiInterface, + I::Ty: std::fmt::Display, +{ + match layout.backend_repr { + // The primitive for this algorithm. + BackendRepr::Scalar(scalar) => { + let kind = match scalar.primitive() { + Primitive::Int(..) | Primitive::Pointer(_) => RegKind::Integer, + Primitive::Float(_) => RegKind::Float, + }; + Ok(HomogeneousAggregate::Homogeneous(Reg { kind, size: layout.size })) + } + + BackendRepr::SimdVector { element, count: _ } => { + assert!(!layout.is_zst()); + + Ok(HomogeneousAggregate::Homogeneous(Reg { + kind: RegKind::Vector { hint_vector_elem: element.primitive() }, + size: layout.size, + })) + } + + BackendRepr::SimdScalableVector { .. } => { + unreachable!("`homogeneous_aggregate` should not be called for scalable vectors") + } + + BackendRepr::ScalarPair(..) | BackendRepr::Memory { sized: true } => { + // Helper for computing `homogeneous_aggregate`, allowing a custom + // starting offset (used below for handling variants). + let from_fields_at = + |layout: TyAndLayout, + start: Size| + -> Result<(HomogeneousAggregate, Size), Heterogeneous> { + let is_union = match layout.fields { + FieldsShape::Primitive => { + unreachable!("aggregates can't have `FieldsShape::Primitive`") + } + FieldsShape::Array { count, .. } => { + assert_eq!(start, Size::ZERO); + + let result = if count > 0 { + homogeneous_aggregate(cx, layout.field(cx, 0))? + } else { + HomogeneousAggregate::NoData + }; + return Ok((result, layout.size)); + } + FieldsShape::Union(_) => true, + FieldsShape::Arbitrary { .. } => false, + }; + + let mut result = HomogeneousAggregate::NoData; + let mut total = start; + + for i in 0..layout.fields.count() { + let field = layout.field(cx, i); + if field.is_1zst() { + // No data here and no impact on layout, can be ignored. + // (We might be able to also ignore all aligned ZST but that's less clear.) + continue; + } + + if !is_union && total != layout.fields.offset(i) { + // This field isn't just after the previous one we considered, abort. + return Err(Heterogeneous); + } + + result = result.merge(homogeneous_aggregate(cx, field)?)?; + + // Keep track of the offset (without padding). + let size = field.size; + if is_union { + total = total.max(size); + } else { + total += size; + } + } + + Ok((result, total)) + }; + + let (mut result, mut total) = from_fields_at(layout, Size::ZERO)?; + + match &layout.variants { + Variants::Single { .. } | Variants::Empty => {} + Variants::Multiple { variants, .. } => { + // Treat enum variants like union members. + // HACK(eddyb) pretend the `enum` field (discriminant) + // is at the start of every variant (otherwise the gap + // at the start of all variants would disqualify them). + // + // NB: for all tagged `enum`s (which include all non-C-like + // `enum`s with defined FFI representation), this will + // match the homogeneous computation on the equivalent + // `struct { tag; union { variant1; ... } }` and/or + // `union { struct { tag; variant1; } ... }` + // (the offsets of variant fields should be identical + // between the two for either to be a homogeneous aggregate). + let variant_start = total; + for variant_idx in variants.indices() { + let (variant_result, variant_total) = + from_fields_at(layout.for_variant(cx, variant_idx), variant_start)?; + + result = result.merge(variant_result)?; + total = total.max(variant_total); + } + } + } + + // There needs to be no padding. + if total != layout.size { + Err(Heterogeneous) + } else { + match result { + HomogeneousAggregate::Homogeneous(_) => { + assert_ne!(total, Size::ZERO); + } + HomogeneousAggregate::NoData => { + assert_eq!(total, Size::ZERO); + } + } + Ok(result) + } + } + BackendRepr::Memory { sized: false } => Err(Heterogeneous), + } +} + /// Determines whether `layout` contains no uninit bytes (no padding, no unions), /// using only the computed layout. /// /// Conservative: returns `false` for anything it cannot prove fully initialized, /// including multi-variant enums and SIMD vectors. // FIXME: extend to multi-variant enums (per-variant padding analysis needed). -fn layout_is_noundef<'a, Ty, C>(layout: TyAndLayout<'a, Ty>, cx: &C) -> bool +fn layout_is_noundef(layout: TyAndLayout, cx: &C) -> bool where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { match layout.backend_repr { @@ -902,9 +1051,9 @@ where /// Returns `true` if the fields of `layout` contiguously cover bytes `0..layout.size` /// with no padding gaps and each field is recursively `layout_is_noundef`. -fn fields_are_noundef<'a, Ty, C>(layout: TyAndLayout<'a, Ty>, cx: &C) -> bool +fn fields_are_noundef(layout: TyAndLayout, cx: &C) -> bool where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { let mut cursor = Size::ZERO; @@ -923,15 +1072,3 @@ where } cursor == layout.size } - -// Some types are used a lot. Make sure they don't unintentionally get bigger. -#[cfg(target_pointer_width = "64")] -mod size_asserts { - use rustc_data_structures::static_assert_size; - - use super::*; - // tidy-alphabetical-start - static_assert_size!(ArgAbi<'_, usize>, 56); - static_assert_size!(FnAbi<'_, usize>, 80); - // tidy-alphabetical-end -} diff --git a/compiler/rustc_target/src/callconv/msp430.rs b/compiler/rustc_target/src/callconv/msp430.rs index 7d2336346beb5..9490ed6d5f91a 100644 --- a/compiler/rustc_target/src/callconv/msp430.rs +++ b/compiler/rustc_target/src/callconv/msp430.rs @@ -1,7 +1,7 @@ // Reference: MSP430 Embedded Application Binary Interface // https://www.ti.com/lit/an/slaa534a/slaa534a.pdf -use rustc_abi::TyAbiInterface; +use rustc_type_ir::{Interner, TyAbiInterface}; use crate::callconv::{ArgAbi, FnAbi}; @@ -11,7 +11,7 @@ use crate::callconv::{ArgAbi, FnAbi}; // returned by reference. To pass a structure or union by reference, the caller // places its address in the appropriate location: either in a register or on // the stack, according to its position in the argument list. (..)" -fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { +fn classify_ret(ret: &mut ArgAbi) { if ret.layout.is_aggregate() && ret.layout.size.bits() > 32 { ret.make_indirect(); } else { @@ -19,9 +19,9 @@ fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { } } -fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) +fn classify_arg(cx: &C, arg: &mut ArgAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if arg.layout.pass_indirectly_in_non_rustic_abis(cx) { arg.make_indirect(); @@ -34,9 +34,9 @@ where } } -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if !fn_abi.ret.is_ignore() { classify_ret(&mut fn_abi.ret); diff --git a/compiler/rustc_target/src/callconv/nvptx64.rs b/compiler/rustc_target/src/callconv/nvptx64.rs index 3919b7a69a78b..c1e562c6978dd 100644 --- a/compiler/rustc_target/src/callconv/nvptx64.rs +++ b/compiler/rustc_target/src/callconv/nvptx64.rs @@ -1,10 +1,11 @@ use arrayvec::ArrayVec; -use rustc_abi::{HasDataLayout, Reg, Size, TyAbiInterface}; +use rustc_abi::{HasDataLayout, Reg, Size}; +use rustc_type_ir::{Interner, TyAbiInterface}; use super::CastTarget; use crate::callconv::{ArgAbi, FnAbi, Uniform}; -fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { +fn classify_ret(ret: &mut ArgAbi) { if ret.layout.is_aggregate() && ret.layout.is_sized() { classify_aggregate(ret) } else if ret.layout.size.bits() < 32 && ret.layout.is_sized() { @@ -12,9 +13,9 @@ fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { } } -fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) +fn classify_arg(cx: &C, arg: &mut ArgAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if arg.layout.pass_indirectly_in_non_rustic_abis(cx) { arg.make_indirect(); @@ -28,7 +29,7 @@ where } /// the pass mode used for aggregates in arg and ret position -fn classify_aggregate(arg: &mut ArgAbi<'_, Ty>) { +fn classify_aggregate(arg: &mut ArgAbi) { let align_bytes = arg.layout.align.bytes(); let size = arg.layout.size; @@ -50,9 +51,9 @@ fn classify_aggregate(arg: &mut ArgAbi<'_, Ty>) { } } -fn classify_arg_kernel<'a, Ty, C>(_cx: &C, arg: &mut ArgAbi<'a, Ty>) +fn classify_arg_kernel(_cx: &C, arg: &mut ArgAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { match arg.mode { @@ -87,9 +88,9 @@ where } } -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if !fn_abi.ret.is_ignore() { classify_ret(&mut fn_abi.ret); @@ -103,9 +104,9 @@ where } } -pub(crate) fn compute_ptx_kernel_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_ptx_kernel_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { if !fn_abi.ret.layout.is_unit() && !fn_abi.ret.layout.is_never() { diff --git a/compiler/rustc_target/src/callconv/powerpc.rs b/compiler/rustc_target/src/callconv/powerpc.rs index 2b6a104e1221d..48e9a5fef5a69 100644 --- a/compiler/rustc_target/src/callconv/powerpc.rs +++ b/compiler/rustc_target/src/callconv/powerpc.rs @@ -1,9 +1,9 @@ -use rustc_abi::TyAbiInterface; +use rustc_type_ir::{Interner, TyAbiInterface}; use crate::callconv::{ArgAbi, FnAbi}; use crate::spec::{Env, HasTargetSpec, Os}; -fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { +fn classify_ret(ret: &mut ArgAbi) { if ret.layout.is_aggregate() { ret.make_indirect(); } else { @@ -11,9 +11,9 @@ fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { } } -fn classify_arg<'a, Ty, C: HasTargetSpec>(cx: &C, arg: &mut ArgAbi<'a, Ty>) +fn classify_arg(cx: &C, arg: &mut ArgAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if arg.is_ignore() { // powerpc-unknown-linux-{gnu,musl,uclibc} doesn't ignore ZSTs. @@ -32,9 +32,9 @@ where } } -pub(crate) fn compute_abi_info<'a, Ty, C: HasTargetSpec>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if !fn_abi.ret.is_ignore() { classify_ret(&mut fn_abi.ret); diff --git a/compiler/rustc_target/src/callconv/powerpc64.rs b/compiler/rustc_target/src/callconv/powerpc64.rs index 3eb40abe90f33..096f78c9b783c 100644 --- a/compiler/rustc_target/src/callconv/powerpc64.rs +++ b/compiler/rustc_target/src/callconv/powerpc64.rs @@ -2,9 +2,10 @@ // Alignment of 128 bit types is not currently handled, this will // need to be fixed when PowerPC vector support is added. -use rustc_abi::{HasDataLayout, TyAbiInterface}; +use rustc_abi::HasDataLayout; +use rustc_type_ir::{Interner, TyAbiInterface}; -use crate::callconv::{Align, ArgAbi, FnAbi, Reg, RegKind, Uniform}; +use crate::callconv::{Align, ArgAbi, FnAbi, Reg, RegKind, Uniform, homogeneous_aggregate}; use crate::spec::{HasTargetSpec, LlvmAbi, Os}; #[derive(Debug, Clone, Copy, PartialEq)] @@ -15,16 +16,16 @@ enum ABI { } use ABI::*; -fn is_homogeneous_aggregate<'a, Ty, C>( +fn is_homogeneous_aggregate( cx: &C, - arg: &mut ArgAbi<'a, Ty>, + arg: &mut ArgAbi, abi: ABI, ) -> Option where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { - arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { + homogeneous_aggregate(cx, arg.layout).ok().and_then(|ha| ha.unit()).and_then(|unit| { // ELFv1 and AIX only passes one-member aggregates transparently. // ELFv2 passes up to eight uniquely addressable members. if ((abi == ELFv1 || abi == AIX) && arg.layout.size > unit.size) @@ -43,9 +44,9 @@ where }) } -fn classify<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, abi: ABI, is_ret: bool) +fn classify(cx: &C, arg: &mut ArgAbi, abi: ABI, is_ret: bool) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { if arg.is_ignore() || !arg.layout.is_sized() { @@ -101,9 +102,9 @@ where }; } -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout + HasTargetSpec, { let abi = match cx.target_spec().options.llvm_abiname { diff --git a/compiler/rustc_target/src/callconv/riscv.rs b/compiler/rustc_target/src/callconv/riscv.rs index bc81ec95c86e3..9e03c0548a8b9 100644 --- a/compiler/rustc_target/src/callconv/riscv.rs +++ b/compiler/rustc_target/src/callconv/riscv.rs @@ -4,10 +4,8 @@ // Reference: Clang RISC-V ELF psABI lowering code // https://github.com/llvm/llvm-project/blob/8e780252a7284be45cf1ba224cabd884847e8e92/clang/lib/CodeGen/TargetInfo.cpp#L9311-L9773 -use rustc_abi::{ - BackendRepr, FieldsShape, HasDataLayout, Primitive, Reg, RegKind, Size, TyAbiInterface, - TyAndLayout, Variants, -}; +use rustc_abi::{BackendRepr, FieldsShape, HasDataLayout, Primitive, Reg, RegKind, Size, Variants}; +use rustc_type_ir::{Interner, TyAbiInterface, TyAndLayout}; use crate::callconv::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Uniform}; use crate::spec::{HasTargetSpec, LlvmAbi}; @@ -29,16 +27,16 @@ enum FloatConv { #[derive(Copy, Clone)] struct CannotUseFpConv; -fn is_riscv_aggregate(arg: &ArgAbi<'_, Ty>) -> bool { +fn is_riscv_aggregate(arg: &ArgAbi) -> bool { match arg.layout.backend_repr { BackendRepr::SimdVector { .. } => true, _ => arg.layout.is_aggregate(), } } -fn should_use_fp_conv_helper<'a, Ty, C>( +fn should_use_fp_conv_helper( cx: &C, - arg_layout: &TyAndLayout<'a, Ty>, + arg_layout: &TyAndLayout, xlen: u64, flen: u64, field1_kind: &mut RegPassKind, @@ -46,7 +44,7 @@ fn should_use_fp_conv_helper<'a, Ty, C>( offset_from_start: Size, ) -> Result<(), CannotUseFpConv> where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { match arg_layout.backend_repr { BackendRepr::Scalar(scalar) => match scalar.primitive() { @@ -152,14 +150,14 @@ where Ok(()) } -fn should_use_fp_conv<'a, Ty, C>( +fn should_use_fp_conv( cx: &C, - arg: &TyAndLayout<'a, Ty>, + arg: &TyAndLayout, xlen: u64, flen: u64, ) -> Option where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { let mut field1_kind = RegPassKind::Unknown; let mut field2_kind = RegPassKind::Unknown; @@ -213,9 +211,9 @@ where } } -fn classify_ret<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, xlen: u64, flen: u64) -> bool +fn classify_ret(cx: &C, arg: &mut ArgAbi, xlen: u64, flen: u64) -> bool where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if !arg.layout.is_sized() { // Not touching this... @@ -280,16 +278,16 @@ where false } -fn classify_arg<'a, Ty, C>( +fn classify_arg( cx: &C, - arg: &mut ArgAbi<'a, Ty>, + arg: &mut ArgAbi, xlen: u64, flen: u64, is_vararg: bool, avail_gprs: &mut u64, avail_fprs: &mut u64, ) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if !arg.layout.is_sized() { // FIXME: Update avail_gprs? @@ -400,7 +398,7 @@ fn classify_arg<'a, Ty, C>( } } -fn extend_integer_width(arg: &mut ArgAbi<'_, Ty>, xlen: u64) { +fn extend_integer_width(arg: &mut ArgAbi, xlen: u64) { if let BackendRepr::Scalar(scalar) = arg.layout.backend_repr && let Primitive::Int(i, _) = scalar.primitive() && i.size().bits() == 32 @@ -414,9 +412,9 @@ fn extend_integer_width(arg: &mut ArgAbi<'_, Ty>, xlen: u64) { arg.extend_integer_width_to(xlen); } -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout + HasTargetSpec, { let flen = match &cx.target_spec().llvm_abiname { @@ -449,9 +447,9 @@ where } } -pub(crate) fn compute_rust_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_rust_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout + HasTargetSpec, { let xlen = cx.data_layout().pointer_size().bits(); diff --git a/compiler/rustc_target/src/callconv/s390x.rs b/compiler/rustc_target/src/callconv/s390x.rs index 581c1e2e862c5..b3bc323995ffc 100644 --- a/compiler/rustc_target/src/callconv/s390x.rs +++ b/compiler/rustc_target/src/callconv/s390x.rs @@ -1,12 +1,13 @@ // Reference: ELF Application Binary Interface s390x Supplement // https://github.com/IBM/s390x-abi -use rustc_abi::{BackendRepr, HasDataLayout, TyAbiInterface}; +use rustc_abi::{BackendRepr, HasDataLayout}; +use rustc_type_ir::{Interner, TyAbiInterface}; use crate::callconv::{ArgAbi, FnAbi, Reg}; use crate::spec::{Env, HasTargetSpec, Os}; -fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { +fn classify_ret(ret: &mut ArgAbi) { let size = ret.layout.size; if size.bits() <= 128 && matches!(ret.layout.backend_repr, BackendRepr::SimdVector { .. }) { return; @@ -18,9 +19,9 @@ fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { } } -fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) +fn classify_arg(cx: &C, arg: &mut ArgAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout + HasTargetSpec, { if !arg.layout.is_sized() { @@ -77,9 +78,9 @@ where } } -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout + HasTargetSpec, { if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/callconv/sparc.rs b/compiler/rustc_target/src/callconv/sparc.rs index d424214aa497e..bb9567b54ba33 100644 --- a/compiler/rustc_target/src/callconv/sparc.rs +++ b/compiler/rustc_target/src/callconv/sparc.rs @@ -1,8 +1,9 @@ -use rustc_abi::{HasDataLayout, Size, TyAbiInterface}; +use rustc_abi::{HasDataLayout, Size}; +use rustc_type_ir::{Interner, TyAbiInterface}; use crate::callconv::{ArgAbi, FnAbi, Reg, Uniform}; -fn classify_ret(cx: &C, ret: &mut ArgAbi<'_, Ty>, offset: &mut Size) +fn classify_ret(cx: &C, ret: &mut ArgAbi, offset: &mut Size) where C: HasDataLayout, { @@ -14,9 +15,9 @@ where } } -fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, offset: &mut Size) +fn classify_arg(cx: &C, arg: &mut ArgAbi, offset: &mut Size) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { if !arg.layout.is_sized() { @@ -43,9 +44,9 @@ where *offset = offset.align_to(align) + size.align_to(align); } -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { let mut offset = Size::ZERO; diff --git a/compiler/rustc_target/src/callconv/sparc64.rs b/compiler/rustc_target/src/callconv/sparc64.rs index b5e5c3e2a88b3..ca2a11d86ceb9 100644 --- a/compiler/rustc_target/src/callconv/sparc64.rs +++ b/compiler/rustc_target/src/callconv/sparc64.rs @@ -1,8 +1,8 @@ use arrayvec::ArrayVec; use rustc_abi::{ - Align, BackendRepr, FieldsShape, Float, HasDataLayout, Primitive, Reg, Size, TyAbiInterface, - TyAndLayout, Variants, + Align, BackendRepr, FieldsShape, Float, HasDataLayout, Primitive, Reg, Size, Variants, }; +use rustc_type_ir::{Interner, TyAbiInterface, TyAndLayout}; use crate::callconv::{ArgAbi, ArgAttribute, CastTarget, FnAbi, Uniform}; use crate::spec::{HasTargetSpec, Os}; @@ -24,13 +24,13 @@ enum Word { Integer, } -fn classify<'a, Ty, C>( +fn classify( cx: &C, - arg_layout: &TyAndLayout<'a, Ty>, + arg_layout: &TyAndLayout, offset: Size, double_words: &mut [DoubleWord; 4], ) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { // If this function does not update the `double_words` array, the value will be passed via @@ -100,13 +100,13 @@ fn classify<'a, Ty, C>( } } -fn classify_arg<'a, Ty, C>( +fn classify_arg( cx: &C, - arg: &mut ArgAbi<'a, Ty>, + arg: &mut ArgAbi, in_registers_max: Size, total_double_word_count: &mut usize, ) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { // 64-bit SPARC allocates argument stack space in 64-bit chunks (double words), some of which @@ -193,9 +193,9 @@ fn classify_arg<'a, Ty, C>( arg.cast_to_and_pad_i32(cast_target.with_attrs(attrs.into()), pad); } -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout + HasTargetSpec, { if !fn_abi.ret.is_ignore() && fn_abi.ret.layout.is_sized() { diff --git a/compiler/rustc_target/src/callconv/wasm.rs b/compiler/rustc_target/src/callconv/wasm.rs index 5be8cd5d88f26..1950ba9e1c282 100644 --- a/compiler/rustc_target/src/callconv/wasm.rs +++ b/compiler/rustc_target/src/callconv/wasm.rs @@ -1,14 +1,15 @@ -use rustc_abi::{BackendRepr, Float, HasDataLayout, Integer, Primitive, TyAbiInterface}; +use rustc_abi::{BackendRepr, Float, HasDataLayout, Integer, Primitive}; +use rustc_type_ir::{Interner, TyAbiInterface}; -use crate::callconv::{ArgAbi, FnAbi}; +use crate::callconv::{ArgAbi, FnAbi, homogeneous_aggregate}; -fn unwrap_trivial_aggregate<'a, Ty, C>(cx: &C, val: &mut ArgAbi<'a, Ty>) -> bool +fn unwrap_trivial_aggregate(cx: &C, val: &mut ArgAbi) -> bool where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { if val.layout.is_aggregate() { - if let Some(unit) = val.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()) { + if let Some(unit) = homogeneous_aggregate(cx, val.layout).ok().and_then(|ha| ha.unit()) { let size = val.layout.size; // This size check also catches over-aligned scalars as `size` will be rounded up to a // multiple of the alignment, and the default alignment of all scalar types on wasm @@ -22,9 +23,9 @@ where false } -fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) +fn classify_ret(cx: &C, ret: &mut ArgAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { ret.extend_integer_width_to(32); @@ -43,9 +44,9 @@ where } } -fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) +fn classify_arg(cx: &C, arg: &mut ArgAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { if !arg.layout.is_sized() { @@ -63,9 +64,9 @@ where } /// The purpose of this ABI is to match the C ABI (aka clang) exactly. -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/callconv/x86.rs b/compiler/rustc_target/src/callconv/x86.rs index 81ff1a2a45900..dbd4e7dc002bb 100644 --- a/compiler/rustc_target/src/callconv/x86.rs +++ b/compiler/rustc_target/src/callconv/x86.rs @@ -1,8 +1,7 @@ -use rustc_abi::{ - AddressSpace, Align, BackendRepr, HasDataLayout, Primitive, Reg, RegKind, TyAndLayout, -}; +use rustc_abi::{AddressSpace, Align, BackendRepr, HasDataLayout, Primitive, Reg, RegKind}; +use rustc_type_ir::{Interner, TyAbiInterface, TyAndLayout}; -use crate::callconv::{ArgAttribute, FnAbi, PassMode, TyAbiInterface}; +use crate::callconv::{ArgAttribute, FnAbi, PassMode, homogeneous_aggregate}; use crate::spec::{HasTargetSpec, RustcAbi}; #[derive(PartialEq)] @@ -17,9 +16,9 @@ pub(crate) struct X86Options { pub reg_struct_return: bool, } -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>, opts: X86Options) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi, opts: X86Options) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout + HasTargetSpec, { if !fn_abi.ret.is_ignore() { @@ -87,9 +86,9 @@ where // // 4. If none of these conditions are true, the alignment is 4. - fn contains_vector<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool + fn contains_vector(cx: &C, layout: TyAndLayout) -> bool where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { match layout.backend_repr { BackendRepr::Scalar(_) | BackendRepr::ScalarPair(..) => false, @@ -128,13 +127,13 @@ where fill_inregs(cx, fn_abi, opts, false); } -pub(crate) fn fill_inregs<'a, Ty, C>( +pub(crate) fn fill_inregs( cx: &C, - fn_abi: &mut FnAbi<'a, Ty>, + fn_abi: &mut FnAbi, opts: X86Options, rust_abi: bool, ) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if opts.flavor != Flavor::FastcallOrVectorcall && opts.regparm.is_none_or(|x| x == 0) { return; @@ -172,7 +171,7 @@ pub(crate) fn fill_inregs<'a, Ty, C>( }; // At this point we know this must be a primitive of sorts. - let unit = arg.layout.homogeneous_aggregate(cx).unwrap().unit().unwrap(); + let unit = homogeneous_aggregate(cx, arg.layout).unwrap().unit().unwrap(); assert_eq!(unit.size, arg.layout.size); if matches!(unit.kind, RegKind::Float | RegKind::Vector { .. }) { continue; @@ -200,9 +199,9 @@ pub(crate) fn fill_inregs<'a, Ty, C>( } } -pub(crate) fn compute_rust_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_rust_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout + HasTargetSpec, { // Avoid returning floats in x87 registers on x86 as loading and storing from x87 diff --git a/compiler/rustc_target/src/callconv/x86_64.rs b/compiler/rustc_target/src/callconv/x86_64.rs index 3055d18ffa014..1dc8dd5073cfe 100644 --- a/compiler/rustc_target/src/callconv/x86_64.rs +++ b/compiler/rustc_target/src/callconv/x86_64.rs @@ -1,10 +1,8 @@ // The classification code for the x86_64 ABI is taken from the clay language // https://github.com/jckarter/clay/blob/db0bd2702ab0b6e48965cd85f8859bbd5f60e48e/compiler/externals.cpp -use rustc_abi::{ - BackendRepr, HasDataLayout, Primitive, Reg, RegKind, Size, TyAbiInterface, TyAndLayout, - Variants, -}; +use rustc_abi::{BackendRepr, HasDataLayout, Primitive, Reg, RegKind, Size, Variants}; +use rustc_type_ir::{Interner, TyAbiInterface, TyAndLayout}; use crate::callconv::{ArgAbi, CastTarget, FnAbi}; use crate::spec::HasTargetSpec; @@ -26,22 +24,22 @@ struct Memory; const LARGEST_VECTOR_SIZE: usize = 512; const MAX_EIGHTBYTES: usize = LARGEST_VECTOR_SIZE / 64; -fn classify_arg<'a, Ty, C>( +fn classify_arg( cx: &C, - arg: &ArgAbi<'a, Ty>, + arg: &ArgAbi, ) -> Result<[Option; MAX_EIGHTBYTES], Memory> where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { - fn classify<'a, Ty, C>( + fn classify( cx: &C, - layout: TyAndLayout<'a, Ty>, + layout: TyAndLayout, cls: &mut [Option], off: Size, ) -> Result<(), Memory> where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout, { if !off.is_aligned(layout.align.abi) { @@ -175,15 +173,15 @@ fn cast_target(cls: &[Option], size: Size) -> CastTarget { const MAX_INT_REGS: usize = 6; // RDI, RSI, RDX, RCX, R8, R9 const MAX_SSE_REGS: usize = 8; // XMM0-7 -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout + HasTargetSpec, { let mut int_regs = MAX_INT_REGS; let mut sse_regs = MAX_SSE_REGS; - let mut x86_64_arg_or_ret = |arg: &mut ArgAbi<'a, Ty>, is_arg: bool| { + let mut x86_64_arg_or_ret = |arg: &mut ArgAbi, is_arg: bool| { if !arg.layout.is_sized() { // FIXME: Update int_regs? // Not touching this... diff --git a/compiler/rustc_target/src/callconv/x86_win32.rs b/compiler/rustc_target/src/callconv/x86_win32.rs index 824e7cc098a46..a86fceccae2da 100644 --- a/compiler/rustc_target/src/callconv/x86_win32.rs +++ b/compiler/rustc_target/src/callconv/x86_win32.rs @@ -1,14 +1,15 @@ -use rustc_abi::{Align, HasDataLayout, Reg, TyAbiInterface}; +use rustc_abi::{Align, HasDataLayout, Reg}; +use rustc_type_ir::{Interner, TyAbiInterface}; use crate::callconv::FnAbi; use crate::spec::HasTargetSpec; -pub(crate) fn compute_abi_info<'a, Ty, C>( +pub(crate) fn compute_abi_info( cx: &C, - fn_abi: &mut FnAbi<'a, Ty>, + fn_abi: &mut FnAbi, opts: super::x86::X86Options, ) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout + HasTargetSpec, { if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/callconv/x86_win64.rs b/compiler/rustc_target/src/callconv/x86_win64.rs index cece9d032b53a..be678623af771 100644 --- a/compiler/rustc_target/src/callconv/x86_win64.rs +++ b/compiler/rustc_target/src/callconv/x86_win64.rs @@ -1,15 +1,16 @@ -use rustc_abi::{BackendRepr, Float, Integer, Primitive, Size, TyAbiInterface}; +use rustc_abi::{BackendRepr, Float, Integer, Primitive, Size}; +use rustc_type_ir::{Interner, TyAbiInterface}; use crate::callconv::{ArgAbi, FnAbi, Reg}; use crate::spec::{HasTargetSpec, RustcAbi}; // Win64 ABI: https://docs.microsoft.com/en-us/cpp/build/parameter-passing -pub(crate) fn compute_abi_info<'a, Ty, C: HasTargetSpec>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { - let fixup = |a: &mut ArgAbi<'_, Ty>, is_ret: bool| { + let fixup = |a: &mut ArgAbi, is_ret: bool| { match a.layout.backend_repr { BackendRepr::Memory { sized: false } => {} BackendRepr::ScalarPair(..) | BackendRepr::Memory { sized: true } => { diff --git a/compiler/rustc_target/src/callconv/xtensa.rs b/compiler/rustc_target/src/callconv/xtensa.rs index 4dc9fad650636..e1c83b9cd3a8b 100644 --- a/compiler/rustc_target/src/callconv/xtensa.rs +++ b/compiler/rustc_target/src/callconv/xtensa.rs @@ -5,7 +5,8 @@ //! Section 8.1.4 & 8.1.5 of the Xtensa ISA reference manual, as well as snippets from //! Section 2.3 from the Xtensa programmers guide. -use rustc_abi::{BackendRepr, HasDataLayout, Size, TyAbiInterface}; +use rustc_abi::{BackendRepr, HasDataLayout, Size}; +use rustc_type_ir::{Interner, TyAbiInterface}; use crate::callconv::{ArgAbi, FnAbi, Reg, Uniform}; use crate::spec::HasTargetSpec; @@ -15,9 +16,9 @@ const NUM_RET_GPRS: u64 = 4; const MAX_ARG_IN_REGS_SIZE: u64 = NUM_ARG_GPRS * 32; const MAX_RET_IN_REGS_SIZE: u64 = NUM_RET_GPRS * 32; -fn classify_ret_ty<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) +fn classify_ret_ty(cx: &C, arg: &mut ArgAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if arg.is_ignore() { return; @@ -36,13 +37,13 @@ where } } -fn classify_arg_ty<'a, Ty, C>( +fn classify_arg_ty( cx: &C, - arg: &mut ArgAbi<'a, Ty>, + arg: &mut ArgAbi, arg_gprs_left: &mut u64, is_ret: bool, ) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { assert!(*arg_gprs_left <= NUM_ARG_GPRS, "Arg GPR tracking underflow"); @@ -107,9 +108,9 @@ fn classify_arg_ty<'a, Ty, C>( } } -pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +pub(crate) fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, C: HasDataLayout + HasTargetSpec, { if !fn_abi.ret.is_ignore() { @@ -126,7 +127,7 @@ where } } -fn is_xtensa_aggregate<'a, Ty>(arg: &ArgAbi<'a, Ty>) -> bool { +fn is_xtensa_aggregate(arg: &ArgAbi) -> bool { match arg.layout.backend_repr { BackendRepr::SimdVector { .. } => true, _ => arg.layout.is_aggregate(), diff --git a/compiler/rustc_transmute/src/layout/mod.rs b/compiler/rustc_transmute/src/layout/mod.rs index 4e548ff8fe20c..3907c19a96bce 100644 --- a/compiler/rustc_transmute/src/layout/mod.rs +++ b/compiler/rustc_transmute/src/layout/mod.rs @@ -132,9 +132,8 @@ impl Type for () {} #[cfg(feature = "rustc")] pub mod rustc { - use rustc_abi::Layout; use rustc_middle::ty::layout::{HasTyCtxt, LayoutCx, LayoutError}; - use rustc_middle::ty::{self, Region, Ty}; + use rustc_middle::ty::{self, Layout, Region, Ty}; /// A visibility node in the layout. #[derive(Debug, Hash, Eq, PartialEq, Clone, Copy)] @@ -161,7 +160,7 @@ pub mod rustc { pub(crate) fn layout_of<'tcx>( cx: LayoutCx<'tcx>, ty: Ty<'tcx>, - ) -> Result, &'tcx LayoutError<'tcx>> { + ) -> Result, LayoutError<'tcx>> { use rustc_middle::ty::layout::LayoutOf; let ty = cx.tcx().erase_and_anonymize_regions(ty); cx.layout_of(ty).map(|tl| tl.layout) diff --git a/compiler/rustc_transmute/src/layout/tree.rs b/compiler/rustc_transmute/src/layout/tree.rs index d7aeb6b06b82f..a49318b261881 100644 --- a/compiler/rustc_transmute/src/layout/tree.rs +++ b/compiler/rustc_transmute/src/layout/tree.rs @@ -249,12 +249,11 @@ where #[cfg(feature = "rustc")] pub(crate) mod rustc { - use rustc_abi::{ - FieldIdx, FieldsShape, Layout, Size, TagEncoding, TyAndLayout, VariantIdx, Variants, - }; + use rustc_abi::{FieldIdx, FieldsShape, Size, TagEncoding, VariantIdx, Variants}; use rustc_middle::ty::layout::{HasTyCtxt, LayoutCx, LayoutError}; use rustc_middle::ty::{ - self, AdtDef, AdtKind, List, Region, ScalarInt, Ty, TyCtxt, TypeVisitableExt, + self, AdtDef, AdtKind, Layout, List, Region, ScalarInt, Ty, TyAndLayout, TyCtxt, + TypeVisitableExt, }; use rustc_span::ErrorGuaranteed; @@ -273,8 +272,8 @@ pub(crate) mod rustc { TypeError(ErrorGuaranteed), } - impl<'tcx> From<&LayoutError<'tcx>> for Err { - fn from(err: &LayoutError<'tcx>) -> Self { + impl<'tcx> From> for Err { + fn from(err: LayoutError<'tcx>) -> Self { match err { LayoutError::Unknown(..) | LayoutError::ReferencesError(..) diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index 51db1b8efde2f..b3ec226a52fa1 100644 --- a/compiler/rustc_ty_utils/src/abi.rs +++ b/compiler/rustc_ty_utils/src/abi.rs @@ -10,12 +10,10 @@ use rustc_middle::query::Providers; use rustc_middle::ty::layout::{ FnAbiError, HasTyCtxt, HasTypingEnv, LayoutCx, LayoutOf, TyAndLayout, fn_can_unwind, }; -use rustc_middle::ty::{self, InstanceKind, ShimKind, Ty, TyCtxt, Unnormalized}; +use rustc_middle::ty::{self, ArgAbi, FnAbi, InstanceKind, ShimKind, Ty, TyCtxt, Unnormalized}; use rustc_span::DUMMY_SP; use rustc_span::def_id::DefId; -use rustc_target::callconv::{ - AbiMap, ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, FnAbi, PassMode, -}; +use rustc_target::callconv::{AbiMap, ArgAttribute, ArgAttributes, ArgExtension, PassMode}; use tracing::debug; pub(crate) fn provide(providers: &mut Providers) { @@ -291,7 +289,7 @@ impl<'tcx> FnAbiDesc<'tcx> { fn fn_abi_of_fn_ptr<'tcx>( tcx: TyCtxt<'tcx>, query: ty::PseudoCanonicalInput<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List>)>, -) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> { +) -> Result<&'tcx FnAbi<'tcx>, &'tcx FnAbiError<'tcx>> { let desc = FnAbiDesc::for_fn_ptr(tcx, query); fn_abi_new_uncached(desc) } @@ -299,7 +297,7 @@ fn fn_abi_of_fn_ptr<'tcx>( fn fn_abi_of_instance_no_deduced_attrs<'tcx>( tcx: TyCtxt<'tcx>, query: ty::PseudoCanonicalInput<'tcx, (ty::Instance<'tcx>, &'tcx ty::List>)>, -) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> { +) -> Result<&'tcx FnAbi<'tcx>, &'tcx FnAbiError<'tcx>> { let desc = FnAbiDesc::for_instance(tcx, query); fn_abi_new_uncached(desc) } @@ -307,7 +305,7 @@ fn fn_abi_of_instance_no_deduced_attrs<'tcx>( fn fn_abi_of_instance_raw<'tcx>( tcx: TyCtxt<'tcx>, query: ty::PseudoCanonicalInput<'tcx, (ty::Instance<'tcx>, &'tcx ty::List>)>, -) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> { +) -> Result<&'tcx FnAbi<'tcx>, &'tcx FnAbiError<'tcx>> { // The `fn_abi_of_instance_no_deduced_attrs` query may have been called during CTFE, so we // delegate to it here in order to reuse (and, if necessary, augment) its result. tcx.fn_abi_of_instance_no_deduced_attrs(query).map(|fn_abi| { @@ -434,11 +432,7 @@ fn arg_attrs_for_rust_scalar<'tcx>( } /// Ensure that the ABI makes basic sense. -fn fn_abi_sanity_check<'tcx>( - cx: &LayoutCx<'tcx>, - fn_abi: &FnAbi<'tcx, Ty<'tcx>>, - spec_abi: ExternAbi, -) { +fn fn_abi_sanity_check<'tcx>(cx: &LayoutCx<'tcx>, fn_abi: &FnAbi<'tcx>, spec_abi: ExternAbi) { fn fn_arg_attrs_sanity_check(attrs: &ArgAttributes, is_ret: bool) { if attrs.regular.contains(ArgAttribute::NoFree) { assert!(!is_ret, "NoFree not valid on return values"); @@ -447,9 +441,9 @@ fn fn_abi_sanity_check<'tcx>( fn fn_arg_sanity_check<'tcx>( cx: &LayoutCx<'tcx>, - fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &FnAbi<'tcx>, spec_abi: ExternAbi, - arg: &ArgAbi<'tcx, Ty<'tcx>>, + arg: &ArgAbi<'tcx>, is_ret: bool, ) { let tcx = cx.tcx(); @@ -571,7 +565,7 @@ fn fn_abi_new_uncached<'tcx>( is_virtual_call, extra_args, }: FnAbiDesc<'tcx>, -) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> { +) -> Result<&'tcx FnAbi<'tcx>, &'tcx FnAbiError<'tcx>> { let tcx = cx.tcx(); let abi_map = AbiMap::from_target(&tcx.sess.target); @@ -602,7 +596,7 @@ fn fn_abi_new_uncached<'tcx>( let _entered = span.enter(); let is_return = arg_idx.is_none(); - let layout = cx.layout_of(ty).map_err(|err| &*tcx.arena.alloc(FnAbiError::Layout(*err)))?; + let layout = cx.layout_of(ty).map_err(|err| &*tcx.arena.alloc(FnAbiError::Layout(err)))?; let layout = if is_virtual_call && arg_idx == Some(0) { // Don't pass the vtable, it's not an argument of the virtual fn. // Instead, pass just the data pointer, but give it the type `*const/mut dyn Trait` @@ -645,15 +639,11 @@ fn fn_abi_new_uncached<'tcx>( } #[tracing::instrument(level = "trace", skip(cx))] -fn fn_abi_adjust_for_abi<'tcx>( - cx: &LayoutCx<'tcx>, - fn_abi: &mut FnAbi<'tcx, Ty<'tcx>>, - abi: ExternAbi, -) { +fn fn_abi_adjust_for_abi<'tcx>(cx: &LayoutCx<'tcx>, fn_abi: &mut FnAbi<'tcx>, abi: ExternAbi) { if abi == ExternAbi::Unadjusted { // The "unadjusted" ABI passes aggregates in "direct" mode. That's fragile but needed for // some LLVM intrinsics. - fn unadjust<'tcx>(arg: &mut ArgAbi<'tcx, Ty<'tcx>>) { + fn unadjust<'tcx>(arg: &mut ArgAbi<'tcx>) { // This still uses `PassMode::Pair` for ScalarPair types. That's unlikely to be intended, // but who knows what breaks if we change this now. if matches!(arg.layout.backend_repr, BackendRepr::Memory { .. }) { @@ -679,10 +669,10 @@ fn fn_abi_adjust_for_abi<'tcx>( #[tracing::instrument(level = "trace", skip(cx))] fn fn_abi_adjust_for_deduced_attrs<'tcx>( cx: &LayoutCx<'tcx>, - fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>, + fn_abi: &'tcx FnAbi<'tcx>, abi: ExternAbi, fn_def_id: DefId, -) -> &'tcx FnAbi<'tcx, Ty<'tcx>> { +) -> &'tcx FnAbi<'tcx> { let tcx = cx.tcx(); // Look up the deduced parameter attributes for this function, if we have its def ID. // We'll tag its parameters with those attributes as appropriate. @@ -709,7 +699,7 @@ fn apply_deduced_attributes<'tcx>( cx: &LayoutCx<'tcx>, deduced: &[DeducedParamAttrs], idx: usize, - arg: &mut ArgAbi<'tcx, Ty<'tcx>>, + arg: &mut ArgAbi<'tcx>, ) { // Deduction is performed under the assumption of the indirection pass mode. let PassMode::Indirect { ref mut attrs, .. } = arg.mode else { diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index cdf280381247a..0bf563ce51ddb 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -3,7 +3,7 @@ use rustc_abi as abi; use rustc_abi::Integer::{I8, I32}; use rustc_abi::Primitive::{self, Float, Int, Pointer}; use rustc_abi::{ - AddressSpace, BackendRepr, FIRST_VARIANT, FieldIdx, FieldsShape, HasDataLayout, Layout, + AddressSpace, BackendRepr, FIRST_VARIANT, FieldIdx, FieldsShape, HasDataLayout, LayoutCalculatorError, LayoutData, Niche, ReprOptions, Scalar, Size, StructKind, TagEncoding, VariantIdx, Variants, WrappingRange, }; @@ -19,7 +19,7 @@ use rustc_middle::ty::layout::{ }; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{ - self, AdtDef, CoroutineArgsExt, EarlyBinder, PseudoCanonicalInput, Ty, TyCtxt, + self, AdtDef, CoroutineArgsExt, EarlyBinder, Layout, PseudoCanonicalInput, Ty, TyCtxt, TypeVisitableExt, Unnormalized, }; use rustc_session::{DataTypeKind, FieldInfo, FieldKind, SizeKind, VariantInfo}; @@ -38,7 +38,7 @@ pub(crate) fn provide(providers: &mut Providers) { fn layout_of<'tcx>( tcx: TyCtxt<'tcx>, query: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>, -) -> Result, &'tcx LayoutError<'tcx>> { +) -> Result, LayoutError<'tcx>> { let PseudoCanonicalInput { typing_env: original_typing_env, value: original_ty } = query; debug!(?original_ty); @@ -61,10 +61,10 @@ fn layout_of<'tcx>( let normalized_ty = match tcx.try_normalize_erasing_regions(typing_env, unnormalized_ty) { Ok(t) => t, Err(normalization_error) => { - return Err(tcx.arena.alloc(LayoutError::NormalizationFailure( + return Err(LayoutError::NormalizationFailure( unnormalized_ty.skip_normalization(), normalization_error, - ))); + )); } }; @@ -107,15 +107,15 @@ fn layout_of<'tcx>( Ok(layout) } -fn error<'tcx>(cx: &LayoutCx<'tcx>, err: LayoutError<'tcx>) -> &'tcx LayoutError<'tcx> { - cx.tcx().arena.alloc(err) +fn error<'tcx>(_cx: &LayoutCx<'tcx>, err: LayoutError<'tcx>) -> LayoutError<'tcx> { + err } fn map_error<'tcx>( cx: &LayoutCx<'tcx>, ty: Ty<'tcx>, err: LayoutCalculatorError>, -) -> &'tcx LayoutError<'tcx> { +) -> LayoutError<'tcx> { let err = match err { LayoutCalculatorError::SizeOverflow => { // This is sometimes not a compile error in `check` builds. @@ -168,7 +168,7 @@ fn extract_const_value<'tcx>( cx: &LayoutCx<'tcx>, ty: Ty<'tcx>, ct: ty::Const<'tcx>, -) -> Result, &'tcx LayoutError<'tcx>> { +) -> Result, LayoutError<'tcx>> { match ct.kind() { ty::ConstKind::Value(cv) => Ok(cv), ty::ConstKind::Param(_) | ty::ConstKind::Expr(_) => { @@ -204,7 +204,7 @@ fn extract_const_value<'tcx>( fn layout_of_uncached<'tcx>( cx: &LayoutCx<'tcx>, ty: Ty<'tcx>, -) -> Result, &'tcx LayoutError<'tcx>> { +) -> Result, LayoutError<'tcx>> { // Types that reference `ty::Error` pessimistically don't have a meaningful layout. // The only side-effect of this is possibly worse diagnostics in case the layout // was actually computable (like if the `ty::Error` showed up only in a `PhantomData`). diff --git a/compiler/rustc_type_ir/Cargo.toml b/compiler/rustc_type_ir/Cargo.toml index 97cddd857af18..dd3cf0e7e3f9a 100644 --- a/compiler/rustc_type_ir/Cargo.toml +++ b/compiler/rustc_type_ir/Cargo.toml @@ -36,6 +36,7 @@ nightly = [ "dep:rustc_macros", "dep:rustc_serialize", "dep:rustc_span", + "rustc_abi/nightly", "rustc_ast_ir/nightly", "rustc_index/nightly", "rustc_type_ir_macros/nightly", diff --git a/compiler/rustc_type_ir/src/inherent.rs b/compiler/rustc_type_ir/src/inherent.rs index 77e5fcac07b3f..5202e2d73b6ef 100644 --- a/compiler/rustc_type_ir/src/inherent.rs +++ b/compiler/rustc_type_ir/src/inherent.rs @@ -3,9 +3,11 @@ //! scope when programming in interner-agnostic settings, and to avoid importing any of these //! directly elsewhere (i.e. specify the full path for an implementation downstream). -use std::fmt::Debug; +use std::fmt::{Debug, Display}; use std::hash::Hash; +use std::ops::Deref; +use rustc_abi::{AbiAlign, Align, BackendRepr, FieldIdx, LayoutData, Niche, Size, VariantIdx}; use rustc_ast_ir::Mutability; use crate::elaborate::Elaboratable; @@ -21,6 +23,7 @@ use crate::{ pub trait Ty>: Copy + Debug + + Display + Hash + Eq + Into @@ -228,6 +231,20 @@ pub trait Safety>: Copy + Debug + Hash + Eq { fn prefix_str(self) -> &'static str; } +#[rust_analyzer::prefer_underscore_import] +pub trait Layout>: + Copy + Debug + Hash + Eq + Deref> +{ + fn fields(self) -> I::FieldsShapeRef; + fn variants(self) -> I::VariantsRef; + fn backend_repr(self) -> BackendRepr; + fn largest_niche(self) -> Option; + fn align(self) -> AbiAlign; + fn size(self) -> Size; + fn max_repr_align(self) -> Option; + fn unadjusted_abi_align(self) -> Align; +} + #[rust_analyzer::prefer_underscore_import] pub trait Region>: Copy diff --git a/compiler/rustc_type_ir/src/interner.rs b/compiler/rustc_type_ir/src/interner.rs index 815890c989d93..1e9e45610c910 100644 --- a/compiler/rustc_type_ir/src/interner.rs +++ b/compiler/rustc_type_ir/src/interner.rs @@ -170,6 +170,11 @@ pub trait Interner: + SliceLike; type Safety: Safety; + // Layouts + type Layout: Layout; + type FieldsShapeRef; + type VariantsRef; + // Kinds of consts type Const: Const; type Consts: Copy + Debug + Hash + Eq + SliceLike + Default; diff --git a/compiler/rustc_abi/src/layout/ty.rs b/compiler/rustc_type_ir/src/layout.rs similarity index 70% rename from compiler/rustc_abi/src/layout/ty.rs rename to compiler/rustc_type_ir/src/layout.rs index 9ca4aa2254547..749be1f086914 100644 --- a/compiler/rustc_abi/src/layout/ty.rs +++ b/compiler/rustc_type_ir/src/layout.rs @@ -1,70 +1,18 @@ use std::fmt; use std::ops::{Deref, Range}; -use rustc_data_structures::intern::Interned; +use derive_where::derive_where; +use rustc_abi::{ + BackendRepr, FieldIdx, FieldsShape, Float, HasDataLayout, LayoutData, PointeeInfo, Primitive, + Size, VariantIdx, Variants, +}; use rustc_data_structures::range_set::RangeSet; -use rustc_macros::StableHash; +use rustc_macros::StableHash_NoContext; -use crate::layout::{FieldIdx, VariantIdx}; -use crate::{ - AbiAlign, Align, BackendRepr, FieldsShape, Float, HasDataLayout, LayoutData, Niche, - PointeeInfo, Primitive, Size, Variants, -}; +use crate::Interner; // Explicitly import `Float` to avoid ambiguity with `Primitive::Float`. -#[derive(Copy, Clone, PartialEq, Eq, Hash, StableHash)] -#[rustc_pass_by_value] -pub struct Layout<'a>(pub Interned<'a, LayoutData>); - -impl<'a> fmt::Debug for Layout<'a> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - // See comment on `::fmt` above. - self.0.0.fmt(f) - } -} - -impl<'a> Deref for Layout<'a> { - type Target = &'a LayoutData; - fn deref(&self) -> &&'a LayoutData { - &self.0.0 - } -} - -impl<'a> Layout<'a> { - pub fn fields(self) -> &'a FieldsShape { - &self.0.0.fields - } - - pub fn variants(self) -> &'a Variants { - &self.0.0.variants - } - - pub fn backend_repr(self) -> BackendRepr { - self.0.0.backend_repr - } - - pub fn largest_niche(self) -> Option { - self.0.0.largest_niche - } - - pub fn align(self) -> AbiAlign { - self.0.0.align - } - - pub fn size(self) -> Size { - self.0.0.size - } - - pub fn max_repr_align(self) -> Option { - self.0.0.max_repr_align - } - - pub fn unadjusted_abi_align(self) -> Align { - self.0.0.unadjusted_abi_align - } -} - /// The layout of a type, alongside the type itself. /// Provides various type traversal APIs (e.g., recursing into fields). /// @@ -72,13 +20,14 @@ impl<'a> Layout<'a> { /// to that obtained from `layout_of(ty)`, as we need to produce /// layouts for which Rust types do not exist, such as enum variants /// or synthetic fields of enums (i.e., discriminants) and wide pointers. -#[derive(Copy, Clone, PartialEq, Eq, Hash, StableHash)] -pub struct TyAndLayout<'a, Ty> { - pub ty: Ty, - pub layout: Layout<'a>, +#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[cfg_attr(feature = "nightly", derive(StableHash_NoContext))] +pub struct TyAndLayout { + pub ty: I::Ty, + pub layout: I::Layout, } -impl<'a, Ty: fmt::Display> fmt::Debug for TyAndLayout<'a, Ty> { +impl fmt::Debug for TyAndLayout { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // Print the type in a readable way, not its debug representation. f.debug_struct("TyAndLayout") @@ -88,68 +37,96 @@ impl<'a, Ty: fmt::Display> fmt::Debug for TyAndLayout<'a, Ty> { } } -impl<'a, Ty> Deref for TyAndLayout<'a, Ty> { - type Target = &'a LayoutData; - fn deref(&self) -> &&'a LayoutData { - &self.layout.0.0 +impl Deref for TyAndLayout { + type Target = LayoutData; + fn deref(&self) -> &LayoutData { + self.layout.deref() } } -impl<'a, Ty> AsRef> for TyAndLayout<'a, Ty> { +impl AsRef> for TyAndLayout { fn as_ref(&self) -> &LayoutData { - &*self.layout.0.0 + self.layout.deref() + } +} + +#[cfg(feature = "nightly")] +impl rustc_serialize::Encodable for TyAndLayout +where + I::Layout: rustc_serialize::Encodable, + I::Ty: rustc_serialize::Encodable, +{ + fn encode(&self, s: &mut E) { + self.layout.encode(s); + self.ty.encode(s); + } +} + +#[cfg(feature = "nightly")] +impl rustc_serialize::Decodable for TyAndLayout +where + I::Layout: rustc_serialize::Decodable, + I::Ty: rustc_serialize::Decodable, +{ + fn decode(decoder: &mut D) -> Self { + let layout = I::Layout::decode(decoder); + let ty = I::Ty::decode(decoder); + Self { layout, ty } } } /// Trait that needs to be implemented by the higher-level type representation /// (e.g. `rustc_middle::ty::Ty`), to provide `rustc_target::abi` functionality. -pub trait TyAbiInterface<'a, C>: Sized + std::fmt::Debug + std::fmt::Display { +pub trait TyAbiInterface: Interner { fn ty_and_layout_for_variant( - this: TyAndLayout<'a, Self>, + this: TyAndLayout, cx: &C, variant_index: VariantIdx, - ) -> TyAndLayout<'a, Self>; - fn ty_and_layout_field(this: TyAndLayout<'a, Self>, cx: &C, i: usize) -> TyAndLayout<'a, Self>; + ) -> TyAndLayout; + fn ty_and_layout_field(this: TyAndLayout, cx: &C, i: usize) -> TyAndLayout; fn ty_and_layout_pointee_info_at( - this: TyAndLayout<'a, Self>, + this: TyAndLayout, cx: &C, offset: Size, ) -> Option; - fn is_adt(this: TyAndLayout<'a, Self>) -> bool; - fn is_never(this: TyAndLayout<'a, Self>) -> bool; - fn is_tuple(this: TyAndLayout<'a, Self>) -> bool; - fn is_unit(this: TyAndLayout<'a, Self>) -> bool; - fn is_transparent(this: TyAndLayout<'a, Self>) -> bool; - fn is_scalable_vector(this: TyAndLayout<'a, Self>) -> bool; + fn is_adt(this: TyAndLayout) -> bool; + fn is_never(this: TyAndLayout) -> bool; + fn is_tuple(this: TyAndLayout) -> bool; + fn is_unit(this: TyAndLayout) -> bool; + fn is_transparent(this: TyAndLayout) -> bool; + fn is_scalable_vector(this: TyAndLayout) -> bool; /// See [`TyAndLayout::pass_indirectly_in_non_rustic_abis`] for details. - fn is_pass_indirectly_in_non_rustic_abis_flag_set(this: TyAndLayout<'a, Self>) -> bool; + fn is_pass_indirectly_in_non_rustic_abis_flag_set(this: TyAndLayout) -> bool; } -impl<'a, Ty> TyAndLayout<'a, Ty> { +impl TyAndLayout +where + I::Ty: fmt::Display, +{ pub fn for_variant(self, cx: &C, variant_index: VariantIdx) -> Self where - Ty: TyAbiInterface<'a, C>, + I: TyAbiInterface, { - Ty::ty_and_layout_for_variant(self, cx, variant_index) + I::ty_and_layout_for_variant(self, cx, variant_index) } pub fn field(self, cx: &C, i: usize) -> Self where - Ty: TyAbiInterface<'a, C>, + I: TyAbiInterface, { - Ty::ty_and_layout_field(self, cx, i) + I::ty_and_layout_field(self, cx, i) } pub fn pointee_info_at(self, cx: &C, offset: Size) -> Option where - Ty: TyAbiInterface<'a, C>, + I: TyAbiInterface, { - Ty::ty_and_layout_pointee_info_at(self, cx, offset) + I::ty_and_layout_pointee_info_at(self, cx, offset) } pub fn is_single_fp_element(self, cx: &C) -> bool where - Ty: TyAbiInterface<'a, C>, + I: TyAbiInterface, C: HasDataLayout, { match self.backend_repr { @@ -169,7 +146,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { pub fn is_single_vector_element(self, cx: &C, expected_size: Size) -> bool where - Ty: TyAbiInterface<'a, C>, + I: TyAbiInterface, C: HasDataLayout, { match self.backend_repr { @@ -187,44 +164,44 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { pub fn is_adt(self) -> bool where - Ty: TyAbiInterface<'a, C>, + I: TyAbiInterface, { - Ty::is_adt(self) + I::is_adt(self) } pub fn is_never(self) -> bool where - Ty: TyAbiInterface<'a, C>, + I: TyAbiInterface, { - Ty::is_never(self) + I::is_never(self) } pub fn is_tuple(self) -> bool where - Ty: TyAbiInterface<'a, C>, + I: TyAbiInterface, { - Ty::is_tuple(self) + I::is_tuple(self) } pub fn is_unit(self) -> bool where - Ty: TyAbiInterface<'a, C>, + I: TyAbiInterface, { - Ty::is_unit(self) + I::is_unit(self) } pub fn is_transparent(self) -> bool where - Ty: TyAbiInterface<'a, C>, + I: TyAbiInterface, { - Ty::is_transparent(self) + I::is_transparent(self) } pub fn is_scalable_vector(self) -> bool where - Ty: TyAbiInterface<'a, C>, + I: TyAbiInterface, { - Ty::is_scalable_vector(self) + I::is_scalable_vector(self) } /// If this method returns `true`, then this type should always have a `PassMode` of @@ -240,10 +217,10 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { /// This function handles transparent types automatically. pub fn pass_indirectly_in_non_rustic_abis(self, cx: &C) -> bool where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { let base = self.peel_transparent_wrappers(cx); - Ty::is_pass_indirectly_in_non_rustic_abis_flag_set(base) + I::is_pass_indirectly_in_non_rustic_abis_flag_set(base) } /// Recursively peel away transparent wrappers, returning the inner value. @@ -252,7 +229,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { /// not have a non-1zst field. pub fn peel_transparent_wrappers(mut self, cx: &C) -> Self where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { while self.is_transparent() && let Some((_, field)) = self.non_1zst_field(cx) @@ -267,7 +244,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { /// Returns `None` if there are multiple non-1-ZST fields or only 1-ZST-fields. pub fn non_1zst_field(&self, cx: &C) -> Option<(FieldIdx, Self)> where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { let mut found = None; for field_idx in 0..self.fields.count() { @@ -293,7 +270,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { /// (E.g. `Option` has no guaranteed padding so the empty range set is returned, but its `None` value still has padding). pub fn padding_ranges(&self, cx: &C) -> Vec> where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { let mut data = RangeSet::new(); self.add_data_ranges(cx, Size::ZERO, &mut data); @@ -321,7 +298,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { /// variants but not for others; those offset *will* get added to `out`. fn add_data_ranges(self, cx: &C, base_offset: Size, out: &mut RangeSet) where - Ty: TyAbiInterface<'a, C> + Copy, + I: TyAbiInterface, { if self.is_zst() { return; diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index 0fdfe17b963fa..175fad462033f 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -47,6 +47,7 @@ mod generic_arg; mod generic_visit; mod infer_ctxt; mod interner; +mod layout; mod opaque_ty; mod pattern; mod predicate; @@ -75,6 +76,7 @@ pub use generic_arg::*; pub use generic_visit::*; pub use infer_ctxt::*; pub use interner::*; +pub use layout::*; pub use opaque_ty::*; pub use pattern::*; pub use predicate::*; diff --git a/src/librustdoc/html/render/type_layout.rs b/src/librustdoc/html/render/type_layout.rs index c3a8582deaeee..360123cf1374a 100644 --- a/src/librustdoc/html/render/type_layout.rs +++ b/src/librustdoc/html/render/type_layout.rs @@ -13,7 +13,7 @@ use crate::html::render::Context; #[template(path = "type_layout.html")] struct TypeLayout<'cx> { variants: Vec<(Symbol, TypeLayoutSize)>, - type_layout_size: Result>, + type_layout_size: Result>, } #[derive(Template)] diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs index 80f392363ba01..fb578ea9f254d 100644 --- a/src/tools/miri/src/machine.rs +++ b/src/tools/miri/src/machine.rs @@ -25,12 +25,11 @@ use rustc_middle::query::TyCtxtAt; use rustc_middle::ty::layout::{ HasTyCtxt, HasTypingEnv, LayoutCx, LayoutError, LayoutOf, TyAndLayout, }; -use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; +use rustc_middle::ty::{self, FnAbi, Instance, Ty, TyCtxt}; use rustc_session::config::InliningThreshold; use rustc_span::def_id::{CrateNum, DefId}; use rustc_span::{Span, SpanData, Symbol}; use rustc_symbol_mangling::mangle_internal_symbol; -use rustc_target::callconv::FnAbi; use rustc_target::spec::{Arch, Os}; use crate::alloc_addresses::EvalContextExt; @@ -435,7 +434,7 @@ pub struct PrimitiveLayouts<'tcx> { } impl<'tcx> PrimitiveLayouts<'tcx> { - fn new(layout_cx: LayoutCx<'tcx>) -> Result> { + fn new(layout_cx: LayoutCx<'tcx>) -> Result> { let tcx = layout_cx.tcx(); let mut_raw_ptr = Ty::new_mut_ptr(tcx, tcx.types.unit); let const_raw_ptr = Ty::new_imm_ptr(tcx, tcx.types.unit); @@ -1247,7 +1246,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { fn find_mir_or_eval_fn( ecx: &mut MiriInterpCx<'tcx>, instance: ty::Instance<'tcx>, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[FnArg<'tcx>], dest: &PlaceTy<'tcx>, ret: Option, @@ -1283,7 +1282,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { fn call_extra_fn( ecx: &mut MiriInterpCx<'tcx>, fn_val: DynSym, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[FnArg<'tcx>], dest: &PlaceTy<'tcx>, ret: Option, diff --git a/src/tools/miri/src/shims/aarch64.rs b/src/tools/miri/src/shims/aarch64.rs index 3d8946fb36720..ddeab58d610fb 100644 --- a/src/tools/miri/src/shims/aarch64.rs +++ b/src/tools/miri/src/shims/aarch64.rs @@ -1,8 +1,7 @@ use rustc_abi::CanonAbi; use rustc_middle::mir::BinOp; -use rustc_middle::ty::Ty; +use rustc_middle::ty::FnAbi; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; use crate::shims::math::compute_crc32; use crate::*; @@ -12,7 +11,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_aarch64_intrinsic( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/alloc.rs b/src/tools/miri/src/shims/alloc.rs index b4d53c36d19b3..e014ab5ec230c 100644 --- a/src/tools/miri/src/shims/alloc.rs +++ b/src/tools/miri/src/shims/alloc.rs @@ -1,8 +1,7 @@ use rustc_abi::{Align, AlignFromBytesError, CanonAbi, Size}; use rustc_ast::expand::allocator::SpecialAllocatorMethod; -use rustc_middle::ty::Ty; +use rustc_middle::ty::FnAbi; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; use rustc_target::spec::{Arch, Os}; use crate::*; @@ -115,7 +114,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, method: SpecialAllocatorMethod, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &PlaceTy<'tcx>, ) -> InterpResult<'tcx> { diff --git a/src/tools/miri/src/shims/backtrace.rs b/src/tools/miri/src/shims/backtrace.rs index 1ca814ee7afff..8a9e18ea2996b 100644 --- a/src/tools/miri/src/shims/backtrace.rs +++ b/src/tools/miri/src/shims/backtrace.rs @@ -1,7 +1,6 @@ use rustc_abi::{CanonAbi, FieldIdx, Size}; -use rustc_middle::ty::{self, Instance, Ty}; +use rustc_middle::ty::{self, FnAbi, Instance}; use rustc_span::{BytePos, Loc, Symbol, hygiene}; -use rustc_target::callconv::FnAbi; use crate::*; @@ -9,7 +8,7 @@ impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn handle_miri_backtrace_size( &mut self, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, link_name: Symbol, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, @@ -29,7 +28,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn handle_miri_get_backtrace( &mut self, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, link_name: Symbol, args: &[OpTy<'tcx>], ) -> InterpResult<'tcx> { @@ -108,7 +107,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn handle_miri_resolve_frame( &mut self, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, link_name: Symbol, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, @@ -185,7 +184,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn handle_miri_resolve_frame_names( &mut self, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, link_name: Symbol, args: &[OpTy<'tcx>], ) -> InterpResult<'tcx> { diff --git a/src/tools/miri/src/shims/foreign_items.rs b/src/tools/miri/src/shims/foreign_items.rs index 5fd86769e96b5..2ae8ecc98a31c 100644 --- a/src/tools/miri/src/shims/foreign_items.rs +++ b/src/tools/miri/src/shims/foreign_items.rs @@ -10,10 +10,9 @@ use rustc_hir::def::DefKind; use rustc_hir::def_id::CrateNum; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::interpret::AllocInit; -use rustc_middle::ty::{Instance, Ty}; +use rustc_middle::ty::{FnAbi, Instance}; use rustc_middle::{mir, ty}; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; use rustc_target::spec::{Arch, Os}; use super::alloc::EvalContextExt as _; @@ -44,7 +43,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_foreign_item( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &PlaceTy<'tcx>, ret: Option, @@ -111,7 +110,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_dyn_sym( &mut self, sym: DynSym, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &PlaceTy<'tcx>, ret: Option, @@ -248,7 +247,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_foreign_item_inner( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/loongarch.rs b/src/tools/miri/src/shims/loongarch.rs index 8642a5ce1a47b..8b9de1eeb39ac 100644 --- a/src/tools/miri/src/shims/loongarch.rs +++ b/src/tools/miri/src/shims/loongarch.rs @@ -1,7 +1,6 @@ use rustc_abi::{CanonAbi, Size}; -use rustc_middle::ty::Ty; +use rustc_middle::ty::FnAbi; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; use crate::shims::math::compute_crc32; use crate::*; @@ -11,7 +10,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_loongarch_intrinsic( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/math.rs b/src/tools/miri/src/shims/math.rs index 479e129579b2b..6f274b4e31022 100644 --- a/src/tools/miri/src/shims/math.rs +++ b/src/tools/miri/src/shims/math.rs @@ -1,8 +1,7 @@ use rustc_abi::CanonAbi; use rustc_apfloat::Float; -use rustc_middle::ty::Ty; +use rustc_middle::ty::FnAbi; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; use self::math::{ToHost, ToSoft}; use crate::*; @@ -12,7 +11,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_foreign_item_inner( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/sig.rs b/src/tools/miri/src/shims/sig.rs index 99673319240fe..661efb8a53464 100644 --- a/src/tools/miri/src/shims/sig.rs +++ b/src/tools/miri/src/shims/sig.rs @@ -1,9 +1,8 @@ //! Everything related to checking the signature of shim invocations. use rustc_abi::{CanonAbi, ExternAbi}; -use rustc_middle::ty::{Binder, FnSig, FnSigKind, Ty}; +use rustc_middle::ty::{Binder, FnAbi, FnSig, FnSigKind, Ty}; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; use crate::*; @@ -144,8 +143,8 @@ macro_rules! shim_sig_arg { /// Helper function to compare two ABIs. fn check_shim_abi<'tcx>( this: &MiriInterpCx<'tcx>, - callee_abi: &FnAbi<'tcx, Ty<'tcx>>, - caller_abi: &FnAbi<'tcx, Ty<'tcx>>, + callee_abi: &FnAbi<'tcx>, + caller_abi: &FnAbi<'tcx>, ) -> InterpResult<'tcx> { if callee_abi.conv != caller_abi.conv { throw_ub_format!( @@ -226,7 +225,7 @@ impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn check_shim_sig_lenient<'a, const N: usize>( &mut self, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, exp_abi: CanonAbi, link_name: Symbol, args: &'a [OpTy<'tcx>], @@ -262,7 +261,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, shim_sig: fn(&MiriInterpCx<'tcx>) -> ShimSig<'tcx, N>, link_name: Symbol, - caller_fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + caller_fn_abi: &FnAbi<'tcx>, caller_args: &'a [OpTy<'tcx>], ) -> InterpResult<'tcx, &'a [OpTy<'tcx>; N]> { let this = self.eval_context_mut(); @@ -296,7 +295,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Returns a tuple that consisting of an array of fixed args, and a slice of varargs. fn check_shim_sig_variadic_lenient<'a, const N: usize>( &mut self, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, exp_abi: CanonAbi, link_name: Symbol, args: &'a [OpTy<'tcx>], diff --git a/src/tools/miri/src/shims/unix/android/foreign_items.rs b/src/tools/miri/src/shims/unix/android/foreign_items.rs index 999750a9e00a9..660ba221801fd 100644 --- a/src/tools/miri/src/shims/unix/android/foreign_items.rs +++ b/src/tools/miri/src/shims/unix/android/foreign_items.rs @@ -1,7 +1,6 @@ use rustc_abi::CanonAbi; -use rustc_middle::ty::Ty; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::FnAbi; use crate::shims::unix::env::EvalContextExt as _; use crate::shims::unix::linux_like::epoll::EvalContextExt as _; @@ -20,7 +19,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_foreign_item_inner( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/unix/foreign_items.rs b/src/tools/miri/src/shims/unix/foreign_items.rs index 14eb7af4b52df..9b4ee924151f4 100644 --- a/src/tools/miri/src/shims/unix/foreign_items.rs +++ b/src/tools/miri/src/shims/unix/foreign_items.rs @@ -3,9 +3,8 @@ use std::str; use std::time::Duration; use rustc_abi::{CanonAbi, Size}; -use rustc_middle::ty::Ty; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::FnAbi; use rustc_target::spec::Os; use self::shims::unix::android::foreign_items as android; @@ -103,7 +102,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_foreign_item_inner( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/unix/freebsd/foreign_items.rs b/src/tools/miri/src/shims/unix/freebsd/foreign_items.rs index 1cc87050e59d8..2c76e7edecca8 100644 --- a/src/tools/miri/src/shims/unix/freebsd/foreign_items.rs +++ b/src/tools/miri/src/shims/unix/freebsd/foreign_items.rs @@ -1,7 +1,6 @@ use rustc_abi::CanonAbi; -use rustc_middle::ty::Ty; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::FnAbi; use super::sync::EvalContextExt as _; use crate::shims::unix::*; @@ -16,7 +15,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_foreign_item_inner( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/unix/linux/foreign_items.rs b/src/tools/miri/src/shims/unix/linux/foreign_items.rs index caea737582d78..391d285ae77e1 100644 --- a/src/tools/miri/src/shims/unix/linux/foreign_items.rs +++ b/src/tools/miri/src/shims/unix/linux/foreign_items.rs @@ -1,7 +1,6 @@ use rustc_abi::CanonAbi; -use rustc_middle::ty::Ty; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::FnAbi; use self::shims::unix::linux::mem::EvalContextExt as _; use self::shims::unix::linux_like::eventfd::EvalContextExt as _; @@ -26,7 +25,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_foreign_item_inner( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/unix/linux_like/syscall.rs b/src/tools/miri/src/shims/unix/linux_like/syscall.rs index 875fd09428389..7a63a3aff8568 100644 --- a/src/tools/miri/src/shims/unix/linux_like/syscall.rs +++ b/src/tools/miri/src/shims/unix/linux_like/syscall.rs @@ -1,7 +1,6 @@ use rustc_abi::CanonAbi; -use rustc_middle::ty::Ty; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::FnAbi; use crate::shims::sig::check_min_vararg_count; use crate::shims::unix::env::EvalContextExt; @@ -13,7 +12,7 @@ use crate::*; pub fn syscall<'tcx>( ecx: &mut MiriInterpCx<'tcx>, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx> { diff --git a/src/tools/miri/src/shims/unix/linux_like/thread.rs b/src/tools/miri/src/shims/unix/linux_like/thread.rs index da76af5704d88..c79134ae2758d 100644 --- a/src/tools/miri/src/shims/unix/linux_like/thread.rs +++ b/src/tools/miri/src/shims/unix/linux_like/thread.rs @@ -1,7 +1,6 @@ use rustc_abi::{CanonAbi, Size}; -use rustc_middle::ty::Ty; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::FnAbi; use crate::shims::sig::check_min_vararg_count; use crate::shims::unix::thread::{EvalContextExt as _, ThreadNameResult}; @@ -12,7 +11,7 @@ const TASK_COMM_LEN: u64 = 16; pub fn prctl<'tcx>( ecx: &mut MiriInterpCx<'tcx>, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx> { diff --git a/src/tools/miri/src/shims/unix/macos/foreign_items.rs b/src/tools/miri/src/shims/unix/macos/foreign_items.rs index d8146ab7b8886..6ee63945af3ce 100644 --- a/src/tools/miri/src/shims/unix/macos/foreign_items.rs +++ b/src/tools/miri/src/shims/unix/macos/foreign_items.rs @@ -1,7 +1,6 @@ use rustc_abi::CanonAbi; -use rustc_middle::ty::Ty; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::FnAbi; use super::sync::{EvalContextExt as _, MacOsFutexTimeout}; use crate::shims::unix::*; @@ -24,7 +23,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_foreign_item_inner( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/unix/solarish/foreign_items.rs b/src/tools/miri/src/shims/unix/solarish/foreign_items.rs index 37b665ceebd1f..dd7f945499f69 100644 --- a/src/tools/miri/src/shims/unix/solarish/foreign_items.rs +++ b/src/tools/miri/src/shims/unix/solarish/foreign_items.rs @@ -1,7 +1,6 @@ use rustc_abi::CanonAbi; -use rustc_middle::ty::Ty; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::FnAbi; use rustc_target::spec::Os; use crate::shims::unix::foreign_items::EvalContextExt as _; @@ -19,7 +18,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_foreign_item_inner( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/windows/foreign_items.rs b/src/tools/miri/src/shims/windows/foreign_items.rs index efef55f5cf91b..af0861ac7261b 100644 --- a/src/tools/miri/src/shims/windows/foreign_items.rs +++ b/src/tools/miri/src/shims/windows/foreign_items.rs @@ -3,9 +3,8 @@ use std::path::{self, Path, PathBuf}; use std::{io, iter, str}; use rustc_abi::{Align, Size}; -use rustc_middle::ty::Ty; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::FnAbi; use rustc_target::spec::Env; use self::shims::windows::handle::{Handle, PseudoHandle}; @@ -131,7 +130,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_foreign_item_inner( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/x86/aesni.rs b/src/tools/miri/src/shims/x86/aesni.rs index fdd3e78c61052..e5ca12872ebd3 100644 --- a/src/tools/miri/src/shims/x86/aesni.rs +++ b/src/tools/miri/src/shims/x86/aesni.rs @@ -1,7 +1,7 @@ use rustc_abi::CanonAbi; use rustc_middle::ty::Ty; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::FnAbi; use crate::*; @@ -10,7 +10,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_aesni_intrinsic( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/x86/avx.rs b/src/tools/miri/src/shims/x86/avx.rs index cda9dbde04a5d..e96e4d114af27 100644 --- a/src/tools/miri/src/shims/x86/avx.rs +++ b/src/tools/miri/src/shims/x86/avx.rs @@ -1,8 +1,7 @@ use rustc_abi::CanonAbi; use rustc_apfloat::ieee::{Double, Single}; -use rustc_middle::ty::Ty; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::FnAbi; use super::{ FloatBinOp, FloatUnaryOp, bin_op_simd_float_all, conditional_dot_product, convert_float_to_int, @@ -15,7 +14,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_avx_intrinsic( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/x86/avx2.rs b/src/tools/miri/src/shims/x86/avx2.rs index bddb9d47457ca..abc2c1322f8ab 100644 --- a/src/tools/miri/src/shims/x86/avx2.rs +++ b/src/tools/miri/src/shims/x86/avx2.rs @@ -1,8 +1,7 @@ use rustc_abi::CanonAbi; use rustc_middle::mir; -use rustc_middle::ty::Ty; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::FnAbi; use super::{ ShiftOp, horizontal_bin_op, mpsadbw, packssdw, packsswb, packusdw, packuswb, permute, pmaddbw, @@ -15,7 +14,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_avx2_intrinsic( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/x86/avx512.rs b/src/tools/miri/src/shims/x86/avx512.rs index 6bc9bfd9e0017..5d8bf9b3c6a17 100644 --- a/src/tools/miri/src/shims/x86/avx512.rs +++ b/src/tools/miri/src/shims/x86/avx512.rs @@ -1,7 +1,6 @@ use rustc_abi::CanonAbi; -use rustc_middle::ty::Ty; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::FnAbi; use super::{ packssdw, packsswb, packusdw, packuswb, permute, permute2, pmaddbw, pmaddwd, psadbw, pshufb, @@ -13,7 +12,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_avx512_intrinsic( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/x86/bmi.rs b/src/tools/miri/src/shims/x86/bmi.rs index 877ecf319ca40..46f0c51e3fba0 100644 --- a/src/tools/miri/src/shims/x86/bmi.rs +++ b/src/tools/miri/src/shims/x86/bmi.rs @@ -1,7 +1,6 @@ use rustc_abi::CanonAbi; -use rustc_middle::ty::Ty; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::FnAbi; use rustc_target::spec::Arch; use crate::*; @@ -11,7 +10,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_bmi_intrinsic( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/x86/gfni.rs b/src/tools/miri/src/shims/x86/gfni.rs index 9a98a80d6dcc2..84e0cd22e24fa 100644 --- a/src/tools/miri/src/shims/x86/gfni.rs +++ b/src/tools/miri/src/shims/x86/gfni.rs @@ -1,7 +1,6 @@ use rustc_abi::CanonAbi; -use rustc_middle::ty::Ty; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::FnAbi; use crate::*; @@ -10,7 +9,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_gfni_intrinsic( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/x86/mod.rs b/src/tools/miri/src/shims/x86/mod.rs index b3a8291b9361b..00bbc886160ef 100644 --- a/src/tools/miri/src/shims/x86/mod.rs +++ b/src/tools/miri/src/shims/x86/mod.rs @@ -4,7 +4,7 @@ use rustc_apfloat::ieee::Single; use rustc_middle::ty::Ty; use rustc_middle::{mir, ty}; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::FnAbi; use rustc_target::spec::Arch; use self::helpers::bool_to_simd_element; @@ -29,7 +29,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_intrinsic( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/x86/sha.rs b/src/tools/miri/src/shims/x86/sha.rs index 00fe58119e472..d581900e9573a 100644 --- a/src/tools/miri/src/shims/x86/sha.rs +++ b/src/tools/miri/src/shims/x86/sha.rs @@ -5,9 +5,8 @@ //! [RustCrypto's sha256 module]: https://github.com/RustCrypto/hashes/blob/6be8466247e936c415d8aafb848697f39894a386/sha2/src/sha256/soft.rs use rustc_abi::CanonAbi; -use rustc_middle::ty::Ty; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::FnAbi; use crate::*; @@ -16,7 +15,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_sha_intrinsic( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/x86/sse.rs b/src/tools/miri/src/shims/x86/sse.rs index 7da7a0b57c907..00ba08398dac2 100644 --- a/src/tools/miri/src/shims/x86/sse.rs +++ b/src/tools/miri/src/shims/x86/sse.rs @@ -1,8 +1,7 @@ use rustc_abi::CanonAbi; use rustc_apfloat::ieee::Single; -use rustc_middle::ty::Ty; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::FnAbi; use super::{ FloatBinOp, FloatUnaryOp, bin_op_simd_float_all, bin_op_simd_float_first, unary_op_ps, @@ -15,7 +14,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_sse_intrinsic( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/x86/sse2.rs b/src/tools/miri/src/shims/x86/sse2.rs index 1a33f4c70fd28..6da8ca2b01be2 100644 --- a/src/tools/miri/src/shims/x86/sse2.rs +++ b/src/tools/miri/src/shims/x86/sse2.rs @@ -1,8 +1,7 @@ use rustc_abi::CanonAbi; use rustc_apfloat::ieee::Double; -use rustc_middle::ty::Ty; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::FnAbi; use super::{ FloatBinOp, ShiftOp, bin_op_simd_float_all, bin_op_simd_float_first, convert_float_to_int, @@ -15,7 +14,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_sse2_intrinsic( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/x86/sse3.rs b/src/tools/miri/src/shims/x86/sse3.rs index 17c8360d33998..282a19e02f3e7 100644 --- a/src/tools/miri/src/shims/x86/sse3.rs +++ b/src/tools/miri/src/shims/x86/sse3.rs @@ -1,7 +1,6 @@ use rustc_abi::CanonAbi; -use rustc_middle::ty::Ty; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; +use rustc_middle::ty::FnAbi; use crate::*; @@ -10,7 +9,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_sse3_intrinsic( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/x86/sse41.rs b/src/tools/miri/src/shims/x86/sse41.rs index c5a4a98ba881b..b1218b71aee5d 100644 --- a/src/tools/miri/src/shims/x86/sse41.rs +++ b/src/tools/miri/src/shims/x86/sse41.rs @@ -1,7 +1,6 @@ use rustc_abi::CanonAbi; -use rustc_middle::ty::Ty; +use rustc_middle::ty::FnAbi; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; use super::{conditional_dot_product, mpsadbw, packusdw, round_all, round_first, test_bits_masked}; use crate::*; @@ -11,7 +10,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_sse41_intrinsic( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/x86/sse42.rs b/src/tools/miri/src/shims/x86/sse42.rs index 6b0e6726e8f79..ca816c420ebec 100644 --- a/src/tools/miri/src/shims/x86/sse42.rs +++ b/src/tools/miri/src/shims/x86/sse42.rs @@ -1,8 +1,7 @@ use rustc_abi::{CanonAbi, Size}; use rustc_middle::mir; -use rustc_middle::ty::Ty; +use rustc_middle::ty::{FnAbi, Ty}; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; use rustc_target::spec::Arch; use crate::shims::math::compute_crc32; @@ -202,7 +201,7 @@ fn deconstruct_args<'tcx>( unprefixed_name: &str, ecx: &mut MiriInterpCx<'tcx>, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], ) -> InterpResult<'tcx, (OpTy<'tcx>, OpTy<'tcx>, Option<(u64, u64)>, u8)> { let array_layout_fn = |ecx: &mut MiriInterpCx<'tcx>, imm: u8| { @@ -280,7 +279,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_sse42_intrinsic( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { diff --git a/src/tools/miri/src/shims/x86/ssse3.rs b/src/tools/miri/src/shims/x86/ssse3.rs index 7c1d15ff1265d..966cbe646b004 100644 --- a/src/tools/miri/src/shims/x86/ssse3.rs +++ b/src/tools/miri/src/shims/x86/ssse3.rs @@ -1,8 +1,7 @@ use rustc_abi::CanonAbi; use rustc_middle::mir; -use rustc_middle::ty::Ty; +use rustc_middle::ty::FnAbi; use rustc_span::Symbol; -use rustc_target::callconv::FnAbi; use super::{horizontal_bin_op, pmaddbw, pmulhrsw, pshufb, psign}; use crate::*; @@ -12,7 +11,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_ssse3_intrinsic( &mut self, link_name: Symbol, - abi: &FnAbi<'tcx, Ty<'tcx>>, + abi: &FnAbi<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> {