From 918ede64740b3610dfd8b43ff0d995261a236ac5 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 26 Nov 2022 20:43:31 +0000 Subject: [PATCH] make Opaque have one field: OpaqueTy --- compiler/rustc_middle/src/ty/mod.rs | 2 +- compiler/rustc_middle/src/ty/sty.rs | 10 +++++++++ compiler/rustc_type_ir/src/lib.rs | 1 + compiler/rustc_type_ir/src/sty.rs | 32 ++++++++++++++--------------- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index e480414a3589..efc45b5646e2 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -97,7 +97,7 @@ pub use self::sty::{ BoundVariableKind, CanonicalPolyFnSig, ClosureSubsts, ClosureSubstsParts, ConstVid, EarlyBoundRegion, ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FnSig, FreeRegion, GenSig, GeneratorSubsts, GeneratorSubstsParts, InlineConstSubsts, - InlineConstSubstsParts, ParamConst, ParamTy, PolyExistentialPredicate, + InlineConstSubstsParts, OpaqueTy, ParamConst, ParamTy, PolyExistentialPredicate, PolyExistentialProjection, PolyExistentialTraitRef, PolyFnSig, PolyGenSig, PolyTraitRef, ProjectionTy, Region, RegionKind, RegionVid, TraitRef, TyKind, TypeAndMut, UpvarSubsts, VarianceDiagInfo, diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 9b9c26d6a8b1..4c75614a5bc6 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1199,6 +1199,16 @@ impl<'tcx> ProjectionTy<'tcx> { } } +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] +#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] +pub struct OpaqueTy<'tcx> { + /// The parameters of the opaque. + pub substs: SubstsRef<'tcx>, + + /// The `DefId` of the `impl Trait`. + pub def_id: DefId, +} + #[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable, Lift)] pub struct GenSig<'tcx> { pub resume_ty: Ty<'tcx>, diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index e3f7a1bd033c..983fc9d992ad 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -44,6 +44,7 @@ pub trait Interner { type ListTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type ProjectionTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type ParamTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; + type OpaqueTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type BoundTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type PlaceholderType: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type InferTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; diff --git a/compiler/rustc_type_ir/src/sty.rs b/compiler/rustc_type_ir/src/sty.rs index 9aa2be124e29..5119733d84cd 100644 --- a/compiler/rustc_type_ir/src/sty.rs +++ b/compiler/rustc_type_ir/src/sty.rs @@ -184,7 +184,7 @@ pub enum TyKind { /// while for TAIT it is used for the generic parameters of the alias. /// /// During codegen, `tcx.type_of(def_id)` can be used to get the underlying type. - Opaque(I::DefId, I::SubstsRef), + Opaque(I::OpaqueTy), /// A type parameter; for example, `T` in `fn f(x: T) {}`. Param(I::ParamTy), @@ -253,7 +253,7 @@ const fn tykind_discriminant(value: &TyKind) -> usize { Never => 18, Tuple(_) => 19, Projection(_) => 20, - Opaque(_, _) => 21, + Opaque(_) => 21, Param(_) => 22, Bound(_, _) => 23, Placeholder(_) => 24, @@ -287,7 +287,7 @@ impl Clone for TyKind { Never => Never, Tuple(t) => Tuple(t.clone()), Projection(p) => Projection(p.clone()), - Opaque(d, s) => Opaque(d.clone(), s.clone()), + Opaque(o) => Opaque(o.clone()), Param(p) => Param(p.clone()), Bound(d, b) => Bound(d.clone(), b.clone()), Placeholder(p) => Placeholder(p.clone()), @@ -324,7 +324,7 @@ impl PartialEq for TyKind { (GeneratorWitness(a_g), GeneratorWitness(b_g)) => a_g == b_g, (Tuple(a_t), Tuple(b_t)) => a_t == b_t, (Projection(a_p), Projection(b_p)) => a_p == b_p, - (Opaque(a_d, a_s), Opaque(b_d, b_s)) => a_d == b_d && a_s == b_s, + (Opaque(a_o), Opaque(b_o)) => a_o == b_o, (Param(a_p), Param(b_p)) => a_p == b_p, (Bound(a_d, a_b), Bound(b_d, b_b)) => a_d == b_d && a_b == b_b, (Placeholder(a_p), Placeholder(b_p)) => a_p == b_p, @@ -382,7 +382,7 @@ impl Ord for TyKind { (GeneratorWitness(a_g), GeneratorWitness(b_g)) => a_g.cmp(b_g), (Tuple(a_t), Tuple(b_t)) => a_t.cmp(b_t), (Projection(a_p), Projection(b_p)) => a_p.cmp(b_p), - (Opaque(a_d, a_s), Opaque(b_d, b_s)) => a_d.cmp(b_d).then_with(|| a_s.cmp(b_s)), + (Opaque(a_o), Opaque(b_o)) => a_o.cmp(b_o), (Param(a_p), Param(b_p)) => a_p.cmp(b_p), (Bound(a_d, a_b), Bound(b_d, b_b)) => a_d.cmp(b_d).then_with(|| a_b.cmp(b_b)), (Placeholder(a_p), Placeholder(b_p)) => a_p.cmp(b_p), @@ -444,9 +444,8 @@ impl hash::Hash for TyKind { GeneratorWitness(g) => g.hash(state), Tuple(t) => t.hash(state), Projection(p) => p.hash(state), - Opaque(d, s) => { - d.hash(state); - s.hash(state) + Opaque(o) => { + o.hash(state); } Param(p) => p.hash(state), Bound(d, b) => { @@ -486,7 +485,7 @@ impl fmt::Debug for TyKind { Never => f.write_str("Never"), Tuple(t) => f.debug_tuple_field1_finish("Tuple", t), Projection(p) => f.debug_tuple_field1_finish("Projection", p), - Opaque(d, s) => f.debug_tuple_field2_finish("Opaque", d, s), + Opaque(o) => f.debug_tuple_field1_finish("Opaque", o), Param(p) => f.debug_tuple_field1_finish("Param", p), Bound(d, b) => f.debug_tuple_field2_finish("Bound", d, b), Placeholder(p) => f.debug_tuple_field1_finish("Placeholder", p), @@ -515,6 +514,7 @@ where I::ListTy: Encodable, I::ProjectionTy: Encodable, I::ParamTy: Encodable, + I::OpaqueTy: Encodable, I::BoundTy: Encodable, I::PlaceholderType: Encodable, I::InferTy: Encodable, @@ -589,9 +589,8 @@ where Projection(p) => e.emit_enum_variant(disc, |e| { p.encode(e); }), - Opaque(def_id, substs) => e.emit_enum_variant(disc, |e| { - def_id.encode(e); - substs.encode(e); + Opaque(o) => e.emit_enum_variant(disc, |e| { + o.encode(e); }), Param(p) => e.emit_enum_variant(disc, |e| { p.encode(e); @@ -632,6 +631,7 @@ where I::ListTy: Decodable, I::ProjectionTy: Decodable, I::ParamTy: Decodable, + I::OpaqueTy: Decodable, I::BoundTy: Decodable, I::PlaceholderType: Decodable, I::InferTy: Decodable, @@ -661,7 +661,7 @@ where 18 => Never, 19 => Tuple(Decodable::decode(d)), 20 => Projection(Decodable::decode(d)), - 21 => Opaque(Decodable::decode(d), Decodable::decode(d)), + 21 => Opaque(Decodable::decode(d)), 22 => Param(Decodable::decode(d)), 23 => Bound(Decodable::decode(d), Decodable::decode(d)), 24 => Placeholder(Decodable::decode(d)), @@ -698,6 +698,7 @@ where I::ProjectionTy: HashStable, I::BoundTy: HashStable, I::ParamTy: HashStable, + I::OpaqueTy: HashStable, I::PlaceholderType: HashStable, I::InferTy: HashStable, I::ErrorGuaranteed: HashStable, @@ -775,9 +776,8 @@ where Projection(p) => { p.hash_stable(__hcx, __hasher); } - Opaque(def_id, substs) => { - def_id.hash_stable(__hcx, __hasher); - substs.hash_stable(__hcx, __hasher); + Opaque(o) => { + o.hash_stable(__hcx, __hasher); } Param(p) => { p.hash_stable(__hcx, __hasher);