Skip to content

Commit 4fa060d

Browse files
committed
WIP: Massive refactoring of trans
Fixes rust-lang#3387
1 parent b01d21b commit 4fa060d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+6178
-4889
lines changed

Makefile.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ endif
100100
ifdef TIME_LLVM_PASSES
101101
CFG_RUSTC_FLAGS += -Z time-llvm-passes
102102
endif
103+
ifdef TRACE
104+
CFG_RUSTC_FLAGS += -Z trace
105+
endif
103106

104107
# platform-specific auto-configuration
105108
include $(CFG_SRC_DIR)mk/platform.mk

src/libstd/getopts.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -767,10 +767,11 @@ mod tests {
767767
let rs = getopts(args, opts);
768768
match rs {
769769
Ok(m) => {
770-
assert (opt_present(m, ~"test"));
771-
assert (opt_str(m, ~"test") == ~"20");
772-
assert (opt_strs(m, ~"test")[0] == ~"20");
773-
assert (opt_strs(m, ~"test")[1] == ~"30");
770+
assert (opt_present(m, ~"test"));
771+
assert (opt_str(m, ~"test") == ~"20");
772+
let pair = opt_strs(m, ~"test");
773+
assert (pair[0] == ~"20");
774+
assert (pair[1] == ~"30");
774775
}
775776
_ => fail
776777
}
@@ -821,8 +822,9 @@ mod tests {
821822
Ok(m) => {
822823
assert (opt_present(m, ~"t"));
823824
assert (opt_str(m, ~"t") == ~"20");
824-
assert (opt_strs(m, ~"t")[0] == ~"20");
825-
assert (opt_strs(m, ~"t")[1] == ~"30");
825+
let pair = opt_strs(m, ~"t");
826+
assert (pair[0] == ~"20");
827+
assert (pair[1] == ~"30");
826828
}
827829
_ => fail
828830
}
@@ -870,10 +872,12 @@ mod tests {
870872
assert (opt_present(m, ~"flag"));
871873
assert (opt_str(m, ~"long") == ~"30");
872874
assert (opt_present(m, ~"f"));
873-
assert (opt_strs(m, ~"m")[0] == ~"40");
874-
assert (opt_strs(m, ~"m")[1] == ~"50");
875-
assert (opt_strs(m, ~"n")[0] == ~"-A B");
876-
assert (opt_strs(m, ~"n")[1] == ~"-60 70");
875+
let pair = opt_strs(m, ~"m");
876+
assert (pair[0] == ~"40");
877+
assert (pair[1] == ~"50");
878+
let pair = opt_strs(m, ~"n");
879+
assert (pair[0] == ~"-A B");
880+
assert (pair[1] == ~"-60 70");
877881
assert (!opt_present(m, ~"notpresent"));
878882
}
879883
_ => fail

src/libstd/test.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import libc::size_t;
1212
import task::TaskBuilder;
1313
import comm = core::comm;
1414

15+
/*
1516
export test_name;
1617
export test_fn;
1718
export test_desc;
@@ -22,6 +23,7 @@ export tr_ok;
2223
export tr_failed;
2324
export tr_ignored;
2425
export run_tests_console;
26+
*/
2527

2628
#[abi = "cdecl"]
2729
extern mod rustrt {

src/libsyntax/print/pprust.rs

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,29 +1165,38 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
11651165
None => ()
11661166
}
11671167
word_space(s, ~"=>");
1168+
11681169
// Extract the expression from the extra block the parser adds
1169-
assert arm.body.node.view_items.is_empty();
1170-
assert arm.body.node.stmts.is_empty();
1171-
assert arm.body.node.rules == ast::default_blk;
1172-
match arm.body.node.expr {
1173-
Some(expr) => {
1174-
match expr.node {
1175-
ast::expr_block(blk) => {
1176-
// the block will close the pattern's ibox
1177-
print_block_unclosed_indent(s, blk, alt_indent_unit);
1178-
}
1179-
_ => {
1180-
end(s); // close the ibox for the pattern
1181-
print_expr(s, expr);
1182-
}
1183-
}
1184-
if !expr_is_simple_block(expr)
1185-
&& i < len - 1 {
1186-
word(s.s, ~",");
1170+
// in the case of foo => expr
1171+
if arm.body.node.view_items.is_empty() &&
1172+
arm.body.node.stmts.is_empty() &&
1173+
arm.body.node.rules == ast::default_blk &&
1174+
arm.body.node.expr.is_some()
1175+
{
1176+
match arm.body.node.expr {
1177+
Some(expr) => {
1178+
match expr.node {
1179+
ast::expr_block(blk) => {
1180+
// the block will close the pattern's ibox
1181+
print_block_unclosed_indent(
1182+
s, blk, alt_indent_unit);
1183+
}
1184+
_ => {
1185+
end(s); // close the ibox for the pattern
1186+
print_expr(s, expr);
1187+
}
1188+
}
1189+
if !expr_is_simple_block(expr)
1190+
&& i < len - 1 {
1191+
word(s.s, ~",");
1192+
}
1193+
end(s); // close enclosing cbox
1194+
}
1195+
None => fail
11871196
}
1188-
end(s); // close enclosing cbox
1189-
}
1190-
None => fail
1197+
} else {
1198+
// the block will close the pattern's ibox
1199+
print_block_unclosed_indent(s, arm.body, alt_indent_unit);
11911200
}
11921201
}
11931202
bclose_(s, expr.span, alt_indent_unit);

src/rt/memory_region.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
//
2323
// NB: please do not commit code with level 2. It's
2424
// hugely expensive and should only be used as a last resort.
25-
#define RUSTRT_TRACK_ALLOCATIONS 0
25+
#define RUSTRT_TRACK_ALLOCATIONS 2
2626

2727
struct rust_env;
2828

src/rt/rust_upcall.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ extern "C" CDECL void
147147
upcall_s_exchange_malloc(s_exchange_malloc_args *args) {
148148
rust_task *task = args->task;
149149
LOG_UPCALL_ENTRY(task);
150-
LOG(task, mem, "upcall exchange malloc(0x%" PRIxPTR ")", args->td);
151150

152151
size_t total_size = get_box_size(args->size, args->td->align);
153152
// FIXME--does this have to be calloc? (Issue #2682)
@@ -159,6 +158,9 @@ upcall_s_exchange_malloc(s_exchange_malloc_args *args) {
159158
header->prev = 0;
160159
header->next = 0;
161160

161+
LOG(task, mem, "exchange malloced %p of size %" PRIuPTR,
162+
header, args->size);
163+
162164
args->retval = (uintptr_t)header;
163165
}
164166

@@ -187,6 +189,7 @@ extern "C" CDECL void
187189
upcall_s_exchange_free(s_exchange_free_args *args) {
188190
rust_task *task = args->task;
189191
LOG_UPCALL_ENTRY(task);
192+
LOG(task, mem, "exchange freed %p", args->ptr);
190193
task->kernel->free(args->ptr);
191194
}
192195

src/rustc/middle/borrowck.rs

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ import syntax::visit;
220220
import syntax::ast_util;
221221
import syntax::ast_map;
222222
import syntax::codemap::span;
223-
import util::ppaux::{ty_to_str, region_to_str, explain_region};
223+
import util::ppaux::{ty_to_str, region_to_str, explain_region,
224+
note_and_explain_region};
224225
import std::map::{int_hash, hashmap, set};
225226
import std::list;
226227
import std::list::{list, cons, nil};
@@ -414,6 +415,7 @@ impl borrowck_ctxt {
414415
err.cmt.span,
415416
fmt!("illegal borrow: %s",
416417
self.bckerr_code_to_str(err.code)));
418+
self.note_and_explain_bckerr(err.code);
417419
}
418420

419421
fn span_err(s: span, m: ~str) {
@@ -438,37 +440,65 @@ impl borrowck_ctxt {
438440

439441
fn bckerr_code_to_str(code: bckerr_code) -> ~str {
440442
match code {
441-
err_mutbl(req, act) => {
442-
fmt!("creating %s alias to aliasable, %s memory",
443-
self.mut_to_str(req), self.mut_to_str(act))
444-
}
445-
err_mut_uniq => {
446-
~"unique value in aliasable, mutable location"
447-
}
448-
err_mut_variant => {
449-
~"enum variant in aliasable, mutable location"
450-
}
451-
err_root_not_permitted => {
452-
// note: I don't expect users to ever see this error
453-
// message, reasons are discussed in attempt_root() in
454-
// preserve.rs.
455-
~"rooting is not permitted"
456-
}
457-
err_out_of_root_scope(super_scope, sub_scope) => {
458-
fmt!("managed value would have to be rooted for %s, \
459-
but can only be rooted for %s",
460-
explain_region(self.tcx, sub_scope),
461-
explain_region(self.tcx, super_scope))
462-
}
463-
err_out_of_scope(super_scope, sub_scope) => {
464-
fmt!("borrowed pointer must be valid for %s, \
465-
but the borrowed value is only valid for %s",
466-
explain_region(self.tcx, sub_scope),
467-
explain_region(self.tcx, super_scope))
443+
err_mutbl(req, act) => {
444+
fmt!("creating %s alias to aliasable, %s memory",
445+
self.mut_to_str(req), self.mut_to_str(act))
446+
}
447+
err_mut_uniq => {
448+
~"unique value in aliasable, mutable location"
449+
}
450+
err_mut_variant => {
451+
~"enum variant in aliasable, mutable location"
452+
}
453+
err_root_not_permitted => {
454+
// note: I don't expect users to ever see this error
455+
// message, reasons are discussed in attempt_root() in
456+
// preserve.rs.
457+
~"rooting is not permitted"
458+
}
459+
err_out_of_root_scope(*) => {
460+
~"cannot root managed value long enough"
461+
}
462+
err_out_of_scope(*) => {
463+
~"borrowed value does not live long enough"
464+
}
465+
}
466+
}
467+
468+
fn note_and_explain_bckerr(code: bckerr_code) {
469+
match code {
470+
err_mutbl(*) | err_mut_uniq | err_mut_variant |
471+
err_root_not_permitted => {}
472+
473+
err_out_of_root_scope(super_scope, sub_scope) => {
474+
note_and_explain_region(
475+
self.tcx,
476+
~"managed value would have to be rooted for ",
477+
sub_scope,
478+
~"...");
479+
note_and_explain_region(
480+
self.tcx,
481+
~"...but can only be rooted for ",
482+
super_scope,
483+
~"");
484+
}
485+
486+
err_out_of_scope(super_scope, sub_scope) => {
487+
note_and_explain_region(
488+
self.tcx,
489+
~"borrowed pointer must be valid for ",
490+
sub_scope,
491+
~"...");
492+
note_and_explain_region(
493+
self.tcx,
494+
~"...but borrowed value is only valid for ",
495+
super_scope,
496+
~"");
468497
}
469498
}
470499
}
471500

501+
472502
fn cmt_to_str(cmt: cmt) -> ~str {
473503
let mc = &mem_categorization_ctxt {tcx: self.tcx,
474504
method_map: self.method_map};

src/rustc/middle/borrowck/check_loans.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ impl check_loan_ctxt {
404404
e.cmt.span,
405405
fmt!("illegal borrow unless pure: %s",
406406
self.bccx.bckerr_code_to_str(e.code)));
407+
self.bccx.note_and_explain_bckerr(e.code);
407408
self.tcx().sess.span_note(
408409
sp,
409410
fmt!("impure due to %s", msg));
@@ -465,10 +466,14 @@ impl check_loan_ctxt {
465466
// when there is an outstanding loan. In that case, it is not
466467
// safe to consider the use a last_use.
467468
fn check_last_use(expr: @ast::expr) {
469+
debug!("Checking last use of expr %?", expr.id);
468470
let cmt = self.bccx.cat_expr(expr);
469471
let lp = match cmt.lp {
470-
None => return,
471-
Some(lp) => lp
472+
None => {
473+
debug!("Not a loanable expression");
474+
return;
475+
}
476+
Some(lp) => lp
472477
};
473478
for self.walk_loans_of(cmt.id, lp) |_loan| {
474479
debug!("Removing last use entry %? due to outstanding loan",
@@ -573,6 +578,9 @@ fn check_loans_in_local(local: @ast::local,
573578
fn check_loans_in_expr(expr: @ast::expr,
574579
&&self: check_loan_ctxt,
575580
vt: visit::vt<check_loan_ctxt>) {
581+
debug!("check_loans_in_expr(expr=%?/%s)",
582+
expr.id, pprust::expr_to_str(expr, self.tcx().sess.intr()));
583+
576584
self.check_for_conflicting_loans(expr.id);
577585

578586
match expr.node {

src/rustc/middle/borrowck/gather_loans.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ fn req_loans_in_expr(ex: @ast::expr,
9090
let tcx = bccx.tcx;
9191
let old_root_ub = self.root_ub;
9292

93-
debug!("req_loans_in_expr(ex=%s)",
94-
pprust::expr_to_str(ex, tcx.sess.intr()));
93+
debug!("req_loans_in_expr(expr=%?/%s)",
94+
ex.id, pprust::expr_to_str(ex, tcx.sess.intr()));
9595

9696
// If this expression is borrowed, have to ensure it remains valid:
9797
for tcx.borrowings.find(ex.id).each |borrow| {
@@ -200,6 +200,20 @@ fn req_loans_in_expr(ex: @ast::expr,
200200
visit::visit_expr(ex, self, vt);
201201
}
202202

203+
ast::expr_binary(_, lhs, rhs) => {
204+
// Universal comparison operators like ==, >=, etc
205+
// take their arguments by reference.
206+
let lhs_ty = ty::expr_ty(self.tcx(), lhs);
207+
if !ty::type_is_scalar(lhs_ty) {
208+
let scope_r = ty::re_scope(ex.id);
209+
let lhs_cmt = self.bccx.cat_expr(lhs);
210+
self.guarantee_valid(lhs_cmt, m_imm, scope_r);
211+
let rhs_cmt = self.bccx.cat_expr(rhs);
212+
self.guarantee_valid(rhs_cmt, m_imm, scope_r);
213+
}
214+
visit::visit_expr(ex, self, vt);
215+
}
216+
203217
ast::expr_field(rcvr, _, _)
204218
if self.bccx.method_map.contains_key(ex.id) => {
205219
// Receivers in method calls are always passed by ref.
@@ -395,14 +409,15 @@ impl gather_loan_ctxt {
395409
}
396410

397411
fn add_loans(scope_id: ast::node_id, loans: @DVec<loan>) {
412+
debug!("adding %u loans to scope_id %?", loans.len(), scope_id);
398413
match self.req_maps.req_loan_map.find(scope_id) {
399-
Some(l) => {
400-
(*l).push(loans);
401-
}
402-
None => {
403-
self.req_maps.req_loan_map.insert(
404-
scope_id, @dvec::from_vec(~[mut loans]));
405-
}
414+
Some(l) => {
415+
l.push(loans);
416+
}
417+
None => {
418+
self.req_maps.req_loan_map.insert(
419+
scope_id, @dvec::from_vec(~[mut loans]));
420+
}
406421
}
407422
}
408423

src/rustc/middle/kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ fn is_nullary_variant(cx: ctx, ex: @expr) -> bool {
419419

420420
fn check_copy_ex(cx: ctx, ex: @expr, implicit_copy: bool,
421421
why: Option<(&str,&str)>) {
422-
if ty::expr_is_lval(cx.method_map, ex) &&
422+
if ty::expr_is_lval(cx.tcx, cx.method_map, ex) &&
423423

424424
// this is a move
425425
!cx.last_use_map.contains_key(ex.id) &&

0 commit comments

Comments
 (0)