Rollup merge of #101549 - eholk:type-ir-derive-hashstable_generic, r=jackh726
Use HashStable_Generic in rustc_type_ir A lot of the types in this crate implemented HashStable directly to avoid circular dependencies. One way around that is to use HashStable_Generic. We adopt that here to avoid a lot of boilerplate. This doesn't update all the types, because some would require `I: Interner + HashStable`. r? `@cjgillot`
This commit is contained in:
commit
7f46d7313c
5 changed files with 16 additions and 43 deletions
|
@ -3958,6 +3958,7 @@ dependencies = [
|
||||||
"rustc_session",
|
"rustc_session",
|
||||||
"rustc_span",
|
"rustc_span",
|
||||||
"rustc_target",
|
"rustc_target",
|
||||||
|
"rustc_type_ir",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"thin-vec",
|
"thin-vec",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
|
|
@ -21,6 +21,7 @@ rustc_serialize = { path = "../rustc_serialize" }
|
||||||
rustc_session = { path = "../rustc_session" }
|
rustc_session = { path = "../rustc_session" }
|
||||||
rustc_span = { path = "../rustc_span" }
|
rustc_span = { path = "../rustc_span" }
|
||||||
rustc_target = { path = "../rustc_target" }
|
rustc_target = { path = "../rustc_target" }
|
||||||
|
rustc_type_ir = { path = "../rustc_type_ir" }
|
||||||
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
||||||
thin-vec = "0.2.8"
|
thin-vec = "0.2.8"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
|
|
|
@ -148,3 +148,5 @@ impl<'tcx> HashStable<StableHashingContext<'tcx>> for rustc_feature::Features {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'ctx> rustc_type_ir::HashStableContext for StableHashingContext<'ctx> {}
|
||||||
|
|
|
@ -23,6 +23,9 @@ pub mod sty;
|
||||||
pub use codec::*;
|
pub use codec::*;
|
||||||
pub use sty::*;
|
pub use sty::*;
|
||||||
|
|
||||||
|
/// Needed so we can use #[derive(HashStable_Generic)]
|
||||||
|
pub trait HashStableContext {}
|
||||||
|
|
||||||
pub trait Interner {
|
pub trait Interner {
|
||||||
type AdtDef: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
|
type AdtDef: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
|
||||||
type SubstsRef: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
|
type SubstsRef: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
|
||||||
|
@ -295,6 +298,7 @@ rustc_index::newtype_index! {
|
||||||
/// is the outer fn.
|
/// is the outer fn.
|
||||||
///
|
///
|
||||||
/// [dbi]: https://en.wikipedia.org/wiki/De_Bruijn_index
|
/// [dbi]: https://en.wikipedia.org/wiki/De_Bruijn_index
|
||||||
|
#[derive(HashStable_Generic)]
|
||||||
pub struct DebruijnIndex {
|
pub struct DebruijnIndex {
|
||||||
DEBUG_FORMAT = "DebruijnIndex({})",
|
DEBUG_FORMAT = "DebruijnIndex({})",
|
||||||
const INNERMOST = 0,
|
const INNERMOST = 0,
|
||||||
|
@ -366,7 +370,7 @@ impl DebruijnIndex {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||||
#[derive(Encodable, Decodable)]
|
#[derive(Encodable, Decodable, HashStable_Generic)]
|
||||||
pub enum IntTy {
|
pub enum IntTy {
|
||||||
Isize,
|
Isize,
|
||||||
I8,
|
I8,
|
||||||
|
@ -413,7 +417,7 @@ impl IntTy {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, Debug)]
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, Debug)]
|
||||||
#[derive(Encodable, Decodable)]
|
#[derive(Encodable, Decodable, HashStable_Generic)]
|
||||||
pub enum UintTy {
|
pub enum UintTy {
|
||||||
Usize,
|
Usize,
|
||||||
U8,
|
U8,
|
||||||
|
@ -460,7 +464,7 @@ impl UintTy {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||||
#[derive(Encodable, Decodable)]
|
#[derive(Encodable, Decodable, HashStable_Generic)]
|
||||||
pub enum FloatTy {
|
pub enum FloatTy {
|
||||||
F32,
|
F32,
|
||||||
F64,
|
F64,
|
||||||
|
@ -597,7 +601,7 @@ impl UnifyKey for FloatVid {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Decodable, Encodable, Hash)]
|
#[derive(Copy, Clone, PartialEq, Decodable, Encodable, Hash, HashStable_Generic)]
|
||||||
#[rustc_pass_by_value]
|
#[rustc_pass_by_value]
|
||||||
pub enum Variance {
|
pub enum Variance {
|
||||||
Covariant, // T<A> <: T<B> iff A <: B -- e.g., function return type
|
Covariant, // T<A> <: T<B> iff A <: B -- e.g., function return type
|
||||||
|
@ -666,30 +670,6 @@ impl Variance {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<CTX> HashStable<CTX> for DebruijnIndex {
|
|
||||||
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
|
||||||
self.as_u32().hash_stable(ctx, hasher);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<CTX> HashStable<CTX> for IntTy {
|
|
||||||
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
|
||||||
discriminant(self).hash_stable(ctx, hasher);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<CTX> HashStable<CTX> for UintTy {
|
|
||||||
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
|
||||||
discriminant(self).hash_stable(ctx, hasher);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<CTX> HashStable<CTX> for FloatTy {
|
|
||||||
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
|
||||||
discriminant(self).hash_stable(ctx, hasher);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<CTX> HashStable<CTX> for InferTy {
|
impl<CTX> HashStable<CTX> for InferTy {
|
||||||
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
||||||
use InferTy::*;
|
use InferTy::*;
|
||||||
|
@ -703,12 +683,6 @@ impl<CTX> HashStable<CTX> for InferTy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<CTX> HashStable<CTX> for Variance {
|
|
||||||
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
|
||||||
discriminant(self).hash_stable(ctx, hasher);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for IntVarValue {
|
impl fmt::Debug for IntVarValue {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -811,6 +785,7 @@ rustc_index::newtype_index! {
|
||||||
/// declared, but a type name in a non-zero universe is a placeholder
|
/// declared, but a type name in a non-zero universe is a placeholder
|
||||||
/// type -- an idealized representative of "types in general" that we
|
/// type -- an idealized representative of "types in general" that we
|
||||||
/// use for checking generic functions.
|
/// use for checking generic functions.
|
||||||
|
#[derive(HashStable_Generic)]
|
||||||
pub struct UniverseIndex {
|
pub struct UniverseIndex {
|
||||||
DEBUG_FORMAT = "U{}",
|
DEBUG_FORMAT = "U{}",
|
||||||
}
|
}
|
||||||
|
@ -850,9 +825,3 @@ impl UniverseIndex {
|
||||||
self.private < other.private
|
self.private < other.private
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<CTX> HashStable<CTX> for UniverseIndex {
|
|
||||||
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
|
||||||
self.private.hash_stable(ctx, hasher);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
use std::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
|
use std::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
|
||||||
use std::{fmt, hash};
|
use std::{fmt, hash};
|
||||||
|
|
||||||
use crate::DebruijnIndex;
|
|
||||||
use crate::FloatTy;
|
use crate::FloatTy;
|
||||||
use crate::IntTy;
|
use crate::IntTy;
|
||||||
use crate::Interner;
|
use crate::Interner;
|
||||||
|
@ -11,6 +10,7 @@ use crate::TyDecoder;
|
||||||
use crate::TyEncoder;
|
use crate::TyEncoder;
|
||||||
use crate::UintTy;
|
use crate::UintTy;
|
||||||
use crate::UniverseIndex;
|
use crate::UniverseIndex;
|
||||||
|
use crate::{DebruijnIndex, HashStableContext};
|
||||||
|
|
||||||
use self::RegionKind::*;
|
use self::RegionKind::*;
|
||||||
use self::TyKind::*;
|
use self::TyKind::*;
|
||||||
|
@ -774,7 +774,7 @@ where
|
||||||
|
|
||||||
// This is not a derived impl because a derive would require `I: HashStable`
|
// This is not a derived impl because a derive would require `I: HashStable`
|
||||||
#[allow(rustc::usage_of_ty_tykind)]
|
#[allow(rustc::usage_of_ty_tykind)]
|
||||||
impl<CTX, I: Interner> HashStable<CTX> for TyKind<I>
|
impl<CTX: HashStableContext, I: Interner> HashStable<CTX> for TyKind<I>
|
||||||
where
|
where
|
||||||
I::AdtDef: HashStable<CTX>,
|
I::AdtDef: HashStable<CTX>,
|
||||||
I::DefId: HashStable<CTX>,
|
I::DefId: HashStable<CTX>,
|
||||||
|
@ -1286,7 +1286,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is not a derived impl because a derive would require `I: HashStable`
|
// This is not a derived impl because a derive would require `I: HashStable`
|
||||||
impl<CTX, I: Interner> HashStable<CTX> for RegionKind<I>
|
impl<CTX: HashStableContext, I: Interner> HashStable<CTX> for RegionKind<I>
|
||||||
where
|
where
|
||||||
I::EarlyBoundRegion: HashStable<CTX>,
|
I::EarlyBoundRegion: HashStable<CTX>,
|
||||||
I::BoundRegion: HashStable<CTX>,
|
I::BoundRegion: HashStable<CTX>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue