Skip to content

Commit fa23350

Browse files
committed
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.
2 parents 5bb2094 + 8592039 commit fa23350

File tree

10 files changed

+31
-85
lines changed

10 files changed

+31
-85
lines changed

src/librustc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ pub mod middle {
135135
pub mod borrowck;
136136
pub mod expr_use_visitor;
137137
pub mod cstore;
138-
pub mod dataflow;
139138
pub mod dead;
140139
pub mod dependency_format;
141140
pub mod entry;

src/librustc_borrowck/borrowck/check_loans.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ struct CheckLoanCtxt<'a, 'tcx: 'a> {
9191
dfcx_loans: &'a LoanDataFlow<'a, 'tcx>,
9292
move_data: &'a move_data::FlowedMoveData<'a, 'tcx>,
9393
all_loans: &'a [Loan<'tcx>],
94-
param_env: ty::ParamEnv<'tcx>,
9594
movable_generator: bool,
9695
}
9796

@@ -215,7 +214,6 @@ pub fn check_loans<'a, 'b, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
215214
dfcx_loans,
216215
move_data,
217216
all_loans,
218-
param_env,
219217
movable_generator,
220218
};
221219
let rvalue_promotable_map = bccx.tcx.rvalue_promotable_map(def_id);
@@ -801,8 +799,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
801799
use_kind,
802800
&lp,
803801
the_move,
804-
moved_lp,
805-
self.param_env);
802+
moved_lp);
806803
false
807804
});
808805
}

src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,11 @@ pub fn gather_assignment<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
163163
move_data: &MoveData<'tcx>,
164164
assignment_id: hir::ItemLocalId,
165165
assignment_span: Span,
166-
assignee_loan_path: Rc<LoanPath<'tcx>>,
167-
assignee_id: hir::ItemLocalId,
168-
mode: euv::MutateMode) {
166+
assignee_loan_path: Rc<LoanPath<'tcx>>) {
169167
move_data.add_assignment(bccx.tcx,
170168
assignee_loan_path,
171169
assignment_id,
172-
assignment_span,
173-
assignee_id,
174-
mode);
170+
assignment_span);
175171
}
176172

177173
// (keep in sync with move_error::report_cannot_move_out_of )

src/librustc_borrowck/borrowck/gather_loans/lifetime.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ pub fn guarantee_lifetime<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
2828
span: Span,
2929
cause: euv::LoanCause,
3030
cmt: &'a mc::cmt_<'tcx>,
31-
loan_region: ty::Region<'tcx>,
32-
_: ty::BorrowKind)
31+
loan_region: ty::Region<'tcx>)
3332
-> Result<(),()> {
3433
//! Reports error if `loan_region` is larger than S
3534
//! where S is `item_scope` if `cmt` is an upvar,

src/librustc_borrowck/borrowck/gather_loans/mod.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,11 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> {
145145
assignment_id: ast::NodeId,
146146
assignment_span: Span,
147147
assignee_cmt: &mc::cmt_<'tcx>,
148-
mode: euv::MutateMode)
148+
_: euv::MutateMode)
149149
{
150150
self.guarantee_assignment_valid(assignment_id,
151151
assignment_span,
152-
assignee_cmt,
153-
mode);
152+
assignee_cmt);
154153
}
155154

