| 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 // Partial test that the closed world computed from [WorldImpact]s derived from |
| 6 // kernel is equivalent to the original computed from resolution. |
| 7 library dart2js.kernel.closed_world2_test; |
| 8 |
| 9 import 'package:async_helper/async_helper.dart'; |
| 10 import 'package:compiler/src/closure.dart'; |
| 11 import 'package:compiler/src/commandline_options.dart'; |
| 12 import 'package:compiler/src/common.dart'; |
| 13 import 'package:compiler/src/common_elements.dart'; |
| 14 import 'package:compiler/src/common/backend_api.dart'; |
| 15 import 'package:compiler/src/common/resolution.dart'; |
| 16 import 'package:compiler/src/common/work.dart'; |
| 17 import 'package:compiler/src/compiler.dart'; |
| 18 import 'package:compiler/src/deferred_load.dart'; |
| 19 import 'package:compiler/src/elements/resolution_types.dart'; |
| 20 import 'package:compiler/src/elements/elements.dart'; |
| 21 import 'package:compiler/src/elements/entities.dart'; |
| 22 import 'package:compiler/src/elements/types.dart'; |
| 23 import 'package:compiler/src/enqueue.dart'; |
| 24 import 'package:compiler/src/js_backend/backend.dart'; |
| 25 import 'package:compiler/src/js_backend/backend_helpers.dart'; |
| 26 import 'package:compiler/src/js_backend/backend_impact.dart'; |
| 27 import 'package:compiler/src/js_backend/backend_usage.dart'; |
| 28 import 'package:compiler/src/js_backend/custom_elements_analysis.dart'; |
| 29 import 'package:compiler/src/js_backend/native_data.dart'; |
| 30 import 'package:compiler/src/js_backend/impact_transformer.dart'; |
| 31 import 'package:compiler/src/js_backend/interceptor_data.dart'; |
| 32 import 'package:compiler/src/js_backend/lookup_map_analysis.dart'; |
| 33 import 'package:compiler/src/js_backend/mirrors_analysis.dart'; |
| 34 import 'package:compiler/src/js_backend/mirrors_data.dart'; |
| 35 import 'package:compiler/src/js_backend/no_such_method_registry.dart'; |
| 36 import 'package:compiler/src/js_backend/resolution_listener.dart'; |
| 37 import 'package:compiler/src/js_backend/type_variable_handler.dart'; |
| 38 import 'package:compiler/src/native/enqueue.dart'; |
| 39 import 'package:compiler/src/kernel/world_builder.dart'; |
| 40 import 'package:compiler/src/options.dart'; |
| 41 import 'package:compiler/src/universe/world_builder.dart'; |
| 42 import 'package:compiler/src/universe/world_impact.dart'; |
| 43 import 'package:compiler/src/world.dart'; |
| 44 import '../memory_compiler.dart'; |
| 45 import '../serialization/helper.dart'; |
| 46 |
| 47 import 'closed_world_test.dart'; |
| 48 |
| 49 main(List<String> args) { |
| 50 Arguments arguments = new Arguments.from(args); |
| 51 Uri entryPoint; |
| 52 Map<String, String> memorySourceFiles; |
| 53 if (arguments.uri != null) { |
| 54 entryPoint = arguments.uri; |
| 55 memorySourceFiles = const <String, String>{}; |
| 56 } else { |
| 57 entryPoint = Uri.parse('memory:main.dart'); |
| 58 memorySourceFiles = SOURCE; |
| 59 } |
| 60 |
| 61 asyncTest(() async { |
| 62 enableDebugMode(); |
| 63 Compiler compiler = compilerFor( |
| 64 entryPoint: entryPoint, |
| 65 memorySourceFiles: memorySourceFiles, |
| 66 options: [ |
| 67 Flags.analyzeAll, |
| 68 Flags.useKernel, |
| 69 Flags.enableAssertMessage |
| 70 ]); |
| 71 ElementResolutionWorldBuilder.useInstantiationMap = true; |
| 72 compiler.resolution.retainCachesForTesting = true; |
| 73 await compiler.run(entryPoint); |
| 74 compiler.resolutionWorldBuilder.closeWorld(compiler.reporter); |
| 75 |
| 76 KernelWorldBuilder worldBuilder = new KernelWorldBuilder( |
| 77 compiler.reporter, compiler.backend.kernelTask.program); |
| 78 List list = createKernelResolutionEnqueuerListener( |
| 79 compiler.options, compiler.deferredLoadTask, worldBuilder); |
| 80 ResolutionEnqueuerListener resolutionEnqueuerListener = list[0]; |
| 81 ImpactTransformer impactTransformer = list[1]; |
| 82 ResolutionEnqueuer enqueuer = new ResolutionEnqueuer( |
| 83 compiler.enqueuer, |
| 84 compiler.options, |
| 85 compiler.reporter, |
| 86 const TreeShakingEnqueuerStrategy(), |
| 87 resolutionEnqueuerListener, |
| 88 new KernelResolutionWorldBuilder( |
| 89 worldBuilder.elementEnvironment, |
| 90 worldBuilder.commonElements, |
| 91 new NativeBasicDataImpl(), |
| 92 const OpenWorldStrategy()), |
| 93 new KernelWorkItemBuilder(worldBuilder, impactTransformer), |
| 94 'enqueuer from kelements'); |
| 95 |
| 96 computeClosedWorld( |
| 97 compiler.reporter, enqueuer, worldBuilder.elementEnvironment); |
| 98 }); |
| 99 } |
| 100 |
| 101 List createKernelResolutionEnqueuerListener(CompilerOptions options, |
| 102 DeferredLoadTask deferredLoadTask, KernelWorldBuilder worldBuilder) { |
| 103 ElementEnvironment elementEnvironment = worldBuilder.elementEnvironment; |
| 104 CommonElements commonElements = worldBuilder.commonElements; |
| 105 BackendHelpers helpers = |
| 106 new BackendHelpers(elementEnvironment, commonElements); |
| 107 BackendImpacts impacts = new BackendImpacts(options, commonElements, helpers); |
| 108 |
| 109 // TODO(johnniwinther): Create Kernel based implementations for these: |
| 110 NativeBasicData nativeBasicData = new NativeBasicDataImpl(); |
| 111 RuntimeTypesNeedBuilder rtiNeedBuilder = new RuntimeTypesNeedBuilderImpl(); |
| 112 MirrorsDataBuilder mirrorsDataBuilder = new MirrorsDataBuilderImpl(); |
| 113 CustomElementsResolutionAnalysis customElementsResolutionAnalysis = |
| 114 new CustomElementsResolutionAnalysisImpl(); |
| 115 LookupMapResolutionAnalysis lookupMapResolutionAnalysis = |
| 116 new LookupMapResolutionAnalysisImpl(); |
| 117 MirrorsResolutionAnalysis mirrorsResolutionAnalysis = |
| 118 new MirrorsResolutionAnalysisImpl(); |
| 119 |
| 120 BackendClasses backendClasses = new JavaScriptBackendClasses( |
| 121 elementEnvironment, helpers, nativeBasicData); |
| 122 InterceptorDataBuilder interceptorDataBuilder = |
| 123 new InterceptorDataBuilderImpl( |
| 124 nativeBasicData, helpers, elementEnvironment, commonElements); |
| 125 BackendUsageBuilder backendUsageBuilder = |
| 126 new BackendUsageBuilderImpl(commonElements, helpers); |
| 127 NoSuchMethodRegistry noSuchMethodRegistry = new NoSuchMethodRegistry( |
| 128 helpers, new KernelNoSuchMethodResolver(worldBuilder)); |
| 129 NativeResolutionEnqueuer nativeResolutionEnqueuer = |
| 130 new NativeResolutionEnqueuer( |
| 131 options, |
| 132 elementEnvironment, |
| 133 commonElements, |
| 134 helpers, |
| 135 backendClasses, |
| 136 backendUsageBuilder, |
| 137 new KernelNativeClassResolver(worldBuilder)); |
| 138 |
| 139 ResolutionEnqueuerListener listener = new ResolutionEnqueuerListener( |
| 140 options, |
| 141 elementEnvironment, |
| 142 commonElements, |
| 143 helpers, |
| 144 impacts, |
| 145 backendClasses, |
| 146 nativeBasicData, |
| 147 interceptorDataBuilder, |
| 148 backendUsageBuilder, |
| 149 rtiNeedBuilder, |
| 150 mirrorsDataBuilder, |
| 151 noSuchMethodRegistry, |
| 152 customElementsResolutionAnalysis, |
| 153 lookupMapResolutionAnalysis, |
| 154 mirrorsResolutionAnalysis, |
| 155 new TypeVariableResolutionAnalysis( |
| 156 elementEnvironment, impacts, backendUsageBuilder), |
| 157 nativeResolutionEnqueuer, |
| 158 deferredLoadTask); |
| 159 |
| 160 ImpactTransformer transformer = new JavaScriptImpactTransformer( |
| 161 options, |
| 162 elementEnvironment, |
| 163 commonElements, |
| 164 impacts, |
| 165 nativeBasicData, |
| 166 nativeResolutionEnqueuer, |
| 167 backendUsageBuilder, |
| 168 mirrorsDataBuilder, |
| 169 customElementsResolutionAnalysis, |
| 170 rtiNeedBuilder); |
| 171 return [listener, transformer]; |
| 172 } |
| 173 |
| 174 class NativeBasicDataImpl implements NativeBasicData { |
| 175 @override |
| 176 bool isNativeClass(ClassEntity element) { |
| 177 // TODO(johnniwinther): Implement this. |
| 178 return false; |
| 179 } |
| 180 |
| 181 @override |
| 182 bool isJsInteropClass(ClassEntity element) { |
| 183 throw new UnimplementedError('NativeBasicDataImpl.isJsInteropClass'); |
| 184 } |
| 185 |
| 186 @override |
| 187 bool isJsInteropLibrary(LibraryEntity element) { |
| 188 throw new UnimplementedError('NativeBasicDataImpl.isJsInteropLibrary'); |
| 189 } |
| 190 |
| 191 @override |
| 192 bool isNativeOrExtendsNative(ClassEntity element) { |
| 193 // TODO(johnniwinther): Implement this. |
| 194 return false; |
| 195 } |
| 196 |
| 197 @override |
| 198 bool hasNativeTagsForcedNonLeaf(ClassEntity cls) { |
| 199 throw new UnimplementedError( |
| 200 'NativeBasicDataImpl.hasNativeTagsForcedNonLeaf'); |
| 201 } |
| 202 |
| 203 @override |
| 204 List<String> getNativeTagsOfClass(ClassEntity cls) { |
| 205 throw new UnimplementedError('NativeBasicDataImpl.getNativeTagsOfClass'); |
| 206 } |
| 207 } |
| 208 |
| 209 class RuntimeTypesNeedBuilderImpl implements RuntimeTypesNeedBuilder { |
| 210 @override |
| 211 void registerClassUsingTypeVariableExpression(ClassEntity cls) {} |
| 212 |
| 213 @override |
| 214 RuntimeTypesNeed computeRuntimeTypesNeed( |
| 215 ResolutionWorldBuilder resolutionWorldBuilder, |
| 216 ClosedWorld closedWorld, |
| 217 DartTypes types, |
| 218 CommonElements commonElements, |
| 219 BackendHelpers helpers, |
| 220 BackendUsage backendUsage, |
| 221 {bool enableTypeAssertions}) { |
| 222 throw new UnimplementedError( |
| 223 'RuntimeTypesNeedBuilderImpl.computeRuntimeTypesNeed'); |
| 224 } |
| 225 |
| 226 @override |
| 227 void registerRtiDependency(ClassEntity element, ClassEntity dependency) {} |
| 228 } |
| 229 |
| 230 class MirrorsDataBuilderImpl implements MirrorsDataBuilder { |
| 231 @override |
| 232 void registerUsedMember(MemberEntity member) {} |
| 233 |
| 234 @override |
| 235 void computeMembersNeededForReflection( |
| 236 ResolutionWorldBuilder worldBuilder, ClosedWorld closedWorld) {} |
| 237 |
| 238 @override |
| 239 void maybeMarkClosureAsNeededForReflection( |
| 240 ClosureClassElement globalizedElement, |
| 241 FunctionElement callFunction, |
| 242 FunctionElement function) {} |
| 243 |
| 244 @override |
| 245 void registerConstSymbol(String name) {} |
| 246 |
| 247 @override |
| 248 void registerMirrorUsage( |
| 249 Set<String> symbols, Set<Element> targets, Set<Element> metaTargets) {} |
| 250 } |
| 251 |
| 252 class CustomElementsResolutionAnalysisImpl |
| 253 implements CustomElementsResolutionAnalysis { |
| 254 @override |
| 255 CustomElementsAnalysisJoin get join { |
| 256 throw new UnimplementedError('CustomElementsResolutionAnalysisImpl.join'); |
| 257 } |
| 258 |
| 259 @override |
| 260 WorldImpact flush() { |
| 261 // TODO(johnniwinther): Implement this. |
| 262 return const WorldImpact(); |
| 263 } |
| 264 |
| 265 @override |
| 266 void registerStaticUse(MemberEntity element) {} |
| 267 |
| 268 @override |
| 269 void registerInstantiatedClass(ClassEntity classElement) {} |
| 270 |
| 271 @override |
| 272 void registerTypeLiteral(DartType type) {} |
| 273 } |
| 274 |
| 275 class LookupMapResolutionAnalysisImpl implements LookupMapResolutionAnalysis { |
| 276 @override |
| 277 FieldEntity lookupMapVersionVariable; |
| 278 @override |
| 279 LibraryEntity lookupMapLibrary; |
| 280 |
| 281 @override |
| 282 WorldImpact flush() { |
| 283 // TODO(johnniwinther): Implement this. |
| 284 return const WorldImpact(); |
| 285 } |
| 286 |
| 287 @override |
| 288 void init(LibraryEntity library) {} |
| 289 } |
| 290 |
| 291 class MirrorsResolutionAnalysisImpl implements MirrorsResolutionAnalysis { |
| 292 @override |
| 293 void onQueueEmpty(Enqueuer enqueuer, Iterable<ClassEntity> recentClasses) {} |
| 294 |
| 295 @override |
| 296 MirrorsCodegenAnalysis close() { |
| 297 throw new UnimplementedError('MirrorsResolutionAnalysisImpl.close'); |
| 298 } |
| 299 |
| 300 @override |
| 301 void onResolutionComplete() {} |
| 302 } |
| 303 |
| 304 class KernelWorkItemBuilder implements WorkItemBuilder { |
| 305 final KernelWorldBuilder _worldBuilder; |
| 306 final ImpactTransformer _impactTransformer; |
| 307 |
| 308 KernelWorkItemBuilder(this._worldBuilder, this._impactTransformer); |
| 309 |
| 310 @override |
| 311 WorkItem createWorkItem(MemberEntity entity) { |
| 312 return new KernelWorkItem(_worldBuilder, _impactTransformer, entity); |
| 313 } |
| 314 } |
| 315 |
| 316 class KernelWorkItem implements ResolutionWorkItem { |
| 317 final KernelWorldBuilder _worldBuilder; |
| 318 final ImpactTransformer _impactTransformer; |
| 319 final MemberEntity element; |
| 320 |
| 321 KernelWorkItem(this._worldBuilder, this._impactTransformer, this.element); |
| 322 |
| 323 @override |
| 324 WorldImpact run() { |
| 325 ResolutionImpact impact = _worldBuilder.computeWorldImpact(element); |
| 326 return _impactTransformer.transformResolutionImpact(impact); |
| 327 } |
| 328 } |
| OLD | NEW |