Skip to content

Commit 918ede6

Browse files
make Opaque have one field: OpaqueTy
1 parent ed620cf commit 918ede6

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub use self::sty::{
9797
BoundVariableKind, CanonicalPolyFnSig, ClosureSubsts, ClosureSubstsParts, ConstVid,
9898
EarlyBoundRegion, ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FnSig,
9999
FreeRegion, GenSig, GeneratorSubsts, GeneratorSubstsParts, InlineConstSubsts,
100-
InlineConstSubstsParts, ParamConst, ParamTy, PolyExistentialPredicate,
100+
InlineConstSubstsParts, OpaqueTy, ParamConst, ParamTy, PolyExistentialPredicate,
101101
PolyExistentialProjection, PolyExistentialTraitRef, PolyFnSig, PolyGenSig, PolyTraitRef,
102102
ProjectionTy, Region, RegionKind, RegionVid, TraitRef, TyKind, TypeAndMut, UpvarSubsts,
103103
VarianceDiagInfo,

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,16 @@ impl<'tcx> ProjectionTy<'tcx> {
11991199
}
12001200
}
12011201

1202+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
1203+
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
1204+
pub struct OpaqueTy<'tcx> {
1205+
/// The parameters of the opaque.
1206+
pub substs: SubstsRef<'tcx>,
1207+
1208+
/// The `DefId` of the `impl Trait`.
1209+
pub def_id: DefId,
1210+
}
1211+
12021212
#[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable, Lift)]
12031213
pub struct GenSig<'tcx> {
12041214
pub resume_ty: Ty<'tcx>,