156155
fn decl_without_init(&mut self, id: ast::NodeId, _span: Span) {
@@ -246,8 +245,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
246245
fn guarantee_assignment_valid(&mut self,
247246
assignment_id: ast::NodeId,
248247
assignment_span: Span,
249-
cmt: &mc::cmt_<'tcx>,
250-
mode: euv::MutateMode) {
248+
cmt: &mc::cmt_<'tcx>) {
251249

252250
let opt_lp = opt_loan_path(cmt);
253251
debug!("guarantee_assignment_valid(assignment_id={}, cmt={:?}) opt_lp={:?}",
@@ -282,9 +280,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
282280
self.bccx.tcx.hir.node_to_hir_id(assignment_id)
283281
.local_id,
284282
assignment_span,
285-
lp,
286-
cmt.hir_id.local_id,
287-
mode);
283+
lp);
288284
}
289285
None => {
290286
// This can occur with e.g. `*foo() = 5`. In such
@@ -320,7 +316,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
320316
// Check that the lifetime of the borrow does not exceed
321317
// the lifetime of the data being borrowed.
322318
if lifetime::guarantee_lifetime(self.bccx, self.item_ub,
323-
borrow_span, cause, cmt, loan_region, req_kind).is_err() {
319+
borrow_span, cause, cmt, loan_region).is_err() {
324320
return; // reported an error, no sense in reporting more.
325321
}
326322

src/librustc_borrowck/borrowck/mod.rs

+3-23
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ use rustc::hir::HirId;
2424
use rustc::hir::map as hir_map;
2525
use rustc::hir::map::blocks::FnLikeNode;
2626
use rustc::cfg;
27-
use rustc::middle::dataflow::DataFlowContext;
28-
use rustc::middle::dataflow::BitwiseOperator;
29-
use rustc::middle::dataflow::DataFlowOperator;
30-
use rustc::middle::dataflow::KillFrom;
3127
use rustc::middle::borrowck::{BorrowCheckResult, SignalledError};
3228
use rustc::hir::def_id::{DefId, LocalDefId};
3329
use rustc::middle::expr_use_visitor as euv;
@@ -54,6 +50,8 @@ use errors::{DiagnosticBuilder, DiagnosticId};
5450
use rustc::hir;
5551
use rustc::hir::intravisit::{self, Visitor};
5652

53+
use dataflow::{DataFlowContext, BitwiseOperator, DataFlowOperator, KillFrom};
54+
5755
pub mod check_loans;
5856

5957
pub mod gather_loans;
@@ -640,8 +638,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
640638
use_kind: MovedValueUseKind,
641639
lp: &LoanPath<'tcx>,
642640
the_move: &move_data::Move,
643-
moved_lp: &LoanPath<'tcx>,
644-
_param_env: ty::ParamEnv<'tcx>) {
641+
moved_lp: &LoanPath<'tcx>) {
645642
let (verb, verb_participle) = match use_kind {
646643
MovedInUse => ("use", "used"),
647644
MovedInCapture => ("capture", "captured"),
@@ -806,23 +803,6 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
806803
self.signal_error();
807804
}
808805

809-
pub fn struct_span_err_with_code<S: Into<MultiSpan>>(&self,
810-
s: S,
811-
msg: &str,
812-
code: DiagnosticId)
813-
-> DiagnosticBuilder<'a> {
814-
self.tcx.sess.struct_span_err_with_code(s, msg, code)
815-
}
816-
817-
pub fn span_err_with_code<S: Into<MultiSpan>>(
818-
&self,
819-
s: S,
820-
msg: &str,
821-
code: DiagnosticId,
822-
) {
823-
self.tcx.sess.span_err_with_code(s, msg, code);
824-
}
825-
826806
fn report_bckerr(&self, err: &BckError<'a, 'tcx>) {
827807
let error_span = err.span.clone();
828808

src/librustc_borrowck/borrowck/move_data.rs

+8-31
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,12 @@
1313
1414
pub use self::MoveKind::*;
1515

16+
use dataflow::{DataFlowContext, BitwiseOperator, DataFlowOperator, KillFrom};
17+
1618
use borrowck::*;
1719
use rustc::cfg;
18-
use rustc::middle::dataflow::DataFlowContext;
19-
use rustc::middle::dataflow::BitwiseOperator;
20-
use rustc::middle::dataflow::DataFlowOperator;
21-
use rustc::middle::dataflow::KillFrom;
22-
use rustc::middle::expr_use_visitor as euv;
23-
use rustc::middle::expr_use_visitor::MutateMode;
2420
use rustc::ty::{self, TyCtxt};
25-
use rustc::util::nodemap::{FxHashMap, FxHashSet};
21+
use rustc::util::nodemap::FxHashMap;
2622

2723
use std::cell::RefCell;
2824
use std::rc::Rc;
@@ -51,9 +47,6 @@ pub struct MoveData<'tcx> {
5147
/// assigned dataflow bits, but we track them because they still
5248
/// kill move bits.
5349
pub path_assignments: RefCell<Vec<Assignment>>,
54-
55-
/// Assignments to a variable or path, like `x = foo`, but not `x += foo`.
56-
pub assignee_ids: RefCell<FxHashSet<hir::ItemLocalId>>,
5750
}
5851

5952
pub struct FlowedMoveData<'a, 'tcx: 'a> {
@@ -151,9 +144,6 @@ pub struct Assignment {
151144

152145
/// span of node where assignment occurs
153146
pub span: Span,
154-
155-
/// id for place expression on lhs of assignment
156-
pub assignee_id: hir::ItemLocalId,
157147
}
158148

