Skip to content

Commit 8da92b5

Browse files
compiler: Factor rustc_target::abi::* out of middle::ty::layout
1 parent a49aefc commit 8da92b5

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

compiler/rustc_middle/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ field-offset = "0.3.5"
1212
gsgdt = "0.1.2"
1313
polonius-engine = "0.13.0"
1414
rustc-rayon-core = { version = "0.5.0", optional = true }
15+
rustc_abi = { path = "../rustc_abi" }
1516
rustc_apfloat = "0.2.0"
1617
rustc_arena = { path = "../rustc_arena" }
1718
rustc_ast = { path = "../rustc_ast" }

compiler/rustc_middle/src/ty/layout.rs

+17-7
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ use std::num::NonZero;
22
use std::ops::Bound;
33
use std::{cmp, fmt};
44

5+
use rustc_abi::Primitive::{self, Float, Int, Pointer};
6+
use rustc_abi::{
7+
Abi, AddressSpace, Align, FieldsShape, HasDataLayout, Integer, LayoutCalculator, LayoutS,
8+
PointeeInfo, PointerKind, ReprOptions, Scalar, Size, TagEncoding, TargetDataLayout, Variants,
9+
};
510
use rustc_error_messages::DiagMessage;
611
use rustc_errors::{
712
Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg, Level,
813
};
9-
use rustc_hir as hir;
1014
use rustc_hir::LangItem;
1115
use rustc_hir::def_id::DefId;
1216
use rustc_index::IndexVec;
@@ -15,10 +19,11 @@ use rustc_session::config::OptLevel;
1519
use rustc_span::symbol::{Symbol, sym};
1620
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
1721
use rustc_target::abi::call::FnAbi;
18-
use rustc_target::abi::*;
22+
use rustc_target::abi::{FieldIdx, TyAbiInterface, VariantIdx, call};
1923
use rustc_target::spec::abi::Abi as SpecAbi;
2024
use rustc_target::spec::{HasTargetSpec, HasWasmCAbiOpt, PanicStrategy, Target, WasmCAbi};
2125
use tracing::debug;
26+
use {rustc_abi as abi, rustc_hir as hir};
2227

2328
use crate::error::UnsupportedFnAbi;
2429
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
@@ -27,9 +32,10 @@ use crate::ty::normalize_erasing_regions::NormalizationError;
2732
use crate::ty::{self, CoroutineArgsExt, Ty, TyCtxt, TypeVisitableExt};
2833

2934
#[extension(pub trait IntegerExt)]
30-
impl Integer {
35+
impl abi::Integer {
3136
#[inline]
3237
fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx>, signed: bool) -> Ty<'tcx> {
38+
use abi::Integer::{I8, I16, I32, I64, I128};
3339
match (*self, signed) {
3440
(I8, false) => tcx.types.u8,
3541
(I16, false) => tcx.types.u16,
@@ -44,7 +50,8 @@ impl Integer {
4450
}
4551
}
4652

47-
fn from_int_ty<C: HasDataLayout>(cx: &C, ity: ty::IntTy) -> Integer {
53+
fn from_int_ty<C: HasDataLayout>(cx: &C, ity: ty::IntTy) -> abi::Integer {
54+
use abi::Integer::{I8, I16, I32, I64, I128};
4855
match ity {
4956
ty::IntTy::I8 => I8,
5057
ty::IntTy::I16 => I16,
@@ -54,7 +61,8 @@ impl Integer {
5461
ty::IntTy::Isize => cx.data_layout().ptr_sized_integer(),
5562
}
5663
}
57-
fn from_uint_ty<C: HasDataLayout>(cx: &C, ity: ty::UintTy) -> Integer {
64+
fn from_uint_ty<C: HasDataLayout>(cx: &C, ity: ty::UintTy) -> abi::Integer {
65+
use abi::Integer::{I8, I16, I32, I64, I128};
5866
match ity {
5967
ty::UintTy::U8 => I8,
6068
ty::UintTy::U16 => I16,
@@ -102,7 +110,7 @@ impl Integer {
102110
tcx.data_layout().c_enum_min_size
103111
} else {
104112
// repr(Rust) enums try to be as small as possible
105-
I8
113+
Integer::I8
106114
};
107115

108116
// If there are no negative values, we can use the unsigned fit.
@@ -115,9 +123,10 @@ impl Integer {
115123
}
116124

117125
#[extension(pub trait FloatExt)]
118-
impl Float {
126+
impl abi::Float {
119127
#[inline]
120128
fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
129+
use abi::Float::*;
121130
match *self {
122131
F16 => tcx.types.f16,
123132
F32 => tcx.types.f32,
@@ -127,6 +136,7 @@ impl Float {
127136
}
128137

129138
fn from_float_ty(fty: ty::FloatTy) -> Self {
139+
use abi::Float::*;
130140
match fty {
131141
ty::FloatTy::F16 => F16,
132142
ty::FloatTy::F32 => F32,

0 commit comments

Comments
 (0)