Skip to content

Commit

Permalink
Store generator movability outside GeneratorInterior
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed May 8, 2018
1 parent 697a989 commit 0edc8f4
Show file tree
Hide file tree
Showing 38 changed files with 108 additions and 80 deletions.
3 changes: 2 additions & 1 deletion src/librustc/ich/impls_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,11 @@ for mir::AggregateKind<'gcx> {
def_id.hash_stable(hcx, hasher);
substs.hash_stable(hcx, hasher);
}
mir::AggregateKind::Generator(def_id, ref substs, ref interior) => {
mir::AggregateKind::Generator(def_id, ref substs, ref interior, movability) => {
def_id.hash_stable(hcx, hasher);
substs.hash_stable(hcx, hasher);
interior.hash_stable(hcx, hasher);
movability.hash_stable(hcx, hasher);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ for ::middle::const_val::ErrKind<'gcx> {

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

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

impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
parent,
Expand Down Expand Up @@ -908,10 +908,11 @@ for ty::TypeVariants<'gcx>
def_id.hash_stable(hcx, hasher);
closure_substs.hash_stable(hcx, hasher);
}
TyGenerator(def_id, closure_substs, interior) => {
TyGenerator(def_id, closure_substs, interior, movability) => {
def_id.hash_stable(hcx, hasher);
closure_substs.hash_stable(hcx, hasher);
interior.hash_stable(hcx, hasher);
movability.hash_stable(hcx, hasher);
}
TyGeneratorWitness(types) => {
types.hash_stable(hcx, hasher)
Expand Down
11 changes: 6 additions & 5 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ pub enum AggregateKind<'tcx> {
Adt(&'tcx AdtDef, usize, &'tcx Substs<'tcx>, Option<usize>),

Closure(DefId, ClosureSubsts<'tcx>),
Generator(DefId, ClosureSubsts<'tcx>, GeneratorInterior<'tcx>),
Generator(DefId, ClosureSubsts<'tcx>, GeneratorInterior<'tcx>, hir::GeneratorMovability),
}

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

AggregateKind::Generator(def_id, _, _) => ty::tls::with(|tcx| {
AggregateKind::Generator(def_id, _, _, _) => ty::tls::with(|tcx| {
if let Some(node_id) = tcx.hir.as_local_node_id(def_id) {
let name = format!("[generator@{:?}]", tcx.hir.span(node_id));
let mut struct_fmt = fmt.debug_struct(&name);
Expand Down Expand Up @@ -2375,10 +2375,11 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
AggregateKind::Adt(def, v, substs.fold_with(folder), n),
AggregateKind::Closure(id, substs) =>
AggregateKind::Closure(id, substs.fold_with(folder)),
AggregateKind::Generator(id, substs, interior) =>
AggregateKind::Generator(id, substs, interior, movablity) =>
AggregateKind::Generator(id,
substs.fold_with(folder),
interior.fold_with(folder)),
interior.fold_with(folder),
movablity),
};
Aggregate(kind, fields.fold_with(folder))
}
Expand All @@ -2405,7 +2406,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
AggregateKind::Tuple => false,
AggregateKind::Adt(_, _, substs, _) => substs.visit_with(visitor),
AggregateKind::Closure(_, substs) => substs.visit_with(visitor),
AggregateKind::Generator(_, substs, interior) => substs.visit_with(visitor) ||
AggregateKind::Generator(_, substs, interior, _) => substs.visit_with(visitor) ||
interior.visit_with(visitor),
}) || fields.visit_with(visitor)
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/mir/tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ impl<'tcx> Rvalue<'tcx> {
AggregateKind::Closure(did, substs) => {
tcx.mk_closure_from_closure_substs(did, substs)
}
AggregateKind::Generator(did, substs, interior) => {
tcx.mk_generator(did, substs, interior)
AggregateKind::Generator(did, substs, interior, movability) => {
tcx.mk_generator(did, substs, interior, movability)
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,9 @@ macro_rules! make_mir_visitor {
self.visit_closure_substs(closure_substs, location);
}
AggregateKind::Generator(ref $($mutability)* def_id,
ref $($mutability)* closure_substs,
ref $($mutability)* interior) => {
ref $($mutability)* closure_substs,
ref $($mutability)* interior,
_movability) => {
self.visit_def_id(def_id, location);
self.visit_closure_substs(closure_substs, location);
self.visit_generator_interior(interior, location);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2280,7 +2280,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
substs.upvar_tys(def_id, self.tcx()).collect()
}

ty::TyGenerator(def_id, ref substs, interior) => {
ty::TyGenerator(def_id, ref substs, interior, _) => {
substs.upvar_tys(def_id, self.tcx()).chain(iter::once(interior.witness)).collect()
}

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

Expand Down
5 changes: 3 additions & 2 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2453,9 +2453,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
pub fn mk_generator(self,
id: DefId,
closure_substs: ClosureSubsts<'tcx>,
interior: GeneratorInterior<'tcx>)
interior: GeneratorInterior<'tcx>,
movability: hir::GeneratorMovability)
-> Ty<'tcx> {
self.mk_ty(TyGenerator(id, closure_substs, interior))
self.mk_ty(TyGenerator(id, closure_substs, interior, movability))
}

pub fn mk_generator_witness(self, types: ty::Binder<&'tcx Slice<Ty<'tcx>>>) -> Ty<'tcx> {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/fast_reject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub fn simplify_type<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
ty::TyClosure(def_id, _) => {
Some(ClosureSimplifiedType(def_id))
}
ty::TyGenerator(def_id, _, _) => {
ty::TyGenerator(def_id, _, _, _) => {
Some(GeneratorSimplifiedType(def_id))
}
ty::TyGeneratorWitness(ref tys) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl FlagComputation {
}
}

&ty::TyGenerator(_, ref substs, ref interior) => {
&ty::TyGenerator(_, ref substs, ref interior, _) => {
self.add_flags(TypeFlags::HAS_TY_CLOSURE);
self.add_flags(TypeFlags::HAS_LOCAL_NAMES);
self.add_substs(&substs.substs);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/item_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ pub fn characteristic_def_id_of_type(ty: Ty) -> Option<DefId> {

ty::TyFnDef(def_id, _) |
ty::TyClosure(def_id, _) |
ty::TyGenerator(def_id, _, _) |
ty::TyGenerator(def_id, _, _, _) |
ty::TyForeign(def_id) => Some(def_id),

ty::TyBool |
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
}

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

ty::TyGenerator(def_id, ref substs, _) => {
ty::TyGenerator(def_id, ref substs, _, _) => {
substs.field_tys(def_id, tcx).nth(i).unwrap()
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/outlives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}
}

ty::TyGenerator(def_id, ref substs, _) => {
ty::TyGenerator(def_id, ref substs, _, _) => {
// Same as the closure case
for upvar_ty in substs.upvar_tys(def_id, *self) {
self.compute_components(upvar_ty, out);
Expand Down
9 changes: 4 additions & 5 deletions src/librustc/ty/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,16 +415,16 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
Ok(tcx.mk_dynamic(relation.relate(a_obj, b_obj)?, region_bound))
}

(&ty::TyGenerator(a_id, a_substs, a_interior),
&ty::TyGenerator(b_id, b_substs, b_interior))
(&ty::TyGenerator(a_id, a_substs, a_interior, movability),
&ty::TyGenerator(b_id, b_substs, b_interior, _))
if a_id == b_id =>
{
// All TyGenerator types with the same id represent
// the (anonymous) type of the same generator expression. So
// all of their regions should be equated.
let substs = relation.relate(&a_substs, &b_substs)?;
let interior = relation.relate(&a_interior, &b_interior)?;
Ok(tcx.mk_generator(a_id, substs, interior))
Ok(tcx.mk_generator(a_id, substs, interior, movability))
}

(&ty::TyGeneratorWitness(a_types), &ty::TyGeneratorWitness(b_types)) =>
Expand Down Expand Up @@ -618,9 +618,8 @@ impl<'tcx> Relate<'tcx> for ty::GeneratorInterior<'tcx> {
-> RelateResult<'tcx, ty::GeneratorInterior<'tcx>>
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
{
assert_eq!(a.movable, b.movable);
let witness = relation.relate(&a.witness, &b.witness)?;
Ok(ty::GeneratorInterior { witness, movable: a.movable })
Ok(ty::GeneratorInterior { witness })
}
}

Expand Down
14 changes: 9 additions & 5 deletions src/librustc/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::GeneratorInterior<'a> {
type Lifted = ty::GeneratorInterior<'tcx>;
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
tcx.lift(&self.witness).map(|witness| {
ty::GeneratorInterior { witness, movable: self.movable }
ty::GeneratorInterior { witness }
})
}
}
Expand Down Expand Up @@ -867,8 +867,12 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
ty::TyRef(ref r, tm) => {
ty::TyRef(r.fold_with(folder), tm.fold_with(folder))
}
ty::TyGenerator(did, substs, interior) => {
ty::TyGenerator(did, substs.fold_with(folder), interior.fold_with(folder))
ty::TyGenerator(did, substs, interior, movability) => {
ty::TyGenerator(
did,
substs.fold_with(folder),
interior.fold_with(folder),
movability)
}
ty::TyGeneratorWitness(types) => ty::TyGeneratorWitness(types.fold_with(folder)),
ty::TyClosure(did, substs) => ty::TyClosure(did, substs.fold_with(folder)),
Expand Down Expand Up @@ -902,7 +906,7 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
ty::TyFnDef(_, substs) => substs.visit_with(visitor),
ty::TyFnPtr(ref f) => f.visit_with(visitor),
ty::TyRef(r, ref tm) => r.visit_with(visitor) || tm.visit_with(visitor),
ty::TyGenerator(_did, ref substs, ref interior) => {
ty::TyGenerator(_did, ref substs, ref interior, _) => {
substs.visit_with(visitor) || interior.visit_with(visitor)
}
ty::TyGeneratorWitness(ref types) => types.visit_with(visitor),
Expand Down Expand Up @@ -981,7 +985,7 @@ BraceStructTypeFoldableImpl! {

BraceStructTypeFoldableImpl! {
impl<'tcx> TypeFoldable<'tcx> for ty::GeneratorInterior<'tcx> {
witness, movable,
witness,
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub enum TypeVariants<'tcx> {

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

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

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
Expand Down Expand Up @@ -1605,7 +1604,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
TyAdt(_, substs) | TyAnon(_, substs) => {
substs.regions().collect()
}
TyClosure(_, ref substs) | TyGenerator(_, ref substs, _) => {
TyClosure(_, ref substs) | TyGenerator(_, ref substs, _, _) => {
substs.substs.regions().collect()
}
TyProjection(ref data) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ impl<'a, 'gcx, 'tcx, W> TypeVisitor<'tcx> for TypeIdHasher<'a, 'gcx, 'tcx, W>
TyRawPtr(m) |
TyRef(_, m) => self.hash(m.mutbl),
TyClosure(def_id, _) |
TyGenerator(def_id, _, _) |
TyGenerator(def_id, _, _, _) |
TyAnon(def_id, _) |
TyFnDef(def_id, _) => self.def_id(def_id),
TyAdt(d, _) => self.def_id(d.did),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn push_subtypes<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent_ty: Ty<'tcx>) {
ty::TyClosure(_, ref substs) => {
stack.extend(substs.substs.types().rev());
}
ty::TyGenerator(_, ref substs, ref interior) => {
ty::TyGenerator(_, ref substs, ref interior, _) => {
stack.push(interior.witness);
stack.extend(substs.substs.types().rev());
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,9 +1110,9 @@ define_print! {
})
}
TyStr => write!(f, "str"),
TyGenerator(did, substs, interior) => ty::tls::with(|tcx| {
TyGenerator(did, substs, interior, movability) => ty::tls::with(|tcx| {
let upvar_tys = substs.upvar_tys(did, tcx);
if interior.movable {
if movability == hir::GeneratorMovability::Movable {
write!(f, "[generator")?;
} else {
write!(f, "[static generator")?;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
self.describe_field_from_ty(&tnm.ty, field)
}
ty::TyArray(ty, _) | ty::TySlice(ty) => self.describe_field_from_ty(&ty, field),
ty::TyClosure(def_id, _) | ty::TyGenerator(def_id, _, _) => {
ty::TyClosure(def_id, _) | ty::TyGenerator(def_id, _, _, _) => {
// Convert the def-id into a node-id. node-ids are only valid for
// the local code in the current crate, so this returns an `Option` in case
// the closure comes from another crate. But in that case we wouldn't
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<'gcx, 'tcx> RegionInferenceContext<'tcx> {
&substs.substs[..]
));
}
DefiningTy::Generator(def_id, substs, interior) => {
DefiningTy::Generator(def_id, substs, interior, _) => {
err.note(&format!(
"defining type: {:?} with closure substs {:#?} and interior {:?}",
def_id,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/borrow_check/nll/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
}),
}
}
ty::TyGenerator(def_id, substs, _) => {
ty::TyGenerator(def_id, substs, _, _) => {
// Try pre-transform fields first (upvars and current state)
if let Some(ty) = substs.pre_transforms_tys(def_id, tcx).nth(field.index()) {
return Ok(ty);
Expand Down Expand Up @@ -1254,7 +1254,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
}),
}
}
AggregateKind::Generator(def_id, substs, _) => {
AggregateKind::Generator(def_id, substs, _, _) => {
// Try pre-transform fields first (upvars and current state)
if let Some(ty) = substs.pre_transforms_tys(def_id, tcx).nth(field_index) {
Ok(ty)
Expand Down Expand Up @@ -1497,7 +1497,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
tcx.predicates_of(*def_id).instantiate(tcx, substs.substs)
}

AggregateKind::Generator(def_id, substs, _) => {
AggregateKind::Generator(def_id, substs, _, _) => {
tcx.predicates_of(*def_id).instantiate(tcx, substs.substs)
}

Expand Down
Loading

0 comments on commit 0edc8f4

Please sign in to comment.