]> git.lizzy.rs Git - rust.git/commitdiff
Polymorphic protocols work well enough to do MapReduce.
authorEric Holk <eric.holk@gmail.com>
Wed, 25 Jul 2012 17:13:37 +0000 (10:13 -0700)
committerEric Holk <eric.holk@gmail.com>
Wed, 25 Jul 2012 19:12:26 +0000 (12:12 -0700)
I did some horrible things with type variable naming here. It should do the right thing in most cases, but we'll need to go through and make it correct someday.

src/libsyntax/ext/pipes/pipec.rs
src/test/bench/task-perf-word-count-generic.rs

index 529a5953dd5137a91c58681fdb29e6938921717d..392e6ba392acc28119f8ca48dbe0daf73deeda26 100644 (file)
@@ -319,11 +319,12 @@ fn gen_init_bounded(ext_cx: ext_ctxt) -> @ast::expr {
     }
 
     fn buffer_ty_path(cx: ext_ctxt) -> @ast::ty {
-        let mut params = ~[];
+        let mut params: ~[ast::ty_param] = ~[];
         for (copy self.states).each |s| {
             for s.ty_params.each |tp| {
-                if !params.contains(tp) {
-                    vec::push(params, tp);
+                alt params.find(|tpp| *tp.ident == *tpp.ident) {
+                  none { vec::push(params, tp) }
+                  _ { }
                 }
             }
         }
@@ -334,11 +335,12 @@ fn buffer_ty_path(cx: ext_ctxt) -> @ast::ty {
 
     fn gen_buffer_type(cx: ext_ctxt) -> @ast::item {
         let ext_cx = cx;
-        let mut params = ~[];
+        let mut params: ~[ast::ty_param] = ~[];
         let fields = do (copy self.states).map_to_vec |s| {
             for s.ty_params.each |tp| {
-                if !params.contains(tp) {
-                    vec::push(params, tp);
+                alt params.find(|tpp| *tp.ident == *tpp.ident) {
+                  none { vec::push(params, tp) }
+                  _ { }
                 }
             }
             let ty = s.to_ty(cx);
index 62aa4d75f20b230280a608add92ee7ed29077eef..47bb538d03d7e54c0458c1791d48194aed508d10 100644 (file)
@@ -143,14 +143,12 @@ enum ctrl_proto<K: copy send, V: copy send> {
     proto! ctrl_proto {
         open: send<K: copy send, V: copy send> {
             find_reducer(K) -> reducer_response<K, V>,
-            mapper_done -> terminated
+            mapper_done -> !
         }
 
         reducer_response: recv<K: copy send, V: copy send> {
             reducer(chan<reduce_proto<V>>) -> open<K, V>
         }
-
-        terminated: send { }
     }
 
     enum reduce_proto<V: copy send> { emit_val(V), done, ref, release }
@@ -261,7 +259,7 @@ fn map_reduce<K1: copy send, K2: const copy send hash_key, V: copy send>(
         while num_mappers > 0 {
             let (_ready, message, ctrls) = pipes::select(ctrl);
             alt option::unwrap(message) {
-              ctrl_proto::mapper_done(_) {
+              ctrl_proto::mapper_done {
                 // #error("received mapper terminated.");
                 num_mappers -= 1;
                 ctrl = ctrls;