Skip to content

Commit 11c48be

Browse files
compiler: Factor rustc_target::abi::* out of ty_utils
1 parent 8da92b5 commit 11c48be

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

compiler/rustc_ty_utils/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2021"
66
[dependencies]
77
# tidy-alphabetical-start
88
itertools = "0.12"
9+
rustc_abi = { path = "../rustc_abi" }
910
rustc_ast_ir = { path = "../rustc_ast_ir" }
1011
rustc_data_structures = { path = "../rustc_data_structures" }
1112
rustc_errors = { path = "../rustc_errors" }

compiler/rustc_ty_utils/src/abi.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use std::iter;
22

3+
use rustc_abi::Float::*;
4+
use rustc_abi::Primitive::{Float, Pointer};
5+
use rustc_abi::{Abi, AddressSpace, PointerKind, Scalar, Size};
36
use rustc_hir as hir;
47
use rustc_hir::lang_items::LangItem;
58
use rustc_middle::bug;
@@ -14,7 +17,6 @@ use rustc_target::abi::call::{
1417
ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, Conv, FnAbi, PassMode, Reg, RegKind,
1518
RiscvInterruptKind,
1619
};
17-
use rustc_target::abi::*;
1820
use rustc_target::spec::abi::Abi as SpecAbi;
1921
use tracing::debug;
2022

compiler/rustc_ty_utils/src/layout.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ use std::fmt::Debug;
22
use std::iter;
33

44
use hir::def_id::DefId;
5-
use rustc_hir as hir;
5+
use rustc_abi::Integer::{I8, I32};
6+
use rustc_abi::Primitive::{self, Float, Int, Pointer};
7+
use rustc_abi::{
8+
Abi, AbiAndPrefAlign, AddressSpace, Align, FieldsShape, HasDataLayout, LayoutCalculatorError,
9+
LayoutS, Niche, ReprOptions, Scalar, Size, StructKind, TagEncoding, Variants, WrappingRange,
10+
};
611
use rustc_index::bit_set::BitSet;
712
use rustc_index::{IndexSlice, IndexVec};
813
use rustc_middle::bug;
@@ -18,8 +23,9 @@ use rustc_middle::ty::{
1823
use rustc_session::{DataTypeKind, FieldInfo, FieldKind, SizeKind, VariantInfo};
1924
use rustc_span::sym;
2025
use rustc_span::symbol::Symbol;
21-
use rustc_target::abi::*;
26+
use rustc_target::abi::{FIRST_VARIANT, FieldIdx, Layout, VariantIdx};
2227
use tracing::{debug, instrument, trace};
28+
use {rustc_abi as abi, rustc_hir as hir};
2329

2430
use crate::errors::{
2531
MultipleArrayFieldsSimdType, NonPrimitiveSimdType, OversizedSimdType, ZeroLengthSimdType,
@@ -202,9 +208,9 @@ fn layout_of_uncached<'tcx>(
202208
value: Int(I32, false),
203209
valid_range: WrappingRange { start: 0, end: 0x10FFFF },
204210
})),
205-
ty::Int(ity) => scalar(Int(Integer::from_int_ty(dl, ity), true)),
206-
ty::Uint(ity) => scalar(Int(Integer::from_uint_ty(dl, ity), false)),
207-
ty::Float(fty) => scalar(Float(Float::from_float_ty(fty))),
211+
ty::Int(ity) => scalar(Int(abi::Integer::from_int_ty(dl, ity), true)),
212+
ty::Uint(ity) => scalar(Int(abi::Integer::from_uint_ty(dl, ity), false)),
213+
ty::Float(fty) => scalar(Float(abi::Float::from_float_ty(fty))),
208214
ty::FnPtr(..) => {
209215
let mut ptr = scalar_unit(Pointer(dl.instruction_address_space));
210216
ptr.valid_range_mut().start = 1;
@@ -563,7 +569,7 @@ fn layout_of_uncached<'tcx>(
563569
}
564570

565571
let get_discriminant_type =
566-
|min, max| Integer::repr_discr(tcx, ty, &def.repr(), min, max);
572+
|min, max| abi::Integer::repr_discr(tcx, ty, &def.repr(), min, max);
567573

568574
let discriminants_iter = || {
569575
def.is_enum()
@@ -816,7 +822,7 @@ fn coroutine_layout<'tcx>(
816822

817823
// `info.variant_fields` already accounts for the reserved variants, so no need to add them.
818824
let max_discr = (info.variant_fields.len() - 1) as u128;
819-
let discr_int = Integer::fit_unsigned(max_discr);
825+
let discr_int = abi::Integer::fit_unsigned(max_discr);
820826
let tag = Scalar::Initialized {
821827
value: Primitive::Int(discr_int, /* signed = */ false),
822828
valid_range: WrappingRange { start: 0, end: max_discr },

0 commit comments

Comments
 (0)