Skip to content

Commit 5e36a99

Browse files
committed
Refactor trans to replace lvalue and friends with Datum.
Also: - report illegal move/ref combos whether or not ref comes first - commented out fix for #3387, too restrictive and causes an ICE
1 parent adc1427 commit 5e36a99

Some content is hidden

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

53 files changed

+6456
-5110
lines changed

Makefile.in

+3
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/libcore/util.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ mod tests {
6565
fn identity_crisis() {
6666
// Writing a test for the identity function. How did it come to this?
6767
let x = ~[(5, false)];
68-
assert x.eq(id(copy x));
68+
//FIXME #3387 assert x.eq(id(copy x));
69+
let y = copy x;
70+
assert x.eq(id(y));
6971
}
7072
#[test]
7173
fn test_swap() {

src/libstd/getopts.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -800,10 +800,11 @@ mod tests {
800800
let rs = getopts(args, opts);
801801
match rs {
802802
Ok(m) => {
803-
assert (opt_present(m, ~"test"));
804-
assert (opt_str(m, ~"test") == ~"20");
805-
assert (opt_strs(m, ~"test")[0] == ~"20");
806-
assert (opt_strs(m, ~"test")[1] == ~"30");
803+
assert (opt_present(m, ~"test"));
804+
assert (opt_str(m, ~"test") == ~"20");
805+
let pair = opt_strs(m, ~"test");
806+
assert (pair[0] == ~"20");
807+
assert (pair[1] == ~"30");
807808
}
808809
_ => fail
809810
}
@@ -854,8 +855,9 @@ mod tests {
854855
Ok(m) => {
855856
assert (opt_present(m, ~"t"));
856857
assert (opt_str(m, ~"t") == ~"20");
857-
assert (opt_strs(m, ~"t")[0] == ~"20");
858-
assert (opt_strs(m, ~"t")[1] == ~"30");
858+
let pair = opt_strs(m, ~"t");
859+
assert (pair[0] == ~"20");
860+
assert (pair[1] == ~"30");
859861
}
860862
_ => fail
861863
}
@@ -903,10 +905,12 @@ mod tests {
903905
assert (opt_present(m, ~"flag"));
904906
assert (opt_str(m, ~"long") == ~"30");
905907
assert (opt_present(m, ~"f"));
906-
assert (opt_strs(m, ~"m")[0] == ~"40");
907-
assert (opt_strs(m, ~"m")[1] == ~"50");
908-
assert (opt_strs(m, ~"n")[0] == ~"-A B");
909-
assert (opt_strs(m, ~"n")[1] == ~"-60 70");
908+
let pair = opt_strs(m, ~"m");
909+
assert (pair[0] == ~"40");
910+
assert (pair[1] == ~"50");
911+
let pair = opt_strs(m, ~"n");
912+
assert (pair[0] == ~"-A B");
913+
assert (pair[1] == ~"-60 70");
910914
assert (!opt_present(m, ~"notpresent"));
911915
}
912916
_ => fail

src/libstd/par.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const min_granularity : uint = 1024u;
1919
* like map or alli.
2020
*/
2121
fn map_slices<A: copy send, B: copy send>(
22-
xs: ~[A],
22+
xs: &[A],
2323
f: fn() -> fn~(uint, v: &[A]) -> B)
2424
-> ~[B] {
2525

@@ -104,7 +104,7 @@ fn mapi<A: copy send, B: copy send>(xs: ~[A],
104104
* inner elements. This is to skirt the need for copy constructors.
105105
*/
106106
fn mapi_factory<A: copy send, B: copy send>(
107-
xs: ~[A], f: fn() -> fn~(uint, A) -> B) -> ~[B] {
107+
xs: &[A], f: fn() -> fn~(uint, A) -> B) -> ~[B] {
108108
let slices = map_slices(xs, || {
109109
let f = f();
110110
fn~(base: uint, slice : &[A], move f) -> ~[B] {

src/libsyntax/print/pprust.rs

+30-21
Original file line numberDiff line numberDiff line change
@@ -1169,29 +1169,38 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
11691169
None => ()
11701170
}
11711171
word_space(s, ~"=>");
1172+
11721173
// Extract the expression from the extra block the parser adds
1173-
assert arm.body.node.view_items.is_empty();
1174-
assert arm.body.node.stmts.is_empty();
1175-
assert arm.body.node.rules == ast::default_blk;
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(s, blk, alt_indent_unit);
1182-
}
1183-
_ => {
1184-
end(s); // close the ibox for the pattern
1185-
print_expr(s, expr);
1186-
}
1187-
}
1188-
if !expr_is_simple_block(expr)
1189-
&& i < len - 1 {
1190-
word(s.s, ~",");
1174+
// in the case of foo => expr
1175+
if arm.body.node.view_items.is_empty() &&
1176+
arm.body.node.stmts.is_empty() &&
1177+
arm.body.node.rules == ast::default_blk &&
1178+
arm.body.node.expr.is_some()
1179+
{
1180+
match arm.body.node.expr {
1181+
Some(expr) => {
1182+
match expr.node {
1183+
ast::expr_block(blk) => {
1184+
// the block will close the pattern's ibox
1185+
print_block_unclosed_indent(
1186+
s, blk, alt_indent_unit);
1187+
}
1188+
_ => {
1189+
end(s); // close the ibox for the pattern
1190+
print_expr(s, expr);
1191+
}
1192+
}
1193+
if !expr_is_simple_block(expr)
1194+
&& i < len - 1 {
1195+
word(s.s, ~",");
1196+
}
1197+
end(s); // close enclosing cbox
1198+
}
1199+
None => fail
11911200
}
1192-
end(s); // close enclosing cbox
1193-
}
1194-
None => fail
1201+
} else {
1202+
// the block will close the pattern's ibox
1203+
print_block_unclosed_indent(s, arm.body, alt_indent_unit);
11951204
}
11961205
}
11971206
bclose_(s, expr.span, alt_indent_unit);

src/rt/rust_upcall.cpp

+4-1
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/lib/llvm.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,11 @@ extern mod llvm {
456456
ValueRef;
457457
fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
458458
ValueRef;
459-
fn LLVMConstGEP(ConstantVal: ValueRef, ConstantIndices: *uint,
459+
fn LLVMConstGEP(ConstantVal: ValueRef,
460+
ConstantIndices: *ValueRef,
460461
NumIndices: c_uint) -> ValueRef;
461-
fn LLVMConstInBoundsGEP(ConstantVal: ValueRef, ConstantIndices: *uint,
462+
fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
463+
ConstantIndices: *ValueRef,
462464
NumIndices: c_uint) -> ValueRef;
463465
fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
464466
fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
@@ -493,10 +495,10 @@ extern mod llvm {
493495
fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
494496
VectorBConstant: ValueRef,
495497
MaskConstant: ValueRef) -> ValueRef;
496-
fn LLVMConstExtractValue(AggConstant: ValueRef, IdxList: *uint,
498+
fn LLVMConstExtractValue(AggConstant: ValueRef, IdxList: *c_uint,
497499
NumIdx: c_uint) -> ValueRef;
498500
fn LLVMConstInsertValue(AggConstant: ValueRef,
499-
ElementValueConstant: ValueRef, IdxList: *uint,
501+
ElementValueConstant: ValueRef, IdxList: *c_uint,
500502
NumIdx: c_uint) -> ValueRef;
501503
fn LLVMConstInlineAsm(Ty: TypeRef, AsmString: *c_char,
502504
Constraints: *c_char, HasSideEffects: Bool,

src/rustc/middle/borrowck.rs

+58-28
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ use syntax::visit;
220220
use syntax::ast_util;
221221
use syntax::ast_map;
222222
use syntax::codemap::span;
223-
use util::ppaux::{ty_to_str, region_to_str, explain_region};
223+
use util::ppaux::{ty_to_str, region_to_str, explain_region,
224+
note_and_explain_region};
224225
use std::map::{int_hash, hashmap, set};
225226
use std::list;
226227
use std::list::{List, Cons, Nil};
@@ -464,6 +465,7 @@ impl borrowck_ctxt {
464465
err.cmt.span,
465466
fmt!("illegal borrow: %s",
466467
self.bckerr_code_to_str(err.code)));
468+
self.note_and_explain_bckerr(err.code);
467469
}
468470

469471
fn span_err(s: span, m: ~str) {
@@ -488,37 +490,65 @@ impl borrowck_ctxt {
488490

489491
fn bckerr_code_to_str(code: bckerr_code) -> ~str {
490492
match code {
491-
err_mutbl(req, act) => {
492-
fmt!("creating %s alias to aliasable, %s memory",
493-
self.mut_to_str(req), self.mut_to_str(act))
494-
}
495-
err_mut_uniq => {
496-
~"unique value in aliasable, mutable location"
497-
}
498-
err_mut_variant => {
499-
~"enum variant in aliasable, mutable location"
500-
}
501-
err_root_not_permitted => {
502-
// note: I don't expect users to ever see this error
503-
// message, reasons are discussed in attempt_root() in
504-
// preserve.rs.
505-
~"rooting is not permitted"
506-
}
507-
err_out_of_root_scope(super_scope, sub_scope) => {
508-
fmt!("managed value would have to be rooted for %s, \
509-
but can only be rooted for %s",
510-
explain_region(self.tcx, sub_scope),
511-
explain_region(self.tcx, super_scope))
512-
}
513-
err_out_of_scope(super_scope, sub_scope) => {
514-
fmt!("borrowed pointer must be valid for %s, \
515-
but the borrowed value is only valid for %s",
516-
explain_region(self.tcx, sub_scope),
517-
explain_region(self.tcx, super_scope))
493+
err_mutbl(req, act) => {
494+
fmt!("creating %s alias to aliasable, %s memory",
495+
self.mut_to_str(req), self.mut_to_str(act))
496+
}
497+
err_mut_uniq => {
498+
~"unique value in aliasable, mutable location"
499+
}
500+
err_mut_variant => {
501+
~"enum variant in aliasable, mutable location"
502+
}
503+
err_root_not_permitted => {
504+
// note: I don't expect users to ever see this error
505+
// message, reasons are discussed in attempt_root() in
506+
// preserve.rs.
507+
~"rooting is not permitted"
508+
}
509+
err_out_of_root_scope(*) => {
510+
~"cannot root managed value long enough"
511+
}
512+
err_out_of_scope(*) => {
513+
~"borrowed value does not live long enough"
514+
}
515+
}
516+
}
517+
518+
fn note_and_explain_bckerr(code: bckerr_code) {
519+
match code {
520+
err_mutbl(*) | err_mut_uniq | err_mut_variant |
521+
err_root_not_permitted => {}
522+
523+
err_out_of_root_scope(super_scope, sub_scope) => {
524+
note_and_explain_region(
525+
self.tcx,
526+
~"managed value would have to be rooted for ",
527+
sub_scope,
528+
~"...");
529+
note_and_explain_region(
530+
self.tcx,
531+
~"...but can only be rooted for ",
532+
super_scope,
533+
~"");
534+
}
535+
536+
err_out_of_scope(super_scope, sub_scope) => {
537+
note_and_explain_region(
538+
self.tcx,
539+
~"borrowed pointer must be valid for ",
540+
sub_scope,
541+
~"...");
542+
note_and_explain_region(
543+
self.tcx,
544+
~"...but borrowed value is only valid for ",
545+
super_scope,
546+
~"");
518547
}
519548
}
520549
}
521550

551+
522552
fn cmt_to_str(cmt: cmt) -> ~str {
523553
let mc = &mem_categorization_ctxt {tcx: self.tcx,
524554
method_map: self.method_map};

src/rustc/middle/borrowck/check_loans.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ impl check_loan_ctxt {
423423
e.cmt.span,
424424
fmt!("illegal borrow unless pure: %s",
425425
self.bccx.bckerr_code_to_str(e.code)));
426+
self.bccx.note_and_explain_bckerr(e.code);
426427
self.tcx().sess.span_note(
427428
sp,
428429
fmt!("impure due to %s", msg));
@@ -484,10 +485,14 @@ impl check_loan_ctxt {
484485
// when there is an outstanding loan. In that case, it is not
485486
// safe to consider the use a last_use.
486487
fn check_last_use(expr: @ast::expr) {
488+
debug!("Checking last use of expr %?", expr.id);
487489
let cmt = self.bccx.cat_expr(expr);
488490
let lp = match cmt.lp {
489-
None => return,
490-
Some(lp) => lp
491+
None => {
492+
debug!("Not a loanable expression");
493+
return;
494+
}
495+
Some(lp) => lp
491496
};
492497
for self.walk_loans_of(cmt.id, lp) |_loan| {
493498
debug!("Removing last use entry %? due to outstanding loan",
@@ -592,6 +597,9 @@ fn check_loans_in_local(local: @ast::local,
592597
fn check_loans_in_expr(expr: @ast::expr,
593598
&&self: check_loan_ctxt,
594599
vt: visit::vt<check_loan_ctxt>) {
600+
debug!("check_loans_in_expr(expr=%?/%s)",
601+
expr.id, pprust::expr_to_str(expr, self.tcx().sess.intr()));
602+
595603
self.check_for_conflicting_loans(expr.id);
596604

597605
match expr.node {

src/rustc/middle/borrowck/gather_loans.rs

+25-9
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,21 @@ fn req_loans_in_expr(ex: @ast::expr,
200200
visit::visit_expr(ex, self, vt);
201201
}
202202

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

397412
fn add_loans(scope_id: ast::node_id, loans: @DVec<loan>) {
413+
debug!("adding %u loans to scope_id %?", loans.len(), scope_id);
398414
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-
}
415+
Some(l) => {
416+
l.push(loans);
417+
}
418+
None => {
419+
self.req_maps.req_loan_map.insert(
420+
scope_id, @dvec::from_vec(~[mut loans]));
421+
}
406422
}
407423
}
408424

0 commit comments

Comments
 (0)