From b71a8827e3a17720508b7edebdc2c13358179e59 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 17 Jul 2012 16:49:54 -0700 Subject: [PATCH] rustc: Fix coherence errors in the build --- src/libcore/core.rs | 3 +- src/libcore/tuple.rs | 20 +++++++++-- src/libsyntax/ext/pipes/ast_builder.rs | 2 +- src/libsyntax/ext/pipes/pipec.rs | 46 ++++++++++++-------------- src/libsyntax/ext/pipes/proto.rs | 5 +-- 5 files changed, 45 insertions(+), 31 deletions(-) diff --git a/src/libcore/core.rs b/src/libcore/core.rs index 07dac5270b0..4c175490b41 100644 --- a/src/libcore/core.rs +++ b/src/libcore/core.rs @@ -5,7 +5,7 @@ import option::{some, none}; import option = option::option; import path = path::path; -import tuple::extensions; +import tuple::{extensions, tuple_ops, extended_tuple_ops}; import str::{extensions, str_slice, unique_str}; import vec::extensions; import vec::{const_vector, copyable_vector, immutable_vector}; @@ -40,6 +40,7 @@ export str_slice, unique_str; export const_vector, copyable_vector, immutable_vector; export immutable_copyable_vector, iter_trait_extensions, vec_concat; export base_iter, copyable_iter, extended_iter; +export tuple_ops, extended_tuple_ops; export ptr; // Export the log levels as global constants. Higher levels mean diff --git a/src/libcore/tuple.rs b/src/libcore/tuple.rs index 040f34ca00b..681d94c475b 100644 --- a/src/libcore/tuple.rs +++ b/src/libcore/tuple.rs @@ -1,7 +1,12 @@ //! Operations on tuples +trait tuple_ops { + pure fn first() -> T; + pure fn second() -> U; + pure fn swap() -> (U, T); +} -impl extensions for (T, U) { +impl extensions of tuple_ops for (T, U) { /// Return the first element of self pure fn first() -> T { @@ -23,7 +28,14 @@ impl extensions for (T, U) { } -impl extensions for (&[A], &[B]) { +trait extended_tuple_ops { + fn zip() -> ~[(A, B)]; + fn map(f: fn(A, B) -> C) -> ~[C]; +} + +impl extensions of extended_tuple_ops + for (&[A], &[B]) { + fn zip() -> ~[(A, B)] { let (a, b) = self; vec::zip(a, b) @@ -35,7 +47,9 @@ impl extensions for (&[A], &[B]) { } } -impl extensions for (~[A], ~[B]) { +impl extensions of extended_tuple_ops + for (~[A], ~[B]) { + fn zip() -> ~[(A, B)] { let (a, b) = self; vec::zip(a, b) diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs index 58f42152437..eb92be1149d 100644 --- a/src/libsyntax/ext/pipes/ast_builder.rs +++ b/src/libsyntax/ext/pipes/ast_builder.rs @@ -202,7 +202,7 @@ impl ast_builder of ext_ctxt_ast_builder for ext_ctxt { span: empty_span()} } - fn ty_nil() -> @ast::ty { + fn ty_nil_ast_builder() -> @ast::ty { @{id: self.next_id(), node: ast::ty_nil, span: empty_span()} diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index eab2c58e50e..c6b1a2d6932 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -22,7 +22,21 @@ import ast_builder::ast_builder; import ast_builder::methods; import ast_builder::path; -impl compile for message { +trait gen_send { + fn gen_send(cx: ext_ctxt) -> @ast::item; +} + +trait to_type_decls { + fn to_type_decls(cx: ext_ctxt) -> ~[@ast::item]; + fn to_endpoint_decls(cx: ext_ctxt, dir: direction) -> ~[@ast::item]; +} + +trait gen_init { + fn gen_init(cx: ext_ctxt) -> @ast::item; + fn compile(cx: ext_ctxt) -> @ast::item; +} + +impl compile of gen_send for message { fn gen_send(cx: ext_ctxt) -> @ast::item { #debug("pipec: gen_send"); alt self { @@ -80,7 +94,7 @@ impl compile for message { let args_ast = vec::append( ~[cx.arg_mode(@~"pipe", - cx.ty_path(path(this.data_name()) + cx.ty_path_ast_builder(path(this.data_name()) .add_tys(cx.ty_vars(this.ty_params))), ast::by_copy)], args_ast); @@ -104,7 +118,7 @@ impl compile for message { cx.item_fn_poly(self.name(), args_ast, - cx.ty_nil(), + cx.ty_nil_ast_builder(), self.get_params(), cx.expr_block(body)) } @@ -112,12 +126,12 @@ impl compile for message { } fn to_ty(cx: ext_ctxt) -> @ast::ty { - cx.ty_path_ast_builder(path(self.name) - .add_tys(cx.ty_vars(self.ty_params))) + cx.ty_path_ast_builder(path(self.name()) + .add_tys(cx.ty_vars(self.get_params()))) } } -impl compile for state { +impl compile of to_type_decls for state { fn to_type_decls(cx: ext_ctxt) -> ~[@ast::item] { #debug("pipec: to_type_decls"); // This compiles into two different type declarations. Say the @@ -144,7 +158,7 @@ impl compile for state { }; vec::append_one(tys, - cx.ty_path((dir + next_name) + cx.ty_path_ast_builder((dir + next_name) .add_tys(next_tys))) } none { tys } @@ -184,7 +198,7 @@ impl compile for state { } } -impl compile for protocol { +impl compile of gen_init for protocol { fn gen_init(cx: ext_ctxt) -> @ast::item { let start_state = self.states[0]; @@ -303,19 +317,3 @@ impl parse_utils of ext_ctxt_parse_utils for ext_ctxt { } } -trait two_vector_utils { - fn zip() -> ~[(A, B)]; - fn map(f: fn(A, B) -> C) -> ~[C]; -} - -impl methods of two_vector_utils for (~[A], ~[B]) { - fn zip() -> ~[(A, B)] { - let (a, b) = self; - vec::zip(a, b) - } - - fn map(f: fn(A, B) -> C) -> ~[C] { - let (a, b) = self; - vec::map2(a, b, f) - } -} diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs index 1df3466286c..1c88732adb0 100644 --- a/src/libsyntax/ext/pipes/proto.rs +++ b/src/libsyntax/ext/pipes/proto.rs @@ -3,7 +3,7 @@ import dvec::{dvec, extensions}; import ast::{ident}; -import ast_builder::{path, methods, ast_builder}; +import ast_builder::{path, methods, ast_builder, append_types}; enum direction { send, recv @@ -78,7 +78,8 @@ impl methods for state { } fn to_ty(cx: ext_ctxt) -> @ast::ty { - cx.ty_path(path(self.name).add_tys(cx.ty_vars(self.ty_params))) + cx.ty_path_ast_builder + (path(self.name).add_tys(cx.ty_vars(self.ty_params))) } }