Skip to content

Commit f32c578

Browse files
committed
remove the generator_sigs map, query, and plumbing
1 parent f7bba79 commit f32c578

File tree

13 files changed

+24
-171
lines changed

13 files changed

+24
-171
lines changed

src/librustc/dep_graph/dep_node.rs

-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,6 @@ define_dep_nodes!( <'tcx>
499499
[] ImplTraitRef(DefId),
500500
[] ImplPolarity(DefId),
501501
[] FnSignature(DefId),
502-
[] GenSignature(DefId),
503502
[] CoerceUnsizedInfo(DefId),
504503

505504
[] ItemVarianceConstraints(DefId),

src/librustc/infer/freshen.rs

+1-106
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@
4343
4444
use ty::{self, Ty, TyCtxt, TypeFoldable};
4545
use ty::fold::TypeFolder;
46-
use ty::subst::Substs;
4746
use util::nodemap::FxHashMap;
48-
use hir::def_id::DefId;
4947

5048
use std::collections::hash_map::Entry;
5149

@@ -56,7 +54,6 @@ pub struct TypeFreshener<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
5654
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
5755
freshen_count: u32,
5856
freshen_map: FxHashMap<ty::InferTy, Ty<'tcx>>,
59-
closure_set: Vec<DefId>,
6057
}
6158

6259
impl<'a, 'gcx, 'tcx> TypeFreshener<'a, 'gcx, 'tcx> {
@@ -66,7 +63,6 @@ impl<'a, 'gcx, 'tcx> TypeFreshener<'a, 'gcx, 'tcx> {
6663
infcx,
6764
freshen_count: 0,
6865
freshen_map: FxHashMap(),
69-
closure_set: vec![],
7066
}
7167
}
7268

@@ -92,88 +88,6 @@ impl<'a, 'gcx, 'tcx> TypeFreshener<'a, 'gcx, 'tcx> {
9288
}
9389
}
9490
}
95-
96-
fn next_fresh<F>(&mut self,
97-
freshener: F)
98-
-> Ty<'tcx>
99-
where F: FnOnce(u32) -> ty::InferTy,
100-
{
101-
let index = self.freshen_count;
102-
self.freshen_count += 1;
103-
self.infcx.tcx.mk_infer(freshener(index))
104-
}
105-
106-
fn freshen_generator_like<M, C>(&mut self,
107-
def_id: DefId,
108-
substs: ty::ClosureSubsts<'tcx>,
109-
t: Ty<'tcx>,
110-
markers: M,
111-
combine: C)
112-
-> Ty<'tcx>
113-
where M: FnOnce(&mut Self) -> (Ty<'tcx>, Ty<'tcx>),
114-
C: FnOnce(&'tcx Substs<'tcx>) -> Ty<'tcx>
115-
{
116-
let tcx = self.infcx.tcx;
117-
118-
let closure_in_progress = self.infcx.in_progress_tables.map_or(false, |tables| {
119-
tcx.hir.as_local_node_id(def_id).map_or(false, |closure_id| {
120-
tables.borrow().local_id_root ==
121-
Some(DefId::local(tcx.hir.node_to_hir_id(closure_id).owner))
122-
})
123-
});
124-
125-
if !closure_in_progress {
126-
// If this closure belongs to another infcx, its kind etc. were
127-
// fully inferred and its signature/kind are exactly what's listed
128-
// in its infcx. So we don't need to add the markers for them.
129-
return t.super_fold_with(self);
130-
}
131-
132-
// We are encoding a closure in progress. Because we want our freshening
133-
// key to contain all inference information needed to make sense of our
134-
// value, we need to encode the closure signature and kind. The way
135-
// we do that is to add them as 2 variables to the closure substs,
136-
// basically because it's there (and nobody cares about adding extra stuff
137-
// to substs).
138-
//
139-
// This means the "freshened" closure substs ends up looking like
140-
// fresh_substs = [PARENT_SUBSTS* ; UPVARS* ; SIG_MARKER ; KIND_MARKER]
141-
let (marker_1, marker_2) = if self.closure_set.contains(&def_id) {
142-
// We found the closure def-id within its own signature. Just
143-
// leave a new freshened type - any matching operations would
144-
// have found and compared the exterior closure already to
145-
// get here.
146-
//
147-
// In that case, we already know what the signature would
148-
// be - the parent closure on the stack already contains a
149-
// "copy" of the signature, so there is no reason to encode
150-
// it again for injectivity. Just use a fresh type variable
151-
// to make everything comparable.
152-
//
153-
// For example (closure kinds omitted for clarity)
154-
// t=[closure FOO sig=[closure BAR sig=[closure FOO ..]]]
155-
// Would get encoded to
156-
// t=[closure FOO sig=[closure BAR sig=[closure FOO sig=$0]]]
157-
//
158-
// and we can decode by having
159-
// $0=[closure BAR {sig doesn't exist in decode}]
160-
// and get
161-
// t=[closure FOO]
162-
// sig[FOO] = [closure BAR]
163-
// sig[BAR] = [closure FOO]
164-
(self.next_fresh(ty::FreshTy), self.next_fresh(ty::FreshTy))
165-
} else {
166-
self.closure_set.push(def_id);
167-
let markers = markers(self);
168-
self.closure_set.pop();
169-
markers
170-
};
171-
172-
combine(tcx.mk_substs(
173-
substs.substs.iter().map(|k| k.fold_with(self)).chain(
174-
[marker_1, marker_2].iter().cloned().map(From::from)
175-
)))
176-
}
17791
}
17892

