From f4bc92526a5b76d4d23267e9e5881f65eee264e8 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 31 Mar 2015 08:32:11 +0530 Subject: [PATCH 1/9] Add #[heapsize]/#[derive(HeapSizeOf)] plugin to auto-derive `HeapSizeOf` impls (fixes #5914) --- components/plugins/heapsize.rs | 54 ++++++++++++++++++++++++++++++++++ components/plugins/lib.rs | 7 +++-- components/util/mem.rs | 28 ++++++++++++++++++ 3 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 components/plugins/heapsize.rs diff --git a/components/plugins/heapsize.rs b/components/plugins/heapsize.rs new file mode 100644 index 00000000000..4da8cc070a8 --- /dev/null +++ b/components/plugins/heapsize.rs @@ -0,0 +1,54 @@ + +use syntax::ext::base::{Annotatable, ExtCtxt}; +use syntax::codemap::Span; +use syntax::ptr::P; +use syntax::ast::*; +use syntax::attr::AttrMetaMethods; +use syntax::ext::build::AstBuilder; +use syntax::ext::deriving::generic::*; + +pub fn expand_heapsize(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, item: Annotatable, push: &mut FnMut(Annotatable)) { + let trait_def = TraitDef { + span: span, + attributes: Vec::new(), + path: ty::Path::new(vec!("util", "mem", "HeapSizeOf")), + additional_bounds: Vec::new(), + generics: ty::LifetimeBounds::empty(), + methods: vec![ + MethodDef { + name: "heap_size_of_children", + generics: ty::LifetimeBounds::empty(), + explicit_self: ty::borrowed_explicit_self(), + args: vec!(), + ret_ty: ty::Literal(ty::Path::new_local("usize")), + attributes: vec!(), + is_unsafe: false, + combine_substructure: combine_substructure(Box::new(heapsize_substructure)) + } + ], + associated_types: vec![], + }; + trait_def.expand(cx, mitem, &item, push) +} + +fn heapsize_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P { + let fields = match *substr.fields { + Struct(ref fs) | EnumMatching(_, _, ref fs) => fs, + _ => cx.span_bug(trait_span, "impossible substructure in `heapsize`") + }; + + fields.iter().fold(cx.expr_usize(trait_span, 0), + |acc, ref item| { + if item.attrs.iter() + .find(|ref a| a.check_name("ignore_heapsize")) + .is_some() { + acc + } else { + cx.expr_binary(item.span, BiAdd, acc, + cx.expr_method_call(item.span, + item.self_.clone(), + substr.method_ident, + Vec::new())) + } + }) +} diff --git a/components/plugins/lib.rs b/components/plugins/lib.rs index 614cce94ab3..6138e4bef84 100644 --- a/components/plugins/lib.rs +++ b/components/plugins/lib.rs @@ -8,8 +8,7 @@ //! //! - `#[privatize]` : Forces all fields in a struct/enum to be private //! - `#[jstraceable]` : Auto-derives an implementation of `JSTraceable` for a struct in the script crate -//! - `#[must_root]` : Prevents data of the marked type from being used on the stack. See the lints module for more -//! details +//! - `#[must_root]` : Prevents data of the marked type from being used on the stack. See the lints module for more details //! - `#[dom_struct]` : Implies `#[privatize]`,`#[jstraceable]`, and `#[must_root]`. //! Use this for structs that correspond to a DOM type @@ -31,6 +30,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; /// Autogenerates implementations of Reflectable on DOM structs pub mod reflector; pub mod lints; @@ -43,6 +44,8 @@ pub fn plugin_registrar(reg: &mut Registry) { reg.register_syntax_extension(intern("dom_struct"), MultiModifier(box jstraceable::expand_dom_struct)); reg.register_syntax_extension(intern("jstraceable"), MultiDecorator(box jstraceable::expand_jstraceable)); reg.register_syntax_extension(intern("_generate_reflector"), MultiDecorator(box reflector::expand_reflector)); + reg.register_syntax_extension(intern("derive_HeapSizeOf"), MultiDecorator(box heapsize::expand_heapsize)); + reg.register_syntax_extension(intern("heapsize"), MultiDecorator(box heapsize::expand_heapsize)); reg.register_macro("to_lower", casing::expand_lower); reg.register_macro("to_upper", casing::expand_upper); reg.register_lint_pass(box lints::transmute_type::TransmutePass as LintPassObject); diff --git a/components/util/mem.rs b/components/util/mem.rs index cd1b9834e48..175863ddb9e 100644 --- a/components/util/mem.rs +++ b/components/util/mem.rs @@ -158,3 +158,31 @@ impl Drop for LinkedList2 { fn drop(&mut self) {} } +/// For use on types defined in external crates +/// with known heap sizes +#[macro_export] +macro_rules! known_heap_size( + ($size:expr, $($ty:ident),+) => ( + $( + impl $crate::mem::HeapSizeOf for $ty { + #[inline] + fn heap_size_of_children(&self) -> usize { + $size + } + } + )+ + ); + ($size: expr, $ty:ident<$($gen:ident),+>) => ( + impl<$($gen),+> $crate::mem::HeapSizeOf for $ty<$($gen),+> { + #[inline] + fn heap_size_of_children(&self) -> usize { + $size + } + } + ); +); + + +known_heap_size!(0, u8, u16, u32, u64, usize); +known_heap_size!(0, i8, i16, i32, i64, isize); +known_heap_size!(0, bool); \ No newline at end of file From c1daf889afd396226bf4eb6a90a0a084e4677dc5 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 26 May 2015 23:34:17 +0530 Subject: [PATCH 2/9] use HeapSizeOf plugin in gfx --- components/gfx/display_list/mod.rs | 20 ++++++++------------ components/gfx/lib.rs | 3 ++- components/plugins/heapsize.rs | 8 ++++++-- components/plugins/lib.rs | 6 +++--- components/util/mem.rs | 6 +++--- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/components/gfx/display_list/mod.rs b/components/gfx/display_list/mod.rs index 1aef67246a8..393b909ed96 100644 --- a/components/gfx/display_list/mod.rs +++ b/components/gfx/display_list/mod.rs @@ -27,7 +27,7 @@ use azure::azure::AzFloat; use azure::azure_hl::{Color}; use collections::linked_list::{self, LinkedList}; -use geom::{Matrix2D, Point2D, Rect, SideOffsets2D, Size2D, Matrix4}; +use geom::{Point2D, Rect, SideOffsets2D, Size2D, Matrix2D}; use geom::approxeq::ApproxEq; use geom::num::Zero; use libc::uintptr_t; @@ -254,7 +254,8 @@ pub struct StackingContext { pub blend_mode: mix_blend_mode::T, /// A transform to be applied to this stacking context. - pub transform: Matrix4, + #[ignore_heap_size] + pub transform: Matrix2D, } impl StackingContext { @@ -264,7 +265,7 @@ impl StackingContext { bounds: &Rect, overflow: &Rect, z_index: i32, - transform: &Matrix4, + transform: &Matrix2D, filters: filter::T, blend_mode: mix_blend_mode::T, layer: Option>) @@ -285,7 +286,7 @@ impl StackingContext { pub fn optimize_and_draw_into_context(&self, paint_context: &mut PaintContext, tile_bounds: &Rect, - transform: &Matrix4, + transform: &Matrix2D, clip_rect: Option<&Rect>) { let transform = transform.mul(&self.transform); let temporary_draw_target = @@ -318,10 +319,7 @@ impl StackingContext { // Set up our clip rect and transform. let old_transform = paint_subcontext.draw_target.get_transform(); - let xform_2d = Matrix2D::new(transform.m11, transform.m12, - transform.m21, transform.m22, - transform.m41, transform.m42); - paint_subcontext.draw_target.set_transform(&xform_2d); + paint_subcontext.draw_target.set_transform(&transform); paint_subcontext.push_clip_if_applicable(); // Steps 1 and 2: Borders and background for the root. @@ -343,8 +341,7 @@ impl StackingContext { positioned_kid.bounds .origin .y - .to_nearest_px() as AzFloat, - 0.0); + .to_nearest_px() as AzFloat); let new_tile_rect = self.compute_tile_rect_for_child_stacking_context(tile_bounds, &**positioned_kid); @@ -392,8 +389,7 @@ impl StackingContext { positioned_kid.bounds .origin .y - .to_nearest_px() as AzFloat, - 0.0); + .to_nearest_px() as AzFloat); let new_tile_rect = self.compute_tile_rect_for_child_stacking_context(tile_bounds, &**positioned_kid); diff --git a/components/gfx/lib.rs b/components/gfx/lib.rs index 236eafd83d8..90d3d8ca962 100644 --- a/components/gfx/lib.rs +++ b/components/gfx/lib.rs @@ -6,7 +6,8 @@ #![feature(box_syntax)] #![feature(collections)] #![feature(core)] -#![feature(plugin)] +#![feature(plugin, custom_attribute)] +#![feature(custom_derive)] #![feature(rustc_private)] #![feature(std_misc)] #![feature(str_char)] diff --git a/components/plugins/heapsize.rs b/components/plugins/heapsize.rs index 4da8cc070a8..1a6d27fea22 100644 --- a/components/plugins/heapsize.rs +++ b/components/plugins/heapsize.rs @@ -1,3 +1,6 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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}; use syntax::codemap::Span; @@ -7,7 +10,8 @@ use syntax::attr::AttrMetaMethods; use syntax::ext::build::AstBuilder; use syntax::ext::deriving::generic::*; -pub fn expand_heapsize(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, item: Annotatable, push: &mut FnMut(Annotatable)) { +pub fn expand_heapsize(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, + item: Annotatable, push: &mut FnMut(Annotatable)) { let trait_def = TraitDef { span: span, attributes: Vec::new(), @@ -40,7 +44,7 @@ fn heapsize_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructu fields.iter().fold(cx.expr_usize(trait_span, 0), |acc, ref item| { if item.attrs.iter() - .find(|ref a| a.check_name("ignore_heapsize")) + .find(|ref a| a.check_name("ignore_heap_size")) .is_some() { acc } else { diff --git a/components/plugins/lib.rs b/components/plugins/lib.rs index 6138e4bef84..fd8fdd615b7 100644 --- a/components/plugins/lib.rs +++ b/components/plugins/lib.rs @@ -8,9 +8,10 @@ //! //! - `#[privatize]` : Forces all fields in a struct/enum to be private //! - `#[jstraceable]` : Auto-derives an implementation of `JSTraceable` for a struct in the script crate -//! - `#[must_root]` : Prevents data of the marked type from being used on the stack. See the lints module for more details +//! - `#[must_root]` : Prevents data of the marked type from being used on the stack. +//! See the lints module for more details //! - `#[dom_struct]` : Implies `#[privatize]`,`#[jstraceable]`, and `#[must_root]`. -//! Use this for structs that correspond to a DOM type +//! Use this for structs that correspond to a DOM type #![feature(plugin_registrar, quote, plugin, box_syntax, rustc_private, collections)] @@ -45,7 +46,6 @@ pub fn plugin_registrar(reg: &mut Registry) { reg.register_syntax_extension(intern("jstraceable"), MultiDecorator(box jstraceable::expand_jstraceable)); reg.register_syntax_extension(intern("_generate_reflector"), MultiDecorator(box reflector::expand_reflector)); reg.register_syntax_extension(intern("derive_HeapSizeOf"), MultiDecorator(box heapsize::expand_heapsize)); - reg.register_syntax_extension(intern("heapsize"), MultiDecorator(box heapsize::expand_heapsize)); reg.register_macro("to_lower", casing::expand_lower); reg.register_macro("to_upper", casing::expand_upper); reg.register_lint_pass(box lints::transmute_type::TransmutePass as LintPassObject); diff --git a/components/util/mem.rs b/components/util/mem.rs index 175863ddb9e..8bbfb909199 100644 --- a/components/util/mem.rs +++ b/components/util/mem.rs @@ -165,7 +165,7 @@ macro_rules! known_heap_size( ($size:expr, $($ty:ident),+) => ( $( impl $crate::mem::HeapSizeOf for $ty { - #[inline] + #[inline(always)] fn heap_size_of_children(&self) -> usize { $size } @@ -174,7 +174,7 @@ macro_rules! known_heap_size( ); ($size: expr, $ty:ident<$($gen:ident),+>) => ( impl<$($gen),+> $crate::mem::HeapSizeOf for $ty<$($gen),+> { - #[inline] + #[inline(always)] fn heap_size_of_children(&self) -> usize { $size } @@ -185,4 +185,4 @@ macro_rules! known_heap_size( known_heap_size!(0, u8, u16, u32, u64, usize); known_heap_size!(0, i8, i16, i32, i64, isize); -known_heap_size!(0, bool); \ No newline at end of file +known_heap_size!(0, bool); From a5975e8f33b5404493893ffd6ece776de9763d26 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 27 May 2015 22:11:01 +0530 Subject: [PATCH 3/9] use knownheapsize for geom stuff --- components/gfx/display_list/mod.rs | 141 +++++++---------------------- components/util/mem.rs | 18 +++- 2 files changed, 48 insertions(+), 111 deletions(-) diff --git a/components/gfx/display_list/mod.rs b/components/gfx/display_list/mod.rs index 393b909ed96..6e085ebb66c 100644 --- a/components/gfx/display_list/mod.rs +++ b/components/gfx/display_list/mod.rs @@ -66,7 +66,7 @@ const MIN_INDENTATION_LENGTH: usize = 4; /// Because the script task's GC does not trace layout, node data cannot be safely stored in layout /// data structures. Also, layout code tends to be faster when the DOM is not being accessed, for /// locality reasons. Using `OpaqueNode` enforces this invariant. -#[derive(Clone, PartialEq, Copy, Debug)] +#[derive(Clone, PartialEq, Copy, Debug, HeapSizeOf)] pub struct OpaqueNode(pub uintptr_t); impl OpaqueNode { @@ -82,6 +82,7 @@ impl OpaqueNode { /// /// TODO(pcwalton): We could reduce the size of this structure with a more "skip list"-like /// structure, omitting several pointers and lengths. +#[derive(HeapSizeOf)] pub struct DisplayList { /// The border and backgrounds for the root of this stacking context: steps 1 and 2. pub background_and_borders: LinkedList, @@ -218,24 +219,15 @@ impl DisplayList { } } -impl HeapSizeOf for DisplayList { - fn heap_size_of_children(&self) -> usize { - self.background_and_borders.heap_size_of_children() + - self.block_backgrounds_and_borders.heap_size_of_children() + - self.floats.heap_size_of_children() + - self.content.heap_size_of_children() + - self.positioned_content.heap_size_of_children() + - self.outlines.heap_size_of_children() + - self.children.heap_size_of_children() - } -} - +// FIXME(njn): other fields may be measured later, esp. `layer` +#[derive(HeapSizeOf)] /// 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, /// The layer for this stacking context, if there is one. + #[ignore_heap_size] pub layer: Option>, /// The position and size of this stacking context. @@ -248,13 +240,14 @@ pub struct StackingContext { pub z_index: i32, /// CSS filters to be applied to this stacking context (including opacity). + #[ignore_heap_size] pub filters: filter::T, /// The blend mode with which this stacking context blends with its backdrop. + #[ignore_heap_size] pub blend_mode: mix_blend_mode::T, /// A transform to be applied to this stacking context. - #[ignore_heap_size] pub transform: Matrix2D, } @@ -584,14 +577,6 @@ impl StackingContext { } } -impl HeapSizeOf for StackingContext { - fn heap_size_of_children(&self) -> usize { - self.display_list.heap_size_of_children() - - // FIXME(njn): other fields may be measured later, esp. `layer` - } -} - /// Returns the stacking context in the given tree of stacking contexts with a specific layer ID. pub fn find_stacking_context_with_layer_id(this: &Arc, layer_id: LayerId) -> Option> { @@ -611,7 +596,7 @@ pub fn find_stacking_context_with_layer_id(this: &Arc, layer_id } /// One drawing command in the list. -#[derive(Clone)] +#[derive(Clone, HeapSizeOf)] pub enum DisplayItem { SolidColorClass(Box), TextClass(Box), @@ -623,7 +608,7 @@ pub enum DisplayItem { } /// Information common to all display items. -#[derive(Clone)] +#[derive(Clone, HeapSizeOf)] pub struct BaseDisplayItem { /// The boundaries of the display item, in layer coordinates. pub bounds: Rect, @@ -647,17 +632,11 @@ impl BaseDisplayItem { } } -impl HeapSizeOf for BaseDisplayItem { - fn heap_size_of_children(&self) -> usize { - self.metadata.heap_size_of_children() + - self.clip.heap_size_of_children() - } -} /// A clipping region for a display item. Currently, this can describe rectangles, rounded /// rectangles (for `border-radius`), or arbitrary intersections of the two. Arbitrary transforms /// are not supported because those are handled by the higher-level `StackingContext` abstraction. -#[derive(Clone, PartialEq, Debug)] +#[derive(Clone, PartialEq, Debug, HeapSizeOf)] pub struct ClippingRegion { /// The main rectangular region. This does not include any corners. pub main: Rect, @@ -671,7 +650,7 @@ pub struct ClippingRegion { /// A complex clipping region. These don't as easily admit arbitrary intersection operations, so /// they're stored in a list over to the side. Currently a complex clipping region is just a /// rounded rectangle, but the CSS WGs will probably make us throw more stuff in here eventually. -#[derive(Clone, PartialEq, Debug)] +#[derive(Clone, PartialEq, Debug, HeapSizeOf)] pub struct ComplexClippingRegion { /// The boundaries of the rectangle. pub rect: Rect, @@ -779,27 +758,17 @@ impl ClippingRegion { } } -impl HeapSizeOf for ClippingRegion { - fn heap_size_of_children(&self) -> usize { - self.complex.heap_size_of_children() - } -} - -impl HeapSizeOf for ComplexClippingRegion { - fn heap_size_of_children(&self) -> usize { - 0 - } -} /// Metadata attached to each display item. This is useful for performing auxiliary tasks with /// the display list involving hit testing: finding the originating DOM node and determining the /// cursor to use when the element is hovered over. -#[derive(Clone, Copy)] +#[derive(Clone, Copy, HeapSizeOf)] pub struct DisplayItemMetadata { /// The DOM node from which this display item originated. pub node: OpaqueNode, /// The value of the `cursor` property when the mouse hovers over this display item. If `None`, /// this display item is ineligible for pointer events (`pointer-events: none`). + #[ignore_heap_size] pub pointing: Option, } @@ -822,41 +791,33 @@ impl DisplayItemMetadata { } } -impl HeapSizeOf for DisplayItemMetadata { - fn heap_size_of_children(&self) -> usize { - 0 - } -} - /// Paints a solid color. -#[derive(Clone)] +#[derive(Clone, HeapSizeOf)] pub struct SolidColorDisplayItem { /// Fields common to all display items. pub base: BaseDisplayItem, /// The color. + #[ignore_heap_size] pub color: Color, } -impl HeapSizeOf for SolidColorDisplayItem { - fn heap_size_of_children(&self) -> usize { - self.base.heap_size_of_children() - } -} - /// Paints text. -#[derive(Clone)] +#[derive(Clone, HeapSizeOf)] pub struct TextDisplayItem { /// Fields common to all display items. pub base: BaseDisplayItem, /// The text run. + #[ignore_heap_size] // We exclude `text_run` because it is non-owning. pub text_run: Arc>, /// The range of text within the text run. + #[ignore_heap_size] pub range: Range, /// The color of the text. + #[ignore_heap_size] pub text_color: Color, /// The position of the start of the baseline of this text. @@ -869,14 +830,7 @@ pub struct TextDisplayItem { pub blur_radius: Au, } -impl HeapSizeOf for TextDisplayItem { - fn heap_size_of_children(&self) -> usize { - self.base.heap_size_of_children() - // We exclude `text_run` because it is non-owning. - } -} - -#[derive(Clone, Eq, PartialEq)] +#[derive(Clone, Eq, PartialEq, HeapSizeOf)] pub enum TextOrientation { Upright, SidewaysLeft, @@ -884,9 +838,10 @@ pub enum TextOrientation { } /// Paints an image. -#[derive(Clone)] +#[derive(Clone, HeapSizeOf)] pub struct ImageDisplayItem { pub base: BaseDisplayItem, + #[ignore_heap_size] // We exclude `image` here because it is non-owning. pub image: Arc, /// The dimensions to which the image display item should be stretched. If this is smaller than @@ -896,15 +851,10 @@ pub struct ImageDisplayItem { /// The algorithm we should use to stretch the image. See `image_rendering` in CSS-IMAGES-3 § /// 5.3. + #[ignore_heap_size] pub image_rendering: image_rendering::T, } -impl HeapSizeOf for ImageDisplayItem { - fn heap_size_of_children(&self) -> usize { - self.base.heap_size_of_children() - // We exclude `image` here because it is non-owning. - } -} /// Paints a gradient. #[derive(Clone)] @@ -922,6 +872,7 @@ pub struct GradientDisplayItem { pub stops: Vec, } + impl HeapSizeOf for GradientDisplayItem { fn heap_size_of_children(&self) -> usize { use libc::c_void; @@ -937,7 +888,7 @@ impl HeapSizeOf for GradientDisplayItem { /// Paints a border. -#[derive(Clone)] +#[derive(Clone, HeapSizeOf)] pub struct BorderDisplayItem { /// Fields common to all display items. pub base: BaseDisplayItem, @@ -946,9 +897,11 @@ pub struct BorderDisplayItem { pub border_widths: SideOffsets2D, /// Border colors. + #[ignore_heap_size] pub color: SideOffsets2D, /// Border styles. + #[ignore_heap_size] pub style: SideOffsets2D, /// Border radii. @@ -957,12 +910,6 @@ pub struct BorderDisplayItem { pub radius: BorderRadii, } -impl HeapSizeOf for BorderDisplayItem { - fn heap_size_of_children(&self) -> usize { - self.base.heap_size_of_children() - } -} - /// Information about the border radii. /// /// TODO(pcwalton): Elliptical radii. @@ -996,25 +943,21 @@ impl BorderRadii where T: PartialEq + Zero + Clone { } /// Paints a line segment. -#[derive(Clone)] +#[derive(Clone, HeapSizeOf)] pub struct LineDisplayItem { pub base: BaseDisplayItem, /// The line segment color. + #[ignore_heap_size] pub color: Color, /// The line segment style. + #[ignore_heap_size] pub style: border_style::T } -impl HeapSizeOf for LineDisplayItem { - fn heap_size_of_children(&self) -> usize { - self.base.heap_size_of_children() - } -} - /// Paints a box shadow per CSS-BACKGROUNDS. -#[derive(Clone)] +#[derive(Clone, HeapSizeOf)] pub struct BoxShadowDisplayItem { /// Fields common to all display items. pub base: BaseDisplayItem, @@ -1026,6 +969,7 @@ pub struct BoxShadowDisplayItem { pub offset: Point2D, /// The color of this shadow. + #[ignore_heap_size] pub color: Color, /// The blur radius for this shadow. @@ -1038,14 +982,8 @@ pub struct BoxShadowDisplayItem { pub clip_mode: BoxShadowClipMode, } -impl HeapSizeOf for BoxShadowDisplayItem { - fn heap_size_of_children(&self) -> usize { - self.base.heap_size_of_children() - } -} - /// How a box shadow should be clipped. -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, HeapSizeOf)] pub enum BoxShadowClipMode { /// No special clipping should occur. This is used for (shadowed) text decorations. None, @@ -1206,17 +1144,4 @@ impl fmt::Debug for DisplayItem { } } -impl HeapSizeOf for DisplayItem { - fn heap_size_of_children(&self) -> usize { - match *self { - SolidColorClass(ref item) => item.heap_size_of_children(), - TextClass(ref item) => item.heap_size_of_children(), - ImageClass(ref item) => item.heap_size_of_children(), - BorderClass(ref item) => item.heap_size_of_children(), - GradientClass(ref item) => item.heap_size_of_children(), - LineClass(ref item) => item.heap_size_of_children(), - BoxShadowClass(ref item) => item.heap_size_of_children(), - } - } -} diff --git a/components/util/mem.rs b/components/util/mem.rs index 8bbfb909199..6c9f04af984 100644 --- a/components/util/mem.rs +++ b/components/util/mem.rs @@ -9,6 +9,11 @@ use std::collections::LinkedList; use std::mem::transmute; use std::sync::Arc; +use geom::{Point2D, Rect, SideOffsets2D, Size2D, Matrix2D}; + +use geometry::Au; +use range::Range; + extern { // Get the size of a heap block. // @@ -172,17 +177,24 @@ macro_rules! known_heap_size( } )+ ); - ($size: expr, $ty:ident<$($gen:ident),+>) => ( - impl<$($gen),+> $crate::mem::HeapSizeOf for $ty<$($gen),+> { + ($size: expr, $($ty:ident<$($gen:ident),+>),+) => ( + $( + impl<$($gen: $crate::mem::HeapSizeOf),+> $crate::mem::HeapSizeOf for $ty<$($gen),+> { #[inline(always)] fn heap_size_of_children(&self) -> usize { $size } } + )+ ); ); known_heap_size!(0, u8, u16, u32, u64, usize); known_heap_size!(0, i8, i16, i32, i64, isize); -known_heap_size!(0, bool); +known_heap_size!(0, bool, f32, f64); + +known_heap_size!(0, Rect, Point2D, Size2D, Matrix2D, SideOffsets2D); + +known_heap_size!(0, Au); +known_heap_size!(0, Range); \ No newline at end of file From 5447d2af3d4e73eeece380f08ffd9e22d1d454c3 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 27 May 2015 22:24:49 +0530 Subject: [PATCH 4/9] remove more heapsize ignores --- components/gfx/display_list/mod.rs | 10 +--------- components/gfx/text/glyph.rs | 1 + components/style/lib.rs | 3 ++- components/style/properties.mako.rs | 4 ++-- components/style/values.rs | 2 +- components/util/mem.rs | 5 +++-- 6 files changed, 10 insertions(+), 15 deletions(-) diff --git a/components/gfx/display_list/mod.rs b/components/gfx/display_list/mod.rs index 6e085ebb66c..9d2c3c46848 100644 --- a/components/gfx/display_list/mod.rs +++ b/components/gfx/display_list/mod.rs @@ -24,7 +24,7 @@ use text::glyph::CharIndex; use text::TextRun; use azure::azure::AzFloat; -use azure::azure_hl::{Color}; +use azure::azure_hl::Color; use collections::linked_list::{self, LinkedList}; use geom::{Point2D, Rect, SideOffsets2D, Size2D, Matrix2D}; @@ -798,7 +798,6 @@ pub struct SolidColorDisplayItem { pub base: BaseDisplayItem, /// The color. - #[ignore_heap_size] pub color: Color, } @@ -813,11 +812,9 @@ pub struct TextDisplayItem { pub text_run: Arc>, /// The range of text within the text run. - #[ignore_heap_size] pub range: Range, /// The color of the text. - #[ignore_heap_size] pub text_color: Color, /// The position of the start of the baseline of this text. @@ -897,11 +894,9 @@ pub struct BorderDisplayItem { pub border_widths: SideOffsets2D, /// Border colors. - #[ignore_heap_size] pub color: SideOffsets2D, /// Border styles. - #[ignore_heap_size] pub style: SideOffsets2D, /// Border radii. @@ -948,11 +943,9 @@ pub struct LineDisplayItem { pub base: BaseDisplayItem, /// The line segment color. - #[ignore_heap_size] pub color: Color, /// The line segment style. - #[ignore_heap_size] pub style: border_style::T } @@ -969,7 +962,6 @@ pub struct BoxShadowDisplayItem { pub offset: Point2D, /// The color of this shadow. - #[ignore_heap_size] pub color: Color, /// The blur radius for this shadow. diff --git a/components/gfx/text/glyph.rs b/components/gfx/text/glyph.rs index 0edddf87459..bc900960be9 100644 --- a/components/gfx/text/glyph.rs +++ b/components/gfx/text/glyph.rs @@ -519,6 +519,7 @@ int_range_index! { #[derive(RustcEncodable)] #[doc = "An index that refers to a character in a text run. This could \ point to the middle of a glyph."] + #[derive(HeapSizeOf)] struct CharIndex(isize) } diff --git a/components/style/lib.rs b/components/style/lib.rs index 9469d021196..7fa25ac8fad 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -9,8 +9,9 @@ #![feature(collections)] #![feature(hash)] #![feature(rustc_private)] - +#![feature(custom_attribute, custom_derive)] #![plugin(string_cache_plugin)] +#![plugin(plugins)] #[macro_use] extern crate log; #[macro_use] extern crate bitflags; diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs index 01ee1f884e2..0e630183801 100644 --- a/components/style/properties.mako.rs +++ b/components/style/properties.mako.rs @@ -1027,8 +1027,8 @@ pub mod longhands { #[inline] pub fn get_initial_value() -> computed_value::T { computed_value::T(vec![ - ("\u{201c}".to_string(), "\u{201d}".to_string()), - ("\u{2018}".to_string(), "\u{2019}".to_string()), + ("\u{201c}".to_owned(), "\u{201d}".to_owned()), + ("\u{2018}".to_owned(), "\u{2019}".to_owned()), ]) } diff --git a/components/style/values.rs b/components/style/values.rs index 5c2c29f7aef..f1d9a9df9fa 100644 --- a/components/style/values.rs +++ b/components/style/values.rs @@ -43,7 +43,7 @@ macro_rules! define_numbered_css_keyword_enum { }; ($name: ident: $( $css: expr => $variant: ident = $value: expr ),+) => { #[allow(non_camel_case_types)] - #[derive(Clone, Eq, PartialEq, PartialOrd, Ord, Copy, RustcEncodable, Debug)] + #[derive(Clone, Eq, PartialEq, PartialOrd, Ord, Copy, RustcEncodable, Debug, HeapSizeOf)] pub enum $name { $( $variant = $value ),+ } diff --git a/components/util/mem.rs b/components/util/mem.rs index 6c9f04af984..3575627d46a 100644 --- a/components/util/mem.rs +++ b/components/util/mem.rs @@ -13,6 +13,7 @@ use geom::{Point2D, Rect, SideOffsets2D, Size2D, Matrix2D}; use geometry::Au; use range::Range; +use azure::azure_hl::Color; extern { // Get the size of a heap block. @@ -196,5 +197,5 @@ known_heap_size!(0, bool, f32, f64); known_heap_size!(0, Rect, Point2D, Size2D, Matrix2D, SideOffsets2D); -known_heap_size!(0, Au); -known_heap_size!(0, Range); \ No newline at end of file +known_heap_size!(0, Au, Color); +known_heap_size!(0, Range); From 13b4bcfbb7ce7a7337d28e30a8a6a2954dd14e50 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 27 May 2015 22:53:01 +0530 Subject: [PATCH 5/9] Remove all Arc-less ignores, force reasons, ignore_heap_size_of --- components/gfx/display_list/mod.rs | 11 ++-- components/plugins/heap_size.rs | 81 +++++++++++++++++++++++++++++ components/plugins/heapsize.rs | 58 --------------------- components/plugins/lib.rs | 6 +-- components/style/properties.mako.rs | 6 +-- components/style/values.rs | 5 +- components/util/mem.rs | 12 ++--- 7 files changed, 97 insertions(+), 82 deletions(-) create mode 100644 components/plugins/heap_size.rs delete mode 100644 components/plugins/heapsize.rs diff --git a/components/gfx/display_list/mod.rs b/components/gfx/display_list/mod.rs index 9d2c3c46848..45f74b3185b 100644 --- a/components/gfx/display_list/mod.rs +++ b/components/gfx/display_list/mod.rs @@ -219,7 +219,6 @@ impl DisplayList { } } -// FIXME(njn): other fields may be measured later, esp. `layer` #[derive(HeapSizeOf)] /// Represents one CSS stacking context, which may or may not have a hardware layer. pub struct StackingContext { @@ -227,7 +226,7 @@ pub struct StackingContext { pub display_list: Box, /// The layer for this stacking context, if there is one. - #[ignore_heap_size] + #[ignore_heap_size_of = "FIXME(njn): should measure this at some point"] pub layer: Option>, /// The position and size of this stacking context. @@ -240,11 +239,9 @@ pub struct StackingContext { pub z_index: i32, /// CSS filters to be applied to this stacking context (including opacity). - #[ignore_heap_size] pub filters: filter::T, /// The blend mode with which this stacking context blends with its backdrop. - #[ignore_heap_size] pub blend_mode: mix_blend_mode::T, /// A transform to be applied to this stacking context. @@ -768,7 +765,6 @@ pub struct DisplayItemMetadata { pub node: OpaqueNode, /// The value of the `cursor` property when the mouse hovers over this display item. If `None`, /// this display item is ineligible for pointer events (`pointer-events: none`). - #[ignore_heap_size] pub pointing: Option, } @@ -808,7 +804,7 @@ pub struct TextDisplayItem { pub base: BaseDisplayItem, /// The text run. - #[ignore_heap_size] // We exclude `text_run` because it is non-owning. + #[ignore_heap_size_of = "Because it is non-owning"] pub text_run: Arc>, /// The range of text within the text run. @@ -838,7 +834,7 @@ pub enum TextOrientation { #[derive(Clone, HeapSizeOf)] pub struct ImageDisplayItem { pub base: BaseDisplayItem, - #[ignore_heap_size] // We exclude `image` here because it is non-owning. + #[ignore_heap_size_of = "Because it is non-owning"] pub image: Arc, /// The dimensions to which the image display item should be stretched. If this is smaller than @@ -848,7 +844,6 @@ pub struct ImageDisplayItem { /// The algorithm we should use to stretch the image. See `image_rendering` in CSS-IMAGES-3 § /// 5.3. - #[ignore_heap_size] pub image_rendering: image_rendering::T, } diff --git a/components/plugins/heap_size.rs b/components/plugins/heap_size.rs new file mode 100644 index 00000000000..c59a89b8904 --- /dev/null +++ b/components/plugins/heap_size.rs @@ -0,0 +1,81 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +//! Handles the auto-deriving for `#[derive(HeapSizeOf)]` +//! +//! This provides the `#[derive(HeapSizeOf)]` decorator, which +//! generates a `HeapSizeOf` implementation that adds up +//! calls to heap_size_of_children() for all the fields +//! of a struct or enum variant. +//! +//! Fields marked `#[ignore_heap_size_of = "reason"]` will +//! be ignored in this calculation. Providing a reason is compulsory. + + +use syntax::ext::base::{Annotatable, ExtCtxt}; +use syntax::codemap::Span; +use syntax::ptr::P; +use syntax::ast::*; +use syntax::attr::AttrMetaMethods; +use syntax::ext::build::AstBuilder; +use syntax::ext::deriving::generic::*; + +pub fn expand_heap_size(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, + item: Annotatable, push: &mut FnMut(Annotatable)) { + let trait_def = TraitDef { + span: span, + attributes: Vec::new(), + path: ty::Path::new(vec!("util", "mem", "HeapSizeOf")), + additional_bounds: Vec::new(), + generics: ty::LifetimeBounds::empty(), + methods: vec![ + MethodDef { + name: "heap_size_of_children", + generics: ty::LifetimeBounds::empty(), + explicit_self: ty::borrowed_explicit_self(), + args: vec!(), + ret_ty: ty::Literal(ty::Path::new_local("usize")), + attributes: vec!(), + is_unsafe: false, + combine_substructure: combine_substructure(Box::new(heap_size_substructure)) + } + ], + associated_types: vec![], + }; + trait_def.expand(cx, mitem, &item, push) +} + +/// Defines how the implementation for `heap_size_of_children()` is to be generated. +fn heap_size_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P { + let fields = match *substr.fields { + Struct(ref fs) | EnumMatching(_, _, ref fs) => fs, + _ => cx.span_bug(trait_span, "impossible substructure in `#[derive(HeapSizeOf)]`") + }; + + fields.iter().fold(cx.expr_usize(trait_span, 0), |acc, ref item| { + if item.attrs.iter() + .find(|ref a| { + if a.check_name("ignore_heap_size_of") { + match a.node.value.node { + MetaNameValue(..) => (), + _ => cx.span_err(a.span, "#[ignore_heap_size_of] \ + should have an explanation, \ + e.g. #[ignore_heap_size_of = \"foo\"]") + } + true + } else { + false + } + }) + .is_some() { + acc + } else { + cx.expr_binary(item.span, BiAdd, acc, + cx.expr_method_call(item.span, + item.self_.clone(), + substr.method_ident, + Vec::new())) + } + }) +} diff --git a/components/plugins/heapsize.rs b/components/plugins/heapsize.rs deleted file mode 100644 index 1a6d27fea22..00000000000 --- a/components/plugins/heapsize.rs +++ /dev/null @@ -1,58 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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}; -use syntax::codemap::Span; -use syntax::ptr::P; -use syntax::ast::*; -use syntax::attr::AttrMetaMethods; -use syntax::ext::build::AstBuilder; -use syntax::ext::deriving::generic::*; - -pub fn expand_heapsize(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, - item: Annotatable, push: &mut FnMut(Annotatable)) { - let trait_def = TraitDef { - span: span, - attributes: Vec::new(), - path: ty::Path::new(vec!("util", "mem", "HeapSizeOf")), - additional_bounds: Vec::new(), - generics: ty::LifetimeBounds::empty(), - methods: vec![ - MethodDef { - name: "heap_size_of_children", - generics: ty::LifetimeBounds::empty(), - explicit_self: ty::borrowed_explicit_self(), - args: vec!(), - ret_ty: ty::Literal(ty::Path::new_local("usize")), - attributes: vec!(), - is_unsafe: false, - combine_substructure: combine_substructure(Box::new(heapsize_substructure)) - } - ], - associated_types: vec![], - }; - trait_def.expand(cx, mitem, &item, push) -} - -fn heapsize_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P { - let fields = match *substr.fields { - Struct(ref fs) | EnumMatching(_, _, ref fs) => fs, - _ => cx.span_bug(trait_span, "impossible substructure in `heapsize`") - }; - - fields.iter().fold(cx.expr_usize(trait_span, 0), - |acc, ref item| { - if item.attrs.iter() - .find(|ref a| a.check_name("ignore_heap_size")) - .is_some() { - acc - } else { - cx.expr_binary(item.span, BiAdd, acc, - cx.expr_method_call(item.span, - item.self_.clone(), - substr.method_ident, - Vec::new())) - } - }) -} diff --git a/components/plugins/lib.rs b/components/plugins/lib.rs index fd8fdd615b7..8f9f698f1d8 100644 --- a/components/plugins/lib.rs +++ b/components/plugins/lib.rs @@ -31,8 +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; +/// Handles the auto-deriving for `#[derive(HeapSizeOf)]` +pub mod heap_size; /// Autogenerates implementations of Reflectable on DOM structs pub mod reflector; pub mod lints; @@ -45,7 +45,7 @@ pub fn plugin_registrar(reg: &mut Registry) { reg.register_syntax_extension(intern("dom_struct"), MultiModifier(box jstraceable::expand_dom_struct)); reg.register_syntax_extension(intern("jstraceable"), MultiDecorator(box jstraceable::expand_jstraceable)); reg.register_syntax_extension(intern("_generate_reflector"), MultiDecorator(box reflector::expand_reflector)); - reg.register_syntax_extension(intern("derive_HeapSizeOf"), MultiDecorator(box heapsize::expand_heapsize)); + reg.register_syntax_extension(intern("derive_HeapSizeOf"), MultiDecorator(box heap_size::expand_heap_size)); reg.register_macro("to_lower", casing::expand_lower); reg.register_macro("to_upper", casing::expand_upper); reg.register_lint_pass(box lints::transmute_type::TransmutePass as LintPassObject); diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs index 0e630183801..fd2267a0a94 100644 --- a/components/style/properties.mako.rs +++ b/components/style/properties.mako.rs @@ -2935,7 +2935,7 @@ pub mod longhands { use values::CSSFloat; use values::specified::{Angle}; - #[derive(Clone, PartialEq, Debug)] + #[derive(Clone, PartialEq, Debug, HeapSizeOf)] pub enum Filter { Blur(Au), Brightness(CSSFloat), @@ -2948,7 +2948,7 @@ pub mod longhands { Sepia(CSSFloat), } - #[derive(Clone, PartialEq, Debug)] + #[derive(Clone, PartialEq, Debug, HeapSizeOf)] pub struct T { pub filters: Vec } impl T { @@ -3631,7 +3631,7 @@ pub mod longhands { use cssparser::ToCss; use std::fmt; - #[derive(Copy, Clone, Debug, PartialEq)] + #[derive(Copy, Clone, Debug, PartialEq, HeapSizeOf)] pub enum T { Auto, CrispEdges, diff --git a/components/style/values.rs b/components/style/values.rs index f1d9a9df9fa..9c74dc47fd4 100644 --- a/components/style/values.rs +++ b/components/style/values.rs @@ -12,7 +12,7 @@ macro_rules! define_css_keyword_enum { }; ($name: ident: $( $css: expr => $variant: ident ),+) => { #[allow(non_camel_case_types)] - #[derive(Clone, Eq, PartialEq, Copy, Hash, RustcEncodable, Debug)] + #[derive(Clone, Eq, PartialEq, Copy, Hash, RustcEncodable, Debug, HeapSizeOf)] pub enum $name { $( $variant ),+ } @@ -68,7 +68,6 @@ macro_rules! define_numbered_css_keyword_enum { } } - pub type CSSFloat = f32; @@ -607,7 +606,7 @@ pub mod specified { } } - #[derive(Clone, PartialEq, PartialOrd, Copy, Debug)] + #[derive(Clone, PartialEq, PartialOrd, Copy, Debug, HeapSizeOf)] pub struct Angle(pub CSSFloat); impl ToCss for Angle { diff --git a/components/util/mem.rs b/components/util/mem.rs index 3575627d46a..5043fea7d93 100644 --- a/components/util/mem.rs +++ b/components/util/mem.rs @@ -9,11 +9,12 @@ use std::collections::LinkedList; use std::mem::transmute; use std::sync::Arc; -use geom::{Point2D, Rect, SideOffsets2D, Size2D, Matrix2D}; +use azure::azure_hl::Color; +use cursor::Cursor; +use geom::{Point2D, Rect, SideOffsets2D, Size2D, Matrix2D}; use geometry::Au; use range::Range; -use azure::azure_hl::Color; extern { // Get the size of a heap block. @@ -41,9 +42,6 @@ pub fn heap_size_of(ptr: *const c_void) -> usize { // return multiple measurements -- e.g. measure text separately from images -- are also possible, // and should be used when appropriate. // -// FIXME(njn): it would be nice to be able to derive this trait automatically, given that -// implementations are mostly repetitive and mechanical. -// pub trait HeapSizeOf { /// Measure the size of any heap-allocated structures that hang off this value, but not the /// space taken up by the value itself (i.e. what size_of:: measures, more or less); that @@ -165,7 +163,7 @@ impl Drop for LinkedList2 { } /// For use on types defined in external crates -/// with known heap sizes +/// with known heap sizes. #[macro_export] macro_rules! known_heap_size( ($size:expr, $($ty:ident),+) => ( @@ -197,5 +195,5 @@ known_heap_size!(0, bool, f32, f64); known_heap_size!(0, Rect, Point2D, Size2D, Matrix2D, SideOffsets2D); -known_heap_size!(0, Au, Color); +known_heap_size!(0, Au, Color, Cursor); known_heap_size!(0, Range); From 2551cce51e157f74a6ea247616f8e8d8596a5473 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 2 Jun 2015 07:30:37 +0530 Subject: [PATCH 6/9] address review comments --- components/plugins/heap_size.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/plugins/heap_size.rs b/components/plugins/heap_size.rs index c59a89b8904..956888fc712 100644 --- a/components/plugins/heap_size.rs +++ b/components/plugins/heap_size.rs @@ -22,7 +22,7 @@ use syntax::ext::build::AstBuilder; use syntax::ext::deriving::generic::*; pub fn expand_heap_size(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, - item: Annotatable, push: &mut FnMut(Annotatable)) { + item: Annotatable, push: &mut FnMut(Annotatable)) { let trait_def = TraitDef { span: span, attributes: Vec::new(), @@ -61,7 +61,7 @@ fn heap_size_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substruct MetaNameValue(..) => (), _ => cx.span_err(a.span, "#[ignore_heap_size_of] \ should have an explanation, \ - e.g. #[ignore_heap_size_of = \"foo\"]") + e.g. #[ignore_heap_size_of = \"\"]") } true } else { From 7bc88d541fa840cfde588309f101d3e61a0f7756 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 2 Jun 2015 16:38:46 +0530 Subject: [PATCH 7/9] Add unit test for plugin --- components/servo/Cargo.lock | 1 + tests/unit/util/Cargo.toml | 4 ++++ tests/unit/util/lib.rs | 3 +++ tests/unit/util/mem.rs | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 tests/unit/util/mem.rs diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index e698c8811a7..439a17d6ecc 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -1280,6 +1280,7 @@ name = "util_tests" version = "0.0.1" dependencies = [ "geom 0.1.0 (git+https://github.com/servo/rust-geom)", + "plugins 0.0.1", "util 0.0.1", ] diff --git a/tests/unit/util/Cargo.toml b/tests/unit/util/Cargo.toml index 48df1b5aedb..f6adbaca25d 100644 --- a/tests/unit/util/Cargo.toml +++ b/tests/unit/util/Cargo.toml @@ -11,5 +11,9 @@ doctest = false [dependencies.util] path = "../../../components/util" + +[dependencies.plugins] +path = "../../../components/plugins" + [dependencies.geom] git = "https://github.com/servo/rust-geom" diff --git a/tests/unit/util/lib.rs b/tests/unit/util/lib.rs index 07ce741d972..2048c2a0b57 100644 --- a/tests/unit/util/lib.rs +++ b/tests/unit/util/lib.rs @@ -2,6 +2,8 @@ * 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/. */ +#![feature(plugin, custom_derive, custom_attributes)] +#![plugin(plugins)] extern crate util; extern crate geom; @@ -9,3 +11,4 @@ extern crate geom; #[cfg(test)] mod logical_geometry; #[cfg(test)] mod task; #[cfg(test)] mod vec; +#[cfg(test)] mod mem; diff --git a/tests/unit/util/mem.rs b/tests/unit/util/mem.rs new file mode 100644 index 00000000000..8ad01063809 --- /dev/null +++ b/tests/unit/util/mem.rs @@ -0,0 +1,33 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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 util::mem::HeapSizeOf; + + +struct Four; +impl HeapSizeOf for Four { + fn heap_size_of_children(&self) -> usize { + 4 + } +} + +#[derive(HeapSizeOf)] +struct Eight(Four, Four, bool, bool, bool); + +#[derive(HeapSizeOf)] +enum EightOrFour { + Eight(Eight), + Four(Four), + Zero(u8) +} + +#[test] +fn test_heap_size() { + assert_eq!(Four.heap_size_of_children(), 4); + let eight = Eight(Four, Four, true, true, true); + assert_eq!(eight.heap_size_of_children(), 8); + assert_eq!(EightOrFour::Eight(eight).heap_size_of_children(), 8); + assert_eq!(EightOrFour::Four(Four).heap_size_of_children(), 4); + assert_eq!(EightOrFour::Zero(1).heap_size_of_children(), 0); +} From d2496a45c3151a789fea6f46a6dcd3b9f58d382e Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 3 Jun 2015 07:14:53 +0530 Subject: [PATCH 8/9] fix rebase issues --- components/plugins/heap_size.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/plugins/heap_size.rs b/components/plugins/heap_size.rs index 956888fc712..7e4c508a8aa 100644 --- a/components/plugins/heap_size.rs +++ b/components/plugins/heap_size.rs @@ -22,7 +22,7 @@ use syntax::ext::build::AstBuilder; use syntax::ext::deriving::generic::*; pub fn expand_heap_size(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, - item: Annotatable, push: &mut FnMut(Annotatable)) { + item: &Annotatable, push: &mut FnMut(Annotatable)) { let trait_def = TraitDef { span: span, attributes: Vec::new(), @@ -43,7 +43,7 @@ pub fn expand_heap_size(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, ], associated_types: vec![], }; - trait_def.expand(cx, mitem, &item, push) + trait_def.expand(cx, mitem, item, push) } /// Defines how the implementation for `heap_size_of_children()` is to be generated. From d347aeda3800e5e17b0e5553ac4689cca99ee2bb Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 3 Jun 2015 09:56:07 +0530 Subject: [PATCH 9/9] fix rebase conflicts --- components/gfx/display_list/mod.rs | 21 +++++++++++++-------- components/util/mem.rs | 4 ++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/components/gfx/display_list/mod.rs b/components/gfx/display_list/mod.rs index 45f74b3185b..a259b4f4ff7 100644 --- a/components/gfx/display_list/mod.rs +++ b/components/gfx/display_list/mod.rs @@ -27,7 +27,7 @@ use azure::azure::AzFloat; use azure::azure_hl::Color; use collections::linked_list::{self, LinkedList}; -use geom::{Point2D, Rect, SideOffsets2D, Size2D, Matrix2D}; +use geom::{Point2D, Rect, SideOffsets2D, Size2D, Matrix2D, Matrix4}; use geom::approxeq::ApproxEq; use geom::num::Zero; use libc::uintptr_t; @@ -245,7 +245,7 @@ pub struct StackingContext { pub blend_mode: mix_blend_mode::T, /// A transform to be applied to this stacking context. - pub transform: Matrix2D, + pub transform: Matrix4, } impl StackingContext { @@ -255,7 +255,7 @@ impl StackingContext { bounds: &Rect, overflow: &Rect, z_index: i32, - transform: &Matrix2D, + transform: &Matrix4, filters: filter::T, blend_mode: mix_blend_mode::T, layer: Option>) @@ -276,7 +276,7 @@ impl StackingContext { pub fn optimize_and_draw_into_context(&self, paint_context: &mut PaintContext, tile_bounds: &Rect, - transform: &Matrix2D, + transform: &Matrix4, clip_rect: Option<&Rect>) { let transform = transform.mul(&self.transform); let temporary_draw_target = @@ -309,7 +309,10 @@ impl StackingContext { // Set up our clip rect and transform. let old_transform = paint_subcontext.draw_target.get_transform(); - paint_subcontext.draw_target.set_transform(&transform); + let xform_2d = Matrix2D::new(transform.m11, transform.m12, + transform.m21, transform.m22, + transform.m41, transform.m42); + paint_subcontext.draw_target.set_transform(&xform_2d); paint_subcontext.push_clip_if_applicable(); // Steps 1 and 2: Borders and background for the root. @@ -331,7 +334,8 @@ impl StackingContext { positioned_kid.bounds .origin .y - .to_nearest_px() as AzFloat); + .to_nearest_px() as AzFloat, + 0.0); let new_tile_rect = self.compute_tile_rect_for_child_stacking_context(tile_bounds, &**positioned_kid); @@ -379,7 +383,8 @@ impl StackingContext { positioned_kid.bounds .origin .y - .to_nearest_px() as AzFloat); + .to_nearest_px() as AzFloat, + 0.0); let new_tile_rect = self.compute_tile_rect_for_child_stacking_context(tile_bounds, &**positioned_kid); @@ -903,7 +908,7 @@ pub struct BorderDisplayItem { /// Information about the border radii. /// /// TODO(pcwalton): Elliptical radii. -#[derive(Clone, Default, PartialEq, Debug, Copy)] +#[derive(Clone, Default, PartialEq, Debug, Copy, HeapSizeOf)] pub struct BorderRadii { pub top_left: T, pub top_right: T, diff --git a/components/util/mem.rs b/components/util/mem.rs index 5043fea7d93..0ca80b51563 100644 --- a/components/util/mem.rs +++ b/components/util/mem.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use azure::azure_hl::Color; use cursor::Cursor; -use geom::{Point2D, Rect, SideOffsets2D, Size2D, Matrix2D}; +use geom::{Point2D, Rect, SideOffsets2D, Size2D, Matrix2D, Matrix4}; use geometry::Au; use range::Range; @@ -193,7 +193,7 @@ known_heap_size!(0, u8, u16, u32, u64, usize); known_heap_size!(0, i8, i16, i32, i64, isize); known_heap_size!(0, bool, f32, f64); -known_heap_size!(0, Rect, Point2D, Size2D, Matrix2D, SideOffsets2D); +known_heap_size!(0, Rect, Point2D, Size2D, Matrix2D, SideOffsets2D, Matrix4); known_heap_size!(0, Au, Color, Cursor); known_heap_size!(0, Range);