Bug 152337

Summary: Add "explicit operator bool" to ScratchRegisterAllocator::PreservedState
Product: WebKit Reporter: Saam Barati <saam>
Component: JavaScriptCoreAssignee: Saam Barati <saam>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, keith_miller, mark.lam, msaboff
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
patch mark.lam: review+

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