Bug 141257 - Web Inspector: ES6: Better support for Symbol types in Type Profiler
Summary: Web Inspector: ES6: Better support for Symbol types in Type Profiler
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Saam Barati
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-02-04 12:41 PST by Joseph Pecoraro
Modified: 2015-03-28 10:29 PDT (History)
9 users (show)

See Also:


Attachments
WIP (12.23 KB, patch)
2015-03-11 21:09 PDT, Saam Barati
no flags Details | Formatted Diff | Diff
patch (17.18 KB, patch)
2015-03-12 15:53 PDT, Saam Barati
joepeck: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 2015-02-04 12:41:22 PST
* SUMMARY
We should better support for Symbol types in Type Profiler. Symbols are pseudo-primitives, like unique strings. I would expect them to be handled similar to Strings in the Type profiling.

* TEST
<script>
function foo(a) {
  console.log(a);
}
</script>

js> foo(Symbol()); // I expect "Symbol" to show up next to foo's `a` param.
js> foo(1); // I expect "(many)" to show up next to foo's `a` param. Popover should have "Integer" and "Symbol".

* NOTES
- Symbol has some special properties. But it is more like a primitive than an object.
Comment 1 Radar WebKit Bug Importer 2015-02-04 12:41:38 PST
<rdar://problem/19719214>
Comment 2 Saam Barati 2015-03-11 21:09:55 PDT
Created attachment 248484 [details]
WIP

it begins
Comment 3 Joseph Pecoraro 2015-03-11 21:58:07 PDT
Comment on attachment 248484 [details]
WIP

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

Yeah, this looks good!

> Source/JavaScriptCore/runtime/TypeSet.cpp:77
> +    if (structure && newShape && (type & (TypeString | TypeSymbol) == TypeNothing)) {

Why are String|Symbol special but boolean and number aren't?

> Source/JavaScriptCore/runtime/TypeSet.cpp:139
> +    if (m_seenTypes & TypeSymbol)
> +         seen.append("Symbol ");

These can all be appendLiteral.
Comment 4 Saam Barati 2015-03-12 00:37:02 PDT
Comment on attachment 248484 [details]
WIP

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

Just checked out my local build. Looks like this patch works. Gonna run the tests I have now to make sure they work and also write a few more.

>> Source/JavaScriptCore/runtime/TypeSet.cpp:77
>> +    if (structure && newShape && (type & (TypeString | TypeSymbol) == TypeNothing)) {
> 
> Why are String|Symbol special but boolean and number aren't?

Because Symbol and String are the two primitives that are also JSCells.
It may be worth writing a function that checks if a RuntimeType bit mask is a primitive, something like:
bool isPrimitive(uint16_t types) { return types & ~(TypeFunction | TypeObject) }
and the above line can just be
... && !isPrimitive(type)
Comment 5 Saam Barati 2015-03-12 15:53:35 PDT
Created attachment 248549 [details]
patch
Comment 6 Joseph Pecoraro 2015-03-12 20:20:31 PDT
Comment on attachment 248549 [details]
patch

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

Nice! r=me, some nits you can choose to fix if you want to.

> Source/JavaScriptCore/dfg/DFGFixupPhase.cpp:1183
> -            uint8_t seenTypes = typeSet->seenTypes();
> +            uint16_t seenTypes = typeSet->seenTypes();

Instead of "uint16_t" can this just be "RuntimeType"?

> Source/JavaScriptCore/runtime/TypeSet.cpp:2
> - * Copyright (C) 2008, 2014 Apple Inc. All Rights Reserved.
> + * Copyright (C) 2014, 2015 Apple Inc. All Rights Reserved.

lol

> Source/JavaScriptCore/runtime/TypeSet.cpp:123
> +        seen.append("Function ");

Since you're updating each of these lines anyways, these should be "appendLiteral" instead of just "append".

> Source/JavaScriptCore/runtime/TypeSet.cpp:164
> -bool TypeSet::doesTypeConformTo(uint8_t test) const
> +bool TypeSet::doesTypeConformTo(uint16_t test) const

Instead of "uint16_t" can this just be "RuntimeType"?

> Source/JavaScriptCore/runtime/TypeSet.cpp:327
> +            json.append(",");

Nit: All of these appends with 1 character can/should be append(',').

> Source/JavaScriptCore/runtime/TypeSet.cpp:329
> +        json.append("\"Symbol\"");

Nit: This can/should be appendLiteral.

> Source/JavaScriptCore/runtime/TypeSet.h:113
> +    bool doesTypeConformTo(uint16_t test) const;
> +    uint16_t seenTypes() const { return m_seenTypes; }

Same here about "uint16_t" <=> "RuntimeType"?

> Source/JavaScriptCore/runtime/TypeSet.h:117
> +    uint16_t m_seenTypes;

Same here about "uint16_t" <=> "RuntimeType"?
Comment 7 Saam Barati 2015-03-28 10:29:27 PDT
landed in:
http://trac.webkit.org/changeset/182114