| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:front_end/compiler_options.dart'; | 7 import 'package:front_end/compiler_options.dart'; |
| 8 import 'package:front_end/incremental_kernel_generator.dart'; | 8 import 'package:front_end/incremental_kernel_generator.dart'; |
| 9 import 'package:front_end/memory_file_system.dart'; | 9 import 'package:front_end/memory_file_system.dart'; |
| 10 import 'package:front_end/src/byte_store/byte_store.dart'; | 10 import 'package:front_end/src/byte_store/byte_store.dart'; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 ..sdkSummary = sdkOutlineUri; | 50 ..sdkSummary = sdkOutlineUri; |
| 51 | 51 |
| 52 if (setPackages) { | 52 if (setPackages) { |
| 53 compilerOptions.packagesFileUri = Uri.parse('file:///test/.packages'); | 53 compilerOptions.packagesFileUri = Uri.parse('file:///test/.packages'); |
| 54 } | 54 } |
| 55 incrementalKernelGenerator = await IncrementalKernelGenerator | 55 incrementalKernelGenerator = await IncrementalKernelGenerator |
| 56 .newInstance(compilerOptions, entryPoint, watch: watchFn); | 56 .newInstance(compilerOptions, entryPoint, watch: watchFn); |
| 57 return (await incrementalKernelGenerator.computeDelta()).newProgram; | 57 return (await incrementalKernelGenerator.computeDelta()).newProgram; |
| 58 } | 58 } |
| 59 | 59 |
| 60 test_acceptLastDelta() async { |
| 61 writeFile('/test/.packages', 'test:lib/'); |
| 62 String path = '/test/lib/test.dart'; |
| 63 Uri uri = writeFile(path, 'var v = 1;'); |
| 64 |
| 65 await getInitialState(uri); |
| 66 incrementalKernelGenerator.acceptLastDelta(); |
| 67 |
| 68 // Attempt to accept the second time. |
| 69 expect(() { |
| 70 incrementalKernelGenerator.acceptLastDelta(); |
| 71 }, throwsStateError); |
| 72 } |
| 73 |
| 60 test_compile_chain() async { | 74 test_compile_chain() async { |
| 61 writeFile('/test/.packages', 'test:lib/'); | 75 writeFile('/test/.packages', 'test:lib/'); |
| 62 String aPath = '/test/lib/a.dart'; | 76 String aPath = '/test/lib/a.dart'; |
| 63 String bPath = '/test/lib/b.dart'; | 77 String bPath = '/test/lib/b.dart'; |
| 64 String cPath = '/test/lib/c.dart'; | 78 String cPath = '/test/lib/c.dart'; |
| 65 Uri aUri = writeFile(aPath, 'var a = 1;'); | 79 Uri aUri = writeFile(aPath, 'var a = 1;'); |
| 66 Uri bUri = writeFile(bPath, r''' | 80 Uri bUri = writeFile(bPath, r''' |
| 67 import 'a.dart'; | 81 import 'a.dart'; |
| 68 var b = a; | 82 var b = a; |
| 69 '''); | 83 '''); |
| 70 Uri cUri = writeFile(cPath, r''' | 84 Uri cUri = writeFile(cPath, r''' |
| 71 import 'a.dart'; | 85 import 'a.dart'; |
| 72 import 'b.dart'; | 86 import 'b.dart'; |
| 73 var c1 = a; | 87 var c1 = a; |
| 74 var c2 = b; | 88 var c2 = b; |
| 75 void main() {} | 89 void main() {} |
| 76 '''); | 90 '''); |
| 77 | 91 |
| 78 { | 92 { |
| 79 Program program = await getInitialState(cUri); | 93 Program program = await getInitialState(cUri); |
| 94 incrementalKernelGenerator.acceptLastDelta(); |
| 80 _assertLibraryUris(program, | 95 _assertLibraryUris(program, |
| 81 includes: [aUri, bUri, cUri, Uri.parse('dart:core')]); | 96 includes: [aUri, bUri, cUri, Uri.parse('dart:core')]); |
| 82 Library library = _getLibrary(program, cUri); | 97 Library library = _getLibrary(program, cUri); |
| 83 expect(_getLibraryText(library), r''' | 98 expect(_getLibraryText(library), r''' |
| 84 library; | 99 library; |
| 85 import self as self; | 100 import self as self; |
| 86 import "dart:core" as core; | 101 import "dart:core" as core; |
| 87 import "./a.dart" as a; | 102 import "./a.dart" as a; |
| 88 import "./b.dart" as b; | 103 import "./b.dart" as b; |
| 89 | 104 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 import 'c.dart'; | 162 import 'c.dart'; |
| 148 b() { | 163 b() { |
| 149 c(); | 164 c(); |
| 150 } | 165 } |
| 151 '''); | 166 '''); |
| 152 Uri cUri = writeFile(cPath, 'c() { print(0); }'); | 167 Uri cUri = writeFile(cPath, 'c() { print(0); }'); |
| 153 Uri dUri = writeFile(dPath, 'd() {}'); | 168 Uri dUri = writeFile(dPath, 'd() {}'); |
| 154 | 169 |
| 155 { | 170 { |
| 156 Program program = await getInitialState(aUri); | 171 Program program = await getInitialState(aUri); |
| 172 incrementalKernelGenerator.acceptLastDelta(); |
| 157 _assertLibraryUris(program, | 173 _assertLibraryUris(program, |
| 158 includes: [aUri, bUri, cUri, dUri, Uri.parse('dart:core')]); | 174 includes: [aUri, bUri, cUri, dUri, Uri.parse('dart:core')]); |
| 159 } | 175 } |
| 160 | 176 |
| 161 // Update c.dart and compute the delta. | 177 // Update c.dart and compute the delta. |
| 162 // It should include the changed c.dart, plus b.dart and a.dart because VM | 178 // It should include the changed c.dart, plus b.dart and a.dart because VM |
| 163 // requires this (because of possible inlining). But d.dart is not on the | 179 // requires this (because of possible inlining). But d.dart is not on the |
| 164 // path from main() to the changed c.dart, so it is not included. | 180 // path from main() to the changed c.dart, so it is not included. |
| 165 writeFile(cPath, 'c() { print(1); }'); | 181 writeFile(cPath, 'c() { print(1); }'); |
| 166 incrementalKernelGenerator.invalidate(cUri); | 182 incrementalKernelGenerator.invalidate(cUri); |
| 167 { | 183 { |
| 168 DeltaProgram delta = await incrementalKernelGenerator.computeDelta(); | 184 DeltaProgram delta = await incrementalKernelGenerator.computeDelta(); |
| 185 incrementalKernelGenerator.acceptLastDelta(); |
| 169 Program program = delta.newProgram; | 186 Program program = delta.newProgram; |
| 170 _assertLibraryUris(program, | 187 _assertLibraryUris(program, |
| 171 includes: [aUri, bUri, cUri], | 188 includes: [aUri, bUri, cUri], |
| 172 excludes: [dUri, Uri.parse('dart:core')]); | 189 excludes: [dUri, Uri.parse('dart:core')]); |
| 173 // While a.dart and b.dart are is included (VM needs them), they were not | 190 // While a.dart and b.dart are is included (VM needs them), they were not |
| 174 // recompiled, because the change to c.dart was in the function body. | 191 // recompiled, because the change to c.dart was in the function body. |
| 175 _assertCompiledUris([cUri]); | 192 _assertCompiledUris([cUri]); |
| 176 } | 193 } |
| 177 } | 194 } |
| 178 | 195 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 expect(_getLibraryText(library), r''' | 240 expect(_getLibraryText(library), r''' |
| 224 library; | 241 library; |
| 225 import self as self; | 242 import self as self; |
| 226 import "dart:core" as core; | 243 import "dart:core" as core; |
| 227 import "package:test/a.dart" as a; | 244 import "package:test/a.dart" as a; |
| 228 | 245 |
| 229 static field core::int b = a::a; | 246 static field core::int b = a::a; |
| 230 '''); | 247 '''); |
| 231 } | 248 } |
| 232 | 249 |
| 250 test_rejectLastDelta() async { |
| 251 writeFile('/test/.packages', 'test:lib/'); |
| 252 String path = '/test/lib/test.dart'; |
| 253 Uri uri = writeFile(path, 'var v = 1;'); |
| 254 |
| 255 // The first delta includes the the library. |
| 256 { |
| 257 Program program = await getInitialState(uri); |
| 258 _assertLibraryUris(program, includes: [uri]); |
| 259 Library library = _getLibrary(program, uri); |
| 260 expect(_getLibraryText(library), contains('core::int v = 1')); |
| 261 } |
| 262 |
| 263 // Reject the last delta, so the test library is included again. |
| 264 incrementalKernelGenerator.rejectLastDelta(); |
| 265 { |
| 266 var delta = await incrementalKernelGenerator.computeDelta(); |
| 267 Program program = delta.newProgram; |
| 268 _assertLibraryUris(program, includes: [uri]); |
| 269 } |
| 270 |
| 271 // Attempt to reject the last delta twice. |
| 272 incrementalKernelGenerator.rejectLastDelta(); |
| 273 expect(() { |
| 274 incrementalKernelGenerator.rejectLastDelta(); |
| 275 }, throwsStateError); |
| 276 } |
| 277 |
| 233 test_updateEntryPoint() async { | 278 test_updateEntryPoint() async { |
| 234 writeFile('/test/.packages', 'test:lib/'); | 279 writeFile('/test/.packages', 'test:lib/'); |
| 235 String path = '/test/lib/test.dart'; | 280 String path = '/test/lib/test.dart'; |
| 236 Uri uri = writeFile(path, r''' | 281 Uri uri = writeFile(path, r''' |
| 237 main() { | 282 main() { |
| 238 var v = 1; | 283 var v = 1; |
| 239 } | 284 } |
| 240 '''); | 285 '''); |
| 241 | 286 |
| 242 String initialText = r''' | 287 String initialText = r''' |
| 243 library; | 288 library; |
| 244 import self as self; | 289 import self as self; |
| 245 import "dart:core" as core; | 290 import "dart:core" as core; |
| 246 | 291 |
| 247 static method main() → dynamic { | 292 static method main() → dynamic { |
| 248 core::int v = 1; | 293 core::int v = 1; |
| 249 } | 294 } |
| 250 '''; | 295 '''; |
| 251 | 296 |
| 252 // Compute the initial state. | 297 // Compute the initial state. |
| 253 { | 298 { |
| 254 Program program = await getInitialState(uri); | 299 Program program = await getInitialState(uri); |
| 300 incrementalKernelGenerator.acceptLastDelta(); |
| 255 Library library = _getLibrary(program, uri); | 301 Library library = _getLibrary(program, uri); |
| 256 expect(_getLibraryText(library), initialText); | 302 expect(_getLibraryText(library), initialText); |
| 257 } | 303 } |
| 258 | 304 |
| 259 // Update the entry point library. | 305 // Update the entry point library. |
| 260 writeFile(path, r''' | 306 writeFile(path, r''' |
| 261 main() { | 307 main() { |
| 262 var v = 2.3; | 308 var v = 2.3; |
| 263 } | 309 } |
| 264 '''); | 310 '''); |
| 265 | 311 |
| 266 // We have not invalidated the file, so the delta is empty. | 312 // We have not invalidated the file, so the delta is empty. |
| 267 { | 313 { |
| 268 DeltaProgram delta = await incrementalKernelGenerator.computeDelta(); | 314 DeltaProgram delta = await incrementalKernelGenerator.computeDelta(); |
| 315 incrementalKernelGenerator.acceptLastDelta(); |
| 269 expect(delta.newProgram.libraries, isEmpty); | 316 expect(delta.newProgram.libraries, isEmpty); |
| 270 } | 317 } |
| 271 | 318 |
| 272 // Invalidate the file, so get the new text. | 319 // Invalidate the file, so get the new text. |
| 273 incrementalKernelGenerator.invalidate(uri); | 320 incrementalKernelGenerator.invalidate(uri); |
| 274 { | 321 { |
| 275 DeltaProgram delta = await incrementalKernelGenerator.computeDelta(); | 322 DeltaProgram delta = await incrementalKernelGenerator.computeDelta(); |
| 323 incrementalKernelGenerator.acceptLastDelta(); |
| 276 Program program = delta.newProgram; | 324 Program program = delta.newProgram; |
| 277 _assertLibraryUris(program, includes: [uri]); | 325 _assertLibraryUris(program, includes: [uri]); |
| 278 Library library = _getLibrary(program, uri); | 326 Library library = _getLibrary(program, uri); |
| 279 expect(_getLibraryText(library), r''' | 327 expect(_getLibraryText(library), r''' |
| 280 library; | 328 library; |
| 281 import self as self; | 329 import self as self; |
| 282 import "dart:core" as core; | 330 import "dart:core" as core; |
| 283 | 331 |
| 284 static method main() → dynamic { | 332 static method main() → dynamic { |
| 285 core::double v = 2.3; | 333 core::double v = 2.3; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 305 if (used) { | 353 if (used) { |
| 306 usedFiles.add(uri); | 354 usedFiles.add(uri); |
| 307 } else { | 355 } else { |
| 308 unusedFiles.add(uri); | 356 unusedFiles.add(uri); |
| 309 } | 357 } |
| 310 return new Future.value(); | 358 return new Future.value(); |
| 311 }; | 359 }; |
| 312 | 360 |
| 313 { | 361 { |
| 314 await getInitialState(cUri); | 362 await getInitialState(cUri); |
| 363 incrementalKernelGenerator.acceptLastDelta(); |
| 315 // We use at least c.dart and a.dart now. | 364 // We use at least c.dart and a.dart now. |
| 316 expect(usedFiles, contains(cUri)); | 365 expect(usedFiles, contains(cUri)); |
| 317 expect(usedFiles, contains(aUri)); | 366 expect(usedFiles, contains(aUri)); |
| 318 usedFiles.clear(); | 367 usedFiles.clear(); |
| 319 expect(unusedFiles, isEmpty); | 368 expect(unusedFiles, isEmpty); |
| 320 } | 369 } |
| 321 | 370 |
| 322 // Update c.dart to reference also b.dart file. | 371 // Update c.dart to reference also b.dart file. |
| 323 writeFile(cPath, r''' | 372 writeFile(cPath, r''' |
| 324 import 'a.dart'; | 373 import 'a.dart'; |
| 325 import 'b.dart'; | 374 import 'b.dart'; |
| 326 '''); | 375 '''); |
| 327 incrementalKernelGenerator.invalidate(cUri); | 376 incrementalKernelGenerator.invalidate(cUri); |
| 328 { | 377 { |
| 329 await incrementalKernelGenerator.computeDelta(); | 378 await incrementalKernelGenerator.computeDelta(); |
| 379 incrementalKernelGenerator.acceptLastDelta(); |
| 330 // The only new file is b.dart now. | 380 // The only new file is b.dart now. |
| 331 expect(usedFiles, [bUri]); | 381 expect(usedFiles, [bUri]); |
| 332 usedFiles.clear(); | 382 usedFiles.clear(); |
| 333 expect(unusedFiles, isEmpty); | 383 expect(unusedFiles, isEmpty); |
| 334 } | 384 } |
| 335 | 385 |
| 336 // Update c.dart to stop referencing b.dart file. | 386 // Update c.dart to stop referencing b.dart file. |
| 337 writeFile(cPath, r''' | 387 writeFile(cPath, r''' |
| 338 import 'a.dart'; | 388 import 'a.dart'; |
| 339 '''); | 389 '''); |
| 340 incrementalKernelGenerator.invalidate(cUri); | 390 incrementalKernelGenerator.invalidate(cUri); |
| 341 { | 391 { |
| 342 await incrementalKernelGenerator.computeDelta(); | 392 await incrementalKernelGenerator.computeDelta(); |
| 393 incrementalKernelGenerator.acceptLastDelta(); |
| 343 // No new used files. | 394 // No new used files. |
| 344 expect(usedFiles, isEmpty); | 395 expect(usedFiles, isEmpty); |
| 345 // The file b.dart is not used anymore. | 396 // The file b.dart is not used anymore. |
| 346 expect(unusedFiles, [bUri]); | 397 expect(unusedFiles, [bUri]); |
| 347 unusedFiles.clear(); | 398 unusedFiles.clear(); |
| 348 } | 399 } |
| 349 } | 400 } |
| 350 | 401 |
| 351 test_watch_null() async { | 402 test_watch_null() async { |
| 352 writeFile('/test/.packages', 'test:lib/'); | 403 writeFile('/test/.packages', 'test:lib/'); |
| 353 String aPath = '/test/lib/a.dart'; | 404 String aPath = '/test/lib/a.dart'; |
| 354 String bPath = '/test/lib/b.dart'; | 405 String bPath = '/test/lib/b.dart'; |
| 355 writeFile(aPath, ""); | 406 writeFile(aPath, ""); |
| 356 Uri bUri = writeFile(bPath, ""); | 407 Uri bUri = writeFile(bPath, ""); |
| 357 | 408 |
| 358 // Set null, as if the watch function is not provided. | 409 // Set null, as if the watch function is not provided. |
| 359 watchFn = null; | 410 watchFn = null; |
| 360 | 411 |
| 361 await getInitialState(bUri); | 412 await getInitialState(bUri); |
| 413 incrementalKernelGenerator.acceptLastDelta(); |
| 362 | 414 |
| 363 // Update b.dart to import a.dart file. | 415 // Update b.dart to import a.dart file. |
| 364 writeFile(bPath, "import 'a.dart';"); | 416 writeFile(bPath, "import 'a.dart';"); |
| 365 incrementalKernelGenerator.invalidate(bUri); | 417 incrementalKernelGenerator.invalidate(bUri); |
| 366 await incrementalKernelGenerator.computeDelta(); | 418 await incrementalKernelGenerator.computeDelta(); |
| 367 | 419 |
| 368 // No exception even though the watcher function is null. | 420 // No exception even though the watcher function is null. |
| 369 } | 421 } |
| 370 | 422 |
| 371 /// Write the given [text] of the file with the given [path] into the | 423 /// Write the given [text] of the file with the given [path] into the |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 throw fail('No library found with URI "$uri"'); | 473 throw fail('No library found with URI "$uri"'); |
| 422 } | 474 } |
| 423 | 475 |
| 424 String _getLibraryText(Library library) { | 476 String _getLibraryText(Library library) { |
| 425 StringBuffer buffer = new StringBuffer(); | 477 StringBuffer buffer = new StringBuffer(); |
| 426 new Printer(buffer, syntheticNames: new NameSystem()) | 478 new Printer(buffer, syntheticNames: new NameSystem()) |
| 427 .writeLibraryFile(library); | 479 .writeLibraryFile(library); |
| 428 return buffer.toString(); | 480 return buffer.toString(); |
| 429 } | 481 } |
| 430 } | 482 } |
| OLD | NEW |