Skip to content

#7081: Further syntax::visit refactors #9453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 24, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustc/middle/borrowck/check_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use util::ppaux::Repr;

#[deriving(Clone)]
struct CheckLoanCtxt<'self> {
bccx: @BorrowckCtxt,
bccx: &'self BorrowckCtxt,
dfcx_loans: &'self LoanDataFlow,
move_data: @move_data::FlowedMoveData,
all_loans: &'self [Loan],
Expand All @@ -60,7 +60,7 @@ impl<'self> Visitor<()> for CheckLoanCtxt<'self> {
}
}

pub fn check_loans(bccx: @BorrowckCtxt,
pub fn check_loans(bccx: &BorrowckCtxt,
dfcx_loans: &LoanDataFlow,
move_data: move_data::FlowedMoveData,
all_loans: &[Loan],
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/middle/borrowck/gather_loans/gather_moves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use syntax::ast_util;
use syntax::codemap::Span;
use util::ppaux::{UserString};

pub fn gather_decl(bccx: @BorrowckCtxt,
pub fn gather_decl(bccx: &BorrowckCtxt,
move_data: &mut MoveData,
decl_id: ast::NodeId,
_decl_span: Span,
Expand All @@ -31,23 +31,23 @@ pub fn gather_decl(bccx: @BorrowckCtxt,
move_data.add_move(bccx.tcx, loan_path, decl_id, Declared);
}

pub fn gather_move_from_expr(bccx: @BorrowckCtxt,
pub fn gather_move_from_expr(bccx: &BorrowckCtxt,
move_data: &mut MoveData,
move_expr: @ast::Expr,
cmt: mc::cmt) {
gather_move_from_expr_or_pat(bccx, move_data, move_expr.id,
MoveExpr(move_expr), cmt);
}

pub fn gather_move_from_pat(bccx: @BorrowckCtxt,
pub fn gather_move_from_pat(bccx: &BorrowckCtxt,
move_data: &mut MoveData,
move_pat: @ast::Pat,
cmt: mc::cmt) {
gather_move_from_expr_or_pat(bccx, move_data, move_pat.id,
MovePat(move_pat), cmt);
}

fn gather_move_from_expr_or_pat(bccx: @BorrowckCtxt,
fn gather_move_from_expr_or_pat(bccx: &BorrowckCtxt,
move_data: &mut MoveData,
move_id: ast::NodeId,
move_kind: MoveKind,
Expand All @@ -66,7 +66,7 @@ fn gather_move_from_expr_or_pat(bccx: @BorrowckCtxt,
}
}

pub fn gather_captures(bccx: @BorrowckCtxt,
pub fn gather_captures(bccx: &BorrowckCtxt,
move_data: &mut MoveData,
closure_expr: @ast::Expr) {
let captured_vars = bccx.capture_map.get(&closure_expr.id);
Expand All @@ -83,7 +83,7 @@ pub fn gather_captures(bccx: @BorrowckCtxt,
}
}

pub fn gather_assignment(bccx: @BorrowckCtxt,
pub fn gather_assignment(bccx: &BorrowckCtxt,
move_data: &mut MoveData,
assignment_id: ast::NodeId,
assignment_span: Span,
Expand All @@ -96,7 +96,7 @@ pub fn gather_assignment(bccx: @BorrowckCtxt,
assignee_id);
}

fn check_is_legal_to_move_from(bccx: @BorrowckCtxt,
fn check_is_legal_to_move_from(bccx: &BorrowckCtxt,
cmt0: mc::cmt,
cmt: mc::cmt) -> bool {
match cmt.cat {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/borrowck/gather_loans/lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use syntax::ast;
use syntax::codemap::Span;
use util::ppaux::{note_and_explain_region};

pub fn guarantee_lifetime(bccx: @BorrowckCtxt,
pub fn guarantee_lifetime(bccx: &BorrowckCtxt,
item_scope_id: ast::NodeId,
root_scope_id: ast::NodeId,
span: Span,
Expand All @@ -42,8 +42,8 @@ pub fn guarantee_lifetime(bccx: @BorrowckCtxt,
///////////////////////////////////////////////////////////////////////////
// Private

struct GuaranteeLifetimeContext {
bccx: @BorrowckCtxt,
struct GuaranteeLifetimeContext<'self> {
bccx: &'self BorrowckCtxt,

// the node id of the function body for the enclosing item
item_scope_id: ast::NodeId,
Expand All @@ -58,7 +58,7 @@ struct GuaranteeLifetimeContext {
cmt_original: mc::cmt
}

impl GuaranteeLifetimeContext {
impl<'self> GuaranteeLifetimeContext<'self> {
fn tcx(&self) -> ty::ctxt {
self.bccx.tcx
}
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/borrowck/gather_loans/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ mod gather_moves;
/// No good. Instead what will happen is that `root_ub` will be set to the
/// body of the while loop and we will refuse to root the pointer `&*x`
/// because it would have to be rooted for a region greater than `root_ub`.
struct GatherLoanCtxt {
bccx: @BorrowckCtxt,
struct GatherLoanCtxt<'self> {
bccx: &'self BorrowckCtxt,
id_range: id_range,
move_data: @mut move_data::MoveData,
all_loans: @mut ~[Loan],
item_ub: ast::NodeId,
repeating_ids: ~[ast::NodeId]
}

impl visit::Visitor<()> for GatherLoanCtxt {
impl<'self> visit::Visitor<()> for GatherLoanCtxt<'self> {
fn visit_expr(&mut self, ex:@Expr, _:()) {
gather_loans_in_expr(self, ex);
}
Expand All @@ -100,7 +100,7 @@ impl visit::Visitor<()> for GatherLoanCtxt {
fn visit_item(&mut self, _:@ast::item, _:()) { }
}

pub fn gather_loans(bccx: @BorrowckCtxt,
pub fn gather_loans(bccx: &BorrowckCtxt,
decl: &ast::fn_decl,
body: &ast::Block)
-> (id_range, @mut ~[Loan], @mut move_data::MoveData) {
Expand Down Expand Up @@ -315,7 +315,7 @@ fn gather_loans_in_expr(this: &mut GatherLoanCtxt,
}
}

impl GatherLoanCtxt {
impl<'self> GatherLoanCtxt<'self> {
pub fn tcx(&self) -> ty::ctxt { self.bccx.tcx }

pub fn push_repeating_id(&mut self, id: ast::NodeId) {
Expand Down Expand Up @@ -532,7 +532,7 @@ impl GatherLoanCtxt {
// }
// }

fn check_mutability(bccx: @BorrowckCtxt,
fn check_mutability(bccx: &BorrowckCtxt,
borrow_span: Span,
cmt: mc::cmt,
req_mutbl: LoanMutability) {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/borrowck/gather_loans/restrictions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum RestrictionResult {
SafeIf(@LoanPath, ~[Restriction])
}

pub fn compute_restrictions(bccx: @BorrowckCtxt,
pub fn compute_restrictions(bccx: &BorrowckCtxt,
span: Span,
cmt: mc::cmt,
restr: RestrictionSet) -> RestrictionResult {
Expand All @@ -39,13 +39,13 @@ pub fn compute_restrictions(bccx: @BorrowckCtxt,
///////////////////////////////////////////////////////////////////////////
// Private

struct RestrictionsContext {
bccx: @BorrowckCtxt,
struct RestrictionsContext<'self> {
bccx: &'self BorrowckCtxt,
span: Span,
cmt_original: mc::cmt
}

impl RestrictionsContext {
impl<'self> RestrictionsContext<'self> {
fn tcx(&self) -> ty::ctxt {
self.bccx.tcx
}
Expand Down
23 changes: 10 additions & 13 deletions src/librustc/middle/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ impl Clone for LoanDataFlowOperator {

pub type LoanDataFlow = DataFlowContext<LoanDataFlowOperator>;

struct BorrowckVisitor;

impl Visitor<@BorrowckCtxt> for BorrowckVisitor {
impl Visitor<()> for BorrowckCtxt {
fn visit_fn(&mut self, fk:&fn_kind, fd:&fn_decl,
b:&Block, s:Span, n:NodeId, e:@BorrowckCtxt) {
borrowck_fn(self, fk, fd, b, s, n, e);
b:&Block, s:Span, n:NodeId, _:()) {
borrowck_fn(self, fk, fd, b, s, n);
}
}

Expand All @@ -78,7 +76,7 @@ pub fn check_crate(
capture_map: moves::CaptureMap,
crate: &ast::Crate) -> (root_map, write_guard_map)
{
let bccx = @BorrowckCtxt {
let mut bccx = BorrowckCtxt {
tcx: tcx,
method_map: method_map,
moves_map: moves_map,
Expand All @@ -96,9 +94,9 @@ pub fn check_crate(
guaranteed_paths: 0,
}
};
let bccx = &mut bccx;

let mut v = BorrowckVisitor;
visit::walk_crate(&mut v, crate, bccx);
visit::walk_crate(bccx, crate, ());

if tcx.sess.borrowck_stats() {
io::println("--- borrowck stats ---");
Expand All @@ -116,20 +114,19 @@ pub fn check_crate(

return (bccx.root_map, bccx.write_guard_map);

fn make_stat(bccx: &BorrowckCtxt, stat: uint) -> ~str {
fn make_stat(bccx: &mut BorrowckCtxt, stat: uint) -> ~str {
let stat_f = stat as float;
let total = bccx.stats.guaranteed_paths as float;
fmt!("%u (%.0f%%)", stat , stat_f * 100f / total)
}
}

fn borrowck_fn(v: &mut BorrowckVisitor,
fn borrowck_fn(this: &mut BorrowckCtxt,
fk: &visit::fn_kind,
decl: &ast::fn_decl,
body: &ast::Block,
sp: Span,
id: ast::NodeId,
this: @BorrowckCtxt) {
id: ast::NodeId) {
match fk {
&visit::fk_anon(*) |
&visit::fk_fn_block(*) => {
Expand Down Expand Up @@ -166,7 +163,7 @@ fn borrowck_fn(v: &mut BorrowckVisitor,
}
}

visit::walk_fn(v, fk, decl, body, sp, id, this);
visit::walk_fn(this, fk, decl, body, sp, id, ());
}

// ----------------------------------------------------------------------
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,6 @@ enum AnyVisitor {
NewVisitor(@mut visit::Visitor<()>),
}

type VCObj = @mut Visitor<@mut Context>;

struct Context {
// All known lint modes (string versions)
dict: @LintDict,
Expand Down
Loading