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