Bug 144848 - Introduce UniquedStringImpl and SymbolImpl to separate symbolic strings from AtomicStringImpl
Summary: Introduce UniquedStringImpl and SymbolImpl to separate symbolic strings from ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords:
: 144440 (view as bug list)
Depends on: 145109
Blocks: 145002 145350
  Show dependency treegraph
 
Reported: 2015-05-10 15:01 PDT by Yusuke Suzuki
Modified: 2015-05-23 11:42 PDT (History)
9 users (show)

See Also:


Attachments
Prototype (112.13 KB, patch)
2015-05-10 17:21 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Prototype (150.12 KB, patch)
2015-05-10 22:51 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews102 for mac-mavericks (533.78 KB, application/zip)
2015-05-10 23:43 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews104 for mac-mavericks-wk2 (578.80 KB, application/zip)
2015-05-11 00:17 PDT, Build Bot
no flags Details
Patch (210.90 KB, patch)
2015-05-12 04:08 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (219.66 KB, patch)
2015-05-12 07:30 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (230.32 KB, patch)
2015-05-12 07:41 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (230.57 KB, patch)
2015-05-12 07:56 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (158.58 KB, patch)
2015-05-20 10:24 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (159.49 KB, patch)
2015-05-20 11:03 PDT, 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 2015-05-10 15:01:24 PDT
The current AtomicStringImpl accidentally means the symbol OR atomic StringImpl.
It's not correct to its name and it's error prone.

In this issue, we'll introduce new 2 classes into WTF.

1. UniquedStringImpl

It's derived class from StringImpl. And it represents symbol || atomic StringImpl.
Since it contains symbol string, prohibiting the operator== for the other strings is preferable I think.
Only pointer based comparison is accepted. (due to its uniqueness)

2. SymbolImpl

It's derived class from UniquedStringImpl. Only symbol strings can become this.
It ensures the given StringImpl is symbol in compile time.


And changing AtomicStringImpl.

3. AtomicStringImpl

It's derived class from UniquedStringImpl. Only atomic (non-normal && non-symbol) strings can become this.
It ensures the given StringImpl is atomic in compile time.
Comment 1 Yusuke Suzuki 2015-05-10 17:21:20 PDT
Created attachment 252830 [details]
Prototype

JSC & WTF fix. WebCore and the others still remain
Comment 2 Yusuke Suzuki 2015-05-10 22:51:47 PDT
Created attachment 252840 [details]
Prototype

OSX remains
Comment 3 WebKit Commit Bot 2015-05-10 22:55:53 PDT
Attachment 252840 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/runtime/TypeSet.cpp:337:  The parameter type should use PassRefPtr instead of RefPtr.  [readability/pass_ptr] [5]
ERROR: Source/WebCore/ChangeLog:8:  You should remove the 'No new tests' and either add and list tests, or explain why no new tests were possible.  [changelog/nonewtests] [5]
ERROR: Source/JavaScriptCore/runtime/TypeSet.h:59:  The parameter type should use PassRefPtr instead of RefPtr.  [readability/pass_ptr] [5]
Total errors found: 3 in 78 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Build Bot 2015-05-10 23:43:40 PDT
Comment on attachment 252840 [details]
Prototype

Attachment 252840 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.appspot.com/results/5711213828767744

New failing tests:
fast/dom/named-items-with-symbol-name.html
Comment 5 Build Bot 2015-05-10 23:43:42 PDT
Created attachment 252842 [details]
Archive of layout-test-results from ews102 for mac-mavericks

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews102  Port: mac-mavericks  Platform: Mac OS X 10.9.5
Comment 6 Build Bot 2015-05-11 00:17:47 PDT
Comment on attachment 252840 [details]
Prototype

Attachment 252840 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/6274163782189056

New failing tests:
fast/dom/named-items-with-symbol-name.html
Comment 7 Build Bot 2015-05-11 00:17:51 PDT
Created attachment 252844 [details]
Archive of layout-test-results from ews104 for mac-mavericks-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-mavericks-wk2  Platform: Mac OS X 10.9.5
Comment 8 Yusuke Suzuki 2015-05-11 00:36:49 PDT
We need to create UniquedString, SymbolString in addition to AtomicString...
Comment 9 Darin Adler 2015-05-11 09:15:00 PDT
Comment on attachment 252830 [details]
Prototype

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

Comments on an older version of the patch.

> Source/JavaScriptCore/builtins/BuiltinNames.h:97
> +inline bool BuiltinNames::isPrivateName(SymbolImpl* uid) const
> +{
> +    return m_privateToPublicMap.contains(uid);
> +}

This can’t work with null -- hash table operations just assert with null -- so the argument should be a reference, not a pointer.

