about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-05-10 17:56:02 -0700
committerbors <bors@rust-lang.org>2013-05-10 17:56:02 -0700
commit3e0400fb86170baff30282edcdccff73e243fd6e (patch)
treeec7cc5de5ce7c80845c77fdcbb670cd54c120783 /src/libsyntax
parentd546493096f35e68cbcd9b5d3d7654e7a9345744 (diff)
parent606bd75586419948f109de313ab37e31397ca7a3 (diff)
downloadrust-3e0400fb86170baff30282edcdccff73e243fd6e.tar.gz
rust-3e0400fb86170baff30282edcdccff73e243fd6e.zip
auto merge of #6223 : alexcrichton/rust/issue-6183, r=pcwalton
Closes #6183.

The first commit changes the compiler's method of treating a `for` loop, and all the remaining commits are just dealing with the fallout.

The biggest fallout was the `IterBytes` trait, although it's really a whole lot nicer now because all of the `iter_bytes_XX` methods are just and-ed together. Sadly there was a huge amount of stuff that's `cfg(stage0)` gated, but whoever lands the next snapshot is going to have a lot of fun deleting all this code!

Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/abi.rs29
-rw-r--r--src/libsyntax/ast.rs83
-rw-r--r--src/libsyntax/ast_util.rs9
-rw-r--r--src/libsyntax/codemap.rs14
-rw-r--r--src/libsyntax/ext/deriving/iter_bytes.rs26
-rw-r--r--src/libsyntax/ext/expand.rs14
-rw-r--r--src/libsyntax/ext/pipes/proto.rs16
-rw-r--r--src/libsyntax/opt_vec.rs14
-rw-r--r--src/libsyntax/parse/obsolete.rs8
-rw-r--r--src/libsyntax/parse/token.rs7
10 files changed, 197 insertions, 23 deletions
diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs
index 75782e9ca67..f266b8871a2 100644
--- a/src/libsyntax/abi.rs
+++ b/src/libsyntax/abi.rs
@@ -81,6 +81,7 @@ static AbiDatas: &'static [AbiData] = &[
     AbiData {abi: RustIntrinsic, name: "rust-intrinsic", abi_arch: RustArch},
 ];
 
