Skip to content

Commit 1a88b49

Browse files
committed
Generify trivial traversables over the interner
1 parent c5e9447 commit 1a88b49

File tree

11 files changed

+31
-42
lines changed

11 files changed

+31
-42
lines changed

Cargo.lock

+2
Original file line numberDiff line numberDiff line change
@@ -3918,6 +3918,7 @@ dependencies = [
39183918
"rustc_serialize",
39193919
"rustc_span",
39203920
"rustc_target",
3921+
"rustc_type_ir",
39213922
"smallvec",
39223923
"tracing",
39233924
]
@@ -4572,6 +4573,7 @@ dependencies = [
45724573
"rustc_macros",
45734574
"rustc_serialize",
45744575
"rustc_span",
4576+
"rustc_type_ir",
45754577
"serde_json",
45764578
"tracing",
45774579
]

compiler/rustc_hir/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ rustc_macros = { path = "../rustc_macros" }
1515
rustc_serialize = { path = "../rustc_serialize" }
1616
rustc_span = { path = "../rustc_span" }
1717
rustc_target = { path = "../rustc_target" }
18+
rustc_type_ir = { path = "../rustc_type_ir" }
1819
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
1920
tracing = "0.1"
2021
# tidy-alphabetical-end

compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3256,7 +3256,7 @@ impl<'hir> Item<'hir> {
32563256
}
32573257

