OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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_impact_test; | 5 library dart2js.serialization_impact_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
9 import 'package:compiler/src/commandline_options.dart'; | 9 import 'package:compiler/src/commandline_options.dart'; |
10 import 'package:compiler/src/common/resolution.dart'; | 10 import 'package:compiler/src/common/resolution.dart'; |
11 import 'package:compiler/src/compiler.dart'; | 11 import 'package:compiler/src/compiler.dart'; |
12 import 'package:compiler/src/elements/elements.dart'; | 12 import 'package:compiler/src/elements/elements.dart'; |
13 import 'package:compiler/src/filenames.dart'; | 13 import 'package:compiler/src/filenames.dart'; |
14 import 'package:compiler/src/serialization/equivalence.dart'; | 14 import 'package:compiler/src/serialization/equivalence.dart'; |
15 import 'memory_compiler.dart'; | 15 import 'memory_compiler.dart'; |
16 import 'serialization_helper.dart'; | 16 import 'serialization_helper.dart'; |
17 import 'serialization_test.dart'; | 17 import 'serialization_test_helper.dart'; |
18 | 18 |
19 main(List<String> arguments) { | 19 main(List<String> arguments) { |
20 asyncTest(() async { | 20 asyncTest(() async { |
21 String serializedData = await serializeDartCore(); | 21 String serializedData = await serializeDartCore(); |
22 if (arguments.isNotEmpty) { | 22 if (arguments.isNotEmpty) { |
23 Uri entryPoint = Uri.base.resolve(nativeToUriPath(arguments.last)); | 23 Uri entryPoint = Uri.base.resolve(nativeToUriPath(arguments.last)); |
24 await check(serializedData, entryPoint); | 24 await check(serializedData, entryPoint); |
25 } else { | 25 } else { |
26 Uri entryPoint = Uri.parse('memory:main.dart'); | 26 Uri entryPoint = Uri.parse('memory:main.dart'); |
27 await check(serializedData, entryPoint, {'main.dart': 'main() {}'}); | 27 await check(serializedData, entryPoint, {'main.dart': 'main() {}'}); |
(...skipping 12 matching lines...) Expand all Loading... |
40 compilerNormal.resolution.retainCachesForTesting = true; | 40 compilerNormal.resolution.retainCachesForTesting = true; |
41 await compilerNormal.run(entryPoint); | 41 await compilerNormal.run(entryPoint); |
42 | 42 |
43 Compiler compilerDeserialized = compilerFor( | 43 Compiler compilerDeserialized = compilerFor( |
44 memorySourceFiles: sourceFiles, | 44 memorySourceFiles: sourceFiles, |
45 options: [Flags.analyzeOnly]); | 45 options: [Flags.analyzeOnly]); |
46 compilerDeserialized.resolution.retainCachesForTesting = true; | 46 compilerDeserialized.resolution.retainCachesForTesting = true; |
47 deserialize(compilerDeserialized, serializedData); | 47 deserialize(compilerDeserialized, serializedData); |
48 await compilerDeserialized.run(entryPoint); | 48 await compilerDeserialized.run(entryPoint); |
49 | 49 |
50 checkResolutionImpacts(compilerNormal, compilerDeserialized, verbose: true); | 50 checkAllImpacts(compilerNormal, compilerDeserialized, verbose: true); |
51 } | 51 } |
52 | |
53 /// Check equivalence of [impact1] and [impact2]. | |
54 void checkImpacts(Element element1, Element element2, | |
55 ResolutionImpact impact1, ResolutionImpact impact2, | |
56 {bool verbose: false}) { | |
57 if (impact1 == null || impact2 == null) return; | |
58 | |
59 if (verbose) { | |
60 print('Checking impacts for $element1 vs $element2'); | |
61 } | |
62 | |
63 testResolutionImpactEquivalence(impact1, impact2, const CheckStrategy()); | |
64 } | |
65 | |
66 | |
67 /// Check equivalence between all resolution impacts common to [compiler1] and | |
68 /// [compiler2]. | |
69 void checkResolutionImpacts( | |
70 Compiler compiler1, | |
71 Compiler compiler2, | |
72 {bool verbose: false}) { | |
73 | |
74 void checkMembers(Element member1, Element member2) { | |
75 if (member1.isClass && member2.isClass) { | |
76 ClassElement class1 = member1; | |
77 ClassElement class2 = member2; | |
78 class1.forEachLocalMember((m1) { | |
79 checkMembers(m1, class2.lookupLocalMember(m1.name)); | |
80 }); | |
81 return; | |
82 } | |
83 | |
84 if (!compiler1.resolution.hasResolutionImpact(member1)) { | |
85 return; | |
86 } | |
87 | |
88 if (member2 == null) { | |
89 return; | |
90 } | |
91 | |
92 if (areElementsEquivalent(member1, member2)) { | |
93 checkImpacts( | |
94 member1, member2, | |
95 compiler1.resolution.getResolutionImpact(member1), | |
96 compiler2.serialization.deserializer.getResolutionImpact(member2), | |
97 verbose: verbose); | |
98 } | |
99 } | |
100 | |
101 for (LibraryElement library1 in compiler1.libraryLoader.libraries) { | |
102 LibraryElement library2 = | |
103 compiler2.libraryLoader.lookupLibrary(library1.canonicalUri); | |
104 if (library2 != null) { | |
105 library1.forEachLocalMember((Element member1) { | |
106 checkMembers(member1, library2.localLookup(member1.name)); | |
107 }); | |
108 | |
109 } | |
110 } | |
111 } | |
OLD | NEW |