Skip to content

Commit aa95b96

Browse files
committed
Auto merge of rust-lang#138464 - compiler-errors:less-type-ir, r=lcnr
Use `rustc_type_ir` directly less in the codebase cc rust-lang#138449 This is a somewhat opinionated bundle of changes that will make working on rust-lang#138449 more easy, since it cuts out the bulk of the changes that would be necessitated by the lint. Namely: 1. Fold `rustc_middle::ty::fold` and `rustc_middle::ty::visit` into `rustc_middle::ty`. This is because we already reexport some parts of these modules into `rustc_middle::ty`, and there's really no benefit from namespacing away the rest of these modules's functionality given how important folding and visiting is to the type layer. 2. Rename `{Decodable,Encodable}_Generic` to `{Decodable,Encodable}_NoContext`[^why], change it to be "perfect derive" (`synstructure::AddBounds::Fields`), use it throughout `rustc_type_ir` instead of `TyEncodable`/`TyDecodable`. 3. Make `TyEncodable` and `TyDecodable` derives use `::rustc_middle::ty::codec::TyEncoder` (etc) for its generated paths, and move the `rustc_type_ir::codec` module back to `rustc_middle::ty::codec` :tada:. 4. Stop using `rustc_type_ir` in crates that aren't "fundamental" to the type system, namely middle/infer/trait-selection. This amounted mostly to changing imports from `use rustc_type_ir::...` to `use rustc_middle::ty::...`, but also this means that we can't glob import `TyKind::*` since the reexport into `rustc_middle::ty::TyKind` is a type alias. Instead, use the prefixed variants like `ty::Str` everywhere -- IMO this is a good change, since it makes it more regularized with most of the rest of the compiler. [^why]: `_NoContext` is the name for derive macros with no additional generic bounds and which do "perfect derive" by generating bounds based on field types. See `HashStable_NoContext`. I'm happy to cut out some of these changes into separate PRs to make landing it a bit easier, though I don't expect to have much trouble with bitrot. r? lcnr
2 parents adea7cb + b88f85a commit aa95b96

File tree

160 files changed

+748
-695
lines changed

Some content is hidden

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

160 files changed

+748
-695
lines changed

Cargo.lock

-8
Original file line numberDiff line numberDiff line change
@@ -3440,7 +3440,6 @@ dependencies = [
34403440
"rustc_symbol_mangling",
34413441
"rustc_target",
34423442
"rustc_trait_selection",
3443-
"rustc_type_ir",
34443443
"serde_json",
34453444
"smallvec",
34463445
"tempfile",
@@ -3473,7 +3472,6 @@ dependencies = [
34733472
"rustc_span",
34743473
"rustc_target",
34753474
"rustc_trait_selection",
3476-
"rustc_type_ir",
34773475
"tracing",
34783476
]
34793477

@@ -3736,7 +3734,6 @@ dependencies = [
37363734
"rustc_span",
37373735
"rustc_target",
37383736
"rustc_trait_selection",
3739-
"rustc_type_ir",
37403737
"smallvec",
37413738
"tracing",
37423739
]
@@ -3775,7 +3772,6 @@ dependencies = [
37753772
"rustc_session",
37763773
"rustc_span",
37773774
"rustc_trait_selection",
3778-
"rustc_type_ir",
37793775
"smallvec",
37803776
"tracing",
37813777
]
@@ -3922,7 +3918,6 @@ dependencies = [
39223918
"rustc_span",
39233919
"rustc_target",
39243920
"rustc_trait_selection",
3925-
"rustc_type_ir",
39263921
"smallvec",
39273922
"tracing",
39283923
"unicode-security",
@@ -3998,7 +3993,6 @@ dependencies = [
39983993
"rustc_session",
39993994
"rustc_span",
40003995
"rustc_target",
4001-
"rustc_type_ir",
40023996
"tempfile",
40033997
"tracing",
40043998
]
@@ -4114,7 +4108,6 @@ dependencies = [
41144108
"rustc_span",
41154109
"rustc_target",
41164110
"rustc_trait_selection",
4117-
"rustc_type_ir",
41184111
"smallvec",
41194112
"tracing",
41204113
]
@@ -4538,7 +4531,6 @@ dependencies = [
45384531
"rustc_span",
45394532
"rustc_target",
45404533
"rustc_trait_selection",
4541-
"rustc_type_ir",
45424534
"tracing",
45434535
]
45444536

compiler/rustc_abi/src/lib.rs

+25-7
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use rustc_data_structures::stable_hasher::StableOrd;
5252
use rustc_hashes::Hash64;
5353
use rustc_index::{Idx, IndexSlice, IndexVec};
5454
#[cfg(feature = "nightly")]
55-
use rustc_macros::{Decodable_Generic, Encodable_Generic, HashStable_Generic};
55+
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_Generic};
5656

5757
mod callconv;
5858
mod layout;
@@ -74,7 +74,10 @@ pub use layout::{LayoutCalculator, LayoutCalculatorError};
7474
pub trait HashStableContext {}
7575

7676
#[derive(Clone, Copy, PartialEq, Eq, Default)]
77-
#[cfg_attr(feature = "nightly", derive(Encodable_Generic, Decodable_Generic, HashStable_Generic))]
77+
#[cfg_attr(
78+
feature = "nightly",
79+
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
80+
)]
7881
pub struct ReprFlags(u8);
7982

