Skip to content

Commit a0afe6d

Browse files
committed
Store generator movability outside GeneratorInterior
1 parent 427c548 commit a0afe6d

38 files changed

+108
-80
lines changed

src/librustc/ich/impls_mir.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,11 @@ 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) => {
486+
mir::AggregateKind::Generator(def_id, ref substs, ref interior, movability) => {
487487
def_id.hash_stable(hcx, hasher);
488488
substs.hash_stable(hcx, hasher);
489489
interior.hash_stable(hcx, hasher);
490+
movability.hash_stable(hcx, hasher);
490491
}
491492
}
492493
}

src/librustc/ich/impls_ty.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ for ::middle::const_val::ErrKind<'gcx> {
518518

519519
impl_stable_hash_for!(struct ty::ClosureSubsts<'tcx> { substs });
520520

521-
impl_stable_hash_for!(struct ty::GeneratorInterior<'tcx> { witness, movable });
521+
impl_stable_hash_for!(struct ty::GeneratorInterior<'tcx> { witness });
522522

523523
impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
524524
parent,
@@ -908,10 +908,11 @@ for ty::TypeVariants<'gcx>
908908
def_id.hash_stable(hcx, hasher);
909909
closure_substs.hash_stable(hcx, hasher);
910910
}
911-
TyGenerator(def_id, closure_substs, interior) => {
911+
TyGenerator(def_id, closure_substs, interior, movability) => {
912912
def_id.hash_stable(hcx, hasher);
913913
closure_substs.hash_stable(hcx, hasher);
914914
interior.hash_stable(hcx, hasher);
915+
movability.hash_stable(hcx, hasher);
915916
}
916917
TyGeneratorWitness(types) => {
917918
types.hash_stable(hcx, hasher)

src/librustc/mir/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -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>),
1644+
Generator(DefId, ClosureSubsts<'tcx>, GeneratorInterior<'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,10 +2370,11 @@ 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) =>
2373+
AggregateKind::Generator(id, substs, interior, movablity) =>
23742374
AggregateKind::Generator(id,
23752375
substs.fold_with(folder),
2376-
interior.fold_with(folder)),
2376+
interior.fold_with(folder),
2377+
movablity),
23772378
};
23782379
Aggregate(kind, fields.fold_with(folder))
23792380
}
@@ -2400,7 +2401,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
24002401
AggregateKind::Tuple => false,
24012402
AggregateKind::Adt(_, _, substs, _) => substs.visit_with(visitor),
24022403
AggregateKind::Closure(_, substs) => substs.visit_with(visitor),
2403-
AggregateKind::Generator(_, substs, interior) => substs.visit_with(visitor) ||
2404+
AggregateKind::Generator(_, substs, interior, _) => substs.visit_with(visitor) ||
24042405
interior.visit_with(visitor),
24052406
}) || fields.visit_with(visitor)
24062407
}

src/librustc/mir/tcx.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ impl<'tcx> Rvalue<'tcx> {
186186
AggregateKind::Closure(did, substs) => {
187187
tcx.mk_closure_from_closure_substs(did, substs)
188188
}
189-
AggregateKind::Generator(did, substs, interior) => {
190-
tcx.mk_generator(did, substs, interior)
189+
AggregateKind::Generator(did, substs, interior, movability) => {
190+
tcx.mk_generator(did, substs, interior, movability)
191191
}
192192
}
193193
}

