about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-08-15 00:37:52 +0000
committerbors <bors@rust-lang.org>2018-08-15 00:37:52 +0000
commitfa23350a469b4c762d6fc1cb492092d954f678c8 (patch)
treead0d90efe98727a6586ff625abbf3dff336f170d
parent5bb2094d8934c420dbcc41875dc64eb9d82cbb6f (diff)
parent8592039b8c5ebe4d64533bb5138ddad784567225 (diff)
downloadrust-fa23350a469b4c762d6fc1cb492092d954f678c8.tar.gz
rust-fa23350a469b4c762d6fc1cb492092d954f678c8.zip
Auto merge of #52928 - Mark-Simulacrum:borrowck-cleanup, r=cramertj
(old) borrowck cleanup

Primarily moves dataflow code based on CFG to borrowck; this is mostly so we don't forget to delete it once it becomes unused after we fully move to MIR borrowck.
-rw-r--r--src/librustc/lib.rs1
-rw-r--r--src/librustc_borrowck/borrowck/check_loans.rs5
-rw-r--r--src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs8
-rw-r--r--src/librustc_borrowck/borrowck/gather_loans/lifetime.rs3
-rw-r--r--src/librustc_borrowck/borrowck/gather_loans/mod.rs14
-rw-r--r--src/librustc_borrowck/borrowck/mod.rs26
-rw-r--r--src/librustc_borrowck/borrowck/move_data.rs39
-rw-r--r--src/librustc_borrowck/dataflow.rs (renamed from src/librustc/middle/dataflow.rs)16
-rw-r--r--src/librustc_borrowck/graphviz.rs2
-rw-r--r--src/librustc_borrowck/lib.rs2
10 files changed, 31 insertions, 85 deletions
diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs
index e250b7549a0..b6f4bd6dc40 100644
--- a/src/librustc/lib.rs
+++ b/src/librustc/lib.rs
@@ -135,7 +135,6 @@ pub mod middle {
     pub mod borrowck;
     pub mod expr_use_visitor;
     pub mod cstore;
-    pub mod dataflow;
     pub mod dead;
     pub mod dependency_format;
     pub mod entry;
diff --git a/src/librustc_borrowck/borrowck/check_loans.rs b/src/librustc_borrowck/borrowck/check_loans.rs
index 49bd69f8262..709590f649b 100644
--- a/src/librustc_borrowck/borrowck/check_loans.rs
+++ b/src/librustc_borrowck/borrowck/check_loans.rs
@@ -91,7 +91,6 @@ struct CheckLoanCtxt<'a, 'tcx: 'a> {
     dfcx_loans: &'a LoanDataFlow<'a, 'tcx>,
     move_data: &'a move_data::FlowedMoveData<'a, 'tcx>,
     all_loans: &'a [Loan<'tcx>],
-    param_env: ty::ParamEnv<'tcx>,
     movable_generator: bool,
 }
 
@@ -215,7 +214,6 @@ pub fn check_loans<'a, 'b, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
         dfcx_loans,
         move_data,
         all_loans,
-        param_env,
         movable_generator,
     };
     let rvalue_promotable_map = bccx.tcx.rvalue_promotable_map(def_id);
@@ -801,8 +799,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
                 use_kind,
                 &lp,
                 the_move,
-                moved_lp,
-                self.param_env);
+                moved_lp);
             false
         });
     }
diff --git a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs
index 7ce6863a7c9..b76931c3017 100644
--- a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs
+++ b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs
@@ -163,15 +163,11 @@ pub fn gather_assignment<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
                                    move_data: &MoveData<'tcx>,
                                    assignment_id: hir::ItemLocalId,
                                    assignment_span: Span,
-                                   assignee_loan_path: Rc<LoanPath<'tcx>>,
-                                   assignee_id: hir::ItemLocalId,
-                                   mode: euv::MutateMode) {
+                                   assignee_loan_path: Rc<LoanPath<'tcx>>) {
     move_data.add_assignment(bccx.tcx,
                              assignee_loan_path,
                              assignment_id,
-                             assignment_span,
-                             assignee_id,
-                             mode);
+                             assignment_span);
 }
 
 // (keep in sync with move_error::report_cannot_move_out_of )