8083
bitflags! {
@@ -106,7 +109,10 @@ impl std::fmt::Debug for ReprFlags {
106109
}
107110

108111
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
109-
#[cfg_attr(feature = "nightly", derive(Encodable_Generic, Decodable_Generic, HashStable_Generic))]
112+
#[cfg_attr(
113+
feature = "nightly",
114+
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
115+
)]
110116
pub enum IntegerType {
111117
/// Pointer-sized integer type, i.e. `isize` and `usize`. The field shows signedness, e.g.
112118
/// `Pointer(true)` means `isize`.
@@ -127,7 +133,10 @@ impl IntegerType {
127133

128134
/// Represents the repr options provided by the user.
129135
#[derive(Copy, Clone, Debug, Eq, PartialEq, Default)]
130-
#[cfg_attr(feature = "nightly", derive(Encodable_Generic, Decodable_Generic, HashStable_Generic))]
136+
#[cfg_attr(
137+
feature = "nightly",
138+
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
139+
)]
131140
pub struct ReprOptions {
132141
pub int: Option<IntegerType>,
133142
pub align: Option<Align>,
@@ -487,7 +496,10 @@ impl FromStr for Endian {
487496

488497
/// Size of a type in bytes.
489498
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
490-
#[cfg_attr(feature = "nightly", derive(Encodable_Generic, Decodable_Generic, HashStable_Generic))]
499+
#[cfg_attr(
500+
feature = "nightly",
501+
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
502+
)]
491503
pub struct Size {
492504
raw: u64,
493505
}
@@ -713,7 +725,10 @@ impl Step for Size {
713725

714726
/// Alignment of a type in bytes (always a power of two).
715727
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
716-
#[cfg_attr(feature = "nightly", derive(Encodable_Generic, Decodable_Generic, HashStable_Generic))]
728+
#[cfg_attr(
729+
feature = "nightly",
730+
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
731+
)]
717732
pub struct Align {
718733
pow2: u8,
719734
}
@@ -872,7 +887,10 @@ impl AbiAndPrefAlign {
872887

873888
/// Integers, also used for enum discriminants.
874889
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
875-
#[cfg_attr(feature = "nightly", derive(Encodable_Generic, Decodable_Generic, HashStable_Generic))]
890+
#[cfg_attr(
891+
feature = "nightly",
892+
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
893+
)]
876894
pub enum Integer {
877895
I8,
878896
I16,

compiler/rustc_ast_ir/src/lib.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
// tidy-alphabetical-end
1313

1414
#[cfg(feature = "nightly")]
15-
use rustc_macros::{Decodable, Encodable, HashStable_NoContext};
15+
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
1616

1717
pub mod visit;
1818

1919
/// The movability of a coroutine / closure literal:
2020
/// whether a coroutine contains self-references, causing it to be `!Unpin`.
2121
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
22-
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
22+
#[cfg_attr(
23+
feature = "nightly",
24+
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
25+
)]
2326
pub enum Movability {
2427
/// May contain self-references, `!Unpin`.
2528
Static,
@@ -28,7 +31,10 @@ pub enum Movability {
2831
}
2932

3033
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
31-
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
34+
#[cfg_attr(
35+
feature = "nightly",
36+
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
37+
)]
3238
pub enum Mutability {
3339
// N.B. Order is deliberate, so that Not < Mut
3440
Not,
@@ -87,7 +93,10 @@ impl Mutability {
8793
}
8894

8995
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
90-
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
96+
#[cfg_attr(
97+
feature = "nightly",
98+
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
99+
)]
91100
pub enum Pinnedness {
92101
Not,
93102
Pinned,

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ use rustc_infer::infer::{NllRegionVariableOrigin, RelateParamBound};
1414
use rustc_middle::bug;
1515
use rustc_middle::hir::place::PlaceBase;
1616
use rustc_middle::mir::{AnnotationSource, ConstraintCategory, ReturnConstraint};
17-
use rustc_middle::ty::fold::fold_regions;
1817
use rustc_middle::ty::{
19-
self, GenericArgs, Region, RegionVid, Ty, TyCtxt, TypeFoldable, TypeVisitor,
18+
self, GenericArgs, Region, RegionVid, Ty, TyCtxt, TypeFoldable, TypeVisitor, fold_regions,
2019
};
2120
use rustc_span::{Ident, Span, kw};
2221
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;

compiler/rustc_borrowck/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ use rustc_infer::infer::{
3535
};
3636
use rustc_middle::mir::*;
3737
use rustc_middle::query::Providers;
38-
use rustc_middle::ty::fold::fold_regions;
39-
use rustc_middle::ty::{self, ParamEnv, RegionVid, TyCtxt, TypingMode};
38+
use rustc_middle::ty::{self, ParamEnv, RegionVid, TyCtxt, TypingMode, fold_regions};
4039
use rustc_middle::{bug, span_bug};
4140
use rustc_mir_dataflow::impls::{
4241
EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces,

compiler/rustc_borrowck/src/region_infer/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ use rustc_middle::mir::{
1818
ReturnConstraint, TerminatorKind,
1919
};
2020
use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
21-
use rustc_middle::ty::fold::fold_regions;
22-
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable, UniverseIndex};
21+
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable, UniverseIndex, fold_regions};
2322
use rustc_mir_dataflow::points::DenseLocationMap;
2423
use rustc_span::hygiene::DesugaringKind;
2524
use rustc_span::{DUMMY_SP, Span};

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ use rustc_hir::def_id::LocalDefId;
55
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
66
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, TyCtxtInferExt as _};
77
use rustc_macros::extension;
8-
use rustc_middle::ty::fold::fold_regions;
9-
use rustc_middle::ty::visit::TypeVisitableExt;
108
use rustc_middle::ty::{
119
self, GenericArgKind, GenericArgs, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable,
12-
TypingMode,
10+
TypeVisitableExt, TypingMode, fold_regions,
1311
};
1412
use rustc_span::Span;
1513
use rustc_trait_selection::regions::OutlivesEnvironmentBuildExt;