src/librustc/mir/visit.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,9 @@ 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)* closure_substs,
599+
ref $($mutability)* interior,
600+
_movability) => {
600601
self.visit_def_id(def_id, location);
601602
self.visit_closure_substs(closure_substs, location);
602603
self.visit_generator_interior(interior, location);

src/librustc/traits/select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2280,7 +2280,7 @@ 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) => {
2283+
ty::TyGenerator(def_id, ref substs, interior, _) => {
22842284
substs.upvar_tys(def_id, self.tcx()).chain(iter::once(interior.witness)).collect()
22852285
}
22862286

@@ -2756,7 +2756,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
27562756
// type/region parameters
27572757
let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder());
27582758
let (closure_def_id, substs) = match self_ty.sty {
2759-
ty::TyGenerator(id, substs, _) => (id, substs),
2759+
ty::TyGenerator(id, substs, _, _) => (id, substs),
27602760
_ => bug!("closure candidate for non-closure {:?}", obligation)
27612761
};
27622762

src/librustc/ty/context.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2445,9 +2445,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
24452445
pub fn mk_generator(self,
24462446
id: DefId,
24472447
closure_substs: ClosureSubsts<'tcx>,
2448-
interior: GeneratorInterior<'tcx>)
2448+
interior: GeneratorInterior<'tcx>,
2449+
movability: hir::GeneratorMovability)
24492450
-> Ty<'tcx> {
2450-
self.mk_ty(TyGenerator(id, closure_substs, interior))
2451+
self.mk_ty(TyGenerator(id, closure_substs, interior, movability))
24512452
}
24522453

24532454
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-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl FlagComputation {
8787
}
8888
}
8989

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

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 |

src/librustc/ty/layout.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
599599
}
600600

