Skip to content

Commit 80e7d3b

Browse files
committed
---
yaml --- r: 20727 b: refs/heads/snap-stage3 c: 5d32d03 h: refs/heads/master i: 20725: c335e5b 20723: ea7776a 20719: 53d1509 v: v3
1 parent f34733c commit 80e7d3b

35 files changed

+720
-323
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: e430a699f2c60890d9b86069fd0c68a70ece7120
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 6ef13e76e95ea67103a2bc4f4becc91dc290aafc
4+
refs/heads/snap-stage3: 5d32d03b892d67f2cc0574966b50b3eab4b8bd94
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/rustc/middle/astencode.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -436,21 +436,6 @@ impl of tr for method_origin {
436436
}
437437
}
438438

439-
// ______________________________________________________________________
440-
// Encoding and decoding of borrow
441-
442-
trait read_borrow_helper {
443-
fn read_borrow(xcx: extended_decode_ctxt) -> ty::borrow;
444-
}
445-
446-
impl helper of read_borrow_helper for ebml::ebml_deserializer {
447-
fn read_borrow(xcx: extended_decode_ctxt) -> ty::borrow {
448-
let borrow = ty::deserialize_borrow(self);
449-
{scope_id: xcx.tr_id(borrow.scope_id),
450-
mutbl: borrow.mutbl}
451-
}
452-
}
453-
454439
// ______________________________________________________________________
455440
// Encoding and decoding vtable_res
456441

@@ -766,11 +751,13 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
766751
}
767752
}
768753

769-
do option::iter(tcx.borrowings.find(id)) |borrow| {
754+
do option::iter(tcx.borrowings.find(id)) |_borrow| {
770755
do ebml_w.tag(c::tag_table_borrowings) {
771756
ebml_w.id(id);
772757
do ebml_w.tag(c::tag_table_val) {
773-
ty::serialize_borrow(ebml_w, borrow)
758+
// N.B. We don't actually serialize borrows as, in
759+
// trans, we only care whether a value is borrowed or
760+
// not.
774761
}
775762
}
776763
}
@@ -890,7 +877,10 @@ fn decode_side_tables(xcx: extended_decode_ctxt,
890877
dcx.maps.vtable_map.insert(id,
891878
val_dsr.read_vtable_res(xcx));
892879
} else if tag == (c::tag_table_borrowings as uint) {
893-
let borrow = val_dsr.read_borrow(xcx);
880+
// N.B.: we don't actually *serialize* borrows because, in
881+
// trans, the only thing we care about is whether a value was
882+
// borrowed or not.
883+
let borrow = {region: ty::re_static, mutbl: ast::m_imm};
894884
dcx.tcx.borrowings.insert(id, borrow);
895885
} else {
896886
xcx.dcx.tcx.sess.bug(

branches/snap-stage3/src/rustc/middle/borrowck.rs

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,10 @@ type binding_map = std::map::hashmap<ast::node_id, ast::mutability>;
321321
enum bckerr_code {
322322
err_mut_uniq,
323323
err_mut_variant,
324-
err_preserve_gc,
325-
err_mutbl(ast::mutability,
326-
ast::mutability)
324+
err_root_not_permitted,
325+
err_mutbl(ast::mutability, ast::mutability),
326+
err_out_of_root_scope(ty::region, ty::region), // superscope, subscope
327+
err_out_of_scope(ty::region, ty::region) // superscope, subscope
327328
}
328329

329330
// Combination of an error code and the categorization of the expression
@@ -346,7 +347,7 @@ enum categorization {
346347
}
347348

348349
// different kinds of pointers:
349-
enum ptr_kind {uniq_ptr, gc_ptr, region_ptr, unsafe_ptr}
350+
enum ptr_kind {uniq_ptr, gc_ptr, region_ptr(ty::region), unsafe_ptr}
350351

351352
// I am coining the term "components" to mean "pieces of a data
352353
// structure accessible without a dereference":
@@ -391,10 +392,15 @@ enum loan_path {
391392
lp_comp(@loan_path, comp_kind)
392393
}
393394

394-
// a complete record of a loan that was granted
395+
/// a complete record of a loan that was granted
395396
type loan = {lp: @loan_path, cmt: cmt, mutbl: ast::mutability};
396397

397-
// maps computed by `gather_loans` that are then used by `check_loans`
398+
/// maps computed by `gather_loans` that are then used by `check_loans`
399+
///
400+
/// - `req_loan_map`: map from each block/expr to the required loans needed
401+
/// for the duration of that block/expr
402+
/// - `pure_map`: map from block/expr that must be pure to the error message
403+
/// that should be reported if they are not pure
398404
type req_maps = {
399405
req_loan_map: hashmap<ast::node_id, @dvec<@dvec<loan>>>,
400406
pure_map: hashmap<ast::node_id, bckerr>
@@ -519,7 +525,7 @@ impl to_str_methods for borrowck_ctxt {
519525
alt ptr {
520526
uniq_ptr { ~"~" }
521527
gc_ptr { ~"@" }
522-
region_ptr { ~"&" }
528+
region_ptr(_) { ~"&" }
523529
unsafe_ptr { ~"*" }
524530
}
525531
}
@@ -561,15 +567,6 @@ impl to_str_methods for borrowck_ctxt {
561567
ty_to_str(self.tcx, cmt.ty)]
562568
}
563569

564-
fn pk_to_sigil(pk: ptr_kind) -> ~str {
565-
alt pk {
566-
uniq_ptr {~"~"}
567-
gc_ptr {~"@"}
568-
region_ptr {~"&"}
569-
unsafe_ptr {~"*"}
570-
}
571-
}
572-
573570
fn cmt_to_str(cmt: cmt) -> ~str {
574571
let mut_str = self.mut_to_str(cmt.mutbl);
575572
alt cmt.cat {
@@ -584,7 +581,7 @@ impl to_str_methods for borrowck_ctxt {
584581
cat_binding(_) { ~"pattern binding" }
585582
cat_arg(_) { ~"argument" }
586583
cat_deref(_, _, pk) { #fmt["dereference of %s %s pointer",
587-
mut_str, self.pk_to_sigil(pk)] }
584+
mut_str, self.ptr_sigil(pk)] }
588585
cat_stack_upvar(_) {
589586
~"captured outer " + mut_str + ~" variable in a stack closure"
590587
}
@@ -622,12 +619,30 @@ impl to_str_methods for borrowck_ctxt {
622619
err_mut_variant {
623620
~"enum variant in aliasable, mutable location"
624621
}
625-
err_preserve_gc {
626-
~"GC'd value would have to be preserved for longer \
627-
than the scope of the function"
622+
err_root_not_permitted {
623+
// note: I don't expect users to ever see this error
624+
// message, reasons are discussed in attempt_root() in
625+
// preserve.rs.
626+
~"rooting is not permitted"
627+
}
628+
err_out_of_root_scope(super_scope, sub_scope) {
629+
#fmt["managed value would have to be rooted for lifetime %s, \
630+
but can only be rooted for lifetime %s",
631+
self.region_to_str(sub_scope),
632+
self.region_to_str(super_scope)]
633+
}
634+
err_out_of_scope(super_scope, sub_scope) {
635+
#fmt["borrowed pointer has lifetime %s, \
636+
but the borrowed value only has lifetime %s",
637+
self.region_to_str(sub_scope),
638+
self.region_to_str(super_scope)]
628639
}
629640
}
630641
}
642+
643+
fn region_to_str(r: ty::region) -> ~str {
644+
region_to_str(self.tcx, r)
645+
}
631646
}
632647

