compiler: Factor rustc_target::abi::* out of ty_utils

This commit is contained in:
Jubilee Young 2024-10-08 16:58:27 -07:00
parent 8da92b5ce2
commit 11c48bee11
3 changed files with 17 additions and 8 deletions

View File

@ -6,6 +6,7 @@ edition = "2021"
[dependencies]
# tidy-alphabetical-start
itertools = "0.12"
rustc_abi = { path = "../rustc_abi" }
rustc_ast_ir = { path = "../rustc_ast_ir" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }

View File

@ -1,5 +1,8 @@
use std::iter;
use rustc_abi::Float::*;
use rustc_abi::Primitive::{Float, Pointer};
use rustc_abi::{Abi, AddressSpace, PointerKind, Scalar, Size};
use rustc_hir as hir;
use rustc_hir::lang_items::LangItem;
use rustc_middle::bug;
@ -14,7 +17,6 @@ use rustc_target::abi::call::{
ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, Conv, FnAbi, PassMode, Reg, RegKind,
RiscvInterruptKind,
};
use rustc_target::abi::*;
use rustc_target::spec::abi::Abi as SpecAbi;
use tracing::debug;

View File

@ -2,7 +2,12 @@ use std::fmt::Debug;
use std::iter;
use hir::def_id::DefId;
use rustc_hir as hir;
use rustc_abi::Integer::{I8, I32};
use rustc_abi::Primitive::{self, Float, Int, Pointer};
use rustc_abi::{
Abi, AbiAndPrefAlign, AddressSpace, Align, FieldsShape, HasDataLayout, LayoutCalculatorError,
LayoutS, Niche, ReprOptions, Scalar, Size, StructKind, TagEncoding, Variants, WrappingRange,
};
use rustc_index::bit_set::BitSet;
use rustc_index::{IndexSlice, IndexVec};
use rustc_middle::bug;
@ -18,8 +23,9 @@ use rustc_middle::ty::{
use rustc_session::{DataTypeKind, FieldInfo, FieldKind, SizeKind, VariantInfo};
use rustc_span::sym;
use rustc_span::symbol::Symbol;
use rustc_target::abi::*;
use rustc_target::abi::{FIRST_VARIANT, FieldIdx, Layout, VariantIdx};
use tracing::{debug, instrument, trace};
use {rustc_abi as abi, rustc_hir as hir};
use crate::errors::{
MultipleArrayFieldsSimdType, NonPrimitiveSimdType, OversizedSimdType, ZeroLengthSimdType,
@ -202,9 +208,9 @@ fn layout_of_uncached<'tcx>(
value: Int(I32, false),
valid_range: WrappingRange { start: 0, end: 0x10FFFF },
})),
ty::Int(ity) => scalar(Int(Integer::from_int_ty(dl, ity), true)),
ty::Uint(ity) => scalar(Int(Integer::from_uint_ty(dl, ity), false)),
ty::Float(fty) => scalar(Float(Float::from_float_ty(fty))),
ty::Int(ity) => scalar(Int(abi::Integer::from_int_ty(dl, ity), true)),
ty::Uint(ity) => scalar(Int(abi::Integer::from_uint_ty(dl, ity), false)),
ty::Float(fty) => scalar(Float(abi::Float::from_float_ty(fty))),
ty::FnPtr(..) => {
let mut ptr = scalar_unit(Pointer(dl.instruction_address_space));
ptr.valid_range_mut().start = 1;
@ -563,7 +569,7 @@ fn layout_of_uncached<'tcx>(
}
let get_discriminant_type =
|min, max| Integer::repr_discr(tcx, ty, &def.repr(), min, max);
|min, max| abi::Integer::repr_discr(tcx, ty, &def.repr(), min, max);
let discriminants_iter = || {
def.is_enum()
@ -816,7 +822,7 @@ fn coroutine_layout<'tcx>(
// `info.variant_fields` already accounts for the reserved variants, so no need to add them.
let max_discr = (info.variant_fields.len() - 1) as u128;
let discr_int = Integer::fit_unsigned(max_discr);
let discr_int = abi::Integer::fit_unsigned(max_discr);
let tag = Scalar::Initialized {
value: Primitive::Int(discr_int, /* signed = */ false),
valid_range: WrappingRange { start: 0, end: max_discr },