Skip to content

Commit 074477c

Browse files
committed
Store the GeneratorInterior in the new GeneratorSubsts
1 parent a0afe6d commit 074477c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+349
-307
lines changed

src/librustc/ich/impls_mir.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,9 @@ for mir::AggregateKind<'gcx> {
483483
def_id.hash_stable(hcx, hasher);
484484
substs.hash_stable(hcx, hasher);
485485
}
486-
mir::AggregateKind::Generator(def_id, ref substs, ref interior, movability) => {
486+
mir::AggregateKind::Generator(def_id, ref substs, movability) => {
487487
def_id.hash_stable(hcx, hasher);
488488
substs.hash_stable(hcx, hasher);
489-
interior.hash_stable(hcx, hasher);
490489
movability.hash_stable(hcx, hasher);
491490
}
492491
}

src/librustc/ich/impls_ty.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,7 @@ for ::middle::const_val::ErrKind<'gcx> {
517517
}
518518

519519
impl_stable_hash_for!(struct ty::ClosureSubsts<'tcx> { substs });
520-
521-
impl_stable_hash_for!(struct ty::GeneratorInterior<'tcx> { witness });
520+
impl_stable_hash_for!(struct ty::GeneratorSubsts<'tcx> { substs });
522521

523522
impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
524523
parent,
@@ -908,10 +907,9 @@ for ty::TypeVariants<'gcx>
908907
def_id.hash_stable(hcx, hasher);
909908
closure_substs.hash_stable(hcx, hasher);
910909
}
911-
TyGenerator(def_id, closure_substs, interior, movability) => {
910+
TyGenerator(def_id, generator_substs, movability) => {
912911
def_id.hash_stable(hcx, hasher);
913-
closure_substs.hash_stable(hcx, hasher);
914-
interior.hash_stable(hcx, hasher);
912+
generator_substs.hash_stable(hcx, hasher);
915913
movability.hash_stable(hcx, hasher);
916914
}
917915
TyGeneratorWitness(types) => {
@@ -1316,11 +1314,11 @@ for traits::VtableGeneratorData<'gcx, N> where N: HashStable<StableHashingContex
13161314
hcx: &mut StableHashingContext<'a>,
13171315
hasher: &mut StableHasher<W>) {
13181316
let traits::VtableGeneratorData {
1319-
closure_def_id,
1317+
generator_def_id,
13201318
substs,
13211319
ref nested,
13221320
} = *self;
1323-
closure_def_id.hash_stable(hcx, hasher);
1321+
generator_def_id.hash_stable(hcx, hasher);
13241322
substs.hash_stable(hcx, hasher);
13251323
nested.hash_stable(hcx, hasher);
13261324
}

src/librustc/mir/mod.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use hir::def_id::DefId;
2727
use mir::visit::MirVisitable;
2828
use mir::interpret::{Value, PrimVal, EvalErrorKind};
2929
use ty::subst::{Subst, Substs};
30-
use ty::{self, AdtDef, CanonicalTy, ClosureSubsts, Region, Ty, TyCtxt, GeneratorInterior};
30+
use ty::{self, AdtDef, CanonicalTy, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt};
3131
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
3232
use ty::TypeAndMut;
3333
use util::ppaux;
@@ -1641,7 +1641,7 @@ pub enum AggregateKind<'tcx> {
16411641
Adt(&'tcx AdtDef, usize, &'tcx Substs<'tcx>, Option<usize>),
16421642

16431643
Closure(DefId, ClosureSubsts<'tcx>),
1644-
Generator(DefId, ClosureSubsts<'tcx>, GeneratorInterior<'tcx>, hir::GeneratorMovability),
1644+
Generator(DefId, GeneratorSubsts<'tcx>, hir::GeneratorMovability),
16451645
}
16461646

16471647
#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
@@ -1804,7 +1804,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
18041804
}
18051805
}),
18061806

1807-
AggregateKind::Generator(def_id, _, _, _) => ty::tls::with(|tcx| {
1807+
AggregateKind::Generator(def_id, _, _) => ty::tls::with(|tcx| {
18081808
if let Some(node_id) = tcx.hir.as_local_node_id(def_id) {
18091809
let name = format!("[generator@{:?}]", tcx.hir.span(node_id));
18101810
let mut struct_fmt = fmt.debug_struct(&name);
@@ -2370,11 +2370,8 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
23702370
AggregateKind::Adt(def, v, substs.fold_with(folder), n),
23712371
AggregateKind::Closure(id, substs) =>
23722372
AggregateKind::Closure(id, substs.fold_with(folder)),
2373-
AggregateKind::Generator(id, substs, interior, movablity) =>
2374-
AggregateKind::Generator(id,
2375-
substs.fold_with(folder),
2376-
interior.fold_with(folder),
2377-
movablity),
2373+
AggregateKind::Generator(id, substs, movablity) =>
2374+
AggregateKind::Generator(id, substs.fold_with(folder), movablity),
23782375
};
23792376
Aggregate(kind, fields.fold_with(folder))
23802377
}
@@ -2401,8 +2398,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
24012398
AggregateKind::Tuple => false,
24022399
AggregateKind::Adt(_, _, substs, _) => substs.visit_with(visitor),
24032400
AggregateKind::Closure(_, substs) => substs.visit_with(visitor),
2404-
AggregateKind::Generator(_, substs, interior, _) => substs.visit_with(visitor) ||
2405-
interior.visit_with(visitor),
2401+
AggregateKind::Generator(_, substs, _) => substs.visit_with(visitor),
24062402
}) || fields.visit_with(visitor)
24072403
}
24082404
}

src/librustc/mir/tcx.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ impl<'tcx> Rvalue<'tcx> {
184184
tcx.type_of(def.did).subst(tcx, substs)
185185
}
186186
AggregateKind::Closure(did, substs) => {
187-
tcx.mk_closure_from_closure_substs(did, substs)
187+
tcx.mk_closure(did, substs)
188188
}
189-
AggregateKind::Generator(did, substs, interior, movability) => {
190-
tcx.mk_generator(did, substs, interior, movability)
189+
AggregateKind::Generator(did, substs, movability) => {
190+
tcx.mk_generator(did, substs, movability)
191191
}
192192
}
193193
}

