| 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 // Tests that the closed world computed from [WorldImpact]s derived from kernel | 5 // Tests that the closed world computed from [WorldImpact]s derived from kernel |
| 6 // is equivalent to the original computed from resolution. | 6 // is equivalent to the original computed from resolution. |
| 7 library dart2js.kernel.closed_world_test; | 7 library dart2js.kernel.closed_world_test; |
| 8 | 8 |
| 9 import 'package:async_helper/async_helper.dart'; | 9 import 'package:async_helper/async_helper.dart'; |
| 10 import 'package:compiler/src/closure.dart'; | |
| 11 import 'package:compiler/src/commandline_options.dart'; | 10 import 'package:compiler/src/commandline_options.dart'; |
| 12 import 'package:compiler/src/common.dart'; | 11 import 'package:compiler/src/common.dart'; |
| 13 import 'package:compiler/src/common_elements.dart'; | 12 import 'package:compiler/src/common_elements.dart'; |
| 14 import 'package:compiler/src/common/backend_api.dart'; | 13 import 'package:compiler/src/common/backend_api.dart'; |
| 15 import 'package:compiler/src/common/resolution.dart'; | 14 import 'package:compiler/src/common/resolution.dart'; |
| 16 import 'package:compiler/src/common/work.dart'; | 15 import 'package:compiler/src/common/work.dart'; |
| 17 import 'package:compiler/src/compiler.dart'; | 16 import 'package:compiler/src/compiler.dart'; |
| 18 import 'package:compiler/src/deferred_load.dart'; | |
| 19 import 'package:compiler/src/elements/resolution_types.dart'; | 17 import 'package:compiler/src/elements/resolution_types.dart'; |
| 20 import 'package:compiler/src/elements/elements.dart'; | 18 import 'package:compiler/src/elements/elements.dart'; |
| 21 import 'package:compiler/src/elements/entities.dart'; | 19 import 'package:compiler/src/elements/entities.dart'; |
| 22 import 'package:compiler/src/elements/types.dart'; | |
| 23 import 'package:compiler/src/enqueue.dart'; | 20 import 'package:compiler/src/enqueue.dart'; |
| 24 import 'package:compiler/src/js_backend/backend.dart'; | 21 import 'package:compiler/src/js_backend/backend.dart'; |
| 25 import 'package:compiler/src/js_backend/backend_impact.dart'; | |
| 26 import 'package:compiler/src/js_backend/backend_usage.dart'; | 22 import 'package:compiler/src/js_backend/backend_usage.dart'; |
| 27 import 'package:compiler/src/js_backend/custom_elements_analysis.dart'; | |
| 28 import 'package:compiler/src/js_backend/native_data.dart'; | |
| 29 import 'package:compiler/src/js_backend/impact_transformer.dart'; | |
| 30 import 'package:compiler/src/js_backend/interceptor_data.dart'; | 23 import 'package:compiler/src/js_backend/interceptor_data.dart'; |
| 31 import 'package:compiler/src/js_backend/lookup_map_analysis.dart'; | |
| 32 import 'package:compiler/src/js_backend/mirrors_analysis.dart'; | |
| 33 import 'package:compiler/src/js_backend/mirrors_data.dart'; | |
| 34 import 'package:compiler/src/js_backend/no_such_method_registry.dart'; | |
| 35 import 'package:compiler/src/js_backend/resolution_listener.dart'; | 24 import 'package:compiler/src/js_backend/resolution_listener.dart'; |
| 36 import 'package:compiler/src/js_backend/type_variable_handler.dart'; | 25 import 'package:compiler/src/js_backend/type_variable_handler.dart'; |
| 37 import 'package:compiler/src/native/enqueue.dart'; | |
| 38 import 'package:compiler/src/kernel/world_builder.dart'; | |
| 39 import 'package:compiler/src/options.dart'; | |
| 40 import 'package:compiler/src/ssa/kernel_impact.dart'; | 26 import 'package:compiler/src/ssa/kernel_impact.dart'; |
| 41 import 'package:compiler/src/serialization/equivalence.dart'; | 27 import 'package:compiler/src/serialization/equivalence.dart'; |
| 42 import 'package:compiler/src/universe/world_builder.dart'; | 28 import 'package:compiler/src/universe/world_builder.dart'; |
| 43 import 'package:compiler/src/universe/world_impact.dart'; | 29 import 'package:compiler/src/universe/world_impact.dart'; |
| 44 import 'package:compiler/src/world.dart'; | 30 import 'package:compiler/src/world.dart'; |
| 45 import 'package:kernel/ast.dart' as ir; | |
| 46 import 'impact_test.dart'; | 31 import 'impact_test.dart'; |
| 47 import '../memory_compiler.dart'; | 32 import '../memory_compiler.dart'; |
| 48 import '../serialization/helper.dart'; | 33 import '../serialization/helper.dart'; |
| 49 import '../serialization/model_test_helper.dart'; | 34 import '../serialization/model_test_helper.dart'; |
| 50 | 35 |
| 51 const SOURCE = const { | 36 const SOURCE = const { |
| 52 'main.dart': ''' | 37 'main.dart': ''' |
| 53 abstract class A { | 38 abstract class A { |
| 54 // redirecting factory in abstract class to other class | 39 // redirecting factory in abstract class to other class |
| 55 factory A.a() = D.a; | 40 factory A.a() = D.a; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 backend, compiler.resolution, const OpenWorldStrategy()), | 103 backend, compiler.resolution, const OpenWorldStrategy()), |
| 119 new KernelWorkItemBuilder(compiler), | 104 new KernelWorkItemBuilder(compiler), |
| 120 'enqueuer from kernel'); | 105 'enqueuer from kernel'); |
| 121 ClosedWorld closedWorld = computeClosedWorld( | 106 ClosedWorld closedWorld = computeClosedWorld( |
| 122 compiler.reporter, enqueuer, compiler.elementEnvironment); | 107 compiler.reporter, enqueuer, compiler.elementEnvironment); |
| 123 BackendUsage backendUsage = backendUsageBuilder.close(); | 108 BackendUsage backendUsage = backendUsageBuilder.close(); |
| 124 checkResolutionEnqueuers( | 109 checkResolutionEnqueuers( |
| 125 backendUsage, backendUsage, compiler.enqueuer.resolution, enqueuer, | 110 backendUsage, backendUsage, compiler.enqueuer.resolution, enqueuer, |
| 126 typeEquivalence: (ResolutionDartType a, ResolutionDartType b) { | 111 typeEquivalence: (ResolutionDartType a, ResolutionDartType b) { |
| 127 return areTypesEquivalent(unalias(a), unalias(b)); | 112 return areTypesEquivalent(unalias(a), unalias(b)); |
| 128 }, elementFilter: (Element element) { | 113 }, elementFilter: elementFilter, verbose: arguments.verbose); |
| 129 if (element is ConstructorElement && element.isRedirectingFactory) { | |
| 130 // Redirecting factory constructors are skipped in kernel. | |
| 131 return false; | |
| 132 } | |
| 133 if (element is ClassElement) { | |
| 134 for (ConstructorElement constructor in element.constructors) { | |
| 135 if (!constructor.isRedirectingFactory) { | |
| 136 return true; | |
| 137 } | |
| 138 } | |
| 139 // The class cannot itself be instantiated. | |
| 140 return false; | |
| 141 } | |
| 142 return true; | |
| 143 }, verbose: arguments.verbose); | |
| 144 checkClosedWorlds( | 114 checkClosedWorlds( |
| 145 compiler.resolutionWorldBuilder.closedWorldForTesting, closedWorld, | 115 compiler.resolutionWorldBuilder.closedWorldForTesting, closedWorld, |
| 146 verbose: arguments.verbose); | 116 verbose: arguments.verbose); |
| 147 }); | 117 }); |
| 148 } | 118 } |
| 149 | 119 |
| 120 bool elementFilter(Entity element) { |
| 121 if (element is ConstructorElement && element.isRedirectingFactory) { |
| 122 // Redirecting factory constructors are skipped in kernel. |
| 123 return false; |
| 124 } |
| 125 if (element is ClassElement) { |
| 126 for (ConstructorElement constructor in element.constructors) { |
| 127 if (!constructor.isRedirectingFactory) { |
| 128 return true; |
| 129 } |
| 130 } |
| 131 // The class cannot itself be instantiated. |
| 132 return false; |
| 133 } |
| 134 return true; |
| 135 } |
| 136 |
| 150 List createResolutionEnqueuerListener(Compiler compiler) { | 137 List createResolutionEnqueuerListener(Compiler compiler) { |
| 151 JavaScriptBackend backend = compiler.backend; | 138 JavaScriptBackend backend = compiler.backend; |
| 152 BackendUsageBuilder backendUsageBuilder = | 139 BackendUsageBuilder backendUsageBuilder = |
| 153 new BackendUsageBuilderImpl(compiler.commonElements); | 140 new BackendUsageBuilderImpl(compiler.commonElements); |
| 154 ResolutionEnqueuerListener listener = new ResolutionEnqueuerListener( | 141 ResolutionEnqueuerListener listener = new ResolutionEnqueuerListener( |
| 155 compiler.options, | 142 compiler.options, |
| 156 compiler.elementEnvironment, | 143 compiler.elementEnvironment, |
| 157 compiler.commonElements, | 144 compiler.commonElements, |
| 158 backend.impacts, | 145 backend.impacts, |
| 159 backend.nativeBasicData, | 146 backend.nativeBasicData, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 final MemberElement element; | 189 final MemberElement element; |
| 203 | 190 |
| 204 KernelWorkItem(this._compiler, this._impactTransformer, this.element); | 191 KernelWorkItem(this._compiler, this._impactTransformer, this.element); |
| 205 | 192 |
| 206 @override | 193 @override |
| 207 WorldImpact run() { | 194 WorldImpact run() { |
| 208 ResolutionImpact resolutionImpact = build(_compiler, element.resolvedAst); | 195 ResolutionImpact resolutionImpact = build(_compiler, element.resolvedAst); |
| 209 return _impactTransformer.transformResolutionImpact(resolutionImpact); | 196 return _impactTransformer.transformResolutionImpact(resolutionImpact); |
| 210 } | 197 } |
| 211 } | 198 } |
| OLD | NEW |