Skip to content

Commit

Permalink
Store the GeneratorInterior in the new GeneratorSubsts
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed May 8, 2018
1 parent 0edc8f4 commit 710b4ad
Show file tree
Hide file tree
Showing 51 changed files with 357 additions and 308 deletions.
3 changes: 1 addition & 2 deletions src/librustc/ich/impls_mir.rs
Expand Up @@ -483,10 +483,9 @@ for mir::AggregateKind<'gcx> {
def_id.hash_stable(hcx, hasher);
substs.hash_stable(hcx, hasher);
}
mir::AggregateKind::Generator(def_id, ref substs, ref interior, movability) => {
mir::AggregateKind::Generator(def_id, ref substs, movability) => {
def_id.hash_stable(hcx, hasher);
substs.hash_stable(hcx, hasher);
interior.hash_stable(hcx, hasher);
movability.hash_stable(hcx, hasher);
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/librustc/ich/impls_ty.rs
Expand Up @@ -517,8 +517,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 });
impl_stable_hash_for!(struct ty::GeneratorSubsts<'tcx> { substs });

impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
parent,
Expand Down Expand Up @@ -908,10 +907,9 @@ for ty::TypeVariants<'gcx>
def_id.hash_stable(hcx, hasher);
closure_substs.hash_stable(hcx, hasher);
}
TyGenerator(def_id, closure_substs, interior, movability) => {
TyGenerator(def_id, generator_substs, movability) => {
def_id.hash_stable(hcx, hasher);
closure_substs.hash_stable(hcx, hasher);
interior.hash_stable(hcx, hasher);
generator_substs.hash_stable(hcx, hasher);
movability.hash_stable(hcx, hasher);
}
TyGeneratorWitness(types) => {
Expand Down Expand Up @@ -1316,11 +1314,11 @@ for traits::VtableGeneratorData<'gcx, N> where N: HashStable<StableHashingContex
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
let traits::VtableGeneratorData {
closure_def_id,
generator_def_id,
substs,
ref nested,
} = *self;
closure_def_id.hash_stable(hcx, hasher);
generator_def_id.hash_stable(hcx, hasher);
substs.hash_stable(hcx, hasher);
nested.hash_stable(hcx, hasher);
}
Expand Down
16 changes: 6 additions & 10 deletions src/librustc/mir/mod.rs
Expand Up @@ -27,7 +27,7 @@ use hir::def_id::DefId;
use mir::visit::MirVisitable;
use mir::interpret::{Value, PrimVal, EvalErrorKind};
use ty::subst::{Subst, Substs};
use ty::{self, AdtDef, CanonicalTy, ClosureSubsts, Region, Ty, TyCtxt, GeneratorInterior};
use ty::{self, AdtDef, CanonicalTy, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt};
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
use ty::TypeAndMut;
use util::ppaux;
Expand Down 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>, hir::GeneratorMovability),
Generator(DefId, GeneratorSubsts<'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,11 +2375,8 @@ 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, movablity) =>
AggregateKind::Generator(id,
substs.fold_with(folder),
interior.fold_with(folder),
movablity),
AggregateKind::Generator(id, substs, movablity) =>
AggregateKind::Generator(id, substs.fold_with(folder), movablity),
};
Aggregate(kind, fields.fold_with(folder))
}
Expand All @@ -2406,8 +2403,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) ||
interior.visit_with(visitor),
AggregateKind::Generator(_, substs, _) => substs.visit_with(visitor),
}) || fields.visit_with(visitor)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/mir/tcx.rs
Expand Up @@ -184,10 +184,10 @@ impl<'tcx> Rvalue<'tcx> {
tcx.type_of(def.did).subst(tcx, substs)
}
AggregateKind::Closure(did, substs) => {
tcx.mk_closure_from_closure_substs(did, substs)
tcx.mk_closure(did, substs)
}
AggregateKind::Generator(did, substs, interior, movability) => {
tcx.mk_generator(did, substs, interior, movability)
AggregateKind::Generator(did, substs, movability) => {
tcx.mk_generator(did, substs, movability)
}
}
}
Expand Down
18 changes: 8 additions & 10 deletions src/librustc/mir/visit.rs
Expand Up @@ -10,7 +10,7 @@

use hir::def_id::DefId;
use ty::subst::Substs;
use ty::{CanonicalTy, ClosureSubsts, Region, Ty, GeneratorInterior};
use ty::{CanonicalTy, ClosureSubsts, GeneratorSubsts, Region, Ty};
use mir::*;
use syntax_pos::Span;

Expand Down Expand Up @@ -243,10 +243,10 @@ macro_rules! make_mir_visitor {
self.super_closure_substs(substs);
}

