diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2013-11-19 11:13:34 +1100 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2013-11-19 11:18:34 +1100 |
| commit | df0f50381c630c56adcd7ca0023b8daaa3ad2776 (patch) | |
| tree | c52ee43cf8f6a4eb13a76e6d217f1f95d7197d60 /src/libsyntax | |
| parent | 3d569df41de221ce5b0ffd385caaa9fd6d5fb2ff (diff) | |
| download | rust-df0f50381c630c56adcd7ca0023b8daaa3ad2776.tar.gz rust-df0f50381c630c56adcd7ca0023b8daaa3ad2776.zip | |
Mark some derived methods as #[inline].
ToStr, Encodable and Decodable are not marked as such, since they're
already expensive, and lead to large methods, so inlining will bloat the
metadata & the binaries.
This means that something like
#[deriving(Eq)]
struct A { x: int }
creates an instance like
#[doc = "Automatically derived."]
impl ::std::cmp::Eq for A {
#[inline]
fn eq(&self, __arg_0: &A) -> ::bool {
match *__arg_0 {
A{x: ref __self_1_0} =>
match *self {
A{x: ref __self_0_0} => true && __self_0_0.eq(__self_1_0)
}
}
}
#[inline]
fn ne(&self, __arg_0: &A) -> ::bool {
match *__arg_0 {
A{x: ref __self_1_0} =>
match *self {
A{x: ref __self_0_0} => false || __self_0_0.ne(__self_1_0)
}
}
}
}
(The change being the `#[inline]` attributes.)
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/deriving/clone.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/cmp/eq.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/cmp/ord.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/cmp/totaleq.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/cmp/totalord.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/decodable.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/default.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/encodable.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/generic.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/iter_bytes.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/primitive.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/rand.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/to_str.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/zero.rs | 2 |
14 files changed, 27 insertions, 1 deletions
diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs index 6ff39351448..118ada116d9 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax/ext/deriving/clone.rs @@ -30,6 +30,7 @@ pub fn expand_deriving_clone(cx: @ExtCtxt, explicit_self: borrowed_explicit_self(), args: ~[], ret_ty: Self, + inline: true, const_nonmatching: false, combine_substructure: |c, s, sub| cs_clone("Clone", c, s, sub) } @@ -55,6 +56,7 @@ pub fn expand_deriving_deep_clone(cx: @ExtCtxt, explicit_self: borrowed_explicit_self(), args: ~[], ret_ty: Self, + inline: true, const_nonmatching: false, // cs_clone uses the ident passed to it, i.e. it will // call deep_clone (not clone) here. diff --git a/src/libsyntax/ext/deriving/cmp/eq.rs b/src/libsyntax/ext/deriving/cmp/eq.rs index 468e3e5e7f2..eb07d2d209c 100644 --- a/src/libsyntax/ext/deriving/cmp/eq.rs +++ b/src/libsyntax/ext/deriving/cmp/eq.rs @@ -37,6 +37,7 @@ pub fn expand_deriving_eq(cx: @ExtCtxt, explicit_self: borrowed_explicit_self(), args: ~[borrowed_self()], ret_ty: Literal(Path::new(~["bool"])), + inline: true, const_nonmatching: true, combine_substructure: $f } diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax/ext/deriving/cmp/ord.rs index 33f45d45bdb..95d617af0c7 100644 --- a/src/libsyntax/ext/deriving/cmp/ord.rs +++ b/src/libsyntax/ext/deriving/cmp/ord.rs @@ -27,6 +27,7 @@ pub fn expand_deriving_ord(cx: @ExtCtxt, explicit_self: borrowed_explicit_self(), args: ~[borrowed_self()], ret_ty: Literal(Path::new(~["bool"])), + inline: true, const_nonmatching: false, combine_substructure: |cx, span, substr| cs_op($op, $equal, cx, span, substr) } diff --git a/src/libsyntax/ext/deriving/cmp/totaleq.rs b/src/libsyntax/ext/deriving/cmp/totaleq.rs index c6123451071..51965e1b582 100644 --- a/src/libsyntax/ext/deriving/cmp/totaleq.rs +++ b/src/libsyntax/ext/deriving/cmp/totaleq.rs @@ -34,6 +34,7 @@ pub fn expand_deriving_totaleq(cx: @ExtCtxt, explicit_self: borrowed_explicit_self(), args: ~[borrowed_self()], ret_ty: Literal(Path::new(~["bool"])), + inline: true, const_nonmatching: true, combine_substructure: cs_equals } diff --git a/src/libsyntax/ext/deriving/cmp/totalord.rs b/src/libsyntax/ext/deriving/cmp/totalord.rs index 34c6d1104da..217acd98c68 100644 --- a/src/libsyntax/ext/deriving/cmp/totalord.rs +++ b/src/libsyntax/ext/deriving/cmp/totalord.rs @@ -31,6 +31,7 @@ pub fn expand_deriving_totalord(cx: @ExtCtxt, explicit_self: borrowed_explicit_self(), args: ~[borrowed_self()], ret_ty: Literal(Path::new(~["std", "cmp", "Ordering"])), + inline: true, const_nonmatching: false, combine_substructure: cs_cmp } diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index 4ad835f032f..3f745d64a7b 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -39,6 +39,7 @@ pub fn expand_deriving_decodable(cx: @ExtCtxt, args: ~[Ptr(~Literal(Path::new_local("__D")), Borrowed(None, MutMutable))], ret_ty: Self, + inline: false, const_nonmatching: true, combine_substructure: decodable_substructure, }, diff --git a/src/libsyntax/ext/deriving/default.rs b/src/libsyntax/ext/deriving/default.rs index 6bc2b06806b..866df36bba4 100644 --- a/src/libsyntax/ext/deriving/default.rs +++ b/src/libsyntax/ext/deriving/default.rs @@ -30,6 +30,7 @@ pub fn expand_deriving_default(cx: @ExtCtxt, explicit_self: None, args: ~[], ret_ty: Self, + inline: true, const_nonmatching: false, combine_substructure: default_substructure }, diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index a037a4daabf..899100f14ba 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -101,6 +101,7 @@ pub fn expand_deriving_encodable(cx: @ExtCtxt, args: ~[Ptr(~Literal(Path::new_local("__E")), Borrowed(None, MutMutable))], ret_ty: nil_ty(), + inline: false, const_nonmatching: true, combine_substructure: encodable_substructure, }, diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index b37757341ef..aa83b7656a6 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -218,6 +218,9 @@ pub struct MethodDef<'self> { /// Return type ret_ty: Ty<'self>, + /// Whether to mark this as #[inline] + inline: bool, + /// if the value of the nonmatching enums is independent of the /// actual enum variants, i.e. can use _ => .. match. const_nonmatching: bool, @@ -553,11 +556,16 @@ impl<'self> MethodDef<'self> { let fn_decl = cx.fn_decl(args, ret_type); let body_block = cx.block_expr(body); + let attrs = if self.inline { + ~[cx.attribute(trait_span, cx.meta_word(trait_span, @"inline"))] + } else { + ~[] + }; // Create the method. @ast::method { ident: method_ident, - attrs: ~[], + attrs: attrs, generics: fn_generics, explicit_self: explicit_self, purity: ast::impure_fn, diff --git a/src/libsyntax/ext/deriving/iter_bytes.rs b/src/libsyntax/ext/deriving/iter_bytes.rs index 82f449fc116..fed630cc668 100644 --- a/src/libsyntax/ext/deriving/iter_bytes.rs +++ b/src/libsyntax/ext/deriving/iter_bytes.rs @@ -33,6 +33,7 @@ pub fn expand_deriving_iter_bytes(cx: @ExtCtxt, Literal(Path::new(~["std", "to_bytes", "Cb"])) ], ret_ty: Literal(Path::new(~["bool"])), + inline: true, const_nonmatching: false, combine_substructure: iter_bytes_substructure } diff --git a/src/libsyntax/ext/deriving/primitive.rs b/src/libsyntax/ext/deriving/primitive.rs index 38c30def1d1..77b0d913dcd 100644 --- a/src/libsyntax/ext/deriving/primitive.rs +++ b/src/libsyntax/ext/deriving/primitive.rs @@ -35,6 +35,8 @@ pub fn expand_deriving_from_primitive(cx: @ExtCtxt, None, ~[~Self], true)), + // liable to cause code-bloat + inline: true, const_nonmatching: false, combine_substructure: |c, s, sub| cs_from("i64", c, s, sub), }, @@ -49,6 +51,8 @@ pub fn expand_deriving_from_primitive(cx: @ExtCtxt, None, ~[~Self], true)), + // liable to cause code-bloat + inline: true, const_nonmatching: false, combine_substructure: |c, s, sub| cs_from("u64", c, s, sub), }, diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index d014816c070..2a16d0b025d 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -39,6 +39,7 @@ pub fn expand_deriving_rand(cx: @ExtCtxt, Borrowed(None, ast::MutMutable)) ], ret_ty: Self, + inline: false, const_nonmatching: false, combine_substructure: rand_substructure } diff --git a/src/libsyntax/ext/deriving/to_str.rs b/src/libsyntax/ext/deriving/to_str.rs index 69e5ce566f4..26f4668ccfd 100644 --- a/src/libsyntax/ext/deriving/to_str.rs +++ b/src/libsyntax/ext/deriving/to_str.rs @@ -31,6 +31,7 @@ pub fn expand_deriving_to_str(cx: @ExtCtxt, explicit_self: borrowed_explicit_self(), args: ~[], ret_ty: Ptr(~Literal(Path::new_local("str")), Send), + inline: false, const_nonmatching: false, combine_substructure: to_str_substructure } diff --git a/src/libsyntax/ext/deriving/zero.rs b/src/libsyntax/ext/deriving/zero.rs index 827491ad8cb..939c7b55844 100644 --- a/src/libsyntax/ext/deriving/zero.rs +++ b/src/libsyntax/ext/deriving/zero.rs @@ -30,6 +30,7 @@ pub fn expand_deriving_zero(cx: @ExtCtxt, explicit_self: None, args: ~[], ret_ty: Self, + inline: true, const_nonmatching: false, combine_substructure: zero_substructure }, @@ -39,6 +40,7 @@ pub fn expand_deriving_zero(cx: @ExtCtxt, explicit_self: borrowed_explicit_self(), args: ~[], ret_ty: Literal(Path::new(~["bool"])), + inline: true, const_nonmatching: false, combine_substructure: |cx, span, substr| { cs_and(|cx, span, _, _| cx.span_bug(span, |