17993
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> {
249163
t
250164
}
251165

252-
ty::TyGenerator(def_id, substs, interior) => {
253-
self.freshen_generator_like(
254-
def_id, substs, t,
255-
|this| {
256-
let gen_sig = this.infcx.generator_sig(def_id).unwrap();
257-
// FIXME: want to revise this strategy when generator
258-
// signatures can actually contain LBRs.
259-
let sig = this.tcx().no_late_bound_regions(&gen_sig)
260-
.unwrap_or_else(|| {
261-
bug!("late-bound regions in signature of {:?}",
262-
def_id)
263-
});
264-
(sig.yield_ty, sig.return_ty).fold_with(this)
265-
},
266-
|substs| {
267-
tcx.mk_generator(def_id, ty::ClosureSubsts { substs }, interior)
268-
}
269-
)
270-
}
271-
166+
ty::TyGenerator(..) |
272167
ty::TyBool |
273168
ty::TyChar |
274169
ty::TyInt(..) |

src/librustc/infer/mod.rs

-13
Original file line numberDiff line numberDiff line change
@@ -1375,19 +1375,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13751375

13761376
self.tcx.fn_sig(def_id)
13771377
}
1378-
1379-
pub fn generator_sig(&self, def_id: DefId) -> Option<ty::PolyGenSig<'tcx>> {
1380-
if let Some(tables) = self.in_progress_tables {
1381-
if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
1382-
let hir_id = self.tcx.hir.node_to_hir_id(id);
1383-
if let Some(&ty) = tables.borrow().generator_sigs().get(hir_id) {
1384-
return ty.map(|t| ty::Binder(t));
1385-
}
1386-
}
1387-
}
1388-
1389-
self.tcx.generator_sig(def_id)
1390-
}
13911378
}
13921379