src/librustc/mir/visit.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use hir::def_id::DefId;
1212
use ty::subst::Substs;
13-
use ty::{CanonicalTy, ClosureSubsts, Region, Ty, GeneratorInterior};
13+
use ty::{CanonicalTy, ClosureSubsts, GeneratorSubsts, Region, Ty};
1414
use mir::*;
1515
use syntax_pos::Span;
1616

@@ -243,10 +243,10 @@ macro_rules! make_mir_visitor {
243243
self.super_closure_substs(substs);
244244
}
245245

246-
fn visit_generator_interior(&mut self,
247-
interior: & $($mutability)* GeneratorInterior<'tcx>,
246+
fn visit_generator_substs(&mut self,
247+
substs: & $($mutability)* GeneratorSubsts<'tcx>,
248248
_: Location) {
249-
self.super_generator_interior(interior);
249+
self.super_generator_substs(substs);
250250
}
251251

252252
fn visit_local_decl(&mut self,
@@ -595,12 +595,10 @@ macro_rules! make_mir_visitor {
595595
self.visit_closure_substs(closure_substs, location);
596596
}
597597
AggregateKind::Generator(ref $($mutability)* def_id,
598-
ref $($mutability)* closure_substs,
599-
ref $($mutability)* interior,
598+
ref $($mutability)* generator_substs,
600599
_movability) => {
601600
self.visit_def_id(def_id, location);
602-
self.visit_closure_substs(closure_substs, location);
603-
self.visit_generator_interior(interior, location);
601+
self.visit_generator_substs(generator_substs, location);
604602
}
605603
}
606604

@@ -787,8 +785,8 @@ macro_rules! make_mir_visitor {
787785
fn super_substs(&mut self, _substs: & $($mutability)* &'tcx Substs<'tcx>) {
788786
}
789787

790-
fn super_generator_interior(&mut self,
791-
_interior: & $($mutability)* GeneratorInterior<'tcx>) {
788+
fn super_generator_substs(&mut self,
789+
_substs: & $($mutability)* GeneratorSubsts<'tcx>) {
792790
}
793791

794792
fn super_closure_substs(&mut self,

src/librustc/traits/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,8 @@ pub struct VtableImplData<'tcx, N> {
480480

481481
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)]
482482
pub struct VtableGeneratorData<'tcx, N> {
483-
pub closure_def_id: DefId,
484-
pub substs: ty::ClosureSubsts<'tcx>,
483+
pub generator_def_id: DefId,
484+
pub substs: ty::GeneratorSubsts<'tcx>,
485485
/// Nested obligations. This can be non-empty if the generator
486486
/// signature contains associated types.
487487
pub nested: Vec<N>
@@ -989,7 +989,7 @@ impl<'tcx, N> Vtable<'tcx, N> {
989989
nested: p.nested.into_iter().map(f).collect(),
990990
}),
991991
VtableGenerator(c) => VtableGenerator(VtableGeneratorData {
992-
closure_def_id: c.closure_def_id,
992+
generator_def_id: c.generator_def_id,
993993
substs: c.substs,
994994
nested: c.nested.into_iter().map(f).collect(),
995995
}),

src/librustc/traits/project.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ fn confirm_generator_candidate<'cx, 'gcx, 'tcx>(
12881288
vtable: VtableGeneratorData<'tcx, PredicateObligation<'tcx>>)
12891289
-> Progress<'tcx>
12901290
{
1291-
let gen_sig = vtable.substs.generator_poly_sig(vtable.closure_def_id, selcx.tcx());
1291+
let gen_sig = vtable.substs.poly_sig(vtable.generator_def_id, selcx.tcx());
12921292
let Normalized {
12931293
value: gen_sig,
12941294
obligations

src/librustc/traits/select.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -2280,8 +2280,9 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
22802280
substs.upvar_tys(def_id, self.tcx()).collect()
22812281
}
22822282

2283-
ty::TyGenerator(def_id, ref substs, interior, _) => {
2284-
substs.upvar_tys(def_id, self.tcx()).chain(iter::once(interior.witness)).collect()
2283+
ty::TyGenerator(def_id, ref substs, _) => {
2284+
let witness = substs.witness(def_id, self.tcx());
2285+
substs.upvar_tys(def_id, self.tcx()).chain(iter::once(witness)).collect()
22852286
}
22862287

22872288
ty::TyGeneratorWitness(types) => {
@@ -2755,18 +2756,18 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
27552756
// touch bound regions, they just capture the in-scope
27562757
// type/region parameters
27572758
let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder());
2758-
let (closure_def_id, substs) = match self_ty.sty {
2759-
ty::TyGenerator(id, substs, _, _) => (id, substs),
2759+
let (generator_def_id, substs) = match self_ty.sty {
2760+
ty::TyGenerator(id, substs, _) => (id, substs),
27602761
_ => bug!("closure candidate for non-closure {:?}", obligation)
27612762
};
27622763

27632764
debug!("confirm_generator_candidate({:?},{:?},{:?})",
27642765
obligation,
2765-
closure_def_id,
2766+
generator_def_id,
27662767
substs);
27672768

27682769
let trait_ref =
2769-
self.generator_trait_ref_unnormalized(obligation, closure_def_id, substs);
2770+
self.generator_trait_ref_unnormalized(obligation, generator_def_id, substs);
27702771
let Normalized {
27712772
value: trait_ref,
27722773
mut obligations
@@ -2776,8 +2777,9 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
27762777
obligation.recursion_depth+1,
27772778
&trait_ref);
27782779

2779-
debug!("confirm_generator_candidate(closure_def_id={:?}, trait_ref={:?}, obligations={:?})",
2780-
closure_def_id,
2780+
debug!("confirm_generator_candidate(generator_def_id={:?}, \
2781+
trait_ref={:?}, obligations={:?})",
2782+
generator_def_id,
27812783
trait_ref,
27822784
obligations);
27832785

@@ -2788,7 +2790,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
27882790
trait_ref)?);
27892791

27902792
Ok(VtableGeneratorData {
2791-
closure_def_id: closure_def_id,
2793+
generator_def_id: generator_def_id,
27922794
substs: substs.clone(),
27932795
nested: obligations
27942796
})
@@ -3295,10 +3297,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
32953297
fn generator_trait_ref_unnormalized(&mut self,
32963298
obligation: &TraitObligation<'tcx>,
32973299
closure_def_id: DefId,
3298-
substs: ty::ClosureSubsts<'tcx>)
3300+
substs: ty::GeneratorSubsts<'tcx>)
32993301
-> ty::PolyTraitRef<'tcx>
33003302
{
3301-
let gen_sig = substs.generator_poly_sig(closure_def_id, self.tcx());
3303+
let gen_sig = substs.poly_sig(closure_def_id, self.tcx());
33023304

33033305
// (1) Feels icky to skip the binder here, but OTOH we know
33043306
// that the self-type is an generator type and hence is

src/librustc/traits/structural_impls.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableImplData<'tcx, N> {
8383

8484
impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableGeneratorData<'tcx, N> {
8585
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
86-
write!(f, "VtableGenerator(closure_def_id={:?}, substs={:?}, nested={:?})",
87-
self.closure_def_id,
86+
write!(f, "VtableGenerator(generator_def_id={:?}, substs={:?}, nested={:?})",
87+
self.generator_def_id,
8888
self.substs,
8989
self.nested)
9090
}
@@ -294,13 +294,13 @@ impl<'a, 'tcx> Lift<'tcx> for traits::Vtable<'a, ()> {
294294
}
295295
traits::VtableAutoImpl(t) => Some(traits::VtableAutoImpl(t)),
296296
traits::VtableGenerator(traits::VtableGeneratorData {
297-
closure_def_id,
297+
generator_def_id,
298298
substs,
299299
nested
300300
}) => {
301301
tcx.lift(&substs).map(|substs| {
302302
traits::VtableGenerator(traits::VtableGeneratorData {
303-
closure_def_id: closure_def_id,
303+
generator_def_id: generator_def_id,
304304
substs: substs,
305305
nested: nested
306306
})
@@ -373,7 +373,7 @@ BraceStructTypeFoldableImpl! {
373373

374374
BraceStructTypeFoldableImpl! {
375375
impl<'tcx, N> TypeFoldable<'tcx> for traits::VtableGeneratorData<'tcx, N> {
376-
closure_def_id, substs, nested
376+
generator_def_id, substs, nested
377377
} where N: TypeFoldable<'tcx>
378378
}
379379

src/librustc/ty/context.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use traits;
4141
use traits::{Clause, Clauses, Goal, Goals};
4242
use ty::{self, Ty, TypeAndMut};
4343
use ty::{TyS, TypeVariants, Slice};
44-
use ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorInterior, Region, Const};
44+
use ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorSubsts, Region, Const};
4545
use ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predicate};
4646
use ty::RegionKind;
4747
use ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid};
@@ -2428,27 +2428,17 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
24282428
}))
24292429
}
24302430

