Skip to content

Mark some derived methods as #[inline]. #10557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/libsyntax/ext/deriving/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/ext/deriving/cmp/eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/ext/deriving/cmp/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/ext/deriving/cmp/totaleq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/ext/deriving/cmp/totalord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/ext/deriving/decodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/ext/deriving/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/ext/deriving/encodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
10 changes: 9 additions & 1 deletion src/libsyntax/ext/deriving/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/ext/deriving/iter_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions src/libsyntax/ext/deriving/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand All @@ -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),
},
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/ext/deriving/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/ext/deriving/to_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions src/libsyntax/ext/deriving/zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand All @@ -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,
Expand Down