Skip to content

Commit a176bd2

Browse files
authored
Rollup merge of #70634 - Centril:import-directly, r=Mark-Simulacrum
Remove some reexports in `rustc_middle` This will help get these imports out of the way of detecting the true dependencies in and out to `rustc_middle`, thereby helping future work towards #65031.
2 parents 4b6231b + d796b7a commit a176bd2

File tree

132 files changed

+416
-469
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+416
-469
lines changed

src/librustc_codegen_llvm/abi.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@ use rustc_codegen_ssa::mir::place::PlaceRef;
1010
use rustc_codegen_ssa::traits::*;
1111
use rustc_codegen_ssa::MemFlags;
1212
use rustc_middle::bug;
13-
use rustc_middle::ty::layout::{self};
13+
pub use rustc_middle::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA};
1414
use rustc_middle::ty::Ty;
1515
use rustc_target::abi::call::ArgAbi;
16-
use rustc_target::abi::{HasDataLayout, LayoutOf};
17-
18-
use libc::c_uint;
19-
20-
pub use rustc_middle::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA};
2116
pub use rustc_target::abi::call::*;
17+
use rustc_target::abi::{self, HasDataLayout, Int, LayoutOf};
2218
pub use rustc_target::spec::abi::Abi;
2319

20+
use libc::c_uint;
21+
2422
macro_rules! for_each_kind {
2523
($flags: ident, $f: ident, $($kind: ident),+) => ({
2624
$(if $flags.contains(ArgAttribute::$kind) { $f(llvm::Attribute::$kind) })+
@@ -443,11 +441,11 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
443441
PassMode::Indirect(ref attrs, _) => apply(attrs, Some(self.ret.layout.llvm_type(bx))),
444442
_ => {}
445443
}
446-
if let layout::Abi::Scalar(ref scalar) = self.ret.layout.abi {
444+
if let abi::Abi::Scalar(ref scalar) = self.ret.layout.abi {
447445
// If the value is a boolean, the range is 0..2 and that ultimately
448446
// become 0..0 when the type becomes i1, which would be rejected
449447
// by the LLVM verifier.
450-
if let layout::Int(..) = scalar.value {
448+
if let Int(..) = scalar.value {
451449
if !scalar.is_bool() {
452450
let range = scalar.valid_range_exclusive(bx);
453451
if range.start != range.end {

src/librustc_codegen_llvm/builder.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ use rustc_codegen_ssa::MemFlags;
1616
use rustc_data_structures::const_cstr;
1717
use rustc_data_structures::small_c_str::SmallCStr;
1818
use rustc_hir::def_id::DefId;
19-
use rustc_middle::ty::layout::{self, Align, Size, TyAndLayout};
19+
use rustc_middle::ty::layout::TyAndLayout;
2020
use rustc_middle::ty::{self, Ty, TyCtxt};
2121
use rustc_session::config::{self, Sanitizer};
22+
use rustc_target::abi::{self, Align, Size};
2223
use rustc_target::spec::{HasTargetSpec, Target};
2324
use std::borrow::Cow;
2425
use std::ffi::CStr;
@@ -60,8 +61,8 @@ impl BackendTypes for Builder<'_, 'll, 'tcx> {
6061
type DIVariable = <CodegenCx<'ll, 'tcx> as BackendTypes>::DIVariable;
6162
}
6263

63-
impl ty::layout::HasDataLayout for Builder<'_, '_, '_> {
64-
fn data_layout(&self) -> &ty::layout::TargetDataLayout {
64+
impl abi::HasDataLayout for Builder<'_, '_, '_> {
65+
fn data_layout(&self) -> &abi::TargetDataLayout {
6566
self.cx.data_layout()
6667
}
6768
}
@@ -84,7 +85,7 @@ impl HasTargetSpec for Builder<'_, '_, 'tcx> {
8485
}
8586
}
8687

87-
impl ty::layout::LayoutOf for Builder<'_, '_, 'tcx> {
88+
impl abi::LayoutOf for Builder<'_, '_, 'tcx> {
8889
type Ty = Ty<'tcx>;
8990
type TyAndLayout = TyAndLayout<'tcx>;
9091

@@ -435,17 +436,17 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
435436
fn scalar_load_metadata<'a, 'll, 'tcx>(
436437
bx: &mut Builder<'a, 'll, 'tcx>,
437438
load: &'ll Value,
438-
scalar: &layout::Scalar,
439+
scalar: &abi::Scalar,
439440
) {
440441
let vr = scalar.valid_range.clone();
441442
match scalar.value {
442-
layout::Int(..) => {
443+
abi::Int(..) => {
443444
let range = scalar.valid_range_exclusive(bx);
444445
if range.start != range.end {
445446
bx.range_metadata(load, range);
446447
}
447448
}
448-
layout::Pointer if vr.start() < vr.end() && !vr.contains(&0) => {
449+
abi::Pointer if vr.start() < vr.end() && !vr.contains(&0) => {
449450
bx.nonnull_metadata(load);
450451
}
451452
_ => {}
@@ -465,16 +466,16 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
465466
}
466467
let llval = const_llval.unwrap_or_else(|| {
467468
let load = self.load(place.llval, place.align);
468-
if let layout::Abi::Scalar(ref scalar) = place.layout.abi {
469+
if let abi::Abi::Scalar(ref scalar) = place.layout.abi {
469470
scalar_load_metadata(self, load, scalar);
470471
}
471472
load
472473
});
473474
OperandValue::Immediate(to_immediate(self, llval, place.layout))
474-
} else if let layout::Abi::ScalarPair(ref a, ref b) = place.layout.abi {
475+
} else if let abi::Abi::ScalarPair(ref a, ref b) = place.layout.abi {
475476
let b_offset = a.value.size(self).align_to(b.value.align(self).abi);
476477

477-
let mut load = |i, scalar: &layout::Scalar, align| {
478+
let mut load = |i, scalar: &abi::Scalar, align| {
478479
let llptr = self.struct_gep(place.llval, i as u64);
479480
let load = self.load(llptr, align);
480481
scalar_load_metadata(self, load, scalar);

src/librustc_codegen_llvm/common.rs

+12-19
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,24 @@
22

33
//! Code that is useful in various codegen modules.
44
5-
use crate::consts;
5+
use crate::consts::{self, const_alloc_to_llvm};
6+
pub use crate::context::CodegenCx;
67
use crate::llvm::{self, BasicBlock, Bool, ConstantInt, False, OperandBundleDef, True};
78
use crate::type_::Type;
89
use crate::type_of::LayoutLlvmExt;
910
use crate::value::Value;
10-
use log::debug;
11-
use rustc_codegen_ssa::traits::*;
12-
use rustc_middle::bug;
1311

14-
use crate::consts::const_alloc_to_llvm;
12+
use rustc_ast::ast::Mutability;
1513
use rustc_codegen_ssa::mir::place::PlaceRef;
14+
use rustc_codegen_ssa::traits::*;
15+
use rustc_middle::bug;
1616
use rustc_middle::mir::interpret::{Allocation, GlobalAlloc, Scalar};
17-
use rustc_middle::ty::layout::{self, HasDataLayout, LayoutOf, Size, TyAndLayout};
18-
19-
use libc::{c_char, c_uint};
20-
21-
use rustc_ast::ast::Mutability;
17+
use rustc_middle::ty::layout::TyAndLayout;
2218
use rustc_span::symbol::Symbol;
19+
use rustc_target::abi::{self, HasDataLayout, LayoutOf, Pointer, Size};
2320

24-
pub use crate::context::CodegenCx;
21+
use libc::{c_char, c_uint};
22+
use log::debug;
2523

2624
/*
2725
* A note on nomenclature of linking: "extern", "foreign", and "upcall".
@@ -229,12 +227,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
229227
})
230228
}
231229

232-
fn scalar_to_backend(
233-
&self,
234-
cv: Scalar,
235-
layout: &layout::Scalar,
236-
llty: &'ll Type,
237-
) -> &'ll Value {
230+
fn scalar_to_backend(&self, cv: Scalar, layout: &abi::Scalar, llty: &'ll Type) -> &'ll Value {
238231
let bitsize = if layout.is_bool() { 1 } else { layout.value.size(self).bits() };
239232
match cv {
240233
Scalar::Raw { size: 0, .. } => {
@@ -244,7 +237,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
244237
Scalar::Raw { data, size } => {
245238
assert_eq!(size as u64, layout.value.size(self).bytes());
246239
let llval = self.const_uint_big(self.type_ix(bitsize), data);
247-
if layout.value == layout::Pointer {
240+
if layout.value == Pointer {
248241
unsafe { llvm::LLVMConstIntToPtr(llval, llty) }
249242
} else {
250243
self.const_bitcast(llval, llty)
@@ -278,7 +271,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
278271
1,
279272
)
280273
};
281-
if layout.value != layout::Pointer {
274+
if layout.value != Pointer {
282275
unsafe { llvm::LLVMConstPtrToInt(llval, llty) }
283276
} else {
284277
self.const_bitcast(llval, llty)

src/librustc_codegen_llvm/consts.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ use rustc_middle::mir::interpret::{
1616
read_target_uint, Allocation, ConstValue, ErrorHandled, Pointer,
1717
};
1818
use rustc_middle::mir::mono::MonoItem;
19-
use rustc_middle::ty::layout::{self, Align, LayoutOf, Size};
2019
use rustc_middle::ty::{self, Instance, Ty};
2120
use rustc_middle::{bug, span_bug};
2221
use rustc_span::symbol::{sym, Symbol};
2322
use rustc_span::Span;
24-
use rustc_target::abi::HasDataLayout;
23+
use rustc_target::abi::{Align, HasDataLayout, LayoutOf, Primitive, Scalar, Size};
2524

2625
use std::ffi::CStr;
2726

@@ -56,7 +55,7 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll
5655
as u64;
5756
llvals.push(cx.scalar_to_backend(
5857
Pointer::new(alloc_id, Size::from_bytes(ptr_offset)).into(),
59-
&layout::Scalar { value: layout::Primitive::Pointer, valid_range: 0..=!0 },
58+
&Scalar { value: Primitive::Pointer, valid_range: 0..=!0 },
6059
cx.type_i8p(),
6160
));
6261
next_offset = offset + pointer_size;

src/librustc_codegen_llvm/context.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ use rustc_data_structures::fx::FxHashMap;
1414
use rustc_data_structures::small_c_str::SmallCStr;
1515
use rustc_middle::bug;
1616
use rustc_middle::mir::mono::CodegenUnit;
17-
use rustc_middle::ty::layout::{
18-
HasParamEnv, LayoutError, LayoutOf, PointeeInfo, Size, TyAndLayout, VariantIdx,
19-
};
17+
use rustc_middle::ty::layout::{HasParamEnv, LayoutError, TyAndLayout};
2018
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
2119
use rustc_session::config::{self, CFGuard, DebugInfo};
2220
use rustc_session::Session;
2321
use rustc_span::source_map::{Span, DUMMY_SP};
2422
use rustc_span::symbol::Symbol;
23+
use rustc_target::abi::{HasDataLayout, LayoutOf, PointeeInfo, Size, TargetDataLayout, VariantIdx};
2524
use rustc_target::spec::{HasTargetSpec, Target};
2625

2726
use std::cell::{Cell, RefCell};
@@ -817,8 +816,8 @@ impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
817816
}
818817
}
819818

820-
impl ty::layout::HasDataLayout for CodegenCx<'ll, 'tcx> {
821-
fn data_layout(&self) -> &ty::layout::TargetDataLayout {
819+
impl HasDataLayout for CodegenCx<'ll, 'tcx> {
820+
fn data_layout(&self) -> &TargetDataLayout {
822821
&self.tcx.data_layout
823822
}
824823
}

src/librustc_codegen_llvm/debuginfo/metadata.rs

+29-39
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ use rustc_middle::ich::NodeIdHashingMode;
3434
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
3535
use rustc_middle::mir::interpret::truncate;
3636
use rustc_middle::mir::{self, Field, GeneratorLayout};
37-
use rustc_middle::ty::layout::{
38-
self, Align, Integer, IntegerExt, LayoutOf, PrimitiveExt, Size, TyAndLayout, VariantIdx,
39-
};
37+
use rustc_middle::ty::layout::{self, IntegerExt, PrimitiveExt, TyAndLayout};
4038
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
4139
use rustc_middle::ty::Instance;
4240
use rustc_middle::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt};
4341
use rustc_middle::{bug, span_bug};
4442
use rustc_session::config::{self, DebugInfo};
4543
use rustc_span::symbol::{Interner, Symbol};
4644
use rustc_span::{self, FileName, Span};
47-
use rustc_target::abi::HasDataLayout;
45+
use rustc_target::abi::{Abi, Align, DiscriminantKind, HasDataLayout, Integer, LayoutOf};
46+
use rustc_target::abi::{Int, Pointer, F32, F64};
47+
use rustc_target::abi::{Primitive, Size, VariantIdx, Variants};
4848

4949
use libc::{c_longlong, c_uint};
5050
use std::collections::hash_map::Entry;
@@ -1364,7 +1364,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
13641364
};
13651365

13661366
match self.layout.variants {
1367-
layout::Variants::Single { index } => {
1367+
Variants::Single { index } => {
13681368
if let ty::Adt(adt, _) = &self.enum_type.kind {
13691369
if adt.variants.is_empty() {
13701370
return vec![];
@@ -1399,8 +1399,8 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
13991399
discriminant: None,
14001400
}]
14011401
}
1402-
layout::Variants::Multiple {
1403-
discr_kind: layout::DiscriminantKind::Tag,
1402+
Variants::Multiple {
1403+
discr_kind: DiscriminantKind::Tag,
14041404
discr_index,
14051405
ref variants,
14061406
..
@@ -1457,9 +1457,9 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
14571457
})
14581458
.collect()
14591459
}
1460-
layout::Variants::Multiple {
1460+
Variants::Multiple {
14611461
discr_kind:
1462-
layout::DiscriminantKind::Niche { ref niche_variants, niche_start, dataful_variant },
1462+
DiscriminantKind::Niche { ref niche_variants, niche_start, dataful_variant },
14631463
ref discr,
14641464
ref variants,
14651465
discr_index,
@@ -1592,7 +1592,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
15921592
// Creates `MemberDescription`s for the fields of a single enum variant.
15931593
struct VariantMemberDescriptionFactory<'ll, 'tcx> {
15941594
/// Cloned from the `layout::Struct` describing the variant.
1595-
offsets: Vec<layout::Size>,
1595+
offsets: Vec<Size>,
15961596
args: Vec<(String, Ty<'tcx>)>,
15971597
discriminant_type_metadata: Option<&'ll DIType>,
15981598
span: Span,
@@ -1777,7 +1777,7 @@ fn prepare_enum_metadata(
17771777
// <unknown>
17781778
let file_metadata = unknown_file_metadata(cx);
17791779

1780-
let discriminant_type_metadata = |discr: layout::Primitive| {
1780+
let discriminant_type_metadata = |discr: Primitive| {
17811781
let enumerators_metadata: Vec<_> = match enum_type.kind {
17821782
ty::Adt(def, _) => def
17831783
.discriminants(cx.tcx)
@@ -1870,27 +1870,20 @@ fn prepare_enum_metadata(
18701870
let layout = cx.layout_of(enum_type);
18711871

18721872
if let (
1873-
&layout::Abi::Scalar(_),
1874-
&layout::Variants::Multiple {
1875-
discr_kind: layout::DiscriminantKind::Tag, ref discr, ..
1876-
},
1873+
&Abi::Scalar(_),
1874+
&Variants::Multiple { discr_kind: DiscriminantKind::Tag, ref discr, .. },
18771875
) = (&layout.abi, &layout.variants)
18781876
{
18791877
return FinalMetadata(discriminant_type_metadata(discr.value));
18801878
}
18811879

18821880
if use_enum_fallback(cx) {
18831881
let discriminant_type_metadata = match layout.variants {
1884-
layout::Variants::Single { .. }
1885-
| layout::Variants::Multiple {
1886-
discr_kind: layout::DiscriminantKind::Niche { .. },
1887-
..
1888-
} => None,
1889-
layout::Variants::Multiple {
1890-
discr_kind: layout::DiscriminantKind::Tag,
1891-
ref discr,
1892-
..
1893-
} => Some(discriminant_type_metadata(discr.value)),
1882+
Variants::Single { .. }
1883+
| Variants::Multiple { discr_kind: DiscriminantKind::Niche { .. }, .. } => None,
1884+
Variants::Multiple { discr_kind: DiscriminantKind::Tag, ref discr, .. } => {
1885+
Some(discriminant_type_metadata(discr.value))
1886+
}
18941887
};
18951888

18961889
let enum_metadata = {
@@ -1938,10 +1931,10 @@ fn prepare_enum_metadata(
19381931
};
19391932
let discriminator_metadata = match layout.variants {
19401933
// A single-variant enum has no discriminant.
1941-
layout::Variants::Single { .. } => None,
1934+
Variants::Single { .. } => None,
19421935

1943-
layout::Variants::Multiple {
1944-
discr_kind: layout::DiscriminantKind::Niche { .. },
1936+
Variants::Multiple {
1937+
discr_kind: DiscriminantKind::Niche { .. },
19451938
ref discr,
19461939
discr_index,
19471940
..
@@ -1951,10 +1944,10 @@ fn prepare_enum_metadata(
19511944
let align = discr.value.align(cx);
19521945

19531946
let discr_type = match discr.value {
1954-
layout::Int(t, _) => t,
1955-
layout::F32 => Integer::I32,
1956-
layout::F64 => Integer::I64,
1957-
layout::Pointer => cx.data_layout().ptr_sized_integer(),
1947+
Int(t, _) => t,
1948+
F32 => Integer::I32,
1949+
F64 => Integer::I64,
1950+
Pointer => cx.data_layout().ptr_sized_integer(),
19581951
}
19591952
.to_ty(cx.tcx, false);
19601953

@@ -1976,11 +1969,8 @@ fn prepare_enum_metadata(
19761969
}
19771970
}
19781971

1979-
layout::Variants::Multiple {
1980-
discr_kind: layout::DiscriminantKind::Tag,
1981-
ref discr,
1982-
discr_index,
1983-
..
1972+
Variants::Multiple {
1973+
discr_kind: DiscriminantKind::Tag, ref discr, discr_index, ..
19841974
} => {
19851975
let discr_type = discr.value.to_ty(cx.tcx);
19861976
let (size, align) = cx.size_and_align_of(discr_type);
@@ -2005,8 +1995,8 @@ fn prepare_enum_metadata(
20051995
};
20061996

20071997
let mut outer_fields = match layout.variants {
2008-
layout::Variants::Single { .. } => vec![],
2009-
layout::Variants::Multiple { .. } => {
1998+
Variants::Single { .. } => vec![],
1999+
Variants::Multiple { .. } => {
20102000
let tuple_mdf = TupleMemberDescriptionFactory {
20112001
ty: enum_type,
20122002
component_types: outer_field_tys,

0 commit comments

Comments
 (0)