2431-
pub fn mk_closure(self,
2432-
closure_id: DefId,
2433-
substs: ClosureSubsts<'tcx>)
2434-
-> Ty<'tcx> {
2435-
self.mk_closure_from_closure_substs(closure_id, substs)
2436-
}
2437-
2438-
pub fn mk_closure_from_closure_substs(self,
2439-
closure_id: DefId,
2440-
closure_substs: ClosureSubsts<'tcx>)
2431+
pub fn mk_closure(self, closure_id: DefId, closure_substs: ClosureSubsts<'tcx>)
24412432
-> Ty<'tcx> {
24422433
self.mk_ty(TyClosure(closure_id, closure_substs))
24432434
}
24442435

24452436
pub fn mk_generator(self,
24462437
id: DefId,
2447-
closure_substs: ClosureSubsts<'tcx>,
2448-
interior: GeneratorInterior<'tcx>,
2438+
generator_substs: GeneratorSubsts<'tcx>,
24492439
movability: hir::GeneratorMovability)
24502440
-> Ty<'tcx> {
2451-
self.mk_ty(TyGenerator(id, closure_substs, interior, movability))
2441+
self.mk_ty(TyGenerator(id, generator_substs, movability))
24522442
}
24532443

24542444
pub fn mk_generator_witness(self, types: ty::Binder<&'tcx Slice<Ty<'tcx>>>) -> Ty<'tcx> {