32583258
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
3259-
#[derive(Encodable, Decodable, HashStable_Generic)]
3259+
#[derive(Encodable, Decodable, HashStable_Generic, TypeFoldable, TypeVisitable)]
32603260
pub enum Unsafety {
32613261
Unsafe,
32623262
Normal,

compiler/rustc_middle/src/macros.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,28 @@ macro_rules! TrivialLiftImpls {
5959
/// allocated data** (i.e., don't need to be folded).
6060
#[macro_export]
6161
macro_rules! TrivialTypeTraversalImpls {
62-
($($ty:ty),+ $(,)?) => {
62+
($(for { $($generic:tt)+ } { $interner:ty } { $ty:ty })+) => {
6363
$(
64-
impl<'tcx> $crate::ty::fold::TypeFoldable<$crate::ty::TyCtxt<'tcx>> for $ty {
65-
fn try_fold_with<F: $crate::ty::fold::FallibleTypeFolder<$crate::ty::TyCtxt<'tcx>>>(
64+
impl<$($generic)+> $crate::ty::fold::TypeFoldable<$interner> for $ty {
65+
fn try_fold_with<F: $crate::ty::fold::FallibleTypeFolder<$interner>>(
6666
self,
6767
_: &mut F,
6868
) -> ::std::result::Result<Self, F::Error> {
6969
Ok(self)
7070
}
7171

7272
#[inline]
73-
fn fold_with<F: $crate::ty::fold::TypeFolder<$crate::ty::TyCtxt<'tcx>>>(
73+
fn fold_with<F: $crate::ty::fold::TypeFolder<$interner>>(
7474
self,
7575
_: &mut F,
7676
) -> Self {
7777
self
7878
}
7979
}
8080

81-
impl<'tcx> $crate::ty::visit::TypeVisitable<$crate::ty::TyCtxt<'tcx>> for $ty {
81+
impl<$($generic)+> $crate::ty::visit::TypeVisitable<$interner> for $ty {
8282
#[inline]
83-
fn visit_with<F: $crate::ty::visit::TypeVisitor<$crate::ty::TyCtxt<'tcx>>>(
83+
fn visit_with<F: $crate::ty::visit::TypeVisitor<$interner>>(
8484
&self,
8585
_: &mut F)
8686
-> ::std::ops::ControlFlow<F::BreakTy>
@@ -90,12 +90,16 @@ macro_rules! TrivialTypeTraversalImpls {
9090
}
9191
)+
9292
};
93-
}
9493

95-
#[macro_export]
96-
macro_rules! TrivialTypeTraversalAndLiftImpls {
97-
($($t:tt)*) => {
98-
TrivialTypeTraversalImpls! { $($t)* }
99-
TrivialLiftImpls! { $($t)* }
100-
}
94+
(for <$tcx:lifetime> { $($ty:ty),+ $(,)? }) => {
95+
TrivialTypeTraversalImpls! {
96+
$(for { $tcx } { $crate::ty::TyCtxt<$tcx> } { $ty })+
97+
}
98+
};
99+
100+
($($ty:ty),+ $(,)?) => {
101+
TrivialTypeTraversalImpls! {
102+
$(for { I: $crate::ty::Interner } { I } { $ty })+
103+
}
104+
};
101105
}

compiler/rustc_middle/src/ty/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub type MinCaptureList<'tcx> = Vec<CapturedPlace<'tcx>>;
7777
/// You can get the environment type of a closure using
7878
/// `tcx.closure_env_ty()`.
7979
#[derive(Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)]
80-
#[derive(HashStable)]
80+
#[derive(HashStable, TypeFoldable, TypeVisitable)]
8181
pub enum ClosureKind {
8282
// Warning: Ordering is significant here! The ordering is chosen
8383
// because the trait Fn is a subtrait of FnMut and so in turn, and

compiler/rustc_middle/src/ty/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ pub enum Visibility<Id = LocalDefId> {
305305
}
306306

307307
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)]
308+
#[derive(TypeFoldable, TypeVisitable)]
308309
pub enum BoundConstness {
309310
/// `T: Trait`
310311
NotConst,

compiler/rustc_middle/src/ty/structural_impls.rs

+4-24
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::ty::{
1212
};
1313
use rustc_hir::def::Namespace;
1414
use rustc_span::source_map::Spanned;
15-
use rustc_target::abi::TyAndLayout;
1615
use rustc_type_ir::{ConstKind, DebugWithInfcx, InferCtxtLike, WithInfcx};
1716

1817
use std::fmt::{self, Debug};
@@ -409,31 +408,18 @@ TrivialLiftImpls! {
409408
bool,
410409
usize,
411410
u64,
411+
::rustc_hir::def_id::DefId,
412412
::rustc_hir::Mutability,
413+
::rustc_hir::Unsafety,
414+
::rustc_target::spec::abi::Abi,
415+
crate::ty::ClosureKind,
413416
crate::ty::ParamConst,
414417
crate::ty::ParamTy,
415418
interpret::Scalar,
416419
interpret::AllocId,
417420
rustc_target::abi::Size,
418421
}
419422

420-
// For some things about which the type library does not know, or does not
421-
// provide any traversal implementations, we need to provide a traversal
422-
// implementation (only for TyCtxt<'_> interners).
423-
TrivialTypeTraversalImpls! {
424-
crate::ty::BoundConstness,
425-
}
426-
// For some things about which the type library does not know, or does not
427-
// provide any traversal implementations, we need to provide a traversal
428-
// implementation and a lift implementation (the former only for TyCtxt<'_>
429-
// interners).
430-
TrivialTypeTraversalAndLiftImpls! {
431-
::rustc_hir::def_id::DefId,
432-
::rustc_hir::Unsafety,
433-
::rustc_target::spec::abi::Abi,
434-
crate::ty::ClosureKind,
435-
}
436-
437423
///////////////////////////////////////////////////////////////////////////
438424
// Lift implementations
439425

@@ -807,9 +793,3 @@ impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for ty::UnevaluatedConst<'tcx> {
807793
self.args.visit_with(visitor)
808794
}
809795
}
810-
811-
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for TyAndLayout<'tcx, Ty<'tcx>> {
812-
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
813-
visitor.visit_ty(self.ty)
814-
}
815-
}

compiler/rustc_span/src/def_id.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl<D: Decoder> Decodable<D> for DefIndex {
238238
/// index and a def index.
239239
///
240240
/// You can create a `DefId` from a `LocalDefId` using `local_def_id.to_def_id()`.
241-
#[derive(Clone, PartialEq, Eq, Copy)]
241+
#[derive(Clone, PartialEq, Eq, Copy, TypeFoldable, TypeVisitable)]
242242
// Don't derive order on 64-bit big-endian, so we can be consistent regardless of field order.
243243
#[cfg_attr(not(all(target_pointer_width = "64", target_endian = "big")), derive(PartialOrd, Ord))]
244244
// On below-64 bit systems we can simply use the derived `Hash` impl

compiler/rustc_target/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ rustc_index = { path = "../rustc_index" }
1414
rustc_macros = { path = "../rustc_macros" }
1515
rustc_serialize = { path = "../rustc_serialize" }
1616
rustc_span = { path = "../rustc_span" }
17+
rustc_type_ir = { path = "../rustc_type_ir" }
1718
serde_json = "1.0.59"
1819
tracing = "0.1"
1920
# tidy-alphabetical-end

compiler/rustc_target/src/abi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<'a> Layout<'a> {
131131
/// to that obtained from `layout_of(ty)`, as we need to produce
132132
/// layouts for which Rust types do not exist, such as enum variants
133133
/// or synthetic fields of enums (i.e., discriminants) and fat pointers.
134-
#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable_Generic)]
134+
#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable_Generic, TypeVisitable)]
135135
pub struct TyAndLayout<'a, Ty> {
136136
pub ty: Ty,
137137
pub layout: Layout<'a>,

compiler/rustc_target/src/spec/abi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::{Span, Symbol};
88
mod tests;
99

1010
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Debug)]
11-
#[derive(HashStable_Generic, Encodable, Decodable)]
11+
#[derive(HashStable_Generic, Encodable, Decodable, TypeFoldable, TypeVisitable)]
1212
pub enum Abi {
1313
// Some of the ABIs come first because every time we add a new ABI, we have to re-bless all the
1414
// hashing tests. These are used in many places, so giving them stable values reduces test

0 commit comments

Comments
 (0)