Skip to content

Commit 9e72ef4

Browse files
Add comments, adjust names
1 parent 8e1cabc commit 9e72ef4

File tree

9 files changed

+32
-28
lines changed

9 files changed

+32
-28
lines changed

compiler/rustc_middle/src/ty/codec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ macro_rules! impl_binder_encode_decode {
515515
impl_binder_encode_decode! {
516516
&'tcx ty::List<Ty<'tcx>>,
517517
&'tcx ty::List<ty::GeneratorPredicate<'tcx>>,
518-
ty::GeneratorWitnessInner<'tcx>,
518+
ty::GeneratorInterior<'tcx>,
519519
ty::FnSig<'tcx>,
520520
ty::ExistentialPredicate<'tcx>,
521521
ty::TraitRef<'tcx>,

compiler/rustc_middle/src/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::ty::TyKind::*;
1717
use crate::ty::{
1818
self, AdtDef, AdtKind, Binder, BindingMode, BoundVar, CanonicalPolyFnSig,
1919
ClosureSizeProfileData, Const, ConstVid, DefIdTree, ExistentialPredicate, FloatTy, FloatVar,
20-
FloatVid, GeneratorPredicate, GeneratorWitnessInner, GenericParamDefKind, InferConst, InferTy,
20+
FloatVid, GeneratorInterior, GeneratorPredicate, GenericParamDefKind, InferConst, InferTy,
2121
IntTy, IntVar, IntVid, List, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateInner,
2222
PredicateKind, ProjectionTy, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind,
2323
TyS, TyVar, TyVid, TypeAndMut, UintTy,
@@ -2413,7 +2413,7 @@ impl<'tcx> TyCtxt<'tcx> {
24132413
#[inline]
24142414
pub fn mk_generator_witness(
24152415
self,
2416-
inner: ty::Binder<'tcx, GeneratorWitnessInner<'tcx>>,
2416+
inner: ty::Binder<'tcx, GeneratorInterior<'tcx>>,
24172417
) -> Ty<'tcx> {
24182418
self.mk_ty(GeneratorWitness(inner))
24192419
}

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub use self::sty::{
7575
Binder, BoundRegion, BoundRegionKind, BoundTy, BoundTyKind, BoundVar, BoundVariableKind,
7676
CanonicalPolyFnSig, ClosureSubsts, ClosureSubstsParts, ConstVid, EarlyBoundRegion,
7777
ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FnSig, FreeRegion, GenSig,
78-
GeneratorSubsts, GeneratorSubstsParts, GeneratorWitnessInner, InlineConstSubsts,
78+
GeneratorInterior, GeneratorSubsts, GeneratorSubstsParts, InlineConstSubsts,
7979
InlineConstSubstsParts, ParamConst, ParamTy, PolyExistentialProjection,
8080
PolyExistentialTraitRef, PolyFnSig, PolyGenSig, PolyTraitRef, ProjectionTy, Region, RegionKind,
8181
RegionVid, TraitRef, TyKind, TypeAndMut, UpvarSubsts, VarianceDiagInfo,

compiler/rustc_middle/src/ty/relate.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,15 @@ impl<'tcx> Relate<'tcx> for ty::ExistentialTraitRef<'tcx> {
340340
}
341341
}
342342

343-
impl<'tcx> Relate<'tcx> for ty::GeneratorWitnessInner<'tcx> {
343+
impl<'tcx> Relate<'tcx> for ty::GeneratorInterior<'tcx> {
344344
fn relate<R: TypeRelation<'tcx>>(
345345
relation: &mut R,
346-
a: ty::GeneratorWitnessInner<'tcx>,
347-
b: ty::GeneratorWitnessInner<'tcx>,
348-
) -> RelateResult<'tcx, ty::GeneratorWitnessInner<'tcx>> {
346+
a: ty::GeneratorInterior<'tcx>,
347+
b: ty::GeneratorInterior<'tcx>,
348+
) -> RelateResult<'tcx, ty::GeneratorInterior<'tcx>> {
349349
assert_eq!(a.tys.len(), b.tys.len());
350350
assert_eq!(a.predicates.len(), b.predicates.len());
351-
Ok(ty::GeneratorWitnessInner {
351+
Ok(ty::GeneratorInterior {
352352
tys: relation
353353
.tcx()
354354
.mk_type_list(a.tys.iter().zip(b.tys).map(|(a, b)| relation.relate(a, b)))?,

compiler/rustc_middle/src/ty/sty.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub enum TyKind<'tcx> {
160160

161161
/// A type representing the types stored inside a generator.
162162
/// This should only appear inside of a generator's interior types.
163-
GeneratorWitness(Binder<'tcx, GeneratorWitnessInner<'tcx>>),
163+
GeneratorWitness(Binder<'tcx, GeneratorInterior<'tcx>>),
164164

165165
/// The never type `!`.
166166
Never,
@@ -2311,7 +2311,10 @@ impl<'tcx> VarianceDiagInfo<'tcx> {
23112311

23122312
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
23132313
#[derive(TyEncodable, TyDecodable, Debug, HashStable, TypeFoldable)]
2314-
pub struct GeneratorWitnessInner<'tcx> {
2314+
pub struct GeneratorInterior<'tcx> {
2315+
/// types alive across await points in the generator
23152316
pub tys: &'tcx List<Ty<'tcx>>,
2317+
/// predicates that we know hold in the environment where the generator was created,
2318+
/// which are used when checking auto traits on the generator witness
23162319
pub predicates: &'tcx List<ty::GeneratorPredicate<'tcx>>,
23172320
}

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
317317
let (param_env, nested) =
318318
if let ty::GeneratorWitness(interior) = self_ty.skip_binder().kind() {
319319
self.infcx().commit_unconditionally(|_| {
320-
let ty::GeneratorWitnessInner { tys: nested, predicates } =
320+
let ty::GeneratorInterior { tys: nested, predicates } =
321321
self.infcx().replace_bound_vars_with_placeholders(*interior);
322322
// FIXME(compiler-errors): Not sure if we should augment the param_env,
323323
// or just make a new param_env from these predicates...

compiler/rustc_typeck/src/check/generator_interior.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
8585
.find(|yield_data| {
8686
trace!(
8787
"comparing counts yield: {} self: {}, source_span = {:?}",
88-
yield_data.expr_and_pat_count, self.expr_count, source_span
88+
yield_data.expr_and_pat_count,
89+
self.expr_count,
90+
source_span
8991
);
9092

9193
if ENABLE_DROP_TRACKING
@@ -304,7 +306,7 @@ pub fn resolve_interior<'a, 'tcx>(
304306
);
305307

306308
let witness = fcx.tcx.mk_generator_witness(ty::Binder::bind_with_vars(
307-
ty::GeneratorWitnessInner { tys: anon_tys, predicates: anon_predicates },
309+
ty::GeneratorInterior { tys: anon_tys, predicates: anon_predicates },
308310
bound_vars.clone(),
309311
));
310312

compiler/rustc_typeck/src/check/generator_interior/structural_predicate.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ use rustc_data_structures::stable_set::FxHashSet;
44
use rustc_middle::ty::{self, Ty};
55
use rustc_span::Span;
66

7+
/// This helper walks through generator-interior types, collecting projection types,
8+
/// and creating ProjectionPredicates that we can use in the param-env when checking
9+
/// auto traits later on.
10+
///
11+
/// We walk through the constituent types of a type, and when we encounter a projection,
12+
/// normalize that projection. If that normalization was successful, then create a
13+
/// ProjectionPredicate out of the old projection type and its normalized ty.
714
pub(super) struct StructuralPredicateElaborator<'a, 'tcx> {
815
stack: Vec<Ty<'tcx>>,
916
seen: FxHashSet<Ty<'tcx>>,
@@ -19,18 +26,8 @@ impl<'a, 'tcx> StructuralPredicateElaborator<'a, 'tcx> {
1926
StructuralPredicateElaborator { seen, stack, fcx, span }
2027
}
2128

22-
/// For default impls, we need to break apart a type into its
23-
/// "constituent types" -- meaning, the types that it contains.
24-
///
25-
/// Here are some (simple) examples:
26-
///
27-
/// ```
28-
/// (i32, u32) -> [i32, u32]
29-
/// Foo where struct Foo { x: i32, y: u32 } -> [i32, u32]
30-
/// Bar<i32> where struct Bar<T> { x: T, y: u32 } -> [i32, u32]
31-
/// Zed<i32> where enum Zed { A(T), B(u32) } -> [i32, u32]
32-
/// ```
33-
fn constituent_types_for_auto_trait(&self, t: Ty<'tcx>) -> Vec<Ty<'tcx>> {
29+
// Ripped from confirmation code, lol.
30+
fn constituent_types(&self, t: Ty<'tcx>) -> Vec<Ty<'tcx>> {
3431
match *t.kind() {
3532
ty::Projection(..) => {
3633
bug!("this type should be handled separately: {:?}", t)
@@ -100,10 +97,12 @@ impl<'tcx> Iterator for StructuralPredicateElaborator<'_, 'tcx> {
10097
while let Some(ty) = self.stack.pop() {
10198
if let ty::Projection(projection_ty) = *ty.kind() {
10299
let mut normalized_ty = self.fcx.normalize_associated_types_in(self.span, ty);
100+
// Try to resolve the projection type
103101
if normalized_ty.is_ty_var() {
104102
self.fcx.select_obligations_where_possible(false, |_| {});
105103
normalized_ty = self.fcx.resolve_vars_if_possible(normalized_ty);
106104
}
105+
// If we have a normalized type, then stash it
107106
if !normalized_ty.is_ty_var() && normalized_ty != ty {
108107
if self.seen.insert(normalized_ty) {
109108
self.stack.push(normalized_ty);
@@ -115,7 +114,7 @@ impl<'tcx> Iterator for StructuralPredicateElaborator<'_, 'tcx> {
115114
}
116115
} else {
117116
let structural: Vec<_> = self
118-
.constituent_types_for_auto_trait(ty)
117+
.constituent_types(ty)
119118
.into_iter()
120119
.map(|ty| self.fcx.resolve_vars_if_possible(ty))
121120
.filter(|ty| self.seen.insert(ty))

compiler/rustc_typeck/src/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ struct GeneratorTypes<'tcx> {
499499
/// Type of value that is yielded.
500500
yield_ty: Ty<'tcx>,
501501

502-
/// Types that are captured (see `GeneratorWitnessInner` for more).
502+
/// Types that are captured (see `GeneratorInterior` for more).
503503
interior: Ty<'tcx>,
504504

505505
/// Indicates if the generator is movable or static (immovable).

0 commit comments

Comments
 (0)