summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2015-03-24 15:34:59 -0400
committerNiko Matsakis <niko@alum.mit.edu>2015-03-30 04:59:56 -0400
commitd649292e601a47b3b602415a2e9d9b6ebc298d45 (patch)
treea5fc3112ad466a325036da4d9b235412decd8512 /src/libsyntax
parentf55d03c8d8f5cf76628da771c1f5c4b9a9589c00 (diff)
downloadrust-d649292e601a47b3b602415a2e9d9b6ebc298d45.tar.gz
rust-d649292e601a47b3b602415a2e9d9b6ebc298d45.zip
Implement new type-checking strategy for binary operators. Basically,
the plan is to treat all binary operators as if they were overloaded,
relying on the fact that we have impls for all the builtin scalar
operations (and no more). But then during writeback we clear the
overload if the types correspond to a builtin op.

This strategy allows us to avoid having to know the types of the
operands ahead of time. It also avoids us overspecializing as we did in
the past.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast_util.rs28
1 files changed, 6 insertions, 22 deletions
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs
index b7aa2aebbfa..b83b42c73e7 100644
--- a/src/libsyntax/ast_util.rs
+++ b/src/libsyntax/ast_util.rs
@@ -86,33 +86,17 @@ pub fn is_shift_binop(b: BinOp_) -> bool {
 
 pub fn is_comparison_binop(b: BinOp_) -> bool {
     match b {
-        BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => true,
-        _ => false
+        BiEq | BiLt | BiLe | BiNe | BiGt | BiGe =>
+            true,
+        BiAnd | BiOr | BiAdd | BiSub | BiMul | BiDiv | BiRem |
+        BiBitXor | BiBitAnd | BiBitOr | BiShl | BiShr =>
+            false,
     }
 }
 
 /// Returns `true` if the binary operator takes its arguments by value
 pub fn is_by_value_binop(b: BinOp_) -> bool {
-    match b {
-        BiAdd | BiSub | BiMul | BiDiv | BiRem | BiBitXor | BiBitAnd | BiBitOr | BiShl | BiShr => {
-            true
-        }
-        _ => false
-    }
-}
-
-/// Returns `true` if the binary operator is symmetric in the sense that LHS
-/// and RHS must have the same type. So the type of LHS can serve as an hint
-/// for the type of RHS and vice versa.
-pub fn is_symmetric_binop(b: BinOp_) -> bool {
-    match b {
-        BiAdd | BiSub | BiMul | BiDiv | BiRem |
-        BiBitXor | BiBitAnd | BiBitOr |
-        BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => {
-            true
-        }
-        _ => false
-    }
+    !is_comparison_binop(b)
 }
 
 /// Returns `true` if the unary operator takes its argument by value