use middle::ty;
use util::ppaux::{note_and_explain_region, Repr, UserString};
-use std::cell::{Cell};
use std::rc::Rc;
-use std::gc::{Gc, GC};
use std::string::String;
use syntax::ast;
use syntax::ast_map;
}
}
-pub fn check_crate(tcx: &ty::ctxt,
- krate: &ast::Crate) {
+pub fn check_crate(tcx: &ty::ctxt) {
let mut bccx = BorrowckCtxt {
tcx: tcx,
- stats: box(GC) BorrowStats {
- loaned_paths_same: Cell::new(0),
- loaned_paths_imm: Cell::new(0),
- stable_paths: Cell::new(0),
- guaranteed_paths: Cell::new(0),
+ stats: BorrowStats {
+ loaned_paths_same: 0,
+ loaned_paths_imm: 0,
+ stable_paths: 0,
+ guaranteed_paths: 0
}
};
- visit::walk_crate(&mut bccx, krate);
+ visit::walk_crate(&mut bccx, tcx.map.krate());
if tcx.sess.borrowck_stats() {
println!("--- borrowck stats ---");
println!("paths requiring guarantees: {}",
- bccx.stats.guaranteed_paths.get());
+ bccx.stats.guaranteed_paths);
println!("paths requiring loans : {}",
- make_stat(&bccx, bccx.stats.loaned_paths_same.get()));
+ make_stat(&bccx, bccx.stats.loaned_paths_same));
println!("paths requiring imm loans : {}",
- make_stat(&bccx, bccx.stats.loaned_paths_imm.get()));
+ make_stat(&bccx, bccx.stats.loaned_paths_imm));
println!("stable paths : {}",
- make_stat(&bccx, bccx.stats.stable_paths.get()));
+ make_stat(&bccx, bccx.stats.stable_paths));
}
fn make_stat(bccx: &BorrowckCtxt, stat: uint) -> String {
- let total = bccx.stats.guaranteed_paths.get() as f64;
+ let total = bccx.stats.guaranteed_paths as f64;
let perc = if total == 0.0 { 0.0 } else { stat as f64 * 100.0 / total };
format!("{} ({:.0f}%)", stat, perc)
}
// loan step is intended for things that have a data
// flow dependent conditions.
match item.node {
- ast::ItemStatic(_, _, ex) => {
- gather_loans::gather_loans_in_static_initializer(this, &*ex);
+ ast::ItemStatic(_, _, ref ex) => {
+ gather_loans::gather_loans_in_static_initializer(this, &**ex);
}
_ => {
visit::walk_item(this, item);
let mut bccx = BorrowckCtxt {
tcx: tcx,
- stats: box(GC) BorrowStats {
- loaned_paths_same: Cell::new(0),
- loaned_paths_imm: Cell::new(0),
- stable_paths: Cell::new(0),
- guaranteed_paths: Cell::new(0),
+ stats: BorrowStats {
+ loaned_paths_same: 0,
+ loaned_paths_imm: 0,
+ stable_paths: 0,
+ guaranteed_paths: 0
}
};
tcx: &'a ty::ctxt<'tcx>,
// Statistics:
- stats: Gc<BorrowStats>,
+ stats: BorrowStats
}
-pub struct BorrowStats {
- loaned_paths_same: Cell<uint>,
- loaned_paths_imm: Cell<uint>,
- stable_paths: Cell<uint>,
- guaranteed_paths: Cell<uint>,
+struct BorrowStats {
+ loaned_paths_same: uint,
+ loaned_paths_imm: uint,
+ stable_paths: uint,
+ guaranteed_paths: uint
}
pub type BckResult<T> = Result<T, BckError>;
tcx: &ty::ctxt) -> ast::NodeId {
match tcx.map.get(closure_id) {
ast_map::NodeExpr(expr) => match expr.node {
- ast::ExprProc(_, block) |
- ast::ExprFnBlock(_, _, block) |
- ast::ExprUnboxedFn(_, _, _, block) => { block.id }
+ ast::ExprProc(_, ref block) |
+ ast::ExprFnBlock(_, _, ref block) |
+ ast::ExprUnboxedFn(_, _, _, ref block) => { block.id }
_ => fail!("encountered non-closure id: {}", closure_id)
},
_ => fail!("encountered non-expr id: {}", closure_id)
None
}
- mc::cat_local(id) |
- mc::cat_arg(id) => {
+ mc::cat_local(id) => {
Some(Rc::new(LpVar(id)))
}
adj: &ty::AutoAdjustment)
-> mc::cmt {
let r = match *adj {
- ty::AutoDerefRef(
+ ty::AdjustDerefRef(
ty::AutoDerefRef {
autoderefs: autoderefs, ..}) => {
self.mc().cat_expr_autoderefd(expr, autoderefs)
}
- ty::AutoAddEnv(..) => {
+ ty::AdjustAddEnv(..) => {
// no autoderefs
self.mc().cat_expr_unadjusted(expr)
}