about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2017-11-09 15:44:29 -0500
committerNiko Matsakis <niko@alum.mit.edu>2017-11-18 07:47:38 -0500
commit5e04c66885729bb0c5d58e1e1624f89b129bf6dd (patch)
tree74076c8ece9c6ac1774b96d6e2244bc9851fb0f4
parent7010d8cf51d846acada6229528c729748cceea85 (diff)
downloadrust-5e04c66885729bb0c5d58e1e1624f89b129bf6dd.tar.gz
rust-5e04c66885729bb0c5d58e1e1624f89b129bf6dd.zip
remove the `generator_sigs` map, query, and plumbing
-rw-r--r--src/librustc/dep_graph/dep_node.rs1
-rw-r--r--src/librustc/infer/freshen.rs107
-rw-r--r--src/librustc/infer/mod.rs13
-rw-r--r--src/librustc/traits/project.rs3
-rw-r--r--src/librustc/traits/select.rs3
-rw-r--r--src/librustc/ty/maps/mod.rs4
-rw-r--r--src/librustc/ty/maps/plumbing.rs1
-rw-r--r--src/librustc_metadata/cstore_impl.rs1
-rw-r--r--src/librustc_metadata/decoder.rs17
-rw-r--r--src/librustc_metadata/encoder.rs31
-rw-r--r--src/librustc_metadata/schema.rs3
-rw-r--r--src/librustc_trans/common.rs2
-rw-r--r--src/librustc_typeck/check/mod.rs9
13 files changed, 24 insertions, 171 deletions
diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs
index b1a49b87acd..db3aa9a1efa 100644
--- a/src/librustc/dep_graph/dep_node.rs
+++ b/src/librustc/dep_graph/dep_node.rs
@@ -499,7 +499,6 @@ define_dep_nodes!( <'tcx>
     [] ImplTraitRef(DefId),
     [] ImplPolarity(DefId),
     [] FnSignature(DefId),
-    [] GenSignature(DefId),
     [] CoerceUnsizedInfo(DefId),
 
     [] ItemVarianceConstraints(DefId),
diff --git a/src/librustc/infer/freshen.rs b/src/librustc/infer/freshen.rs
index b1ee6d7a298..426c61e9ac0 100644
--- a/src/librustc/infer/freshen.rs
+++ b/src/librustc/infer/freshen.rs
@@ -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(..) |
diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs
index 05f1184fad3..ca95d4fd291 100644
--- a/src/librustc/infer/mod.rs
+++ b/src/librustc/infer/mod.rs
@@ -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,
diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs
index 9c56df058c3..0cc755dc427 100644
--- a/src/librustc/traits/project.rs
+++ b/src/librustc/traits/project.rs
@@ -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
diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs
index fba894d528e..4bc3e2dd4d8 100644
--- a/src/librustc/traits/select.rs
+++ b/src/librustc/traits/select.rs
@@ -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)
diff --git a/src/librustc/ty/maps/mod.rs b/src/librustc/ty/maps/mod.rs
index c27bc63ff8e..228503b1a3f 100644
--- a/src/librustc/ty/maps/mod.rs
+++ b/src/librustc/ty/maps/mod.rs
@@ -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,
diff --git a/src/librustc/ty/maps/plumbing.rs b/src/librustc/ty/maps/plumbing.rs
index 617712b87cf..739537c7c3a 100644
--- a/src/librustc/ty/maps/plumbing.rs
+++ b/src/librustc/ty/maps/plumbing.rs
@@ -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!()); }
diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs
index d18816262c0..1f671adf4f8 100644
--- a/src/librustc_metadata/cstore_impl.rs
+++ b/src/librustc_metadata/cstore_impl.rs
@@ -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)))
     }
diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs
index 349b1cd8828..633806d5ef5 100644
--- a/src/librustc_metadata/decoder.rs
+++ b/src/librustc_metadata/decoder.rs
@@ -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)
diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs
index 6228eb0f386..80b68022fe2 100644
--- a/src/librustc_metadata/encoder.rs
+++ b/src/librustc_metadata/encoder.rs
@@ -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 {
diff --git a/src/librustc_metadata/schema.rs b/src/librustc_metadata/schema.rs
index 0593c3d8c0d..8ff32746391 100644
--- a/src/librustc_metadata/schema.rs
+++ b/src/librustc_metadata/schema.rs
@@ -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 });
diff --git a/src/librustc_trans/common.rs b/src/librustc_trans/common.rs
index 7309b05d5a0..07bbd9b8c3d 100644
--- a/src/librustc_trans/common.rs
+++ b/src/librustc_trans/common.rs
@@ -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);
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 91283ab7a2f..fe1d81a1231 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -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> {