diff --git a/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs b/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs
index 323e0997e3e..c9dcc0d9fa2 100644
--- a/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs
+++ b/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs
@@ -28,8 +28,7 @@ pub fn guarantee_lifetime<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
                                     span: Span,
                                     cause: euv::LoanCause,
                                     cmt: &'a mc::cmt_<'tcx>,
-                                    loan_region: ty::Region<'tcx>,
-                                    _: ty::BorrowKind)
+                                    loan_region: ty::Region<'tcx>)
                                     -> Result<(),()> {
     //! Reports error if `loan_region` is larger than S
     //! where S is `item_scope` if `cmt` is an upvar,
diff --git a/src/librustc_borrowck/borrowck/gather_loans/mod.rs b/src/librustc_borrowck/borrowck/gather_loans/mod.rs
index d0881413871..6c83e2dd1c2 100644
--- a/src/librustc_borrowck/borrowck/gather_loans/mod.rs
+++ b/src/librustc_borrowck/borrowck/gather_loans/mod.rs
@@ -145,12 +145,11 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> {
               assignment_id: ast::NodeId,
               assignment_span: Span,
               assignee_cmt: &mc::cmt_<'tcx>,
-              mode: euv::MutateMode)
+              _: euv::MutateMode)
     {
         self.guarantee_assignment_valid(assignment_id,
                                         assignment_span,
-                                        assignee_cmt,
-                                        mode);
+                                        assignee_cmt);
     }
 
     fn decl_without_init(&mut self, id: ast::NodeId, _span: Span) {
@@ -246,8 +245,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
     fn guarantee_assignment_valid(&mut self,
                                   assignment_id: ast::NodeId,
                                   assignment_span: Span,
-                                  cmt: &mc::cmt_<'tcx>,
-                                  mode: euv::MutateMode) {
+                                  cmt: &mc::cmt_<'tcx>) {
 
         let opt_lp = opt_loan_path(cmt);
         debug!("guarantee_assignment_valid(assignment_id={}, cmt={:?}) opt_lp={:?}",
@@ -282,9 +280,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
                                                 self.bccx.tcx.hir.node_to_hir_id(assignment_id)
                                                     .local_id,
                                                 assignment_span,
-                                                lp,
-                                                cmt.hir_id.local_id,
-                                                mode);
+                                                lp);
             }
             None => {
                 // This can occur with e.g. `*foo() = 5`.  In such
@@ -320,7 +316,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
         // Check that the lifetime of the borrow does not exceed
         // the lifetime of the data being borrowed.
         if lifetime::guarantee_lifetime(self.bccx, self.item_ub,
-                                        borrow_span, cause, cmt, loan_region, req_kind).is_err() {
+                                        borrow_span, cause, cmt, loan_region).is_err() {
             return; // reported an error, no sense in reporting more.
         }
 
diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs
index a97fc666e25..098149c36ce 100644
--- a/src/librustc_borrowck/borrowck/mod.rs
+++ b/src/librustc_borrowck/borrowck/mod.rs
@@ -24,10 +24,6 @@ use rustc::hir::HirId;
 use rustc::hir::map as hir_map;
 use rustc::hir::map::blocks::FnLikeNode;
 use rustc::cfg;
-use rustc::middle::dataflow::DataFlowContext;
-use rustc::middle::dataflow::BitwiseOperator;
-use rustc::middle::dataflow::DataFlowOperator;
-use rustc::middle::dataflow::KillFrom;
 use rustc::middle::borrowck::{BorrowCheckResult, SignalledError};
 use rustc::hir::def_id::{DefId, LocalDefId};
 use rustc::middle::expr_use_visitor as euv;
@@ -54,6 +50,8 @@ use errors::{DiagnosticBuilder, DiagnosticId};
 use rustc::hir;
 use rustc::hir::intravisit::{self, Visitor};
 
+use dataflow::{DataFlowContext, BitwiseOperator, DataFlowOperator, KillFrom};
+
 pub mod check_loans;
 
 pub mod gather_loans;
@@ -640,8 +638,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
                                      use_kind: MovedValueUseKind,
                                      lp: &LoanPath<'tcx>,
                                      the_move: &move_data::Move,
-                                     moved_lp: &LoanPath<'tcx>,
-                                     _param_env: ty::ParamEnv<'tcx>) {
+                                     moved_lp: &LoanPath<'tcx>) {
         let (verb, verb_participle) = match use_kind {
             MovedInUse => ("use", "used"),
             MovedInCapture => ("capture", "captured"),
@@ -806,23 +803,6 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
         self.signal_error();
     }
 
-    pub fn struct_span_err_with_code<S: Into<MultiSpan>>(&self,
-                                                         s: S,
-                                                         msg: &str,
-                                                         code: DiagnosticId)
-                                                         -> DiagnosticBuilder<'a> {
-        self.tcx.sess.struct_span_err_with_code(s, msg, code)
-    }
-
-    pub fn span_err_with_code<S: Into<MultiSpan>>(
-        &self,
-        s: S,
-        msg: &str,
-        code: DiagnosticId,
-    ) {
-        self.tcx.sess.span_err_with_code(s, msg, code);
-    }
-
     fn report_bckerr(&self, err: &BckError<'a, 'tcx>) {
         let error_span = err.span.clone();
 
diff --git a/src/librustc_borrowck/borrowck/move_data.rs b/src/librustc_borrowck/borrowck/move_data.rs
index 4091ca046f4..979d71a0923 100644
--- a/src/librustc_borrowck/borrowck/move_data.rs
+++ b/src/librustc_borrowck/borrowck/move_data.rs
@@ -13,16 +13,12 @@
 
 pub use self::MoveKind::*;
 
+use dataflow::{DataFlowContext, BitwiseOperator, DataFlowOperator, KillFrom};
+
 use borrowck::*;
 use rustc::cfg;
-use rustc::middle::dataflow::DataFlowContext;
-use rustc::middle::dataflow::BitwiseOperator;
-use rustc::middle::dataflow::DataFlowOperator;
-use rustc::middle::dataflow::KillFrom;
-use rustc::middle::expr_use_visitor as euv;
-use rustc::middle::expr_use_visitor::MutateMode;
 use rustc::ty::{self, TyCtxt};
-use rustc::util::nodemap::{FxHashMap, FxHashSet};
+use rustc::util::nodemap::FxHashMap;
 
 use std::cell::RefCell;
 use std::rc::Rc;
@@ -51,9 +47,6 @@ pub struct MoveData<'tcx> {
     /// assigned dataflow bits, but we track them because they still
     /// kill move bits.
     pub path_assignments: RefCell<Vec<Assignment>>,
-
-    /// Assignments to a variable or path, like `x = foo`, but not `x += foo`.
-    pub assignee_ids: RefCell<FxHashSet<hir::ItemLocalId>>,
 }
 
 pub struct FlowedMoveData<'a, 'tcx: 'a> {
