Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: test/mjsunit/es6/tail-call-simple.js

Issue 1760253003: [crankshaft] Support ES6 tail call elimination. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@tco-crank-2
Patch Set: Addressing comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/mjsunit/es6/tail-call-megatest.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --allow-natives-syntax --harmony-tailcalls --stack-size=100 5 // Flags: --allow-natives-syntax --harmony-tailcalls --stack-size=100
6 // TODO(v8:4698), TODO(ishell): support these cases.
7 // Flags: --no-turbo --nostress-opt
6 8
7 // 9 //
8 // Tail calls work only in strict mode. 10 // Tail calls work only in strict mode.
9 // 11 //
10 (function() { 12 (function() {
11 function f(n) { 13 function f(n) {
12 if (n <= 0) { 14 if (n <= 0) {
13 return "foo"; 15 return "foo";
14 } 16 }
15 return f(n - 1); 17 return f(n - 1);
16 } 18 }
17 assertThrows(()=>{ f(1e5) }); 19 assertThrows(()=>{ f(1e5) });
18 %OptimizeFunctionOnNextCall(f); 20 %OptimizeFunctionOnNextCall(f);
19 assertThrows(()=>{ f(1e5) }); 21 assertThrows(()=>{ f(1e5) });
20 })(); 22 })();
21 23
22 24
23 // 25 //
24 // Tail call normal functions. 26 // Tail call normal functions.
25 // 27 //
26 (function() { 28 (function() {
27 "use strict"; 29 "use strict";
28 function f(n) { 30 function f(n) {
29 if (n <= 0) { 31 if (n <= 0) {
30 return "foo"; 32 return "foo";
31 } 33 }
32 return f(n - 1); 34 return f(n - 1);
33 } 35 }
34 assertEquals("foo", f(1e5)); 36 assertEquals("foo", f(1e5));
35 %OptimizeFunctionOnNextCall(f); 37 %OptimizeFunctionOnNextCall(f);
36 assertEquals("foo", f(1e5)); 38 assertEquals("foo", f(1e5));
37 })(); 39 })();
38 40
39 41
40 (function() { 42 (function() {
41 "use strict"; 43 "use strict";
44 function f(n) {
45 if (n <= 0) {
46 return "foo";
47 }
48 return f(n - 1, 42); // Call with arguments adaptor.
49 }
50 assertEquals("foo", f(1e5));
51 %OptimizeFunctionOnNextCall(f);
52 assertEquals("foo", f(1e5));
53 })();
54
55
56 (function() {
57 "use strict";
42 function f(n){ 58 function f(n){
43 if (n <= 0) { 59 if (n <= 0) {
44 return "foo"; 60 return "foo";
45 } 61 }
46 return g(n - 1); 62 return g(n - 1);
47 } 63 }
48 function g(n){ 64 function g(n){
49 if (n <= 0) { 65 if (n <= 0) {
50 return "bar"; 66 return "bar";
51 } 67 }
52 return f(n - 1); 68 return f(n - 1);
53 } 69 }
54 assertEquals("foo", f(1e5)); 70 assertEquals("foo", f(1e5));
55 assertEquals("bar", f(1e5 + 1)); 71 assertEquals("bar", f(1e5 + 1));
56 %OptimizeFunctionOnNextCall(f); 72 %OptimizeFunctionOnNextCall(f);
57 assertEquals("foo", f(1e5)); 73 assertEquals("foo", f(1e5));
58 assertEquals("bar", f(1e5 + 1)); 74 assertEquals("bar", f(1e5 + 1));
59 })(); 75 })();
60 76
61 77
78 (function() {
79 "use strict";
80 function f(n){
81 if (n <= 0) {
82 return "foo";
83 }
84 return g(n - 1, 42); // Call with arguments adaptor.
85 }
86 function g(n){
87 if (n <= 0) {
88 return "bar";
89 }
90 return f(n - 1, 42); // Call with arguments adaptor.
91 }
92 assertEquals("foo", f(1e5));
93 assertEquals("bar", f(1e5 + 1));
94 %OptimizeFunctionOnNextCall(f);
95 assertEquals("foo", f(1e5));
96 assertEquals("bar", f(1e5 + 1));
97 })();
98
99
62 // 100 //
63 // Tail call bound functions. 101 // Tail call bound functions.
64 // 102 //
65 (function() { 103 (function() {
66 "use strict"; 104 "use strict";
67 function f0(n) { 105 function f0(n) {
68 if (n <= 0) { 106 if (n <= 0) {
69 return "foo"; 107 return "foo";
70 } 108 }
71 return f_bound(n - 1); 109 return f_bound(n - 1);
(...skipping 26 matching lines...) Expand all
98 var g_bound = g0.bind({}); 136 var g_bound = g0.bind({});
99 function f(n) { 137 function f(n) {
100 return f_bound(n); 138 return f_bound(n);
101 } 139 }
102 assertEquals("foo", f(1e5)); 140 assertEquals("foo", f(1e5));
103 assertEquals("bar", f(1e5 + 1)); 141 assertEquals("bar", f(1e5 + 1));
104 %OptimizeFunctionOnNextCall(f); 142 %OptimizeFunctionOnNextCall(f);
105 assertEquals("foo", f(1e5)); 143 assertEquals("foo", f(1e5));
106 assertEquals("bar", f(1e5 + 1)); 144 assertEquals("bar", f(1e5 + 1));
107 })(); 145 })();
OLDNEW
« no previous file with comments | « test/mjsunit/es6/tail-call-megatest.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698