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

Implement GridTemplateAreas with reference counting #19465

Merged
merged 1 commit into from Jan 31, 2018

Conversation

@CYBAI
Copy link
Collaborator

CYBAI commented Dec 2, 2017

Use Arc to implement refcounting for GridTemplateAreas
r? emilio


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #19428
  • These changes do not require tests

This change is Reviewable

@highfive
Copy link

highfive commented Dec 2, 2017

Heads up! This PR modifies the following files:

  • @bholley: components/style/properties/gecko.mako.rs, components/style/values/specified/position.rs, components/style/properties/shorthand/position.mako.rs
  • @canaltinova: components/style/properties/gecko.mako.rs, components/style/values/specified/position.rs, components/style/properties/shorthand/position.mako.rs
  • @emilio: components/style/properties/gecko.mako.rs, components/style/values/specified/position.rs, components/style/properties/shorthand/position.mako.rs
@highfive
Copy link

highfive commented Dec 2, 2017

warning Warning warning

  • These commits modify style code, but no tests are modified. Please consider adding a test!
}

impl MallocSizeOf for TemplateAreasArc {
/// FIXIME: (cybai) NEED TO FIGURE OUT HOW TO IMPLEMENT

This comment has been minimized.

@tigercosmos

tigercosmos Dec 2, 2017

Collaborator

FIXIME -> FIXME

This comment has been minimized.

@CYBAI

CYBAI Dec 2, 2017

Author Collaborator

Oh, thanks :P

@CYBAI CYBAI force-pushed the CYBAI:refcount-template-area branch from 507e5f4 to 4c8778f Dec 2, 2017
@tigercosmos
Copy link
Collaborator

tigercosmos commented Dec 3, 2017

@CYBAI

test specified_values::size_of_specified_values ... FAILED

failures:

---- specified_values::size_of_specified_values stdout ----

	thread 'specified_values::size_of_specified_values' panicked at 'Your changes have decreased the size of grid_template_areas SpecifiedValue to 8. Good work! The threshold is currently 24. Please consider removing `boxed="True"` from this longhand.', /home/travis/build/servo/servo/tests/unit/stylo/specified_values.rs:48:8

note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

stack backtrace:

   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace

             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49

   1: std::sys_common::backtrace::_print

             at /checkout/src/libstd/sys_common/backtrace.rs:71

   2: std::panicking::default_hook::{{closure}}

             at /checkout/src/libstd/sys_common/backtrace.rs:60

             at /checkout/src/libstd/panicking.rs:381

   3: std::panicking::default_hook

             at /checkout/src/libstd/panicking.rs:391

   4: std::panicking::rust_panic_with_hook

             at /checkout/src/libstd/panicking.rs:611

   5: std::panicking::begin_panic

             at /checkout/src/libstd/panicking.rs:572

   6: std::panicking::begin_panic_fmt

             at /checkout/src/libstd/panicking.rs:522

   7: stylo_tests::specified_values::size_of_specified_values

             at ./specified_values.rs:48

   8: <F as test::FnBox<T>>::call_box

             at /checkout/src/libtest/lib.rs:1480

             at /checkout/src/libcore/ops/function.rs:223

             at /checkout/src/libtest/lib.rs:141

   9: __rust_maybe_catch_panic

             at /checkout/src/libpanic_unwind/lib.rs:99

failures:

