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

stylo: Use atoms as the pseudo-element back-end. #12815

Merged
merged 12 commits into from Aug 16, 2016
Merged

Conversation

@emilio
Copy link
Member

emilio commented Aug 11, 2016

A bit of work left, and we can uber-optimize this (left comments, will fill follow-ups), but this is a decent refactor so I thought I'd rather get some feedback on it.

r? @bholley (not formally yet, maybe, but some feedback is appreciated).


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes do not require tests because geckolib only...

This change is Reviewable

@highfive
Copy link

highfive commented Aug 11, 2016

Heads up! This PR modifies the following files:

  • @bholley: components/style/gecko_selector_impl.rs, components/style/generated/gecko_pseudo_element_helper.rs
@highfive
Copy link

highfive commented Aug 11, 2016

warning Warning warning

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

#[inline]
pub unsafe fn from_static(ptr: *mut nsIAtom) -> Self {

This comment has been minimized.

@bholley

bholley Aug 12, 2016

Contributor

Please document this.

else:
print("OK")

return 0

This comment has been minimized.

@emilio

emilio Aug 12, 2016

Author Member

whoops, return ret.

CLASS = "nsGKAtoms"
TYPE = "nsICSSAnonBoxPseudo"

@staticmethod

This comment has been minimized.

@emilio

emilio Aug 12, 2016

Author Member

This is not needed anymore.

@@ -214,7 +223,7 @@ impl fmt::Debug for Atom {

impl fmt::Display for Atom {
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
for c in char::decode_utf16(self.as_slice().iter().cloned()) {
for c in self.chars() {

This comment has been minimized.

@bholley

bholley Aug 12, 2016

Contributor

I actually wanted @SimonSapin to remove this in #12571, because it makes it too easy to accidentally trigger a slow stringification. Can you revert this line and remove |pub fn chars|? I'd also be ok with chars() being non-public with a comment indicating that it's slow and shouldn't be exposed.

This comment has been minimized.

@SimonSapin

SimonSapin Aug 13, 2016

Member

I’ve removed PartialEq<str> for Atom because, I agree, it’s easy to accidentally use it instead of fast atom comparison.

But consuming Atom::chars is O(n) like str::chars, and calling it has to be explicit, so I don’t see what the problem is. When possible, it’s better than using with_str which allocates.

MozSVGForeignContent,
MozSVGText,
// TODO: automatize this list from
// http://searchfox.org/mozilla-central/source/layout/style/nsCSSPseudoElements.h and

This comment has been minimized.

@bholley

bholley Aug 12, 2016

Contributor

This gets fixed up in future patches, right?

match Self::from_atom(&*atom, true) {
Some(pseudo) => {
assert_eq!(pseudo.is_anon_box(), is_anon_box);
return pseudo;

This comment has been minimized.

@bholley

bholley Aug 12, 2016

Contributor

Why do we need this return?

#[derive(Clone)]
struct Utf16toASCIIIter<'a>(Iter<'a, u16>);

impl<'a> Iterator for Utf16toASCIIIter<'a> {

This comment has been minimized.

@bholley

bholley Aug 13, 2016

Contributor

I don't understand why we need to do all this junk, though it looks like it goes away in subsequent patches? In the mean time, wouldn't we get the same effect by just comparing against atom!(":before") like from_bytes_iter does? Seems preferable to all that nasty unicode munging (which I didn't really look at because it goes away).

This comment has been minimized.

@bholley

bholley Aug 13, 2016

Contributor

(Would still prefer to not introduce the nasty stuff at all though, even for a temporary patch)

}

parse!("before", atom!(":before"));
parse!("after", atom!(":after"));

This comment has been minimized.

@bholley

bholley Aug 13, 2016

Contributor

Do I understand correctly that this temporarily regresses our support for anon boxes during this patch? I don't see us passing |true| to parse! anywhere. I guess I'm ok with that, though generally would prefer to review less intermediate code...

in_ua_stylesheet: bool,
byte_len: usize) -> Option<Self> {
use std::ascii::AsciiExt;
macro_rules! parse {

This comment has been minimized.

@bholley

bholley Aug 13, 2016

Contributor

Per IRC discussion this macro should go away.

@emilio emilio force-pushed the emilio:stylo-atoms branch 2 times, most recently from 8dd76af to 01f981a Aug 13, 2016
self.value = value
self.cpp_class = source.CLASS
# FIXME(emilio): This is crap, and we really could/should just store a
# reference to the source, but...

This comment has been minimized.

@bholley

bholley Aug 13, 2016

Contributor

Why not do that? :-)

* Expected usage is as follows:
*
* Also, it guarantees the property that normal pseudo-elements are processed
* before anonymous boxes.

This comment has been minimized.

@bholley

bholley Aug 13, 2016

Contributor

Nit: put this above the 'expected usage' part.

return ptr::null_mut();
}
};
let atom = unsafe { Atom::from_static(pseudo_tag) };

This comment has been minimized.

@bholley

bholley Aug 13, 2016

Contributor

This is a nice optimization, but a bit scary, since it would lead to an unpaired Release() if we ever got it wrong (this only works because ReleaseAtom() is a no-op for static atoms).

Can we make the gecko Atom struct carry an extra bit that indicates whether the atom was created with from_static, and skip the ReleaseAtom() call in that case? That would reduce the risk here, and also save an FFI call.

This comment has been minimized.

@emilio

emilio Aug 13, 2016

Author Member

It's probably better if we generate accessors for the atom bitfield, with the extra benefit that gives us the length (which means in some cases we don't need to make an ffi call to make some comparisons).

This comment has been minimized.

@emilio

emilio Aug 13, 2016

Author Member

Oh, also, note that from_atom_unchecked still checks the atom in debug builds.

Gecko_AtomEqualsUTF8IgnoreCase(self.as_ptr(), s.as_ptr() as *const _, s.len() as u32)
Gecko_AtomEqualsUTF8IgnoreCase(self.as_ptr(),
bytes.as_ptr() as *const _,
bytes.len() as u32)

This comment has been minimized.

@bholley

bholley Aug 13, 2016

Contributor

yikes. @Manishearth, any ideas on tooling to prevent us from making errors like this in the future?

This comment has been minimized.

@SimonSapin

SimonSapin Aug 13, 2016

Member

I think this change is a no-op: str::len returns a number of UTF-8 bytes, not of code points.

This comment has been minimized.

@emilio

emilio Aug 13, 2016

Author Member

That's true, I removed it. I'll also fill follow-ups to remove the FFI
functions for string comparison and a few other things.

On 08/13/2016 09:47 AM, Simon Sapin wrote:

In ports/geckolib/string_cache/lib.rs
#12815 (comment):

     unsafe {
  •        Gecko_AtomEqualsUTF8IgnoreCase(self.as_ptr(), s.as_ptr() as *const _, s.len() as u32)
    
  •        Gecko_AtomEqualsUTF8IgnoreCase(self.as_ptr(),
    
  •                                       bytes.as_ptr() as *const _,
    
  •                                       bytes.len() as u32)
    

I think this change is a no-op: |str::len| returns a number of UTF-8
bytes, not of code points.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/servo/servo/pull/12815/files/93e6fb1a6569a2b6934cb28c8d4889122d0b2897..22a7892934b829e32c75a8e408b5569535f13414#r74689195,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABQwurP0WCuwUHsCBBfOmvp2EkqOgZ76ks5qffUtgaJpZM4Jh0-a.

@@ -1339,6 +1339,80 @@ fn static_assert() {
${impl_coord_copy('column_width', 'mColumnWidth')}
</%self:impl_trait>

<%self:impl_trait style_struct_name="Counters"

This comment has been minimized.

@bholley

bholley Aug 13, 2016

Contributor

Nit: The comment message should say "the content property"

This comment has been minimized.

@bholley

bholley Aug 13, 2016

Contributor

Actually, could you split this commit out into a separate PR? I've got to run pretty soon and may not have time to review the whole thing, and it's pretty separate from the atom stuff (and also presumably needs some gecko-side changes).

@bholley
Copy link
Contributor

bholley commented Aug 13, 2016

r=me with comments addressed on everything but the |content| patch, which I'd like to see in a separate PR.

@bors-servo delegate+

@bors-servo
Copy link
Contributor

bors-servo commented Aug 13, 2016

✌️ @emilio can now approve this pull request

@emilio emilio force-pushed the emilio:stylo-atoms branch 2 times, most recently from dd159cc to 8a92235 Aug 13, 2016

AnonBox(AnonBoxPseudoElement),
}
pub struct PseudoElement(Atom, bool);

This comment has been minimized.

@SimonSapin

SimonSapin Aug 13, 2016

Member

Maybe use struct syntax with named fields? I particular to say what this bool is.

This comment has been minimized.

@emilio

emilio Aug 13, 2016

Author Member

It's documented above (though the diff makes it difficult to find), but
yeah, it's fair, I'll do it.

On 08/13/2016 08:04 AM, Simon Sapin wrote:

In components/style/gecko_selector_impl.rs
#12815 (comment):

  • MozNumberWrapper,
  • MozNumberText,
  • MozNumberSpinBox,
  • MozNumberSpinUp,
  • MozNumberSpinDown,
  • MozProgressBar,
  • MozRangeTrack,
  • MozRangeProgress,
  • MozRangeThumb,
  • MozMeterBar,
  • MozPlaceholder,

- MozColorSwatch,

  • AnonBox(AnonBoxPseudoElement),
    -}
    +pub struct PseudoElement(Atom, bool);

Maybe use struct syntax with named fields? I particular to say what this
|bool| is.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/servo/servo/pull/12815/files/8a92235c7c372b7d884a6928608a7477e2af7c70#r74687932,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABQwull1-KtkBA4749IbfIn2nU6g_1AUks5qfd0PgaJpZM4Jh0-a.

@emilio emilio force-pushed the emilio:stylo-atoms branch 3 times, most recently from 2a71630 to 15f8390 Aug 13, 2016
emilio added 2 commits Aug 10, 2016
@emilio emilio force-pushed the emilio:stylo-atoms branch from 4827a24 to f783caf Aug 16, 2016


def msvc32_symbolify(source, ident):
return "?" + ident + "@" + source.CLASS + "@@2PAV" + source.TYPE + "@@A"

This comment has been minimized.

@emilio

emilio Aug 16, 2016

Author Member

cc @upsuper, hopefully I got the msvc manglings fine.

This comment has been minimized.

@upsuper

upsuper Aug 17, 2016

Member

TBH, I have no idea about msvc manglings. Their mangling rule looks complicated, so I disassembled the object file and copied the pattern to here directly.

If the type is just pointers, I guess reusing this is probably fine, but I'm unconfident about that anyway.

@emilio emilio force-pushed the emilio:stylo-atoms branch from f783caf to 09cc240 Aug 16, 2016
@emilio
Copy link
Member Author

emilio commented Aug 16, 2016

Left just the atom patches, will submit the content patches after this lands.

@bors-servo: r=bholley

@bors-servo
Copy link
Contributor

bors-servo commented Aug 16, 2016

📌 Commit 09cc240 has been approved by bholley

@bors-servo
Copy link
Contributor

bors-servo commented Aug 16, 2016

Testing commit 09cc240 with merge d9adca6...

bors-servo added a commit that referenced this pull request Aug 16, 2016
stylo: Use atoms as the pseudo-element back-end.

<!-- Please describe your changes on the following line: -->

A bit of work left, and we can uber-optimize this (left comments, will fill follow-ups), but this is a decent refactor so I thought I'd rather get some feedback on it.

r? @bholley (not formally yet, maybe, but some feedback is appreciated).

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors

<!-- Either: -->
- [x] These changes do not require tests because geckolib only...

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- 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/12815)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Aug 16, 2016

💔 Test failed - linux-rel

@highfive
Copy link

highfive commented Aug 16, 2016

  ▶ FAIL [expected PASS] /css-transforms-1_dev/html/perspective-origin-006.htm
  └   → /css-transforms-1_dev/html/perspective-origin-006.htm d2f9f49eb190646b004d0ea13de938dfa265561d
/css-transforms-1_dev/html/reference/ref-filled-green-100px-square.htm d4aa213e3e31e41d0d8e84aec79e94f860f27178
Testing d2f9f49eb190646b004d0ea13de938dfa265561d == d4aa213e3e31e41d0d8e84aec79e94f860f27178
@emilio
Copy link
Member Author

emilio commented Aug 16, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Aug 16, 2016

Previous build results for arm32, arm64, linux-dev, mac-dev-unit, mac-rel-css, windows-dev are reusable. Rebuilding only linux-rel, mac-rel-wpt...

@bors-servo
Copy link
Contributor

bors-servo commented Aug 16, 2016

💔 Test failed - linux-rel

@highfive
Copy link

highfive commented Aug 16, 2016

  ▶ FAIL [expected PASS] /css-transforms-1_dev/html/perspective-origin-006.htm
  └   → /css-transforms-1_dev/html/perspective-origin-006.htm d2f9f49eb190646b004d0ea13de938dfa265561d
/css-transforms-1_dev/html/reference/ref-filled-green-100px-square.htm d4aa213e3e31e41d0d8e84aec79e94f860f27178
Testing d2f9f49eb190646b004d0ea13de938dfa265561d == d4aa213e3e31e41d0d8e84aec79e94f860f27178
@emilio
Copy link
Member Author

emilio commented Aug 16, 2016

@bors-servo: retry

@bors-servo
Copy link
Contributor

bors-servo commented Aug 16, 2016

Testing commit 09cc240 with merge c386a3c...

bors-servo added a commit that referenced this pull request Aug 16, 2016
stylo: Use atoms as the pseudo-element back-end.

<!-- Please describe your changes on the following line: -->

A bit of work left, and we can uber-optimize this (left comments, will fill follow-ups), but this is a decent refactor so I thought I'd rather get some feedback on it.

r? @bholley (not formally yet, maybe, but some feedback is appreciated).

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors

<!-- Either: -->
- [x] These changes do not require tests because geckolib only...

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- 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/12815)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Aug 16, 2016

@bors-servo bors-servo merged commit 09cc240 into servo:master Aug 16, 2016
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
@emilio emilio deleted the emilio:stylo-atoms branch Aug 16, 2016
@upsuper
Copy link
Member

upsuper commented Aug 19, 2016

Looks like it works fine with MSVC.

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.

None yet

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