> Source/JavaScriptCore/builtins/BuiltinNames.h:101
> +inline bool BuiltinNames::isPrivateName(UniquedStringImpl* uid) const
>  {
>      if (!uid->isSymbol())

This doesn’t work with null -- we dereference the pointer right away -- so the argument should be a reference, not a pointer.

> Source/JavaScriptCore/bytecode/CodeBlock.cpp:3813
> +            return String(static_pointer_cast<StringImpl>(ptr->key));

I don’t understand the need to cast here.

> Source/JavaScriptCore/runtime/Identifier.h:178
> +    Identifier(SymbolImpl* uid) : m_string(uid) { ASSERT(m_string.impl()->isSymbol()); }

Should this constructor be explicit? Since this won’t work with null, this should take a reference, not a pointer. I don’t think the assertion makes sense now that the type is specific.

> Source/JavaScriptCore/runtime/MapData.h:118
> +    typedef HashMap<SymbolImpl*, int32_t, typename WTF::DefaultHash<SymbolImpl*>::Hash, WTF::HashTraits<SymbolImpl*>, IndexTraits> SymbolKeyedMap;

I think PtrHash would be clearer than DefaultHash here.

> Source/JavaScriptCore/runtime/PrivateName.h:30
>  #include <wtf/text/StringImpl.h>
> +#include <wtf/text/SymbolImpl.h>

Do we need both? I think that SymbolImpl.h must include StringImpl.h so we should just include it.

> Source/JavaScriptCore/runtime/PropertyMapHashTable.h:33
> +#include <wtf/text/UniquedStringImpl.h>

Should not need to add this include, since AtomicStringImpl has to include UniquedStringImpl.

> Source/JavaScriptCore/runtime/PropertyName.h:40
>          ASSERT(!m_impl || m_impl->isAtomic() || m_impl->isSymbol());

Assertion seems unneeded now that the type indicates this at runtime.

> Source/JavaScriptCore/runtime/SymbolTable.h:43
>  #include <wtf/text/StringImpl.h>
> +#include <wtf/text/UniquedStringImpl.h>

Don’t think we need both of these includes.

> Source/WTF/wtf/PrintStream.h:75
>  inline void printInternal(PrintStream& out, const AtomicStringImpl* value) { printInternal(out, bitwise_cast<const StringImpl*>(value)); }
> +inline void printInternal(PrintStream& out, const UniquedStringImpl* value) { printInternal(out, bitwise_cast<const StringImpl*>(value)); }

Can’t we just do the StringImpl* one and leave out the overloads for derived classes from StringImpl?

> Source/WTF/wtf/text/AtomicStringImpl.h:24
>  #include <wtf/text/StringImpl.h>

Should not need this include.

> Source/WTF/wtf/text/AtomicStringImpl.h:35
>  public:
> -    AtomicStringImpl() : StringImpl(0) {}
> +    AtomicStringImpl()
> +        : UniquedStringImpl()
> +    {
> +    }

Should be able to just delete all of this.

> Source/WTF/wtf/text/StringImpl.h:137
> +    friend class UniquedStringImpl;
>      friend class AtomicStringImpl;
> +    friend class SymbolImpl;

Alphabetic sorting please? Why would AtomicStringImpl need to be a friend any more?

> Source/WTF/wtf/text/UniquedStringImpl.h:36
> +        : StringImpl(0)

Should be nullptr, not 0.
Comment 10 Darin Adler 2015-05-11 09:16:03 PDT
(In reply to comment #8)
> We need to create UniquedString, SymbolString in addition to AtomicString...

We should not. We should just use RefPtr<UniquedStringImpl> and Ref<UniquedStringImpl> where we would otherwise use UniquedString. Same for SymbolStringImpl. Later we might rename the underlying classes to not have Impl in their names.
Comment 11 Yusuke Suzuki 2015-05-11 23:20:29 PDT
Comment on attachment 252830 [details]
Prototype

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

>> Source/JavaScriptCore/builtins/BuiltinNames.h:97
>> +}
> 
> This can’t work with null -- hash table operations just assert with null -- so the argument should be a reference, not a pointer.

OK, I've changed it to reference.

>> Source/JavaScriptCore/builtins/BuiltinNames.h:101
>>      if (!uid->isSymbol())
> 
> This doesn’t work with null -- we dereference the pointer right away -- so the argument should be a reference, not a pointer.

Fixed.

>> Source/JavaScriptCore/bytecode/CodeBlock.cpp:3813
>> +            return String(static_pointer_cast<StringImpl>(ptr->key));
> 
> I don’t understand the need to cast here.

Because there's no implict conversion from RefPtr<Derived> to RefPtr<Base>.
Here, I'll use ptr->key.get().

>> Source/JavaScriptCore/runtime/Identifier.h:178
>> +    Identifier(SymbolImpl* uid) : m_string(uid) { ASSERT(m_string.impl()->isSymbol()); }
> 
> Should this constructor be explicit? Since this won’t work with null, this should take a reference, not a pointer. I don’t think the assertion makes sense now that the type is specific.

Yeah! I've added explicit. (BTW, this constructor is private, and only called from the factory function.)
And drop the nonsense assert, it's now asserted in the compile phase by types!

>> Source/JavaScriptCore/runtime/MapData.h:118
>> +    typedef HashMap<SymbolImpl*, int32_t, typename WTF::DefaultHash<SymbolImpl*>::Hash, WTF::HashTraits<SymbolImpl*>, IndexTraits> SymbolKeyedMap;
> 
> I think PtrHash would be clearer than DefaultHash here.

Make sense!

>> Source/JavaScriptCore/runtime/PrivateName.h:30
>> +#include <wtf/text/SymbolImpl.h>
> 
> Do we need both? I think that SymbolImpl.h must include StringImpl.h so we should just include it.

Make sense. Just include SymbolImpl.h.

>> Source/JavaScriptCore/runtime/PropertyMapHashTable.h:33
>> +#include <wtf/text/UniquedStringImpl.h>
> 
> Should not need to add this include, since AtomicStringImpl has to include UniquedStringImpl.

Fixed

>> Source/JavaScriptCore/runtime/PropertyName.h:40
>>          ASSERT(!m_impl || m_impl->isAtomic() || m_impl->isSymbol());
> 
> Assertion seems unneeded now that the type indicates this at runtime.

Yeah. Fixed.

>> Source/JavaScriptCore/runtime/SymbolTable.h:43
>> +#include <wtf/text/UniquedStringImpl.h>
> 
> Don’t think we need both of these includes.

Change it to only including UniquedStringImpl.h.

>> Source/WTF/wtf/PrintStream.h:75
>> +inline void printInternal(PrintStream& out, const UniquedStringImpl* value) { printInternal(out, bitwise_cast<const StringImpl*>(value)); }
> 
> Can’t we just do the StringImpl* one and leave out the overloads for derived classes from StringImpl?

It raises the compile error since this is routed to the definition
template<typename T>
void printInternal(PrintStream& out, const T& value)
{
    value.dump(out);
}

To avoid it, I think we need to clean up this printInternal mechanism.
To make the patch simple I think using the current system in this patch is preferable; just adding UniquedStringImpl case such like AtomicStringImpl.

>> Source/WTF/wtf/text/AtomicStringImpl.h:24
>>  #include <wtf/text/StringImpl.h>
> 
> Should not need this include.

Fixed.

>> Source/WTF/wtf/text/AtomicStringImpl.h:35
>> +    }
> 
> Should be able to just delete all of this.

