compiler: Directly use rustc_abi in metadata and middle

Stop reexporting ReprOptions from middle::ty
This commit is contained in:
Jubilee Young 2024-11-02 19:33:00 -07:00
parent 89ec8c2cfe
commit 236fe33345
35 changed files with 93 additions and 102 deletions

View File

@ -1,6 +1,7 @@
use std::ops::ControlFlow;
use std::path::{Path, PathBuf};
use rustc_abi::ExternAbi;
use rustc_ast::CRATE_NODE_ID;
use rustc_attr as attr;
use rustc_data_structures::fx::FxHashSet;
@ -17,7 +18,6 @@
use rustc_span::def_id::{DefId, LOCAL_CRATE};
use rustc_span::symbol::{Symbol, sym};
use rustc_target::spec::LinkSelfContainedComponents;
use rustc_target::spec::abi::Abi;
use crate::{errors, fluent_generated};
@ -203,7 +203,7 @@ fn process_module(&mut self, module: &ForeignModule) {
let sess = self.tcx.sess;
if matches!(abi, Abi::Rust | Abi::RustIntrinsic) {
if matches!(abi, ExternAbi::Rust | ExternAbi::RustIntrinsic) {
return;
}
@ -625,7 +625,7 @@ fn i686_arg_list_size(&self, item: DefId) -> usize {
fn build_dll_import(
&self,
abi: Abi,
abi: ExternAbi,
import_name_type: Option<PeImportNameType>,
item: DefId,
) -> DllImport {
@ -634,12 +634,14 @@ fn build_dll_import(
// this logic is similar to `Target::adjust_abi` (in rustc_target/src/spec/mod.rs) but errors on unsupported inputs
let calling_convention = if self.tcx.sess.target.arch == "x86" {
match abi {
Abi::C { .. } | Abi::Cdecl { .. } => DllCallingConvention::C,
Abi::Stdcall { .. } => DllCallingConvention::Stdcall(self.i686_arg_list_size(item)),
ExternAbi::C { .. } | ExternAbi::Cdecl { .. } => DllCallingConvention::C,
ExternAbi::Stdcall { .. } => {
DllCallingConvention::Stdcall(self.i686_arg_list_size(item))
}
// On Windows, `extern "system"` behaves like msvc's `__stdcall`.
// `__stdcall` only applies on x86 and on non-variadic functions:
// https://learn.microsoft.com/en-us/cpp/cpp/stdcall?view=msvc-170
Abi::System { .. } => {
ExternAbi::System { .. } => {
let c_variadic =
self.tcx.type_of(item).instantiate_identity().fn_sig(self.tcx).c_variadic();
@ -649,10 +651,10 @@ fn build_dll_import(
DllCallingConvention::Stdcall(self.i686_arg_list_size(item))
}
}
Abi::Fastcall { .. } => {
ExternAbi::Fastcall { .. } => {
DllCallingConvention::Fastcall(self.i686_arg_list_size(item))
}
Abi::Vectorcall { .. } => {
ExternAbi::Vectorcall { .. } => {
DllCallingConvention::Vectorcall(self.i686_arg_list_size(item))
}
_ => {
@ -661,7 +663,9 @@ fn build_dll_import(
}
} else {
match abi {
Abi::C { .. } | Abi::Win64 { .. } | Abi::System { .. } => DllCallingConvention::C,
ExternAbi::C { .. } | ExternAbi::Win64 { .. } | ExternAbi::System { .. } => {
DllCallingConvention::C
}
_ => {
self.tcx.dcx().emit_fatal(errors::UnsupportedAbi { span });
}

View File

@ -6,7 +6,7 @@
use def_path_hash_map::DefPathHashMapRef;
use encoder::EncodeContext;
pub use encoder::{EncodedMetadata, encode_metadata, rendered_const};
use rustc_abi::{FieldIdx, VariantIdx};
use rustc_abi::{FieldIdx, ReprOptions, VariantIdx};
use rustc_ast::expand::StrippedCfgItem;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::svh::Svh;
@ -27,7 +27,7 @@
use rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault;
use rustc_middle::ty::fast_reject::SimplifiedType;
use rustc_middle::ty::{
self, DeducedParamAttrs, ParameterizedOverTcx, ReprOptions, Ty, TyCtxt, UnusedGenericParams,
self, DeducedParamAttrs, ParameterizedOverTcx, Ty, TyCtxt, UnusedGenericParams,
};
use rustc_middle::util::Providers;
use rustc_middle::{mir, trivially_parameterized_over_tcx};

View File

@ -9,7 +9,7 @@ macro_rules! arena_types {
($macro:path) => (
$macro!([
[] layout: rustc_abi::LayoutData<rustc_abi::FieldIdx, rustc_abi::VariantIdx>,
[] fn_abi: rustc_target::abi::call::FnAbi<'tcx, rustc_middle::ty::Ty<'tcx>>,
[] fn_abi: rustc_target::callconv::FnAbi<'tcx, rustc_middle::ty::Ty<'tcx>>,
// AdtDef are interned and compared by address
[decode] adt_def: rustc_middle::ty::AdtDefData,
[] steal_thir: rustc_data_structures::steal::Steal<rustc_middle::thir::Thir<'tcx>>,

View File

@ -1,3 +1,4 @@
use rustc_abi::ExternAbi;
use rustc_ast::visit::{VisitorResult, walk_list};
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@ -12,7 +13,6 @@
use rustc_span::def_id::StableCrateId;
use rustc_span::symbol::{Ident, Symbol, kw, sym};
use rustc_span::{ErrorGuaranteed, Span};
use rustc_target::spec::abi::Abi;
use {rustc_ast as ast, rustc_hir_pretty as pprust_hir};
use crate::hir::ModuleItems;
@ -668,7 +668,7 @@ pub fn get_defining_scope(self, id: HirId) -> HirId {
}
}
pub fn get_foreign_abi(self, hir_id: HirId) -> Abi {
pub fn get_foreign_abi(self, hir_id: HirId) -> ExternAbi {
let parent = self.get_parent_item(hir_id);
if let OwnerNode::Item(Item { kind: ItemKind::ForeignMod { abi, .. }, .. }) =
self.tcx.hir_owner_node(parent)

View File

@ -1,6 +1,6 @@
use rustc_abi::{FieldIdx, VariantIdx};
use rustc_hir::HirId;
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
use rustc_target::abi::{FieldIdx, VariantIdx};
use crate::ty;
use crate::ty::Ty;

View File

@ -1,7 +1,7 @@
use rustc_abi::Align;
use rustc_attr::{InlineAttr, InstructionSetAttr, OptimizeAttr};
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
use rustc_span::symbol::Symbol;
use rustc_target::abi::Align;
use rustc_target::spec::SanitizerSet;
use crate::mir::mono::Linkage;

View File

@ -1,12 +1,12 @@
use std::fmt::{self, Debug, Display, Formatter};
use either::Either;
use rustc_abi::{HasDataLayout, Size};
use rustc_hir::def_id::DefId;
use rustc_macros::{HashStable, Lift, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
use rustc_session::RemapFileNameExt;
use rustc_session::config::RemapPathScopeComponents;
use rustc_span::{DUMMY_SP, Span};
use rustc_target::abi::{HasDataLayout, Size};
use crate::mir::interpret::{AllocId, ConstAllocation, ErrorHandled, Scalar, alloc_range};
use crate::mir::{Promoted, pretty_print_const_value};

View File

@ -12,10 +12,10 @@
use init_mask::*;
pub use init_mask::{InitChunk, InitChunkIter};
use provenance_map::*;
use rustc_abi::{Align, HasDataLayout, Size};
use rustc_ast::Mutability;
use rustc_data_structures::intern::Interned;
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
use rustc_target::abi::{Align, HasDataLayout, Size};
use super::{
AllocId, BadBytesAccess, CtfeProvenance, InterpErrorKind, InterpResult, Pointer,

View File

@ -4,9 +4,9 @@
use std::ops::Range;
use std::{hash, iter};
use rustc_abi::Size;
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
use rustc_serialize::{Decodable, Encodable};
use rustc_target::abi::Size;
use rustc_type_ir::{TyDecoder, TyEncoder};
use super::AllocRange;

View File

@ -3,10 +3,10 @@
use std::cmp;
use rustc_abi::{HasDataLayout, Size};
use rustc_data_structures::sorted_map::SortedMap;
use rustc_macros::HashStable;
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use rustc_target::abi::{HasDataLayout, Size};
use tracing::trace;
use super::{AllocError, AllocRange, AllocResult, CtfeProvenance, Provenance, alloc_range};

View File

@ -4,6 +4,7 @@
use std::{convert, fmt, mem, ops};
use either::Either;
use rustc_abi::{Align, Size, VariantIdx, WrappingRange};
use rustc_ast_ir::Mutability;
use rustc_data_structures::sync::Lock;
use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, ErrorGuaranteed, IntoDiagArg};
@ -11,7 +12,6 @@
use rustc_session::CtfeBacktrace;
use rustc_span::def_id::DefId;
use rustc_span::{DUMMY_SP, Span, Symbol};
use rustc_target::abi::{Align, Size, VariantIdx, WrappingRange, call};
use super::{AllocId, AllocRange, ConstAllocation, Pointer, Scalar};
use crate::error;
@ -217,7 +217,7 @@ pub enum InvalidProgramInfo<'tcx> {
/// An error occurred during FnAbi computation: the passed --target lacks FFI support
/// (which unfortunately typeck does not reject).
/// Not using `FnAbiError` as that contains a nested `LayoutError`.
FnAbiAdjustForForeignAbi(call::AdjustForForeignAbiError),
FnAbiAdjustForForeignAbi(rustc_target::callconv::AdjustForForeignAbiError),
}
/// Details of why a pointer had to be in-bounds.

View File

@ -12,6 +12,7 @@
use std::num::NonZero;
use std::{fmt, io};
use rustc_abi::{AddressSpace, Endian, HasDataLayout};
use rustc_ast::LitKind;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::Lock;
@ -20,7 +21,6 @@
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_serialize::{Decodable, Encodable};
use rustc_target::abi::{AddressSpace, Endian, HasDataLayout};
use tracing::{debug, trace};
// Also make the error macros available from this module.
pub use {

View File

@ -1,9 +1,9 @@
use std::fmt;
use std::num::NonZero;
use rustc_abi::{HasDataLayout, Size};
use rustc_data_structures::static_assert_size;
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
use rustc_target::abi::{HasDataLayout, Size};
use super::AllocId;

View File

@ -1,10 +1,10 @@
use std::fmt;
use either::{Either, Left, Right};
use rustc_abi::{HasDataLayout, Size};
use rustc_apfloat::Float;
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
use rustc_target::abi::{HasDataLayout, Size};
use super::{
AllocId, CtfeProvenance, InterpResult, Pointer, PointerArithmetic, Provenance,

View File

@ -10,6 +10,7 @@
pub use basic_blocks::BasicBlocks;
use either::Either;
use polonius_engine::Atom;
use rustc_abi::{FieldIdx, VariantIdx};
pub use rustc_ast::Mutability;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
@ -27,7 +28,6 @@
use rustc_span::source_map::Spanned;
use rustc_span::symbol::Symbol;
use rustc_span::{DUMMY_SP, Span};
use rustc_target::abi::{FieldIdx, VariantIdx};
use tracing::trace;
pub use self::query::*;

View File

@ -4,6 +4,7 @@
use std::io::{self, Write as _};
use std::path::{Path, PathBuf};
use rustc_abi::Size;
use rustc_ast::InlineAsmTemplatePiece;
use rustc_middle::mir::interpret::{
AllocBytes, AllocId, Allocation, GlobalAlloc, Pointer, Provenance, alloc_range,
@ -11,7 +12,6 @@
};
use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::*;
use rustc_target::abi::Size;
use tracing::trace;
use super::graphviz::write_mir_fn_graphviz;

View File

@ -4,6 +4,7 @@
use std::fmt::{self, Debug};
use derive_where::derive_where;
use rustc_abi::{FieldIdx, VariantIdx};
use rustc_data_structures::fx::FxIndexMap;
use rustc_errors::ErrorGuaranteed;
use rustc_hir::def_id::LocalDefId;
@ -12,7 +13,6 @@
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
use rustc_span::Span;
use rustc_span::symbol::Symbol;
use rustc_target::abi::{FieldIdx, VariantIdx};
use smallvec::SmallVec;
use super::{ConstValue, SourceInfo};

View File

@ -3,6 +3,7 @@
//! This is in a dedicated file so that changes to this file can be reviewed more carefully.
//! The intention is that this file only contains datatype declarations, no code.
use rustc_abi::{FieldIdx, VariantIdx};
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece, Mutability};
use rustc_data_structures::packed::Pu128;
use rustc_hir::CoroutineKind;
@ -13,7 +14,6 @@
use rustc_span::def_id::LocalDefId;
use rustc_span::source_map::Spanned;
use rustc_span::symbol::Symbol;
use rustc_target::abi::{FieldIdx, VariantIdx};
use rustc_target::asm::InlineAsmRegOrRegClass;
use smallvec::SmallVec;

View File

@ -132,12 +132,10 @@ impl EraseType for Result<bool, &ty::layout::LayoutError<'_>> {
type Result = [u8; size_of::<Result<bool, &'static ty::layout::LayoutError<'static>>>()];
}
impl EraseType
for Result<rustc_target::abi::TyAndLayout<'_, Ty<'_>>, &ty::layout::LayoutError<'_>>
{
impl EraseType for Result<rustc_abi::TyAndLayout<'_, Ty<'_>>, &ty::layout::LayoutError<'_>> {
type Result = [u8; size_of::<
Result<
rustc_target::abi::TyAndLayout<'static, Ty<'static>>,
rustc_abi::TyAndLayout<'static, Ty<'static>>,
&'static ty::layout::LayoutError<'static>,
>,
>()];
@ -253,13 +251,14 @@ impl EraseType for $ty {
Option<rustc_span::def_id::DefId>,
Option<rustc_span::def_id::LocalDefId>,
Option<rustc_span::Span>,
Option<rustc_target::abi::FieldIdx>,
Option<rustc_abi::FieldIdx>,
Option<rustc_target::spec::PanicStrategy>,
Option<usize>,
Option<rustc_middle::ty::IntrinsicDef>,
Result<(), rustc_errors::ErrorGuaranteed>,
Result<(), rustc_middle::traits::query::NoSolution>,
Result<rustc_middle::traits::EvaluationResult, rustc_middle::traits::OverflowError>,
rustc_abi::ReprOptions,
rustc_ast::expand::allocator::AllocatorKind,
rustc_attr::ConstStability,
rustc_attr::DefaultBodyStability,
@ -311,7 +310,6 @@ impl EraseType for $ty {
rustc_middle::ty::fast_reject::SimplifiedType,
rustc_middle::ty::ImplPolarity,
rustc_middle::ty::Representability,
rustc_middle::ty::ReprOptions,
rustc_middle::ty::UnusedGenericParams,
rustc_middle::ty::util::AlwaysRequiresDrop,
rustc_middle::ty::Visibility<rustc_span::def_id::DefId>,

View File

@ -5,7 +5,6 @@
use rustc_query_system::query::{DefIdCache, DefaultCache, SingleCache, VecCache};
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::{DUMMY_SP, Span};
use rustc_target::abi;
use crate::infer::canonical::CanonicalQueryInput;
use crate::ty::fast_reject::SimplifiedType;
@ -509,7 +508,7 @@ fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
}
}
impl<'tcx> Key for (Ty<'tcx>, abi::VariantIdx) {
impl<'tcx> Key for (Ty<'tcx>, rustc_abi::VariantIdx) {
type Cache<V> = DefaultCache<Self, V>;
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {

View File

@ -42,9 +42,8 @@
use rustc_span::def_id::LOCAL_CRATE;
use rustc_span::symbol::Symbol;
use rustc_span::{DUMMY_SP, Span};
use rustc_target::abi;
use rustc_target::spec::PanicStrategy;
use {rustc_ast as ast, rustc_attr as attr, rustc_hir as hir};
use {rustc_abi as abi, rustc_ast as ast, rustc_attr as attr, rustc_hir as hir};
use crate::infer::canonical::{self, Canonical};
use crate::lint::LintExpectation;
@ -1465,7 +1464,7 @@
/// instead, where the instance is an `InstanceKind::Virtual`.
query fn_abi_of_fn_ptr(
key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, &'tcx ty::layout::FnAbiError<'tcx>> {
) -> Result<&'tcx rustc_target::callconv::FnAbi<'tcx, Ty<'tcx>>, &'tcx ty::layout::FnAbiError<'tcx>> {
desc { "computing call ABI of `{}` function pointers", key.value.0 }
}
@ -1476,7 +1475,7 @@
/// to an `InstanceKind::Virtual` instance (of `<dyn Trait as Trait>::fn`).
query fn_abi_of_instance(
key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, &'tcx ty::layout::FnAbiError<'tcx>> {
) -> Result<&'tcx rustc_target::callconv::FnAbi<'tcx, Ty<'tcx>>, &'tcx ty::layout::FnAbiError<'tcx>> {
desc { "computing call ABI of `{}`", key.value.0 }
}

View File

@ -12,6 +12,7 @@
use std::fmt;
use std::ops::Index;
use rustc_abi::{FieldIdx, Integer, Size, VariantIdx};
use rustc_ast::{AsmMacro, InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
@ -29,7 +30,6 @@
};
use rustc_span::def_id::LocalDefId;
use rustc_span::{ErrorGuaranteed, Span, Symbol};
use rustc_target::abi::{FieldIdx, Integer, Size, VariantIdx};
use rustc_target::asm::InlineAsmRegOrRegClass;
use tracing::instrument;
@ -1063,7 +1063,7 @@ pub fn compare_with(
a.partial_cmp(&b)
}
ty::Int(ity) => {
let size = rustc_target::abi::Integer::from_int_ty(&tcx, *ity).size();
let size = rustc_abi::Integer::from_int_ty(&tcx, *ity).size();
let a = size.sign_extend(a) as i128;
let b = size.sign_extend(b) as i128;
Some(a.cmp(&b))

View File

@ -1,8 +1,8 @@
use rustc_abi::FieldIdx;
use rustc_hir as hir;
use rustc_hir::lang_items::LangItem;
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
use rustc_span::Span;
use rustc_target::abi::FieldIdx;
use crate::ty::{self, Ty, TyCtxt};

View File

@ -3,6 +3,7 @@
use std::ops::Range;
use std::str;
use rustc_abi::{FIRST_VARIANT, ReprOptions, VariantIdx};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
@ -17,7 +18,6 @@
use rustc_query_system::ich::StableHashingContext;
use rustc_session::DataTypeKind;
use rustc_span::symbol::sym;
use rustc_target::abi::{FIRST_VARIANT, ReprOptions, VariantIdx};
use tracing::{debug, info, trace};
use super::{

View File

@ -10,12 +10,12 @@
use std::intrinsics;
use std::marker::DiscriminantKind;
use rustc_abi::{FieldIdx, VariantIdx};
use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::LocalDefId;
use rustc_middle::ty::TyCtxt;
use rustc_serialize::{Decodable, Encodable};
use rustc_span::Span;
use rustc_target::abi::{FieldIdx, VariantIdx};
pub use rustc_type_ir::{TyDecoder, TyEncoder};
use crate::arena::ArenaAllocatable;

View File

@ -1,11 +1,11 @@
use std::fmt;
use std::num::NonZero;
use rustc_abi::Size;
use rustc_apfloat::Float;
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
use rustc_errors::{DiagArgValue, IntoDiagArg};
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use rustc_target::abi::Size;
use crate::ty::TyCtxt;

View File

@ -12,7 +12,7 @@
use std::ops::{Bound, Deref};
use std::{fmt, iter, mem};
use rustc_abi::{FieldIdx, Layout, LayoutData, TargetDataLayout, VariantIdx};
use rustc_abi::{ExternAbi, FieldIdx, Layout, LayoutData, TargetDataLayout, VariantIdx};
use rustc_ast::{self as ast, attr};
use rustc_data_structures::defer;
use rustc_data_structures::fingerprint::Fingerprint;
@ -49,7 +49,6 @@
use rustc_span::def_id::{CRATE_DEF_ID, DefPathHash, StableCrateId};
use rustc_span::symbol::{Ident, Symbol, kw, sym};
use rustc_span::{DUMMY_SP, Span};
use rustc_target::spec::abi;
use rustc_type_ir::TyKind::*;
use rustc_type_ir::fold::TypeFoldable;
use rustc_type_ir::lang_items::TraitSolverLangItem;
@ -136,7 +135,7 @@ fn with_cached_task<T>(self, task: impl FnOnce() -> T) -> (T, DepNodeIndex) {
type AllocId = crate::mir::interpret::AllocId;
type Pat = Pattern<'tcx>;
type Safety = hir::Safety;
type Abi = abi::Abi;
type Abi = ExternAbi;
type Const = ty::Const<'tcx>;
type PlaceholderConst = ty::PlaceholderConst;
@ -695,13 +694,13 @@ fn as_local(self) -> Option<LocalDefId> {
}
}
impl<'tcx> rustc_type_ir::inherent::Abi<TyCtxt<'tcx>> for abi::Abi {
impl<'tcx> rustc_type_ir::inherent::Abi<TyCtxt<'tcx>> for ExternAbi {
fn rust() -> Self {
abi::Abi::Rust
ExternAbi::Rust
}
fn is_rust(self) -> bool {
matches!(self, abi::Abi::Rust)
matches!(self, ExternAbi::Rust)
}
}
@ -2557,7 +2556,7 @@ pub fn signature_unclosure(self, sig: PolyFnSig<'tcx>, safety: hir::Safety) -> P
ty::Tuple(params) => *params,
_ => bug!(),
};
self.mk_fn_sig(params, s.output(), s.c_variadic, safety, abi::Abi::Rust)
self.mk_fn_sig(params, s.output(), s.c_variadic, safety, ExternAbi::Rust)
})
}
@ -2819,7 +2818,7 @@ pub fn mk_fn_sig<I, T>(
output: I::Item,
c_variadic: bool,
safety: hir::Safety,
abi: abi::Abi,
abi: ExternAbi,
) -> T::Output
where
I: IntoIterator<Item = T>,

View File

@ -2,11 +2,10 @@
use std::ops::Bound;
use std::{cmp, fmt};
use rustc_abi::Primitive::{self, Float, Int, Pointer};
use rustc_abi::{
AddressSpace, Align, BackendRepr, FieldsShape, HasDataLayout, Integer, LayoutCalculator,
LayoutData, PointeeInfo, PointerKind, ReprOptions, Scalar, Size, TagEncoding, TargetDataLayout,
Variants,
AddressSpace, Align, BackendRepr, ExternAbi, FieldIdx, FieldsShape, HasDataLayout, LayoutData,
PointeeInfo, PointerKind, Primitive, ReprOptions, Scalar, Size, TagEncoding, TargetDataLayout,
TyAbiInterface, VariantIdx, Variants,
};
use rustc_error_messages::DiagMessage;
use rustc_errors::{
@ -19,9 +18,7 @@
use rustc_session::config::OptLevel;
use rustc_span::symbol::{Symbol, sym};
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
use rustc_target::abi::call::FnAbi;
use rustc_target::abi::{FieldIdx, TyAbiInterface, VariantIdx, call};
use rustc_target::spec::abi::Abi as SpecAbi;
use rustc_target::callconv::FnAbi;
use rustc_target::spec::{
HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, PanicStrategy, Target, WasmCAbi, X86Abi,
};
@ -86,16 +83,16 @@ fn repr_discr<'tcx>(
repr: &ReprOptions,
min: i128,
max: i128,
) -> (Integer, bool) {
) -> (abi::Integer, bool) {
// Theoretically, negative values could be larger in unsigned representation
// than the unsigned representation of the signed minimum. However, if there
// are any negative values, the only valid unsigned representation is u128
// which can fit all i128 values, so the result remains unaffected.
let unsigned_fit = Integer::fit_unsigned(cmp::max(min as u128, max as u128));
let signed_fit = cmp::max(Integer::fit_signed(min), Integer::fit_signed(max));
let unsigned_fit = abi::Integer::fit_unsigned(cmp::max(min as u128, max as u128));
let signed_fit = cmp::max(abi::Integer::fit_signed(min), abi::Integer::fit_signed(max));
if let Some(ity) = repr.int {
let discr = Integer::from_attr(&tcx, ity);
let discr = abi::Integer::from_attr(&tcx, ity);
let fit = if ity.is_signed() { signed_fit } else { unsigned_fit };
if discr < fit {
bug!(
@ -113,7 +110,7 @@ fn repr_discr<'tcx>(
tcx.data_layout().c_enum_min_size
} else {
// repr(Rust) enums try to be as small as possible
Integer::I8
abi::Integer::I8
};
// If there are no negative values, we can use the unsigned fit.
@ -154,10 +151,10 @@ impl Primitive {
#[inline]
fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
match *self {
Int(i, signed) => i.to_ty(tcx, signed),
Float(f) => f.to_ty(tcx),
Primitive::Int(i, signed) => i.to_ty(tcx, signed),
Primitive::Float(f) => f.to_ty(tcx),
// FIXME(erikdesjardins): handle non-default addrspace ptr sizes
Pointer(_) => Ty::new_mut_ptr(tcx, tcx.types.unit),
Primitive::Pointer(_) => Ty::new_mut_ptr(tcx, tcx.types.unit),
}
}
@ -166,13 +163,13 @@ fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
#[inline]
fn to_int_ty<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
match *self {
Int(i, signed) => i.to_ty(tcx, signed),
Primitive::Int(i, signed) => i.to_ty(tcx, signed),
// FIXME(erikdesjardins): handle non-default addrspace ptr sizes
Pointer(_) => {
Primitive::Pointer(_) => {
let signed = false;
tcx.data_layout().ptr_sized_integer().to_ty(tcx, signed)
}
Float(_) => bug!("floats do not have an int type"),
Primitive::Float(_) => bug!("floats do not have an int type"),
}
}
}
@ -299,13 +296,13 @@ fn into_diag_arg(self) -> DiagArgValue {
#[derive(Clone, Copy)]
pub struct LayoutCx<'tcx> {
pub calc: LayoutCalculator<TyCtxt<'tcx>>,
pub calc: abi::LayoutCalculator<TyCtxt<'tcx>>,
pub param_env: ty::ParamEnv<'tcx>,
}
impl<'tcx> LayoutCx<'tcx> {
pub fn new(tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Self {
Self { calc: LayoutCalculator::new(tcx), param_env }
Self { calc: abi::LayoutCalculator::new(tcx), param_env }
}
}
@ -645,7 +642,7 @@ fn to_result(self) -> Result<T, Self::Error> {
}
}
pub type TyAndLayout<'tcx> = rustc_target::abi::TyAndLayout<'tcx, Ty<'tcx>>;
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`.
@ -1048,7 +1045,7 @@ fn ty_and_layout_pointee_info_at(
if let Some(variant) = data_variant {
// FIXME(erikdesjardins): handle non-default addrspace ptr sizes
// (requires passing in the expected address space from the caller)
let ptr_end = offset + Pointer(AddressSpace::DATA).size(cx);
let ptr_end = offset + Primitive::Pointer(AddressSpace::DATA).size(cx);
for i in 0..variant.fields.count() {
let field_start = variant.fields.offset(i);
if field_start <= offset {
@ -1163,7 +1160,7 @@ fn is_transparent(this: TyAndLayout<'tcx>) -> bool {
/// affects various optimizations and codegen.
#[inline]
#[tracing::instrument(level = "debug", skip(tcx))]
pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: SpecAbi) -> bool {
pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: ExternAbi) -> bool {
if let Some(did) = fn_def_id {
// Special attribute for functions which can't unwind.
if tcx.codegen_fn_attrs(did).flags.contains(CodegenFnAttrFlags::NEVER_UNWIND) {
@ -1195,7 +1192,7 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: SpecAbi) ->
// ABIs have such an option. Otherwise the only other thing here is Rust
// itself, and those ABIs are determined by the panic strategy configured
// for this compilation.
use SpecAbi::*;
use ExternAbi::*;
match abi {
C { unwind }
| System { unwind }
@ -1231,17 +1228,16 @@ pub enum FnAbiError<'tcx> {
Layout(LayoutError<'tcx>),
/// Error produced by attempting to adjust a `FnAbi`, for a "foreign" ABI.
AdjustForForeignAbi(call::AdjustForForeignAbiError),
AdjustForForeignAbi(rustc_target::callconv::AdjustForForeignAbiError),
}
impl<'a, 'b, G: EmissionGuarantee> Diagnostic<'a, G> for FnAbiError<'b> {
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
match self {
Self::Layout(e) => e.into_diagnostic().into_diag(dcx, level),
Self::AdjustForForeignAbi(call::AdjustForForeignAbiError::Unsupported {
arch,
abi,
}) => UnsupportedFnAbi { arch, abi: abi.name() }.into_diag(dcx, level),
Self::AdjustForForeignAbi(
rustc_target::callconv::AdjustForForeignAbiError::Unsupported { arch, abi },
) => UnsupportedFnAbi { arch, abi: abi.name() }.into_diag(dcx, level),
}
}
}

View File

@ -24,6 +24,7 @@
pub use generic_args::{GenericArgKind, TermKind, *};
pub use generics::*;
pub use intrinsic::IntrinsicDef;
use rustc_abi::{Align, FieldIdx, Integer, IntegerType, ReprFlags, ReprOptions, VariantIdx};
use rustc_ast::expand::StrippedCfgItem;
use rustc_ast::node_id::NodeMap;
pub use rustc_ast_ir::{Movability, Mutability, try_visit};
@ -48,8 +49,6 @@
use rustc_span::hygiene::MacroKind;
use rustc_span::symbol::{Ident, Symbol, kw, sym};
use rustc_span::{ExpnId, ExpnKind, Span};
use rustc_target::abi::{Align, FieldIdx, Integer, IntegerType, VariantIdx};
pub use rustc_target::abi::{ReprFlags, ReprOptions};
pub use rustc_type_ir::ConstKind::{
Bound as BoundCt, Error as ErrorCt, Expr as ExprCt, Infer as InferCt, Param as ParamCt,
Placeholder as PlaceholderCt, Unevaluated, Value,

View File

@ -3,6 +3,7 @@
use std::iter;
use std::ops::{Deref, DerefMut};
use rustc_abi::{ExternAbi, Size};
use rustc_apfloat::Float;
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
@ -17,8 +18,6 @@
use rustc_session::cstore::{ExternCrate, ExternCrateSource};
use rustc_span::FileNameDisplayPreference;
use rustc_span::symbol::{Ident, Symbol, kw};
use rustc_target::abi::Size;
use rustc_target::spec::abi::Abi;
use rustc_type_ir::{Upcast as _, elaborate};
use smallvec::SmallVec;
@ -3029,7 +3028,7 @@ macro_rules! define_print_and_forward_display {
ty::FnSig<'tcx> {
p!(write("{}", self.safety.prefix_str()));
if self.abi != Abi::Rust {
if self.abi != ExternAbi::Rust {
p!(write("extern {} ", self.abi));
}

View File

@ -5,11 +5,11 @@
use std::fmt::{self, Debug};
use rustc_abi::TyAndLayout;
use rustc_ast_ir::try_visit;
use rustc_ast_ir::visit::VisitorResult;
use rustc_hir::def::Namespace;
use rustc_span::source_map::Spanned;
use rustc_target::abi::TyAndLayout;
use rustc_type_ir::ConstKind;
use super::print::PrettyPrinter;
@ -218,8 +218,8 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// provide any traversal implementations, we need to provide a traversal
// implementation (only for TyCtxt<'_> interners).
TrivialTypeTraversalImpls! {
::rustc_target::abi::FieldIdx,
::rustc_target::abi::VariantIdx,
::rustc_abi::FieldIdx,
::rustc_abi::VariantIdx,
crate::middle::region::Scope,
::rustc_ast::InlineAsmOptions,
::rustc_ast::InlineAsmTemplatePiece,
@ -271,12 +271,12 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
interpret::AllocId,
interpret::CtfeProvenance,
interpret::Scalar,
rustc_target::abi::Size,
rustc_abi::Size,
}
TrivialLiftImpls! {
::rustc_hir::Safety,
::rustc_target::spec::abi::Abi,
::rustc_abi::ExternAbi,
}
///////////////////////////////////////////////////////////////////////////

View File

@ -8,6 +8,7 @@
use std::ops::{ControlFlow, Range};
use hir::def::{CtorKind, DefKind};
use rustc_abi::{ExternAbi, FIRST_VARIANT, FieldIdx, VariantIdx};
use rustc_data_structures::captures::Captures;
use rustc_errors::{ErrorGuaranteed, MultiSpan};
use rustc_hir as hir;
@ -16,8 +17,6 @@
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, extension};
use rustc_span::symbol::{Symbol, sym};
use rustc_span::{DUMMY_SP, Span};
use rustc_target::abi::{FIRST_VARIANT, FieldIdx, VariantIdx};
use rustc_target::spec::abi;
use rustc_type_ir::TyKind::*;
use rustc_type_ir::visit::TypeVisitableExt;
use rustc_type_ir::{self as ir, BoundVar, CollectAndApply, DynKind};
@ -1365,7 +1364,7 @@ pub fn fn_sig(self, tcx: TyCtxt<'tcx>) -> PolyFnSig<'tcx> {
inputs_and_output: ty::List::empty(),
c_variadic: false,
safety: hir::Safety::Safe,
abi: abi::Abi::Rust,
abi: ExternAbi::Rust,
})
}
Closure(..) => bug!(

View File

@ -2,6 +2,7 @@
use std::hash::Hash;
use std::iter;
use rustc_abi::{FieldIdx, VariantIdx};
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::unord::{ExtendUnord, UnordItems, UnordSet};
use rustc_errors::ErrorGuaranteed;
@ -16,7 +17,6 @@
use rustc_middle::mir::FakeReadCause;
use rustc_session::Session;
use rustc_span::Span;
use rustc_target::abi::{FieldIdx, VariantIdx};
use super::RvalueScopes;
use crate::hir::place::Place as HirPlace;

View File

@ -2,6 +2,7 @@
use std::{fmt, iter};
use rustc_abi::{ExternAbi, Float, Integer, IntegerType, Size};
use rustc_apfloat::Float as _;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::stable_hasher::{Hash128, HashStable, StableHasher};
@ -14,8 +15,6 @@
use rustc_macros::{HashStable, TyDecodable, TyEncodable, extension};
use rustc_session::Limit;
use rustc_span::sym;
use rustc_target::abi::{Float, Integer, IntegerType, Size};
use rustc_target::spec::abi::Abi;
use smallvec::{SmallVec, smallvec};
use tracing::{debug, instrument};
@ -1783,7 +1782,7 @@ pub fn is_doc_notable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
/// the compiler to make some assumptions about its shape; if the user doesn't use a feature gate, they may
/// cause an ICE that we otherwise may want to prevent.
pub fn intrinsic_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::IntrinsicDef> {
if (matches!(tcx.fn_sig(def_id).skip_binder().abi(), Abi::RustIntrinsic)
if (matches!(tcx.fn_sig(def_id).skip_binder().abi(), ExternAbi::RustIntrinsic)
&& tcx.features().intrinsics())
|| (tcx.has_attr(def_id, sym::rustc_intrinsic) && tcx.features().rustc_attrs())
{

View File

@ -67,7 +67,7 @@ fn from_cycle_error(
err,
false,
rustc_hir::Safety::Safe,
rustc_target::spec::abi::Abi::Rust,
rustc_abi::ExternAbi::Rust,
));
// SAFETY: This is never called when `Self` is not `ty::Binder<'tcx, ty::FnSig<'tcx>>`.