601601
// Tuples, generators and closures.
602-
ty::TyGenerator(def_id, ref substs, _) => {
602+
ty::TyGenerator(def_id, ref substs, _, _) => {
603603
let tys = substs.field_tys(def_id, tcx);
604604
univariant(&tys.map(|ty| self.layout_of(ty)).collect::<Result<Vec<_>, _>>()?,
605605
&ReprOptions::default(),
@@ -1603,7 +1603,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
16031603
substs.upvar_tys(def_id, tcx).nth(i).unwrap()
16041604
}
16051605

1606-
ty::TyGenerator(def_id, ref substs, _) => {
1606+
ty::TyGenerator(def_id, ref substs, _, _) => {
16071607
substs.field_tys(def_id, tcx).nth(i).unwrap()
16081608
}
16091609

src/librustc/ty/outlives.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
7979
}
8080
}
8181

82-
ty::TyGenerator(def_id, ref substs, _) => {
82+
ty::TyGenerator(def_id, ref substs, _, _) => {
8383
// Same as the closure case
8484
for upvar_ty in substs.upvar_tys(def_id, *self) {
8585
self.compute_components(upvar_ty, out);

src/librustc/ty/relate.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -415,16 +415,16 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
415415
Ok(tcx.mk_dynamic(relation.relate(a_obj, b_obj)?, region_bound))
416416
}
417417

418-
(&ty::TyGenerator(a_id, a_substs, a_interior),
419-
&ty::TyGenerator(b_id, b_substs, b_interior))
418+
(&ty::TyGenerator(a_id, a_substs, a_interior, movability),
419+
&ty::TyGenerator(b_id, b_substs, b_interior, _))
420420
if a_id == b_id =>
421421
{
422422
// All TyGenerator types with the same id represent
423423
// the (anonymous) type of the same generator expression. So
424424
// all of their regions should be equated.
425425
let substs = relation.relate(&a_substs, &b_substs)?;
426426
let interior = relation.relate(&a_interior, &b_interior)?;
427-
Ok(tcx.mk_generator(a_id, substs, interior))
427+
Ok(tcx.mk_generator(a_id, substs, interior, movability))
428428
}
429429

430430
(&ty::TyGeneratorWitness(a_types), &ty::TyGeneratorWitness(b_types)) =>
@@ -618,9 +618,8 @@ impl<'tcx> Relate<'tcx> for ty::GeneratorInterior<'tcx> {
618618
-> RelateResult<'tcx, ty::GeneratorInterior<'tcx>>
619619
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
620620
{
621-
assert_eq!(a.movable, b.movable);
622621
let witness = relation.relate(&a.witness, &b.witness)?;
623-
Ok(ty::GeneratorInterior { witness, movable: a.movable })
622+
Ok(ty::GeneratorInterior { witness })
624623
}
625624
}
626625

src/librustc/ty/structural_impls.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::GeneratorInterior<'a> {
313313
type Lifted = ty::GeneratorInterior<'tcx>;
314314
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
315315
tcx.lift(&self.witness).map(|witness| {
316-
ty::GeneratorInterior { witness, movable: self.movable }
316+
ty::GeneratorInterior { witness }
317317
})
318318
}
319319
}
@@ -867,8 +867,12 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
867867
ty::TyRef(ref r, tm) => {
868868
ty::TyRef(r.fold_with(folder), tm.fold_with(folder))
869869
}
870-
ty::TyGenerator(did, substs, interior) => {
871-
ty::TyGenerator(did, substs.fold_with(folder), interior.fold_with(folder))
870+
ty::TyGenerator(did, substs, interior, movability) => {
871+
ty::TyGenerator(
872+
did,
873+
substs.fold_with(folder),
874+
interior.fold_with(folder),
875+
movability)
872876
}
873877
ty::TyGeneratorWitness(types) => ty::TyGeneratorWitness(types.fold_with(folder)),
874878
ty::TyClosure(did, substs) => ty::TyClosure(did, substs.fold_with(folder)),
@@ -902,7 +906,7 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
902906
ty::TyFnDef(_, substs) => substs.visit_with(visitor),
903907
ty::TyFnPtr(ref f) => f.visit_with(visitor),
904908
ty::TyRef(r, ref tm) => r.visit_with(visitor) || tm.visit_with(visitor),
905-
ty::TyGenerator(_did, ref substs, ref interior) => {
909+
ty::TyGenerator(_did, ref substs, ref interior, _) => {
906910
substs.visit_with(visitor) || interior.visit_with(visitor)
907911
}
908912
ty::TyGeneratorWitness(ref types) => types.visit_with(visitor),
@@ -981,7 +985,7 @@ BraceStructTypeFoldableImpl! {
981985

982986
BraceStructTypeFoldableImpl! {
983987
impl<'tcx> TypeFoldable<'tcx> for ty::GeneratorInterior<'tcx> {
984-
witness, movable,
988+
witness,
985989
}
986990
}
987991

src/librustc/ty/sty.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub enum TypeVariants<'tcx> {
139139

140140
/// The anonymous type of a generator. Used to represent the type of
141141
/// `|a| yield a`.
142-
TyGenerator(DefId, ClosureSubsts<'tcx>, GeneratorInterior<'tcx>),
142+
TyGenerator(DefId, ClosureSubsts<'tcx>, GeneratorInterior<'tcx>, hir::GeneratorMovability),
143143

144144
/// A type representin the types stored inside a generator.
145145
/// This should only appear in GeneratorInteriors.
@@ -420,7 +420,6 @@ impl<'a, 'gcx, 'tcx> ClosureSubsts<'tcx> {
420420
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
421421
pub struct GeneratorInterior<'tcx> {
422422
pub witness: Ty<'tcx>,
423-
pub movable: bool,
424423
}
425424

426425
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
@@ -1610,7 +1609,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
16101609
TyAdt(_, substs) | TyAnon(_, substs) => {
16111610
substs.regions().collect()
16121611
}
1613-
TyClosure(_, ref substs) | TyGenerator(_, ref substs, _) => {
1612+
TyClosure(_, ref substs) | TyGenerator(_, ref substs, _, _) => {
16141613
substs.substs.regions().collect()
16151614
}
16161615
TyProjection(ref data) => {

src/librustc/ty/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ impl<'a, 'gcx, 'tcx, W> TypeVisitor<'tcx> for TypeIdHasher<'a, 'gcx, 'tcx, W>
667667
TyRawPtr(m) |
668668
TyRef(_, m) => self.hash(m.mutbl),
669669
TyClosure(def_id, _) |
670-
TyGenerator(def_id, _, _) |
670+
TyGenerator(def_id, _, _, _) |
671671
TyAnon(def_id, _) |
672672
TyFnDef(def_id, _) => self.def_id(def_id),
673673
TyAdt(d, _) => self.def_id(d.did),

src/librustc/ty/walk.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn push_subtypes<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent_ty: Ty<'tcx>) {
118118
ty::TyClosure(_, ref substs) => {
119119
stack.extend(substs.substs.types().rev());
120120
}
121-
ty::TyGenerator(_, ref substs, ref interior) => {
121+
ty::TyGenerator(_, ref substs, ref interior, _) => {
122122
stack.push(interior.witness);
123123
stack.extend(substs.substs.types().rev());
124124
}

src/librustc/util/ppaux.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1110,9 +1110,9 @@ define_print! {
11101110
})
11111111
}
11121112
TyStr => write!(f, "str"),
1113-
TyGenerator(did, substs, interior) => ty::tls::with(|tcx| {
1113+
TyGenerator(did, substs, interior, movability) => ty::tls::with(|tcx| {
11141114
let upvar_tys = substs.upvar_tys(did, tcx);
1115-
if interior.movable {
1115+
if movability == hir::GeneratorMovability::Movable {
11161116
write!(f, "[generator")?;
11171117
} else {
11181118
write!(f, "[static generator")?;

src/librustc_mir/borrow_check/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
776776
self.describe_field_from_ty(&tnm.ty, field)
777777
}
778778
ty::TyArray(ty, _) | ty::TySlice(ty) => self.describe_field_from_ty(&ty, field),
779-
ty::TyClosure(def_id, _) | ty::TyGenerator(def_id, _, _) => {
779+
ty::TyClosure(def_id, _) | ty::TyGenerator(def_id, _, _, _) => {
780780
// Convert the def-id into a node-id. node-ids are only valid for
781781
// the local code in the current crate, so this returns an `Option` in case
782782
// the closure comes from another crate. But in that case we wouldn't

src/librustc_mir/borrow_check/nll/region_infer/annotation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl<'gcx, 'tcx> RegionInferenceContext<'tcx> {
3030
&substs.substs[..]
3131
));
3232
}
33-
DefiningTy::Generator(def_id, substs, interior) => {
33+
DefiningTy::Generator(def_id, substs, interior, _) => {
3434
err.note(&format!(
3535
"defining type: {:?} with closure substs {:#?} and interior {:?}",
3636
def_id,

src/librustc_mir/borrow_check/nll/type_check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
528528
}),
529529
}
530530
}
531-
ty::TyGenerator(def_id, substs, _) => {
531+
ty::TyGenerator(def_id, substs, _, _) => {
532532
// Try pre-transform fields first (upvars and current state)
533533
if let Some(ty) = substs.pre_transforms_tys(def_id, tcx).nth(field.index()) {
534534
return Ok(ty);
@@ -1199,7 +1199,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
11991199
}),
12001200
}
12011201
}
1202-
AggregateKind::Generator(def_id, substs, _) => {
1202+
AggregateKind::Generator(def_id, substs, _, _) => {
12031203
// Try pre-transform fields first (upvars and current state)
12041204
if let Some(ty) = substs.pre_transforms_tys(def_id, tcx).nth(field_index) {
12051205
Ok(ty)
@@ -1442,7 +1442,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
14421442
tcx.predicates_of(*def_id).instantiate(tcx, substs.substs)
14431443
}
14441444

1445-
AggregateKind::Generator(def_id, substs, _) => {
1445+
AggregateKind::Generator(def_id, substs, _, _) => {
14461446
tcx.predicates_of(*def_id).instantiate(tcx, substs.substs)
14471447
}
14481448

0 commit comments

Comments
 (0)