Bug 152337 - Add "explicit operator bool" to ScratchRegisterAllocator::PreservedState
Summary: Add "explicit operator bool" to ScratchRegisterAllocator::PreservedState
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Saam Barati
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-16 08:52 PST by Saam Barati
Modified: 2015-12-16 10:37 PST (History)
4 users (show)

See Also:


Attachments
patch (3.21 KB, patch)
2015-12-16 09:15 PST, Saam Barati
mark.lam: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Saam Barati 2015-12-16 08:52:14 PST
We should assert we only get valid PreservedStates in restore reused registers.
Comment 1 Saam Barati 2015-12-16 09:15:23 PST
Created attachment 267460 [details]
patch
Comment 2 Mark Lam 2015-12-16 09:17:51 PST
Comment on attachment 267460 [details]
patch

r=me
Comment 3 Darin Adler 2015-12-16 09:18:31 PST
Comment on attachment 267460 [details]
patch

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

> Source/JavaScriptCore/jit/ScratchRegisterAllocator.cpp:130
> +    RELEASE_ASSERT(!!preservedState);

Really surprised that we need !! here. I think that means there is something wrong with the RELEASE_ASSERT macro.

> Source/JavaScriptCore/jit/ScratchRegisterAllocator.h:82
> +        explicit operator bool() const { return numberOfBytesPreserved != std::numeric_limits<unsigned>::max(); }

I am interested to learn that this is sufficient by itself without also defining operator! for the class. I think this means we can remove many of our operator! definitions throughout the WebKit project.
Comment 4 Saam Barati 2015-12-16 09:38:19 PST
Comment on attachment 267460 [details]
patch

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

>> Source/JavaScriptCore/jit/ScratchRegisterAllocator.cpp:130
>> +    RELEASE_ASSERT(!!preservedState);
> 
> Really surprised that we need !! here. I think that means there is something wrong with the RELEASE_ASSERT macro.

We don't. I just do this for stylistic reasons (or lack thereof).
I happen to like the explicitness of how !! looks when testing the truthiness of something. This is probably overkill inside an assert.

>> Source/JavaScriptCore/jit/ScratchRegisterAllocator.h:82
>> +        explicit operator bool() const { return numberOfBytesPreserved != std::numeric_limits<unsigned>::max(); }
> 
> I am interested to learn that this is sufficient by itself without also defining operator! for the class. I think this means we can remove many of our operator! definitions throughout the WebKit project.

I think one of the main benefits of "explicit operator bool" is that it eliminates most of the need for operator!.
Comment 5 Saam Barati 2015-12-16 10:37:09 PST
landed in:
http://trac.webkit.org/changeset/194158