Skip to content

Commit

Permalink
implement new borrow ck (disabled by default)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed May 10, 2012
1 parent 5e7229b commit 50a3dd4
Show file tree
Hide file tree
Showing 32 changed files with 2,100 additions and 311 deletions.
2 changes: 1 addition & 1 deletion mk/target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTSYNTAX): \
$$(TCORELIB_DEFAULT$(1)_T_$(2)_H_$(3)) \
$$(TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3))
@$$(call E, compile_and_link: $$@)
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@
$$(STAGE$(1)_T_$(2)_H_$(3)) $(BORROWCK) -o $$@ $$< && touch $$@

endef

Expand Down
21 changes: 16 additions & 5 deletions src/rustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import session::session;
import syntax::parse;
import syntax::{ast, codemap};
import syntax::attr;
import middle::{trans, resolve, freevars, kind, ty, typeck, fn_usage,
import middle::{trans, resolve, freevars, kind, ty, typeck,
last_use, lint};
import syntax::print::{pp, pprust};
import util::{ppaux, filesearch};
Expand Down Expand Up @@ -158,12 +158,13 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
bind middle::block_use::check_crate(ty_cx, crate));
time(time_passes, "loop checking",
bind middle::check_loop::check_crate(ty_cx, crate));
time(time_passes, "function usage",
bind fn_usage::check_crate_fn_usage(ty_cx, crate));
time(time_passes, "alt checking",
bind middle::check_alt::check_crate(ty_cx, crate));
time(time_passes, "typestate checking",
bind middle::tstate::ck::check_crate(ty_cx, crate));
let _root_map = time(
time_passes, "borrow checking",
bind middle::borrowck::check_crate(ty_cx, method_map, crate));
let mutbl_map =
time(time_passes, "mutability checking",
bind middle::mutbl::check_crate(ty_cx, crate));
Expand Down Expand Up @@ -401,6 +402,14 @@ fn build_session_options(match: getopts::match,
let target_opt = getopts::opt_maybe_str(match, "target");
let mut no_asm_comments = getopts::opt_present(match, "no-asm-comments");
let debug_rustc = getopts::opt_present(match, "debug-rustc");
let borrowck = alt getopts::opt_maybe_str(match, "borrowck") {
none { 0u }
some("warn") { 1u }
some("err") { 2u }
some(_) {
early_error(demitter, "borrowck may be warn or err")
}
};
alt output_type {
// unless we're emitting huamn-readable assembly, omit comments.
link::output_type_llvm_assembly | link::output_type_assembly {}
Expand Down Expand Up @@ -455,7 +464,8 @@ fn build_session_options(match: getopts::match,
parse_only: parse_only,
no_trans: no_trans,
no_asm_comments: no_asm_comments,
debug_rustc: debug_rustc};
debug_rustc: debug_rustc,
borrowck: borrowck};
ret sopts;
}

Expand Down Expand Up @@ -533,7 +543,8 @@ fn opts() -> [getopts::opt] {
optmulti("cfg"), optflag("test"),
optflag("lib"), optflag("bin"), optflag("static"), optflag("gc"),
optflag("no-asm-comments"),
optflag("debug-rustc")];
optflag("debug-rustc"),
optopt("borrowck")];
}

type output_filenames = @{out_filename: str, obj_filename:str};
Expand Down
4 changes: 3 additions & 1 deletion src/rustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ type options =
parse_only: bool,
no_trans: bool,
no_asm_comments: bool,
debug_rustc: bool};
debug_rustc: bool,
borrowck: uint}; // 0=off,1=warn,2=err

type crate_metadata = {name: str, data: [u8]};

Expand Down Expand Up @@ -139,6 +140,7 @@ fn basic_options() -> @options {
no_trans: false,
no_asm_comments: false,
debug_rustc: false,
borrowck: 0u,
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/rustc/metadata/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,9 +844,10 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
}
}

option::iter(tcx.borrowings.find(id)) {|_i|
option::iter(tcx.borrowings.find(id)) {|s|
ebml_w.tag(c::tag_table_borrowings) {||
ebml_w.id(id);
ebml_w.wr_tagged_i64(c::tag_table_val as uint, s as i64);
}
}
}
Expand Down Expand Up @@ -919,8 +920,6 @@ fn decode_side_tables(xcx: extended_decode_ctxt,
dcx.maps.copy_map.insert(id, ());
} else if tag == (c::tag_table_spill as uint) {
dcx.maps.spill_map.insert(id, ());
} else if tag == (c::tag_table_borrowings as uint) {
dcx.tcx.borrowings.insert(id, ());
} else {
let val_doc = entry_doc[c::tag_table_val];
let val_dsr = ebml::ebml_deserializer(val_doc);
Expand Down Expand Up @@ -952,7 +951,10 @@ fn decode_side_tables(xcx: extended_decode_ctxt,
val_dsr.read_method_origin(xcx));
} else if tag == (c::tag_table_vtable_map as uint) {
dcx.maps.vtable_map.insert(id,
val_dsr.read_vtable_res(xcx));
val_dsr.read_vtable_res(xcx));
} else if tag == (c::tag_table_borrowings as uint) {
let scope_id = ebml::doc_as_i64(val_doc) as int;
dcx.tcx.borrowings.insert(id, scope_id);
} else {
xcx.dcx.tcx.sess.bug(
#fmt["unknown tag found in side tables: %x", tag]);
Expand Down
Loading

0 comments on commit 50a3dd4

Please sign in to comment.