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/common.dart'; | 10 import 'package:compiler/src/common.dart'; |
10 import 'package:compiler/src/commandline_options.dart'; | 11 import 'package:compiler/src/common/names.dart'; |
11 import 'package:compiler/src/common/resolution.dart'; | 12 import 'package:compiler/src/common/resolution.dart'; |
12 import 'package:compiler/src/compiler.dart'; | 13 import 'package:compiler/src/compiler.dart'; |
13 import 'package:compiler/src/elements/elements.dart'; | 14 import 'package:compiler/src/elements/elements.dart'; |
| 15 import 'package:compiler/src/resolution/registry.dart'; |
14 import 'package:compiler/src/ssa/kernel_impact.dart'; | 16 import 'package:compiler/src/ssa/kernel_impact.dart'; |
15 import 'package:compiler/src/serialization/equivalence.dart'; | 17 import 'package:compiler/src/serialization/equivalence.dart'; |
| 18 import 'package:compiler/src/universe/feature.dart'; |
| 19 import 'package:compiler/src/universe/use.dart'; |
16 import '../memory_compiler.dart'; | 20 import '../memory_compiler.dart'; |
17 import '../serialization/test_helper.dart'; | 21 import '../serialization/test_helper.dart'; |
18 | 22 |
19 const Map<String, String> SOURCE = const <String, String>{ | 23 const Map<String, String> SOURCE = const <String, String>{ |
20 'main.dart': ''' | 24 'main.dart': r''' |
21 import 'helper.dart'; | 25 import 'helper.dart'; |
22 | 26 |
23 main() { | 27 main() { |
24 testEmpty(); | 28 testEmpty(); |
25 testNull(); | 29 testNull(); |
26 testTrue(); | 30 testTrue(); |
27 testFalse(); | 31 testFalse(); |
28 testInt(); | 32 testInt(); |
29 testDouble(); | 33 testDouble(); |
30 testString(); | 34 testString(); |
| 35 testStringInterpolation(); |
| 36 testStringInterpolationConst(); |
| 37 testStringJuxtaposition(); |
31 testSymbol(); | 38 testSymbol(); |
32 testEmptyListLiteral(); | 39 testEmptyListLiteral(); |
33 testEmptyListLiteralDynamic(); | 40 testEmptyListLiteralDynamic(); |
34 testEmptyListLiteralTyped(); | 41 testEmptyListLiteralTyped(); |
35 testEmptyListLiteralConstant(); | 42 testEmptyListLiteralConstant(); |
36 testNonEmptyListLiteral(); | 43 testNonEmptyListLiteral(); |
37 testEmptyMapLiteral(); | 44 testEmptyMapLiteral(); |
38 testEmptyMapLiteralDynamic(); | 45 testEmptyMapLiteralDynamic(); |
39 testEmptyMapLiteralTyped(); | 46 testEmptyMapLiteralTyped(); |
40 testEmptyMapLiteralConstant(); | 47 testEmptyMapLiteralConstant(); |
41 testNonEmptyMapLiteral(); | 48 testNonEmptyMapLiteral(); |
42 testNot(); | 49 testNot(); |
43 testUnaryMinus(); | 50 testUnaryMinus(); |
44 testConditional(); | 51 testConditional(); |
45 testPostInc(null); | 52 testPostInc(null); |
46 testPostDec(null); | 53 testPostDec(null); |
47 testPreInc(null); | 54 testPreInc(null); |
48 testPreDec(null); | 55 testPreDec(null); |
49 testIfThen(); | 56 testIfThen(); |
50 testIfThenElse(); | 57 testIfThenElse(); |
51 testTopLevelInvoke(); | 58 testTopLevelInvoke(); |
52 testTopLevelInvokeTyped(); | 59 testTopLevelInvokeTyped(); |
53 testTopLevelField(); | 60 testTopLevelField(); |
54 testTopLevelFieldTyped(); | 61 testTopLevelFieldTyped(); |
55 testDynamicInvoke(null); | 62 testDynamicInvoke(null); |
56 testDynamicGet(null); | 63 testDynamicGet(null); |
57 testDynamicSet(null); | 64 testDynamicSet(null); |
58 testLocalWithInitializer(); | 65 testLocalWithInitializer(); |
| 66 testLocalFunction(); |
| 67 testLocalFunctionInvoke(); |
| 68 testLocalFunctionGet(); |
59 testInvokeIndex(null); | 69 testInvokeIndex(null); |
60 testInvokeIndexSet(null); | 70 testInvokeIndexSet(null); |
61 testAssert(); | 71 testAssert(); |
62 testAssertWithMessage(); | 72 testAssertWithMessage(); |
63 testFactoryInvoke(); | 73 testFactoryInvoke(); |
64 testFactoryInvokeGeneric(); | 74 testFactoryInvokeGeneric(); |
65 testFactoryInvokeGenericRaw(); | 75 testFactoryInvokeGenericRaw(); |
66 testFactoryInvokeGenericDynamic(); | 76 testFactoryInvokeGenericDynamic(); |
67 } | 77 } |
68 | 78 |
69 testEmpty() {} | 79 testEmpty() {} |
70 testNull() => null; | 80 testNull() => null; |
71 testTrue() => true; | 81 testTrue() => true; |
72 testFalse() => false; | 82 testFalse() => false; |
73 testInt() => 42; | 83 testInt() => 42; |
74 testDouble() => 37.5; | 84 testDouble() => 37.5; |
75 testString() => 'foo'; | 85 testString() => 'foo'; |
| 86 testStringInterpolation() => '${0}'; |
| 87 testStringInterpolationConst() { |
| 88 const b = '${0}'; |
| 89 } |
| 90 testStringJuxtaposition() => 'a' 'b'; |
76 testSymbol() => #main; | 91 testSymbol() => #main; |
77 testEmptyListLiteral() => []; | 92 testEmptyListLiteral() => []; |
78 testEmptyListLiteralDynamic() => <dynamic>[]; | 93 testEmptyListLiteralDynamic() => <dynamic>[]; |
79 testEmptyListLiteralTyped() => <String>[]; | 94 testEmptyListLiteralTyped() => <String>[]; |
80 testEmptyListLiteralConstant() => const []; | 95 testEmptyListLiteralConstant() => const []; |
81 testNonEmptyListLiteral() => [0]; | 96 testNonEmptyListLiteral() => [0]; |
82 testEmptyMapLiteral() => {}; | 97 testEmptyMapLiteral() => {}; |
83 testEmptyMapLiteralDynamic() => <dynamic, dynamic>{}; | 98 testEmptyMapLiteralDynamic() => <dynamic, dynamic>{}; |
84 testEmptyMapLiteralTyped() => <String, int>{}; | 99 testEmptyMapLiteralTyped() => <String, int>{}; |
85 testEmptyMapLiteralConstant() => const {}; | 100 testEmptyMapLiteralConstant() => const {}; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 o.f6(8, b: 9); | 160 o.f6(8, b: 9); |
146 o.f7(10, c: 11); | 161 o.f7(10, c: 11); |
147 o.f8(12, b: 13, c: 14); | 162 o.f8(12, b: 13, c: 14); |
148 o.f9(15, c: 16, b: 17); | 163 o.f9(15, c: 16, b: 17); |
149 } | 164 } |
150 testDynamicGet(o) => o.foo; | 165 testDynamicGet(o) => o.foo; |
151 testDynamicSet(o) => o.foo = 42; | 166 testDynamicSet(o) => o.foo = 42; |
152 testLocalWithInitializer() { | 167 testLocalWithInitializer() { |
153 var l = 42; | 168 var l = 42; |
154 } | 169 } |
| 170 testLocalFunction() { |
| 171 localFunction() {} |
| 172 } |
| 173 testLocalFunctionInvoke() { |
| 174 localFunction() {} |
| 175 localFunction(); |
| 176 } |
| 177 testLocalFunctionGet() { |
| 178 localFunction() {} |
| 179 localFunction; |
| 180 } |
155 testInvokeIndex(o) => o[42]; | 181 testInvokeIndex(o) => o[42]; |
156 testInvokeIndexSet(o) => o[42] = null; | 182 testInvokeIndexSet(o) => o[42] = null; |
157 testAssert() { | 183 testAssert() { |
158 assert(true); | 184 assert(true); |
159 } | 185 } |
160 testAssertWithMessage() { | 186 testAssertWithMessage() { |
161 assert(true, 'ok'); | 187 assert(true, 'ok'); |
162 } | 188 } |
163 testFactoryInvoke() { | 189 testFactoryInvoke() { |
164 new Class.fact(); | 190 new Class.fact(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 if (element.isClass) { | 232 if (element.isClass) { |
207 // TODO(johnniwinther): Handle class members. | 233 // TODO(johnniwinther): Handle class members. |
208 } else { | 234 } else { |
209 checkElement(compiler, element); | 235 checkElement(compiler, element); |
210 } | 236 } |
211 }); | 237 }); |
212 } | 238 } |
213 | 239 |
214 void checkElement(Compiler compiler, AstElement element) { | 240 void checkElement(Compiler compiler, AstElement element) { |
215 ResolutionImpact astImpact = compiler.resolution.getResolutionImpact(element); | 241 ResolutionImpact astImpact = compiler.resolution.getResolutionImpact(element); |
| 242 astImpact = laxImpact(element, astImpact); |
216 ResolutionImpact kernelImpact = build(compiler, element.resolvedAst); | 243 ResolutionImpact kernelImpact = build(compiler, element.resolvedAst); |
217 testResolutionImpactEquivalence( | 244 testResolutionImpactEquivalence( |
218 astImpact, kernelImpact, const CheckStrategy()); | 245 astImpact, kernelImpact, const CheckStrategy()); |
219 } | 246 } |
| 247 |
| 248 /// Lax the precision of [impact] to meet expectancy of the corresponding impact |
| 249 /// generated from kernel. |
| 250 ResolutionImpact laxImpact(AstElement element, ResolutionImpact impact) { |
| 251 ResolutionWorldImpactBuilder builder = |
| 252 new ResolutionWorldImpactBuilder('Lax impact of ${element}'); |
| 253 impact.staticUses.forEach(builder.registerStaticUse); |
| 254 impact.dynamicUses.forEach(builder.registerDynamicUse); |
| 255 impact.typeUses.forEach(builder.registerTypeUse); |
| 256 impact.constantLiterals.forEach(builder.registerConstantLiteral); |
| 257 impact.constSymbolNames.forEach(builder.registerConstSymbolName); |
| 258 impact.listLiterals.forEach(builder.registerListLiteral); |
| 259 impact.mapLiterals.forEach(builder.registerMapLiteral); |
| 260 for (Feature feature in impact.features) { |
| 261 builder.registerFeature(feature); |
| 262 switch (feature) { |
| 263 case Feature.STRING_INTERPOLATION: |
| 264 case Feature.STRING_JUXTAPOSITION: |
| 265 // These are both converted into a string concatenation in kernel so |
| 266 // we cannot tell the diferrence. |
| 267 builder.registerFeature(Feature.STRING_INTERPOLATION); |
| 268 builder.registerFeature(Feature.STRING_JUXTAPOSITION); |
| 269 break; |
| 270 default: |
| 271 } |
| 272 } |
| 273 impact.nativeData.forEach(builder.registerNativeData); |
| 274 return builder; |
| 275 } |
OLD | NEW |