+#[cfg(stage0)]
 fn each_abi(op: &fn(abi: Abi) -> bool) {
     /*!
      *
@@ -93,6 +94,15 @@ fn each_abi(op: &fn(abi: Abi) -> bool) {
         }
     }
 }
+#[cfg(not(stage0))]
+fn each_abi(op: &fn(abi: Abi) -> bool) -> bool {
+    /*!
+     *
+     * Iterates through each of the defined ABIs.
+     */
+
+    AbiDatas.each(|abi_data| op(abi_data.abi))
+}
 
 pub fn lookup(name: &str) -> Option<Abi> {
     /*!
@@ -189,6 +199,7 @@ pub impl AbiSet {
         self.bits |= (1 << abi.index());
     }
 
+    #[cfg(stage0)]
     fn each(&self, op: &fn(abi: Abi) -> bool) {
         for each_abi |abi| {
             if self.contains(abi) {
@@ -198,6 +209,10 @@ pub impl AbiSet {
             }
         }
     }
+    #[cfg(not(stage0))]
+    fn each(&self, op: &fn(abi: Abi) -> bool) -> bool {
+        each_abi(|abi| !self.contains(abi) || op(abi))
+    }
 
     fn is_empty(&self) -> bool {
         self.bits == 0
@@ -252,17 +267,31 @@ pub impl AbiSet {
     }
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for Abi {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         self.index().iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for Abi {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        self.index().iter_bytes(lsb0, f)
+    }
+}
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for AbiSet {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         self.bits.iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for AbiSet {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        self.bits.iter_bytes(lsb0, f)
+    }
+}
 
 impl ToStr for Abi {
     fn to_str(&self) -> ~str {
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index de59f2107cc..f4e3e683229 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -97,11 +97,18 @@ impl<D:Decoder> Decodable<D> for ident {
     }
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for ident {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         self.repr.iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for ident {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        self.repr.iter_bytes(lsb0, f)
+    }
+}
 
 // Functions may or may not have names.
 pub type fn_ident = Option<ident>;
@@ -284,6 +291,7 @@ pub enum binding_mode {
     bind_infer
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for binding_mode {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         match *self {
@@ -297,6 +305,18 @@ impl to_bytes::IterBytes for binding_mode {
         }
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for binding_mode {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        match *self {
+          bind_by_copy => 0u8.iter_bytes(lsb0, f),
+
+          bind_by_ref(ref m) => to_bytes::iter_bytes_2(&1u8, m, lsb0, f),
+
+          bind_infer => 2u8.iter_bytes(lsb0, f),
+        }
+    }
+}
 
 #[auto_encode]
 #[auto_decode]
@@ -330,11 +350,18 @@ pub enum pat_ {
 #[deriving(Eq)]
 pub enum mutability { m_mutbl, m_imm, m_const, }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for mutability {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (*self as u8).iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for mutability {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (*self as u8).iter_bytes(lsb0, f)
+    }
+}
 
 #[auto_encode]
 #[auto_decode]
@@ -345,11 +372,18 @@ pub enum Sigil {
     ManagedSigil
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for Sigil {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (*self as uint).iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for Sigil {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (*self as uint).iter_bytes(lsb0, f)
+    }
+}
 
 impl ToStr for Sigil {
     fn to_str(&self) -> ~str {
@@ -744,11 +778,18 @@ impl ToStr for int_ty {
     }
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for int_ty {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (*self as u8).iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for int_ty {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (*self as u8).iter_bytes(lsb0, f)
+    }
+}
 
 #[auto_encode]
 #[auto_decode]
@@ -761,11 +802,18 @@ impl ToStr for uint_ty {
     }
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for uint_ty {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (*self as u8).iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for uint_ty {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (*self as u8).iter_bytes(lsb0, f)
+    }
+}
 
 #[auto_encode]
 #[auto_decode]
@@ -778,11 +826,18 @@ impl ToStr for float_ty {
     }
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for float_ty {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (*self as u8).iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for float_ty {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (*self as u8).iter_bytes(lsb0, f)
+    }
+}
 
 // NB Eq method appears below.
 #[auto_encode]
@@ -823,11 +878,18 @@ impl ToStr for Onceness {
     }
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for Onceness {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (*self as uint).iter_bytes(lsb0, f);
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for Onceness {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (*self as uint).iter_bytes(lsb0, f)
+    }
+}
 
 #[auto_encode]
 #[auto_decode]
@@ -874,11 +936,18 @@ pub enum ty_ {
     ty_infer,
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for Ty {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         to_bytes::iter_bytes_2(&self.span.lo, &self.span.hi, lsb0, f);
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for Ty {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        to_bytes::iter_bytes_2(&self.span.lo, &self.span.hi, lsb0, f)
+    }
+}
 
 #[auto_encode]
 #[auto_decode]
@@ -941,11 +1010,18 @@ impl ToStr for purity {
     }
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for purity {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (*self as u8).iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for purity {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (*self as u8).iter_bytes(lsb0, f)
+    }
+}
 
 #[auto_encode]
 #[auto_decode]
@@ -956,11 +1032,18 @@ pub enum ret_style {
     return_val, // everything else
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for ret_style {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (*self as u8).iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for ret_style {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (*self as u8).iter_bytes(lsb0, f)
+    }
+}
 
 #[auto_encode]
 #[auto_decode]
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs
index 77277dea814..ceff868d11f 100644
--- a/src/libsyntax/ast_util.rs
+++ b/src/libsyntax/ast_util.rs
@@ -191,12 +191,21 @@ pub fn is_call_expr(e: @expr) -> bool {
 }
 
 // This makes def_id hashable
+#[cfg(stage0)]
 impl to_bytes::IterBytes for def_id {
     #[inline(always)]
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         to_bytes::iter_bytes_2(&self.crate, &self.node, lsb0, f);
     }
 }
+// This makes def_id hashable
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for def_id {
+    #[inline(always)]
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        to_bytes::iter_bytes_2(&self.crate, &self.node, lsb0, f)
+    }
+}
 
 pub fn block_from_expr(e: @expr) -> blk {
     let blk_ = default_block(~[], option::Some::<@expr>(e), e.id);
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs
index 846097550d1..053ed76d66b 100644
--- a/src/libsyntax/codemap.rs
+++ b/src/libsyntax/codemap.rs
@@ -65,11 +65,18 @@ impl Sub<BytePos, BytePos> for BytePos {
     }
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for BytePos {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (**self).iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for BytePos {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (**self).iter_bytes(lsb0, f)
+    }
+}
 
 impl Pos for CharPos {
     fn from_uint(n: uint) -> CharPos { CharPos(n) }
@@ -83,11 +90,18 @@ impl cmp::Ord for CharPos {
     fn gt(&self, other: &CharPos) -> bool { **self > **other }
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for CharPos {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (**self).iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for CharPos {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (**self).iter_bytes(lsb0, f)
+    }
+}
 
 impl Add<CharPos,CharPos> for CharPos {
     fn add(&self, rhs: &CharPos) -> CharPos {
diff --git a/src/libsyntax/ext/deriving/iter_bytes.rs b/src/libsyntax/ext/deriving/iter_bytes.rs
index 3d66506d6ca..9eb246ffe22 100644
--- a/src/libsyntax/ext/deriving/iter_bytes.rs
+++ b/src/libsyntax/ext/deriving/iter_bytes.rs
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use ast::{meta_item, item, expr};
+use ast::{meta_item, item, expr, and};
 use codemap::span;
 use ext::base::ext_ctxt;
 use ext::build;
@@ -31,7 +31,7 @@ pub fn expand_deriving_iter_bytes(cx: @ext_ctxt,
                     Literal(Path::new(~[~"bool"])),
                     Literal(Path::new(~[~"core", ~"to_bytes", ~"Cb"]))
                 ],
-                ret_ty: nil_ty(),
+                ret_ty: Literal(Path::new(~[~"bool"])),
                 const_nonmatching: false,
                 combine_substructure: iter_bytes_substructure
             }
@@ -58,13 +58,11 @@ fn iter_bytes_substructure(cx: @ext_ctxt, span: span, substr: &Substructure) ->
     };
     let iter_bytes_ident = substr.method_ident;
     let call_iterbytes = |thing_expr| {
-        build::mk_stmt(
-            cx, span,
-            build::mk_method_call(cx, span,
-                                  thing_expr, iter_bytes_ident,
-                                  copy lsb0_f))
+        build::mk_method_call(cx, span,
+                              thing_expr, iter_bytes_ident,
+                              copy lsb0_f)
     };
-    let mut stmts = ~[];
+    let mut exprs = ~[];
     let fields;
     match *substr.fields {
         Struct(ref fs) => {
@@ -78,7 +76,7 @@ fn iter_bytes_substructure(cx: @ext_ctxt, span: span, substr: &Substructure) ->
                 None => build::mk_uint(cx, span, index)
             };
 
-            stmts.push(call_iterbytes(discriminant));
+            exprs.push(call_iterbytes(discriminant));
 
             fields = fs;
         }
@@ -86,8 +84,14 @@ fn iter_bytes_substructure(cx: @ext_ctxt, span: span, substr: &Substructure) ->
     }
 
     for fields.each |&(_, field, _)| {
-        stmts.push(call_iterbytes(field));
+        exprs.push(call_iterbytes(field));
     }
 
-    build::mk_block(cx, span, ~[], stmts, None)
+    if exprs.len() == 0 {
+        cx.span_bug(span, "#[deriving(IterBytes)] needs at least one field");
+    }
+
+    do vec::foldl(exprs[0], exprs.slice(1, exprs.len())) |prev, me| {
+        build::mk_binary(cx, span, and, prev, *me)
+    }
 }
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index 68c74c2d12b..5129fa6ebd2 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -195,18 +195,8 @@ pub fn expand_item(extsbox: @mut SyntaxEnv,
 }
 
 // does this attribute list contain "macro_escape" ?
-pub fn contains_macro_escape (attrs: &[ast::attribute]) -> bool{
-    let mut accum = false;
-    do attrs.each |attr| {
-        let mname = attr::get_attr_name(attr);
-        if (mname == @~"macro_escape") {
-            accum = true;
-            false
-        } else {
-            true
-        }
-    }
-    accum
+pub fn contains_macro_escape (attrs: &[ast::attribute]) -> bool {
+    attrs.any(|attr| "macro_escape" == *attr::get_attr_name(attr))
 }
 
 // this macro disables (one layer of) macro
diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs
index 647c7741bd8..7c78ec066d0 100644
--- a/src/libsyntax/ext/pipes/proto.rs
+++ b/src/libsyntax/ext/pipes/proto.rs
@@ -100,6 +100,7 @@ pub impl state_ {
 
     /// Iterate over the states that can be reached in one message
     /// from this state.
+    #[cfg(stage0)]
     fn reachable(&self, f: &fn(state) -> bool) {
         for self.messages.each |m| {
             match *m {
@@ -111,6 +112,21 @@ pub impl state_ {
             }
         }
     }
+    /// Iterate over the states that can be reached in one message
+    /// from this state.
+    #[cfg(not(stage0))]
+    fn reachable(&self, f: &fn(state) -> bool) -> bool {
+        for self.messages.each |m| {
+            match *m {
+              message(_, _, _, _, Some(next_state { state: ref id, _ })) => {
+                let state = self.proto.get_state((*id));
+                if !f(state) { return false; }
+              }
+              _ => ()
+            }
+        }
+        return true;
+    }
 }
 
 pub type protocol = @mut protocol_;
diff --git a/src/libsyntax/opt_vec.rs b/src/libsyntax/opt_vec.rs
index 600ab964e52..6110579863d 100644
--- a/src/libsyntax/opt_vec.rs
+++ b/src/libsyntax/opt_vec.rs
@@ -132,12 +132,20 @@ impl<A:Eq> Eq for OptVec<A> {
 }
 
 impl<A> BaseIter<A> for OptVec<A> {
+    #[cfg(stage0)]
     fn each(&self, blk: &fn(v: &A) -> bool) {
         match *self {
             Empty => {}
             Vec(ref v) => v.each(blk)
         }
     }
+    #[cfg(not(stage0))]
+    fn each(&self, blk: &fn(v: &A) -> bool) -> bool {
+        match *self {
+            Empty => true,
+            Vec(ref v) => v.each(blk)
+        }
+    }
 
     fn size_hint(&self) -> Option<uint> {
         Some(self.len())
@@ -146,10 +154,16 @@ impl<A> BaseIter<A> for OptVec<A> {
 
 impl<A> old_iter::ExtendedIter<A> for OptVec<A> {
     #[inline(always)]
+    #[cfg(stage0)]
     fn eachi(&self, blk: &fn(v: uint, v: &A) -> bool) {
         old_iter::eachi(self, blk)
     }
     #[inline(always)]
+    #[cfg(not(stage0))]
+    fn eachi(&self, blk: &fn(v: uint, v: &A) -> bool) -> bool {
+        old_iter::eachi(self, blk)
+    }
+    #[inline(always)]
     fn all(&self, blk: &fn(&A) -> bool) -> bool {
         old_iter::all(self, blk)
     }
diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs
index e486a6254e7..a4ac038cf46 100644
--- a/src/libsyntax/parse/obsolete.rs
+++ b/src/libsyntax/parse/obsolete.rs
@@ -62,12 +62,20 @@ pub enum ObsoleteSyntax {
     ObsoleteFixedLengthVectorType,
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for ObsoleteSyntax {
     #[inline(always)]
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (*self as uint).iter_bytes(lsb0, f);
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for ObsoleteSyntax {
+    #[inline(always)]
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (*self as uint).iter_bytes(lsb0, f)
+    }
+}
 
 pub impl Parser {
     /// Reports an obsolete syntax non-fatal error.
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index 43745bce1bf..5688678b06a 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -355,11 +355,18 @@ impl<'self> Equiv<@~str> for StringRef<'self> {
     fn equiv(&self, other: &@~str) -> bool { str::eq_slice(**self, **other) }
 }
 
+#[cfg(stage0)]
 impl<'self> to_bytes::IterBytes for StringRef<'self> {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (**self).iter_bytes(lsb0, f);
     }
 }
+#[cfg(not(stage0))]
+impl<'self> to_bytes::IterBytes for StringRef<'self> {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (**self).iter_bytes(lsb0, f)
+    }
+}
 
 /**
  * Maps a token to a record specifying the corresponding binary