]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/borrow_check/nll/invalidation.rs
Changes the type `mir::Mir` into `mir::Body`
[rust.git] / src / librustc_mir / borrow_check / nll / invalidation.rs
index fd17d4a81256609a63dee51491597de3e5ca7e93..017f4d48c120050d2d833539a246913634e15933 100644 (file)
@@ -3,7 +3,6 @@
 use crate::borrow_check::{JustWrite, WriteAndRead};
 use crate::borrow_check::{AccessDepth, Deep, Shallow};
 use crate::borrow_check::{ReadOrWrite, Activation, Read, Reservation, Write};
-use crate::borrow_check::{Context, ContextKind};
 use crate::borrow_check::{LocalMutationIsAllowed, MutateMode};
 use crate::borrow_check::ArtificialField;
 use crate::borrow_check::{ReadKind, WriteKind};
@@ -12,7 +11,7 @@
 use crate::dataflow::indexes::BorrowIndex;
 use rustc::ty::TyCtxt;
 use rustc::mir::visit::Visitor;
-use rustc::mir::{BasicBlock, Location, Mir, Place, PlaceBase, Rvalue};
+use rustc::mir::{BasicBlock, Location, Body, Place, PlaceBase, Rvalue};
 use rustc::mir::{Statement, StatementKind};
 use rustc::mir::TerminatorKind;
 use rustc::mir::{Operand, BorrowKind};
@@ -22,7 +21,7 @@ pub(super) fn generate_invalidates<'cx, 'gcx, 'tcx>(
     tcx: TyCtxt<'cx, 'gcx, 'tcx>,
     all_facts: &mut Option<AllFacts>,
     location_table: &LocationTable,
-    mir: &Mir<'tcx>,
+    mir: &Body<'tcx>,
     borrow_set: &BorrowSet<'tcx>,
 ) {
     if all_facts.is_none() {
@@ -40,7 +39,7 @@ pub(super) fn generate_invalidates<'cx, 'gcx, 'tcx>(
             mir,
             dominators,
         };
-        ig.visit_mir(mir);
+        ig.visit_body(mir);
     }
 }
 
@@ -48,7 +47,7 @@ struct InvalidationGenerator<'cx, 'tcx: 'cx, 'gcx: 'tcx> {
     tcx: TyCtxt<'cx, 'gcx, 'tcx>,
     all_facts: &'cx mut AllFacts,
     location_table: &'cx LocationTable,
-    mir: &'cx Mir<'tcx>,
+    mir: &'cx Body<'tcx>,
     dominators: Dominators<BasicBlock>,
     borrow_set: &'cx BorrowSet<'tcx>,
 }
