| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 // Partial test that the closed world computed from [WorldImpact]s derived from | 5 // Partial test that the closed world computed from [WorldImpact]s derived from |
| 6 // kernel is equivalent to the original computed from resolution. | 6 // kernel is equivalent to the original computed from resolution. |
| 7 library dart2js.kernel.closed_world2_test; | 7 library dart2js.kernel.closed_world2_test; |
| 8 | 8 |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 import 'package:compiler/src/js_backend/no_such_method_registry.dart'; | 35 import 'package:compiler/src/js_backend/no_such_method_registry.dart'; |
| 36 import 'package:compiler/src/js_backend/resolution_listener.dart'; | 36 import 'package:compiler/src/js_backend/resolution_listener.dart'; |
| 37 import 'package:compiler/src/js_backend/type_variable_handler.dart'; | 37 import 'package:compiler/src/js_backend/type_variable_handler.dart'; |
| 38 import 'package:compiler/src/native/enqueue.dart'; | 38 import 'package:compiler/src/native/enqueue.dart'; |
| 39 import 'package:compiler/src/native/resolver.dart'; | 39 import 'package:compiler/src/native/resolver.dart'; |
| 40 import 'package:compiler/src/kernel/element_map.dart'; | 40 import 'package:compiler/src/kernel/element_map.dart'; |
| 41 import 'package:compiler/src/kernel/kernel_strategy.dart'; | 41 import 'package:compiler/src/kernel/kernel_strategy.dart'; |
| 42 import 'package:compiler/src/library_loader.dart'; | 42 import 'package:compiler/src/library_loader.dart'; |
| 43 import 'package:compiler/src/options.dart'; | 43 import 'package:compiler/src/options.dart'; |
| 44 import 'package:compiler/src/universe/world_builder.dart'; | 44 import 'package:compiler/src/universe/world_builder.dart'; |
| 45 import 'package:compiler/src/util/util.dart'; |
| 45 import 'package:compiler/src/world.dart'; | 46 import 'package:compiler/src/world.dart'; |
| 46 import 'package:expect/expect.dart'; | 47 import 'package:expect/expect.dart'; |
| 47 import 'package:kernel/ast.dart' as ir; | 48 import 'package:kernel/ast.dart' as ir; |
| 48 import '../memory_compiler.dart'; | 49 import '../memory_compiler.dart'; |
| 49 import '../serialization/helper.dart'; | 50 import '../serialization/helper.dart'; |
| 50 import '../serialization/model_test_helper.dart'; | 51 import '../serialization/model_test_helper.dart'; |
| 51 import '../serialization/test_helper.dart'; | 52 import '../serialization/test_helper.dart'; |
| 52 | 53 |
| 53 import 'closed_world_test.dart' hide KernelWorkItemBuilder; | 54 import 'closed_world_test.dart' hide KernelWorkItemBuilder; |
| 55 import 'compiler_helper.dart'; |
| 54 import 'impact_test.dart'; | 56 import 'impact_test.dart'; |
| 55 | 57 |
| 56 const SOURCE = const { | 58 const SOURCE = const { |
| 57 'main.dart': ''' | 59 'main.dart': ''' |
| 58 import 'dart:html'; | 60 import 'dart:html'; |
| 59 import 'dart:typed_data'; | 61 import 'dart:typed_data'; |
| 60 import 'package:expect/expect.dart'; | 62 import 'package:expect/expect.dart'; |
| 61 | 63 |
| 62 class ClassWithSetter { | 64 class ClassWithSetter { |
| 63 void set setter(_) {} | 65 void set setter(_) {} |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 137 } |
| 136 if (collector.warnings.isNotEmpty && skipWarnings) { | 138 if (collector.warnings.isNotEmpty && skipWarnings) { |
| 137 print('Skipping due to warnings.'); | 139 print('Skipping due to warnings.'); |
| 138 return ResultKind.warnings; | 140 return ResultKind.warnings; |
| 139 } | 141 } |
| 140 Expect.isFalse(compiler1.compilationFailed); | 142 Expect.isFalse(compiler1.compilationFailed); |
| 141 ResolutionEnqueuer enqueuer1 = compiler1.enqueuer.resolution; | 143 ResolutionEnqueuer enqueuer1 = compiler1.enqueuer.resolution; |
| 142 BackendUsage backendUsage1 = compiler1.backend.backendUsage; | 144 BackendUsage backendUsage1 = compiler1.backend.backendUsage; |
| 143 ClosedWorld closedWorld1 = compiler1.resolutionWorldBuilder.closeWorld(); | 145 ClosedWorld closedWorld1 = compiler1.resolutionWorldBuilder.closeWorld(); |
| 144 | 146 |
| 145 print('---- analyze-all -------------------------------------------------'); | 147 Pair<Compiler, Compiler> compilers = |
| 146 Compiler compiler = compilerFor( | 148 await analyzeOnly(entryPoint, memorySourceFiles, printSteps: true); |
| 147 entryPoint: entryPoint, | 149 Compiler compiler = compilers.a; |
| 148 memorySourceFiles: memorySourceFiles, | |
| 149 options: [Flags.analyzeAll, Flags.useKernel, Flags.enableAssertMessage]); | |
| 150 await compiler.run(entryPoint); | |
| 151 compiler.resolutionWorldBuilder.closeWorld(); | 150 compiler.resolutionWorldBuilder.closeWorld(); |
| 152 ElementEnvironment environment1 = compiler.elementEnvironment; | 151 ElementEnvironment environment1 = compiler.elementEnvironment; |
| 153 | 152 |
| 154 print('---- closed world from kernel ------------------------------------'); | 153 Compiler compiler2 = compilers.b; |
| 155 Compiler compiler2 = compilerFor( | |
| 156 entryPoint: entryPoint, | |
| 157 memorySourceFiles: memorySourceFiles, | |
| 158 options: [ | |
| 159 Flags.analyzeOnly, | |
| 160 Flags.enableAssertMessage, | |
| 161 Flags.loadFromDill | |
| 162 ]); | |
| 163 ElementResolutionWorldBuilder.useInstantiationMap = true; | |
| 164 compiler2.resolution.retainCachesForTesting = true; | |
| 165 KernelFrontEndStrategy frontEndStrategy = compiler2.frontEndStrategy; | 154 KernelFrontEndStrategy frontEndStrategy = compiler2.frontEndStrategy; |
| 166 KernelToElementMap elementMap = frontEndStrategy.elementMap; | 155 KernelToElementMap elementMap = frontEndStrategy.elementMap; |
| 167 compiler2.libraryLoader = new MemoryDillLibraryLoaderTask( | |
| 168 elementMap, | |
| 169 compiler2.reporter, | |
| 170 compiler2.measurer, | |
| 171 compiler.backend.kernelTask.program); | |
| 172 await compiler2.run(entryPoint); | |
| 173 Expect.isFalse(compiler2.compilationFailed); | 156 Expect.isFalse(compiler2.compilationFailed); |
| 174 | 157 |
| 175 KernelEquivalence equivalence = new KernelEquivalence(elementMap); | 158 KernelEquivalence equivalence = new KernelEquivalence(elementMap); |
| 176 | 159 |
| 177 ElementEnvironment environment2 = compiler2.elementEnvironment; | 160 ElementEnvironment environment2 = compiler2.elementEnvironment; |
| 178 checkElementEnvironment(environment1, environment2, equivalence); | 161 checkElementEnvironment(environment1, environment2, equivalence); |
| 179 | 162 |
| 180 ResolutionEnqueuer enqueuer2 = compiler2.enqueuer.resolution; | 163 ResolutionEnqueuer enqueuer2 = compiler2.enqueuer.resolution; |
| 181 BackendUsage backendUsage2 = compiler2.backend.backendUsage; | 164 BackendUsage backendUsage2 = compiler2.backend.backendUsage; |
| 182 ClosedWorld closedWorld2 = compiler2.resolutionWorldBuilder.closeWorld(); | 165 ClosedWorld closedWorld2 = compiler2.resolutionWorldBuilder.closeWorld(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 277 |
| 295 classes2.add(cls2); | 278 classes2.add(cls2); |
| 296 }); | 279 }); |
| 297 env2.forEachClass(lib2, (ClassEntity cls2) { | 280 env2.forEachClass(lib2, (ClassEntity cls2) { |
| 298 Expect.isTrue(classes2.contains(cls2), "Extra class $cls2 in $lib2"); | 281 Expect.isTrue(classes2.contains(cls2), "Extra class $cls2 in $lib2"); |
| 299 }); | 282 }); |
| 300 }); | 283 }); |
| 301 | 284 |
| 302 // TODO(johnniwinther): Test the remaining properties of [ElementEnvironment]. | 285 // TODO(johnniwinther): Test the remaining properties of [ElementEnvironment]. |
| 303 } | 286 } |
| 304 | |
| 305 class MemoryDillLibraryLoaderTask extends DillLibraryLoaderTask { | |
| 306 final ir.Program program; | |
| 307 | |
| 308 MemoryDillLibraryLoaderTask(KernelToElementMap elementMap, | |
| 309 DiagnosticReporter reporter, Measurer measurer, this.program) | |
| 310 : super(elementMap, null, null, reporter, measurer); | |
| 311 | |
| 312 Future<LoadedLibraries> loadLibrary(Uri resolvedUri, | |
| 313 {bool skipFileWithPartOfTag: false}) async { | |
| 314 return createLoadedLibraries(program); | |
| 315 } | |
| 316 } | |
| OLD | NEW |