Skip to content

Commit

Permalink
rewrite borrowck_fn to only use the body-id
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Feb 28, 2017
1 parent d885e4c commit 03e8b26
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
5 changes: 3 additions & 2 deletions src/librustc_borrowck/borrowck/fragments.rs
Expand Up @@ -27,7 +27,7 @@ use rustc::middle::mem_categorization as mc;
use std::mem;
use std::rc::Rc;
use syntax::ast;
use syntax_pos::{Span, DUMMY_SP};
use syntax_pos::DUMMY_SP;

#[derive(PartialEq, Eq, PartialOrd, Ord)]
enum Fragment {
Expand Down Expand Up @@ -200,14 +200,15 @@ impl FragmentSets {

pub fn instrument_move_fragments<'a, 'tcx>(this: &MoveData<'tcx>,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
sp: Span,
id: ast::NodeId) {
let span_err = tcx.hir.attrs(id).iter()
.any(|a| a.check_name("rustc_move_fragments"));
let print = tcx.sess.opts.debugging_opts.print_move_fragments;

if !span_err && !print { return; }

let sp = tcx.hir.span(id);

let instrument_all_paths = |kind, vec_rc: &Vec<MovePathIndex>| {
for (i, mpi) in vec_rc.iter().enumerate() {
let lp = || this.path_loan_path(*mpi);
Expand Down
31 changes: 13 additions & 18 deletions src/librustc_borrowck/borrowck/mod.rs
Expand Up @@ -70,11 +70,13 @@ impl<'a, 'tcx> Visitor<'tcx> for BorrowckCtxt<'a, 'tcx> {
match fk {
FnKind::ItemFn(..) |
FnKind::Method(..) => {
borrowck_fn(self, fk, fd, b, s, id, fk.attrs())
borrowck_fn(self, b);
intravisit::walk_fn(self, fk, fd, b, s, id);
}

FnKind::Closure(..) => {
borrowck_fn(self, fk, fd, b, s, id, fk.attrs());
borrowck_fn(self, b);
intravisit::walk_fn(self, fk, fd, b, s, id);
}
}
}
Expand Down Expand Up @@ -154,24 +156,20 @@ pub struct AnalysisData<'a, 'tcx: 'a> {
pub move_data: move_data::FlowedMoveData<'a, 'tcx>,
}

fn borrowck_fn<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>,
fk: FnKind<'tcx>,
decl: &'tcx hir::FnDecl,
body_id: hir::BodyId,
sp: Span,
id: ast::NodeId,
attributes: &[ast::Attribute]) {
debug!("borrowck_fn(id={})", id);
fn borrowck_fn<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>, body_id: hir::BodyId) {
debug!("borrowck_fn(body_id={:?})", body_id);

assert!(this.tables.is_none());
let owner_def_id = this.tcx.hir.local_def_id(this.tcx.hir.body_owner(body_id));
let owner_id = this.tcx.hir.body_owner(body_id);
let owner_def_id = this.tcx.hir.local_def_id(owner_id);
let attributes = this.tcx.get_attrs(owner_def_id);
let tables = this.tcx.item_tables(owner_def_id);
this.tables = Some(tables);

let body = this.tcx.hir.body(body_id);

if attributes.iter().any(|item| item.check_name("rustc_mir_borrowck")) {
mir::borrowck_mir(this, id, attributes);
if this.tcx.has_attr(owner_def_id, "rustc_mir_borrowck") {
mir::borrowck_mir(this, owner_id, &attributes);
}

let cfg = cfg::CFG::new(this.tcx, &body.value);
Expand All @@ -182,17 +180,14 @@ fn borrowck_fn<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>,

move_data::fragments::instrument_move_fragments(&flowed_moves.move_data,
this.tcx,
sp,
id);
owner_id);
move_data::fragments::build_unfragmented_map(this,
&flowed_moves.move_data,
id);
owner_id);

check_loans::check_loans(this, &loan_dfcx, &flowed_moves, &all_loans[..], body);

this.tables = None;

intravisit::walk_fn(this, fk, decl, body_id, sp, id);
}

fn build_borrowck_dataflow_data<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>,
Expand Down

0 comments on commit 03e8b26

Please sign in to comment.