src/librustc/ty/fast_reject.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub fn simplify_type<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
9090
ty::TyClosure(def_id, _) => {
9191
Some(ClosureSimplifiedType(def_id))
9292
}
93-
ty::TyGenerator(def_id, _, _, _) => {
93+
ty::TyGenerator(def_id, _, _) => {
9494
Some(GeneratorSimplifiedType(def_id))
9595
}
9696
ty::TyGeneratorWitness(ref tys) => {

src/librustc/ty/flags.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,10 @@ impl FlagComputation {
8787
}
8888
}
8989

90-
&ty::TyGenerator(_, ref substs, ref interior, _) => {
90+
&ty::TyGenerator(_, ref substs, _) => {
9191
self.add_flags(TypeFlags::HAS_TY_CLOSURE);
9292
self.add_flags(TypeFlags::HAS_LOCAL_NAMES);
9393
self.add_substs(&substs.substs);
94-
self.add_ty(interior.witness);
9594
}
9695

9796
&ty::TyGeneratorWitness(ref ts) => {

src/librustc/ty/instance.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,10 @@ fn resolve_associated_item<'a, 'tcx>(
270270
let substs = tcx.erase_regions(&substs);
271271
Some(ty::Instance::new(def_id, substs))
272272
}
273-
traits::VtableGenerator(closure_data) => {
273+
traits::VtableGenerator(generator_data) => {
274274
Some(Instance {
275-
def: ty::InstanceDef::Item(closure_data.closure_def_id),
276-
substs: closure_data.substs.substs
275+
def: ty::InstanceDef::Item(generator_data.generator_def_id),
276+
substs: generator_data.substs.substs
277277
})
278278
}
279279
traits::VtableClosure(closure_data) => {
@@ -356,8 +356,7 @@ fn fn_once_adapter_instance<'a, 'tcx>(
356356
.unwrap().def_id;
357357
let def = ty::InstanceDef::ClosureOnceShim { call_once };
358358

359-
let self_ty = tcx.mk_closure_from_closure_substs(
360-
closure_did, substs);
359+
let self_ty = tcx.mk_closure(closure_did, substs);
361360

362361
let sig = substs.closure_sig(closure_did, tcx);
363362
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);

src/librustc/ty/item_path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ pub fn characteristic_def_id_of_type(ty: Ty) -> Option<DefId> {
369369

370370
ty::TyFnDef(def_id, _) |
371371
ty::TyClosure(def_id, _) |
372-
ty::TyGenerator(def_id, _, _, _) |
372+
ty::TyGenerator(def_id, _, _) |
373373
ty::TyForeign(def_id) => Some(def_id),
374374

375375
ty::TyBool |

0 commit comments

Comments
 (0)