Bug 203252 - Move MatchResult and related types out of StyleResolver
Summary: Move MatchResult and related types out of StyleResolver
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-10-22 09:20 PDT by Antti Koivisto
Modified: 2019-10-24 01:19 PDT (History)
13 users (show)

See Also:


Attachments
wip (41.02 KB, patch)
2019-10-22 09:21 PDT, Antti Koivisto
no flags Details | Formatted Diff | Diff
wip (41.67 KB, patch)
2019-10-22 12:05 PDT, Antti Koivisto
no flags Details | Formatted Diff | Diff
wip (41.02 KB, patch)
2019-10-22 12:29 PDT, Antti Koivisto
no flags Details | Formatted Diff | Diff
wip (41.02 KB, patch)
2019-10-23 02:23 PDT, Antti Koivisto
no flags Details | Formatted Diff | Diff
wip (41.86 KB, patch)
2019-10-23 02:49 PDT, Antti Koivisto
no flags Details | Formatted Diff | Diff
patch (45.62 KB, patch)
2019-10-23 04:31 PDT, Antti Koivisto
zalan: review+
Details | Formatted Diff | Diff
patch (45.58 KB, patch)
2019-10-24 00:08 PDT, Antti Koivisto
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Antti Koivisto 2019-10-22 09:20:57 PDT
Reverse the dependency between StyleResolver and ElementRuleCollector. The former should depend on the latter.
Comment 1 Antti Koivisto 2019-10-22 09:21:21 PDT
Created attachment 381552 [details]
wip
Comment 2 Antti Koivisto 2019-10-22 12:05:31 PDT
Created attachment 381579 [details]
wip
Comment 3 Antti Koivisto 2019-10-22 12:29:34 PDT
Created attachment 381581 [details]
wip
Comment 4 Antti Koivisto 2019-10-23 02:23:47 PDT
Created attachment 381667 [details]
wip
Comment 5 Antti Koivisto 2019-10-23 02:49:16 PDT
Created attachment 381668 [details]
wip
Comment 6 Antti Koivisto 2019-10-23 04:31:36 PDT
Created attachment 381675 [details]
patch
Comment 7 Said Abou-Hallawa 2019-10-23 11:54:27 PDT
Comment on attachment 381675 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=381675&action=review

> Source/WebCore/ChangeLog:12
> +        The desired cascade level is indicated with en enum instead of a range.

Typo: en enum.

> Source/WebCore/css/ElementRuleCollector.cpp:130
>      if (!isCacheable)
>          m_result.isCacheable = false;

I think these two lines should be moved before addMatchedProperties() above because if isCacheable is false, addMatchedProperties() should try to fix m_result.isCacheable.

> Source/WebCore/css/ElementRuleCollector.cpp:622
> +    if (matchedProperties.styleScopeOrdinal != Style::ScopeOrdinal::Element)
> +        m_result.isCacheable = false;
> +
> +    if (m_result.isCacheable) {

Maybe the part of fixing the m_result.isCacheable deserves its own function. 

    m_result.isCacheable = fixIsCacheable(matchedProperties);
    switch (declarationOrigin) {
        ...
    }

I think it can be even be a static. It will also save lines by early returns instead of setting m_result.isCacheable = false; break; below.

> Source/WebCore/css/ElementRuleCollector.cpp:632
> +            if (!current.isInherited()) {

Can we flip the condition and continue:

if (current.isInherited())
    continue;

> Source/WebCore/css/StyleResolver.cpp:2255
> +static auto& declarationsForCascadeLevel(const MatchResult& matchResult, CascadeLevel cascadeLevel)

This function can be added to MatchResult. It can be even a bracket operator. So instead of:

    declarationsForCascadeLevel(matchResult, cascadeLevel)

It can be

    matchResult[cascadeLevel]

> Source/WebCore/css/StyleResolver.h:421
> +        Vector<MatchedProperties> userAgentDeclarations;
> +        Vector<MatchedProperties> userDeclarations;
> +        Vector<MatchedProperties> authorDeclarations;

Can't we replace these member by just one MatchResult?  I think all what we do with these members is assigning their values from a MatchResult and comparing them with a MatchResult.
Comment 8 Antti Koivisto 2019-10-23 22:32:28 PDT
> This function can be added to MatchResult. ]

I actually had that but it requires some further refactoring (moving CascadeLevel enum). I decided I need to stop at some point.

> 
> > Source/WebCore/css/StyleResolver.h:421
> > +        Vector<MatchedProperties> userAgentDeclarations;
> > +        Vector<MatchedProperties> userDeclarations;
> > +        Vector<MatchedProperties> authorDeclarations;
> 
> Can't we replace these member by just one MatchResult?  I think all what we
> do with these members is assigning their values from a MatchResult and
> comparing them with a MatchResult.

Almost, the issue is that MatchResult has large inline capacity for these (it is a temporary type used during collection) while cache entries have none (they are long-lived and immutable).

Making that work requires either templating MatchResult or proving that inline capacity is unnecessary (it probably is) which is best left for another patch.
Comment 9 Antti Koivisto 2019-10-24 00:08:02 PDT
Created attachment 381781 [details]
patch
Comment 10 WebKit Commit Bot 2019-10-24 01:18:43 PDT
Comment on attachment 381781 [details]
patch

Clearing flags on attachment: 381781

Committed r251532: <https://trac.webkit.org/changeset/251532>
Comment 11 WebKit Commit Bot 2019-10-24 01:18:45 PDT
All reviewed patches have been landed.  Closing bug.
Comment 12 Radar WebKit Bug Importer 2019-10-24 01:19:13 PDT
<rdar://problem/56571489>