Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Add plugin for autoderiving HeapSize #6188
Conversation
|
Critic review: https://critic.hoppipolla.co.uk/r/5103 This is an external review system which you may optionally use for the code review of your pull request. In order to help critic track your changes, please do not make in-place history rewrites (e.g. via |
|
|
Basically it looks good but seems like some clean-up needs to be done before landing; I'd like to see it again before that happens. In particular...
|
|
Sounds good -- I'll fix up these nits later today, and work on unignoring scalar fields and we can work on explaining ignores later. I could also force |
|
The reason is typically a short-to-medium length sentence. I'm not sure if that fits well within a #[...] annotation? But maybe there are other cases where that it acceptable? Not sure. |
|
Annotations can be indented across lines :) |
|
@nnethercote: removed most of the ignores. |
| /// Represents one CSS stacking context, which may or may not have a hardware layer. | ||
| pub struct StackingContext { | ||
| /// The display items that make up this stacking context. | ||
| pub display_list: Box<DisplayList>, | ||
|
|
||
| /// The layer for this stacking context, if there is one. | ||
| #[ignore_heap_size = "FIXME(njn): other fields may be measured later, esp. `layer`"] |
nnethercote
May 27, 2015
Contributor
It looks like this is the only unmeasured field in StackingContext now, in which case this comment should just say something like "FIXME(njn): should measure this at some point".
It looks like this is the only unmeasured field in StackingContext now, in which case this comment should just say something like "FIXME(njn): should measure this at some point".
| pub struct TextDisplayItem { | ||
| /// Fields common to all display items. | ||
| pub base: BaseDisplayItem, | ||
|
|
||
| /// The text run. | ||
| #[ignore_heap_size = "We exclude this because it is non-owning"] |
nnethercote
May 27, 2015
Contributor
"Because it is non-owning" is probably enough for the comment? The "We exclude this" part is redundant once you know that the string is an explanation for the ignore.
"Because it is non-owning" is probably enough for the comment? The "We exclude this" part is redundant once you know that the string is an explanation for the ignore.
| pub struct ImageDisplayItem { | ||
| pub base: BaseDisplayItem, | ||
| #[ignore_heap_size = "We exclude this here because it is non-owning"] |
nnethercote
May 27, 2015
Contributor
Again, "Because it is non-owning" is enough.
Again, "Because it is non-owning" is enough.
| use syntax::ext::build::AstBuilder; | ||
| use syntax::ext::deriving::generic::*; | ||
|
|
||
| pub fn expand_heapsize(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, |
nnethercote
May 27, 2015
Contributor
expand_heap_size, for consistency
expand_heap_size, for consistency
|
|
||
| // Mostly copied from syntax::ext::deriving::hash | ||
| /// Defines how the implementation for `trace()` is to be generated | ||
| fn heapsize_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> { |
nnethercote
May 27, 2015
Contributor
heap_size_substructure, for consistency
heap_size_substructure, for consistency
| }; | ||
|
|
||
| fields.iter().fold(cx.expr_usize(trait_span, 0), | ||
| |acc, ref item| { |
nnethercote
May 27, 2015
Contributor
Nit: is it considered ok Rust style to move the |acc, ref item| { to the previous line? Then the body of the closure would only need to be indented four spaces. I've seen something similar to that used a lot in JS code.
Nit: is it considered ok Rust style to move the |acc, ref item| { to the previous line? Then the body of the closure would only need to be indented four spaces. I've seen something similar to that used a lot in JS code.
| @@ -31,6 +31,8 @@ use syntax::parse::token::intern; | |||
| // Public for documentation to show up | |||
| /// Handles the auto-deriving for `#[jstraceable]` | |||
| pub mod jstraceable; | |||
| /// Handles the auto-deriving for `#[heapsize]` | |||
| pub mod heapsize; | |||
nnethercote
May 27, 2015
Contributor
heap_size, for consistency
heap_size, for consistency
| use geometry::Au; | ||
| use range::Range; | ||
| use cursor::Cursor; | ||
| use azure::azure_hl::Color; |
nnethercote
May 27, 2015
Contributor
This is one of those cases where everybody has a different way of ordering and grouping their use items, right? :(
This is one of those cases where everybody has a different way of ordering and grouping their use items, right? :(
| @@ -158,3 +165,38 @@ impl<T> Drop for LinkedList2<T> { | |||
| fn drop(&mut self) {} | |||
| } | |||
|
|
|||
| /// For use on types defined in external crates | |||
| /// with known heap sizes | |||
nnethercote
May 27, 2015
Contributor
Nit: end sentence with '.', please :)
Nit: end sentence with '.', please :)
| fn heapsize_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> { | ||
| let fields = match *substr.fields { | ||
| Struct(ref fs) | EnumMatching(_, _, ref fs) => fs, | ||
| _ => cx.span_bug(trait_span, "impossible substructure in `heapsize`") |
nnethercote
May 27, 2015
Contributor
heap_size
heap_size
| } | ||
|
|
||
| // Mostly copied from syntax::ext::deriving::hash | ||
| /// Defines how the implementation for `trace()` is to be generated |
nnethercote
May 27, 2015
Contributor
Nit: end sentence with '.'.
Nit: end sentence with '.'.
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| use syntax::ext::base::{Annotatable, ExtCtxt}; |
nnethercote
May 27, 2015
Contributor
I think this file should have a top-level comment briefly explaining what it's for, and when to use the ignore_heap_size annotation.
I think this file should have a top-level comment briefly explaining what it's for, and when to use the ignore_heap_size annotation.
| if a.check_name("ignore_heap_size") { | ||
| match a.node.value.node { | ||
| MetaNameValue(..) => (), | ||
| _ => cx.span_err(a.span, "#[ignore_heap_size] \ |
nnethercote
May 27, 2015
Contributor
Would ignore_heap_size_of or ignore_for_heap_size_of be better? I like having the "of" in there for consistency with HeapSizeOf and heap_size_of_children.
Would ignore_heap_size_of or ignore_for_heap_size_of be better? I like having the "of" in there for consistency with HeapSizeOf and heap_size_of_children.
|
I have lots of nits above, but generally this is looking really nice. Avoiding all this boilerplate will make this code less error-prone, and easier to improve coverage in the future. Thank you for doing it. |
|
Comments addressed. You're welcome! :) |
|
I think this may be worth a blog post! It's certainly a nice example of using Rust to speed up browser development. |
|
On blog.s.org? Sounds good! (Two months of being blocked on things has finally paid off!) |
I've been thinking about writing one myself, comparing the C++ code for this stuff in Firefox to the Rust code for this in Servo. We should avoid both writing one, though... |
|
|
…Of` impls (fixes #5914)
|
@bors-servo r=nnethercote |
|
|
|
|
|
|
|
@bors-servo retry |
Fixes #5914 r? @nnethercote for the gfx changes r? @kmcallister or @jdm for the plugin <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6188) <!-- Reviewable:end -->
|
|
|
Ugh, messed up the rebase |
|
@bors-servo r=nnethercote |
|
|
Fixes #5914 r? @nnethercote for the gfx changes r? @kmcallister or @jdm for the plugin <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6188) <!-- Reviewable:end -->
|
\o/ |
Fixes #5914
r? @nnethercote for the gfx changes
r? @kmcallister or @jdm for the plugin