@@ -151,9 +144,6 @@ pub struct Assignment {
 
     /// span of node where assignment occurs
     pub span: Span,
-
-    /// id for place expression on lhs of assignment
-    pub assignee_id: hir::ItemLocalId,
 }
 
 #[derive(Clone, Copy)]
@@ -388,9 +378,7 @@ impl<'a, 'tcx> MoveData<'tcx> {
     pub fn add_assignment(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
                           lp: Rc<LoanPath<'tcx>>,
                           assign_id: hir::ItemLocalId,
-                          span: Span,
-                          assignee_id: hir::ItemLocalId,
-                          mode: euv::MutateMode) {
+                          span: Span) {
         // Assigning to one union field automatically assigns to all its fields.
         if let LpExtend(ref base_lp, mutbl, LpInterior(opt_variant_id, interior)) = lp.kind {
             if let ty::TyAdt(adt_def, _) = base_lp.ty.sty {
@@ -407,39 +395,28 @@ impl<'a, 'tcx> MoveData<'tcx> {
                                                     LpInterior(opt_variant_id, field));
                         let sibling_lp = Rc::new(LoanPath::new(sibling_lp_kind, field_ty));
                         self.add_assignment_helper(tcx, sibling_lp, assign_id,
-                                                   span, assignee_id, mode);
+                                                   span);
                     }
                     return;
                 }
             }
         }
 
