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'; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 testIsNotGenericDynamic(null); | 66 testIsNotGenericDynamic(null); |
67 testIsTypedef(null); | 67 testIsTypedef(null); |
68 testIsTypedefGeneric(null); | 68 testIsTypedefGeneric(null); |
69 testIsTypedefGenericRaw(null); | 69 testIsTypedefGenericRaw(null); |
70 testIsTypedefGenericDynamic(null); | 70 testIsTypedefGenericDynamic(null); |
71 testAs(null); | 71 testAs(null); |
72 testAsGeneric(null); | 72 testAsGeneric(null); |
73 testAsGenericRaw(null); | 73 testAsGenericRaw(null); |
74 testAsGenericDynamic(null); | 74 testAsGenericDynamic(null); |
75 testThrow(); | 75 testThrow(); |
| 76 testIfNull(null); |
| 77 testSetIfNull(null); |
76 testSyncStar(); | 78 testSyncStar(); |
77 testAsync(); | 79 testAsync(); |
78 testAsyncStar(); | 80 testAsyncStar(); |
79 testIfThen(); | 81 testIfThen(); |
80 testIfThenElse(); | 82 testIfThenElse(); |
81 testForIn(null); | 83 testForIn(null); |
82 testForInTyped(null); | 84 testForInTyped(null); |
83 testAsyncForIn(null); | 85 testAsyncForIn(null); |
84 testAsyncForInTyped(null); | 86 testAsyncForInTyped(null); |
85 testTryCatch(); | 87 testTryCatch(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 testFactoryInvokeGenericRaw(); | 132 testFactoryInvokeGenericRaw(); |
131 testFactoryInvokeGenericDynamic(); | 133 testFactoryInvokeGenericDynamic(); |
132 testRedirectingFactoryInvoke(); | 134 testRedirectingFactoryInvoke(); |
133 testRedirectingFactoryInvokeGeneric(); | 135 testRedirectingFactoryInvokeGeneric(); |
134 testRedirectingFactoryInvokeGenericRaw(); | 136 testRedirectingFactoryInvokeGenericRaw(); |
135 testRedirectingFactoryInvokeGenericDynamic(); | 137 testRedirectingFactoryInvokeGenericDynamic(); |
136 testConstRedirectingFactoryInvoke(); | 138 testConstRedirectingFactoryInvoke(); |
137 testConstRedirectingFactoryInvokeGeneric(); | 139 testConstRedirectingFactoryInvokeGeneric(); |
138 testConstRedirectingFactoryInvokeGenericRaw(); | 140 testConstRedirectingFactoryInvokeGenericRaw(); |
139 testConstRedirectingFactoryInvokeGenericDynamic(); | 141 testConstRedirectingFactoryInvokeGenericDynamic(); |
| 142 testImplicitConstructor(); |
| 143 testFactoryConstructor(); |
| 144 testDefaultValuesPositional(); |
| 145 testDefaultValuesNamed(); |
140 } | 146 } |
141 | 147 |
142 testEmpty() {} | 148 testEmpty() {} |
143 testNull() => null; | 149 testNull() => null; |
144 testTrue() => true; | 150 testTrue() => true; |
145 testFalse() => false; | 151 testFalse() => false; |
146 testInt() => 42; | 152 testInt() => 42; |
147 testDouble() => 37.5; | 153 testDouble() => 37.5; |
148 testString() => 'foo'; | 154 testString() => 'foo'; |
149 testStringInterpolation() => '${0}'; | 155 testStringInterpolation() => '${0}'; |
(...skipping 30 matching lines...) Expand all Loading... |
180 testIsNotGenericDynamic(o) => o is! GenericClass<dynamic, dynamic>; | 186 testIsNotGenericDynamic(o) => o is! GenericClass<dynamic, dynamic>; |
181 testIsTypedef(o) => o is Typedef; | 187 testIsTypedef(o) => o is Typedef; |
182 testIsTypedefGeneric(o) => o is GenericTypedef<int, String>; | 188 testIsTypedefGeneric(o) => o is GenericTypedef<int, String>; |
183 testIsTypedefGenericRaw(o) => o is GenericTypedef; | 189 testIsTypedefGenericRaw(o) => o is GenericTypedef; |
184 testIsTypedefGenericDynamic(o) => o is GenericTypedef<dynamic, dynamic>; | 190 testIsTypedefGenericDynamic(o) => o is GenericTypedef<dynamic, dynamic>; |
185 testAs(o) => o as Class; | 191 testAs(o) => o as Class; |
186 testAsGeneric(o) => o as GenericClass<int, String>; | 192 testAsGeneric(o) => o as GenericClass<int, String>; |
187 testAsGenericRaw(o) => o as GenericClass; | 193 testAsGenericRaw(o) => o as GenericClass; |
188 testAsGenericDynamic(o) => o as GenericClass<dynamic, dynamic>; | 194 testAsGenericDynamic(o) => o as GenericClass<dynamic, dynamic>; |
189 testThrow() => throw ''; | 195 testThrow() => throw ''; |
| 196 testIfNull(o) => o ?? 42; |
| 197 testSetIfNull(o) => o ??= 42; |
190 | 198 |
191 testSyncStar() sync* {} | 199 testSyncStar() sync* {} |
192 testAsync() async {} | 200 testAsync() async {} |
193 testAsyncStar() async* {} | 201 testAsyncStar() async* {} |
194 testIfThen() { | 202 testIfThen() { |
195 if (false) return 42; | 203 if (false) return 42; |
196 return 1; | 204 return 1; |
197 } | 205 } |
198 testIfThenElse() { | 206 testIfThenElse() { |
199 if (true) { | 207 if (true) { |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 } | 418 } |
411 testConstRedirectingFactoryInvokeGeneric() { | 419 testConstRedirectingFactoryInvokeGeneric() { |
412 const GenericClass<int, String>.redirect(); | 420 const GenericClass<int, String>.redirect(); |
413 } | 421 } |
414 testConstRedirectingFactoryInvokeGenericRaw() { | 422 testConstRedirectingFactoryInvokeGenericRaw() { |
415 const GenericClass.redirect(); | 423 const GenericClass.redirect(); |
416 } | 424 } |
417 testConstRedirectingFactoryInvokeGenericDynamic() { | 425 testConstRedirectingFactoryInvokeGenericDynamic() { |
418 const GenericClass<dynamic, dynamic>.redirect(); | 426 const GenericClass<dynamic, dynamic>.redirect(); |
419 } | 427 } |
| 428 class ClassImplicitConstructor {} |
| 429 testImplicitConstructor() => new ClassImplicitConstructor(); |
| 430 class ClassFactoryConstructor { |
| 431 factory ClassFactoryConstructor() => null; |
| 432 } |
| 433 testFactoryConstructor() => new ClassFactoryConstructor(); |
| 434 testDefaultValuesPositional([bool value = false]) {} |
| 435 testDefaultValuesNamed({bool value: false}) {} |
420 ''', | 436 ''', |
421 'helper.dart': ''' | 437 'helper.dart': ''' |
422 class Class { | 438 class Class { |
423 const Class.generative(); | 439 const Class.generative(); |
424 factory Class.fact() => null; | 440 factory Class.fact() => null; |
425 const factory Class.redirect() = Class.generative; | 441 const factory Class.redirect() = Class.generative; |
426 } | 442 } |
427 class GenericClass<X, Y> { | 443 class GenericClass<X, Y> { |
428 const GenericClass.generative(); | 444 const GenericClass.generative(); |
429 factory GenericClass.fact() => null; | 445 factory GenericClass.fact() => null; |
(...skipping 18 matching lines...) Expand all Loading... |
448 ]); | 464 ]); |
449 compiler.resolution.retainCachesForTesting = true; | 465 compiler.resolution.retainCachesForTesting = true; |
450 await compiler.run(entryPoint); | 466 await compiler.run(entryPoint); |
451 checkLibrary(compiler, compiler.mainApp); | 467 checkLibrary(compiler, compiler.mainApp); |
452 }); | 468 }); |
453 } | 469 } |
454 | 470 |
455 void checkLibrary(Compiler compiler, LibraryElement library) { | 471 void checkLibrary(Compiler compiler, LibraryElement library) { |
456 library.forEachLocalMember((AstElement element) { | 472 library.forEachLocalMember((AstElement element) { |
457 if (element.isClass) { | 473 if (element.isClass) { |
458 // TODO(johnniwinther): Handle class members. | 474 ClassElement cls = element; |
| 475 cls.forEachLocalMember((AstElement member) { |
| 476 checkElement(compiler, member); |
| 477 }); |
459 } else if (element.isTypedef) { | 478 } else if (element.isTypedef) { |
460 // Skip typedefs. | 479 // Skip typedefs. |
461 } else { | 480 } else { |
462 checkElement(compiler, element); | 481 checkElement(compiler, element); |
463 } | 482 } |
464 }); | 483 }); |
465 } | 484 } |
466 | 485 |
467 void checkElement(Compiler compiler, AstElement element) { | 486 void checkElement(Compiler compiler, AstElement element) { |
468 ResolutionImpact astImpact = compiler.resolution.getResolutionImpact(element); | 487 ResolutionImpact astImpact = compiler.resolution.getResolutionImpact(element); |
(...skipping 10 matching lines...) Expand all Loading... |
479 Compiler compiler, AstElement element, ResolutionImpact impact) { | 498 Compiler compiler, AstElement element, ResolutionImpact impact) { |
480 ResolutionWorldImpactBuilder builder = | 499 ResolutionWorldImpactBuilder builder = |
481 new ResolutionWorldImpactBuilder('Lax impact of ${element}'); | 500 new ResolutionWorldImpactBuilder('Lax impact of ${element}'); |
482 for (StaticUse staticUse in impact.staticUses) { | 501 for (StaticUse staticUse in impact.staticUses) { |
483 switch (staticUse.kind) { | 502 switch (staticUse.kind) { |
484 case StaticUseKind.CONST_CONSTRUCTOR_INVOKE: | 503 case StaticUseKind.CONST_CONSTRUCTOR_INVOKE: |
485 ConstructorElement constructor = staticUse.element; | 504 ConstructorElement constructor = staticUse.element; |
486 ConstructorElement effectiveTarget = constructor.effectiveTarget; | 505 ConstructorElement effectiveTarget = constructor.effectiveTarget; |
487 DartType effectiveTargetType = | 506 DartType effectiveTargetType = |
488 constructor.computeEffectiveTargetType(staticUse.type); | 507 constructor.computeEffectiveTargetType(staticUse.type); |
489 builder.registerStaticUse( | 508 builder.registerStaticUse(new StaticUse.typedConstructorInvoke( |
490 new StaticUse.typedConstructorInvoke(effectiveTarget, null, effectiv
eTargetType)); | 509 effectiveTarget, null, effectiveTargetType)); |
491 break; | 510 break; |
492 default: | 511 default: |
493 builder.registerStaticUse(staticUse); | 512 builder.registerStaticUse(staticUse); |
494 break; | 513 break; |
495 } | 514 } |
496 } | 515 } |
497 impact.dynamicUses.forEach(builder.registerDynamicUse); | 516 impact.dynamicUses.forEach(builder.registerDynamicUse); |
498 for (TypeUse typeUse in impact.typeUses) { | 517 for (TypeUse typeUse in impact.typeUses) { |
499 if (typeUse.type.isTypedef) { | 518 if (typeUse.type.isTypedef) { |
500 typeUse = new TypeUse.internal(typeUse.type.unaliased, typeUse.kind); | 519 typeUse = new TypeUse.internal(typeUse.type.unaliased, typeUse.kind); |
(...skipping 24 matching lines...) Expand all Loading... |
525 builder.registerFeature(Feature.THROW_EXPRESSION); | 544 builder.registerFeature(Feature.THROW_EXPRESSION); |
526 break; | 545 break; |
527 default: | 546 default: |
528 builder.registerFeature(feature); | 547 builder.registerFeature(feature); |
529 break; | 548 break; |
530 } | 549 } |
531 } | 550 } |
532 impact.nativeData.forEach(builder.registerNativeData); | 551 impact.nativeData.forEach(builder.registerNativeData); |
533 return builder; | 552 return builder; |
534 } | 553 } |
OLD | NEW |