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

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

Issue 2495013002: Add kernel/closed_world_test (Closed)
Patch Set: Updated cf. comments. Created 4 years, 1 month 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) 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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Tests that the closed world computed from [WorldImpact]s derived from kernel
6 // is equivalent to the original computed from resolution.
7 library dart2js.kernel.closed_world_test;
8
9 import 'package:async_helper/async_helper.dart';
10 import 'package:compiler/src/commandline_options.dart';
11 import 'package:compiler/src/common.dart';
12 import 'package:compiler/src/common/names.dart';
13 import 'package:compiler/src/common/resolution.dart';
14 import 'package:compiler/src/compiler.dart';
15 import 'package:compiler/src/constants/expressions.dart';
16 import 'package:compiler/src/dart_types.dart';
17 import 'package:compiler/src/elements/elements.dart';
18 import 'package:compiler/src/enqueue.dart';
19 import 'package:compiler/src/js_backend/backend.dart';
20 import 'package:compiler/src/js_backend/type_variable_handler.dart';
21 import 'package:compiler/src/resolution/registry.dart';
22 import 'package:compiler/src/resolution/tree_elements.dart';
23 import 'package:compiler/src/ssa/kernel_impact.dart';
24 import 'package:compiler/src/serialization/equivalence.dart';
25 import 'package:compiler/src/universe/call_structure.dart';
26 import 'package:compiler/src/universe/feature.dart';
27 import 'package:compiler/src/universe/world_impact.dart';
28 import 'package:compiler/src/world.dart';
29 import 'package:expect/expect.dart';
30 import 'impact_test.dart';
31 import '../memory_compiler.dart';
32 import '../serialization/helper.dart';
33 import '../serialization/model_test_helper.dart';
34
35 const SOURCE = const {
36 'main.dart': '''
37 main() {
38 print('Hello World!');
39 }
40 '''
41 };
42
43 main(List<String> args) {
44 Arguments arguments = new Arguments.from(args);
45 Uri entryPoint;
46 Map<String, String> memorySourceFiles;
47 if (arguments.uri != null) {
48 entryPoint = arguments.uri;
49 memorySourceFiles = const <String, String>{};
50 } else {
51 entryPoint = Uri.parse('memory:main.dart');
52 memorySourceFiles = SOURCE;
53 }
54
55 asyncTest(() async {
56 enableDebugMode();
57 Compiler compiler = compilerFor(
58 entryPoint: entryPoint,
59 memorySourceFiles: memorySourceFiles,
60 options: [
61 Flags.analyzeOnly,
62 Flags.useKernel,
63 Flags.enableAssertMessage
64 ]);
65 compiler.resolution.retainCachesForTesting = true;
66 await compiler.run(entryPoint);
67 compiler.openWorld.closeWorld(compiler.reporter);
68
69 JavaScriptBackend backend = compiler.backend;
70 // Create a new resolution enqueuer and feed it with the [WorldImpact]s
71 // computed from kernel through the [build] in `kernel_impact.dart`.
72 ResolutionEnqueuer enqueuer = new ResolutionEnqueuer(
73 compiler.enqueuer,
74 compiler.options,
75 compiler.resolution,
76 compiler.enqueuerFilter,
77 const TreeShakingEnqueuerStrategy(),
78 compiler.globalDependencies,
79 backend,
80 compiler.commonElements,
81 compiler.cacheStrategy);
82 // TODO(johnniwinther): Store backend info separately. This replacement is
83 // made to reset a field in [TypeVariableHandler] that prevents it from
84 // enqueuing twice.
85 backend.typeVariableHandler = new TypeVariableHandler(compiler);
86
87 backend.enqueueHelpers(enqueuer);
88 enqueuer.addToWorkList(compiler.mainFunction);
89 enqueuer.forEach((work) {
90 AstElement element = work.element;
91 ResolutionImpact resolutionImpact = build(compiler, element.resolvedAst);
92 WorldImpact worldImpact = compiler.backend.impactTransformer
93 .transformResolutionImpact(enqueuer, resolutionImpact);
94 enqueuer.registerProcessedElement(element);
95 enqueuer.applyImpact(compiler.impactStrategy, worldImpact,
96 impactSource: element);
97 });
98 ClosedWorld closedWorld =
99 enqueuer.universe.openWorld.closeWorld(compiler.reporter);
100
101 checkResolutionEnqueuers(compiler.enqueuer.resolution, enqueuer,
102 typeEquivalence: (DartType a, DartType b) {
103 return areTypesEquivalent(unalias(a), unalias(b));
104 }, elementFilter: (Element element) {
105 if (element is ConstructorElement && element.isRedirectingFactory) {
106 // Redirecting factory constructors are skipped in kernel.
107 return false;
108 }
109 return true;
110 }, verbose: arguments.verbose);
111 checkClosedWorlds(compiler.closedWorld, closedWorld,
112 verbose: arguments.verbose);
113 });
114 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/enqueue.dart ('k') | tests/compiler/dart2js/serialization/model_test_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698