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

Side by Side Diff: tests/compiler/dart2js/serialization/model_test_helper.dart

Issue 2150533002: Serialize data for LibraryElement.getImportsFor (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 5 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library dart2js.serialization_model_test; 5 library dart2js.serialization_model_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'package:async_helper/async_helper.dart'; 9 import 'package:async_helper/async_helper.dart';
10 import 'package:expect/expect.dart'; 10 import 'package:expect/expect.dart';
11 import 'package:compiler/src/closure.dart'; 11 import 'package:compiler/src/closure.dart';
12 import 'package:compiler/src/commandline_options.dart'; 12 import 'package:compiler/src/commandline_options.dart';
13 import 'package:compiler/src/common.dart';
13 import 'package:compiler/src/compiler.dart'; 14 import 'package:compiler/src/compiler.dart';
15 import 'package:compiler/src/deferred_load.dart';
14 import 'package:compiler/src/elements/elements.dart'; 16 import 'package:compiler/src/elements/elements.dart';
15 import 'package:compiler/src/filenames.dart'; 17 import 'package:compiler/src/filenames.dart';
16 import 'package:compiler/src/js_backend/js_backend.dart'; 18 import 'package:compiler/src/js_backend/js_backend.dart';
17 import 'package:compiler/src/serialization/equivalence.dart'; 19 import 'package:compiler/src/serialization/equivalence.dart';
18 import 'package:compiler/src/tree/nodes.dart'; 20 import 'package:compiler/src/tree/nodes.dart';
19 import 'package:compiler/src/universe/class_set.dart'; 21 import 'package:compiler/src/universe/class_set.dart';
20 import '../memory_compiler.dart'; 22 import '../memory_compiler.dart';
21 import 'helper.dart'; 23 import 'helper.dart';
22 import 'test_data.dart'; 24 import 'test_data.dart';
23 import 'test_helper.dart'; 25 import 'test_helper.dart';
24 26
25 main(List<String> args) { 27 main(List<String> args) {
26 asyncTest(() async { 28 asyncTest(() async {
27 Arguments arguments = new Arguments.from(args); 29 Arguments arguments = new Arguments.from(args);
28 SerializedData serializedData = 30 SerializedData serializedData =
29 await serializeDartCore(arguments: arguments); 31 await serializeDartCore(arguments: arguments);
30 if (arguments.filename != null) { 32 if (arguments.filename != null) {
31 Uri entryPoint = Uri.base.resolve(nativeToUriPath(arguments.filename)); 33 Uri entryPoint = Uri.base.resolve(nativeToUriPath(arguments.filename));
34 print('----------------------------------------------------------------');
35 print('serialize ${entryPoint}');
36 print('----------------------------------------------------------------');
37 SerializationResult result = await serialize(
38 entryPoint,
39 memorySourceFiles: serializedData.toMemorySourceFiles(),
40 resolutionInputs: serializedData.toUris(),
41 dataUri: Uri.parse('memory:test.data'));
32 await checkModels(entryPoint, 42 await checkModels(entryPoint,
33 sourceFiles: serializedData.toMemorySourceFiles(), 43 sourceFiles: serializedData.toMemorySourceFiles(
34 resolutionInputs: serializedData.toUris()); 44 result.serializedData.toMemorySourceFiles()),
45 resolutionInputs: serializedData.toUris(
46 result.serializedData.toUris()));
35 } else { 47 } else {
36 Uri entryPoint = Uri.parse('memory:main.dart'); 48 Uri entryPoint = Uri.parse('memory:main.dart');
37 await arguments.forEachTest(serializedData, TESTS, checkModels); 49 await arguments.forEachTest(serializedData, TESTS, checkModels);
38 } 50 }
39 }); 51 });
40 } 52 }
41 53
42 Future checkModels( 54 Future checkModels(
43 Uri entryPoint, 55 Uri entryPoint,
44 {Map<String, String> sourceFiles: const <String, String>{}, 56 {Map<String, String> sourceFiles: const <String, String>{},
45 List<Uri> resolutionInputs, 57 List<Uri> resolutionInputs,
46 int index, 58 int index,
47 Test test, 59 Test test,
48 bool verbose: false}) async { 60 bool verbose: false}) async {
49 String testDescription = test != null ? test.name : '${entryPoint}'; 61 String testDescription = test != null ? test.name : '${entryPoint}';
50 String id = index != null ? '$index: ' : ''; 62 String id = index != null ? '$index: ' : '';
51 print('------------------------------------------------------------------'); 63 print('------------------------------------------------------------------');
52 print('compile normal ${id}${testDescription}'); 64 print('compile normal ${id}${testDescription}');
53 print('------------------------------------------------------------------'); 65 print('------------------------------------------------------------------');
54 Compiler compilerNormal = compilerFor( 66 Compiler compilerNormal = compilerFor(
55 memorySourceFiles: sourceFiles, 67 memorySourceFiles: sourceFiles,
56 options: [Flags.analyzeOnly]); 68 options: [Flags.analyzeOnly]);
57 compilerNormal.resolution.retainCachesForTesting = true; 69 compilerNormal.resolution.retainCachesForTesting = true;
58 await compilerNormal.run(entryPoint); 70 await compilerNormal.run(entryPoint);
59 compilerNormal.phase = Compiler.PHASE_DONE_RESOLVING; 71 compilerNormal.phase = Compiler.PHASE_DONE_RESOLVING;
60 compilerNormal.world.populate(); 72 compilerNormal.world.populate();
61 compilerNormal.backend.onResolutionComplete(); 73 compilerNormal.backend.onResolutionComplete();
74 compilerNormal.deferredLoadTask.onResolutionComplete(
75 compilerNormal.mainFunction);
62 76
63 print('------------------------------------------------------------------'); 77 print('------------------------------------------------------------------');
64 print('compile deserialized ${id}${testDescription}'); 78 print('compile deserialized ${id}${testDescription}');
65 print('------------------------------------------------------------------'); 79 print('------------------------------------------------------------------');
66 Compiler compilerDeserialized = compilerFor( 80 Compiler compilerDeserialized = compilerFor(
67 memorySourceFiles: sourceFiles, 81 memorySourceFiles: sourceFiles,
68 resolutionInputs: resolutionInputs, 82 resolutionInputs: resolutionInputs,
69 options: [Flags.analyzeOnly]); 83 options: [Flags.analyzeOnly]);
70 compilerDeserialized.resolution.retainCachesForTesting = true; 84 compilerDeserialized.resolution.retainCachesForTesting = true;
71 await compilerDeserialized.run(entryPoint); 85 await compilerDeserialized.run(entryPoint);
72 compilerDeserialized.phase = Compiler.PHASE_DONE_RESOLVING; 86 compilerDeserialized.phase = Compiler.PHASE_DONE_RESOLVING;
73 compilerDeserialized.world.populate(); 87 compilerDeserialized.world.populate();
74 compilerDeserialized.backend.onResolutionComplete(); 88 compilerDeserialized.backend.onResolutionComplete();
89 compilerDeserialized.deferredLoadTask.onResolutionComplete(
90 compilerDeserialized.mainFunction);
75 91
76 checkAllImpacts( 92 checkAllImpacts(
77 compilerNormal, compilerDeserialized, 93 compilerNormal, compilerDeserialized,
78 verbose: verbose); 94 verbose: verbose);
79 95
80 checkSets( 96 checkSets(
81 compilerNormal.resolverWorld.directlyInstantiatedClasses, 97 compilerNormal.resolverWorld.directlyInstantiatedClasses,
82 compilerDeserialized.resolverWorld.directlyInstantiatedClasses, 98 compilerDeserialized.resolverWorld.directlyInstantiatedClasses,
83 "Directly instantiated classes mismatch", 99 "Directly instantiated classes mismatch",
84 areElementsEquivalent, 100 areElementsEquivalent,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 "Compiler.enabledInvokeOn mismatch"); 139 "Compiler.enabledInvokeOn mismatch");
124 Expect.equals(compilerNormal.enabledFunctionApply, 140 Expect.equals(compilerNormal.enabledFunctionApply,
125 compilerDeserialized.enabledFunctionApply, 141 compilerDeserialized.enabledFunctionApply,
126 "Compiler.enabledFunctionApply mismatch"); 142 "Compiler.enabledFunctionApply mismatch");
127 Expect.equals(compilerNormal.enabledRuntimeType, 143 Expect.equals(compilerNormal.enabledRuntimeType,
128 compilerDeserialized.enabledRuntimeType, 144 compilerDeserialized.enabledRuntimeType,
129 "Compiler.enabledRuntimeType mismatch"); 145 "Compiler.enabledRuntimeType mismatch");
130 Expect.equals(compilerNormal.hasIsolateSupport, 146 Expect.equals(compilerNormal.hasIsolateSupport,
131 compilerDeserialized.hasIsolateSupport, 147 compilerDeserialized.hasIsolateSupport,
132 "Compiler.hasIsolateSupport mismatch"); 148 "Compiler.hasIsolateSupport mismatch");
149 Expect.equals(
150 compilerNormal.deferredLoadTask.isProgramSplit,
151 compilerDeserialized.deferredLoadTask.isProgramSplit,
152 "isProgramSplit mismatch");
133 } 153 }
134 154
135 void checkElements( 155 void checkElements(
136 Compiler compiler1, Compiler compiler2, 156 Compiler compiler1, Compiler compiler2,
137 Element element1, Element element2, 157 Element element1, Element element2,
138 {bool verbose: false}) { 158 {bool verbose: false}) {
139 if (element1.isFunction || 159 if (element1.isFunction ||
140 element1.isConstructor || 160 element1.isConstructor ||
141 (element1.isField && element1.isInstanceMember)) { 161 (element1.isField && element1.isInstanceMember)) {
142 AstElement astElement1 = element1; 162 AstElement astElement1 = element1;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 const CheckStrategy()); 224 const CheckStrategy());
205 }); 225 });
206 } 226 }
207 } 227 }
208 JavaScriptBackend backend1 = compiler1.backend; 228 JavaScriptBackend backend1 = compiler1.backend;
209 JavaScriptBackend backend2 = compiler2.backend; 229 JavaScriptBackend backend2 = compiler2.backend;
210 Expect.equals( 230 Expect.equals(
211 backend1.inlineCache.getCurrentCacheDecisionForTesting(element1), 231 backend1.inlineCache.getCurrentCacheDecisionForTesting(element1),
212 backend2.inlineCache.getCurrentCacheDecisionForTesting(element2), 232 backend2.inlineCache.getCurrentCacheDecisionForTesting(element2),
213 "Inline cache decision mismatch for $element1 vs $element2"); 233 "Inline cache decision mismatch for $element1 vs $element2");
234
235 checkOutputUnits(compiler1, compiler2, element1, element2);
214 } 236 }
215 237
216 void checkMixinUses( 238 void checkMixinUses(
217 Compiler compiler1, Compiler compiler2, 239 Compiler compiler1, Compiler compiler2,
218 ClassElement class1, ClassElement class2, 240 ClassElement class1, ClassElement class2,
219 {bool verbose: false}) { 241 {bool verbose: false}) {
220 242
221 checkSets( 243 checkSets(
222 compiler1.world.mixinUsesOf(class1), 244 compiler1.world.mixinUsesOf(class1),
223 compiler2.world.mixinUsesOf(class2), 245 compiler2.world.mixinUsesOf(class2),
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 areElementsEquivalent); 339 areElementsEquivalent);
318 return true; 340 return true;
319 } 341 }
320 342
321 String nodeToString(Node node) { 343 String nodeToString(Node node) {
322 String text = '$node'; 344 String text = '$node';
323 if (text.length > 40) { 345 if (text.length > 40) {
324 return '(${node.runtimeType}) ${text.substring(0, 37)}...'; 346 return '(${node.runtimeType}) ${text.substring(0, 37)}...';
325 } 347 }
326 return '(${node.runtimeType}) $text'; 348 return '(${node.runtimeType}) $text';
349 }
350
351 void checkOutputUnits(Compiler compiler1, Compiler compiler2, Element element1,
352 Element element2) {
353 OutputUnit outputUnit1 =
354 compiler1.deferredLoadTask.outputUnitForElement(element1);
355 OutputUnit outputUnit2 =
356 compiler2.deferredLoadTask.outputUnitForElement(element2);
357 check(outputUnit1, outputUnit2,
358 'OutputUnit.isMainOutput for $element1 vs $element2',
359 outputUnit1.isMainOutput, outputUnit2.isMainOutput);
360 checkSetEquivalence(outputUnit1, outputUnit2,
361 'OutputUnit.imports for $element1 vs $element2',
362 outputUnit1.imports, outputUnit2.imports,
363 (a, b) => areElementsEquivalent(a.declaration, b.declaration));
327 } 364 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698