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 library dart2js.kernel.impact_test; | 5 library dart2js.kernel.impact_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
9 import 'package:compiler/src/commandline_options.dart'; | 9 import 'package:compiler/src/commandline_options.dart'; |
10 import 'package:compiler/src/common.dart'; | 10 import 'package:compiler/src/common.dart'; |
11 import 'package:compiler/src/common/names.dart'; | 11 import 'package:compiler/src/common/names.dart'; |
12 import 'package:compiler/src/common/resolution.dart'; | 12 import 'package:compiler/src/common/resolution.dart'; |
13 import 'package:compiler/src/compiler.dart'; | 13 import 'package:compiler/src/compiler.dart'; |
14 import 'package:compiler/src/elements/elements.dart'; | 14 import 'package:compiler/src/elements/elements.dart'; |
15 import 'package:compiler/src/resolution/registry.dart'; | 15 import 'package:compiler/src/resolution/registry.dart'; |
16 import 'package:compiler/src/ssa/kernel_impact.dart'; | 16 import 'package:compiler/src/ssa/kernel_impact.dart'; |
17 import 'package:compiler/src/serialization/equivalence.dart'; | 17 import 'package:compiler/src/serialization/equivalence.dart'; |
18 import 'package:compiler/src/universe/feature.dart'; | 18 import 'package:compiler/src/universe/feature.dart'; |
19 import 'package:compiler/src/universe/use.dart'; | 19 import 'package:compiler/src/universe/use.dart'; |
| 20 import 'package:expect/expect.dart'; |
20 import '../memory_compiler.dart'; | 21 import '../memory_compiler.dart'; |
21 import '../serialization/test_helper.dart'; | 22 import '../serialization/test_helper.dart'; |
22 | 23 |
23 const Map<String, String> SOURCE = const <String, String>{ | 24 const Map<String, String> SOURCE = const <String, String>{ |
24 'main.dart': r''' | 25 'main.dart': r''' |
25 import 'helper.dart'; | 26 import 'helper.dart'; |
26 | 27 |
27 main() { | 28 main() { |
28 testEmpty(); | 29 testEmpty(); |
29 testNull(); | 30 testNull(); |
(...skipping 23 matching lines...) Expand all Loading... |
53 testPostDec(null); | 54 testPostDec(null); |
54 testPreInc(null); | 55 testPreInc(null); |
55 testPreDec(null); | 56 testPreDec(null); |
56 testIfThen(); | 57 testIfThen(); |
57 testIfThenElse(); | 58 testIfThenElse(); |
58 testTopLevelInvoke(); | 59 testTopLevelInvoke(); |
59 testTopLevelInvokeTyped(); | 60 testTopLevelInvokeTyped(); |
60 testTopLevelFunctionTyped(); | 61 testTopLevelFunctionTyped(); |
61 testTopLevelFunctionGet(); | 62 testTopLevelFunctionGet(); |
62 testTopLevelField(); | 63 testTopLevelField(); |
| 64 testTopLevelFieldLazy(); |
| 65 testTopLevelFieldConst(); |
| 66 testTopLevelFieldFinal(); |
63 testTopLevelFieldTyped(); | 67 testTopLevelFieldTyped(); |
| 68 testTopLevelFieldGeneric1(); |
| 69 testTopLevelFieldGeneric2(); |
| 70 testTopLevelFieldGeneric3(); |
64 testDynamicInvoke(null); | 71 testDynamicInvoke(null); |
65 testDynamicGet(null); | 72 testDynamicGet(null); |
66 testDynamicSet(null); | 73 testDynamicSet(null); |
67 testLocalWithoutInitializer(); | 74 testLocalWithoutInitializer(); |
68 testLocalWithInitializer(); | 75 testLocalWithInitializer(); |
69 testLocalWithInitializerTyped(); | 76 testLocalWithInitializerTyped(); |
70 testLocalFunction(); | 77 testLocalFunction(); |
71 testLocalFunctionTyped(); | 78 testLocalFunctionTyped(); |
72 testLocalFunctionInvoke(); | 79 testLocalFunctionInvoke(); |
73 testLocalFunctionGet(); | 80 testLocalFunctionGet(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 testTopLevelFunctionTyped() { | 173 testTopLevelFunctionTyped() { |
167 topLevelFunctionTyped1(null); | 174 topLevelFunctionTyped1(null); |
168 topLevelFunctionTyped2(null); | 175 topLevelFunctionTyped2(null); |
169 topLevelFunctionTyped3(null); | 176 topLevelFunctionTyped3(null); |
170 topLevelFunctionTyped4(null); | 177 topLevelFunctionTyped4(null); |
171 } | 178 } |
172 testTopLevelFunctionGet() => topLevelFunction1; | 179 testTopLevelFunctionGet() => topLevelFunction1; |
173 | 180 |
174 var topLevelField; | 181 var topLevelField; |
175 testTopLevelField() => topLevelField; | 182 testTopLevelField() => topLevelField; |
| 183 var topLevelFieldLazy = topLevelFunction1(null); |
| 184 testTopLevelFieldLazy() => topLevelFieldLazy; |
| 185 const topLevelFieldConst = 0; |
| 186 testTopLevelFieldConst() => topLevelFieldConst; |
| 187 final topLevelFieldFinal = topLevelFunction1(null); |
| 188 testTopLevelFieldFinal() => topLevelFieldFinal; |
176 int topLevelFieldTyped; | 189 int topLevelFieldTyped; |
177 testTopLevelFieldTyped() => topLevelFieldTyped; | 190 testTopLevelFieldTyped() => topLevelFieldTyped; |
| 191 GenericClass topLevelFieldGeneric1; |
| 192 testTopLevelFieldGeneric1() => topLevelFieldGeneric1; |
| 193 GenericClass<dynamic, dynamic> topLevelFieldGeneric2; |
| 194 testTopLevelFieldGeneric2() => topLevelFieldGeneric2; |
| 195 GenericClass<int, String> topLevelFieldGeneric3; |
| 196 testTopLevelFieldGeneric3() => topLevelFieldGeneric3; |
| 197 |
178 testDynamicInvoke(o) { | 198 testDynamicInvoke(o) { |
179 o.f1(0); | 199 o.f1(0); |
180 o.f2(1); | 200 o.f2(1); |
181 o.f3(2, 3); | 201 o.f3(2, 3); |
182 o.f4(4, 5, 6); | 202 o.f4(4, 5, 6); |
183 o.f5(7); | 203 o.f5(7); |
184 o.f6(8, b: 9); | 204 o.f6(8, b: 9); |
185 o.f7(10, c: 11); | 205 o.f7(10, c: 11); |
186 o.f8(12, b: 13, c: 14); | 206 o.f8(12, b: 13, c: 14); |
187 o.f9(15, c: 16, b: 17); | 207 o.f9(15, c: 16, b: 17); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 } else { | 309 } else { |
290 checkElement(compiler, element); | 310 checkElement(compiler, element); |
291 } | 311 } |
292 }); | 312 }); |
293 } | 313 } |
294 | 314 |
295 void checkElement(Compiler compiler, AstElement element) { | 315 void checkElement(Compiler compiler, AstElement element) { |
296 ResolutionImpact astImpact = compiler.resolution.getResolutionImpact(element); | 316 ResolutionImpact astImpact = compiler.resolution.getResolutionImpact(element); |
297 astImpact = laxImpact(element, astImpact); | 317 astImpact = laxImpact(element, astImpact); |
298 ResolutionImpact kernelImpact = build(compiler, element.resolvedAst); | 318 ResolutionImpact kernelImpact = build(compiler, element.resolvedAst); |
| 319 Expect.isNotNull(kernelImpact, 'No impact computed for $element'); |
299 testResolutionImpactEquivalence( | 320 testResolutionImpactEquivalence( |
300 astImpact, kernelImpact, const CheckStrategy()); | 321 astImpact, kernelImpact, const CheckStrategy()); |
301 } | 322 } |
302 | 323 |
303 /// Lax the precision of [impact] to meet expectancy of the corresponding impact | 324 /// Lax the precision of [impact] to meet expectancy of the corresponding impact |
304 /// generated from kernel. | 325 /// generated from kernel. |
305 ResolutionImpact laxImpact(AstElement element, ResolutionImpact impact) { | 326 ResolutionImpact laxImpact(AstElement element, ResolutionImpact impact) { |
306 ResolutionWorldImpactBuilder builder = | 327 ResolutionWorldImpactBuilder builder = |
307 new ResolutionWorldImpactBuilder('Lax impact of ${element}'); | 328 new ResolutionWorldImpactBuilder('Lax impact of ${element}'); |
308 impact.staticUses.forEach(builder.registerStaticUse); | 329 impact.staticUses.forEach(builder.registerStaticUse); |
(...skipping 12 matching lines...) Expand all Loading... |
321 // we cannot tell the diferrence. | 342 // we cannot tell the diferrence. |
322 builder.registerFeature(Feature.STRING_INTERPOLATION); | 343 builder.registerFeature(Feature.STRING_INTERPOLATION); |
323 builder.registerFeature(Feature.STRING_JUXTAPOSITION); | 344 builder.registerFeature(Feature.STRING_JUXTAPOSITION); |
324 break; | 345 break; |
325 default: | 346 default: |
326 } | 347 } |
327 } | 348 } |
328 impact.nativeData.forEach(builder.registerNativeData); | 349 impact.nativeData.forEach(builder.registerNativeData); |
329 return builder; | 350 return builder; |
330 } | 351 } |
OLD | NEW |