-        self.add_assignment_helper(tcx, lp.clone(), assign_id, span, assignee_id, mode);
+        self.add_assignment_helper(tcx, lp.clone(), assign_id, span);
     }
 
     fn add_assignment_helper(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
                              lp: Rc<LoanPath<'tcx>>,
                              assign_id: hir::ItemLocalId,
-                             span: Span,
-                             assignee_id: hir::ItemLocalId,
-                             mode: euv::MutateMode) {
-        debug!("add_assignment(lp={:?}, assign_id={:?}, assignee_id={:?}",
-               lp, assign_id, assignee_id);
+                             span: Span) {
+        debug!("add_assignment(lp={:?}, assign_id={:?}", lp, assign_id);
 
         let path_index = self.move_path(tcx, lp.clone());
 
-        match mode {
-            MutateMode::Init | MutateMode::JustWrite => {
-                self.assignee_ids.borrow_mut().insert(assignee_id);
-            }
-            MutateMode::WriteAndRead => { }
-        }
-
         let assignment = Assignment {
             path: path_index,
             id: assign_id,
             span,
-            assignee_id,
         };
 
         if self.is_var_path(path_index) {
diff --git a/src/librustc/middle/dataflow.rs b/src/librustc_borrowck/dataflow.rs
index b949fd02126..d5f30c1dcd4 100644
--- a/src/librustc/middle/dataflow.rs
+++ b/src/librustc_borrowck/dataflow.rs
@@ -14,9 +14,9 @@
 //! and thus uses bitvectors. Your job is simply to specify the so-called
 //! GEN and KILL bits for each expression.
 
-use cfg;
-use cfg::CFGIndex;
-use ty::TyCtxt;
+use rustc::cfg;
+use rustc::cfg::CFGIndex;
+use rustc::ty::TyCtxt;
 use std::io;
 use std::mem;
 use std::usize;
@@ -24,10 +24,10 @@ use syntax::print::pprust::PrintState;
 
 use rustc_data_structures::graph::implementation::OUTGOING;
 
-use util::nodemap::FxHashMap;
-use hir;
-use hir::intravisit::{self, IdRange};
-use hir::print as pprust;
+use rustc::util::nodemap::FxHashMap;
+use rustc::hir;
+use rustc::hir::intravisit::{self, IdRange};
+use rustc::hir::print as pprust;
 
 
 #[derive(Copy, Clone, Debug)]
@@ -193,7 +193,7 @@ fn build_local_id_to_index(body: Option<&hir::Body>,
     fn add_entries_from_fn_body(index: &mut FxHashMap<hir::ItemLocalId, Vec<CFGIndex>>,
                                 body: &hir::Body,
                                 entry: CFGIndex) {
-        use hir::intravisit::Visitor;
+        use rustc::hir::intravisit::Visitor;
 
         struct Formals<'a> {
             entry: CFGIndex,
diff --git a/src/librustc_borrowck/graphviz.rs b/src/librustc_borrowck/graphviz.rs
index 22867ba5b55..dddd6a354c1 100644
--- a/src/librustc_borrowck/graphviz.rs
+++ b/src/librustc_borrowck/graphviz.rs
@@ -21,7 +21,7 @@ use borrowck;
 use borrowck::{BorrowckCtxt, LoanPath};
 use dot;
 use rustc::cfg::CFGIndex;
-use rustc::middle::dataflow::{DataFlowOperator, DataFlowContext, EntryOrExit};
+use dataflow::{DataFlowOperator, DataFlowContext, EntryOrExit};
 use std::rc::Rc;
 use dot::IntoCow;
 
diff --git a/src/librustc_borrowck/lib.rs b/src/librustc_borrowck/lib.rs
index aa85582432b..16da8c8a3b8 100644
--- a/src/librustc_borrowck/lib.rs
+++ b/src/librustc_borrowck/lib.rs
@@ -39,4 +39,6 @@ mod borrowck;
 
 pub mod graphviz;
 
+mod dataflow;
+
 pub use borrowck::provide;