Skip to content

Commit

Permalink
compiler: Factor rustc_target::abi::* out of ty_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
workingjubilee committed Oct 9, 2024
1 parent 8da92b5 commit 11c48be
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_ty_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_ty_utils/src/abi.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down
20 changes: 13 additions & 7 deletions compiler/rustc_ty_utils/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 },
Expand Down

0 comments on commit 11c48be

Please sign in to comment.