633648
// The inherent mutability of a component is its default mutability

branches/snap-stage3/src/rustc/middle/borrowck/categorization.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ fn opt_deref_kind(t: ty::t) -> option<deref_kind> {
5050
some(deref_ptr(uniq_ptr))
5151
}
5252

53-
ty::ty_rptr(*) |
54-
ty::ty_evec(_, ty::vstore_slice(_)) |
55-
ty::ty_estr(ty::vstore_slice(_)) {
56-
some(deref_ptr(region_ptr))
53+
ty::ty_rptr(r, _) |
54+
ty::ty_evec(_, ty::vstore_slice(r)) |
55+
ty::ty_estr(ty::vstore_slice(r)) {
56+
some(deref_ptr(region_ptr(r)))
5757
}
5858

5959
ty::ty_box(*) |
@@ -343,7 +343,7 @@ impl public_methods for borrowck_ctxt {
343343
// not loanable.
344344
alt ptr {
345345
uniq_ptr => {some(@lp_deref(l, ptr))}
346-
gc_ptr | region_ptr | unsafe_ptr => {none}
346+
gc_ptr | region_ptr(_) | unsafe_ptr => {none}
347347
}
348348
};
349349

@@ -353,7 +353,7 @@ impl public_methods for borrowck_ctxt {
353353
uniq_ptr => {
354354
self.inherited_mutability(base_cmt.mutbl, mt.mutbl)
355355
}
356-
gc_ptr | region_ptr | unsafe_ptr => {
356+
gc_ptr | region_ptr(_) | unsafe_ptr => {
357357
mt.mutbl
358358
}
359359
};
@@ -402,7 +402,7 @@ impl public_methods for borrowck_ctxt {
402402
uniq_ptr => {
403403
self.inherited_mutability(base_cmt.mutbl, mt.mutbl)
404404
}
405-
gc_ptr | region_ptr | unsafe_ptr => {
405+
gc_ptr | region_ptr(_) | unsafe_ptr => {
406406
mt.mutbl
407407
}
408408
};

0 commit comments

Comments
 (0)