compiler: Factor rustc_target::abi::* out of middle::ty::layout

This commit is contained in:
Jubilee Young 2024-10-08 16:13:54 -07:00
parent a49aefcd8b
commit 8da92b5ce2
2 changed files with 18 additions and 7 deletions

View File

@ -12,6 +12,7 @@ field-offset = "0.3.5"
gsgdt = "0.1.2" gsgdt = "0.1.2"
polonius-engine = "0.13.0" polonius-engine = "0.13.0"
rustc-rayon-core = { version = "0.5.0", optional = true } rustc-rayon-core = { version = "0.5.0", optional = true }
rustc_abi = { path = "../rustc_abi" }
rustc_apfloat = "0.2.0" rustc_apfloat = "0.2.0"
rustc_arena = { path = "../rustc_arena" } rustc_arena = { path = "../rustc_arena" }
rustc_ast = { path = "../rustc_ast" } rustc_ast = { path = "../rustc_ast" }

View File

@ -2,11 +2,15 @@ use std::num::NonZero;
use std::ops::Bound; use std::ops::Bound;
use std::{cmp, fmt}; use std::{cmp, fmt};
use rustc_abi::Primitive::{self, Float, Int, Pointer};
use rustc_abi::{
Abi, AddressSpace, Align, FieldsShape, HasDataLayout, Integer, LayoutCalculator, LayoutS,
PointeeInfo, PointerKind, ReprOptions, Scalar, Size, TagEncoding, TargetDataLayout, Variants,
};
use rustc_error_messages::DiagMessage; use rustc_error_messages::DiagMessage;
use rustc_errors::{ use rustc_errors::{
Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg, Level, Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg, Level,
}; };
use rustc_hir as hir;
use rustc_hir::LangItem; use rustc_hir::LangItem;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_index::IndexVec; use rustc_index::IndexVec;
@ -15,10 +19,11 @@ use rustc_session::config::OptLevel;
use rustc_span::symbol::{Symbol, sym}; use rustc_span::symbol::{Symbol, sym};
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span}; use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
use rustc_target::abi::call::FnAbi; use rustc_target::abi::call::FnAbi;
use rustc_target::abi::*; use rustc_target::abi::{FieldIdx, TyAbiInterface, VariantIdx, call};
use rustc_target::spec::abi::Abi as SpecAbi; use rustc_target::spec::abi::Abi as SpecAbi;
use rustc_target::spec::{HasTargetSpec, HasWasmCAbiOpt, PanicStrategy, Target, WasmCAbi}; use rustc_target::spec::{HasTargetSpec, HasWasmCAbiOpt, PanicStrategy, Target, WasmCAbi};
use tracing::debug; use tracing::debug;
use {rustc_abi as abi, rustc_hir as hir};
use crate::error::UnsupportedFnAbi; use crate::error::UnsupportedFnAbi;
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
@ -27,9 +32,10 @@ use crate::ty::normalize_erasing_regions::NormalizationError;
use crate::ty::{self, CoroutineArgsExt, Ty, TyCtxt, TypeVisitableExt}; use crate::ty::{self, CoroutineArgsExt, Ty, TyCtxt, TypeVisitableExt};
#[extension(pub trait IntegerExt)] #[extension(pub trait IntegerExt)]
impl Integer { impl abi::Integer {
#[inline] #[inline]
fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx>, signed: bool) -> Ty<'tcx> { fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx>, signed: bool) -> Ty<'tcx> {
use abi::Integer::{I8, I16, I32, I64, I128};
match (*self, signed) { match (*self, signed) {
(I8, false) => tcx.types.u8, (I8, false) => tcx.types.u8,
(I16, false) => tcx.types.u16, (I16, false) => tcx.types.u16,
@ -44,7 +50,8 @@ impl Integer {
} }
} }
fn from_int_ty<C: HasDataLayout>(cx: &C, ity: ty::IntTy) -> Integer { fn from_int_ty<C: HasDataLayout>(cx: &C, ity: ty::IntTy) -> abi::Integer {
use abi::Integer::{I8, I16, I32, I64, I128};
match ity { match ity {
ty::IntTy::I8 => I8, ty::IntTy::I8 => I8,
ty::IntTy::I16 => I16, ty::IntTy::I16 => I16,
@ -54,7 +61,8 @@ impl Integer {
ty::IntTy::Isize => cx.data_layout().ptr_sized_integer(), ty::IntTy::Isize => cx.data_layout().ptr_sized_integer(),
} }
} }
fn from_uint_ty<C: HasDataLayout>(cx: &C, ity: ty::UintTy) -> Integer { fn from_uint_ty<C: HasDataLayout>(cx: &C, ity: ty::UintTy) -> abi::Integer {
use abi::Integer::{I8, I16, I32, I64, I128};
match ity { match ity {
ty::UintTy::U8 => I8, ty::UintTy::U8 => I8,
ty::UintTy::U16 => I16, ty::UintTy::U16 => I16,
@ -102,7 +110,7 @@ impl Integer {
tcx.data_layout().c_enum_min_size tcx.data_layout().c_enum_min_size
} else { } else {
// repr(Rust) enums try to be as small as possible // repr(Rust) enums try to be as small as possible
I8 Integer::I8
}; };
// If there are no negative values, we can use the unsigned fit. // If there are no negative values, we can use the unsigned fit.
@ -115,9 +123,10 @@ impl Integer {
} }
#[extension(pub trait FloatExt)] #[extension(pub trait FloatExt)]
impl Float { impl abi::Float {
#[inline] #[inline]
fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
use abi::Float::*;
match *self { match *self {
F16 => tcx.types.f16, F16 => tcx.types.f16,
F32 => tcx.types.f32, F32 => tcx.types.f32,
@ -127,6 +136,7 @@ impl Float {
} }
fn from_float_ty(fty: ty::FloatTy) -> Self { fn from_float_ty(fty: ty::FloatTy) -> Self {
use abi::Float::*;
match fty { match fty {
ty::FloatTy::F16 => F16, ty::FloatTy::F16 => F16,
ty::FloatTy::F32 => F32, ty::FloatTy::F32 => F32,