From 11c48bee11150987e4cce40ff83d0dc083d5c172 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Tue, 8 Oct 2024 16:58:27 -0700 Subject: [PATCH] compiler: Factor rustc_target::abi::* out of ty_utils --- compiler/rustc_ty_utils/Cargo.toml | 1 + compiler/rustc_ty_utils/src/abi.rs | 4 +++- compiler/rustc_ty_utils/src/layout.rs | 20 +++++++++++++------- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_ty_utils/Cargo.toml b/compiler/rustc_ty_utils/Cargo.toml index 01d5251bfa0..40356e0c978 100644 --- a/compiler/rustc_ty_utils/Cargo.toml +++ b/compiler/rustc_ty_utils/Cargo.toml @@ -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" } diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index 3d6c09bf89c..deda16b76b5 100644 --- a/compiler/rustc_ty_utils/src/abi.rs +++ b/compiler/rustc_ty_utils/src/abi.rs @@ -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; diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index 34c9f1b63c0..afdfa2e80c1 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -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 },