Skip to content

Commit 5e04c66

Browse files
committed
remove the generator_sigs map, query, and plumbing
1 parent 7010d8c commit 5e04c66

File tree

13 files changed

+24
-171
lines changed

13 files changed

+24
-171
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 106 deletions
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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,19 +1501,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
15011501
self.tcx.fn_sig(def_id)
15021502
}
15031503

1504-
pub fn generator_sig(&self, def_id: DefId) -> Option<ty::PolyGenSig<'tcx>> {
1505-
if let Some(tables) = self.in_progress_tables {
1506-
if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
1507-
let hir_id = self.tcx.hir.node_to_hir_id(id);
1508-
if let Some(&ty) = tables.borrow().generator_sigs().get(hir_id) {
1509-
return ty.map(|t| ty::Binder(t));
1510-
}
1511-
}
1512-
}
1513-
1514-
self.tcx.generator_sig(def_id)
1515-
}
1516-
15171504
/// Normalizes associated types in `value`, potentially returning
15181505
/// new obligations that must further be processed.
15191506
pub fn partially_normalize_associated_types_in<T>(&self,

src/librustc/traits/project.rs

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 0 additions & 4 deletions
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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,6 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
783783
DepKind::ImplTraitRef => { force!(impl_trait_ref, def_id!()); }
784784
DepKind::ImplPolarity => { force!(impl_polarity, def_id!()); }
785785
DepKind::FnSignature => { force!(fn_sig, def_id!()); }
786-
DepKind::GenSignature => { force!(generator_sig, def_id!()); }
787786
DepKind::CoerceUnsizedInfo => { force!(coerce_unsized_info, def_id!()); }
788787
DepKind::ItemVariances => { force!(variances_of, def_id!()); }
789788
DepKind::IsConstFn => { force!(is_const_fn, def_id!()); }

src/librustc_metadata/cstore_impl.rs

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,23 +1036,6 @@ impl<'a, 'tcx> CrateMetadata {
10361036
sig.decode((self, tcx))
10371037
}
10381038

1039-
fn get_generator_data(&self,
1040-
id: DefIndex,
1041-
tcx: TyCtxt<'a, 'tcx, 'tcx>)
1042-
-> Option<GeneratorData<'tcx>> {
1043-
match self.entry(id).kind {
1044-
EntryKind::Generator(data) => Some(data.decode((self, tcx))),
1045-
_ => None,
1046-
}
1047-
}
1048-
1049-
pub fn generator_sig(&self,
1050-
id: DefIndex,
1051-
tcx: TyCtxt<'a, 'tcx, 'tcx>)
1052-
-> Option<ty::PolyGenSig<'tcx>> {
1053-
self.get_generator_data(id, tcx).map(|d| d.sig)
1054-
}
1055-
10561039
#[inline]
10571040
pub fn def_key(&self, index: DefIndex) -> DefKey {
10581041
self.def_path_table.def_key(index)

src/librustc_metadata/encoder.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,18 +1205,25 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
12051205
debug!("IsolatedEncoder::encode_info_for_closure({:?})", def_id);
12061206
let tcx = self.tcx;
12071207

1208-
let kind = if let Some(sig) = self.tcx.generator_sig(def_id) {
1209-
let layout = self.tcx.generator_layout(def_id);
1210-
let data = GeneratorData {
1211-
sig,
1212-
layout: layout.clone(),
1213-
};
1214-
EntryKind::Generator(self.lazy(&data))
1215-
} else {
1216-
let data = ClosureData {
1217-
sig: self.lazy(&tcx.fn_sig(def_id)),
1218-
};
1219-
EntryKind::Closure(self.lazy(&data))
1208+
let tables = self.tcx.typeck_tables_of(def_id);
1209+
let node_id = self.tcx.hir.as_local_node_id(def_id).unwrap();
1210+
let hir_id = self.tcx.hir.node_to_hir_id(node_id);
1211+
let kind = match tables.node_id_to_type(hir_id).sty {
1212+
ty::TyGenerator(def_id, ..) => {
1213+
let layout = self.tcx.generator_layout(def_id);
1214+
let data = GeneratorData {
1215+
layout: layout.clone(),
1216+
};
1217+
EntryKind::Generator(self.lazy(&data))
1218+
}
1219+
1220+
ty::TyClosure(def_id, substs) => {
1221+
let sig = substs.closure_sig(def_id, self.tcx);
1222+
let data = ClosureData { sig: self.lazy(&sig) };
1223+
EntryKind::Closure(self.lazy(&data))
1224+
}
1225+
1226+
_ => bug!("closure that is neither generator nor closure")
12201227
};
12211228

12221229
Entry {

0 commit comments

Comments
 (0)