compiler/rustc_borrowck/src/renumber.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use rustc_index::IndexSlice;
22
use rustc_infer::infer::NllRegionVariableOrigin;
33
use rustc_middle::mir::visit::{MutVisitor, TyContext};
44
use rustc_middle::mir::{Body, ConstOperand, Location, Promoted};
5-
use rustc_middle::ty::fold::fold_regions;
6-
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeFoldable};
5+
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeFoldable, fold_regions};
76
use rustc_span::Symbol;
87
use tracing::{debug, instrument};
98

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ use rustc_infer::infer::{self, InferCtxt, SubregionOrigin};
77
use rustc_infer::traits::query::type_op::DeeplyNormalize;
88
use rustc_middle::bug;
99
use rustc_middle::mir::{ClosureOutlivesSubject, ClosureRegionRequirements, ConstraintCategory};
10-
use rustc_middle::ty::fold::fold_regions;
11-
use rustc_middle::ty::{self, GenericArgKind, Ty, TyCtxt, TypeFoldable, TypeVisitableExt};
10+
use rustc_middle::ty::{
11+
self, GenericArgKind, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, fold_regions,
12+
};
1213
use rustc_span::Span;
1314
use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
1415
use tracing::{debug, instrument};

compiler/rustc_borrowck/src/type_check/liveness/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use rustc_middle::mir::visit::{TyContext, Visitor};
44
use rustc_middle::mir::{Body, Local, Location, SourceInfo};
55
use rustc_middle::span_bug;
66
use rustc_middle::ty::relate::Relate;
7-
use rustc_middle::ty::visit::TypeVisitable;
8-
use rustc_middle::ty::{GenericArgsRef, Region, RegionVid, Ty, TyCtxt};
7+
use rustc_middle::ty::{GenericArgsRef, Region, RegionVid, Ty, TyCtxt, TypeVisitable};
98
use rustc_mir_dataflow::ResultsCursor;
109
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
1110
use rustc_mir_dataflow::move_paths::MoveData;

