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

Side by Side Diff: tests/compiler/dart2js/kernel/closed_world_from_dill_test.dart

Issue 2865693002: Create closed world for hello world using .dill file (Closed)
Patch Set: Updated cf. comments. Created 3 years, 7 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Partial test that the closed world computed from [WorldImpact]s derived from
6 // kernel is equivalent to the original computed from resolution.
7 library dart2js.kernel.closed_world_from_dill_test;
8
9 import 'dart:async';
10 import 'dart:io';
11
12 import 'package:async_helper/async_helper.dart';
13 import 'package:compiler/src/commandline_options.dart';
14 import 'package:compiler/src/common.dart';
15 import 'package:compiler/src/compiler.dart';
16 import 'package:compiler/src/elements/resolution_types.dart';
17 import 'package:compiler/src/elements/types.dart';
18 import 'package:compiler/src/enqueue.dart';
19 import 'package:compiler/src/kernel/element_map.dart';
20 import 'package:compiler/src/kernel/kernel_strategy.dart';
21 import 'package:compiler/src/resolution/enum_creator.dart';
22 import 'package:compiler/src/universe/world_builder.dart';
23 import 'package:compiler/src/world.dart';
24 import 'package:expect/expect.dart';
25 import '../memory_compiler.dart';
26 import '../equivalence/check_functions.dart';
27 import '../serialization/helper.dart';
28 import 'test_helpers.dart';
29
30 import 'compiler_helper.dart';
31
32 const SOURCE = const {
33 'main.dart': '''
34 main() {
35 print('Hello World');
36 }
37 '''
38 };
39
40 main(List<String> args) {
41 asyncTest(() async {
42 await mainInternal(args);
43 });
44 }
45
46 enum ResultKind { crashes, errors, warnings, success, failure }
47
48 Future<ResultKind> mainInternal(List<String> args,
49 {bool skipWarnings: false, bool skipErrors: false}) async {
50 Arguments arguments = new Arguments.from(args);
51 Uri entryPoint;
52 Map<String, String> memorySourceFiles;
53 if (arguments.uri != null) {
54 entryPoint = arguments.uri;
55 memorySourceFiles = const <String, String>{};
56 } else {
57 entryPoint = Uri.parse('memory:main.dart');
58 memorySourceFiles = SOURCE;
59 }
60
61 enableDebugMode();
62 EnumCreator.matchKernelRepresentationForTesting = true;
63
64 Directory dir = await Directory.systemTemp.createTemp('dart2js-with-dill');
65 print('--- create temp directory $dir -------------------------------');
66 memorySourceFiles.forEach((String name, String source) {
67 new File.fromUri(dir.uri.resolve(name)).writeAsStringSync(source);
68 });
69 entryPoint = dir.uri.resolve(entryPoint.path);
70
71 print('---- analyze-only ------------------------------------------------');
72 DiagnosticCollector collector = new DiagnosticCollector();
73 Compiler compiler1 = compilerFor(
74 entryPoint: entryPoint,
75 diagnosticHandler: collector,
76 options: [Flags.analyzeOnly, Flags.enableAssertMessage]);
77 ElementResolutionWorldBuilder.useInstantiationMap = true;
78 compiler1.resolution.retainCachesForTesting = true;
79 await compiler1.run(entryPoint);
80 if (collector.crashes.isNotEmpty) {
81 print('Skipping due to crashes.');
82 return ResultKind.crashes;
83 }
84 if (collector.errors.isNotEmpty && skipErrors) {
85 print('Skipping due to errors.');
86 return ResultKind.errors;
87 }
88 if (collector.warnings.isNotEmpty && skipWarnings) {
89 print('Skipping due to warnings.');
90 return ResultKind.warnings;
91 }
92 Expect.isFalse(compiler1.compilationFailed);
93 ResolutionEnqueuer enqueuer1 = compiler1.enqueuer.resolution;
94 ClosedWorld closedWorld1 = compiler1.resolutionWorldBuilder.closeWorld();
95
96 Compiler compiler2 =
97 await compileWithDill(entryPoint, const {}, printSteps: true);
98
99 KernelFrontEndStrategy frontEndStrategy = compiler2.frontEndStrategy;
100 KernelToElementMap elementMap = frontEndStrategy.elementMap;
101
102 Expect.isFalse(compiler2.compilationFailed);
103
104 KernelEquivalence equivalence = new KernelEquivalence(elementMap);
105
106 ResolutionEnqueuer enqueuer2 = compiler2.enqueuer.resolution;
107 ClosedWorld closedWorld2 = compiler2.resolutionWorldBuilder.closeWorld();
108
109 checkBackendUsage(closedWorld1.backendUsage, closedWorld2.backendUsage,
110 equivalence.defaultStrategy);
111
112 checkResolutionEnqueuers(closedWorld1.backendUsage, closedWorld2.backendUsage,
113 enqueuer1, enqueuer2, elementEquivalence: equivalence.entityEquivalence,
114 typeEquivalence: (ResolutionDartType a, DartType b) {
115 return equivalence.typeEquivalence(unalias(a), b);
116 }, elementFilter: elementFilter, verbose: arguments.verbose);
117
118 checkClosedWorlds(closedWorld1, closedWorld2,
119 strategy: equivalence.defaultStrategy, verbose: arguments.verbose);
120
121 return ResultKind.success;
122 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/dart2js.status ('k') | tests/compiler/dart2js/kernel/compiler_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698