Yes, dropped.

>> Source/WTF/wtf/text/StringImpl.h:137
>> +    friend class SymbolImpl;
> 
> Alphabetic sorting please? Why would AtomicStringImpl need to be a friend any more?

This is because ~StringImpl() is private.
So I'll change these system.
1. Drop these friend classes
2. Drop these class' constructors

>> Source/WTF/wtf/text/UniquedStringImpl.h:36
>> +        : StringImpl(0)
> 
> Should be nullptr, not 0.

Dropped these constructors.
Comment 12 Yusuke Suzuki 2015-05-11 23:45:16 PDT
(In reply to comment #10)
> (In reply to comment #8)
> > We need to create UniquedString, SymbolString in addition to AtomicString...
> 
> We should not. We should just use RefPtr<UniquedStringImpl> and
> Ref<UniquedStringImpl> where we would otherwise use UniquedString. Same for
> SymbolStringImpl. Later we might rename the underlying classes to not have
> Impl in their names.

I think it would make the patch very large.
Since we cannot change AtomicString to RefPtr<UniqueStringImpl> mechanically, because at least operator== should be considered.
So I suggest the following scenario.

1. In the separate patch, use RefPtr<UniqueStringImpl> instead of AtomicString.
2. In this patch, rename AtomicString into UniquedString.
3. AtomicString table related operations should be moved from AtomicString to AtomicStringImpl. (This makes sense because these static functions return StringImpl :D)
4. And UniquedString accept UniquedStringImpl without atomization.

When StringImpl / const char*, LChar* etc. are passed to UniquedString, it will be interned. But when UniquedStringImpl* comes, it will not interned. This design is correct to the name *uniqued*. And the change becomes simple. But we can introduce UniquedStringImpl, SymbolImpl and AtomicStringImpl. And this change paves the way to drop AtomicString and use UniqueStringImpl directly.
Comment 13 Yusuke Suzuki 2015-05-12 03:45:11 PDT
(In reply to comment #12)
> (In reply to comment #10)
> > (In reply to comment #8)
> > > We need to create UniquedString, SymbolString in addition to AtomicString...
> > 
> > We should not. We should just use RefPtr<UniquedStringImpl> and
> > Ref<UniquedStringImpl> where we would otherwise use UniquedString. Same for
> > SymbolStringImpl. Later we might rename the underlying classes to not have
> > Impl in their names.
> 
> I think it would make the patch very large.
> Since we cannot change AtomicString to RefPtr<UniqueStringImpl>
> mechanically, because at least operator== should be considered.
> So I suggest the following scenario.
> 
> 1. In the separate patch, use RefPtr<UniqueStringImpl> instead of
> AtomicString.
> 2. In this patch, rename AtomicString into UniquedString.
> 3. AtomicString table related operations should be moved from AtomicString
> to AtomicStringImpl. (This makes sense because these static functions return
> StringImpl :D)
> 4. And UniquedString accept UniquedStringImpl without atomization.
> 
> When StringImpl / const char*, LChar* etc. are passed to UniquedString, it
> will be interned. But when UniquedStringImpl* comes, it will not interned.
> This design is correct to the name *uniqued*. And the change becomes simple.
> But we can introduce UniquedStringImpl, SymbolImpl and AtomicStringImpl. And
> this change paves the way to drop AtomicString and use UniqueStringImpl
> directly.

Still it requires significantly large changes.
So in this time, I just accept UniqueStringImpl in AtomicString.

As the result,

1. Now AtomicStringImpl issue is fixed. Its SymbolImpl is separated and UniquedStringImpl is introduced.
2. But AtomicString still have both symbol and atomic strings.

But I think it could be the first step to fix the things.
Comment 14 Yusuke Suzuki 2015-05-12 03:46:16 PDT
(In reply to comment #10)
> (In reply to comment #8)
> > We need to create UniquedString, SymbolString in addition to AtomicString...
> 
> We should not. We should just use RefPtr<UniquedStringImpl> and
> Ref<UniquedStringImpl> where we would otherwise use UniquedString. Same for
> SymbolStringImpl. Later we might rename the underlying classes to not have
> Impl in their names.

And how to handle WTFString and StringImpl?
Comment 15 Yusuke Suzuki 2015-05-12 04:08:52 PDT
Created attachment 252955 [details]
Patch

OSX remains
Comment 16 Yusuke Suzuki 2015-05-12 07:30:47 PDT
Created attachment 252963 [details]
Patch
Comment 17 WebKit Commit Bot 2015-05-12 07:34:05 PDT
Attachment 252963 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/text/AtomicString.h:45:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:46:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:47:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:48:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:49:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:50:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:60:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:63:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:166:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:169:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/JavaScriptCore/runtime/TypeSet.h:59:  The parameter type should use PassRefPtr instead of RefPtr.  [readability/pass_ptr] [5]
ERROR: Source/WTF/wtf/text/WTFString.h:121:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/WTFString.h:122:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/WTFString.h:123:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/JavaScriptCore/runtime/TypeSet.cpp:337:  The parameter type should use PassRefPtr instead of RefPtr.  [readability/pass_ptr] [5]
Total errors found: 15 in 91 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 18 Yusuke Suzuki 2015-05-12 07:41:49 PDT
Created attachment 252964 [details]
Patch
Comment 19 WebKit Commit Bot 2015-05-12 07:45:43 PDT
Attachment 252964 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/text/AtomicString.h:45:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:46:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:47:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:48:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:49:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:50:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:60:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:63:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:166:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:169:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/JavaScriptCore/runtime/TypeSet.h:59:  The parameter type should use PassRefPtr instead of RefPtr.  [readability/pass_ptr] [5]
ERROR: Source/WTF/wtf/text/WTFString.h:121:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/WTFString.h:122:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/WTFString.h:123:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/JavaScriptCore/runtime/TypeSet.cpp:337:  The parameter type should use PassRefPtr instead of RefPtr.  [readability/pass_ptr] [5]
Total errors found: 15 in 94 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 20 Yusuke Suzuki 2015-05-12 07:56:21 PDT
Created attachment 252965 [details]
Patch
Comment 21 WebKit Commit Bot 2015-05-12 07:59:04 PDT
Attachment 252965 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/text/AtomicString.h:45:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:46:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:47:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:48:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:49:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:50:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:60:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:63:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:166:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/AtomicString.h:169:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/JavaScriptCore/runtime/TypeSet.h:59:  The parameter type should use PassRefPtr instead of RefPtr.  [readability/pass_ptr] [5]
ERROR: Source/WTF/wtf/text/WTFString.h:121:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/WTFString.h:122:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/WTF/wtf/text/WTFString.h:123:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/JavaScriptCore/runtime/TypeSet.cpp:337:  The parameter type should use PassRefPtr instead of RefPtr.  [readability/pass_ptr] [5]
Total errors found: 15 in 94 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 22 Yusuke Suzuki 2015-05-12 08:28:01 PDT
Comment on attachment 252965 [details]
Patch

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

Added comments

> Source/WTF/wtf/text/AtomicString.h:50
> +    AtomicString(const UChar* s) : m_string(AtomicStringImpl::add(s)) { }

They are originaly written in one line. But style checker raises errors.
What do you think about it? Is it preferable to extract it such as the following?

AtomicString(const char* s)
    : m_string(add(s))
{
}

> Source/WTF/wtf/text/AtomicStringImpl.h:48
> +    }

They are renamed from `find` to `lookup`. Because C++ spec doesn't allow the static & non-static member functions that have the same signature.
StringImpl (the base class) already has non-static member function `find(StringImpl* string)`.
Comment 23 Yusuke Suzuki 2015-05-13 02:10:14 PDT
Comment on attachment 252965 [details]
Patch

Ah, ok. ready for review.
Comment 24 Yusuke Suzuki 2015-05-17 12:22:39 PDT
I'll split the AtomicStringImpl table part to the separate patch.
Comment 25 Yusuke Suzuki 2015-05-17 12:40:35 PDT
Separated issue is opened. https://bugs.webkit.org/show_bug.cgi?id=145109
Comment 26 Yusuke Suzuki 2015-05-19 21:25:19 PDT
Now, AtomicStringImpl table operation part is landed in the separate patch.
I'll rebase this patch now...
Comment 27 Yusuke Suzuki 2015-05-20 10:22:20 PDT
*** Bug 144440 has been marked as a duplicate of this bug. ***
Comment 28 Yusuke Suzuki 2015-05-20 10:24:26 PDT
Created attachment 253445 [details]
Patch
Comment 29 WebKit Commit Bot 2015-05-20 10:26:37 PDT
Attachment 253445 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/runtime/TypeSet.cpp:337:  The parameter type should use PassRefPtr instead of RefPtr.  [readability/pass_ptr] [5]
ERROR: Source/JavaScriptCore/runtime/TypeSet.h:59:  The parameter type should use PassRefPtr instead of RefPtr.  [readability/pass_ptr] [5]
Total errors found: 2 in 82 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 30 Yusuke Suzuki 2015-05-20 11:03:11 PDT
Created attachment 253448 [details]
Patch
Comment 31 Yusuke Suzuki 2015-05-20 11:04:12 PDT
OK, the patch is ready for review.
Comment 32 Darin Adler 2015-05-21 09:39:26 PDT
Comment on attachment 253448 [details]
Patch

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

Nice job.

I prefer auto or auto* or even possibly const auto* to stating the type when we just want to get something and don’t want to express an opinion about the type it should have. I don’t know if we have consensus about that, though.

> Source/JavaScriptCore/bytecode/CodeBlock.cpp:2026
> +                    UniquedStringImpl* uid = ident.impl();

I think auto is better here than naming a class. I also think it’s not helpful to put this into a local variable. I also think auto is better for the iterator type below.

> Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:453
> +        typedef HashMap<UniquedStringImpl*, GetterSetterPair, IdentifierRepHash> GetterSetterMap;

Behavior change here. Will this be a performance improvement?

> Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:-3638
> -            AtomicStringImpl* uid;
> +            UniquedStringImpl* uid = nullptr;
>              if (identifierNumber != UINT_MAX)
>                  uid = m_graph.identifiers()[identifierNumber];
> -            else
> -                uid = nullptr;

Not sure that initializing to null is an improvement. Rationale for the change?

> Source/JavaScriptCore/dfg/DFGDesiredIdentifiers.cpp:74
> +        UniquedStringImpl* rep = m_addedIdentifiers[i];

auto is better

> Source/JavaScriptCore/dfg/DFGFixupPhase.cpp:962
> +                UniquedStringImpl* uid = m_graph.identifiers()[node->identifierNumber()];

auto is better

> Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp:909
> +                static_cast<const AtomicStringImpl*>(string->tryGetValueImpl()));

Does not look good! Why is this a safe cast? I don’t see a type check. May require a comment.

> Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp:2092
> +        UniquedStringImpl* uid = m_graph.identifiers()[m_node->identifierNumber()];

auto

> Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp:4816
> +                const AtomicStringImpl* str = static_cast<const AtomicStringImpl*>(string->tryGetValueImpl());

auto

> Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp:5739
> +        UniquedStringImpl* uid = m_graph.identifiers()[m_node->identifierNumber()];

auto

> Source/JavaScriptCore/parser/Nodes.h:1565
> -        bool captures(StringImpl* uid) { return m_capturedVariables.contains(uid); }
> +        bool captures(UniquedStringImpl* uid) { return m_capturedVariables.contains(uid); }

This function won’t work on null pointers because it uses the pointer as a key in hash table functions, so it should definitely take a reference, not a pointer, in the future.

> Source/JavaScriptCore/parser/Nodes.h:1613
> +        Vector<RefPtr<UniquedStringImpl>> m_closedVariables;

Seems like this should be Vector<Ref>, not Vector<RefPtr>.

> Source/JavaScriptCore/parser/Parser.h:108
>  struct ScopeLabelInfo {
> -    ScopeLabelInfo(StringImpl* ident, bool isLoop)
> +    ScopeLabelInfo(UniquedStringImpl* ident, bool isLoop)
>          : m_ident(ident)
>          , m_isLoop(isLoop)
>      {
>      }
>  
> -    StringImpl* m_ident;
> +    UniquedStringImpl* m_ident;
>      bool m_isLoop;
>  };

Wrong coding style for structs. Data member names should not have m_ prefix. Should not have a constructor; should use ScopeLabeInfo { identifier, isLoop } syntax instead when constructing.

> Source/JavaScriptCore/parser/Parser.h:890
> +    Vector<RefPtr<UniquedStringImpl>> m_closedVariables;

Should be Vector<Ref>, not Vector<RefPtr>.

> Source/JavaScriptCore/parser/SourceProviderCacheItem.h:45
> +    Vector<RefPtr<UniquedStringImpl>> usedVariables;
> +    Vector<RefPtr<UniquedStringImpl>> writtenVariables;

Should be Vector<Ref>, not Vector<RefPtr>.

> Source/JavaScriptCore/runtime/Identifier.h:181
> +    explicit Identifier(SymbolImpl* uid)
> +        : m_string(uid)
> +    {
> +    }

Is null allowed? If not, this should change to take a SymbolImpl&.

> Source/JavaScriptCore/runtime/Identifier.h:277
> +    UniquedStringImpl* uid = identifier.impl();

auto

> Source/JavaScriptCore/runtime/IdentifierInlines.h:77
> +    return Identifier(static_cast<SymbolImpl*>(uid));

Surprised that Identifier() is needed. I would expect that just static_cast<SymbolImpl*>(uid) would work.

> Source/JavaScriptCore/runtime/IdentifierInlines.h:87
> +    return Identifier(name.uid());

Surprised that Identifier() is needed. I would expect that just name.uid() would work.

> Source/JavaScriptCore/runtime/Lookup.h:103
> +        UniquedStringImpl* uid = propertyName.uid();

auto

> Source/JavaScriptCore/runtime/ObjectConstructor.cpp:245
> +        UniquedStringImpl* impl = properties[i].impl();

auto

> Source/JavaScriptCore/runtime/PrivateName.h:40
> +    explicit PrivateName(SymbolImpl* uid)

If null is not allowed, this should be a reference, not a pointer.

> Source/JavaScriptCore/runtime/PropertyName.h:37
> +    PropertyName(UniquedStringImpl* propertyName)

If null is not allowed, this should be a reference, not a pointer.

> Source/JavaScriptCore/runtime/PropertyName.h:118
> +    UniquedStringImpl* uid = propertyName.uid();

auto

> Source/JavaScriptCore/runtime/PropertyNameArray.h:72
> +    void add(UniquedStringImpl*);
> +    void addKnownUnique(UniquedStringImpl*);

Null is not allowed, so these arguments should be reference, not pointers.

> Source/JavaScriptCore/runtime/Structure.cpp:885
> +    UniquedStringImpl* rep = propertyName.uid();

auto

> Source/JavaScriptCore/runtime/Structure.cpp:904
> +    UniquedStringImpl* rep = propertyName.uid();

auto

> Source/JavaScriptCore/runtime/Structure.h:51
> -#include <wtf/text/AtomicStringImpl.h>
> +#include <wtf/text/UniquedStringImpl.h>

Does this file really require including that header? Would a forward declaration suffice? I don’t see code below actually operating on these objects, just moving pointers around.

> Source/JavaScriptCore/runtime/StructureTransitionTable.h:134
>      inline void add(VM&, Structure*);
> -    inline bool contains(AtomicStringImpl* rep, unsigned attributes) const;
> -    inline Structure* get(AtomicStringImpl* rep, unsigned attributes) const;
> +    inline bool contains(UniquedStringImpl* rep, unsigned attributes) const;
> +    inline Structure* get(UniquedStringImpl* rep, unsigned attributes) const;

inline here has no effect and should be removed. Argument name "rep" adds nothing. Arguments should probably be reference not pointer.

> Source/JavaScriptCore/runtime/SymbolConstructor.cpp:112
> +    Ref<SymbolImpl> uid = exec->vm().symbolRegistry().symbolForKey(string);
> +    return JSValue::encode(Symbol::create(exec->vm(), &uid.get()));

Would read better as a one-liner.

> Source/JavaScriptCore/runtime/TypeSet.cpp:353
> +    for (auto key : m_fields) {

Should be auto&, not auto.

> Source/JavaScriptCore/runtime/TypeSet.h:59
> +    void addProperty(Ref<UniquedStringImpl>);

Wrong type here. This should just be UniquedStringImpl& or Ref&&; we get no value out of requiring the caller to pass in a Ref.

> Source/WTF/wtf/text/AtomicString.h:63
> +    // FIXME: AtomicString may have either SymbolImpl or AtomicStringImpl.

That FIXME is unclear. I would write:

    // FIXME: AtomicString doesn’t always have AtomicStringImpl, so one of those two names needs to change.

> Source/WTF/wtf/text/StringImpl.cpp:118
> +        symbolRegistry()->remove(*static_cast<SymbolImpl*>(this));

I would write static_cast<SymbolImpl&)(*this)

> Source/WTF/wtf/text/SymbolImpl.h:29
> +#include <wtf/text/StringImpl.h>

No reason for this include. Please don’t do it.

> Source/WTF/wtf/text/SymbolImpl.h:34
> +class SymbolImpl : public UniquedStringImpl {

Needs a comment to explain what this class is for and how it differs from AtomicStringImpl.

> Source/WTF/wtf/text/SymbolImpl.h:54
> +#if !ASSERT_DISABLED
> +// SymbolImpls created from StaticASCIILiteral will ASSERT
> +// in the generic ValueCheck<T>::checkConsistency
> +// as they are not allocated by fastMalloc.
> +// We don't currently have any way to detect that case
> +// so we ignore the consistency check for all SymbolImpls*.
> +template<> struct
> +ValueCheck<SymbolImpl*> {
> +    static void checkConsistency(const SymbolImpl*) { }
> +};
> +
> +template<> struct
> +ValueCheck<const SymbolImpl*> {
> +    static void checkConsistency(const SymbolImpl*) { }
> +};
> +#endif

Annoying that we are cut and pasted this code into three different header files. Would be good to find a nicer way to do this later.

> Source/WTF/wtf/text/SymbolRegistry.h:86
> +    WTF_EXPORT_PRIVATE String keyForSymbol(SymbolImpl& uid);

Argument name should be omitted here.

> Source/WTF/wtf/text/SymbolRegistry.h:88
> +    void remove(SymbolImpl& uid);

Argument name should be omitted here.

> Source/WTF/wtf/text/UniquedStringImpl.h:33
> +class UniquedStringImpl : public StringImpl {

Needs a comment to explain what this class is for and how it differs from StringImpl.

> Source/WebCore/bindings/js/JSDOMWindowCustom.cpp:309
> +        ASSERT(!propertyName.isSymbol());

What guarantees this? Comment needs to say why we think this will be true.

> Source/WebCore/bindings/js/JSDOMWindowCustom.cpp:310
> +        AtomicStringImpl* atomicPropertyName = static_cast<AtomicStringImpl*>(propertyName.impl());

auto
Comment 33 Yusuke Suzuki 2015-05-23 11:28:16 PDT
Comment on attachment 253448 [details]
Patch

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

Thank you.
Almost all comments are fixed. But I think changing RefPtr => Ref should be done in a separate patch because it involves too much code fix since it involves IdentifierSet etc.
In the separate patch, we should consider about storing Ref to hash maps instead of RefPtr.

>> Source/JavaScriptCore/bytecode/CodeBlock.cpp:2026
>> +                    UniquedStringImpl* uid = ident.impl();
> 
> I think auto is better here than naming a class. I also think it’s not helpful to put this into a local variable. I also think auto is better for the iterator type below.

OK, here, just use `ident.impl()` directly.

>> Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:453
>> +        typedef HashMap<UniquedStringImpl*, GetterSetterPair, IdentifierRepHash> GetterSetterMap;
> 
> Behavior change here. Will this be a performance improvement?

Yeah. This should improve performance because this map doesn't check the content of the StringImpl*.
It just checks the pointer values.

>> Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:-3638
>> -                uid = nullptr;
> 
> Not sure that initializing to null is an improvement. Rationale for the change?

Personally, uninitialized local variable is not good I think.
But in this time, it's not important for this patch. So just using the previous code.

>> Source/JavaScriptCore/dfg/DFGDesiredIdentifiers.cpp:74
>> +        UniquedStringImpl* rep = m_addedIdentifiers[i];
> 
> auto is better

OK, use `auto`.

>> Source/JavaScriptCore/dfg/DFGFixupPhase.cpp:962
>> +                UniquedStringImpl* uid = m_graph.identifiers()[node->identifierNumber()];
> 
> auto is better

Fixed.

>> Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp:909
>> +                static_cast<const AtomicStringImpl*>(string->tryGetValueImpl()));
> 
> Does not look good! Why is this a safe cast? I don’t see a type check. May require a comment.

This path is checked with the if statement. `if (string->tryGetValueImpl() && string->tryGetValueImpl()->isAtomic()) {`.
So when reaching here, it is guaranteed that the result of `string->tryGetValueImpl()` is always `AtomicStringImpl*`.
OK, I've added comment.

>> Source/JavaScriptCore/parser/Nodes.h:1565
>> +        bool captures(UniquedStringImpl* uid) { return m_capturedVariables.contains(uid); }
> 
> This function won’t work on null pointers because it uses the pointer as a key in hash table functions, so it should definitely take a reference, not a pointer, in the future.

I think it is better to fix these things in the separate patch because it involves so many changes across the code.

>> Source/JavaScriptCore/parser/Nodes.h:1613
>> +        Vector<RefPtr<UniquedStringImpl>> m_closedVariables;
> 
> Seems like this should be Vector<Ref>, not Vector<RefPtr>.

ditto. At that time, we should consider about storing Ref<UniquedStringImpl> in hash tables.

>> Source/JavaScriptCore/parser/Parser.h:108
>>  };
> 
> Wrong coding style for structs. Data member names should not have m_ prefix. Should not have a constructor; should use ScopeLabeInfo { identifier, isLoop } syntax instead when constructing.

Fixed.

>> Source/JavaScriptCore/parser/Parser.h:890
>> +    Vector<RefPtr<UniquedStringImpl>> m_closedVariables;
> 
> Should be Vector<Ref>, not Vector<RefPtr>.

Ditto. This involves all IdentifierSet changes.

>> Source/JavaScriptCore/parser/SourceProviderCacheItem.h:45
>> +    Vector<RefPtr<UniquedStringImpl>> writtenVariables;
> 
> Should be Vector<Ref>, not Vector<RefPtr>.

ditto.

>> Source/JavaScriptCore/runtime/Identifier.h:181
>> +    }
> 
> Is null allowed? If not, this should change to take a SymbolImpl&.

Nice catch. Fixed.

>> Source/JavaScriptCore/runtime/Identifier.h:277
>> +    UniquedStringImpl* uid = identifier.impl();
> 
> auto

Fixed.

>> Source/JavaScriptCore/runtime/IdentifierInlines.h:77
>> +    return Identifier(static_cast<SymbolImpl*>(uid));
> 
> Surprised that Identifier() is needed. I would expect that just static_cast<SymbolImpl*>(uid) would work.

OK, dropping `explicit` in private Identifier(SymbolImpl&).

>> Source/JavaScriptCore/runtime/IdentifierInlines.h:87
>> +    return Identifier(name.uid());
> 
> Surprised that Identifier() is needed. I would expect that just name.uid() would work.

Fixed.

>> Source/JavaScriptCore/runtime/Lookup.h:103
>> +        UniquedStringImpl* uid = propertyName.uid();
> 
> auto

Done.

>> Source/JavaScriptCore/runtime/ObjectConstructor.cpp:245
>> +        UniquedStringImpl* impl = properties[i].impl();
> 
> auto

Done.

>> Source/JavaScriptCore/runtime/PrivateName.h:40
>> +    explicit PrivateName(SymbolImpl* uid)
> 
> If null is not allowed, this should be a reference, not a pointer.

Changed it to SymbolImpl&.

>> Source/JavaScriptCore/runtime/PropertyName.h:37
>> +    PropertyName(UniquedStringImpl* propertyName)
> 
> If null is not allowed, this should be a reference, not a pointer.

Here, since it involves too much code change, changing it in this patch is not good I think.
I'll fix it in the separate patch.

>> Source/JavaScriptCore/runtime/PropertyName.h:118
>> +    UniquedStringImpl* uid = propertyName.uid();
> 
> auto

Fixed.

>> Source/JavaScriptCore/runtime/PropertyNameArray.h:72
>> +    void addKnownUnique(UniquedStringImpl*);
> 
> Null is not allowed, so these arguments should be reference, not pointers.

Ditto.

>> Source/JavaScriptCore/runtime/Structure.cpp:885
>> +    UniquedStringImpl* rep = propertyName.uid();
> 
> auto

Fixed.

>> Source/JavaScriptCore/runtime/Structure.cpp:904
>> +    UniquedStringImpl* rep = propertyName.uid();
> 
> auto

Fixed.

>> Source/JavaScriptCore/runtime/Structure.h:51
>> +#include <wtf/text/UniquedStringImpl.h>
> 
> Does this file really require including that header? Would a forward declaration suffice? I don’t see code below actually operating on these objects, just moving pointers around.

Changed it to forward declaration.

>> Source/JavaScriptCore/runtime/StructureTransitionTable.h:134
>> +    inline Structure* get(UniquedStringImpl* rep, unsigned attributes) const;
> 
> inline here has no effect and should be removed. Argument name "rep" adds nothing. Arguments should probably be reference not pointer.

Yeah, that's reasonable. Dropped inline and `rep`. And dropped `inline` in Structure.cpp.

>> Source/JavaScriptCore/runtime/SymbolConstructor.cpp:112
>> +    return JSValue::encode(Symbol::create(exec->vm(), &uid.get()));
> 
> Would read better as a one-liner.

Fixed.

>> Source/JavaScriptCore/runtime/TypeSet.cpp:353
>> +    for (auto key : m_fields) {
> 
> Should be auto&, not auto.

Oops, thank you!

>> Source/JavaScriptCore/runtime/TypeSet.h:59
>> +    void addProperty(Ref<UniquedStringImpl>);
> 
> Wrong type here. This should just be UniquedStringImpl& or Ref&&; we get no value out of requiring the caller to pass in a Ref.

Fixed!

>> Source/WTF/wtf/text/AtomicString.h:63
>> +    // FIXME: AtomicString may have either SymbolImpl or AtomicStringImpl.
> 
> That FIXME is unclear. I would write:
> 
>     // FIXME: AtomicString doesn’t always have AtomicStringImpl, so one of those two names needs to change.

Looks very nice. Changed.

>> Source/WTF/wtf/text/StringImpl.cpp:118
>> +        symbolRegistry()->remove(*static_cast<SymbolImpl*>(this));
> 
> I would write static_cast<SymbolImpl&)(*this)

Fixed.

>> Source/WTF/wtf/text/SymbolImpl.h:29
>> +#include <wtf/text/StringImpl.h>
> 
> No reason for this include. Please don’t do it.

Oops. Dropped.

>> Source/WTF/wtf/text/SymbolImpl.h:34
>> +class SymbolImpl : public UniquedStringImpl {
> 
> Needs a comment to explain what this class is for and how it differs from AtomicStringImpl.

Added comment.

>> Source/WTF/wtf/text/SymbolImpl.h:54
>> +#endif
> 
> Annoying that we are cut and pasted this code into three different header files. Would be good to find a nicer way to do this later.

Yeah, something like StringHasher.h is needed for these traits.

>> Source/WTF/wtf/text/SymbolRegistry.h:86
>> +    WTF_EXPORT_PRIVATE String keyForSymbol(SymbolImpl& uid);
> 
> Argument name should be omitted here.

Fixed.

>> Source/WTF/wtf/text/SymbolRegistry.h:88
>> +    void remove(SymbolImpl& uid);
> 
> Argument name should be omitted here.

Fixed.

>> Source/WTF/wtf/text/UniquedStringImpl.h:33
>> +class UniquedStringImpl : public StringImpl {
> 
> Needs a comment to explain what this class is for and how it differs from StringImpl.

Added comment.

>> Source/WebCore/bindings/js/JSDOMWindowCustom.cpp:309
>> +        ASSERT(!propertyName.isSymbol());
> 
> What guarantees this? Comment needs to say why we think this will be true.

This propertyName is generated from `Identifier::from`. This function generates Identifier from String and it always returns non-symbol Identifier.

>> Source/WebCore/bindings/js/JSDOMWindowCustom.cpp:310
>> +        AtomicStringImpl* atomicPropertyName = static_cast<AtomicStringImpl*>(propertyName.impl());
> 
> auto

Fixed.
Comment 34 Yusuke Suzuki 2015-05-23 11:42:13 PDT
Committed r184828: <http://trac.webkit.org/changeset/184828>