Bug 201316 - Add support for CompactPointerTuple<..., OptionSet<...>>
Summary: Add support for CompactPointerTuple<..., OptionSet<...>>
Status: REOPENED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: WebKit Local Build
Hardware: All All
: P2 Normal
Assignee: Daniel Bates
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-08-29 16:00 PDT by Daniel Bates
Modified: 2019-10-11 07:30 PDT (History)
12 users (show)

See Also:


Attachments
Patch and test (11.14 KB, patch)
2019-08-29 16:10 PDT, Daniel Bates
no flags Details | Formatted Diff | Diff
Patch and test (11.14 KB, patch)
2019-08-29 16:14 PDT, Daniel Bates
no flags Details | Formatted Diff | Diff
Patch and test (14.21 KB, patch)
2019-08-29 17:35 PDT, Daniel Bates
no flags Details | Formatted Diff | Diff
Patch and test (14.22 KB, patch)
2019-08-30 11:12 PDT, Daniel Bates
no flags Details | Formatted Diff | Diff
Patch (14.25 KB, patch)
2019-09-03 16:15 PDT, Daniel Bates
no flags Details | Formatted Diff | Diff
Patch (15.70 KB, patch)
2019-09-09 12:03 PDT, Daniel Bates
no flags Details | Formatted Diff | Diff
Patch (14.33 KB, patch)
2019-09-13 11:55 PDT, Daniel Bates
no flags Details | Formatted Diff | Diff
Patch (15.76 KB, patch)
2019-09-13 11:57 PDT, Daniel Bates
no flags Details | Formatted Diff | Diff
Updated patch (14.30 KB, patch)
2019-10-09 10:30 PDT, Daniel Bates
no flags Details | Formatted Diff | Diff
To land (14.26 KB, patch)
2019-10-09 14:01 PDT, Daniel Bates
no flags Details | Formatted Diff | Diff
Take 2: To Land (14.33 KB, patch)
2019-10-09 17:12 PDT, Daniel Bates
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Bates 2019-08-29 16:00:06 PDT
Came across code in Node.h <https://trac.webkit.org/browser/trunk/Source/WebCore/dom/Node.h?rev=249287#L619> that uses CompactPointerTuple to store a bitmask and does raw bitmask manipulation. We have a type safe convenience class called OptionSet<> that represents a bitmask that can abstract such operations away plus it is pretty printable. We should support CompactPointerTuple<..., OptionSet<...>>.
Comment 1 Daniel Bates 2019-08-29 16:10:03 PDT
Created attachment 377647 [details]
Patch and test
Comment 2 Daniel Bates 2019-08-29 16:11:22 PDT
Comment on attachment 377647 [details]
Patch and test

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

> Source/WTF/wtf/CompactPointerTuple.h:71
> +        static constexpr uint8_t toRaw(T value) { return value; }
> +        static constexpr T fromRaw(uint8_t value) { return static_cast<T>(value); }

