]> git.lizzy.rs Git - rust.git/commitdiff
Integrate generators to universal region setup
authorSantiago Pastorino <spastorino@gmail.com>
Fri, 19 Jan 2018 22:18:02 +0000 (19:18 -0300)
committerNiko Matsakis <niko@alum.mit.edu>
Sat, 20 Jan 2018 02:32:43 +0000 (21:32 -0500)
src/librustc/mir/visit.rs
src/librustc_mir/borrow_check/nll/constraint_generation.rs
src/librustc_mir/borrow_check/nll/type_check/input_output.rs
src/librustc_mir/borrow_check/nll/universal_regions.rs

index 58067931d562eed2e8d157012a001c06db8db556..57ed41f2f06e63c7ef6968409e55754ef44f3dbc 100644 (file)
@@ -277,6 +277,13 @@ fn visit_visibility_scope(&mut self,
 
             fn super_mir(&mut self,
                          mir: & $($mutability)* Mir<'tcx>) {
+                if let Some(yield_ty) = &$($mutability)* mir.yield_ty {
+                    self.visit_ty(yield_ty, TyContext::YieldTy(SourceInfo {
+                        span: mir.span,
+                        scope: ARGUMENT_VISIBILITY_SCOPE,
+                    }));
+                }
+
                 // for best performance, we want to use an iterator rather
                 // than a for-loop, to avoid calling Mir::invalidate for
                 // each basic block.
@@ -852,6 +859,8 @@ pub enum TyContext {
     /// The return type of the function.
     ReturnTy(SourceInfo),
 
+    YieldTy(SourceInfo),
+
     /// A type found at some location.
     Location(Location),
 }
index 7ca4ebd1cb29660dd60576d21669f5976a06da05..3a39eb5c908de3660efe06d05d7a7da6e2d4d9a1 100644 (file)
@@ -69,6 +69,7 @@ fn visit_region(&mut self, region: &ty::Region<'tcx>, location: Location) {
     fn visit_ty(&mut self, ty: &ty::Ty<'tcx>, ty_context: TyContext) {
         match ty_context {
             TyContext::ReturnTy(source_info) |
+            TyContext::YieldTy(source_info) |
             TyContext::LocalDecl { source_info, .. } => {
                 span_bug!(source_info.span,
                           "should not be visiting outside of the CFG: {:?}",
index 9e88a632f5c3dc833d10733bfe4858c2b7fee395..b1aeae0b76bb112b48234a286e1909d050db9dd9 100644 (file)
@@ -60,6 +60,15 @@ pub(super) fn equate_inputs_and_outputs(
             self.equate_normalized_input_or_output(start_position, input_ty, mir_input_ty);
         }
 
+        assert!(
+            mir.yield_ty.is_some() && universal_regions.yield_ty.is_some() ||
+            mir.yield_ty.is_none() && universal_regions.yield_ty.is_none()
+            );
+        if let Some(mir_yield_ty) = mir.yield_ty {
+            let ur_yield_ty = universal_regions.yield_ty.unwrap();
+            self.equate_normalized_input_or_output(start_position, ur_yield_ty, mir_yield_ty);
+        }
+
         // Return types are a bit more complex. They may contain existential `impl Trait`
         // types.
         debug!(
index 0e329266ea111db58922d22b9ddd1f3be0515032..e426457a3493d8564dd85c7bb3ad979a24d23fab 100644 (file)
@@ -96,6 +96,8 @@ pub struct UniversalRegions<'tcx> {
     /// our special inference variable there, we would mess that up.
     pub region_bound_pairs: Vec<(ty::Region<'tcx>, GenericKind<'tcx>)>,
 
+    pub yield_ty: Option<Ty<'tcx>>,
+
     relations: UniversalRegionRelations,
 }
 
@@ -505,6 +507,13 @@ fn build(mut self) -> UniversalRegions<'tcx> {
             num_universals
         );
 
+        let yield_ty = match defining_ty {
+            DefiningTy::Generator(def_id, substs, _) => {
+                Some(substs.generator_yield_ty(def_id, self.infcx.tcx))
+            }
+            _ => None,
+        };
+
         UniversalRegions {
             indices,
             fr_static,
@@ -516,6 +525,7 @@ fn build(mut self) -> UniversalRegions<'tcx> {
             unnormalized_output_ty,
             unnormalized_input_tys,
             region_bound_pairs: self.region_bound_pairs,
+            yield_ty: yield_ty,
             relations: self.relations,
         }
     }