Skip to content

Commit 32f6c11

Browse files
committed
auto merge of #10557 : huonw/rust/inline-deriving, r=pcwalton
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.)
2 parents c4e28ae + df0f503 commit 32f6c11

14 files changed

+27
-1
lines changed

src/libsyntax/ext/deriving/clone.rs

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub fn expand_deriving_clone(cx: @ExtCtxt,
3030
explicit_self: borrowed_explicit_self(),
3131
args: ~[],
3232
ret_ty: Self,
33+
inline: true,
3334
const_nonmatching: false,
3435
combine_substructure: |c, s, sub| cs_clone("Clone", c, s, sub)
3536
}
@@ -55,6 +56,7 @@ pub fn expand_deriving_deep_clone(cx: @ExtCtxt,
5556
explicit_self: borrowed_explicit_self(),
5657
args: ~[],
5758
ret_ty: Self,
59+
inline: true,
5860
const_nonmatching: false,
5961
// cs_clone uses the ident passed to it, i.e. it will
6062
// call deep_clone (not clone) here.

src/libsyntax/ext/deriving/cmp/eq.rs

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub fn expand_deriving_eq(cx: @ExtCtxt,
3737
explicit_self: borrowed_explicit_self(),
3838
args: ~[borrowed_self()],
3939
ret_ty: Literal(Path::new(~["bool"])),
40+
inline: true,
4041
const_nonmatching: true,
4142
combine_substructure: $f
4243
}

src/libsyntax/ext/deriving/cmp/ord.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub fn expand_deriving_ord(cx: @ExtCtxt,
2727
explicit_self: borrowed_explicit_self(),
2828
args: ~[borrowed_self()],
2929
ret_ty: Literal(Path::new(~["bool"])),
30+
inline: true,
3031
const_nonmatching: false,
3132
combine_substructure: |cx, span, substr| cs_op($op, $equal, cx, span, substr)
3233
}

src/libsyntax/ext/deriving/cmp/totaleq.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub fn expand_deriving_totaleq(cx: @ExtCtxt,
3434
explicit_self: borrowed_explicit_self(),
3535
args: ~[borrowed_self()],
3636
ret_ty: Literal(Path::new(~["bool"])),
37+
inline: true,
3738
const_nonmatching: true,
3839
combine_substructure: cs_equals
3940
}

src/libsyntax/ext/deriving/cmp/totalord.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub fn expand_deriving_totalord(cx: @ExtCtxt,
3131
explicit_self: borrowed_explicit_self(),
3232
args: ~[borrowed_self()],
3333
ret_ty: Literal(Path::new(~["std", "cmp", "Ordering"])),
34+
inline: true,
3435
const_nonmatching: false,
3536
combine_substructure: cs_cmp
3637
}

src/libsyntax/ext/deriving/decodable.rs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub fn expand_deriving_decodable(cx: @ExtCtxt,
3939
args: ~[Ptr(~Literal(Path::new_local("__D")),
4040
Borrowed(None, MutMutable))],
4141
ret_ty: Self,
42+
inline: false,
4243
const_nonmatching: true,
4344
combine_substructure: decodable_substructure,
4445
},

src/libsyntax/ext/deriving/default.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub fn expand_deriving_default(cx: @ExtCtxt,
3030
explicit_self: None,
3131
args: ~[],
3232
ret_ty: Self,
33+
inline: true,
3334
const_nonmatching: false,
3435
combine_substructure: default_substructure
3536
},

src/libsyntax/ext/deriving/encodable.rs

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ pub fn expand_deriving_encodable(cx: @ExtCtxt,
101101
args: ~[Ptr(~Literal(Path::new_local("__E")),
102102
Borrowed(None, MutMutable))],
103103
ret_ty: nil_ty(),
104+
inline: false,
104105
const_nonmatching: true,
105106
combine_substructure: encodable_substructure,
106107
},

src/libsyntax/ext/deriving/generic.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ pub struct MethodDef<'self> {
218218
/// Return type
219219
ret_ty: Ty<'self>,
220220

221+
/// Whether to mark this as #[inline]
222+
inline: bool,
223+
221224
/// if the value of the nonmatching enums is independent of the
222225
/// actual enum variants, i.e. can use _ => .. match.
223226
const_nonmatching: bool,
@@ -553,11 +556,16 @@ impl<'self> MethodDef<'self> {
553556
let fn_decl = cx.fn_decl(args, ret_type);
554557
let body_block = cx.block_expr(body);
555558

559+
let attrs = if self.inline {
560+
~[cx.attribute(trait_span, cx.meta_word(trait_span, @"inline"))]
561+
} else {
562+
~[]
563+
};
556564

557565
// Create the method.
558566
@ast::method {
559567
ident: method_ident,
560-
attrs: ~[],
568+
attrs: attrs,
561569
generics: fn_generics,
562570
explicit_self: explicit_self,
563571
purity: ast::impure_fn,

src/libsyntax/ext/deriving/iter_bytes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub fn expand_deriving_iter_bytes(cx: @ExtCtxt,
3333
Literal(Path::new(~["std", "to_bytes", "Cb"]))
3434
],
3535
ret_ty: Literal(Path::new(~["bool"])),
36+
inline: true,
3637
const_nonmatching: false,
3738
combine_substructure: iter_bytes_substructure
3839
}

src/libsyntax/ext/deriving/primitive.rs

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ pub fn expand_deriving_from_primitive(cx: @ExtCtxt,
3535
None,
3636
~[~Self],
3737
true)),
38+
// liable to cause code-bloat
39+
inline: true,
3840
const_nonmatching: false,
3941
combine_substructure: |c, s, sub| cs_from("i64", c, s, sub),
4042
},
@@ -49,6 +51,8 @@ pub fn expand_deriving_from_primitive(cx: @ExtCtxt,
4951
None,
5052
~[~Self],
5153
true)),
54+
// liable to cause code-bloat
55+
inline: true,
5256
const_nonmatching: false,
5357
combine_substructure: |c, s, sub| cs_from("u64", c, s, sub),
5458
},

src/libsyntax/ext/deriving/rand.rs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub fn expand_deriving_rand(cx: @ExtCtxt,
3939
Borrowed(None, ast::MutMutable))
4040
],
4141
ret_ty: Self,
42+
inline: false,
4243
const_nonmatching: false,
4344
combine_substructure: rand_substructure
4445
}

src/libsyntax/ext/deriving/to_str.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub fn expand_deriving_to_str(cx: @ExtCtxt,
3131
explicit_self: borrowed_explicit_self(),
3232
args: ~[],
3333
ret_ty: Ptr(~Literal(Path::new_local("str")), Send),
34+
inline: false,
3435
const_nonmatching: false,
3536
combine_substructure: to_str_substructure
3637
}

src/libsyntax/ext/deriving/zero.rs

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub fn expand_deriving_zero(cx: @ExtCtxt,
3030
explicit_self: None,
3131
args: ~[],
3232
ret_ty: Self,
33+
inline: true,
3334
const_nonmatching: false,
3435
combine_substructure: zero_substructure
3536
},
@@ -39,6 +40,7 @@ pub fn expand_deriving_zero(cx: @ExtCtxt,
3940
explicit_self: borrowed_explicit_self(),
4041
args: ~[],
4142
ret_ty: Literal(Path::new(~["bool"])),
43+
inline: true,
4244
const_nonmatching: false,
4345
combine_substructure: |cx, span, substr| {
4446
cs_and(|cx, span, _, _| cx.span_bug(span,

0 commit comments

Comments
 (0)