remove generator_sigs from TypeckTables

This commit is contained in:
Niko Matsakis 2017-11-18 11:16:25 -05:00
parent d8969815cf
commit 413f07438e
5 changed files with 21 additions and 58 deletions

View file

@ -360,8 +360,6 @@ pub struct TypeckTables<'tcx> {
/// not all closures are present in the map.
closure_kind_origins: ItemLocalMap<(Span, ast::Name)>,
generator_sigs: ItemLocalMap<Option<ty::GenSig<'tcx>>>,
generator_interiors: ItemLocalMap<ty::GeneratorInterior<'tcx>>,
/// For each fn, records the "liberated" types of its arguments
@ -408,7 +406,6 @@ impl<'tcx> TypeckTables<'tcx> {
pat_binding_modes: ItemLocalMap(),
pat_adjustments: ItemLocalMap(),
upvar_capture_map: FxHashMap(),
generator_sigs: ItemLocalMap(),
generator_interiors: ItemLocalMap(),
closure_kind_origins: ItemLocalMap(),
liberated_fn_sigs: ItemLocalMap(),
@ -661,24 +658,6 @@ impl<'tcx> TypeckTables<'tcx> {
}
}
pub fn generator_sigs(&self)
-> LocalTableInContext<Option<ty::GenSig<'tcx>>>
{
LocalTableInContext {
local_id_root: self.local_id_root,
data: &self.generator_sigs,
}
}
pub fn generator_sigs_mut(&mut self)
-> LocalTableInContextMut<Option<ty::GenSig<'tcx>>>
{
LocalTableInContextMut {
local_id_root: self.local_id_root,
data: &mut self.generator_sigs,
}
}
pub fn generator_interiors(&self)
-> LocalTableInContext<ty::GeneratorInterior<'tcx>>
{
@ -720,7 +699,6 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for TypeckTables<'gcx> {
ref used_trait_imports,
tainted_by_errors,
ref free_region_map,
ref generator_sigs,
ref generator_interiors,
} = *self;
@ -757,7 +735,6 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for TypeckTables<'gcx> {
liberated_fn_sigs.hash_stable(hcx, hasher);
fru_field_types.hash_stable(hcx, hasher);
cast_kinds.hash_stable(hcx, hasher);
generator_sigs.hash_stable(hcx, hasher);
generator_interiors.hash_stable(hcx, hasher);
used_trait_imports.hash_stable(hcx, hasher);
tainted_by_errors.hash_stable(hcx, hasher);

View file

@ -335,16 +335,20 @@ impl<'tcx> ClosureSubsts<'tcx> {
/// Return the "generator signature", which consists of its yield
/// and return types.
///
/// NB. We treat this as a `PolyGenSig`, but since it only
/// contains associated types of the generator, at present it
/// never binds any regions.
/// NB. Some bits of the code prefers to see this wrapped in a
/// binder, but it never contains bound regions. Probably this
/// function should be removed.
pub fn generator_poly_sig(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> PolyGenSig<'tcx> {
ty::Binder(
ty::GenSig {
yield_ty: self.generator_yield_ty(def_id, tcx),
return_ty: self.generator_return_ty(def_id, tcx),
}
)
ty::Binder(self.generator_sig(def_id, tcx))
}
/// Return the "generator signature", which consists of its yield
/// and return types.
pub fn generator_sig(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> GenSig<'tcx> {
ty::GenSig {
yield_ty: self.generator_yield_ty(def_id, tcx),
return_ty: self.generator_return_ty(def_id, tcx),
}
}
}

View file

@ -103,7 +103,7 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
Some((closure_self_ty(tcx, id, body_id), None))
}
ty::TyGenerator(..) => {
let gen_ty = tcx.body_tables(body_id).node_id_to_type(fn_hir_id);
let gen_ty = tcx.body_tables(body_id).node_id_to_type(fn_hir_id);
Some((gen_ty, None))
}
_ => None,
@ -127,7 +127,12 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
let arguments = implicit_argument.into_iter().chain(explicit_arguments);
let (yield_ty, return_ty) = if body.is_generator {
let gen_sig = cx.tables().generator_sigs()[fn_hir_id].clone().unwrap();
let gen_sig = match ty.sty {
ty::TyGenerator(gen_def_id, gen_substs, ..) =>
gen_substs.generator_sig(gen_def_id, tcx),
_ =>
span_bug!(tcx.hir.span(id), "generator w/o generator type: {:?}", ty),
};
(Some(gen_sig.yield_ty), gen_sig.return_ty)
} else {
(None, fn_sig.output())

View file

@ -1037,21 +1037,14 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
let fn_hir_id = fcx.tcx.hir.node_to_hir_id(fn_id);
let gen_ty = if can_be_generator && body.is_generator {
let gen_sig = ty::GenSig {
yield_ty: fcx.yield_ty.unwrap(),
return_ty: ret_ty,
};
inherited.tables.borrow_mut().generator_sigs_mut().insert(fn_hir_id, Some(gen_sig));
let witness = fcx.next_ty_var(TypeVariableOrigin::MiscVariable(span));
fcx.deferred_generator_interiors.borrow_mut().push((body.id(), witness));
let interior = ty::GeneratorInterior::new(witness);
inherited.tables.borrow_mut().generator_interiors_mut().insert(fn_hir_id, interior);
Some(GeneratorTypes { yield_ty: gen_sig.yield_ty, interior: interior })
Some(GeneratorTypes { yield_ty: fcx.yield_ty.unwrap(), interior: interior })
} else {
inherited.tables.borrow_mut().generator_sigs_mut().insert(fn_hir_id, None);
None
};
inherited.tables.borrow_mut().liberated_fn_sigs_mut().insert(fn_hir_id, fn_sig);

View file

@ -46,7 +46,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
wbcx.visit_anon_types();
wbcx.visit_cast_types();
wbcx.visit_free_region_map();
wbcx.visit_generator_sigs();
wbcx.visit_generator_interiors();
let used_trait_imports = mem::replace(&mut self.tables.borrow_mut().used_trait_imports,
@ -391,21 +390,6 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
}
}
fn visit_generator_sigs(&mut self) {
let common_local_id_root = self.fcx.tables.borrow().local_id_root.unwrap();
for (&id, gen_sig) in self.fcx.tables.borrow().generator_sigs().iter() {
let hir_id = hir::HirId {
owner: common_local_id_root.index,
local_id: id,
};
let gen_sig = gen_sig.map(|s| ty::GenSig {
yield_ty: self.resolve(&s.yield_ty, &hir_id),
return_ty: self.resolve(&s.return_ty, &hir_id),
});
self.tables.generator_sigs_mut().insert(hir_id, gen_sig);
}
}
fn visit_liberated_fn_sigs(&mut self) {
let fcx_tables = self.fcx.tables.borrow();
debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root);