mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
remove the generator_sigs
map, query, and plumbing
This commit is contained in:
parent
7010d8cf51
commit
5e04c66885
@ -499,7 +499,6 @@ define_dep_nodes!( <'tcx>
|
||||
[] ImplTraitRef(DefId),
|
||||
[] ImplPolarity(DefId),
|
||||
[] FnSignature(DefId),
|
||||
[] GenSignature(DefId),
|
||||
[] CoerceUnsizedInfo(DefId),
|
||||
|
||||
[] ItemVarianceConstraints(DefId),
|
||||
|
@ -43,9 +43,7 @@
|
||||
|
||||
use ty::{self, Ty, TyCtxt, TypeFoldable};
|
||||
use ty::fold::TypeFolder;
|
||||
use ty::subst::Substs;
|
||||
use util::nodemap::FxHashMap;
|
||||
use hir::def_id::DefId;
|
||||
|
||||
use std::collections::hash_map::Entry;
|
||||
|
||||
@ -56,7 +54,6 @@ pub struct TypeFreshener<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
|
||||
freshen_count: u32,
|
||||
freshen_map: FxHashMap<ty::InferTy, Ty<'tcx>>,
|
||||
closure_set: Vec<DefId>,
|
||||
}
|
||||
|
||||
impl<'a, 'gcx, 'tcx> TypeFreshener<'a, 'gcx, 'tcx> {
|
||||
@ -66,7 +63,6 @@ impl<'a, 'gcx, 'tcx> TypeFreshener<'a, 'gcx, 'tcx> {
|
||||
infcx,
|
||||
freshen_count: 0,
|
||||
freshen_map: FxHashMap(),
|
||||
closure_set: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,88 +88,6 @@ impl<'a, 'gcx, 'tcx> TypeFreshener<'a, 'gcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn next_fresh<F>(&mut self,
|
||||
freshener: F)
|
||||
-> Ty<'tcx>
|
||||
where F: FnOnce(u32) -> ty::InferTy,
|
||||
{
|
||||
let index = self.freshen_count;
|
||||
self.freshen_count += 1;
|
||||
self.infcx.tcx.mk_infer(freshener(index))
|
||||
}
|
||||
|
||||
fn freshen_generator_like<M, C>(&mut self,
|
||||
def_id: DefId,
|
||||
substs: ty::ClosureSubsts<'tcx>,
|
||||
t: Ty<'tcx>,
|
||||
markers: M,
|
||||
combine: C)
|
||||
-> Ty<'tcx>
|
||||
where M: FnOnce(&mut Self) -> (Ty<'tcx>, Ty<'tcx>),
|
||||
C: FnOnce(&'tcx Substs<'tcx>) -> Ty<'tcx>
|
||||
{
|
||||
let tcx = self.infcx.tcx;
|
||||
|
||||
let closure_in_progress = self.infcx.in_progress_tables.map_or(false, |tables| {
|
||||
tcx.hir.as_local_node_id(def_id).map_or(false, |closure_id| {
|
||||
tables.borrow().local_id_root ==
|
||||
Some(DefId::local(tcx.hir.node_to_hir_id(closure_id).owner))
|
||||
})
|
||||
});
|
||||
|
||||
if !closure_in_progress {
|
||||
// If this closure belongs to another infcx, its kind etc. were
|
||||
// fully inferred and its signature/kind are exactly what's listed
|
||||
// in its infcx. So we don't need to add the markers for them.
|
||||
return t.super_fold_with(self);
|
||||
}
|
||||
|
||||
// We are encoding a closure in progress. Because we want our freshening
|
||||
// key to contain all inference information needed to make sense of our
|
||||
// value, we need to encode the closure signature and kind. The way
|
||||
// we do that is to add them as 2 variables to the closure substs,
|
||||
// basically because it's there (and nobody cares about adding extra stuff
|
||||
// to substs).
|
||||
//
|
||||
// This means the "freshened" closure substs ends up looking like
|
||||
// fresh_substs = [PARENT_SUBSTS* ; UPVARS* ; SIG_MARKER ; KIND_MARKER]
|
||||
let (marker_1, marker_2) = if self.closure_set.contains(&def_id) {
|
||||
// We found the closure def-id within its own signature. Just
|
||||
// leave a new freshened type - any matching operations would
|
||||
// have found and compared the exterior closure already to
|
||||
// get here.
|
||||
//
|
||||
// In that case, we already know what the signature would
|
||||
// be - the parent closure on the stack already contains a
|
||||
// "copy" of the signature, so there is no reason to encode
|
||||
// it again for injectivity. Just use a fresh type variable
|
||||
// to make everything comparable.
|
||||
//
|
||||
// For example (closure kinds omitted for clarity)
|
||||
// t=[closure FOO sig=[closure BAR sig=[closure FOO ..]]]
|
||||
// Would get encoded to
|
||||
// t=[closure FOO sig=[closure BAR sig=[closure FOO sig=$0]]]
|
||||
//
|
||||
// and we can decode by having
|
||||
// $0=[closure BAR {sig doesn't exist in decode}]
|
||||
// and get
|
||||
// t=[closure FOO]
|
||||
// sig[FOO] = [closure BAR]
|
||||
// sig[BAR] = [closure FOO]
|
||||
(self.next_fresh(ty::FreshTy), self.next_fresh(ty::FreshTy))
|
||||
} else {
|
||||
self.closure_set.push(def_id);
|
||||
let markers = markers(self);
|
||||
self.closure_set.pop();
|
||||
markers
|
||||
};
|
||||
|
||||
combine(tcx.mk_substs(
|
||||
substs.substs.iter().map(|k| k.fold_with(self)).chain(
|
||||
[marker_1, marker_2].iter().cloned().map(From::from)
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
|
||||
@ -249,26 +163,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
|
||||
t
|
||||
}
|
||||
|
||||
ty::TyGenerator(def_id, substs, interior) => {
|
||||
self.freshen_generator_like(
|
||||
def_id, substs, t,
|
||||
|this| {
|
||||
let gen_sig = this.infcx.generator_sig(def_id).unwrap();
|
||||
// FIXME: want to revise this strategy when generator
|
||||
// signatures can actually contain LBRs.
|
||||
let sig = this.tcx().no_late_bound_regions(&gen_sig)
|
||||
.unwrap_or_else(|| {
|
||||
bug!("late-bound regions in signature of {:?}",
|
||||
def_id)
|
||||
});
|
||||
(sig.yield_ty, sig.return_ty).fold_with(this)
|
||||
},
|
||||
|substs| {
|
||||
tcx.mk_generator(def_id, ty::ClosureSubsts { substs }, interior)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
ty::TyGenerator(..) |
|
||||
ty::TyBool |
|
||||
ty::TyChar |
|
||||
ty::TyInt(..) |
|
||||
|
@ -1501,19 +1501,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
self.tcx.fn_sig(def_id)
|
||||
}
|
||||
|
||||
pub fn generator_sig(&self, def_id: DefId) -> Option<ty::PolyGenSig<'tcx>> {
|
||||
if let Some(tables) = self.in_progress_tables {
|
||||
if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
|
||||
let hir_id = self.tcx.hir.node_to_hir_id(id);
|
||||
if let Some(&ty) = tables.borrow().generator_sigs().get(hir_id) {
|
||||
return ty.map(|t| ty::Binder(t));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.tcx.generator_sig(def_id)
|
||||
}
|
||||
|
||||
/// Normalizes associated types in `value`, potentially returning
|
||||
/// new obligations that must further be processed.
|
||||
pub fn partially_normalize_associated_types_in<T>(&self,
|
||||
|
@ -1264,8 +1264,7 @@ fn confirm_generator_candidate<'cx, 'gcx, 'tcx>(
|
||||
vtable: VtableGeneratorData<'tcx, PredicateObligation<'tcx>>)
|
||||
-> Progress<'tcx>
|
||||
{
|
||||
let gen_sig = selcx.infcx().generator_sig(vtable.closure_def_id).unwrap()
|
||||
.subst(selcx.tcx(), vtable.substs.substs);
|
||||
let gen_sig = vtable.substs.generator_poly_sig(vtable.closure_def_id, selcx.tcx());
|
||||
let Normalized {
|
||||
value: gen_sig,
|
||||
obligations
|
||||
|
@ -3184,8 +3184,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
|
||||
substs: ty::ClosureSubsts<'tcx>)
|
||||
-> ty::PolyTraitRef<'tcx>
|
||||
{
|
||||
let gen_sig = self.infcx.generator_sig(closure_def_id).unwrap()
|
||||
.subst(self.tcx(), substs.substs);
|
||||
let gen_sig = substs.generator_poly_sig(closure_def_id, self.tcx());
|
||||
let ty::Binder((trait_ref, ..)) =
|
||||
self.tcx().generator_trait_ref_and_outputs(obligation.predicate.def_id(),
|
||||
obligation.predicate.0.self_ty(), // (1)
|
||||
|
@ -173,10 +173,6 @@ define_maps! { <'tcx>
|
||||
/// The signature of functions and closures.
|
||||
[] fn fn_sig: FnSignature(DefId) -> ty::PolyFnSig<'tcx>,
|
||||
|
||||
/// Records the signature of each generator. The def ID is the ID of the
|
||||
/// expression defining the closure.
|
||||
[] fn generator_sig: GenSignature(DefId) -> Option<ty::PolyGenSig<'tcx>>,
|
||||
|
||||
/// Caches CoerceUnsized kinds for impls on custom types.
|
||||
[] fn coerce_unsized_info: CoerceUnsizedInfo(DefId)
|
||||
-> ty::adjustment::CoerceUnsizedInfo,
|
||||
|
@ -783,7 +783,6 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
|
||||
DepKind::ImplTraitRef => { force!(impl_trait_ref, def_id!()); }
|
||||
DepKind::ImplPolarity => { force!(impl_polarity, def_id!()); }
|
||||
DepKind::FnSignature => { force!(fn_sig, def_id!()); }
|
||||
DepKind::GenSignature => { force!(generator_sig, def_id!()); }
|
||||
DepKind::CoerceUnsizedInfo => { force!(coerce_unsized_info, def_id!()); }
|
||||
DepKind::ItemVariances => { force!(variances_of, def_id!()); }
|
||||
DepKind::IsConstFn => { force!(is_const_fn, def_id!()); }
|
||||
|
@ -136,7 +136,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
|
||||
|
||||
mir
|
||||
}
|
||||
generator_sig => { cdata.generator_sig(def_id.index, tcx) }
|
||||
mir_const_qualif => {
|
||||
(cdata.mir_const_qualif(def_id.index), Rc::new(IdxSetBuf::new_empty(0)))
|
||||
}
|
||||
|
@ -1036,23 +1036,6 @@ impl<'a, 'tcx> CrateMetadata {
|
||||
sig.decode((self, tcx))
|
||||
}
|
||||
|
||||
fn get_generator_data(&self,
|
||||
id: DefIndex,
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>)
|
||||
-> Option<GeneratorData<'tcx>> {
|
||||
match self.entry(id).kind {
|
||||
EntryKind::Generator(data) => Some(data.decode((self, tcx))),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generator_sig(&self,
|
||||
id: DefIndex,
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>)
|
||||
-> Option<ty::PolyGenSig<'tcx>> {
|
||||
self.get_generator_data(id, tcx).map(|d| d.sig)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn def_key(&self, index: DefIndex) -> DefKey {
|
||||
self.def_path_table.def_key(index)
|
||||
|
@ -1205,18 +1205,25 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
|
||||
debug!("IsolatedEncoder::encode_info_for_closure({:?})", def_id);
|
||||
let tcx = self.tcx;
|
||||
|
||||
let kind = if let Some(sig) = self.tcx.generator_sig(def_id) {
|
||||
let layout = self.tcx.generator_layout(def_id);
|
||||
let data = GeneratorData {
|
||||
sig,
|
||||
layout: layout.clone(),
|
||||
};
|
||||
EntryKind::Generator(self.lazy(&data))
|
||||
} else {
|
||||
let data = ClosureData {
|
||||
sig: self.lazy(&tcx.fn_sig(def_id)),
|
||||
};
|
||||
EntryKind::Closure(self.lazy(&data))
|
||||
let tables = self.tcx.typeck_tables_of(def_id);
|
||||
let node_id = self.tcx.hir.as_local_node_id(def_id).unwrap();
|
||||
let hir_id = self.tcx.hir.node_to_hir_id(node_id);
|
||||
let kind = match tables.node_id_to_type(hir_id).sty {
|
||||
ty::TyGenerator(def_id, ..) => {
|
||||
let layout = self.tcx.generator_layout(def_id);
|
||||
let data = GeneratorData {
|
||||
layout: layout.clone(),
|
||||
};
|
||||
EntryKind::Generator(self.lazy(&data))
|
||||
}
|
||||
|
||||
ty::TyClosure(def_id, substs) => {
|
||||
let sig = substs.closure_sig(def_id, self.tcx);
|
||||
let data = ClosureData { sig: self.lazy(&sig) };
|
||||
EntryKind::Closure(self.lazy(&data))
|
||||
}
|
||||
|
||||
_ => bug!("closure that is neither generator nor closure")
|
||||
};
|
||||
|
||||
Entry {
|
||||
|
@ -518,7 +518,6 @@ impl_stable_hash_for!(struct ClosureData<'tcx> { sig });
|
||||
|
||||
#[derive(RustcEncodable, RustcDecodable)]
|
||||
pub struct GeneratorData<'tcx> {
|
||||
pub sig: ty::PolyGenSig<'tcx>,
|
||||
pub layout: mir::GeneratorLayout<'tcx>,
|
||||
}
|
||||
impl_stable_hash_for!(struct GeneratorData<'tcx> { sig, layout });
|
||||
impl_stable_hash_for!(struct GeneratorData<'tcx> { layout });
|
||||
|
@ -527,7 +527,7 @@ pub fn ty_fn_sig<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||
}
|
||||
ty::TyGenerator(def_id, substs, _) => {
|
||||
let tcx = ccx.tcx();
|
||||
let sig = tcx.generator_sig(def_id).unwrap().subst(tcx, substs.substs);
|
||||
let sig = substs.generator_poly_sig(def_id, ccx.tcx());
|
||||
|
||||
let env_region = ty::ReLateBound(ty::DebruijnIndex::new(1), ty::BrEnv);
|
||||
let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty);
|
||||
|
@ -722,21 +722,12 @@ pub fn provide(providers: &mut Providers) {
|
||||
typeck_item_bodies,
|
||||
typeck_tables_of,
|
||||
has_typeck_tables,
|
||||
generator_sig,
|
||||
adt_destructor,
|
||||
used_trait_imports,
|
||||
..*providers
|
||||
};
|
||||
}
|
||||
|
||||
fn generator_sig<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
def_id: DefId)
|
||||
-> Option<ty::PolyGenSig<'tcx>> {
|
||||
let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
|
||||
let hir_id = tcx.hir.node_to_hir_id(node_id);
|
||||
tcx.typeck_tables_of(def_id).generator_sigs()[hir_id].map(|s| ty::Binder(s))
|
||||
}
|
||||
|
||||
fn adt_destructor<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
def_id: DefId)
|
||||
-> Option<ty::Destructor> {
|
||||
|
Loading…
Reference in New Issue
Block a user