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.)
This commit is contained in:
commit
32f6c11dfa
@ -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.
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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,
|
||||
},
|
||||
|
@ -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
|
||||
},
|
||||
|
@ -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,
|
||||
},
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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),
|
||||
},
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user