Skip to content
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

Add plugin for autoderiving HeapSize #6188

Merged
merged 9 commits into from Jun 3, 2015
Merged

Conversation

@Manishearth
Copy link
Member

@Manishearth Manishearth commented May 26, 2015

Fixes #5914

r? @nnethercote for the gfx changes

r? @kmcallister or @jdm for the plugin

Review on Reviewable

@highfive
Copy link

@highfive highfive commented May 26, 2015

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
@hoppipolla-critic-bot
Copy link

@hoppipolla-critic-bot hoppipolla-critic-bot commented May 26, 2015

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 git rebase -i or git commit --amend) when updating this pull request.

@jdm jdm added the S-fails-tidy label May 26, 2015
@jdm
Copy link
Member

@jdm jdm commented May 26, 2015

2.66s$ ./mach test-tidy
components/plugins/heapsize.rs:1: incorrect license
components/plugins/heapsize.rs:10: (much) overlong line
components/plugins/lib.rs:11: (much) overlong line
components/util/mem.rs:188: no newline at EOF
@nnethercote
Copy link
Contributor

@nnethercote nnethercote commented May 27, 2015

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...

  • The naming is inconsistent: heap_size, heapsize, expand_heapsize, known_heap_size, etc. At the very least there should always be a _ in heap_size.
  • Lots of scalar fields are currently marked with #[ignore_heapsize]. It would be better to remove these, using known_heap_size if necessary.
  • Once that's done, it should be easier to achieve the following, worthy goal: every #[ignore_heap_size] annotation should have an accompanying comment explaining why it's ignored. There are a couple of examples in there currently. (One nice thing about the new style is that it's much easier to comment an annotation than to comment an omitted field measurement in heap_size_of_children.)
@Manishearth
Copy link
Member Author

@Manishearth Manishearth commented May 27, 2015

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 #[ignore_heap_size] annotations to have an associated reason btw. (e.g. #[ignore_heap_size = "fixme(njn)"])

@nnethercote
Copy link
Contributor

@nnethercote nnethercote commented May 27, 2015

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.

@Manishearth
Copy link
Member Author

@Manishearth Manishearth commented May 27, 2015

Annotations can be indented across lines :)

@Manishearth
Copy link
Member Author

@Manishearth Manishearth commented May 27, 2015

@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`"]

This comment has been minimized.

@nnethercote

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".

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"]

This comment has been minimized.

@nnethercote

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.

pub struct ImageDisplayItem {
pub base: BaseDisplayItem,
#[ignore_heap_size = "We exclude this here because it is non-owning"]

This comment has been minimized.

@nnethercote

nnethercote May 27, 2015
Contributor

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,

This comment has been minimized.

@nnethercote

nnethercote May 27, 2015
Contributor

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> {

This comment has been minimized.

@nnethercote

nnethercote May 27, 2015
Contributor

heap_size_substructure, for consistency

};

fields.iter().fold(cx.expr_usize(trait_span, 0),
|acc, ref item| {

This comment has been minimized.

@nnethercote

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.

@@ -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;

This comment has been minimized.

@nnethercote

nnethercote May 27, 2015
Contributor

heap_size, for consistency

use geometry::Au;
use range::Range;
use cursor::Cursor;
use azure::azure_hl::Color;

This comment has been minimized.

@nnethercote

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? :(

@@ -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

This comment has been minimized.

@nnethercote

nnethercote May 27, 2015
Contributor

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`")

This comment has been minimized.

@nnethercote

nnethercote May 27, 2015
Contributor

heap_size

}

// Mostly copied from syntax::ext::deriving::hash
/// Defines how the implementation for `trace()` is to be generated

This comment has been minimized.

@nnethercote

nnethercote May 27, 2015
Contributor

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};

This comment has been minimized.

@nnethercote

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.

if a.check_name("ignore_heap_size") {
match a.node.value.node {
MetaNameValue(..) => (),
_ => cx.span_err(a.span, "#[ignore_heap_size] \

This comment has been minimized.

@nnethercote

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.

@nnethercote
Copy link
Contributor

@nnethercote nnethercote commented May 27, 2015

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.

@Manishearth
Copy link
Member Author

@Manishearth Manishearth commented May 28, 2015

Comments addressed.

You're welcome! :)

@pcwalton
Copy link
Contributor

@pcwalton pcwalton commented May 28, 2015

I think this may be worth a blog post! It's certainly a nice example of using Rust to speed up browser development.

@Manishearth
Copy link
Member Author

@Manishearth Manishearth commented May 28, 2015

On blog.s.org? Sounds good! 😄

(Two months of being blocked on things has finally paid off!)

@nnethercote
Copy link
Contributor

@nnethercote nnethercote commented May 28, 2015

I think this may be worth a blog post!

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...

@Manishearth Manishearth force-pushed the Manishearth:sizeof branch from 80ad7da to 733acdf Jun 1, 2015
@bors-servo
Copy link
Contributor

@bors-servo bors-servo commented Jun 3, 2015

💔 Test failed - mac1

@Manishearth Manishearth force-pushed the Manishearth:sizeof branch from 1b9293b to d2496a4 Jun 3, 2015
@Manishearth
Copy link
Member Author

@Manishearth Manishearth commented Jun 3, 2015

@bors-servo r=nnethercote

@bors-servo
Copy link
Contributor

@bors-servo bors-servo commented Jun 3, 2015

📌 Commit d2496a4 has been approved by nnethercote

@bors-servo
Copy link
Contributor

@bors-servo bors-servo commented Jun 3, 2015

Testing commit d2496a4 with merge 60ac15e...

@bors-servo
Copy link
Contributor

@bors-servo bors-servo commented Jun 3, 2015

💔 Test failed - linux1

@Manishearth
Copy link
Member Author

@Manishearth Manishearth commented Jun 3, 2015

@bors-servo retry

@bors-servo
Copy link
Contributor

@bors-servo bors-servo commented Jun 3, 2015

Testing commit d2496a4 with merge 1b75693...

bors-servo pushed a commit that referenced this pull request Jun 3, 2015
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 -->
@bors-servo
Copy link
Contributor

@bors-servo bors-servo commented Jun 3, 2015

💔 Test failed - linux1

@Manishearth
Copy link
Member Author

@Manishearth Manishearth commented Jun 3, 2015

Ugh, messed up the rebase

@Manishearth Manishearth force-pushed the Manishearth:sizeof branch from 54b12f2 to d347aed Jun 3, 2015
@Manishearth
Copy link
Member Author

@Manishearth Manishearth commented Jun 3, 2015

@bors-servo r=nnethercote

@bors-servo
Copy link
Contributor

@bors-servo bors-servo commented Jun 3, 2015

📌 Commit d347aed has been approved by nnethercote

@bors-servo
Copy link
Contributor

@bors-servo bors-servo commented Jun 3, 2015

Testing commit d347aed with merge 2ca606a...

bors-servo pushed a commit that referenced this pull request Jun 3, 2015
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 -->
@bors-servo
Copy link
Contributor

@bors-servo bors-servo commented Jun 3, 2015

☀️ Test successful - android, gonk, linux1, linux2, linux3, mac1, mac2

@bors-servo bors-servo merged commit d347aed into servo:master Jun 3, 2015
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@nnethercote
Copy link
Contributor

@nnethercote nnethercote commented Jun 3, 2015

\o/

@Manishearth Manishearth deleted the Manishearth:sizeof branch Jun 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

8 participants
You can’t perform that action at this time.