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

Side by Side Diff: pkg/front_end/test/incremental_kernel_generator_test.dart

Issue 2999563002: Add support for SDK outline in IKG. (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
OLDNEW
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/incremental/byte_store.dart'; 10 import 'package:front_end/src/incremental/byte_store.dart';
11 import 'package:front_end/src/incremental_kernel_generator_impl.dart'; 11 import 'package:front_end/src/incremental_kernel_generator_impl.dart';
12 import 'package:front_end/summary_generator.dart';
12 import 'package:kernel/ast.dart'; 13 import 'package:kernel/ast.dart';
13 import 'package:kernel/text/ast_to_text.dart'; 14 import 'package:kernel/text/ast_to_text.dart';
14 import 'package:test/test.dart'; 15 import 'package:test/test.dart';
15 import 'package:test_reflective_loader/test_reflective_loader.dart'; 16 import 'package:test_reflective_loader/test_reflective_loader.dart';
16 17
17 import 'src/incremental/mock_sdk.dart'; 18 import 'src/incremental/mock_sdk.dart';
18 19
19 main() { 20 main() {
20 defineReflectiveSuite(() { 21 defineReflectiveSuite(() {
21 defineReflectiveTests(IncrementalKernelGeneratorTest); 22 defineReflectiveTests(IncrementalKernelGeneratorTest);
22 }); 23 });
23 } 24 }
24 25
25 @reflectiveTest 26 @reflectiveTest
26 class IncrementalKernelGeneratorTest { 27 class IncrementalKernelGeneratorTest {
27 /// Virtual filesystem for testing. 28 /// Virtual filesystem for testing.
28 final fileSystem = new MemoryFileSystem(Uri.parse('file:///')); 29 final fileSystem = new MemoryFileSystem(Uri.parse('file:///'));
29 30
30 /// The used file watcher. 31 /// The used file watcher.
31 WatchUsedFilesFn watchFn = (uri, used) {}; 32 WatchUsedFilesFn watchFn = (uri, used) {};
32 33
33 /// The object under test. 34 /// The object under test.
34 IncrementalKernelGeneratorImpl incrementalKernelGenerator; 35 IncrementalKernelGeneratorImpl incrementalKernelGenerator;
35 36
36 /// Compute the initial [Program] for the given [entryPoint]. 37 /// Compute the initial [Program] for the given [entryPoint].
37 Future<Program> getInitialState(Uri entryPoint, 38 Future<Program> getInitialState(Uri entryPoint,
38 {bool setPackages: true}) async { 39 {Uri sdkOutlineUri, bool setPackages: true}) async {
39 createSdkFiles(fileSystem); 40 createSdkFiles(fileSystem);
40 // TODO(scheglov) Builder the SDK kernel and set it into the options. 41 // TODO(scheglov) Builder the SDK kernel and set it into the options.
41 42
42 var compilerOptions = new CompilerOptions() 43 var compilerOptions = new CompilerOptions()
43 ..fileSystem = fileSystem 44 ..fileSystem = fileSystem
44 ..byteStore = new MemoryByteStore() 45 ..byteStore = new MemoryByteStore()
45 // ..logger = new PerformanceLog(stdout) 46 // ..logger = new PerformanceLog(stdout)
46 ..strongMode = true 47 ..strongMode = true
47 ..chaseDependencies = true 48 ..chaseDependencies = true
48 ..librariesSpecificationUri = Uri.parse('file:///sdk/lib/libraries.json'); 49 ..librariesSpecificationUri = Uri.parse('file:///sdk/lib/libraries.json')
50 ..sdkSummary = sdkOutlineUri;
49 51
50 if (setPackages) { 52 if (setPackages) {
51 compilerOptions.packagesFileUri = Uri.parse('file:///test/.packages'); 53 compilerOptions.packagesFileUri = Uri.parse('file:///test/.packages');
52 } 54 }
53 incrementalKernelGenerator = await IncrementalKernelGenerator 55 incrementalKernelGenerator = await IncrementalKernelGenerator
54 .newInstance(compilerOptions, entryPoint, watch: watchFn); 56 .newInstance(compilerOptions, entryPoint, watch: watchFn);
55 return (await incrementalKernelGenerator.computeDelta()).newProgram; 57 return (await incrementalKernelGenerator.computeDelta()).newProgram;
56 } 58 }
57 59
58 test_compile_chain() async { 60 test_compile_chain() async {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 Program program = delta.newProgram; 169 Program program = delta.newProgram;
168 _assertLibraryUris(program, 170 _assertLibraryUris(program,
169 includes: [aUri, bUri, cUri], 171 includes: [aUri, bUri, cUri],
170 excludes: [dUri, Uri.parse('dart:core')]); 172 excludes: [dUri, Uri.parse('dart:core')]);
171 // While a.dart and b.dart are is included (VM needs them), they were not 173 // While a.dart and b.dart are is included (VM needs them), they were not
172 // recompiled, because the change to c.dart was in the function body. 174 // recompiled, because the change to c.dart was in the function body.
173 _assertCompiledUris([cUri]); 175 _assertCompiledUris([cUri]);
174 } 176 }
175 } 177 }
176 178
179 solo_test_compile_useSdkOutline() async {
Paul Berry 2017/08/07 18:37:13 Remove "solo_"
scheglov 2017/08/07 20:47:51 Done.
180 createSdkFiles(fileSystem);
181 List<int> sdkOutlineBytes = await _computeSdkOutlineBytes();
182
183 Uri sdkOutlineUri = Uri.parse('file:///sdk/outline.dill');
184 fileSystem.entityForUri(sdkOutlineUri).writeAsBytesSync(sdkOutlineBytes);
185
186 writeFile('/test/.packages', 'test:lib/');
187 String path = '/test/lib/test.dart';
188 Uri uri = writeFile(path, r'''
189 import 'dart:async';
190 var a = 1;
191 Future<String> b;
192 ''');
193
194 Program program = await getInitialState(uri, sdkOutlineUri: sdkOutlineUri);
195 _assertLibraryUris(program,
196 includes: [uri], excludes: [Uri.parse('dart:core')]);
197
198 Library library = _getLibrary(program, uri);
199 expect(_getLibraryText(library), r'''library;
200 import self as self;
201 import "dart:core" as core;
202 import "dart:async" as asy;
203
204 static field core::int a = 1;
205 static field asy::Future<core::String> b;
206 ''');
207 }
Siggi Cherem (dart-lang) 2017/08/07 19:12:52 consider adding a test that we don't use the summa
scheglov 2017/08/07 20:47:51 Hm... We could do this, but it seems a bit stretch
208
209 test_inferPackagesFile() async {
210 writeFile('/test/.packages', 'test:lib/');
211 String aPath = '/test/lib/a.dart';
212 String bPath = '/test/lib/b.dart';
213 writeFile(aPath, 'var a = 1;');
214 Uri bUri = writeFile(bPath, r'''
215 import "package:test/a.dart";
216 var b = a;
217 ''');
218
219 // Ensures that the `.packages` file can be discovered automatically
220 // from the entry point file.
221 Program program = await getInitialState(bUri, setPackages: false);
222 Library library = _getLibrary(program, bUri);
223 expect(_getLibraryText(library), r'''
224 library;
225 import self as self;
226 import "dart:core" as core;
227 import "package:test/a.dart" as a;
228
229 static field core::int b = a::a;
230 ''');
231 }
232
177 test_updateEntryPoint() async { 233 test_updateEntryPoint() async {
178 writeFile('/test/.packages', 'test:lib/'); 234 writeFile('/test/.packages', 'test:lib/');
179 String path = '/test/lib/test.dart'; 235 String path = '/test/lib/test.dart';
180 Uri uri = writeFile(path, r''' 236 Uri uri = writeFile(path, r'''
181 main() { 237 main() {
182 var v = 1; 238 var v = 1;
183 } 239 }
184 '''); 240 ''');
185 241
186 String initialText = r''' 242 String initialText = r'''
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 import self as self; 281 import self as self;
226 import "dart:core" as core; 282 import "dart:core" as core;
227 283
228 static method main() → dynamic { 284 static method main() → dynamic {
229 core::double v = 2.3; 285 core::double v = 2.3;
230 } 286 }
231 '''); 287 ''');
232 } 288 }
233 } 289 }
234 290
235 test_inferPackagesFile() async {
236 writeFile('/test/.packages', 'test:lib/');
237 String aPath = '/test/lib/a.dart';
238 String bPath = '/test/lib/b.dart';
239 writeFile(aPath, 'var a = 1;');
240 Uri bUri = writeFile(bPath, r'''
241 import "package:test/a.dart";
242 var b = a;
243 ''');
244
245 // Ensures that the `.packages` file can be discovered automatically
246 // from the entry point file.
247 Program program = await getInitialState(bUri, setPackages: false);
248 Library library = _getLibrary(program, bUri);
249 expect(_getLibraryText(library), r'''
250 library;
251 import self as self;
252 import "dart:core" as core;
253 import "package:test/a.dart" as a;
254
255 static field core::int b = a::a;
256 ''');
257 }
258
259 test_watch() async { 291 test_watch() async {
260 writeFile('/test/.packages', 'test:lib/'); 292 writeFile('/test/.packages', 'test:lib/');
261 String aPath = '/test/lib/a.dart'; 293 String aPath = '/test/lib/a.dart';
262 String bPath = '/test/lib/b.dart'; 294 String bPath = '/test/lib/b.dart';
263 String cPath = '/test/lib/c.dart'; 295 String cPath = '/test/lib/c.dart';
264 Uri aUri = writeFile(aPath, ''); 296 Uri aUri = writeFile(aPath, '');
265 Uri bUri = writeFile(bPath, ''); 297 Uri bUri = writeFile(bPath, '');
266 Uri cUri = writeFile(cPath, r''' 298 Uri cUri = writeFile(cPath, r'''
267 import 'a.dart'; 299 import 'a.dart';
268 '''); 300 ''');
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 List<Uri> libraryUris = 396 List<Uri> libraryUris =
365 program.libraries.map((library) => library.importUri).toList(); 397 program.libraries.map((library) => library.importUri).toList();
366 for (var shouldInclude in includes) { 398 for (var shouldInclude in includes) {
367 expect(libraryUris, contains(shouldInclude)); 399 expect(libraryUris, contains(shouldInclude));
368 } 400 }
369 for (var shouldExclude in excludes) { 401 for (var shouldExclude in excludes) {
370 expect(libraryUris, isNot(contains(shouldExclude))); 402 expect(libraryUris, isNot(contains(shouldExclude)));
371 } 403 }
372 } 404 }
373 405
406 Future<List<int>> _computeSdkOutlineBytes() async {
407 var options = new CompilerOptions()
408 ..fileSystem = fileSystem
409 ..sdkRoot = Uri.parse('file:///sdk/')
410 ..compileSdk = true
411 ..chaseDependencies = true
412 ..strongMode = true;
413 var inputs = [Uri.parse('dart:core')];
414 return summaryFor(inputs, options);
415 }
416
374 Library _getLibrary(Program program, Uri uri) { 417 Library _getLibrary(Program program, Uri uri) {
375 for (var library in program.libraries) { 418 for (var library in program.libraries) {
376 if (library.importUri == uri) return library; 419 if (library.importUri == uri) return library;
377 } 420 }
378 throw fail('No library found with URI "$uri"'); 421 throw fail('No library found with URI "$uri"');
379 } 422 }
380 423
381 String _getLibraryText(Library library) { 424 String _getLibraryText(Library library) {
382 StringBuffer buffer = new StringBuffer(); 425 StringBuffer buffer = new StringBuffer();
383 new Printer(buffer, syntheticNames: new NameSystem()) 426 new Printer(buffer, syntheticNames: new NameSystem())
384 .writeLibraryFile(library); 427 .writeLibraryFile(library);
385 return buffer.toString(); 428 return buffer.toString();
386 } 429 }
387 } 430 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698