Bug 154639

Summary: [ES6] Arrow function. Some not used byte code is emited
Product: WebKit Reporter: GSkachkov <gskachkov>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, keith_miller, mark.lam, msaboff, saam
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 140855    
Attachments:
Description Flags
Patch
none
Patch none

Description GSkachkov 2016-02-24 04:10:51 PST
During checking arrow function I found that some unused byte code is emited:
for instance for:
var f2 = function () { return ()=>'test';}; 
f2()(); 
was generated:
....
f2#DrpDJu:[0x10de8f840->0x10de76f40, NoneFunctionCall, 20]: 20 m_instructions; 160 bytes; 1 parameter(s); 8 callee register(s); 7 variable(s)
[   0] enter             
[   1] get_scope         loc3
[   3] mov               loc4, loc3
[   6] create_lexical_environment loc5, loc3, Cell: 0x10de3bdd0 (0x10de27600:[SymbolTable, {}, NonArray, Leaf]), ID: 20(const0), Undefined(const1) // Not used create_lexical_environment byte code
[  11] mov               loc3, loc5
[  14] op_new_arrow_func_exp loc7, loc3, f0
[  18] ret               loc7

Constants:
   k0 = Cell: 0x10de3bdd0 (0x10de27600:[SymbolTable, {}, NonArray, Leaf]), ID: 20
   k1 = Undefined

#An0cos:[0x10de8f620->0x10de76e00, NoneFunctionCall, 10]: 10 m_instructions; 80 bytes; 1 parameter(s); 8 callee register(s); 6 variable(s)
[   0] enter             
[   1] get_scope         loc3
[   3] mov               loc4, loc3
[   6] ret               String (atomic) (identifier): test, ID: 4(const1)
[   8] ret               Undefined(const2) // Not used byte code
Comment 1 GSkachkov 2016-02-26 11:49:13 PST
Also TDZ is emited for 'this' in arrow function that is invoked in class method
Comment 2 GSkachkov 2016-03-01 00:19:18 PST
Created attachment 272552 [details]
Patch

Patch comming
Comment 3 GSkachkov 2016-03-01 09:17:25 PST
(In reply to comment #1)
> Also TDZ is emited for 'this' in arrow function that is invoked in class
> method

I've checked and seems that this TDZ is not related to the arrow function. It always add when we're accessing to the 'superProperty'
Comment 4 GSkachkov 2016-03-01 11:36:25 PST
Created attachment 272579 [details]
Patch

Fix typo
Comment 5 Saam Barati 2016-03-01 12:03:17 PST
Comment on attachment 272579 [details]
Patch

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

> Source/JavaScriptCore/ChangeLog:13
> +        1.create_lexical_environment not emited always for arrow function, only if some of 
> +        features(this/super/arguments/eval) is used inside of the arrow function. 
> +        2.load 'this' from arrow function scope in constructor is done only if super 
> +        contains in arrow function 

Nice!
Comment 6 WebKit Commit Bot 2016-03-01 13:28:38 PST
Comment on attachment 272579 [details]
Patch

Clearing flags on attachment: 272579

Committed r197410: <http://trac.webkit.org/changeset/197410>
Comment 7 WebKit Commit Bot 2016-03-01 13:28:42 PST
All reviewed patches have been landed.  Closing bug.