Bug 235872 - [WTF] Add GenericHashKey
Summary: [WTF] Add GenericHashKey
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-01-30 11:40 PST by Yusuke Suzuki
Modified: 2022-01-31 00:49 PST (History)
20 users (show)

See Also:


Attachments
Patch (26.15 KB, patch)
2022-01-30 11:43 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (27.04 KB, patch)
2022-01-30 11:53 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (27.65 KB, patch)
2022-01-30 22:20 PST, Yusuke Suzuki
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2022-01-30 11:40:07 PST
[WTF] Add GenericHashKey
Comment 1 Yusuke Suzuki 2022-01-30 11:43:44 PST
Created attachment 450363 [details]
Patch
Comment 2 Yusuke Suzuki 2022-01-30 11:53:50 PST
Created attachment 450364 [details]
Patch
Comment 3 Darin Adler 2022-01-30 21:42:31 PST
I like this idea, helping fit any type into our hash table that requires empty and deleted values, not as sure about the name. If I think of a better name I will suggest it.
Comment 4 Yusuke Suzuki 2022-01-30 22:20:33 PST
Created attachment 450380 [details]
Patch
Comment 5 Yusuke Suzuki 2022-01-30 22:21:09 PST
(In reply to Darin Adler from comment #3)
> I like this idea, helping fit any type into our hash table that requires
> empty and deleted values, not as sure about the name. If I think of a better
> name I will suggest it.

Nice!
Comment 6 Darin Adler 2022-01-30 22:35:53 PST
Comment on attachment 450380 [details]
Patch

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

Can’t help thinking how much better some of this code would look with more use of auto, auto*, and auto&.

> Source/JavaScriptCore/dfg/DFGIntegerCheckCombiningPhase.cpp:195
> +            Range& range = m_map.add(data.m_key, Range { }).iterator->value;

When I see call sites like this, I wonder if we should overload add to have the empty value as the default. It’s annoying to have to write Range { } here.

> Source/JavaScriptCore/runtime/TypeLocationCache.cpp:59
> +    } else
> +        location = iterator->value;

I often like to reverse these things so that the shorter half of the if statement goes first.

But really, this looks like it should be rewritten to use ensure to me.

> Source/WTF/wtf/GenericHashKey.h:77
> +        if (m_value.index() != 0)
> +            return true;

Why not write this using holds_alternative instead of index? I think it would compile to the exact same code, but it would not depend on the ordering of the alternative types in the variant.
Comment 7 Yusuke Suzuki 2022-01-30 23:21:50 PST
Comment on attachment 450380 [details]
Patch

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

>> Source/JavaScriptCore/dfg/DFGIntegerCheckCombiningPhase.cpp:195
>> +            Range& range = m_map.add(data.m_key, Range { }).iterator->value;
> 
> When I see call sites like this, I wonder if we should overload add to have the empty value as the default. It’s annoying to have to write Range { } here.

For now, in this patch, I'll just use the existing interface.

>> Source/JavaScriptCore/runtime/TypeLocationCache.cpp:59
>> +        location = iterator->value;
> 
> I often like to reverse these things so that the shorter half of the if statement goes first.
> 
> But really, this looks like it should be rewritten to use ensure to me.

Sounds good! Changed.

>> Source/WTF/wtf/GenericHashKey.h:77
>> +            return true;
> 
> Why not write this using holds_alternative instead of index? I think it would compile to the exact same code, but it would not depend on the ordering of the alternative types in the variant.

Sounds good, changed!
Comment 8 Yusuke Suzuki 2022-01-31 00:49:01 PST
Committed r288807 (246583@trunk): <https://commits.webkit.org/246583@trunk>
Comment 9 Radar WebKit Bug Importer 2022-01-31 00:49:17 PST
<rdar://problem/88257247>