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

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

Issue 1709583002: [turbofan] Fixing ES6 tail calls in Turbofan. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressing comments Created 4 years, 10 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.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
(Empty)
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
3 // found in the LICENSE file.
4
5 // Flags: --allow-natives-syntax --harmony-tailcalls --no-turbo-inlining
6
7 "use strict";
8
9 Error.prepareStackTrace = (error,stack) => {
10 error.strace = stack;
11 return error.message + "\n at " + stack.join("\n at ");
12 }
13
14
15 function CheckStackTrace(expected) {
16 var e = new Error();
17 e.stack; // prepare stack trace
18 var stack = e.strace;
19 assertEquals("CheckStackTrace", stack[0].getFunctionName());
20 for (var i = 0; i < expected.length; i++) {
21 assertEquals(expected[i].name, stack[i + 1].getFunctionName());
22 }
23 // Don't inline. Don't inline. Don't inline. Don't inline.
24 // Don't inline. Don't inline. Don't inline. Don't inline.
25 // Don't inline. Don't inline. Don't inline. Don't inline.
26 // Don't inline. Don't inline. Don't inline. Don't inline.
27 // Don't inline. Don't inline. Don't inline. Don't inline.
28 // Don't inline. Don't inline. Don't inline. Don't inline.
29 // Don't inline. Don't inline. Don't inline. Don't inline.
30 // Don't inline. Don't inline. Don't inline. Don't inline.
31 // Don't inline. Don't inline. Don't inline. Don't inline.
32 // Don't inline. Don't inline. Don't inline. Don't inline.
33 // Don't inline. Don't inline. Don't inline. Don't inline.
34 // Don't inline. Don't inline. Don't inline. Don't inline.
35 // Don't inline. Don't inline. Don't inline. Don't inline.
36 // Don't inline. Don't inline. Don't inline. Don't inline.
37 // Don't inline. Don't inline. Don't inline. Don't inline.
38 // Don't inline. Don't inline. Don't inline. Don't inline.
Jarin 2016/02/18 09:08:08 Could not you use %NeverOptimizeFunction to preven
Igor Sheludko 2016/02/18 09:30:11 Good point. For utility functions it makes sense,
39 }
40
41 function CheckArguments(expected, args) {
42 args = Array.prototype.slice.call(args);
43 assertEquals(expected, args);
44 // Don't inline. Don't inline. Don't inline. Don't inline.
45 // Don't inline. Don't inline. Don't inline. Don't inline.
46 // Don't inline. Don't inline. Don't inline. Don't inline.
47 // Don't inline. Don't inline. Don't inline. Don't inline.
48 // Don't inline. Don't inline. Don't inline. Don't inline.
49 // Don't inline. Don't inline. Don't inline. Don't inline.
50 // Don't inline. Don't inline. Don't inline. Don't inline.
51 // Don't inline. Don't inline. Don't inline. Don't inline.
52 // Don't inline. Don't inline. Don't inline. Don't inline.
53 // Don't inline. Don't inline. Don't inline. Don't inline.
54 // Don't inline. Don't inline. Don't inline. Don't inline.
55 // Don't inline. Don't inline. Don't inline. Don't inline.
56 // Don't inline. Don't inline. Don't inline. Don't inline.
57 // Don't inline. Don't inline. Don't inline. Don't inline.
58 // Don't inline. Don't inline. Don't inline. Don't inline.
59 // Don't inline. Don't inline. Don't inline. Don't inline.
60 }
61
62
63 var CAN_INLINE_COMMENT = "// Let it be inlined.";
64 var DONT_INLINE_COMMENT = (function() {
65 var line = "// Don't inline. Don't inline. Don't inline. Don't inline.";
66 for (var i = 0; i < 4; i++) {
67 line += "\n " + line;
68 }
69 return line;
70 })();
71
72
73 function ident_source(source, ident) {
74 ident = " ".repeat(ident);
75 return ident + source.replace(/\n/gi, "\n" + ident);
76 }
77
78
79 function run_tests() {
80
81 function f_template_normal(f_inlinable, f_args) {
82 var f_comment = f_inlinable ? CAN_INLINE_COMMENT : DONT_INLINE_COMMENT;
83 var lines = [
84 `function f(a) {`,
85 ` ${f_comment}`,
86 ` assertEquals(undefined, this);`,
87 ` CheckArguments([${f_args}], arguments);`,
88 ` CheckStackTrace([f, test]);`,
89 ` %DeoptimizeNow();`,
90 ` CheckArguments([${f_args}], arguments);`,
91 ` CheckStackTrace([f, test]);`,
92 ` return 42;`,
93 `}`,
94 ];
95 return lines.join("\n");
96 }
97
98 function f_template_bound(f_inlinable, f_args) {
99 var f_comment = f_inlinable ? CAN_INLINE_COMMENT : DONT_INLINE_COMMENT;
100 var lines = [
101 `function ff(a) {`,
102 ` ${f_comment}`,
103 ` assertEquals(153, this.a);`,
104 ` CheckArguments([${f_args}], arguments);`,
105 ` CheckStackTrace([ff, test]);`,
106 ` %DeoptimizeNow();`,
107 ` CheckArguments([${f_args}], arguments);`,
108 ` CheckStackTrace([ff, test]);`,
109 ` return 42;`,
110 `}`,
111 `var f = ff.bind({a: 153});`,
112 ];
113 return lines.join("\n");
114 }
115
116 function f_template_proxy(f_inlinable, f_args) {
117 var f_comment = f_inlinable ? CAN_INLINE_COMMENT : DONT_INLINE_COMMENT;
118 var lines = [
119 `function ff(a) {`,
120 ` ${f_comment}`,
121 ` assertEquals(undefined, this);`,
122 ` CheckArguments([${f_args}], arguments);`,
123 ` CheckStackTrace([f, test]);`,
124 ` %DeoptimizeNow();`,
125 ` CheckArguments([${f_args}], arguments);`,
126 ` CheckStackTrace([f, test]);`,
127 ` return 42;`,
128 `}`,
129 `var f = new Proxy(ff, {});`,
130 ];
131 return lines.join("\n");
132 }
133
134 function g_template(g_inlinable, f_args, g_args) {
135 var g_comment = g_inlinable ? CAN_INLINE_COMMENT : DONT_INLINE_COMMENT;
136 var lines = [
137 `function g(a) {`,
138 ` ${g_comment}`,
139 ` CheckArguments([${g_args}], arguments);`,
140 ` return f(${f_args});`,
141 `}`,
142 ];
143 return lines.join("\n");
144 }
145
146 function test_template(f_source, g_source, g_args,
147 f_inlinable, g_inlinable) {
148 f_source = ident_source(f_source, 2);
149 g_source = ident_source(g_source, 2);
150
151 var lines = [
152 `(function() {`,
153 f_source,
154 g_source,
155 ` function test() {`,
156 ` assertEquals(42, g(${g_args}));`,
157 ` }`,
158 ` ${f_inlinable ? "%SetForceInlineFlag(f)" : ""};`,
159 ` ${g_inlinable ? "%SetForceInlineFlag(g)" : ""};`,
160 ``,
161 ` test();`,
162 ` %OptimizeFunctionOnNextCall(test);`,
163 ` try { %OptimizeFunctionOnNextCall(f); } catch(e) {}`,
164 ` try { %OptimizeFunctionOnNextCall(ff); } catch(e) {}`,
165 ` %OptimizeFunctionOnNextCall(g);`,
166 ` test();`,
167 `})();`,
168 ``,
169 ];
170 var source = lines.join("\n");
171 return source;
172 }
173
174 // TODO(v8:4698), TODO(ishell): support all commented cases.
175 var f_args_variants = ["", "1", "1, 2"];
176 var g_args_variants = [/*"",*/ "10", /*"10, 20"*/];
177 var f_inlinable_variants = [/*true,*/ false];
178 var g_inlinable_variants = [true, false];
179 var f_variants = [
180 f_template_normal,
181 f_template_bound,
182 f_template_proxy
183 ];
184
185 f_variants.forEach((f_template) => {
186 f_args_variants.forEach((f_args) => {
187 g_args_variants.forEach((g_args) => {
188 f_inlinable_variants.forEach((f_inlinable) => {
189 g_inlinable_variants.forEach((g_inlinable) => {
190 var f_source = f_template(f_inlinable, f_args);
191 var g_source = g_template(g_inlinable, f_args, g_args);
192 var source = test_template(f_source, g_source, g_args,
193 f_inlinable, g_inlinable);
194 print("====================");
195 print(source);
196 eval(source);
197 });
198 });
199 });
200 });
201 });
202 }
203
204 run_tests();
OLDNEW
« no previous file with comments | « test/mjsunit/es6/tail-call.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698