fn visit_generator_interior(&mut self,
interior: & $($mutability)* GeneratorInterior<'tcx>,
fn visit_generator_substs(&mut self,
substs: & $($mutability)* GeneratorSubsts<'tcx>,
_: Location) {
self.super_generator_interior(interior);
self.super_generator_substs(substs);
}

fn visit_local_decl(&mut self,
Expand Down Expand Up @@ -595,12 +595,10 @@ 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)* generator_substs,
_movability) => {
self.visit_def_id(def_id, location);
self.visit_closure_substs(closure_substs, location);
self.visit_generator_interior(interior, location);
self.visit_generator_substs(generator_substs, location);
}
}

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

fn super_generator_interior(&mut self,
_interior: & $($mutability)* GeneratorInterior<'tcx>) {
fn super_generator_substs(&mut self,
_substs: & $($mutability)* GeneratorSubsts<'tcx>) {
}

fn super_closure_substs(&mut self,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/traits/mod.rs
Expand Up @@ -480,8 +480,8 @@ pub struct VtableImplData<'tcx, N> {

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)]
pub struct VtableGeneratorData<'tcx, N> {
pub closure_def_id: DefId,
pub substs: ty::ClosureSubsts<'tcx>,
pub generator_def_id: DefId,
pub substs: ty::GeneratorSubsts<'tcx>,
/// Nested obligations. This can be non-empty if the generator
/// signature contains associated types.
pub nested: Vec<N>
Expand Down Expand Up @@ -989,7 +989,7 @@ impl<'tcx, N> Vtable<'tcx, N> {
nested: p.nested.into_iter().map(f).collect(),
}),
VtableGenerator(c) => VtableGenerator(VtableGeneratorData {
closure_def_id: c.closure_def_id,
generator_def_id: c.generator_def_id,
substs: c.substs,
nested: c.nested.into_iter().map(f).collect(),
}),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/project.rs
Expand Up @@ -1288,7 +1288,7 @@ fn confirm_generator_candidate<'cx, 'gcx, 'tcx>(
vtable: VtableGeneratorData<'tcx, PredicateObligation<'tcx>>)
-> Progress<'tcx>
{
let gen_sig = vtable.substs.generator_poly_sig(vtable.closure_def_id, selcx.tcx());
let gen_sig = vtable.substs.poly_sig(vtable.generator_def_id, selcx.tcx());
let Normalized {
value: gen_sig,
obligations
Expand Down
24 changes: 13 additions & 11 deletions src/librustc/traits/select.rs
Expand Up @@ -2280,8 +2280,9 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
substs.upvar_tys(def_id, self.tcx()).collect()
}

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

ty::TyGeneratorWitness(types) => {
Expand Down Expand Up @@ -2755,18 +2756,18 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
// touch bound regions, they just capture the in-scope
// 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),
let (generator_def_id, substs) = match self_ty.sty {
ty::TyGenerator(id, substs, _) => (id, substs),
_ => bug!("closure candidate for non-closure {:?}", obligation)
};

debug!("confirm_generator_candidate({:?},{:?},{:?})",
obligation,
closure_def_id,
generator_def_id,
substs);

let trait_ref =
self.generator_trait_ref_unnormalized(obligation, closure_def_id, substs);
self.generator_trait_ref_unnormalized(obligation, generator_def_id, substs);
let Normalized {
value: trait_ref,
mut obligations
Expand All @@ -2776,8 +2777,9 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
obligation.recursion_depth+1,
&trait_ref);

debug!("confirm_generator_candidate(closure_def_id={:?}, trait_ref={:?}, obligations={:?})",
closure_def_id,
debug!("confirm_generator_candidate(generator_def_id={:?}, \
trait_ref={:?}, obligations={:?})",
generator_def_id,
trait_ref,
obligations);

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

Ok(VtableGeneratorData {
closure_def_id: closure_def_id,
generator_def_id: generator_def_id,
substs: substs.clone(),
nested: obligations
})
Expand Down Expand Up @@ -3294,10 +3296,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
fn generator_trait_ref_unnormalized(&mut self,
obligation: &TraitObligation<'tcx>,
closure_def_id: DefId,
substs: ty::ClosureSubsts<'tcx>)
substs: ty::GeneratorSubsts<'tcx>)
-> ty::PolyTraitRef<'tcx>
{
let gen_sig = substs.generator_poly_sig(closure_def_id, self.tcx());
let gen_sig = substs.poly_sig(closure_def_id, self.tcx());

// (1) Feels icky to skip the binder here, but OTOH we know
// that the self-type is an generator type and hence is
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/traits/structural_impls.rs
Expand Up @@ -83,8 +83,8 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableImplData<'tcx, N> {

impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableGeneratorData<'tcx, N> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "VtableGenerator(closure_def_id={:?}, substs={:?}, nested={:?})",
self.closure_def_id,
write!(f, "VtableGenerator(generator_def_id={:?}, substs={:?}, nested={:?})",
self.generator_def_id,
self.substs,
self.nested)
}
Expand Down Expand Up @@ -294,13 +294,13 @@ impl<'a, 'tcx> Lift<'tcx> for traits::Vtable<'a, ()> {
}
traits::VtableAutoImpl(t) => Some(traits::VtableAutoImpl(t)),
traits::VtableGenerator(traits::VtableGeneratorData {
closure_def_id,
generator_def_id,
substs,
nested
}) => {
tcx.lift(&substs).map(|substs| {
traits::VtableGenerator(traits::VtableGeneratorData {
closure_def_id: closure_def_id,
generator_def_id: generator_def_id,
substs: substs,
nested: nested
})
Expand Down Expand Up @@ -373,7 +373,7 @@ BraceStructTypeFoldableImpl! {

BraceStructTypeFoldableImpl! {
impl<'tcx, N> TypeFoldable<'tcx> for traits::VtableGeneratorData<'tcx, N> {
closure_def_id, substs, nested
generator_def_id, substs, nested
} where N: TypeFoldable<'tcx>
}

Expand Down
18 changes: 4 additions & 14 deletions src/librustc/ty/context.rs
Expand Up @@ -41,7 +41,7 @@ use traits;
use traits::{Clause, Clauses, Goal, Goals};
use ty::{self, Ty, TypeAndMut};
use ty::{TyS, TypeVariants, Slice};
use ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorInterior, Region, Const};
use ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorSubsts, Region, Const};
use ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predicate};
use ty::RegionKind;
use ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid};
Expand Down Expand Up @@ -2436,27 +2436,17 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}))
}