compiler/rustc_type_ir/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub trait Interner {
4444
type ListTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
4545
type ProjectionTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
4646
type ParamTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
47+
type OpaqueTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
4748
type BoundTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
4849
type PlaceholderType: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
4950
type InferTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;

compiler/rustc_type_ir/src/sty.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub enum TyKind<I: Interner> {
184184
/// while for TAIT it is used for the generic parameters of the alias.
185185
///
186186
/// During codegen, `tcx.type_of(def_id)` can be used to get the underlying type.
187-
Opaque(I::DefId, I::SubstsRef),
187+
Opaque(I::OpaqueTy),
188188

189189
/// A type parameter; for example, `T` in `fn f<T>(x: T) {}`.
190190
Param(I::ParamTy),
@@ -253,7 +253,7 @@ const fn tykind_discriminant<I: Interner>(value: &TyKind<I>) -> usize {
253253
Never => 18,
254254
Tuple(_) => 19,
255255
Projection(_) => 20,
256-
Opaque(_, _) => 21,
256+
Opaque(_) => 21,
257257
Param(_) => 22,
258258
Bound(_, _) => 23,
259259
Placeholder(_) => 24,
@@ -287,7 +287,7 @@ impl<I: Interner> Clone for TyKind<I> {
287287
Never => Never,
288288
Tuple(t) => Tuple(t.clone()),
289289
Projection(p) => Projection(p.clone()),
290-
Opaque(d, s) => Opaque(d.clone(), s.clone()),
290+
Opaque(o) => Opaque(o.clone()),
291291
Param(p) => Param(p.clone()),
292292
Bound(d, b) => Bound(d.clone(), b.clone()),
293293
Placeholder(p) => Placeholder(p.clone()),
@@ -324,7 +324,7 @@ impl<I: Interner> PartialEq for TyKind<I> {
324324
(GeneratorWitness(a_g), GeneratorWitness(b_g)) => a_g == b_g,
325325
(Tuple(a_t), Tuple(b_t)) => a_t == b_t,
326326
(Projection(a_p), Projection(b_p)) => a_p == b_p,
327-
(Opaque(a_d, a_s), Opaque(b_d, b_s)) => a_d == b_d && a_s == b_s,
327+
(Opaque(a_o), Opaque(b_o)) => a_o == b_o,
328328
(Param(a_p), Param(b_p)) => a_p == b_p,
329329
(Bound(a_d, a_b), Bound(b_d, b_b)) => a_d == b_d && a_b == b_b,
330330
(Placeholder(a_p), Placeholder(b_p)) => a_p == b_p,
@@ -382,7 +382,7 @@ impl<I: Interner> Ord for TyKind<I> {
382382
(GeneratorWitness(a_g), GeneratorWitness(b_g)) => a_g.cmp(b_g),
383383
(Tuple(a_t), Tuple(b_t)) => a_t.cmp(b_t),
384384
(Projection(a_p), Projection(b_p)) => a_p.cmp(b_p),
385-
(Opaque(a_d, a_s), Opaque(b_d, b_s)) => a_d.cmp(b_d).then_with(|| a_s.cmp(b_s)),
385+
(Opaque(a_o), Opaque(b_o)) => a_o.cmp(b_o),
386386
(Param(a_p), Param(b_p)) => a_p.cmp(b_p),
387387
(Bound(a_d, a_b), Bound(b_d, b_b)) => a_d.cmp(b_d).then_with(|| a_b.cmp(b_b)),
388388
(Placeholder(a_p), Placeholder(b_p)) => a_p.cmp(b_p),
@@ -444,9 +444,8 @@ impl<I: Interner> hash::Hash for TyKind<I> {
444444
GeneratorWitness(g) => g.hash(state),
445445
Tuple(t) => t.hash(state),
446446
Projection(p) => p.hash(state),
447-
Opaque(d, s) => {
448-
d.hash(state);
449-
s.hash(state)
447+
Opaque(o) => {
448+
o.hash(state);
450449
}
451450
Param(p) => p.hash(state),
452451
Bound(d, b) => {
@@ -486,7 +485,7 @@ impl<I: Interner> fmt::Debug for TyKind<I> {
486485
Never => f.write_str("Never"),
487486
Tuple(t) => f.debug_tuple_field1_finish("Tuple", t),
488487
Projection(p) => f.debug_tuple_field1_finish("Projection", p),
489-
Opaque(d, s) => f.debug_tuple_field2_finish("Opaque", d, s),
488+
Opaque(o) => f.debug_tuple_field1_finish("Opaque", o),
490489
Param(p) => f.debug_tuple_field1_finish("Param", p),
491490
Bound(d, b) => f.debug_tuple_field2_finish("Bound", d, b),
492491
Placeholder(p) => f.debug_tuple_field1_finish("Placeholder", p),
@@ -515,6 +514,7 @@ where
515514
I::ListTy: Encodable<E>,
516515
I::ProjectionTy: Encodable<E>,
517516
I::ParamTy: Encodable<E>,
517+
I::OpaqueTy: Encodable<E>,
518518
I::BoundTy: Encodable<E>,
519519
I::PlaceholderType: Encodable<E>,
520520
I::InferTy: Encodable<E>,
@@ -589,9 +589,8 @@ where
589589
Projection(p) => e.emit_enum_variant(disc, |e| {
590590
p.encode(e);
591591
}),
592-
Opaque(def_id, substs) => e.emit_enum_variant(disc, |e| {
593-
def_id.encode(e);
594-
substs.encode(e);
592+
Opaque(o) => e.emit_enum_variant(disc, |e| {
593+
o.encode(e);
595594
}),
596595
Param(p) => e.emit_enum_variant(disc, |e| {
597596
p.encode(e);
@@ -632,6 +631,7 @@ where
632631
I::ListTy: Decodable<D>,
633632
I::ProjectionTy: Decodable<D>,
634633
I::ParamTy: Decodable<D>,
634+
I::OpaqueTy: Decodable<D>,
635635
I::BoundTy: Decodable<D>,
636636
I::PlaceholderType: Decodable<D>,
637637
I::InferTy: Decodable<D>,
@@ -661,7 +661,7 @@ where
661661
18 => Never,
662662
19 => Tuple(Decodable::decode(d)),
663663
20 => Projection(Decodable::decode(d)),
664-
21 => Opaque(Decodable::decode(d), Decodable::decode(d)),
664+
21 => Opaque(Decodable::decode(d)),
665665
22 => Param(Decodable::decode(d)),
666666
23 => Bound(Decodable::decode(d), Decodable::decode(d)),
667667
24 => Placeholder(Decodable::decode(d)),
@@ -698,6 +698,7 @@ where
698698
I::ProjectionTy: HashStable<CTX>,
699699
I::BoundTy: HashStable<CTX>,
700700
I::ParamTy: HashStable<CTX>,
701+
I::OpaqueTy: HashStable<CTX>,
701702
I::PlaceholderType: HashStable<CTX>,
702703
I::InferTy: HashStable<CTX>,
703704
I::ErrorGuaranteed: HashStable<CTX>,
@@ -775,9 +776,8 @@ where
775776
Projection(p) => {
776777
p.hash_stable(__hcx, __hasher);
777778
}
778-
Opaque(def_id, substs) => {
779-
def_id.hash_stable(__hcx, __hasher);
780-
substs.hash_stable(__hcx, __hasher);
779+
Opaque(o) => {
780+
o.hash_stable(__hcx, __hasher);
781781
}
782782
Param(p) => {
783783
p.hash_stable(__hcx, __hasher);

0 commit comments

Comments
 (0)