@@ -66,12 +65,12 @@ fn visit_statement(
         match statement.kind {
             StatementKind::Assign(ref lhs, ref rhs) => {
                 self.consume_rvalue(
-                    ContextKind::AssignRhs.new(location),
+                    location,
                     rhs,
                 );
 
                 self.mutate_place(
-                    ContextKind::AssignLhs.new(location),
+                    location,
                     lhs,
                     Shallow(None),
                     JustWrite
@@ -85,27 +84,26 @@ fn visit_statement(
                 variant_index: _,
             } => {
                 self.mutate_place(
-                    ContextKind::SetDiscrim.new(location),
+                    location,
                     place,
                     Shallow(None),
                     JustWrite,
                 );
             }
             StatementKind::InlineAsm(ref asm) => {
-                let context = ContextKind::InlineAsm.new(location);
                 for (o, output) in asm.asm.outputs.iter().zip(asm.outputs.iter()) {
                     if o.is_indirect {
                         // FIXME(eddyb) indirect inline asm outputs should
                         // be encoded through MIR place derefs instead.
                         self.access_place(
-                            context,
+                            location,
                             output,
                             (Deep, Read(ReadKind::Copy)),
                             LocalMutationIsAllowed::No,
                         );
                     } else {
                         self.mutate_place(
-                            context,
+                            location,
                             output,
                             if o.is_rw { Deep } else { Shallow(None) },
                             if o.is_rw { WriteAndRead } else { JustWrite },
@@ -113,7 +111,7 @@ fn visit_statement(
                     }
                 }
                 for (_, input) in asm.inputs.iter() {
-                    self.consume_operand(context, input);
+                    self.consume_operand(location, input);
                 }
             }
             StatementKind::Nop |
@@ -125,7 +123,7 @@ fn visit_statement(
             }
             StatementKind::StorageDead(local) => {
                 self.access_place(
-                    ContextKind::StorageDead.new(location),
+                    location,
                     &Place::Base(PlaceBase::Local(local)),
                     (Shallow(None), Write(WriteKind::StorageDeadOrDrop)),
                     LocalMutationIsAllowed::Yes,
@@ -150,7 +148,7 @@ fn visit_terminator_kind(
                 values: _,
                 targets: _,
             } => {
-                self.consume_operand(ContextKind::SwitchInt.new(location), discr);
+                self.consume_operand(location, discr);
             }
             TerminatorKind::Drop {
                 location: ref drop_place,
@@ -158,7 +156,7 @@ fn visit_terminator_kind(
                 unwind: _,
             } => {
                 self.access_place(
-                    ContextKind::Drop.new(location),
+                    location,
                     drop_place,
                     (AccessDepth::Drop, Write(WriteKind::StorageDeadOrDrop)),
                     LocalMutationIsAllowed::Yes,
@@ -171,13 +169,13 @@ fn visit_terminator_kind(
                 unwind: _,
             } => {
                 self.mutate_place(
-                    ContextKind::DropAndReplace.new(location),
+                    location,
                     drop_place,
                     Deep,
                     JustWrite,
                 );
                 self.consume_operand(
-                    ContextKind::DropAndReplace.new(location),
+                    location,
                     new_value,
                 );
             }
@@ -188,13 +186,13 @@ fn visit_terminator_kind(
                 cleanup: _,
                 from_hir_call: _,
             } => {
-                self.consume_operand(ContextKind::CallOperator.new(location), func);
+                self.consume_operand(location, func);
                 for arg in args {
-                    self.consume_operand(ContextKind::CallOperand.new(location), arg);
+                    self.consume_operand(location, arg);
                 }
                 if let Some((ref dest, _ /*bb*/)) = *destination {
                     self.mutate_place(
-                        ContextKind::CallDest.new(location),
+                        location,
                         dest,
                         Deep,
                         JustWrite,
@@ -208,11 +206,11 @@ fn visit_terminator_kind(
                 target: _,
                 cleanup: _,
             } => {
-                self.consume_operand(ContextKind::Assert.new(location), cond);
+                self.consume_operand(location, cond);
                 use rustc::mir::interpret::InterpError::BoundsCheck;
                 if let BoundsCheck { ref len, ref index } = *msg {
-                    self.consume_operand(ContextKind::Assert.new(location), len);
-                    self.consume_operand(ContextKind::Assert.new(location), index);
+                    self.consume_operand(location, len);
+                    self.consume_operand(location, index);
                 }
             }
             TerminatorKind::Yield {
@@ -220,7 +218,7 @@ fn visit_terminator_kind(
                 resume,
                 drop: _,
             } => {
-                self.consume_operand(ContextKind::Yield.new(location), value);
+                self.consume_operand(location, value);
 
                 // Invalidate all borrows of local places
                 let borrow_set = self.borrow_set.clone();
@@ -264,13 +262,13 @@ impl<'cg, 'cx, 'tcx, 'gcx> InvalidationGenerator<'cx, 'tcx, 'gcx> {
     /// Simulates mutation of a place.
     fn mutate_place(
         &mut self,
-        context: Context,
+        location: Location,
         place: &Place<'tcx>,
         kind: AccessDepth,
         _mode: MutateMode,
     ) {
         self.access_place(
-            context,
+            location,
             place,
             (kind, Write(WriteKind::Mutate)),
             LocalMutationIsAllowed::ExceptUpvars,
@@ -280,13 +278,13 @@ fn mutate_place(
     /// Simulates consumption of an operand.
     fn consume_operand(
         &mut self,
-        context: Context,
+        location: Location,
         operand: &Operand<'tcx>,
     ) {
         match *operand {
             Operand::Copy(ref place) => {
                 self.access_place(
-                    context,
+                    location,
                     place,
                     (Deep, Read(ReadKind::Copy)),
                     LocalMutationIsAllowed::No,
@@ -294,7 +292,7 @@ fn consume_operand(
             }
             Operand::Move(ref place) => {
                 self.access_place(
-                    context,
+                    location,
                     place,
                     (Deep, Write(WriteKind::Move)),
                     LocalMutationIsAllowed::Yes,
@@ -307,7 +305,7 @@ fn consume_operand(
     // Simulates consumption of an rvalue
     fn consume_rvalue(
         &mut self,
-        context: Context,
+        location: Location,
         rvalue: &Rvalue<'tcx>,
     ) {
         match *rvalue {
@@ -328,7 +326,7 @@ fn consume_rvalue(
                 };
 
                 self.access_place(
-                    context,
+                    location,
                     place,
                     access_kind,
                     LocalMutationIsAllowed::No,
@@ -339,7 +337,7 @@ fn consume_rvalue(
             | Rvalue::Repeat(ref operand, _)
             | Rvalue::UnaryOp(_ /*un_op*/, ref operand)
             | Rvalue::Cast(_ /*cast_kind*/, ref operand, _ /*ty*/) => {
-                self.consume_operand(context, operand)
+                self.consume_operand(location, operand)
             }
 
             Rvalue::Len(ref place) | Rvalue::Discriminant(ref place) => {
@@ -349,7 +347,7 @@ fn consume_rvalue(
                     _ => unreachable!(),
                 };
                 self.access_place(
-                    context,
+                    location,
                     place,
                     (Shallow(af), Read(ReadKind::Copy)),
                     LocalMutationIsAllowed::No,
@@ -358,8 +356,8 @@ fn consume_rvalue(
 
             Rvalue::BinaryOp(_bin_op, ref operand1, ref operand2)
             | Rvalue::CheckedBinaryOp(_bin_op, ref operand1, ref operand2) => {
-                self.consume_operand(context, operand1);
-                self.consume_operand(context, operand2);
+                self.consume_operand(location, operand1);
+                self.consume_operand(location, operand2);
             }
 
             Rvalue::NullaryOp(_op, _ty) => {
@@ -367,7 +365,7 @@ fn consume_rvalue(
 
             Rvalue::Aggregate(_, ref operands) => {
                 for operand in operands {
-                    self.consume_operand(context, operand);
+                    self.consume_operand(location, operand);
                 }
             }
         }
@@ -376,27 +374,27 @@ fn consume_rvalue(
     /// Simulates an access to a place.
     fn access_place(
         &mut self,
-        context: Context,
+        location: Location,
         place: &Place<'tcx>,
         kind: (AccessDepth, ReadOrWrite),
         _is_local_mutation_allowed: LocalMutationIsAllowed,
     ) {
         let (sd, rw) = kind;
         // note: not doing check_access_permissions checks because they don't generate invalidates
-        self.check_access_for_conflict(context, place, sd, rw);
+        self.check_access_for_conflict(location, place, sd, rw);
     }
 
     fn check_access_for_conflict(
         &mut self,
-        context: Context,
+        location: Location,
         place: &Place<'tcx>,
         sd: AccessDepth,
         rw: ReadOrWrite,
     ) {
         debug!(
-            "invalidation::check_access_for_conflict(context={:?}, place={:?}, sd={:?}, \
+            "invalidation::check_access_for_conflict(location={:?}, place={:?}, sd={:?}, \
              rw={:?})",
-            context,
+            location,
             place,
             sd,
             rw,
@@ -409,7 +407,7 @@ fn check_access_for_conflict(
             self,
             tcx,
             mir,
-            context,
+            location,
             (sd, place),
             &borrow_set.clone(),
             indices,
@@ -435,7 +433,7 @@ fn check_access_for_conflict(
 
                     (Read(_), BorrowKind::Unique) | (Read(_), BorrowKind::Mut { .. }) => {
                         // Reading from mere reservations of mutable-borrows is OK.
-                        if !is_active(&this.dominators, borrow, context.loc) {
+                        if !is_active(&this.dominators, borrow, location) {
                             // If the borrow isn't active yet, reads don't invalidate it
                             assert!(allow_two_phase_borrow(borrow.kind));
                             return Control::Continue;
@@ -443,7 +441,7 @@ fn check_access_for_conflict(
 
                         // Unique and mutable borrows are invalidated by reads from any
                         // involved path
-                        this.generate_invalidates(borrow_index, context.loc);
+                        this.generate_invalidates(borrow_index, location);
                     }
 
                     (Reservation(_), _)
@@ -453,7 +451,7 @@ fn check_access_for_conflict(
                         // Reservations count as writes since we need to check
                         // that activating the borrow will be OK
                         // FIXME(bob_twinkles) is this actually the right thing to do?
-                        this.generate_invalidates(borrow_index, context.loc);
+                        this.generate_invalidates(borrow_index, location);
                     }
                 }
                 Control::Continue
@@ -485,7 +483,7 @@ fn check_activations(
             });
 
             self.access_place(
-                ContextKind::Activation.new(location),
+                location,
                 &borrow.borrowed_place,
                 (
                     Deep,