compiler: Directly use rustc_abi in ty_utils

This commit is contained in:
Jubilee Young 2024-11-02 19:33:06 -07:00
parent 6c16a3123b
commit 092135b7b4
4 changed files with 19 additions and 21 deletions

View File

@ -1,7 +1,7 @@
use std::iter;
use rustc_abi::Primitive::Pointer;
use rustc_abi::{BackendRepr, PointerKind, Scalar, Size};
use rustc_abi::{BackendRepr, ExternAbi, PointerKind, Scalar, Size};
use rustc_hir as hir;
use rustc_hir::lang_items::LangItem;
use rustc_middle::bug;
@ -12,10 +12,9 @@ use rustc_middle::ty::layout::{
use rustc_middle::ty::{self, InstanceKind, Ty, TyCtxt};
use rustc_session::config::OptLevel;
use rustc_span::def_id::DefId;
use rustc_target::abi::call::{
use rustc_target::callconv::{
ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, Conv, FnAbi, PassMode, RiscvInterruptKind,
};
use rustc_target::spec::abi::Abi as SpecAbi;
use tracing::debug;
pub(crate) fn provide(providers: &mut Providers) {
@ -39,7 +38,7 @@ fn fn_sig_for_fn_abi<'tcx>(
tcx.thread_local_ptr_ty(instance.def_id()),
false,
hir::Safety::Safe,
rustc_target::spec::abi::Abi::Unadjusted,
rustc_abi::ExternAbi::Unadjusted,
));
}
@ -270,7 +269,7 @@ fn fn_sig_for_fn_abi<'tcx>(
ret_ty,
false,
hir::Safety::Safe,
rustc_target::spec::abi::Abi::Rust,
rustc_abi::ExternAbi::Rust,
)
} else {
// `Iterator::next` doesn't have a `resume` argument.
@ -279,7 +278,7 @@ fn fn_sig_for_fn_abi<'tcx>(
ret_ty,
false,
hir::Safety::Safe,
rustc_target::spec::abi::Abi::Rust,
rustc_abi::ExternAbi::Rust,
)
};
ty::Binder::bind_with_vars(fn_sig, bound_vars)
@ -289,8 +288,8 @@ fn fn_sig_for_fn_abi<'tcx>(
}
#[inline]
fn conv_from_spec_abi(tcx: TyCtxt<'_>, abi: SpecAbi, c_variadic: bool) -> Conv {
use rustc_target::spec::abi::Abi::*;
fn conv_from_spec_abi(tcx: TyCtxt<'_>, abi: ExternAbi, c_variadic: bool) -> Conv {
use rustc_abi::ExternAbi::*;
match tcx.sess.target.adjust_abi(abi, c_variadic) {
RustIntrinsic | Rust | RustCall => Conv::Rust,
@ -453,12 +452,12 @@ fn adjust_for_rust_scalar<'tcx>(
fn fn_abi_sanity_check<'tcx>(
cx: &LayoutCx<'tcx>,
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
spec_abi: SpecAbi,
spec_abi: ExternAbi,
) {
fn fn_arg_sanity_check<'tcx>(
cx: &LayoutCx<'tcx>,
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
spec_abi: SpecAbi,
spec_abi: ExternAbi,
arg: &ArgAbi<'tcx, Ty<'tcx>>,
) {
let tcx = cx.tcx();
@ -489,7 +488,7 @@ fn fn_abi_sanity_check<'tcx>(
// (See issue: https://github.com/rust-lang/rust/issues/117271)
assert!(
matches!(&*tcx.sess.target.arch, "wasm32" | "wasm64")
|| matches!(spec_abi, SpecAbi::PtxKernel | SpecAbi::Unadjusted),
|| matches!(spec_abi, ExternAbi::PtxKernel | ExternAbi::Unadjusted),
"`PassMode::Direct` for aggregates only allowed for \"unadjusted\" and \"ptx-kernel\" functions and on wasm\n\
Problematic type: {:#?}",
arg.layout,
@ -556,7 +555,7 @@ fn fn_abi_new_uncached<'tcx>(
let conv = conv_from_spec_abi(cx.tcx(), sig.abi, sig.c_variadic);
let mut inputs = sig.inputs();
let extra_args = if sig.abi == SpecAbi::RustCall {
let extra_args = if sig.abi == ExternAbi::RustCall {
assert!(!sig.c_variadic && extra_args.is_empty());
if let Some(input) = sig.inputs().last() {
@ -649,10 +648,10 @@ fn fn_abi_new_uncached<'tcx>(
fn fn_abi_adjust_for_abi<'tcx>(
cx: &LayoutCx<'tcx>,
fn_abi: &mut FnAbi<'tcx, Ty<'tcx>>,
abi: SpecAbi,
abi: ExternAbi,
fn_def_id: Option<DefId>,
) -> Result<(), &'tcx FnAbiError<'tcx>> {
if abi == SpecAbi::Unadjusted {
if abi == ExternAbi::Unadjusted {
// The "unadjusted" ABI passes aggregates in "direct" mode. That's fragile but needed for
// some LLVM intrinsics.
fn unadjust<'tcx>(arg: &mut ArgAbi<'tcx, Ty<'tcx>>) {
@ -676,7 +675,7 @@ fn fn_abi_adjust_for_abi<'tcx>(
let tcx = cx.tcx();
if abi == SpecAbi::Rust || abi == SpecAbi::RustCall || abi == SpecAbi::RustIntrinsic {
if abi == ExternAbi::Rust || abi == ExternAbi::RustCall || abi == ExternAbi::RustIntrinsic {
fn_abi.adjust_for_rust_abi(cx, abi);
// Look up the deduced parameter attributes for this function, if we have its def ID and

View File

@ -1,5 +1,6 @@
use std::iter;
use rustc_abi::{FIRST_VARIANT, VariantIdx};
use rustc_errors::ErrorGuaranteed;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::LocalDefId;
@ -11,7 +12,6 @@ use rustc_middle::ty::abstract_const::CastKind;
use rustc_middle::ty::{self, Expr, TyCtxt, TypeVisitableExt};
use rustc_middle::{bug, mir, thir};
use rustc_span::Span;
use rustc_target::abi::{FIRST_VARIANT, VariantIdx};
use tracing::{debug, instrument};
use crate::errors::{GenericConstantTooComplex, GenericConstantTooComplexSub};

View File

@ -5,9 +5,9 @@ use hir::def_id::DefId;
use rustc_abi::Integer::{I8, I32};
use rustc_abi::Primitive::{self, Float, Int, Pointer};
use rustc_abi::{
AbiAndPrefAlign, AddressSpace, Align, BackendRepr, FieldsShape, HasDataLayout,
LayoutCalculatorError, LayoutData, Niche, ReprOptions, Scalar, Size, StructKind, TagEncoding,
Variants, WrappingRange,
AbiAndPrefAlign, AddressSpace, Align, BackendRepr, FIRST_VARIANT, FieldIdx, FieldsShape,
HasDataLayout, Layout, LayoutCalculatorError, LayoutData, Niche, ReprOptions, Scalar, Size,
StructKind, TagEncoding, VariantIdx, Variants, WrappingRange,
};
use rustc_index::bit_set::BitSet;
use rustc_index::{IndexSlice, IndexVec};
@ -24,7 +24,6 @@ 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::{FIRST_VARIANT, FieldIdx, Layout, VariantIdx};
use tracing::{debug, instrument, trace};
use {rustc_abi as abi, rustc_hir as hir};

View File

@ -1,8 +1,8 @@
use std::assert_matches::assert_matches;
use rustc_abi::{BackendRepr, FieldsShape, Scalar, Size, Variants};
use rustc_middle::bug;
use rustc_middle::ty::layout::{HasTyCtxt, LayoutCx, TyAndLayout};
use rustc_target::abi::*;
/// Enforce some basic invariants on layouts.
pub(super) fn partially_check_layout<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayout<'tcx>) {