Just had a thought, maybe toByte() and fromByte() would be better names. Thoughts?
Comment 3 Daniel Bates 2019-08-29 16:14:21 PDT
Created attachment 377648 [details]
Patch and test
Comment 4 Daniel Bates 2019-08-29 16:21:35 PDT
Another thought.... should update code to use std::byte.
Comment 5 Daniel Bates 2019-08-29 16:24:11 PDT
(In reply to Daniel Bates from comment #4)
> Another thought.... should update code to use std::byte.

Not in this bug though assuming it is even feasible.
Comment 6 Sam Weinig 2019-08-29 17:20:06 PDT
Comment on attachment 377648 [details]
Patch and test

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

> Tools/ChangeLog:11
> +        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:

Did you forget to svn add the new test?
Comment 7 Daniel Bates 2019-08-29 17:31:38 PDT
(In reply to Sam Weinig from comment #6)
> Comment on attachment 377648 [details]
> Patch and test
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=377648&action=review
> 
> > Tools/ChangeLog:11
> > +        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
> 
> Did you forget to svn add the new test?

Yep
Comment 8 Daniel Bates 2019-08-29 17:35:16 PDT
Created attachment 377659 [details]
Patch and test
Comment 9 Daniel Bates 2019-08-29 17:38:06 PDT
Could make tests more comprehensive. Anyway this is a start as no tests for CompactPointerTuple were originally added
Comment 10 Daniel Bates 2019-08-30 11:12:14 PDT
Created attachment 377734 [details]
Patch and test
Comment 11 Daniel Bates 2019-09-03 16:15:49 PDT
Created attachment 377928 [details]
Patch
Comment 12 Daniel Bates 2019-09-09 12:03:51 PDT
Created attachment 378391 [details]
Patch
Comment 13 Daniel Bates 2019-09-09 12:07:04 PDT
I didn't specialize std::is_integral because of:

[[
None of the templates defined in <type_traits> may be specialized for a program-defined type, except for std::common_type. This includes the type traits and the class template std::integral_constant.
]]
<https://unixpapa.com/js/testkey.html>
Comment 14 Daniel Bates 2019-09-09 12:07:20 PDT
(In reply to Daniel Bates from comment #13)
> I didn't specialize std::is_integral because of:
> 
> [[
> None of the templates defined in <type_traits> may be specialized for a
> program-defined type, except for std::common_type. This includes the type
> traits and the class template std::integral_constant.
> ]]
> <https://unixpapa.com/js/testkey.html>

* <https://en.cppreference.com/w/cpp/language/extending_std>
Comment 15 Daniel Bates 2019-09-13 11:55:50 PDT
Created attachment 378739 [details]
Patch
Comment 16 Daniel Bates 2019-09-13 11:57:48 PDT
Created attachment 378741 [details]
Patch
Comment 17 Yusuke Suzuki 2019-09-25 13:32:31 PDT
Comment on attachment 378741 [details]
Patch

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

r=me with comment.

> Source/WTF/wtf/CompactPointerTuple.h:77
> +    template<typename T> struct ByteValueTypeAdapter {
> +        static constexpr uint8_t toByte(T value) { return value; }
> +        static constexpr T fromByte(uint8_t value) { return static_cast<T>(value); }
> +    };
> +
> +    template<typename U> struct ByteValueTypeAdapter<OptionSet<U>> {
> +        static constexpr uint8_t toByte(OptionSet<U> value) { return value.toRaw(); }
> +        static constexpr OptionSet<U> fromByte(uint8_t value) { return OptionSet<U>::fromRaw(value); }
> +    };

How about taking this as a template parameter of `CompactPointerTuple`? Like,

template<typename PointerType, typename Type, typename Adaptor = ByteValueTypeAdapter<Type>>
class CompactPointerTuple;
Comment 18 Daniel Bates 2019-09-25 13:35:10 PDT
Comment on attachment 378741 [details]
Patch

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

>> Source/WTF/wtf/CompactPointerTuple.h:77
>> +    };
> 
> How about taking this as a template parameter of `CompactPointerTuple`? Like,
> 
> template<typename PointerType, typename Type, typename Adaptor = ByteValueTypeAdapter<Type>>
> class CompactPointerTuple;

I can do this. Only reason not to is to avoid exposing ByteValueTypeAdapter in the WTF namespace....
Comment 19 Daniel Bates 2019-09-25 13:36:29 PDT
Comment on attachment 378741 [details]
Patch

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

>>> Source/WTF/wtf/CompactPointerTuple.h:77
>>> +    };
>> 
>> How about taking this as a template parameter of `CompactPointerTuple`? Like,
>> 
>> template<typename PointerType, typename Type, typename Adaptor = ByteValueTypeAdapter<Type>>
>> class CompactPointerTuple;
> 
> I can do this. Only reason not to is to avoid exposing ByteValueTypeAdapter in the WTF namespace....

Haha, I was trying to avoid exposing this struct, but accidentally put in public section. So, your suggestion is no different except for qualification.
Comment 20 Daniel Bates 2019-10-09 10:30:03 PDT
Created attachment 380541 [details]
Updated patch
Comment 21 Daniel Bates 2019-10-09 14:01:25 PDT
Created attachment 380562 [details]
To land
Comment 22 Daniel Bates 2019-10-09 14:03:01 PDT
Committed r250930: <https://trac.webkit.org/changeset/250930>
Comment 23 Radar WebKit Bug Importer 2019-10-09 14:03:17 PDT
<rdar://problem/56129500>
Comment 24 Russell Epstein 2019-10-09 16:50:23 PDT
Reverted r250930 for reason:

Broke watchOS Builds

Committed r250943: <https://trac.webkit.org/changeset/250943>
Comment 25 Daniel Bates 2019-10-09 17:12:26 PDT
Created attachment 380589 [details]
Take 2: To Land
Comment 26 Daniel Bates 2019-10-09 17:13:30 PDT
Committed r250945: <https://trac.webkit.org/changeset/250945>
Comment 27 Truitt Savell 2019-10-10 07:55:52 PDT
It looks like this change, as well as the previous one that was rolled out, has broken 18 API tests on Debug for Mac and iOS.

Build:
https://build.webkit.org/builders/Apple%20Mojave%20Debug%20WK1%20%28Tests%29/builds/6157

They are crashing with this:

ASSERTION FAILED: Enumerator is not a positive power of two.
        hasOneBitSet(static_cast<StorageType>(option))
        /Volumes/Data/slave/mojave-debug/build
Comment 28 Jonathan Bedard 2019-10-11 07:30:25 PDT
Reverted r250945 for reason:

Broke 18 Debug API tests

Committed r251008: <https://trac.webkit.org/changeset/251008>