Commit graph

105 commits

Author SHA1 Message Date
Emilio Cobos Álvarez
31e8e418ea Miscellaneous build / tidy fixes. 2021-02-26 17:53:55 +01:00
Emilio Cobos Álvarez
9f40b9ba38 style: Avoid some allocations in selector serialization.
The allocations in display_to_css_identifier show up in the profiles of
bug 1675628.

Differential Revision: https://phabricator.services.mozilla.com/D97856
2021-02-26 16:44:05 +01:00
Cameron McCormack
6bae0b99ca style: Gracefully handle errors creating shared memory UA style sheets.
We still panic in a debug build, so that developers can notice when they
need to add a new static atom after modifying UA sheets.

We also add telemetry to note when this happens, add an app note to a
crash report, in case any crash later on occurs, and re-up the existing,
expired shared memory sheet telemetry probes so we can look at them
again.

Differential Revision: https://phabricator.services.mozilla.com/D73188
2020-06-04 01:50:36 +02:00
Emilio Cobos Álvarez
f76acc84c6 style: Reformat recent changes. 2020-04-16 17:50:17 +02:00
Emilio Cobos Álvarez
7d438cd816 style: Ensure that derived types are right for optimized-away implementations.
We have this optimization where, for non-generic structs, we generate just a
clone / move as the ToComputedValue / ToResolvedValue implementation.

This moves the optimization a bit further down, and refines it so that we still
generate all the relevant where clauses that make it sound, that is, that all
the ToComputedValue implementations of the fields return the same type.

Otherwise this wouldn't be sound and the type would need to become generic.

We add an escape hatch (no_field_bound) for fields that need to be cloned but
which don't implement the trait. This is right now only for the RefPtr<> in the
shared font-family list, and a piece of code in PaintWorklet which looks kinda
fishy, and probably should be fixed (but we don't ship it in Firefox and there's
a pre-existing FIXME for servo, so I punted on it for now).

The other thing this patch does is adding a bunch of ToComputedValue /
ToResolvedValue implementations that are trivial and were missing.

Differential Revision: https://phabricator.services.mozilla.com/D67913
2020-04-16 16:35:07 +02:00
Emilio Cobos Álvarez
219c0f6328
style: Use cbindgen for content property.
This cleans up and also allows us to keep the distinction between content: none
and content: normal, which allows us to fix the computed style we return from
getComputedStyle().

Do this last bit from the resolved value instead of StyleAdjuster, because
otherwise we need to tweak every initial struct for ::before / ::after.

Differential Revision: https://phabricator.services.mozilla.com/D58276
2020-02-12 02:43:08 +01:00
Emilio Cobos Álvarez
006417e40a
style: Rustfmt recent changes. 2019-11-30 20:45:07 +01:00
Emilio Cobos Álvarez
31837a1efa
style: Make Rust static atoms able to be used in const contexts.
I see atom dropping code generated in release builds for stuff like dropping the
"class" atom here:

https://searchfox.org/mozilla-central/rev/4df8821c1b824db5f40f381f48432f219d99ae36/servo/components/style/gecko/wrapper.rs#592

That is silly, and I hope making Atom be able to be used in const context will
help the compiler see that yeah, we're not doing anything interesting and the
atom shouldn't get dropped.

It also allows us to get rid of a few lazy_static!s, so we should do it anyway.

In order to accomplish this, compute the offset into gGkAtoms manually instead
of going through the static_atoms() array and then back to the byte offset.

Differential Revision: https://phabricator.services.mozilla.com/D55039
2019-11-30 20:45:06 +01:00
Emilio Cobos Álvarez
e48c4b88f1
style: Make rust Atom use NonZeroUsize.
At first I thought this was going to enable simplifications in the selector
parser (to simplify the attribute selector setup), but I couldn't end up
shrinking the layout enough.

However this should help with bug 1559076, which returns Option<Atom>, and it
was easy to write.

Differential Revision: https://phabricator.services.mozilla.com/D53766
2019-11-30 20:45:02 +01:00
Simon Sapin
17ec774a49 Stylo: replace uses of mem::uninitialized with MaybeUninit
MozReview-Commit-ID: KGhYL6DJRaR
2019-07-16 08:03:54 +02:00
Emilio Cobos Álvarez
bbc77e3977 style: Share computed and specified value representation of -moz-context-properties.
Differential Revision: https://phabricator.services.mozilla.com/D30545
2019-05-29 16:14:10 +02:00
Emilio Cobos Álvarez
8c004c0858 style: Reformat recent changes. 2019-04-12 12:20:14 +02:00
Cameron McCormack
40248ae5fd style: Add derived ToShmem implementations.
Differential Revision: https://phabricator.services.mozilla.com/D17197
2019-04-12 12:19:52 +02:00
Cameron McCormack
8c007ad999 style: Add ToShmem impl for Atom.
Differential Revision: https://phabricator.services.mozilla.com/D17192
2019-04-12 12:19:48 +02:00
Emilio Cobos Álvarez
8101539c0a style: Document a few more macros. 2019-01-13 21:59:25 +01:00
Emilio Cobos Álvarez
119b316885 style: Rustfmt recent changes. 2019-01-11 00:57:26 +01:00
Cameron McCormack
03507801cf style: Make GkAtoms opaque to avoid lld-link.exe errors.
Differential Revision: https://phabricator.services.mozilla.com/D15800
2019-01-11 00:50:46 +01:00
Cameron McCormack
63fd707bd3 style: Use atom handles in favour of atom pointers in style system code.
Differential Revision: https://phabricator.services.mozilla.com/D15078
2019-01-11 00:50:26 +01:00
Jan Andre Ikenmeyer
1d6fe65401
Update MPL license to https (part 4) 2018-11-19 14:47:27 +01:00
Emilio Cobos Álvarez
f486ef7e47
style: Add an atom bit to know whether we're ascii lowercase.
And thus massively speed up ascii-case-insensitive atom comparisons when both
atoms are lowercase (which is the common case by far).

