Skip to content

Commit 50a3dd4

Browse files
committed
implement new borrow ck (disabled by default)
1 parent 5e7229b commit 50a3dd4

32 files changed

+2100
-311
lines changed

mk/target.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTSYNTAX): \
4949
$$(TCORELIB_DEFAULT$(1)_T_$(2)_H_$(3)) \
5050
$$(TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3))
5151
@$$(call E, compile_and_link: $$@)
52-
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@
52+
$$(STAGE$(1)_T_$(2)_H_$(3)) $(BORROWCK) -o $$@ $$< && touch $$@
5353

5454
endef
5555

src/rustc/driver/driver.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import session::session;
44
import syntax::parse;
55
import syntax::{ast, codemap};
66
import syntax::attr;
7-
import middle::{trans, resolve, freevars, kind, ty, typeck, fn_usage,
7+
import middle::{trans, resolve, freevars, kind, ty, typeck,
88
last_use, lint};
99
import syntax::print::{pp, pprust};
1010
import util::{ppaux, filesearch};
@@ -158,12 +158,13 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
158158
bind middle::block_use::check_crate(ty_cx, crate));
159159
time(time_passes, "loop checking",
160160
bind middle::check_loop::check_crate(ty_cx, crate));
161-
time(time_passes, "function usage",
162-
bind fn_usage::check_crate_fn_usage(ty_cx, crate));
163161
time(time_passes, "alt checking",
164162
bind middle::check_alt::check_crate(ty_cx, crate));
165163
time(time_passes, "typestate checking",
166164
bind middle::tstate::ck::check_crate(ty_cx, crate));
165+
let _root_map = time(
166+
time_passes, "borrow checking",
167+
bind middle::borrowck::check_crate(ty_cx, method_map, crate));
167168
let mutbl_map =
168169
time(time_passes, "mutability checking",
169170
bind middle::mutbl::check_crate(ty_cx, crate));
@@ -401,6 +402,14 @@ fn build_session_options(match: getopts::match,
401402
let target_opt = getopts::opt_maybe_str(match, "target");
402403
let mut no_asm_comments = getopts::opt_present(match, "no-asm-comments");
403404
let debug_rustc = getopts::opt_present(match, "debug-rustc");
405+
let borrowck = alt getopts::opt_maybe_str(match, "borrowck") {
406+
none { 0u }
407+
some("warn") { 1u }
408+
some("err") { 2u }
409+
some(_) {
410+
early_error(demitter, "borrowck may be warn or err")
411+
}
412+
};
404413
alt output_type {
405414
// unless we're emitting huamn-readable assembly, omit comments.
406415
link::output_type_llvm_assembly | link::output_type_assembly {}
@@ -455,7 +464,8 @@ fn build_session_options(match: getopts::match,
455464
parse_only: parse_only,
456465
no_trans: no_trans,
457466
no_asm_comments: no_asm_comments,
458-
debug_rustc: debug_rustc};
467+
debug_rustc: debug_rustc,
468+
borrowck: borrowck};
459469
ret sopts;
460470
}
461471

@@ -533,7 +543,8 @@ fn opts() -> [getopts::opt] {
533543
optmulti("cfg"), optflag("test"),
534544
optflag("lib"), optflag("bin"), optflag("static"), optflag("gc"),
535545
optflag("no-asm-comments"),
536-
optflag("debug-rustc")];
546+
optflag("debug-rustc"),
547+
optopt("borrowck")];
537548
}
538549

539550
type output_filenames = @{out_filename: str, obj_filename:str};

src/rustc/driver/session.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ type options =
4747
parse_only: bool,
4848
no_trans: bool,
4949
no_asm_comments: bool,
50-
debug_rustc: bool};
50+
debug_rustc: bool,
51+
borrowck: uint}; // 0=off,1=warn,2=err
5152

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

@@ -139,6 +140,7 @@ fn basic_options() -> @options {
139140
no_trans: false,
140141
no_asm_comments: false,
141142
debug_rustc: false,
143+
borrowck: 0u,
142144
}
143145
}
144146

src/rustc/metadata/astencode.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -844,9 +844,10 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
844844
}
845845
}
846846

847-
option::iter(tcx.borrowings.find(id)) {|_i|
847+
option::iter(tcx.borrowings.find(id)) {|s|
848848
ebml_w.tag(c::tag_table_borrowings) {||
849849
ebml_w.id(id);
850+
ebml_w.wr_tagged_i64(c::tag_table_val as uint, s as i64);
850851
}
851852
}
852853
}
@@ -919,8 +920,6 @@ fn decode_side_tables(xcx: extended_decode_ctxt,
919920
dcx.maps.copy_map.insert(id, ());
920921
} else if tag == (c::tag_table_spill as uint) {
921922
dcx.maps.spill_map.insert(id, ());
922-
} else if tag == (c::tag_table_borrowings as uint) {
923-
dcx.tcx.borrowings.insert(id, ());
924923
} else {
925924
let val_doc = entry_doc[c::tag_table_val];
926925
let val_dsr = ebml::ebml_deserializer(val_doc);
@@ -952,7 +951,10 @@ fn decode_side_tables(xcx: extended_decode_ctxt,
952951
val_dsr.read_method_origin(xcx));
953952
} else if tag == (c::tag_table_vtable_map as uint) {
954953
dcx.maps.vtable_map.insert(id,
955-
val_dsr.read_vtable_res(xcx));
954+
val_dsr.read_vtable_res(xcx));
955+
} else if tag == (c::tag_table_borrowings as uint) {
956+
let scope_id = ebml::doc_as_i64(val_doc) as int;
957+
dcx.tcx.borrowings.insert(id, scope_id);
956958
} else {
957959
xcx.dcx.tcx.sess.bug(
958960
#fmt["unknown tag found in side tables: %x", tag]);

0 commit comments

Comments
 (0)