| 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 'package:async_helper/async_helper.dart'; | 9 import 'package:async_helper/async_helper.dart'; |
| 10 import 'package:compiler/src/closure.dart'; | 10 import 'package:compiler/src/closure.dart'; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 import 'package:compiler/src/js_backend/resolution_listener.dart'; | 35 import 'package:compiler/src/js_backend/resolution_listener.dart'; |
| 36 import 'package:compiler/src/js_backend/type_variable_handler.dart'; | 36 import 'package:compiler/src/js_backend/type_variable_handler.dart'; |
| 37 import 'package:compiler/src/native/enqueue.dart'; | 37 import 'package:compiler/src/native/enqueue.dart'; |
| 38 import 'package:compiler/src/kernel/world_builder.dart'; | 38 import 'package:compiler/src/kernel/world_builder.dart'; |
| 39 import 'package:compiler/src/options.dart'; | 39 import 'package:compiler/src/options.dart'; |
| 40 import 'package:compiler/src/universe/world_builder.dart'; | 40 import 'package:compiler/src/universe/world_builder.dart'; |
| 41 import 'package:compiler/src/universe/world_impact.dart'; | 41 import 'package:compiler/src/universe/world_impact.dart'; |
| 42 import 'package:compiler/src/world.dart'; | 42 import 'package:compiler/src/world.dart'; |
| 43 import '../memory_compiler.dart'; | 43 import '../memory_compiler.dart'; |
| 44 import '../serialization/helper.dart'; | 44 import '../serialization/helper.dart'; |
| 45 import '../serialization/model_test_helper.dart'; |
| 46 import '../serialization/test_helper.dart'; |
| 45 | 47 |
| 46 import 'closed_world_test.dart'; | 48 import 'closed_world_test.dart'; |
| 49 import 'impact_test.dart'; |
| 50 |
| 51 const SOURCE = const { |
| 52 'main.dart': ''' |
| 53 main() {} |
| 54 ''' |
| 55 }; |
| 47 | 56 |
| 48 main(List<String> args) { | 57 main(List<String> args) { |
| 49 Arguments arguments = new Arguments.from(args); | 58 Arguments arguments = new Arguments.from(args); |
| 50 Uri entryPoint; | 59 Uri entryPoint; |
| 51 Map<String, String> memorySourceFiles; | 60 Map<String, String> memorySourceFiles; |
| 52 if (arguments.uri != null) { | 61 if (arguments.uri != null) { |
| 53 entryPoint = arguments.uri; | 62 entryPoint = arguments.uri; |
| 54 memorySourceFiles = const <String, String>{}; | 63 memorySourceFiles = const <String, String>{}; |
| 55 } else { | 64 } else { |
| 56 entryPoint = Uri.parse('memory:main.dart'); | 65 entryPoint = Uri.parse('memory:main.dart'); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 67 Flags.useKernel, | 76 Flags.useKernel, |
| 68 Flags.enableAssertMessage | 77 Flags.enableAssertMessage |
| 69 ]); | 78 ]); |
| 70 ElementResolutionWorldBuilder.useInstantiationMap = true; | 79 ElementResolutionWorldBuilder.useInstantiationMap = true; |
| 71 compiler.resolution.retainCachesForTesting = true; | 80 compiler.resolution.retainCachesForTesting = true; |
| 72 await compiler.run(entryPoint); | 81 await compiler.run(entryPoint); |
| 73 compiler.resolutionWorldBuilder.closeWorld(); | 82 compiler.resolutionWorldBuilder.closeWorld(); |
| 74 | 83 |
| 75 KernelWorldBuilder worldBuilder = new KernelWorldBuilder( | 84 KernelWorldBuilder worldBuilder = new KernelWorldBuilder( |
| 76 compiler.reporter, compiler.backend.kernelTask.program); | 85 compiler.reporter, compiler.backend.kernelTask.program); |
| 77 List list = createKernelResolutionEnqueuerListener(compiler.options, | 86 KernelEquivalence equivalence = new KernelEquivalence(worldBuilder); |
| 78 compiler.reporter, compiler.deferredLoadTask, worldBuilder); | 87 NativeBasicData nativeBasicData = computeNativeBasicData(worldBuilder); |
| 88 checkNativeBasicData( |
| 89 compiler.backend.nativeBasicData, nativeBasicData, equivalence); |
| 90 List list = createKernelResolutionEnqueuerListener( |
| 91 compiler.options, |
| 92 compiler.reporter, |
| 93 compiler.deferredLoadTask, |
| 94 worldBuilder, |
| 95 nativeBasicData); |
| 79 ResolutionEnqueuerListener resolutionEnqueuerListener = list[0]; | 96 ResolutionEnqueuerListener resolutionEnqueuerListener = list[0]; |
| 80 ImpactTransformer impactTransformer = list[1]; | 97 ImpactTransformer impactTransformer = list[1]; |
| 81 ResolutionEnqueuer enqueuer = new ResolutionEnqueuer( | 98 ResolutionEnqueuer enqueuer = new ResolutionEnqueuer( |
| 82 compiler.enqueuer, | 99 compiler.enqueuer, |
| 83 compiler.options, | 100 compiler.options, |
| 84 compiler.reporter, | 101 compiler.reporter, |
| 85 const TreeShakingEnqueuerStrategy(), | 102 const TreeShakingEnqueuerStrategy(), |
| 86 resolutionEnqueuerListener, | 103 resolutionEnqueuerListener, |
| 87 new KernelResolutionWorldBuilder( | 104 new KernelResolutionWorldBuilder( |
| 88 worldBuilder.elementEnvironment, | 105 worldBuilder.elementEnvironment, |
| 89 worldBuilder.commonElements, | 106 worldBuilder.commonElements, |
| 90 new NativeBasicDataImpl(), | 107 nativeBasicData, |
| 91 const OpenWorldStrategy()), | 108 const OpenWorldStrategy()), |
| 92 new KernelWorkItemBuilder(worldBuilder, impactTransformer), | 109 new KernelWorkItemBuilder(worldBuilder, impactTransformer), |
| 93 'enqueuer from kelements'); | 110 'enqueuer from kelements'); |
| 94 | 111 |
| 95 computeClosedWorld( | 112 computeClosedWorld( |
| 96 compiler.reporter, enqueuer, worldBuilder.elementEnvironment); | 113 compiler.reporter, enqueuer, worldBuilder.elementEnvironment); |
| 97 }); | 114 }); |
| 98 } | 115 } |
| 99 | 116 |
| 100 List createKernelResolutionEnqueuerListener( | 117 List createKernelResolutionEnqueuerListener( |
| 101 CompilerOptions options, | 118 CompilerOptions options, |
| 102 DiagnosticReporter reporter, | 119 DiagnosticReporter reporter, |
| 103 DeferredLoadTask deferredLoadTask, | 120 DeferredLoadTask deferredLoadTask, |
| 104 KernelWorldBuilder worldBuilder) { | 121 KernelWorldBuilder worldBuilder, |
| 122 NativeBasicData nativeBasicData) { |
| 105 ElementEnvironment elementEnvironment = worldBuilder.elementEnvironment; | 123 ElementEnvironment elementEnvironment = worldBuilder.elementEnvironment; |
| 106 CommonElements commonElements = worldBuilder.commonElements; | 124 CommonElements commonElements = worldBuilder.commonElements; |
| 107 BackendImpacts impacts = new BackendImpacts(options, commonElements); | 125 BackendImpacts impacts = new BackendImpacts(options, commonElements); |
| 108 | 126 |
| 109 // TODO(johnniwinther): Create Kernel based implementations for these: | 127 // TODO(johnniwinther): Create Kernel based implementations for these: |
| 110 NativeBasicData nativeBasicData = new NativeBasicDataImpl(); | |
| 111 RuntimeTypesNeedBuilder rtiNeedBuilder = new RuntimeTypesNeedBuilderImpl(); | 128 RuntimeTypesNeedBuilder rtiNeedBuilder = new RuntimeTypesNeedBuilderImpl(); |
| 112 MirrorsDataBuilder mirrorsDataBuilder = new MirrorsDataBuilderImpl(); | 129 MirrorsDataBuilder mirrorsDataBuilder = new MirrorsDataBuilderImpl(); |
| 113 CustomElementsResolutionAnalysis customElementsResolutionAnalysis = | 130 CustomElementsResolutionAnalysis customElementsResolutionAnalysis = |
| 114 new CustomElementsResolutionAnalysisImpl(); | 131 new CustomElementsResolutionAnalysisImpl(); |
| 115 MirrorsResolutionAnalysis mirrorsResolutionAnalysis = | 132 MirrorsResolutionAnalysis mirrorsResolutionAnalysis = |
| 116 new MirrorsResolutionAnalysisImpl(); | 133 new MirrorsResolutionAnalysisImpl(); |
| 117 LookupMapResolutionAnalysis lookupMapResolutionAnalysis = | 134 LookupMapResolutionAnalysis lookupMapResolutionAnalysis = |
| 118 new LookupMapResolutionAnalysis(reporter, elementEnvironment); | 135 new LookupMapResolutionAnalysis(reporter, elementEnvironment); |
| 136 |
| 119 InterceptorDataBuilder interceptorDataBuilder = | 137 InterceptorDataBuilder interceptorDataBuilder = |
| 120 new InterceptorDataBuilderImpl( | 138 new InterceptorDataBuilderImpl( |
| 121 nativeBasicData, elementEnvironment, commonElements); | 139 nativeBasicData, elementEnvironment, commonElements); |
| 122 BackendUsageBuilder backendUsageBuilder = | 140 BackendUsageBuilder backendUsageBuilder = |
| 123 new BackendUsageBuilderImpl(commonElements); | 141 new BackendUsageBuilderImpl(commonElements); |
| 124 NoSuchMethodRegistry noSuchMethodRegistry = new NoSuchMethodRegistry( | 142 NoSuchMethodRegistry noSuchMethodRegistry = new NoSuchMethodRegistry( |
| 125 commonElements, new KernelNoSuchMethodResolver(worldBuilder)); | 143 commonElements, new KernelNoSuchMethodResolver(worldBuilder)); |
| 126 NativeResolutionEnqueuer nativeResolutionEnqueuer = | 144 NativeResolutionEnqueuer nativeResolutionEnqueuer = |
| 127 new NativeResolutionEnqueuer(options, elementEnvironment, commonElements, | 145 new NativeResolutionEnqueuer(options, elementEnvironment, commonElements, |
| 128 backendUsageBuilder, new KernelNativeClassResolver(worldBuilder)); | 146 backendUsageBuilder, new KernelNativeClassResolver(worldBuilder)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 153 impacts, | 171 impacts, |
| 154 nativeBasicData, | 172 nativeBasicData, |
| 155 nativeResolutionEnqueuer, | 173 nativeResolutionEnqueuer, |
| 156 backendUsageBuilder, | 174 backendUsageBuilder, |
| 157 mirrorsDataBuilder, | 175 mirrorsDataBuilder, |
| 158 customElementsResolutionAnalysis, | 176 customElementsResolutionAnalysis, |
| 159 rtiNeedBuilder); | 177 rtiNeedBuilder); |
| 160 return [listener, transformer]; | 178 return [listener, transformer]; |
| 161 } | 179 } |
| 162 | 180 |
| 163 class NativeBasicDataImpl implements NativeBasicData { | 181 /// Computes that NativeBasicData for the libraries in [worldBuilder]. |
| 164 @override | 182 /// TODO(johnniwinther): Use [KernelAnnotationProcessor] instead. |
| 165 bool isNativeClass(ClassEntity element) { | 183 NativeBasicData computeNativeBasicData(KernelWorldBuilder worldBuilder) { |
| 166 // TODO(johnniwinther): Implement this. | 184 NativeBasicDataBuilderImpl builder = new NativeBasicDataBuilderImpl(); |
| 167 return false; | 185 ElementEnvironment elementEnvironment = worldBuilder.elementEnvironment; |
| 186 for (LibraryEntity library in elementEnvironment.libraries) { |
| 187 if (library.canonicalUri.scheme == 'dart') { |
| 188 new KernelAnnotationProcessor(worldBuilder) |
| 189 .extractNativeAnnotations(library, builder); |
| 190 } |
| 168 } | 191 } |
| 169 | 192 return builder.close(elementEnvironment); |
| 170 @override | |
| 171 bool isJsInteropClass(ClassEntity element) { | |
| 172 throw new UnimplementedError('NativeBasicDataImpl.isJsInteropClass'); | |
| 173 } | |
| 174 | |
| 175 @override | |
| 176 bool isJsInteropLibrary(LibraryEntity element) { | |
| 177 throw new UnimplementedError('NativeBasicDataImpl.isJsInteropLibrary'); | |
| 178 } | |
| 179 | |
| 180 @override | |
| 181 bool isNativeOrExtendsNative(ClassEntity element) { | |
| 182 // TODO(johnniwinther): Implement this. | |
| 183 return false; | |
| 184 } | |
| 185 | |
| 186 @override | |
| 187 bool hasNativeTagsForcedNonLeaf(ClassEntity cls) { | |
| 188 throw new UnimplementedError( | |
| 189 'NativeBasicDataImpl.hasNativeTagsForcedNonLeaf'); | |
| 190 } | |
| 191 | |
| 192 @override | |
| 193 List<String> getNativeTagsOfClass(ClassEntity cls) { | |
| 194 throw new UnimplementedError('NativeBasicDataImpl.getNativeTagsOfClass'); | |
| 195 } | |
| 196 } | 193 } |
| 197 | 194 |
| 198 class RuntimeTypesNeedBuilderImpl implements RuntimeTypesNeedBuilder { | 195 class RuntimeTypesNeedBuilderImpl implements RuntimeTypesNeedBuilder { |
| 199 @override | 196 @override |
| 200 void registerClassUsingTypeVariableExpression(ClassEntity cls) {} | 197 void registerClassUsingTypeVariableExpression(ClassEntity cls) {} |
| 201 | 198 |
| 202 @override | 199 @override |
| 203 RuntimeTypesNeed computeRuntimeTypesNeed( | 200 RuntimeTypesNeed computeRuntimeTypesNeed( |
| 204 ResolutionWorldBuilder resolutionWorldBuilder, | 201 ResolutionWorldBuilder resolutionWorldBuilder, |
| 205 ClosedWorld closedWorld, | 202 ClosedWorld closedWorld, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 final MemberEntity element; | 288 final MemberEntity element; |
| 292 | 289 |
| 293 KernelWorkItem(this._worldBuilder, this._impactTransformer, this.element); | 290 KernelWorkItem(this._worldBuilder, this._impactTransformer, this.element); |
| 294 | 291 |
| 295 @override | 292 @override |
| 296 WorldImpact run() { | 293 WorldImpact run() { |
| 297 ResolutionImpact impact = _worldBuilder.computeWorldImpact(element); | 294 ResolutionImpact impact = _worldBuilder.computeWorldImpact(element); |
| 298 return _impactTransformer.transformResolutionImpact(impact); | 295 return _impactTransformer.transformResolutionImpact(impact); |
| 299 } | 296 } |
| 300 } | 297 } |
| 298 |
| 299 void checkNativeBasicData(NativeBasicDataImpl data1, NativeBasicDataImpl data2, |
| 300 KernelEquivalence equivalence) { |
| 301 checkMapEquivalence( |
| 302 data1, |
| 303 data2, |
| 304 'nativeClassTagInfo', |
| 305 data1.nativeClassTagInfo, |
| 306 data2.nativeClassTagInfo, |
| 307 equivalence.entityEquivalence, |
| 308 (a, b) => a == b); |
| 309 } |
| OLD | NEW |