This removes almost all the slow selector-matching in this page, and it seems
an easier fix than storing the lowercased version of all class-names in quirks
mode in elements and selectors...

Differential Revision: https://phabricator.services.mozilla.com/D10945
2018-11-17 09:56:01 +01:00
Emilio Cobos Álvarez
d9453bc0ea
style: Remove dynamic HTML5 atoms.
Co-authored-by: Nicholas Nethercote <nnethercote@mozilla.com>

Differential Revision: https://phabricator.services.mozilla.com/D11035
2018-11-10 21:11:19 +01:00
Simon Sapin
b1822a39fa cargo fix --edition --features gecko 2018-11-10 17:47:28 +01:00
Pyfisch
9e92eb205a Reorder imports 2018-11-06 22:35:07 +01:00
Nicholas Nethercote
0d5d5a9c82
style: Make static atom pointers constexpr.
This saves one word per static atom, per process.

The `nsGkAtoms` change is only a small part of this commit.

In regen_atoms.py:

- There is now only one link name per platform: nsGkAtoms::sAtoms[].

- But there is a new constant per atom, giving the index into
  nsGkAtoms::sAtoms[].

- And the `atom!` macro for each atom indexes into nsGkAtoms::sAtoms[] using
  the index constant.

- A couple of `*mut` pointers are now `*const`.

Elsewhere, the `(nsStaticAtom*)` casts within the `AppendElement()` calls are
necessary to avoid link errors, presumably due to some template instantiation
wrinkle.

Bug: 1449787
Reviewed-by: froydnj,emilio
2018-10-09 19:45:10 +02:00
Emilio Cobos Álvarez
e9a99b2a7f
style: Manually inline class and ID getters.
Somewhat ugly but hopefully not too much. Somehow it ends up removing more lines
than adding.

Differential Revision: https://phabricator.services.mozilla.com/D3536
2018-08-18 17:54:54 +02:00
Cameron McCormack
e305b5a1f8
style: Remove unused BorrowedAtom.
Differential Revision: https://phabricator.services.mozilla.com/D3159
2018-08-18 17:48:12 +02:00
Nicholas Nethercote
46e572a497
Store nsDynamicAtom's chars after the end of the object.
This reduces memory usage because we only need one allocation instead of two
for the dynamic atom and its chars, and because we don't need to store a
refcount and a size. It precludes sharing of chars between dynamic atoms, but
we weren't benefiting much from that anyway.

This reduces per-process memory usage by up to several hundred KiB on my
Linux64 box.

One consequence of this change is that we need to allocate + copy in
DOMString::SetKnownLiveAtom(), which could make some things slower.

Bug: 1447951
Reviewed-by: froydnj
2018-06-23 20:36:41 +02:00
Xidorn Quan
7fe7b2ffb1
style: Add a ValueInfo trait for exposing types needed by devtools.
Most of types just derive it using proc_macro directly. Some of value
types need manual impl.

In my current plan, this new trait will be used in bug 1434130 to expose
values as well.

Bug: 1455576
Reviewed-by: emilio
MozReview-Commit-ID: LI7fy45VkRw
2018-04-29 03:28:34 +02:00
Bobby Holley
c99bcdd4b8 Run rustfmt on selectors, servo_arc, and style.
This was generated with:

./mach cargo fmt --package selectors &&
./mach cargo fmt --package servo_arc &&
./mach cargo fmt --package style

Using rustfmt 0.4.1-nightly (a4462d1 2018-03-26)
2018-04-10 17:35:15 -07:00
Nicholas Nethercote
77e3522507 Statically allocate static atoms. 2018-03-26 17:05:05 +11:00
Emilio Cobos Álvarez
55e2cd5dc3
style: Remove unsound Atom From implementations.
Fixes #20158
2018-03-19 11:06:53 +01:00
Emilio Cobos Álvarez
39a3d93b4f
style: remove unused AsciiExt imports.
eq_ignore_ascii_case is not in AsciiExt since rustc 1.23.
2018-03-04 15:31:06 +01:00
Emilio Cobos Álvarez
f4c9c598a3
style: Optimize serialization of identifiers of length <= 16 🐉🐲
Much like we optimize to_ascii_lowercase.