compiler/rustc_borrowck/src/type_check/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ use rustc_middle::mir::*;
2424
use rustc_middle::traits::query::NoSolution;
2525
use rustc_middle::ty::adjustment::PointerCoercion;
2626
use rustc_middle::ty::cast::CastTy;
27-
use rustc_middle::ty::fold::fold_regions;
28-
use rustc_middle::ty::visit::TypeVisitableExt;
2927
use rustc_middle::ty::{
3028
self, Binder, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, CoroutineArgsExt,
31-
Dynamic, GenericArgsRef, OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, UserArgs,
32-
UserTypeAnnotationIndex,
29+
Dynamic, GenericArgsRef, OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt,
30+
TypeVisitableExt, UserArgs, UserTypeAnnotationIndex, fold_regions,
3331
};
3432
use rustc_middle::{bug, span_bug};
3533
use rustc_mir_dataflow::ResultsCursor;

compiler/rustc_borrowck/src/type_check/opaque_types.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ use std::iter;
22

33
use rustc_data_structures::fx::FxIndexMap;
44
use rustc_middle::span_bug;
5-
use rustc_middle::ty::fold::fold_regions;
65
use rustc_middle::ty::{
76
self, GenericArgKind, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeSuperVisitable,
8-
TypeVisitable, TypeVisitableExt, TypeVisitor,
7+
TypeVisitable, TypeVisitableExt, TypeVisitor, fold_regions,
98
};
109
use tracing::{debug, trace};
1110

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ use rustc_middle::mir::ConstraintCategory;
1010
use rustc_middle::span_bug;
1111
use rustc_middle::traits::ObligationCause;
1212
use rustc_middle::traits::query::NoSolution;
13-
use rustc_middle::ty::fold::FnMutDelegate;
1413
use rustc_middle::ty::relate::combine::{super_combine_consts, super_combine_tys};
15-
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
14+
use rustc_middle::ty::{self, FnMutDelegate, Ty, TyCtxt, TypeVisitableExt};
1615
use rustc_span::{Span, Symbol, sym};
1716
use tracing::{debug, instrument};
1817

compiler/rustc_borrowck/src/universal_regions.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ use rustc_hir::lang_items::LangItem;
2727
use rustc_index::IndexVec;
2828
use rustc_infer::infer::NllRegionVariableOrigin;
2929
use rustc_macros::extension;
30-
use rustc_middle::ty::fold::{TypeFoldable, fold_regions};
3130
use rustc_middle::ty::print::with_no_trimmed_paths;
3231
use rustc_middle::ty::{
3332
self, GenericArgs, GenericArgsRef, InlineConstArgs, InlineConstArgsParts, RegionVid, Ty,
34-
TyCtxt, TypeVisitableExt,
33+
TyCtxt, TypeFoldable, TypeVisitableExt, fold_regions,
3534
};
3635
use rustc_middle::{bug, span_bug};
3736
use rustc_span::{ErrorGuaranteed, kw, sym};

compiler/rustc_codegen_ssa/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ rustc_span = { path = "../rustc_span" }
4040
rustc_symbol_mangling = { path = "../rustc_symbol_mangling" }
4141
rustc_target = { path = "../rustc_target" }
4242
rustc_trait_selection = { path = "../rustc_trait_selection" }
43-
rustc_type_ir = { path = "../rustc_type_ir" }
4443
serde_json = "1.0.59"
4544
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
4645
tempfile = "3.2"

compiler/rustc_codegen_ssa/src/errors.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ use rustc_errors::{
1212
Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg, Level,
1313
};
1414
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
15-
use rustc_middle::ty::Ty;
1615
use rustc_middle::ty::layout::LayoutError;
16+
use rustc_middle::ty::{FloatTy, Ty};
1717
use rustc_span::{Span, Symbol};
18-
use rustc_type_ir::FloatTy;
1918

2019
use crate::assert_module_sources::CguReuse;
2120
use crate::back::command::Command;

compiler/rustc_codegen_ssa/src/mir/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
4343
mir::Const::Ty(_, c) => match c.kind() {
4444
// A constant that came from a const generic but was then used as an argument to
4545
// old-style simd_shuffle (passing as argument instead of as a generic param).
46-
rustc_type_ir::ConstKind::Value(cv) => return Ok(Ok(cv.valtree)),
46+
ty::ConstKind::Value(cv) => return Ok(Ok(cv.valtree)),
4747
other => span_bug!(constant.span, "{other:#?}"),
4848
},
4949
// We should never encounter `Const::Val` unless MIR opts (like const prop) evaluate

compiler/rustc_const_eval/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ rustc_session = { path = "../rustc_session" }
2323
rustc_span = { path = "../rustc_span" }
2424
rustc_target = { path = "../rustc_target" }
2525
rustc_trait_selection = { path = "../rustc_trait_selection" }
26-
rustc_type_ir = { path = "../rustc_type_ir" }
2726
tracing = "0.1"
2827
# tidy-alphabetical-end

0 commit comments

Comments
 (0)