提交 08520a16 编写于 作者: N Niko Matsakis

move borrowck to dvec, insert a few minor copies

上级 d9db4f02
...@@ -164,6 +164,7 @@ ...@@ -164,6 +164,7 @@
import ast_util::op_expr_callee_id; import ast_util::op_expr_callee_id;
import ty::to_str; import ty::to_str;
import driver::session::session; import driver::session::session;
import dvec::{dvec, extensions};
export check_crate, root_map, mutbl_map; export check_crate, root_map, mutbl_map;
...@@ -298,7 +299,7 @@ enum loan_path { ...@@ -298,7 +299,7 @@ enum loan_path {
// maps computed by `gather_loans` that are then used by `check_loans` // maps computed by `gather_loans` that are then used by `check_loans`
type req_maps = { type req_maps = {
req_loan_map: hashmap<ast::node_id, @mut [@const [loan]]>, req_loan_map: hashmap<ast::node_id, @dvec<@dvec<loan>>>,
pure_map: hashmap<ast::node_id, bckerr> pure_map: hashmap<ast::node_id, bckerr>
}; };
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
// 3. assignments do not affect things loaned out as immutable // 3. assignments do not affect things loaned out as immutable
// 4. moves to dnot affect things loaned out in any way // 4. moves to dnot affect things loaned out in any way
import dvec::{dvec, extensions};
import categorization::public_methods; import categorization::public_methods;
export check_loans; export check_loans;
...@@ -22,7 +23,7 @@ enum check_loan_ctxt = @{ ...@@ -22,7 +23,7 @@ enum check_loan_ctxt = @{
// we are in a ctor, we track the self id // we are in a ctor, we track the self id
mut in_ctor: bool, mut in_ctor: bool,
mut declared_purity: ast::purity, mut declared_purity: ast::purity,
mut fn_args: [ast::node_id] mut fn_args: @[ast::node_id]
}; };
// if we are enforcing purity, why are we doing so? // if we are enforcing purity, why are we doing so?
...@@ -44,7 +45,7 @@ fn check_loans(bccx: borrowck_ctxt, ...@@ -44,7 +45,7 @@ fn check_loans(bccx: borrowck_ctxt,
reported: int_hash(), reported: int_hash(),
mut in_ctor: false, mut in_ctor: false,
mut declared_purity: ast::impure_fn, mut declared_purity: ast::impure_fn,
mut fn_args: []}); mut fn_args: @[]});
let vt = visit::mk_vt(@{visit_expr: check_loans_in_expr, let vt = visit::mk_vt(@{visit_expr: check_loans_in_expr,
visit_block: check_loans_in_block, visit_block: check_loans_in_block,
visit_fn: check_loans_in_fn visit_fn: check_loans_in_fn
...@@ -179,7 +180,7 @@ fn check_pure_callee_or_arg(pc: purity_cause, ...@@ -179,7 +180,7 @@ fn check_pure_callee_or_arg(pc: purity_cause,
let did = ast_util::def_id_of_def(def); let did = ast_util::def_id_of_def(def);
let is_fn_arg = let is_fn_arg =
did.crate == ast::local_crate && did.crate == ast::local_crate &&
self.fn_args.contains(did.node); (*self.fn_args).contains(did.node);
if is_fn_arg { ret; } // case (a) above if is_fn_arg { ret; } // case (a) above
} }
ast::expr_fn_block(*) | ast::expr_fn(*) | ast::expr_fn_block(*) | ast::expr_fn(*) |
...@@ -225,7 +226,8 @@ fn is_allowed_pure_arg(expr: @ast::expr) -> bool { ...@@ -225,7 +226,8 @@ fn is_allowed_pure_arg(expr: @ast::expr) -> bool {
ast::expr_path(_) { ast::expr_path(_) {
let def = self.tcx().def_map.get(expr.id); let def = self.tcx().def_map.get(expr.id);
let did = ast_util::def_id_of_def(def); let did = ast_util::def_id_of_def(def);
did.crate == ast::local_crate && self.fn_args.contains(did.node) did.crate == ast::local_crate &&
(*self.fn_args).contains(did.node)
} }
ast::expr_fn_block(*) | ast::expr_fn(*) { ast::expr_fn_block(*) | ast::expr_fn(*) {
self.is_stack_closure(expr.id) self.is_stack_closure(expr.id)
...@@ -484,7 +486,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk, ...@@ -484,7 +486,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
sp: span, id: ast::node_id, &&self: check_loan_ctxt, sp: span, id: ast::node_id, &&self: check_loan_ctxt,
visitor: visit::vt<check_loan_ctxt>) { visitor: visit::vt<check_loan_ctxt>) {
#debug["purity on entry=%?", self.declared_purity]; #debug["purity on entry=%?", copy self.declared_purity];
save_and_restore(self.in_ctor) {|| save_and_restore(self.in_ctor) {||
save_and_restore(self.declared_purity) {|| save_and_restore(self.declared_purity) {||
save_and_restore(self.fn_args) {|| save_and_restore(self.fn_args) {||
...@@ -500,7 +502,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk, ...@@ -500,7 +502,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
visit::fk_ctor(*) { visit::fk_ctor(*) {
self.in_ctor = true; self.in_ctor = true;
self.declared_purity = decl.purity; self.declared_purity = decl.purity;
self.fn_args = decl.inputs.map({|i| i.id}); self.fn_args = @decl.inputs.map({|i| i.id});
} }
visit::fk_anon(*) | visit::fk_anon(*) |
visit::fk_fn_block(*) if is_stack_closure { visit::fk_fn_block(*) if is_stack_closure {
...@@ -512,7 +514,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk, ...@@ -512,7 +514,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
visit::fk_res(*) | visit::fk_dtor(*) { visit::fk_res(*) | visit::fk_dtor(*) {
self.in_ctor = false; self.in_ctor = false;
self.declared_purity = decl.purity; self.declared_purity = decl.purity;
self.fn_args = decl.inputs.map({|i| i.id}); self.fn_args = @decl.inputs.map({|i| i.id});
} }
} }
...@@ -520,7 +522,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk, ...@@ -520,7 +522,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
} }
} }
} }
#debug["purity on exit=%?", self.declared_purity]; #debug["purity on exit=%?", copy self.declared_purity];
} }
fn check_loans_in_expr(expr: @ast::expr, fn check_loans_in_expr(expr: @ast::expr,
......
...@@ -273,13 +273,14 @@ fn check_mutbl(req_mutbl: ast::mutability, ...@@ -273,13 +273,14 @@ fn check_mutbl(req_mutbl: ast::mutability,
} }
} }
fn add_loans(scope_id: ast::node_id, loans: @const [loan]) { fn add_loans(scope_id: ast::node_id, loans: @dvec<loan>) {
alt self.req_maps.req_loan_map.find(scope_id) { alt self.req_maps.req_loan_map.find(scope_id) {
some(l) { some(l) {
*l += [loans]; (*l).push(loans);
} }
none { none {
self.req_maps.req_loan_map.insert(scope_id, @mut [loans]); self.req_maps.req_loan_map.insert(
scope_id, @dvec::from_vec([mut loans]));
} }
} }
} }
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
export public_methods; export public_methods;
impl public_methods for borrowck_ctxt { impl public_methods for borrowck_ctxt {
fn loan(cmt: cmt, mutbl: ast::mutability) -> @const [loan] { fn loan(cmt: cmt, mutbl: ast::mutability) -> @dvec<loan> {
let lc = @{bccx: self, loans: @mut []}; let lc = @{bccx: self, loans: @dvec()};
lc.loan(cmt, mutbl); lc.loan(cmt, mutbl);
ret lc.loans; ret lc.loans;
} }
...@@ -14,7 +14,7 @@ fn loan(cmt: cmt, mutbl: ast::mutability) -> @const [loan] { ...@@ -14,7 +14,7 @@ fn loan(cmt: cmt, mutbl: ast::mutability) -> @const [loan] {
type loan_ctxt = @{ type loan_ctxt = @{
bccx: borrowck_ctxt, bccx: borrowck_ctxt,
loans: @mut [loan] loans: @dvec<loan>
}; };
impl loan_methods for loan_ctxt { impl loan_methods for loan_ctxt {
...@@ -23,9 +23,9 @@ fn ok_with_loan_of(cmt: cmt, ...@@ -23,9 +23,9 @@ fn ok_with_loan_of(cmt: cmt,
// Note: all cmt's that we deal with will have a non-none lp, because // Note: all cmt's that we deal with will have a non-none lp, because
// the entry point into this routine, `borrowck_ctxt::loan()`, rejects // the entry point into this routine, `borrowck_ctxt::loan()`, rejects
// any cmt with a none-lp. // any cmt with a none-lp.
*self.loans += [{lp:option::get(cmt.lp), (*self.loans).push({lp:option::get(cmt.lp),
cmt:cmt, cmt:cmt,
mutbl:mutbl}]; mutbl:mutbl});
} }
fn loan(cmt: cmt, req_mutbl: ast::mutability) { fn loan(cmt: cmt, req_mutbl: ast::mutability) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册