This also fixes a bug in Servo where attr() rules with an unknown namespace
prefix are parsed, which is wrong.
2018-02-07 17:34:22 +01:00
Emilio Cobos Álvarez
69ddb9501b
style: Remove some uses of unused unsafe. 2017-11-15 13:26:24 +01:00
Simon Sapin
954b2cc3d8
Allow unused imports for AsciiExt in style code.
See #19128, this part is cherry-picked so Gecko can build with rust nightly.
2017-11-09 12:43:23 +01:00
Nicholas Nethercote
5866b820e0 Introduce nsStaticAtom.
It's a sub-class of nsAtom, useful for cases where you know you are dealing
exclusively with static atoms. The nice thing about it is that you can use
raw nsStaticAtom pointers instead of RefPtr<>. (In fact, the AddRef/Release
implementations ensure that we'll crash if we use RefPtr<nsStaticAtom>.)
2017-10-27 20:33:40 +11:00
Nicholas Nethercote
a26d25db12 Rename size_of_is_0! as malloc_size_of_is_0!.
The new name makes it clearer that it comes from the `malloc_size_of`
crate.
2017-10-18 14:26:56 +11:00
Nicholas Nethercote
7628c1236a Rename nsIAtom as nsAtom.
Bug 1400459 devirtualized nsIAtom so that it is no longer a subclass of
nsISupports. This means that nsAtom is now a better name for it than
nsIAtom.
2017-10-09 09:27:11 +11:00
Michael Layzell
c1c98659b9 Update ns[C]String::from -> ns[C]Str::from where possible 2017-09-26 11:03:35 -04:00
Nicholas Nethercote
c5aa2cb986 Measure PropertyDeclaration more thoroughly.
This patch replaces the handwritten MallocSizeOf implementation for
PropertyDeclaration with a derived one, which gives much more thorough
measurement.

This requires (a) deriving MallocSizeOf for a *lot* of additional types (most
of which already have `derive(HeapSizeOf)` in Servo builds), and (b)
implementing MallocSizeOf for a few more types in the `malloc_size_of` crate.

These changes would significantly improve the reporting coverage for gmail if
it weren't for the fact that SpecifiedUrl isn't measured due to a lack of
clarity about its fields; that can be fixed as a follow-up once bug 1397971 has
landed.
2017-09-14 13:18:03 +10:00
Nicholas Nethercote
32548e5312 Overhaul MallocSizeOf and related things.
This patch makes the MallocSizeOf stuff in Stylo work more like the HeapSizeOf
stuff already in Servo, except better. In particular, it adds deriving support
for MallocSizeOf, which will make it easier to improve coverage.

The patch does the following.

- Combines servo/components/style/stylesheets/memory.rs and the heapsize crate
  into a new crate, malloc_size_of.

- Forks the heapsize_derive crate, calling it malloc_size_of, so that
  MallocSizeOf can be derived.

- Both the new crates have MIT/Apache licenses, like heapsize, in case they are
  incorporated into heapsize in the future.

- Renames the methods within MallocSizeOf and the related traits so they are
  more concise.

- Removes MallocSizeOfWithGuard.

- Adds `derive(MallocSizeOf)` to a lot of types, in some cases replacing an
  equivalent or almost-equivalent hand-written implementation.

- Adds stuff so that Rc/Arc can be handled properly.
2017-09-12 12:37:51 +10:00
Xidorn Quan
4f6752ed1a Harden assert for creating atom from raw pointer. 2017-08-30 12:36:45 +10:00
Clément DAVID
c5fe235112 order derivable traits lists
Ignoring :
 - **generated**.rs
 - python/tidy/servo_tidy_tests/rust_tidy.rs
2017-08-23 21:38:44 +02:00
Emilio Cobos Álvarez
4e3ea45325
stylo: Devirtualize nsIAtom refcounting.
Bug: 1362338
Reviewed-by: froydnj
MozReview-Commit-ID: 3q5rz3L8quQ
2017-08-09 13:06:11 +02:00
Emilio Cobos Álvarez
efed0ac742
stylo: We've had bitfield accessors for a while now. 2017-08-08 17:34:12 +02:00
Ehsan Akhgari
aeb2b8b098 stylo: Read mName as a raw nsIAtom* from NodeInfoInner. 2017-07-24 10:40:58 -04:00
Simon Sapin
eb98ae6e04 Update cssparser to 0.18
https://github.com/servo/rust-cssparser/pull/171
2017-07-24 11:39:12 +02:00
Emilio Cobos Álvarez
ce9cd802de
style: Clean up after #17427. 2017-06-20 15:42:23 +02:00
Simon Sapin
a5bb55790f Untry style 2017-06-18 13:18:13 +02:00
Simon Sapin
5bccf98aa4 ID and class selectors are ASCII case-insensitive in quirks mode.
https://bugzilla.mozilla.org/show_bug.cgi?id=1363778
2017-06-12 23:33:53 +02:00