about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2013-03-16 11:11:31 -0700
committerPatrick Walton <pcwalton@mimiga.net>2013-03-18 17:21:16 -0700
commite78f2e2ac577f9c47cd58af52d3bcd496254545d (patch)
treef05564837fe02f676458ea86b705709715c44017 /src/libsyntax
parentc4db4faefaf13ac814f34c2a6cf105b7684de019 (diff)
downloadrust-e78f2e2ac577f9c47cd58af52d3bcd496254545d.tar.gz
rust-e78f2e2ac577f9c47cd58af52d3bcd496254545d.zip
librustc: Make the compiler ignore purity.
For bootstrapping purposes, this commit does not remove all uses of
the keyword "pure" -- doing so would cause the compiler to no longer
bootstrap due to some syntax extensions ("deriving" in particular).
Instead, it makes the compiler ignore "pure". Post-snapshot, we can
remove "pure" from the language.

There are quite a few (~100) borrow check errors that were essentially
all the result of mutable fields or partial borrows of `@mut`. Per
discussions with Niko I think we want to allow partial borrows of
`@mut` but detect obvious footguns. We should also improve the error
message when `@mut` is erroneously reborrowed.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/codemap.rs22
-rw-r--r--src/libsyntax/ext/deriving.rs4
-rw-r--r--src/libsyntax/ext/pipes/check.rs3
-rw-r--r--src/libsyntax/ext/pipes/liveness.rs4
-rw-r--r--src/libsyntax/ext/pipes/proto.rs8
-rw-r--r--src/libsyntax/ext/tt/transcribe.rs33
-rw-r--r--src/libsyntax/parse/lexer.rs4
-rw-r--r--src/libsyntax/parse/parser.rs15
-rw-r--r--src/libsyntax/print/pp.rs8
-rw-r--r--src/libsyntax/print/pprust.rs5
-rw-r--r--src/libsyntax/util/interner.rs10
11 files changed, 75 insertions, 41 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs
index 97719a140a6..538f0de8c84 100644
--- a/src/libsyntax/codemap.rs
+++ b/src/libsyntax/codemap.rs
@@ -252,8 +252,8 @@ pub impl FileMap {
     // about what ends a line between this file and parse.rs
     fn next_line(&self, +pos: BytePos) {
         // the new charpos must be > the last one (or it's the first one).
-        fail_unless!((self.lines.len() == 0)
-                || (self.lines[self.lines.len() - 1] < pos));
+        let lines = &mut *self.lines;
+        fail_unless!((lines.len() == 0) || (lines[lines.len() - 1] < pos));
         self.lines.push(pos);
     }
 
@@ -302,11 +302,12 @@ pub impl CodeMap {
         +substr: FileSubstr,
         src: @~str
     ) -> @FileMap {
-        let start_pos = if self.files.len() == 0 {
+        let files = &mut *self.files;
+        let start_pos = if files.len() == 0 {
             0
         } else {
-            let last_start = self.files.last().start_pos.to_uint();
-            let last_len = self.files.last().src.len();
+            let last_start = files.last().start_pos.to_uint();
+            let last_len = files.last().src.len();
             last_start + last_len
         };
 
@@ -364,7 +365,8 @@ pub impl CodeMap {
     }
 
     pub fn span_to_str(&self, sp: span) -> ~str {
-        if self.files.len() == 0 && sp == dummy_sp() {
+        let files = &mut *self.files;
+        if files.len() == 0 && sp == dummy_sp() {
             return ~"no-location";
         }
 
@@ -409,7 +411,8 @@ pub impl CodeMap {
 priv impl CodeMap {
 
     fn lookup_filemap_idx(&self, +pos: BytePos) -> uint {
-        let len = self.files.len();
+        let files = &*self.files;
+        let len = files.len();
         let mut a = 0u;
         let mut b = len;
         while b - a > 1u {
@@ -433,10 +436,11 @@ priv impl CodeMap {
         let idx = self.lookup_filemap_idx(pos);
         let f = self.files[idx];
         let mut a = 0u;
-        let mut b = f.lines.len();
+        let lines = &*f.lines;
+        let mut b = lines.len();
         while b - a > 1u {
             let m = (a + b) / 2u;
-            if f.lines[m] > pos { b = m; } else { a = m; }
+            if lines[m] > pos { b = m; } else { a = m; }
         }
         return FileMapAndLine {fm: f, line: a};
     }
diff --git a/src/libsyntax/ext/deriving.rs b/src/libsyntax/ext/deriving.rs
index 54b123bff2f..76ab21f403b 100644
--- a/src/libsyntax/ext/deriving.rs
+++ b/src/libsyntax/ext/deriving.rs
@@ -226,7 +226,7 @@ fn create_eq_method(cx: @ext_ctxt,
         attrs: ~[],
         generics: ast_util::empty_generics(),
         self_ty: self_ty,
-        purity: pure_fn,
+        purity: impure_fn,
         decl: fn_decl,
         body: body_block,
         id: cx.next_id(),
@@ -405,7 +405,7 @@ fn create_iter_bytes_method(cx: @ext_ctxt,
         attrs: ~[],
         generics: ast_util::empty_generics(),
         self_ty: self_ty,
-        purity: pure_fn,
+        purity: impure_fn,
         decl: fn_decl,
         body: body_block,
         id: cx.next_id(),
diff --git a/src/libsyntax/ext/pipes/check.rs b/src/libsyntax/ext/pipes/check.rs
index 30e7e832db1..29c9e86ec62 100644
--- a/src/libsyntax/ext/pipes/check.rs
+++ b/src/libsyntax/ext/pipes/check.rs
@@ -41,7 +41,8 @@ impl proto::visitor<(), (), ()> for @ext_ctxt {
     fn visit_proto(&self, _proto: protocol, _states: &[()]) { }
 
     fn visit_state(&self, state: state, _m: &[()]) {
-        if state.messages.len() == 0 {
+        let messages = &*state.messages;
+        if messages.len() == 0 {
             self.span_warn(
                 state.span, // use a real span!
                 fmt!("state %s contains no messages, \
diff --git a/src/libsyntax/ext/pipes/liveness.rs b/src/libsyntax/ext/pipes/liveness.rs
index 15ba7f95538..c6fdf4d9c1b 100644
--- a/src/libsyntax/ext/pipes/liveness.rs
+++ b/src/libsyntax/ext/pipes/liveness.rs
@@ -91,7 +91,7 @@ pub fn analyze(proto: protocol, _cx: @ext_ctxt) {
         let states = str::connect(self_live.map(|s| copy s.name), ~" ");
 
         debug!("protocol %s is unbounded due to loops involving: %s",
-               proto.name, states);
+               copy proto.name, states);
 
         // Someday this will be configurable with a warning
         //cx.span_warn(empty_span(),
@@ -103,7 +103,7 @@ pub fn analyze(proto: protocol, _cx: @ext_ctxt) {
         proto.bounded = Some(false);
     }
     else {
-        debug!("protocol %s is bounded. yay!", proto.name);
+        debug!("protocol %s is bounded. yay!", copy proto.name);
         proto.bounded = Some(true);
     }
 }
diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs
index c9680ac02c9..a47b39a45c8 100644
--- a/src/libsyntax/ext/pipes/proto.rs
+++ b/src/libsyntax/ext/pipes/proto.rs
@@ -156,7 +156,10 @@ pub impl protocol_ {
         ~"proto://" + self.name
     }
 
-    fn num_states(&mut self) -> uint { self.states.len() }
+    fn num_states(&mut self) -> uint {
+        let states = &mut *self.states;
+        states.len()
+    }
 
     fn has_ty_params(&mut self) -> bool {
         for self.states.each |s| {
@@ -180,9 +183,10 @@ pub impl protocol_ {
                       +generics: ast::Generics)
                    -> state {
         let messages = @mut ~[];
+        let states = &*self.states;
 
         let state = @state_ {
-            id: self.states.len(),
+            id: states.len(),
             name: name,
             ident: ident,
             span: self.span,
diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs
index 908fbd44825..0196ee6d184 100644
--- a/src/libsyntax/ext/tt/transcribe.rs
+++ b/src/libsyntax/ext/tt/transcribe.rs
@@ -106,8 +106,9 @@ pub pure fn dup_tt_reader(r: @mut TtReader) -> @mut TtReader {
 }
 
 
-pure fn lookup_cur_matched_by_matched(r: @mut TtReader,
-                                      start: @named_match) -> @named_match {
+pure fn lookup_cur_matched_by_matched(r: &mut TtReader,
+                                      start: @named_match)
+                                   -> @named_match {
     pure fn red(+ad: @named_match, idx: &uint) -> @named_match {
         match *ad {
           matched_nonterminal(_) => {
@@ -117,18 +118,20 @@ pure fn lookup_cur_matched_by_matched(r: @mut TtReader,
           matched_seq(ref ads, _) => ads[*idx]
         }
     }
-    vec::foldl(start, r.repeat_idx, red)
+    let r = &mut *r;
+    let repeat_idx = &r.repeat_idx;
+    vec::foldl(start, *repeat_idx, red)
 }
 
-fn lookup_cur_matched(r: @mut TtReader, name: ident) -> @named_match {
+fn lookup_cur_matched(r: &mut TtReader, name: ident) -> @named_match {
     lookup_cur_matched_by_matched(r, r.interpolations.get(&name))
 }
 enum lis {
     lis_unconstrained, lis_constraint(uint, ident), lis_contradiction(~str)
 }
 
-fn lockstep_iter_size(t: token_tree, r: @mut TtReader) -> lis {
-    fn lis_merge(lhs: lis, rhs: lis, r: @mut TtReader) -> lis {
+fn lockstep_iter_size(t: token_tree, r: &mut TtReader) -> lis {
+    fn lis_merge(lhs: lis, rhs: lis, r: &mut TtReader) -> lis {
         match lhs {
           lis_unconstrained => copy rhs,
           lis_contradiction(_) => copy lhs,
@@ -148,8 +151,10 @@ fn lockstep_iter_size(t: token_tree, r: @mut TtReader) -> lis {
     }
     match t {
       tt_delim(ref tts) | tt_seq(_, ref tts, _, _) => {
-        vec::foldl(lis_unconstrained, (*tts), |lis, tt|
-            lis_merge(lis, lockstep_iter_size(*tt, r), r))
+        vec::foldl(lis_unconstrained, (*tts), |lis, tt| {
+            let lis2 = lockstep_iter_size(*tt, r);
+            lis_merge(lis, lis2, r)
+        })
       }
       tt_tok(*) => lis_unconstrained,
       tt_nonterminal(_, name) => match *lookup_cur_matched(r, name) {
@@ -160,12 +165,20 @@ fn lockstep_iter_size(t: token_tree, r: @mut TtReader) -> lis {
 }
 
 
-pub fn tt_next_token(r: @mut TtReader) -> TokenAndSpan {
+pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
     let ret_val = TokenAndSpan {
         tok: copy r.cur_tok,
         sp: r.cur_span,
     };
-    while r.cur.idx >= r.cur.readme.len() {
+    loop {
+        {
+            let cur = &mut *r.cur;
+            let readme = &mut *cur.readme;
+            if cur.idx < readme.len() {
+                break;
+            }
+        }
+
         /* done with this set; pop or repeat? */
         if ! r.cur.dotdotdoted
             || { *r.repeat_idx.last() == *r.repeat_len.last() - 1 } {
diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs
index 09ffd79c246..90f51fe9b65 100644
--- a/src/libsyntax/parse/lexer.rs
+++ b/src/libsyntax/parse/lexer.rs
@@ -811,7 +811,7 @@ pub mod test {
             sp:span {lo:BytePos(21),hi:BytePos(23),expn_info: None}};
         check_equal (tok1,tok2);
         // the 'main' id is already read:
-        check_equal (string_reader.last_pos,BytePos(28));
+        check_equal (copy string_reader.last_pos,BytePos(28));
         // read another token:
         let tok3 = string_reader.next_token();
         let tok4 = TokenAndSpan{
@@ -819,7 +819,7 @@ pub mod test {
             sp:span {lo:BytePos(24),hi:BytePos(28),expn_info: None}};
         check_equal (tok3,tok4);
         // the lparen is already read:
-        check_equal (string_reader.last_pos,BytePos(29))
+        check_equal (copy string_reader.last_pos,BytePos(29))
     }
 
     // check that the given reader produces the desired stream
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 2ea304a0a9b..8a883b73a64 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -412,7 +412,8 @@ pub impl Parser {
 
     fn parse_purity(&self) -> purity {
         if self.eat_keyword(&~"pure") {
-            return pure_fn;
+            // NB: We parse this as impure for bootstrapping purposes.
+            return impure_fn;
         } else if self.eat_keyword(&~"unsafe") {
             return unsafe_fn;
         } else {
@@ -2668,7 +2669,8 @@ pub impl Parser {
 
     fn parse_optional_purity(&self) -> ast::purity {
         if self.eat_keyword(&~"pure") {
-            ast::pure_fn
+            // NB: We parse this as impure for bootstrapping purposes.
+            ast::impure_fn
         } else if self.eat_keyword(&~"unsafe") {
             ast::unsafe_fn
         } else {
@@ -3418,7 +3420,8 @@ pub impl Parser {
 
         let prefix = Path(self.sess.cm.span_to_filename(*self.span));
         let prefix = prefix.dir_path();
-        let mod_path = Path(".").push_many(*self.mod_path_stack);
+        let mod_path_stack = &*self.mod_path_stack;
+        let mod_path = Path(".").push_many(*mod_path_stack);
         let default_path = *self.sess.interner.get(id) + ~".rs";
         let file_path = match ::attr::first_attr_value_str_by_name(
             outer_attrs, ~"path") {
@@ -3505,7 +3508,8 @@ pub impl Parser {
         if self.eat_keyword(&~"fn") { impure_fn }
         else if self.eat_keyword(&~"pure") {
             self.expect_keyword(&~"fn");
-            pure_fn
+            // NB: We parse this as impure for bootstrapping purposes.
+            impure_fn
         } else if self.eat_keyword(&~"unsafe") {
             self.expect_keyword(&~"fn");
             unsafe_fn
@@ -3894,8 +3898,9 @@ pub impl Parser {
                                           maybe_append(attrs, extra_attrs)));
         } else if items_allowed && self.eat_keyword(&~"pure") {
             // PURE FUNCTION ITEM
+            // NB: We parse this as impure for bootstrapping purposes.
             self.expect_keyword(&~"fn");
-            let (ident, item_, extra_attrs) = self.parse_item_fn(pure_fn);
+            let (ident, item_, extra_attrs) = self.parse_item_fn(impure_fn);
             return iovi_item(self.mk_item(lo, self.last_span.hi, ident, item_,
                                           visibility,
                                           maybe_append(attrs, extra_attrs)));
diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs
index 7f46e452299..492ecdb3f4d 100644
--- a/src/libsyntax/print/pp.rs
+++ b/src/libsyntax/print/pp.rs
@@ -452,9 +452,10 @@ pub impl Printer {
         self.pending_indentation += amount;
     }
     fn get_top(&mut self) -> print_stack_elt {
-        let n = self.print_stack.len();
+        let print_stack = &mut *self.print_stack;
+        let n = print_stack.len();
         if n != 0u {
-            self.print_stack[n - 1u]
+            print_stack[n - 1u]
         } else {
             print_stack_elt {
                 offset: 0,
@@ -496,7 +497,8 @@ pub impl Printer {
           }
           END => {
             debug!("print END -> pop END");
-            fail_unless!((self.print_stack.len() != 0u));
+            let print_stack = &*self.print_stack;
+            fail_unless!((print_stack.len() != 0u));
             self.print_stack.pop();
           }
           BREAK(b) => {
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index 5aae5570dbf..71f3de17414 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -279,9 +279,10 @@ pub fn is_bol(s: @ps) -> bool {
 }
 
 pub fn in_cbox(s: @ps) -> bool {
-    let len = s.boxes.len();
+    let boxes = &*s.boxes;
+    let len = boxes.len();
     if len == 0u { return false; }
-    return s.boxes[len - 1u] == pp::consistent;
+    return boxes[len - 1u] == pp::consistent;
 }
 
 pub fn hardbreak_if_not_bol(s: @ps) { if !is_bol(s) { hardbreak(s.s); } }
diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs
index 7a5708049e9..47f49ebadaa 100644
--- a/src/libsyntax/util/interner.rs
+++ b/src/libsyntax/util/interner.rs
@@ -41,14 +41,18 @@ pub impl<T:Eq + IterBytes + Hash + Const + Copy> Interner<T> {
             None => (),
         }
 
-        let new_idx = self.vect.len();
+        let vect = &*self.vect;
+        let new_idx = vect.len();
         self.map.insert(val, new_idx);
         self.vect.push(val);
         new_idx
     }
 
     fn gensym(&self, val: T) -> uint {
-        let new_idx = self.vect.len();
+        let new_idx = {
+            let vect = &*self.vect;
+            vect.len()
+        };
         // leave out of .map to avoid colliding
         self.vect.push(val);
         new_idx
@@ -59,7 +63,7 @@ pub impl<T:Eq + IterBytes + Hash + Const + Copy> Interner<T> {
     // where we first check a pred and then rely on it, ceasing to fail is ok.
     pure fn get(&self, idx: uint) -> T { self.vect[idx] }
 
-    fn len(&self) -> uint { self.vect.len() }
+    fn len(&self) -> uint { let vect = &*self.vect; vect.len() }
 }
 
 #[test]