Commit Graph

166 Commits

Author SHA1 Message Date
Emilio Cobos Álvarez
e6342609f5 Bug 1891296 - Fix an assertion in selector-matching. r=dshin
We can have combinator sequences like [>, <part>], and they are fine.

Add a test to make sure they're handled correctly.

Differential Revision: https://phabricator.services.mozilla.com/D208668
2024-04-25 19:35:10 +00:00
David Shin
06ec16dc27 Bug 1874042: Add support for unknown match result for invalidation by comparing now/then. r=firefox-style-system-reviewers,emilio
Differential Revision: https://phabricator.services.mozilla.com/D205257
2024-04-02 20:29:05 +00:00
Niels
1ebcf8cd41 Bug 1856285 Invert hover_and_active_quirk_applies match statement and extend test_hover_quirk. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D205299
2024-03-27 17:16:52 +00:00
David Shin
01451997f0 Bug 1876962: Part 1 - Fix up logic for determining Rightmost in matches_selector. r=firefox-style-system-reviewers,emilio
Would generate invalid results `:has()` selector if it's in the subject
compound but also uses a pseudo-selector (e.g. `.foo:has(.bar)::after`).

Also rename `Rightmost` to `SubjectOrPseudoElement` to more accurately
describe what it indicates.

Differential Revision: https://phabricator.services.mozilla.com/D200222
2024-02-12 14:42:07 +00:00
David Shin
5fc47d06be Bug 1874066: Distinguish edge selectors vs. other nth selectors. r=firefox-style-system-reviewers,emilio
Differential Revision: https://phabricator.services.mozilla.com/D198464
2024-01-15 16:09:17 +00:00
Zach Hoffman
7c161d33f1 Bug 1865563 - Rustfmt servo/. r=firefox-style-system-reviewers,emilio
$ git ls-files servo/*.rs | xargs rustup run nightly rustfmt

Differential Revision: https://phabricator.services.mozilla.com/D194020
2023-11-20 15:17:57 +00:00
Emilio Cobos Álvarez
369d1f7a56 Bug 1864647 - Don't crash when finding nested relative selectors. r=dshin
For now, do the same as pseudo-elements, which is effectively to keep
them in the replaced selector but don't match them. Avoid crashing in
this case.

I filed https://github.com/w3c/csswg-drafts/issues/9600 since this issue
isn't specific about :has(), and depending on the result of that
discussion, the "proper" solution might be different.

Differential Revision: https://phabricator.services.mozilla.com/D193663
2023-11-15 17:21:24 +00:00
David Shin
a749366a1d Bug 1853258: Part 3 - Optimize invalidating relative selectors on DOM mutation. r=emilio
There are cases where we can run a selector match to realize that some DOM mutations
will not make a difference in the relative selector match state, which avoids
O(n^2) behaviour under some circumstances.

Differential Revision: https://phabricator.services.mozilla.com/D191307
2023-10-24 15:11:54 +00:00
Emilio Cobos Álvarez
4067c993be Bug 1859917 - Make SelectorList cheaply cloneable and more compact. r=dshin
We have ArcSelectorList for selector-lists that are cheap to copy.

For bug 1859915 and related, what we're going to end up doing is probably
expanding into the SelectorList of the parent rule unconditionally, at least
for the "single bare &" case.

It'd be nice to unify SelectorList implementations as preparation for that, and
make them cheaper to clone in general.

My proposal is making SelectorList a tagged pointer to either a single
selector, or to a ThinArc, effectively preserving the SmallVec<> optimization
we have now. This patch implements that proposal.

Depends on D191361

Differential Revision: https://phabricator.services.mozilla.com/D191362
2023-10-19 15:35:54 +00:00
David Shin
f5bdf14ba3 Bug 1858720: Prevent :has over-invalidation with sibling DOM mutations. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D190817
2023-10-17 13:17:31 +00:00
Emilio Cobos Álvarez
3b96b5b52a Bug 1856018 - Make forgiving selectors serialize. r=dshin
As per resolution in https://github.com/w3c/csswg-drafts/issues/8356

Safari already does this. Expand the tests they tweaked to be useful
again (test that when non-forgiving parsing is used, then the selector
is invalid).

Differential Revision: https://phabricator.services.mozilla.com/D189666
2023-10-04 12:52:06 +00:00
Sandor Molnar
ab60af59a7 Backed out changeset 21db15048e15 (bug 1856018) for causing multiple failures/bustages CLOSED TREE 2023-10-03 20:41:43 +03:00
Emilio Cobos Álvarez
09b0938a70 Bug 1856018 - Make forgiving selectors serialize. r=dshin
As per resolution in https://github.com/w3c/csswg-drafts/issues/8356

Safari already does this. Expand the tests they tweaked to be useful
again (test that when non-forgiving parsing is used, then the selector
is invalid).

Differential Revision: https://phabricator.services.mozilla.com/D189666
2023-10-03 16:05:24 +00:00
Emilio Cobos Álvarez
0b7e208450 Bug 1854658 - Fix the part combinator to deal with exportparts correctly. r=zrhoffman
We need to jump to an element in the correct scope just like ::slotted()
does.

Factor that code to its own function both so that it's easier to reason
about and so that the code for that function remains small. At the end
of the day other combinators like descendant or sibling get executed a
ton of times (while pseudo-elements only jump once).

Differential Revision: https://phabricator.services.mozilla.com/D189478
2023-10-02 11:51:03 +00:00
Mike Hommey
d397f97d62 Bug 1855617 - Upgrade stylo to bitflags 2. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D189451
2023-09-28 08:01:16 +00:00
Mike Hommey
ae23761eda Bug 1852209 - Fixup servo for bitflags 2 after bug 1792501. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D189315
2023-09-27 19:56:16 +00:00
David Shin
ec575e1970 Bug 1792501: Part 1 - Mark relative selector search path. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D185674
2023-09-14 22:21:24 +00:00
Sandor Molnar
f1783ba5d9 Backed out 8 changesets (bug 1792501) for causing wpt failures on /css/selectors/...
Backed out changeset 993b0e6567e6 (bug 1792501)
Backed out changeset 7686c9df9ad4 (bug 1792501)
Backed out changeset cf9f855ad80c (bug 1792501)
Backed out changeset 27abe13a5a48 (bug 1792501)
Backed out changeset f708f940e907 (bug 1792501)
Backed out changeset 2a7c57a69803 (bug 1792501)
Backed out changeset 69f1155100f5 (bug 1792501)
Backed out changeset 3f5f59b76a56 (bug 1792501)
2023-09-14 20:08:41 +03:00
David Shin
53433d6130 Bug 1792501: Part 1 - Mark relative selector search path. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D185674
2023-09-14 12:30:54 +00:00
Mike Hommey
298ef7b0b9 Bug 1852201 - Downgrade bitflags in the dom and style crates. r=emilio
This undoes bug 1835681, adjusting for changes that happened since then,
because the crates don't build with the real bitflags 2, and there are
some challenges to make them work with the real bitflags 2.

Differential Revision: https://phabricator.services.mozilla.com/D187748
2023-09-10 22:27:26 +00:00
David Shin
ff427d6005 Bug 1845095: Make sure caching and filtering for relative selector isn't used in invalidation. r=emilio
Unify the invalidation flag used for nth index cache for this purpose.

Differential Revision: https://phabricator.services.mozilla.com/D184526
2023-07-31 12:21:25 +00:00
David Shin
c4efcc3ef0 Bug 1845095: Bloom filter for fast-rejecting :has(). r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D184525
2023-07-31 12:21:24 +00:00
Cristina Horotan
6e85843244 Backed out 2 changesets (bug 1845095) for causing wpt failures at is-pseudo-containing-complex-in-has.html CLOSED TREE
Backed out changeset 28c18b287904 (bug 1845095)
Backed out changeset fb0e9233e07d (bug 1845095)
2023-07-28 19:07:26 +03:00
David Shin
f5740faa23 Bug 1845095: Make sure caching and filtering for relative selector isn't used in invalidation. r=emilio
Unify the invalidation flag used for nth index cache for this purpose.

Differential Revision: https://phabricator.services.mozilla.com/D184526
2023-07-28 13:13:35 +00:00
David Shin
ff147ae14b Bug 1845095: Bloom filter for fast-rejecting :has(). r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D184525
2023-07-28 13:13:34 +00:00
Emilio Cobos Álvarez
dc7ce7ac80 Bug 1844900 - Improve memory usage with nesting. r=dshin
The idea is to share more memory when expanding nested rules (so being
able to share the whole :is() / :where() allocation), and same for the
Dependency computation (basically, share it across all descendant
selectors).

This prevents exponential explosion in cases like the one in bug 1844446
if you replace tag selectors by class selectors (so that we build
invalidation maps for them).

Differential Revision: https://phabricator.services.mozilla.com/D184283
2023-07-27 21:38:10 +00:00
Natalia Csoregi
acc7117fc4 Backed out changeset c59d018a76ed (bug 1844900) for causing bustages. CLOSED TREE 2023-07-28 00:04:59 +03:00
Emilio Cobos Álvarez
c6e1649f4d Bug 1844900 - Improve memory usage with nesting. r=dshin
The idea is to share more memory when expanding nested rules (so being
able to share the whole :is() / :where() allocation), and same for the
Dependency computation (basically, share it across all descendant
selectors).

This prevents exponential explosion in cases like the one in bug 1844446
if you replace tag selectors by class selectors (so that we build
invalidation maps for them).

Differential Revision: https://phabricator.services.mozilla.com/D184283
2023-07-27 20:24:23 +00:00
Iulian Moraru
8136d872ee Backed out 2 changesets (bug 1845095) for causing build bustages related to DummyAtom: PrecomputedHash. CLOSED TREE
Backed out changeset c3549dbe2420 (bug 1845095)
Backed out changeset 2b7db53664a6 (bug 1845095)
2023-07-27 21:31:19 +03:00
David Shin
65bd9482ef Bug 1845095: Make sure caching and filtering for relative selector isn't used in invalidation. r=emilio
Unify the invalidation flag used for nth index cache for this purpose.

Differential Revision: https://phabricator.services.mozilla.com/D184526
2023-07-27 18:03:38 +00:00
David Shin
30103c67d7 Bug 1845095: Bloom filter for fast-rejecting :has(). r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D184525
2023-07-27 18:03:38 +00:00
David Shin
fce48aa58c Bug 1822177: Simple relative selector caching. r=emilio
This simple relative selector cache avoids O(n^2) behaviour when the relative
selector is not in the subject position. e.g. `.anchor:has(.a) ~ .subject`,
with a DOM tree .anchor + .subject + .. + .subject.

Differential Revision: https://phabricator.services.mozilla.com/D184373
2023-07-25 14:23:27 +00:00
David Shin
21dfffaa1a Bug 1843103: Proper cousin style sharing for non-rightmost :has() selectors. r=emilio
Previous code actually could not distinguish when `:has()` is on the rightmost
side or not. This caused every candidate containing any `:has()` selector to be
outright refused from being inserted into style sharing cache.

Differential Revision: https://phabricator.services.mozilla.com/D183405
2023-07-24 12:49:57 +00:00
Markus Stange
faf7cedd20 Bug 1839082 - Add a fast path for non-compound attribute selectors. r=emilio
This improves the testcase in bug 1837673, because it means that we only
check attributes once. Before this patch, we would check them twice: First,
the SimpleFilter path would check for the presence of the attribute, and then
later we would enumerate attributes again to check the attribute value.
Now we don't use the SimpleFilter path anymore and go straight to attribute
enumeration.

Differential Revision: https://phabricator.services.mozilla.com/D181349
2023-07-09 19:09:27 +00:00
Emilio Cobos Álvarez
c7dd68dba8 Bug 1837818 - Remove special selector-matching case in matches_simple_selector. r=boris
This doesn't regress stylebench.

Depends on D180592

Differential Revision: https://phabricator.services.mozilla.com/D180593
2023-06-19 09:51:38 +00:00
Emilio Cobos Álvarez
254cdf61d8 Bug 1837818 - Minor selector matching tweaks. r=boris
The idea is to make the function small enough that it's fast to inline and
optimize by the compiler. For that:

 * Move some complex bits of matches_simple_selector into functions so
   that the compiler can put them out of line if it wants.

 * Rename a function to be more descriptive and not force it to be
   inline (that wasn't measured afaict, comes from the :nth-child(of)
   implementation).

Depends on D180591

Differential Revision: https://phabricator.services.mozilla.com/D180592
2023-06-16 17:24:01 +00:00
Emilio Cobos Álvarez
ddfe8f1e6d Bug 1838670 - Match parent selector like :scope. r=zrhoffman
https://drafts.csswg.org/css-nesting-1/#nest-selector:

    When used in any other context, it represents the same elements as
    :scope in that context (unless otherwise defined).

Differential Revision: https://phabricator.services.mozilla.com/D181119
2023-06-16 15:22:31 +00:00
Zach Hoffman
dcfaf2c081 Bug 1837351 - Skip positional pseudo-class matching during invalidation r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D180769
2023-06-16 03:33:18 +00:00
Emilio Cobos Álvarez
8ca8093552 Bug 1837734 - Remove the never_matches field from attr selectors. r=boris
It's an extra branch which in practice we almost never take, plus extra
checks during parsing.

Differential Revision: https://phabricator.services.mozilla.com/D180529
2023-06-14 21:08:22 +00:00
Emilio Cobos Álvarez
1ed5840820 Bug 1837734 - Add a way to optimize the "attribute in no namespace exists" check. r=boris
Go through the slow path by default. No behavior change.

Differential Revision: https://phabricator.services.mozilla.com/D180528
2023-06-14 21:08:21 +00:00
David Shin
ba793505a2 Bug 1835037: Move ANCHORS_RELATIVE_SELECTOR out of nsINode flags. r=emilio
Move the flag to ComputedValueFlags, like `CONSIDERED_RELATIVE_SELECTOR`.

Differential Revision: https://phabricator.services.mozilla.com/D180726
2023-06-13 13:21:42 +00:00
Emilio Cobos Álvarez
a95f104801 Bug 1835681 - Update bitflags in the dom and style crates. r=zrhoffman
Use from_bits_retain where possible to save a few instructions here and there
while at it.

Differential Revision: https://phabricator.services.mozilla.com/D179379
2023-05-30 08:04:51 +00:00
David Shin
2a948d57d8 Bug 1793012: Correct style sharing handling for any element that considered :has() in selector matching. r=emilio
For any element that anchors a `:has()` selector (i.e. Matches a selector that
contains a `:has()` on its rightmost side), we prevent style sharing altogether,
as evaluation of the `:has()` selector is required in the first place to
determine style sharing.

On the other hand, any element matching a rule containing `:has()` without
anchoring it can do style sharing for siblings, but not cousins.

Differential Revision: https://phabricator.services.mozilla.com/D176836
2023-05-25 14:35:18 +00:00
Emilio Cobos Álvarez
6fa2383486 Bug 1834717 - More gracefully deal with broken calls into selector matching. r=dshin
If this happens again, it might be worth not matching rather than
potentially crashing. Though I guess crashing is a very good way getting
it reported soon...

Differential Revision: https://phabricator.services.mozilla.com/D178921
2023-05-24 13:24:14 +00:00
Emilio Cobos Álvarez
04c12707a0 Bug 1834717 - Properly increase the nesting level when matching :nth-child(of) selectors. r=dshin
Differential Revision: https://phabricator.services.mozilla.com/D178920
2023-05-24 12:55:12 +00:00
David Shin
6f1642c4ef Bug 1820835: :has relative selector matching, with no caching/filtering. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D172019
2023-03-15 16:39:33 +00:00
Zach Hoffman
aa003f1048 Bug 1818151 - Record attribute dependencies within the selector list of :nth-child(... of <selector list>) r=emilio
There are separate filters for IDs, classes, attribute local names, and
element state.

Also, we invalidate siblings of elements matched against the selector
list of :nth-child(... of <selector list>) by marking matched elements
with NODE_HAS_SLOW_SELECTOR_NTH_OF.

The only remaining invalidation case invalidation case is
`:nth-child(An+B of :has())` (bug 1818155), which should not block
shipping `layout.css.nth-child-of.enabled`, because :has(...) is still
being implemented (bug 418039).

Depends on D172352

Differential Revision: https://phabricator.services.mozilla.com/D171936
2023-03-15 06:56:21 +00:00
David Shin
cb015ecc18 Bug 1774588 - Parsing for relative selectors in :has(). r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D171358
2023-03-07 18:04:27 +00:00
Emilio Cobos Álvarez
7f5d57c29f Bug 1811205 - [css-nesting] Parse parent selector. r=zrhoffman
This parses the ampersand as a parent selector behind an
(off-by-default) selectors feature.

The plan is to call replace_parent_selector while we're doing the
CascadeData rebuilds, which is where we can have all the ancestor
nesting information.

No behavior change.

Differential Revision: https://phabricator.services.mozilla.com/D167237
2023-01-24 10:02:18 +00:00
Zach Hoffman
40a0e418f5 Bug 1808228 - Reuse list_matches_complex_selector() where possible r=emilio
It can be reused for the Is, Where, and Negation components.

Differential Revision: https://phabricator.services.mozilla.com/D166267
2023-01-18 21:20:02 +00:00