13931380
impl<'a, 'gcx, 'tcx> TypeTrace<'tcx> {

src/librustc/traits/project.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1264,8 +1264,7 @@ fn confirm_generator_candidate<'cx, 'gcx, 'tcx>(
12641264
vtable: VtableGeneratorData<'tcx, PredicateObligation<'tcx>>)
12651265
-> Progress<'tcx>
12661266
{
1267-
let gen_sig = selcx.infcx().generator_sig(vtable.closure_def_id).unwrap()
1268-
.subst(selcx.tcx(), vtable.substs.substs);
1267+
let gen_sig = vtable.substs.generator_poly_sig(vtable.closure_def_id, selcx.tcx());
12691268
let Normalized {
12701269
value: gen_sig,
12711270
obligations

src/librustc/traits/select.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3184,8 +3184,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
31843184
substs: ty::ClosureSubsts<'tcx>)
31853185
-> ty::PolyTraitRef<'tcx>
31863186
{
3187-
let gen_sig = self.infcx.generator_sig(closure_def_id).unwrap()
3188-
.subst(self.tcx(), substs.substs);
3187+
let gen_sig = substs.generator_poly_sig(closure_def_id, self.tcx());
31893188
let ty::Binder((trait_ref, ..)) =
31903189
self.tcx().generator_trait_ref_and_outputs(obligation.predicate.def_id(),
31913190
obligation.predicate.0.self_ty(), // (1)

src/librustc/ty/maps/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,6 @@ define_maps! { <'tcx>
173173
/// The signature of functions and closures.
174174
[] fn fn_sig: FnSignature(DefId) -> ty::PolyFnSig<'tcx>,
175175

176-
/// Records the signature of each generator. The def ID is the ID of the
177-
/// expression defining the closure.
178-
[] fn generator_sig: GenSignature(DefId) -> Option<ty::PolyGenSig<'tcx>>,
179-
180176
/// Caches CoerceUnsized kinds for impls on custom types.
181177
[] fn coerce_unsized_info: CoerceUnsizedInfo(DefId)
182178
-> ty::adjustment::CoerceUnsizedInfo,

src/librustc/ty/maps/plumbing.rs

-1
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,6 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
763763
DepKind::ImplTraitRef => { force!(impl_trait_ref, def_id!()); }
764764
DepKind::ImplPolarity => { force!(impl_polarity, def_id!()); }
765765
DepKind::FnSignature => { force!(fn_sig, def_id!()); }
766-
DepKind::GenSignature => { force!(generator_sig, def_id!()); }
767766
DepKind::CoerceUnsizedInfo => { force!(coerce_unsized_info, def_id!()); }
768767
DepKind::ItemVariances => { force!(variances_of, def_id!()); }
769768
DepKind::IsConstFn => { force!(is_const_fn, def_id!()); }

src/librustc_metadata/cstore_impl.rs

-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
136136

137137
mir
138138
}
139-
generator_sig => { cdata.generator_sig(def_id.index, tcx) }
140139
mir_const_qualif => {
141140
(cdata.mir_const_qualif(def_id.index), Rc::new(IdxSetBuf::new_empty(0)))
142141
}

src/librustc_metadata/decoder.rs

-17
Original file line numberDiff line numberDiff line change
@@ -1124,23 +1124,6 @@ impl<'a, 'tcx> CrateMetadata {
11241124
sig.decode((self, tcx))
11251125
}
11261126

1127-
fn get_generator_data(&self,
1128-
id: DefIndex,
1129-
tcx: TyCtxt<'a, 'tcx, 'tcx>)
1130-
-> Option<GeneratorData<'tcx>> {
1131-
match self.entry(id).kind {
1132-
EntryKind::Generator(data) => Some(data.decode((self, tcx))),
1133-
_ => None,
1134-
}
1135-
}
1136-
1137-
pub fn generator_sig(&self,
1138-
id: DefIndex,
1139-
tcx: TyCtxt<'a, 'tcx, 'tcx>)
1140-
-> Option<ty::PolyGenSig<'tcx>> {
1141-
self.get_generator_data(id, tcx).map(|d| d.sig)
1142-
}
1143-
11441127
#[inline]
11451128
pub fn def_key(&self, index: DefIndex) -> DefKey {
11461129
self.def_path_table.def_key(index)

src/librustc_metadata/encoder.rs

+19-12
Original file line numberDiff line numberDiff line change
@@ -1178,18 +1178,25 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
11781178
debug!("IsolatedEncoder::encode_info_for_closure({:?})", def_id);
11791179
let tcx = self.tcx;
11801180

1181-
let kind = if let Some(sig) = self.tcx.generator_sig(def_id) {
1182-
let layout = self.tcx.generator_layout(def_id);
1183-
let data = GeneratorData {
1184-
sig,
1185-
layout: layout.clone(),
1186-
};
1187-
EntryKind::Generator(self.lazy(&data))
1188-
} else {
1189-
let data = ClosureData {
1190-
sig: self.lazy(&tcx.fn_sig(def_id)),
1191-
};
1192-
EntryKind::Closure(self.lazy(&data))
1181+
let tables = self.tcx.typeck_tables_of(def_id);
1182+
let node_id = self.tcx.hir.as_local_node_id(def_id).unwrap();
1183+
let hir_id = self.tcx.hir.node_to_hir_id(node_id);
1184+
let kind = match tables.node_id_to_type(hir_id).sty {
1185+
ty::TyGenerator(def_id, ..) => {
1186+
let layout = self.tcx.generator_layout(def_id);
1187+
let data = GeneratorData {
1188+
layout: layout.clone(),
1189+
};
1190+
EntryKind::Generator(self.lazy(&data))
1191+
}
1192+
1193+
ty::TyClosure(def_id, substs) => {
1194+
let sig = substs.closure_sig(def_id, self.tcx);
1195+
let data = ClosureData { sig: self.lazy(&sig) };
1196+
EntryKind::Closure(self.lazy(&data))
1197+
}
1198+
1199+
_ => bug!("closure that is neither generator nor closure")
11931200
};
11941201

11951202
Entry {

src/librustc_metadata/schema.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,6 @@ impl_stable_hash_for!(struct ClosureData<'tcx> { sig });
518518

519519
#[derive(RustcEncodable, RustcDecodable)]
520520
pub struct GeneratorData<'tcx> {
521-
pub sig: ty::PolyGenSig<'tcx>,
522521
pub layout: mir::GeneratorLayout<'tcx>,
523522
}
524-
impl_stable_hash_for!(struct GeneratorData<'tcx> { sig, layout });
523+
impl_stable_hash_for!(struct GeneratorData<'tcx> { layout });

src/librustc_trans/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ pub fn ty_fn_sig<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
527527
}
528528
ty::TyGenerator(def_id, substs, _) => {
529529
let tcx = ccx.tcx();
530-
let sig = tcx.generator_sig(def_id).unwrap().subst(tcx, substs.substs);
530+
let sig = substs.generator_poly_sig(def_id, ccx.tcx());
531531

532532
let env_region = ty::ReLateBound(ty::DebruijnIndex::new(1), ty::BrEnv);
533533
let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty);

src/librustc_typeck/check/mod.rs

-9
Original file line numberDiff line numberDiff line change
@@ -740,21 +740,12 @@ pub fn provide(providers: &mut Providers) {
740740
typeck_item_bodies,
741741
typeck_tables_of,
742742
has_typeck_tables,
743-
generator_sig,
744743
adt_destructor,
745744
used_trait_imports,
746745
..*providers
747746
};
748747
}
749748

750-
fn generator_sig<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
751-
def_id: DefId)
752-
-> Option<ty::PolyGenSig<'tcx>> {
753-
let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
754-
let hir_id = tcx.hir.node_to_hir_id(node_id);
755-
tcx.typeck_tables_of(def_id).generator_sigs()[hir_id].map(|s| ty::Binder(s))
756-
}
757-
758749
fn adt_destructor<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
759750
def_id: DefId)
760751
-> Option<ty::Destructor> {

0 commit comments

Comments
 (0)