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

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 }
24 %NeverOptimizeFunction(CheckStackTrace);
25
26
27 function CheckArguments(expected, args) {
28 args = Array.prototype.slice.call(args);
29 assertEquals(expected, args);
30 }
31 %NeverOptimizeFunction(CheckArguments);
32
33
34 var CAN_INLINE_COMMENT = "// Let it be inlined.";
35 var DONT_INLINE_COMMENT = (function() {
36 var line = "// Don't inline. Don't inline. Don't inline. Don't inline.";
37 for (var i = 0; i < 4; i++) {
38 line += "\n " + line;
39 }
40 return line;
41 })();
42
43
44 function ident_source(source, ident) {
45 ident = " ".repeat(ident);
46 return ident + source.replace(/\n/gi, "\n" + ident);
47 }
48
49
50 function run_tests() {
51
52 function f_template_normal(f_inlinable, f_args) {
53 var f_comment = f_inlinable ? CAN_INLINE_COMMENT : DONT_INLINE_COMMENT;
54 var lines = [
55 `function f(a) {`,
56 ` ${f_comment}`,
57 ` assertEquals(undefined, this);`,
58 ` CheckArguments([${f_args}], arguments);`,
59 ` CheckStackTrace([f, test]);`,
60 ` %DeoptimizeNow();`,
61 ` CheckArguments([${f_args}], arguments);`,
62 ` CheckStackTrace([f, test]);`,
63 ` return 42;`,
64 `}`,
65 ];
66 return lines.join("\n");
67 }
68
69 function f_template_bound(f_inlinable, f_args) {
70 var f_comment = f_inlinable ? CAN_INLINE_COMMENT : DONT_INLINE_COMMENT;
71 var lines = [
72 `function ff(a) {`,
73 ` ${f_comment}`,
74 ` assertEquals(153, this.a);`,
75 ` CheckArguments([${f_args}], arguments);`,
76 ` CheckStackTrace([ff, test]);`,
77 ` %DeoptimizeNow();`,
78 ` CheckArguments([${f_args}], arguments);`,
79 ` CheckStackTrace([ff, test]);`,
80 ` return 42;`,
81 `}`,
82 `var f = ff.bind({a: 153});`,
83 ];
84 return lines.join("\n");
85 }
86
87 function f_template_proxy(f_inlinable, f_args) {
88 var f_comment = f_inlinable ? CAN_INLINE_COMMENT : DONT_INLINE_COMMENT;
89 var lines = [
90 `function ff(a) {`,
91 ` ${f_comment}`,
92 ` assertEquals(undefined, this);`,
93 ` CheckArguments([${f_args}], arguments);`,
94 ` CheckStackTrace([f, test]);`,
95 ` %DeoptimizeNow();`,
96 ` CheckArguments([${f_args}], arguments);`,
97 ` CheckStackTrace([f, test]);`,
98 ` return 42;`,
99 `}`,
100 `var f = new Proxy(ff, {});`,
101 ];
102 return lines.join("\n");
103 }
104
105 function g_template(g_inlinable, f_args, g_args) {
106 var g_comment = g_inlinable ? CAN_INLINE_COMMENT : DONT_INLINE_COMMENT;
107 var lines = [
108 `function g(a) {`,
109 ` ${g_comment}`,
110 ` CheckArguments([${g_args}], arguments);`,
111 ` return f(${f_args});`,
112 `}`,
113 ];
114 return lines.join("\n");
115 }
116
117 function test_template(f_source, g_source, g_args,
118 f_inlinable, g_inlinable) {
119 f_source = ident_source(f_source, 2);
120 g_source = ident_source(g_source, 2);
121
122 var lines = [
123 `(function() {`,
124 f_source,
125 g_source,
126 ` function test() {`,
127 ` assertEquals(42, g(${g_args}));`,
128 ` }`,
129 ` ${f_inlinable ? "%SetForceInlineFlag(f)" : ""};`,
130 ` ${g_inlinable ? "%SetForceInlineFlag(g)" : ""};`,
131 ``,
132 ` test();`,
133 ` %OptimizeFunctionOnNextCall(test);`,
134 ` try { %OptimizeFunctionOnNextCall(f); } catch(e) {}`,
135 ` try { %OptimizeFunctionOnNextCall(ff); } catch(e) {}`,
136 ` %OptimizeFunctionOnNextCall(g);`,
137 ` test();`,
138 `})();`,
139 ``,
140 ];
141 var source = lines.join("\n");
142 return source;
143 }
144
145 // TODO(v8:4698), TODO(ishell): support all commented cases.
146 var f_args_variants = ["", "1", "1, 2"];
147 var g_args_variants = [/*"",*/ "10", /*"10, 20"*/];
148 var f_inlinable_variants = [/*true,*/ false];
149 var g_inlinable_variants = [true, false];
150 var f_variants = [
151 f_template_normal,
152 f_template_bound,
153 f_template_proxy
154 ];
155
156 f_variants.forEach((f_template) => {
157 f_args_variants.forEach((f_args) => {
158 g_args_variants.forEach((g_args) => {
159 f_inlinable_variants.forEach((f_inlinable) => {
160 g_inlinable_variants.forEach((g_inlinable) => {
161 var f_source = f_template(f_inlinable, f_args);
162 var g_source = g_template(g_inlinable, f_args, g_args);
163 var source = test_template(f_source, g_source, g_args,
164 f_inlinable, g_inlinable);
165 print("====================");
166 print(source);
167 eval(source);
168 });
169 });
170 });
171 });
172 });
173 }
174
175 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