pub fn mk_closure(self,
closure_id: DefId,
substs: ClosureSubsts<'tcx>)
-> Ty<'tcx> {
self.mk_closure_from_closure_substs(closure_id, substs)
}

pub fn mk_closure_from_closure_substs(self,
closure_id: DefId,
closure_substs: ClosureSubsts<'tcx>)
pub fn mk_closure(self, closure_id: DefId, closure_substs: ClosureSubsts<'tcx>)
-> Ty<'tcx> {
self.mk_ty(TyClosure(closure_id, closure_substs))
}

pub fn mk_generator(self,
id: DefId,
closure_substs: ClosureSubsts<'tcx>,
interior: GeneratorInterior<'tcx>,
generator_substs: GeneratorSubsts<'tcx>,
movability: hir::GeneratorMovability)
-> Ty<'tcx> {
self.mk_ty(TyGenerator(id, closure_substs, interior, movability))
self.mk_ty(TyGenerator(id, generator_substs, 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
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
3 changes: 1 addition & 2 deletions src/librustc/ty/flags.rs
Expand Up @@ -87,11 +87,10 @@ impl FlagComputation {
}
}

&ty::TyGenerator(_, ref substs, ref interior, _) => {
&ty::TyGenerator(_, ref substs, _) => {
self.add_flags(TypeFlags::HAS_TY_CLOSURE);
self.add_flags(TypeFlags::HAS_LOCAL_NAMES);
self.add_substs(&substs.substs);
self.add_ty(interior.witness);
}

&ty::TyGeneratorWitness(ref ts) => {
Expand Down
9 changes: 4 additions & 5 deletions src/librustc/ty/instance.rs
Expand Up @@ -270,10 +270,10 @@ fn resolve_associated_item<'a, 'tcx>(
let substs = tcx.erase_regions(&substs);
Some(ty::Instance::new(def_id, substs))
}
traits::VtableGenerator(closure_data) => {
traits::VtableGenerator(generator_data) => {
Some(Instance {
def: ty::InstanceDef::Item(closure_data.closure_def_id),
substs: closure_data.substs.substs
def: ty::InstanceDef::Item(generator_data.generator_def_id),
substs: generator_data.substs.substs
})
}
traits::VtableClosure(closure_data) => {
Expand Down Expand Up @@ -356,8 +356,7 @@ fn fn_once_adapter_instance<'a, 'tcx>(
.unwrap().def_id;
let def = ty::InstanceDef::ClosureOnceShim { call_once };

let self_ty = tcx.mk_closure_from_closure_substs(
closure_did, substs);
let self_ty = tcx.mk_closure(closure_did, substs);

let sig = substs.closure_sig(closure_did, tcx);
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/item_path.rs
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

0 comments on commit 710b4ad

Please sign in to comment.