    specified_values::size_of_specified_values

test result: FAILED. 767 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '--lib'

The command "./mach test-stylo" exited with 101.
@CYBAI
Copy link
Collaborator Author

CYBAI commented Dec 3, 2017

@tigercosmos
Yes, I know the failure.
I'll check it later but I guess it's related to MallocSizeOf trait which I implemented it with zero.
Thanks.

Copy link
Member

emilio left a comment

The test-failure is legit and means that with your changes TemplateAreas is no longer big (it's just a pointer now), so you should be able to just remove boxed=True from it.

/// Arc type for `Arc<TemplateAreas>`
pub struct TemplateAreasArc(pub Arc<TemplateAreas>);

impl Parse for TemplateAreasArc {

This comment has been minimized.

@emilio

emilio Dec 3, 2017

Member

We should be able to remove Parse for TemplateAreas now, right? Alternatively this method could be:

TemplateAreasArc(Arc::new(TemplateAreas::parse(context, input)?))

This comment has been minimized.

@CYBAI

CYBAI Dec 3, 2017

Author Collaborator

I remember I impl this trait due to getting errors about lack of this trait.
I'll try to remove it to see if it's necessary.
Or, I'll try to update the method as returning a TemplateAreasArc.
Thanks.

This comment has been minimized.

@CYBAI

CYBAI Dec 3, 2017

Author Collaborator

Hmm... yeah, I'll get error messages like following

error[E0599]: no function or associated item named `parse` found for type `values::Either<values::specified::position::TemplateAreasArc, values::None_>` in the current scope
     --> /servo/target/geckolib/debug/build/style-abfaa561961fdc53/out/properties.rs:40333:13
      |
40333 |             specified::GridTemplateAreas::parse(context, input)
      |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
      = note: the method `parse` exists but the following trait bounds were not satisfied:
              `values::specified::position::TemplateAreasArc : parser::Parse`
      = help: items from traits can only be used if the trait is implemented and in scope
      = note: the following traits define an item `parse`, perhaps you need to implement one of them:
              candidate #1: `parser::Parse`
              candidate #2: `bitflags::<unnamed>::str::StrExt`
              candidate #3: `style_traits::Separator`

error: aborting due to previous error

Let me try to update the method body like what you wrote.

}

impl MallocSizeOf for TemplateAreasArc {
/// FIXME: (cybai) NEED TO FIGURE OUT HOW TO IMPLEMENT

This comment has been minimized.

@emilio

emilio Dec 3, 2017

Member

nit: The comment doesn't really need to be uppercase :)

This comment has been minimized.

@CYBAI

CYBAI Dec 3, 2017

Author Collaborator

Haha, Let me updated this into normal cases :P

/// FIXME: (cybai) NEED TO FIGURE OUT HOW TO IMPLEMENT
/// MallocConditionalSizeOf for this Arc
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
0

This comment has been minimized.

@emilio

emilio Dec 3, 2017

Member

@nnethercote, what's the best way to measure this? For now measuring as 0 may be fine, since this is pretty rare, but in case it comes up again...

@CYBAI
Copy link
Collaborator Author

CYBAI commented Dec 3, 2017

@emilio Yeah, I just tried to remove the boxed=True and the test passed locally!
Thanks a lot and I know why we need boxed now!

@CYBAI CYBAI force-pushed the CYBAI:refcount-template-area branch 3 times, most recently from 0032052 to 027f37e Dec 3, 2017
@nnethercote
Copy link
Contributor

nnethercote commented Dec 3, 2017

About measuring TemplateAreasArc -- can't you just defer to the implementation of MallocConditionalSizeOf for the inner Arc<>?

@CYBAI CYBAI force-pushed the CYBAI:refcount-template-area branch from 027f37e to e76d8bd Dec 4, 2017
@CYBAI
Copy link
Collaborator Author

CYBAI commented Dec 4, 2017

@nnethercote I just tried to use conditional_size_of as the method body of impl MallocSizeOf for TemplateAreasArc and I just updated it in this PR. Please help me review it again. Thanks!

cc @emilio

#[cfg(feature = "gecko")]
impl MallocSizeOf for TemplateAreasArc {
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
self.0.conditional_size_of(ops)

This comment has been minimized.

@nnethercote

nnethercote Dec 5, 2017

Contributor

This isn't quite right. TemplateAreasArc is basically the same as Arc, so it should implement the same traits: one or more of MallocUnconditionalShallowSizeOf, MallocUnconditionalSizeOf, MallocConditionalShallowSizeOf, MallocConditionalSizeOf. It should not implement MallocSizeOf or MallocShallowSizeOf. See components/malloc_size_of/lib.rs for more details.

Having said that: does TemplateAreasArc need to be a newtype? Could it just be a typedef for Arc<TemplateAreas>? Maybe you need a newtype so you can define additional methods?

TemplateAreasArc

This comment has been minimized.

@emilio

emilio Dec 5, 2017

Member

Right, it needs to be a newtype so it can implement ToCss and such.

This comment has been minimized.

@emilio

emilio Dec 5, 2017

Member

Though arguably that should be generically implemented... ToComputedValue is trickier though.

This comment has been minimized.

@CYBAI

CYBAI Dec 9, 2017

Author Collaborator

@nnethercote Due to enum PropertyDeclaration, we must impl MallocSizeOf for TemplateAreasArc so I cannot only impl MallocConditionalSizeOf for it.
How do you think about it?

cc @emilio

This comment has been minimized.

@nnethercote

nnethercote Dec 10, 2017

Contributor

Is #[derive(MallocSizeOf)] involved? It works well for tree-like structures, but less well for graph-like structures. One possibility is to change the relevant MallocSizeOf impl from a derived one to a manually written one that does something appropriate (and different) for the Arc. Another possibility is to keep the derive impl and use the ignore_malloc_size_of attribute on the relevant Arc field.

This comment has been minimized.

@CYBAI

CYBAI Dec 11, 2017

Author Collaborator

Yes, this code block is involved #[derive(MallocSizeOf)].

/// Servo's representation for a property declaration.
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(Clone, PartialEq)]
pub enum PropertyDeclaration {
% for property in data.longhands:

I think adding another checking into mako for only this case might not be good.
I'll try to use ignore_malloc_size_of attribute for it, thanks.

@bors-servo
Copy link
Contributor

bors-servo commented Dec 16, 2017

The latest upstream changes (presumably #19584) made this pull request unmergeable. Please resolve the merge conflicts.

@CYBAI CYBAI force-pushed the CYBAI:refcount-template-area branch 2 times, most recently from c013964 to b361e79 Dec 17, 2017
@jdm jdm removed the S-needs-rebase label Dec 18, 2017
@CYBAI CYBAI force-pushed the CYBAI:refcount-template-area branch 2 times, most recently from c6dac38 to bb7237e Dec 24, 2017
@CYBAI
Copy link
Collaborator Author

CYBAI commented Dec 24, 2017

@nnethercote @emilio I just updated the PR with keeping the impl of MallocSizeOf and use ignore_malloc_size_of attribute!
Please help me to review it again, thanks! 😁

@CYBAI
Copy link
Collaborator Author

CYBAI commented Dec 24, 2017

Travis build failed with #19634

@CYBAI CYBAI force-pushed the CYBAI:refcount-template-area branch from bb7237e to 6a23362 Dec 25, 2017
@CYBAI
Copy link
Collaborator Author

CYBAI commented Dec 25, 2017

Rebased and fixed the build error.

@CYBAI
Copy link
Collaborator Author

CYBAI commented Jan 4, 2018

r? @nnethercote and @emilio
Ping for review, thanks!

@jdm jdm assigned emilio and unassigned nnethercote Jan 4, 2018
@bors-servo
Copy link
Contributor

bors-servo commented Jan 23, 2018

The latest upstream changes (presumably #19838) made this pull request unmergeable. Please resolve the merge conflicts.

@CYBAI CYBAI force-pushed the CYBAI:refcount-template-area branch 2 times, most recently from 0c79fd8 to 6c48285 Jan 24, 2018
@CYBAI
Copy link
Collaborator Author

CYBAI commented Jan 29, 2018

Ping for review from @nnethercote and @emilio
Also, the S-needs-rebase label is outdated.

@@ -624,6 +625,23 @@ impl Parse for TemplateAreas {

trivial_to_computed_value!(TemplateAreas);

#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
/// Arc type for `Arc<TemplateAreas>`

This comment has been minimized.

@nnethercote

nnethercote Jan 31, 2018

Contributor

I'd put the comment above the derive line.

Copy link
Contributor

nnethercote left a comment

Apologies for the long delay, I was on PTO.

The memory measurements parts of this patch look fine to me. Emilio will need to approve the rest of it, though.

@nnethercote
Copy link
Contributor

nnethercote commented Jan 31, 2018

r? @emilio

@CYBAI CYBAI force-pushed the CYBAI:refcount-template-area branch from 6c48285 to 9004fff Jan 31, 2018
@emilio
Copy link
Member

emilio commented Jan 31, 2018

Looks good, thanks!

@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented Jan 31, 2018

📌 Commit 9004fff has been approved by emilio

bors-servo added a commit that referenced this pull request Jan 31, 2018
Implement GridTemplateAreas with reference counting

Use `Arc` to implement refcounting for `GridTemplateAreas`
r? emilio

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #19428
- [x] These changes do not require tests

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19465)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jan 31, 2018

Testing commit 9004fff with merge 12a5966...

@bors-servo
Copy link
Contributor

bors-servo commented Jan 31, 2018

@bors-servo bors-servo merged commit 9004fff into servo:master Jan 31, 2018
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@CYBAI CYBAI deleted the CYBAI:refcount-template-area branch Jan 31, 2018
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.

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