Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/common.dart'; |
| 14 import 'package:compiler/src/constants/values.dart'; | 14 import 'package:compiler/src/constants/values.dart'; |
| 15 import 'package:compiler/src/compiler.dart'; | 15 import 'package:compiler/src/compiler.dart'; |
| 16 import 'package:compiler/src/elements/resolution_types.dart'; | 16 import 'package:compiler/src/elements/resolution_types.dart'; |
| 17 import 'package:compiler/src/elements/types.dart'; | 17 import 'package:compiler/src/elements/types.dart'; |
| 18 import 'package:compiler/src/deferred_load.dart'; | 18 import 'package:compiler/src/deferred_load.dart'; |
| 19 import 'package:compiler/src/elements/elements.dart'; | 19 import 'package:compiler/src/elements/elements.dart'; |
| 20 import 'package:compiler/src/elements/entities.dart'; | 20 import 'package:compiler/src/elements/entities.dart'; |
| 21 import 'package:compiler/src/enqueue.dart'; | 21 import 'package:compiler/src/enqueue.dart'; |
| 22 import 'package:compiler/src/filenames.dart'; | 22 import 'package:compiler/src/filenames.dart'; |
| 23 import 'package:compiler/src/js_backend/js_backend.dart'; | 23 import 'package:compiler/src/js_backend/js_backend.dart'; |
| 24 import 'package:compiler/src/js_backend/backend_usage.dart'; | 24 import 'package:compiler/src/js_backend/backend_usage.dart'; |
| 25 import 'package:compiler/src/js_backend/native_data.dart'; | |
| 26 import 'package:compiler/src/js_backend/interceptor_data.dart'; | |
| 25 import 'package:compiler/src/serialization/equivalence.dart'; | 27 import 'package:compiler/src/serialization/equivalence.dart'; |
| 26 import 'package:compiler/src/tree/nodes.dart'; | 28 import 'package:compiler/src/tree/nodes.dart'; |
| 27 import 'package:compiler/src/universe/class_set.dart'; | 29 import 'package:compiler/src/universe/class_set.dart'; |
| 28 import 'package:compiler/src/universe/world_builder.dart'; | 30 import 'package:compiler/src/universe/world_builder.dart'; |
| 29 import 'package:compiler/src/util/enumset.dart'; | 31 import 'package:compiler/src/util/enumset.dart'; |
| 30 import 'package:compiler/src/world.dart' show ClosedWorld; | 32 import 'package:compiler/src/world.dart' show ClosedWorld; |
| 31 import '../memory_compiler.dart'; | 33 import '../memory_compiler.dart'; |
| 32 import 'helper.dart'; | 34 import 'helper.dart'; |
| 33 import 'test_data.dart'; | 35 import 'test_data.dart'; |
| 34 import 'test_helper.dart'; | 36 import 'test_helper.dart'; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 checkAllImpacts(compilerNormal, compilerDeserialized, verbose: verbose); | 102 checkAllImpacts(compilerNormal, compilerDeserialized, verbose: verbose); |
| 101 checkResolutionEnqueuers( | 103 checkResolutionEnqueuers( |
| 102 compilerNormal.backend.backendUsage, | 104 compilerNormal.backend.backendUsage, |
| 103 compilerDeserialized.backend.backendUsage, | 105 compilerDeserialized.backend.backendUsage, |
| 104 compilerNormal.enqueuer.resolution, | 106 compilerNormal.enqueuer.resolution, |
| 105 compilerDeserialized.enqueuer.resolution, | 107 compilerDeserialized.enqueuer.resolution, |
| 106 verbose: verbose); | 108 verbose: verbose); |
| 107 checkClosedWorlds( | 109 checkClosedWorlds( |
| 108 compilerNormal.resolutionWorldBuilder.closedWorldForTesting, | 110 compilerNormal.resolutionWorldBuilder.closedWorldForTesting, |
| 109 compilerDeserialized.resolutionWorldBuilder.closedWorldForTesting, | 111 compilerDeserialized.resolutionWorldBuilder.closedWorldForTesting, |
| 110 areElementsEquivalent, | 112 // Serialized native data include non-live members. |
| 113 allowExtra: true, | |
| 111 verbose: verbose); | 114 verbose: verbose); |
| 112 checkBackendInfo(compilerNormal, compilerDeserialized, verbose: verbose); | 115 checkBackendInfo(compilerNormal, compilerDeserialized, verbose: verbose); |
| 113 }); | 116 }); |
| 114 } | 117 } |
| 115 | 118 |
| 116 void checkResolutionEnqueuers( | 119 void checkResolutionEnqueuers( |
| 117 BackendUsage backendUsage1, | 120 BackendUsage backendUsage1, |
| 118 BackendUsage backendUsage2, | 121 BackendUsage backendUsage2, |
| 119 ResolutionEnqueuer enqueuer1, | 122 ResolutionEnqueuer enqueuer1, |
| 120 ResolutionEnqueuer enqueuer2, | 123 ResolutionEnqueuer enqueuer2, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 "JavaScriptBackend.hasFunctionApplySupport mismatch"); | 168 "JavaScriptBackend.hasFunctionApplySupport mismatch"); |
| 166 Expect.equals( | 169 Expect.equals( |
| 167 backendUsage1.isRuntimeTypeUsed, | 170 backendUsage1.isRuntimeTypeUsed, |
| 168 backendUsage2.isRuntimeTypeUsed, | 171 backendUsage2.isRuntimeTypeUsed, |
| 169 "JavaScriptBackend.hasRuntimeTypeSupport mismatch"); | 172 "JavaScriptBackend.hasRuntimeTypeSupport mismatch"); |
| 170 Expect.equals(backendUsage1.isIsolateInUse, backendUsage2.isIsolateInUse, | 173 Expect.equals(backendUsage1.isIsolateInUse, backendUsage2.isIsolateInUse, |
| 171 "JavaScriptBackend.hasIsolateSupport mismatch"); | 174 "JavaScriptBackend.hasIsolateSupport mismatch"); |
| 172 } | 175 } |
| 173 | 176 |
| 174 void checkClosedWorlds(ClosedWorld closedWorld1, ClosedWorld closedWorld2, | 177 void checkClosedWorlds(ClosedWorld closedWorld1, ClosedWorld closedWorld2, |
| 175 bool elementEquivalence(Entity a, Entity b), | 178 {TestStrategy strategy: const TestStrategy(), |
| 176 {bool verbose: false}) { | 179 bool allowExtra: false, |
| 180 bool verbose: false}) { | |
| 177 if (verbose) { | 181 if (verbose) { |
| 178 print(closedWorld1.dump()); | 182 print(closedWorld1.dump()); |
| 179 print(closedWorld2.dump()); | 183 print(closedWorld2.dump()); |
| 180 } | 184 } |
| 181 checkClassHierarchyNodes( | 185 checkClassHierarchyNodes( |
| 182 closedWorld1, | 186 closedWorld1, |
| 183 closedWorld2, | 187 closedWorld2, |
| 184 closedWorld1 | 188 closedWorld1 |
| 185 .getClassHierarchyNode(closedWorld1.commonElements.objectClass), | 189 .getClassHierarchyNode(closedWorld1.commonElements.objectClass), |
| 186 closedWorld2 | 190 closedWorld2 |
| 187 .getClassHierarchyNode(closedWorld2.commonElements.objectClass), | 191 .getClassHierarchyNode(closedWorld2.commonElements.objectClass), |
| 188 elementEquivalence, | 192 strategy.elementEquivalence, |
| 193 verbose: verbose); | |
| 194 | |
| 195 checkNativeData(closedWorld1.nativeData, closedWorld2.nativeData, | |
| 196 strategy: strategy, allowExtra: allowExtra, verbose: verbose); | |
| 197 checkInterceptorData(closedWorld1.interceptorData, | |
| 198 closedWorld2.interceptorData, strategy.elementEquivalence, | |
| 189 verbose: verbose); | 199 verbose: verbose); |
| 190 } | 200 } |
| 191 | 201 |
| 202 void checkNativeData(NativeDataImpl data1, NativeDataImpl data2, | |
| 203 {TestStrategy strategy: const TestStrategy(), | |
| 204 bool allowExtra: false, | |
| 205 bool verbose: false}) { | |
| 206 checkMapEquivalence(data1, data2, 'nativeMemberName', data1.nativeMemberName, | |
| 207 data2.nativeMemberName, strategy.elementEquivalence, equality, | |
| 208 allowExtra: allowExtra); | |
| 209 | |
| 210 checkMapEquivalence( | |
| 211 data1, | |
| 212 data2, | |
| 213 'nativeMethodBehavior', | |
| 214 data1.nativeMethodBehavior, | |
| 215 data2.nativeMethodBehavior, | |
|
Siggi Cherem (dart-lang)
2017/05/10 16:50:05
not for this CL, but I keep trying to think of way
Johnni Winther
2017/05/11 12:01:32
Acknowledged.
| |
| 216 strategy.elementEquivalence, | |
| 217 (a, b) => testNativeBehavior(a, b, strategy: strategy), | |
| 218 allowExtra: allowExtra); | |
| 219 | |
| 220 checkMapEquivalence( | |
| 221 data1, | |
| 222 data2, | |
| 223 'nativeFieldLoadBehavior', | |
| 224 data1.nativeFieldLoadBehavior, | |
| 225 data2.nativeFieldLoadBehavior, | |
| 226 strategy.elementEquivalence, | |
| 227 (a, b) => testNativeBehavior(a, b, strategy: strategy), | |
| 228 allowExtra: allowExtra); | |
| 229 | |
| 230 checkMapEquivalence( | |
| 231 data1, | |
| 232 data2, | |
| 233 'nativeFieldStoreBehavior', | |
| 234 data1.nativeFieldStoreBehavior, | |
| 235 data2.nativeFieldStoreBehavior, | |
| 236 strategy.elementEquivalence, | |
| 237 (a, b) => testNativeBehavior(a, b, strategy: strategy), | |
| 238 allowExtra: allowExtra); | |
| 239 | |
| 240 checkMapEquivalence( | |
| 241 data1, | |
| 242 data2, | |
| 243 'jsInteropLibraryNames', | |
| 244 data1.jsInteropLibraryNames, | |
| 245 data2.jsInteropLibraryNames, | |
| 246 strategy.elementEquivalence, | |
| 247 equality); | |
| 248 | |
| 249 checkSetEquivalence( | |
| 250 data1, | |
| 251 data2, | |
| 252 'anonymousJsInteropClasses', | |
| 253 data1.anonymousJsInteropClasses, | |
| 254 data2.anonymousJsInteropClasses, | |
| 255 strategy.elementEquivalence); | |
| 256 | |
| 257 checkMapEquivalence( | |
| 258 data1, | |
| 259 data2, | |
| 260 'jsInteropClassNames', | |
| 261 data1.jsInteropClassNames, | |
| 262 data2.jsInteropClassNames, | |
| 263 strategy.elementEquivalence, | |
| 264 equality); | |
| 265 | |
| 266 checkMapEquivalence( | |
| 267 data1, | |
| 268 data2, | |
| 269 'jsInteropMemberNames', | |
| 270 data1.jsInteropMemberNames, | |
| 271 data2.jsInteropMemberNames, | |
| 272 strategy.elementEquivalence, | |
| 273 equality); | |
| 274 } | |
| 275 | |
| 276 void checkInterceptorData(InterceptorDataImpl data1, InterceptorDataImpl data2, | |
| 277 bool elementEquivalence(Entity a, Entity b), | |
| 278 {bool verbose: false}) { | |
| 279 checkMapEquivalence( | |
| 280 data1, | |
| 281 data2, | |
| 282 'interceptedElements', | |
| 283 data1.interceptedElementsForTesting, | |
| 284 data2.interceptedElementsForTesting, | |
| 285 equality, | |
| 286 (a, b) => areSetsEquivalent(a, b, elementEquivalence)); | |
| 287 | |
| 288 checkSetEquivalence(data1, data2, 'interceptedClasses', | |
| 289 data1.interceptedClasses, data2.interceptedClasses, elementEquivalence); | |
| 290 | |
| 291 checkSetEquivalence( | |
| 292 data1, | |
| 293 data2, | |
| 294 'classesMixedIntoInterceptedClasses', | |
| 295 data1.classesMixedIntoInterceptedClassesForTesting, | |
| 296 data2.classesMixedIntoInterceptedClassesForTesting, | |
| 297 elementEquivalence); | |
| 298 } | |
| 299 | |
| 192 void checkBackendInfo(Compiler compilerNormal, Compiler compilerDeserialized, | 300 void checkBackendInfo(Compiler compilerNormal, Compiler compilerDeserialized, |
| 193 {bool verbose: false}) { | 301 {bool verbose: false}) { |
| 194 checkSets( | 302 checkSets( |
| 195 compilerNormal.enqueuer.resolution.processedEntities, | 303 compilerNormal.enqueuer.resolution.processedEntities, |
| 196 compilerDeserialized.enqueuer.resolution.processedEntities, | 304 compilerDeserialized.enqueuer.resolution.processedEntities, |
| 197 "Processed element mismatch", | 305 "Processed element mismatch", |
| 198 areElementsEquivalent, onSameElement: (a, b) { | 306 areElementsEquivalent, onSameElement: (a, b) { |
| 199 checkElements(compilerNormal, compilerDeserialized, a, b, verbose: verbose); | 307 checkElements(compilerNormal, compilerDeserialized, a, b, verbose: verbose); |
| 200 }, verbose: verbose); | 308 }, verbose: verbose); |
| 201 Expect.equals( | 309 Expect.equals( |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 } | 582 } |
| 475 | 583 |
| 476 bool areInstancesEquivalent(Instance instance1, Instance instance2, | 584 bool areInstancesEquivalent(Instance instance1, Instance instance2, |
| 477 bool typeEquivalence(DartType a, DartType b)) { | 585 bool typeEquivalence(DartType a, DartType b)) { |
| 478 InterfaceType type1 = instance1.type; | 586 InterfaceType type1 = instance1.type; |
| 479 InterfaceType type2 = instance2.type; | 587 InterfaceType type2 = instance2.type; |
| 480 return typeEquivalence(type1, type2) && | 588 return typeEquivalence(type1, type2) && |
| 481 instance1.kind == instance2.kind && | 589 instance1.kind == instance2.kind && |
| 482 instance1.isRedirection == instance2.isRedirection; | 590 instance1.isRedirection == instance2.isRedirection; |
| 483 } | 591 } |
| OLD | NEW |