Bug 146154 - Employ explicit operator bool() instead of using the UnspecifiedBoolType workaround.
Summary: Employ explicit operator bool() instead of using the UnspecifiedBoolType work...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Mark Lam
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-19 11:54 PDT by Mark Lam
Modified: 2015-06-19 14:19 PDT (History)
7 users (show)

See Also:


Attachments
the patch. (16.35 KB, patch)
2015-06-19 12:00 PDT, Mark Lam
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Lam 2015-06-19 11:54:49 PDT
This also fixes a bug in CodeOrigin::isApproximatelyEqualTo() due to an unexpected implicit cast from the UnspecifiedBoolType workaround.
Comment 1 Mark Lam 2015-06-19 12:00:23 PDT
Created attachment 255209 [details]
the patch.
Comment 2 Darin Adler 2015-06-19 12:10:50 PDT
Comment on attachment 255209 [details]
the patch.

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

Iā€™m a little surprised that adopting the real operator bool involves introducing so many cases of !!, which I have always thought of as an idiom we wanted to avoid, popular on Windows for some reason.

> Source/JavaScriptCore/bytecode/CodeOrigin.cpp:77
> +        if (a.inlineCallFrame->executable.get() != b.inlineCallFrame->executable.get())

Looks like this is possibly a change in behavior. Is this a bug fix?

I prefer that we add an overload for the != operator rather than adding the calls to .get() here.

> Source/JavaScriptCore/bytecode/LLIntCallLinkInfo.h:48
> +    bool isLinked() { return !!callee; }

Ugly. Any better alternative? Maybe a local variable?

> Source/JavaScriptCore/heap/Handle.h:55
> +    explicit operator bool() const { return (m_slot && *m_slot); }

No need for the parentheses here.

> Source/JavaScriptCore/runtime/JSArray.cpp:379
> +            bool hadValue = !!valueSlot;

I think you can write this modern variant:

    bool hadValue { valueSlot };

I, for one, like that better than !!.
Comment 3 Filip Pizlo 2015-06-19 13:19:39 PDT
Comment on attachment 255209 [details]
the patch.

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

>> Source/JavaScriptCore/bytecode/CodeOrigin.cpp:77
>> +        if (a.inlineCallFrame->executable.get() != b.inlineCallFrame->executable.get())
> 
> Looks like this is possibly a change in behavior. Is this a bug fix?
> 
> I prefer that we add an overload for the != operator rather than adding the calls to .get() here.

I agree with this change.

I believe that isApproximatelyEqualTo() is not used on any critical path - it's mostly for our bytecode profiler.  Mark, can you confirm?
Comment 4 Mark Lam 2015-06-19 13:48:26 PDT
Comment on attachment 255209 [details]
the patch.

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

>>> Source/JavaScriptCore/bytecode/CodeOrigin.cpp:77
>>> +        if (a.inlineCallFrame->executable.get() != b.inlineCallFrame->executable.get())
>> 
>> Looks like this is possibly a change in behavior. Is this a bug fix?
>> 
>> I prefer that we add an overload for the != operator rather than adding the calls to .get() here.
> 
> I agree with this change.
> 
> I believe that isApproximatelyEqualTo() is not used on any critical path - it's mostly for our bytecode profiler.  Mark, can you confirm?

To answer Darin's question, yes, this is also a bug fix.

To answer Fil, this is used in CallLinkStatus::ContextMap which in turn is used for poly-variant call inlining, ByteCodeParser::handleCall(), and ByteCodeParser::handleVarargsCall().  It doesn't look related to the bytecode profiler.

>> Source/JavaScriptCore/bytecode/LLIntCallLinkInfo.h:48
>> +    bool isLinked() { return !!callee; }
> 
> Ugly. Any better alternative? Maybe a local variable?

I'm opting to leave this as is as it is more concise.

>> Source/JavaScriptCore/runtime/JSArray.cpp:379
>> +            bool hadValue = !!valueSlot;
> 
> I think you can write this modern variant:
> 
>     bool hadValue { valueSlot };
> 
> I, for one, like that better than !!.

Fixed.
Comment 5 Mark Lam 2015-06-19 14:19:28 PDT
Thanks for the review.  Landed in r185768: <http://trac.webkit.org/r185768>.