159149
#[derive(Clone, Copy)]
@@ -388,9 +378,7 @@ impl<'a, 'tcx> MoveData<'tcx> {
388378
pub fn add_assignment(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
389379
lp: Rc<LoanPath<'tcx>>,
390380
assign_id: hir::ItemLocalId,
391-
span: Span,
392-
assignee_id: hir::ItemLocalId,
393-
mode: euv::MutateMode) {
381+
span: Span) {
394382
// Assigning to one union field automatically assigns to all its fields.
395383
if let LpExtend(ref base_lp, mutbl, LpInterior(opt_variant_id, interior)) = lp.kind {
396384
if let ty::TyAdt(adt_def, _) = base_lp.ty.sty {
@@ -407,39 +395,28 @@ impl<'a, 'tcx> MoveData<'tcx> {
407395
LpInterior(opt_variant_id, field));
408396
let sibling_lp = Rc::new(LoanPath::new(sibling_lp_kind, field_ty));
409397
self.add_assignment_helper(tcx, sibling_lp, assign_id,
410-
span, assignee_id, mode);
398+
span);
411399
}
412400
return;
413401
}
414402
}
415403
}
416404

417-
self.add_assignment_helper(tcx, lp.clone(), assign_id, span, assignee_id, mode);
405+
self.add_assignment_helper(tcx, lp.clone(), assign_id, span);
418406
}
419407

420408
fn add_assignment_helper(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
421409
lp: Rc<LoanPath<'tcx>>,
422410
assign_id: hir::ItemLocalId,
423-
span: Span,
424-
assignee_id: hir::ItemLocalId,
425-
mode: euv::MutateMode) {
426-
debug!("add_assignment(lp={:?}, assign_id={:?}, assignee_id={:?}",
427-
lp, assign_id, assignee_id);
411+
span: Span) {
412+
debug!("add_assignment(lp={:?}, assign_id={:?}", lp, assign_id);
428413

429414
let path_index = self.move_path(tcx, lp.clone());
430415

431-
match mode {
432-
MutateMode::Init | MutateMode::JustWrite => {
433-
self.assignee_ids.borrow_mut().insert(assignee_id);
434-
}
435-
MutateMode::WriteAndRead => { }
436-
}
437-
438416
let assignment = Assignment {
439417
path: path_index,
440418
id: assign_id,
441419
span,
442-
assignee_id,
443420
};
444421

445422
if self.is_var_path(path_index) {

src/librustc/middle/dataflow.rs renamed to src/librustc_borrowck/dataflow.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@
1414
//! and thus uses bitvectors. Your job is simply to specify the so-called
1515
//! GEN and KILL bits for each expression.
1616
17-
use cfg;
18-
use cfg::CFGIndex;
19-
use ty::TyCtxt;
17+
use rustc::cfg;
18+
use rustc::cfg::CFGIndex;
19+
use rustc::ty::TyCtxt;
2020
use std::io;
2121
use std::mem;
2222
use std::usize;
2323
use syntax::print::pprust::PrintState;
2424

2525
use rustc_data_structures::graph::implementation::OUTGOING;
2626

27-
use util::nodemap::FxHashMap;
28-
use hir;
29-
use hir::intravisit::{self, IdRange};
30-
use hir::print as pprust;
27+
use rustc::util::nodemap::FxHashMap;
28+
use rustc::hir;
29+
use rustc::hir::intravisit::{self, IdRange};
30+
use rustc::hir::print as pprust;
3131

3232

3333
#[derive(Copy, Clone, Debug)]
@@ -193,7 +193,7 @@ fn build_local_id_to_index(body: Option<&hir::Body>,
193193
fn add_entries_from_fn_body(index: &mut FxHashMap<hir::ItemLocalId, Vec<CFGIndex>>,
194194
body: &hir::Body,
195195
entry: CFGIndex) {
196-
use hir::intravisit::Visitor;
196+
use rustc::hir::intravisit::Visitor;
197197

198198
struct Formals<'a> {
199199
entry: CFGIndex,

src/librustc_borrowck/graphviz.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use borrowck;
2121
use borrowck::{BorrowckCtxt, LoanPath};
2222
use dot;
2323
use rustc::cfg::CFGIndex;
24-
use rustc::middle::dataflow::{DataFlowOperator, DataFlowContext, EntryOrExit};
24+
use dataflow::{DataFlowOperator, DataFlowContext, EntryOrExit};
2525
use std::rc::Rc;
2626
use dot::IntoCow;
2727

src/librustc_borrowck/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ mod borrowck;
3939

4040
pub mod graphviz;
4141

42+
mod dataflow;
43+
4244
pub use borrowck::provide;

0 commit comments

Comments
 (0)