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

Side by Side Diff: runtime/vm/isolate_reload_test.cc

Issue 2998963002: Revert "Revert "Introduce IKG into kernel-service to support incremental compilation."" (Closed)
Patch Set: Created 3 years, 4 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 | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/kernel_isolate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "include/dart_tools_api.h" 6 #include "include/dart_tools_api.h"
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/globals.h" 8 #include "vm/globals.h"
9 #include "vm/isolate.h" 9 #include "vm/isolate.h"
10 #include "vm/lockers.h" 10 #include "vm/lockers.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 "var _unused;" 60 "var _unused;"
61 "main() {\n" 61 "main() {\n"
62 " return 10;\n" 62 " return 10;\n"
63 "}\n"; 63 "}\n";
64 64
65 lib = TestCase::ReloadTestScript(kReloadScript); 65 lib = TestCase::ReloadTestScript(kReloadScript);
66 EXPECT_VALID(lib); 66 EXPECT_VALID(lib);
67 EXPECT_EQ(10, SimpleInvoke(lib, "main")); 67 EXPECT_EQ(10, SimpleInvoke(lib, "main"));
68 } 68 }
69 69
70 TEST_CASE(IsolateReload_IncrementalCompile) {
71 const char* kScriptChars =
72 "main() {\n"
73 " return 42;\n"
74 "}\n";
75 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
76 EXPECT_VALID(lib);
77 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
78 int64_t value = 0;
79 result = Dart_IntegerToInt64(result, &value);
80 EXPECT_VALID(result);
81 EXPECT_EQ(42, value);
82
83 const char* kUpdatedScriptChars =
84 "main() {\n"
85 " return 24;\n"
86 "}\n"
87 "";
88 lib = TestCase::ReloadTestScript(kUpdatedScriptChars);
89 EXPECT_VALID(lib);
90 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
91 result = Dart_IntegerToInt64(result, &value);
92 EXPECT_VALID(result);
93 EXPECT_EQ(24, value);
94 }
95
96 TEST_CASE(IsolateReload_KernelIncrementalCompile) {
97 // clang-format off
98 Dart_SourceFile sourcefiles[] = {
99 {
100 "file:///test-app",
101 "main() {\n"
102 " return 42;\n"
103 "}\n",
104 },
105 {
106 "file:///.packages", "untitled:/"
107 }};
108 // clang-format on
109
110 Dart_Handle lib = TestCase::LoadTestScriptWithDFE(
111 sizeof(sourcefiles) / sizeof(Dart_SourceFile), sourcefiles,
112 NULL /* resolver */, true /* finalize */, true /* incrementally */);
113 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
114 int64_t value = 0;
115 result = Dart_IntegerToInt64(result, &value);
116 EXPECT_VALID(result);
117 EXPECT_EQ(42, value);
118
119 // clang-format off
120 Dart_SourceFile updated_sourcefiles[] = {
121 {
122 "file:///test-app",
123 "main() {\n"
124 " return 24;\n"
125 "}\n"
126 ""
127 }};
128 // clang-format on
129 {
130 void* kernel_pgm = NULL;
131 char* error = TestCase::CompileTestScriptWithDFE(
132 "file:///test-app",
133 sizeof(updated_sourcefiles) / sizeof(Dart_SourceFile),
134 updated_sourcefiles, &kernel_pgm, true /* incrementally */);
135 EXPECT(error == NULL);
136 EXPECT_NOTNULL(kernel_pgm);
137
138 lib = TestCase::ReloadTestKernel(kernel_pgm);
139 EXPECT_VALID(lib);
140 }
141 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
142 result = Dart_IntegerToInt64(result, &value);
143 EXPECT_VALID(result);
144 EXPECT_EQ(24, value);
145 }
146
147 TEST_CASE(IsolateReload_KernelIncrementalCompileAppAndLib) {
148 // clang-format off
149 Dart_SourceFile sourcefiles[] = {
150 {
151 "file:///test-app.dart",
152 "import 'test-lib.dart';\n"
153 "main() {\n"
154 " return WhatsTheMeaningOfAllThis();\n"
155 "}\n",
156 },
157 {
158 "file:///test-lib.dart",
159 "WhatsTheMeaningOfAllThis() {\n"
160 " return 42;\n"
161 "}\n",
162 },
163 {
164 "file:///.packages", "untitled:/"
165 }};
166 // clang-format on
167
168 Dart_Handle lib = TestCase::LoadTestScriptWithDFE(
169 sizeof(sourcefiles) / sizeof(Dart_SourceFile), sourcefiles,
170 NULL /* resolver */, true /* finalize */, true /* incrementally */);
171 EXPECT_VALID(lib);
172 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
173 int64_t value = 0;
174 result = Dart_IntegerToInt64(result, &value);
175 EXPECT_VALID(result);
176 EXPECT_EQ(42, value);
177
178 // clang-format off
179 Dart_SourceFile updated_sourcefiles[] = {
180 {
181 "file:///test-lib.dart",
182 "WhatsTheMeaningOfAllThis() {\n"
183 " return 24;\n"
184 "}\n"
185 ""
186 }};
187 // clang-format on
188 {
189 void* kernel_pgm = NULL;
190 char* error = TestCase::CompileTestScriptWithDFE(
191 "file:///test-app",
192 sizeof(updated_sourcefiles) / sizeof(Dart_SourceFile),
193 updated_sourcefiles, &kernel_pgm, true /* incrementally */);
194 EXPECT(error == NULL);
195 EXPECT_NOTNULL(kernel_pgm);
196
197 lib = TestCase::ReloadTestKernel(kernel_pgm);
198 EXPECT_VALID(lib);
199 }
200 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
201 result = Dart_IntegerToInt64(result, &value);
202 EXPECT_VALID(result);
203 EXPECT_EQ(24, value);
204 }
205
206 TEST_CASE(IsolateReload_KernelIncrementalCompileGenerics) {
207 // clang-format off
208 Dart_SourceFile sourcefiles[] = {
209 {
210 "file:///test-app.dart",
211 "import 'test-lib.dart';\n"
212 "class Account {\n"
213 " int balance() => 42;\n"
214 "}\n"
215 "class MyAccountState extends State<Account> {\n"
216 " MyAccountState(Account a): super(a) {}\n"
217 "}\n"
218 "main() {\n"
219 " return (new MyAccountState(new Account()))\n"
220 " .howAreTheThings().balance();\n"
221 "}\n",
222 },
223 {
224 "file:///test-lib.dart",
225 "class State<T> {\n"
226 " T t;"
227 " State(this.t);\n"
228 " T howAreTheThings() => t;\n"
229 "}\n",
230 },
231 {
232 "file:///.packages", "untitled:/"
233 }};
234 // clang-format on
235
236 Dart_Handle lib = TestCase::LoadTestScriptWithDFE(
237 sizeof(sourcefiles) / sizeof(Dart_SourceFile), sourcefiles,
238 NULL /* resolver */, true /* finalize */, true /* incrementally */);
239 EXPECT_VALID(lib);
240 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
241 int64_t value = 0;
242 result = Dart_IntegerToInt64(result, &value);
243 EXPECT_VALID(result);
244 EXPECT_EQ(42, value);
245
246 // clang-format off
247 Dart_SourceFile updated_sourcefiles[] = {
248 {
249 "file:///test-app.dart",
250 "import 'test-lib.dart';\n"
251 "class Account {\n"
252 " int balance() => 24;\n"
253 "}\n"
254 "class MyAccountState extends State<Account> {\n"
255 " MyAccountState(Account a): super(a) {}\n"
256 "}\n"
257 "main() {\n"
258 " return (new MyAccountState(new Account()))\n"
259 " .howAreTheThings().balance();\n"
260 "}\n",
261 }};
262 // clang-format on
263 {
264 void* kernel_pgm = NULL;
265 char* error = TestCase::CompileTestScriptWithDFE(
266 "file:///test-app",
267 sizeof(updated_sourcefiles) / sizeof(Dart_SourceFile),
268 updated_sourcefiles, &kernel_pgm, true /* incrementally */);
269 EXPECT(error == NULL);
270 EXPECT_NOTNULL(kernel_pgm);
271
272 lib = TestCase::ReloadTestKernel(kernel_pgm);
273 EXPECT_VALID(lib);
274 }
275 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
276 result = Dart_IntegerToInt64(result, &value);
277 EXPECT_VALID(result);
278 EXPECT_EQ(24, value);
279 }
280
70 TEST_CASE(IsolateReload_BadClass) { 281 TEST_CASE(IsolateReload_BadClass) {
71 const char* kScript = 282 const char* kScript =
72 "class Foo {\n" 283 "class Foo {\n"
73 " final a;\n" 284 " final a;\n"
74 " Foo(this.a);\n" 285 " Foo(this.a);\n"
75 "}\n" 286 "}\n"
76 "main() {\n" 287 "main() {\n"
77 " new Foo(5);\n" 288 " new Foo(5);\n"
78 " return 4;\n" 289 " return 4;\n"
79 "}\n"; 290 "}\n";
(...skipping 3318 matching lines...) Expand 10 before | Expand all | Expand 10 after
3398 "}\n"; 3609 "}\n";
3399 3610
3400 Dart_Handle result = TestCase::ReloadTestScript(kReloadScript); 3611 Dart_Handle result = TestCase::ReloadTestScript(kReloadScript);
3401 EXPECT_VALID(result); 3612 EXPECT_VALID(result);
3402 EXPECT_STREQ("false", SimpleInvokeStr(lib, "main")); 3613 EXPECT_STREQ("false", SimpleInvokeStr(lib, "main"));
3403 } 3614 }
3404 3615
3405 #endif // !PRODUCT 3616 #endif // !PRODUCT
3406 3617
3407 } // namespace dart 3618 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/kernel_isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698