Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: tests/compiler/dart2js/kernel/impact_test.dart

Issue 2392943003: Handle const constructor invocation in kernel_impact. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/dart_types.dart';
14 import 'package:compiler/src/elements/elements.dart'; 15 import 'package:compiler/src/elements/elements.dart';
15 import 'package:compiler/src/resolution/registry.dart'; 16 import 'package:compiler/src/resolution/registry.dart';
16 import 'package:compiler/src/ssa/kernel_impact.dart'; 17 import 'package:compiler/src/ssa/kernel_impact.dart';
17 import 'package:compiler/src/serialization/equivalence.dart'; 18 import 'package:compiler/src/serialization/equivalence.dart';
18 import 'package:compiler/src/universe/call_structure.dart'; 19 import 'package:compiler/src/universe/call_structure.dart';
19 import 'package:compiler/src/universe/feature.dart'; 20 import 'package:compiler/src/universe/feature.dart';
20 import 'package:compiler/src/universe/use.dart'; 21 import 'package:compiler/src/universe/use.dart';
21 import 'package:expect/expect.dart'; 22 import 'package:expect/expect.dart';
22 import '../memory_compiler.dart'; 23 import '../memory_compiler.dart';
23 import '../serialization/test_helper.dart'; 24 import '../serialization/test_helper.dart';
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 testConstructorInvokeGenericRaw(); 126 testConstructorInvokeGenericRaw();
126 testConstructorInvokeGenericDynamic(); 127 testConstructorInvokeGenericDynamic();
127 testFactoryInvoke(); 128 testFactoryInvoke();
128 testFactoryInvokeGeneric(); 129 testFactoryInvokeGeneric();
129 testFactoryInvokeGenericRaw(); 130 testFactoryInvokeGenericRaw();
130 testFactoryInvokeGenericDynamic(); 131 testFactoryInvokeGenericDynamic();
131 testRedirectingFactoryInvoke(); 132 testRedirectingFactoryInvoke();
132 testRedirectingFactoryInvokeGeneric(); 133 testRedirectingFactoryInvokeGeneric();
133 testRedirectingFactoryInvokeGenericRaw(); 134 testRedirectingFactoryInvokeGenericRaw();
134 testRedirectingFactoryInvokeGenericDynamic(); 135 testRedirectingFactoryInvokeGenericDynamic();
136 testConstRedirectingFactoryInvoke();
137 testConstRedirectingFactoryInvokeGeneric();
138 testConstRedirectingFactoryInvokeGenericRaw();
139 testConstRedirectingFactoryInvokeGenericDynamic();
135 } 140 }
136 141
137 testEmpty() {} 142 testEmpty() {}
138 testNull() => null; 143 testNull() => null;
139 testTrue() => true; 144 testTrue() => true;
140 testFalse() => false; 145 testFalse() => false;
141 testInt() => 42; 146 testInt() => 42;
142 testDouble() => 37.5; 147 testDouble() => 37.5;
143 testString() => 'foo'; 148 testString() => 'foo';
144 testStringInterpolation() => '${0}'; 149 testStringInterpolation() => '${0}';
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 } 398 }
394 testRedirectingFactoryInvokeGeneric() { 399 testRedirectingFactoryInvokeGeneric() {
395 new GenericClass<int, String>.redirect(); 400 new GenericClass<int, String>.redirect();
396 } 401 }
397 testRedirectingFactoryInvokeGenericRaw() { 402 testRedirectingFactoryInvokeGenericRaw() {
398 new GenericClass.redirect(); 403 new GenericClass.redirect();
399 } 404 }
400 testRedirectingFactoryInvokeGenericDynamic() { 405 testRedirectingFactoryInvokeGenericDynamic() {
401 new GenericClass<dynamic, dynamic>.redirect(); 406 new GenericClass<dynamic, dynamic>.redirect();
402 } 407 }
408 testConstRedirectingFactoryInvoke() {
409 const Class.redirect();
410 }
411 testConstRedirectingFactoryInvokeGeneric() {
412 const GenericClass<int, String>.redirect();
413 }
414 testConstRedirectingFactoryInvokeGenericRaw() {
415 const GenericClass.redirect();
416 }
417 testConstRedirectingFactoryInvokeGenericDynamic() {
418 const GenericClass<dynamic, dynamic>.redirect();
419 }
403 ''', 420 ''',
404 'helper.dart': ''' 421 'helper.dart': '''
405 class Class { 422 class Class {
406 Class.generative(); 423 const Class.generative();
407 factory Class.fact() => null; 424 factory Class.fact() => null;
408 factory Class.redirect() = Class.generative; 425 const factory Class.redirect() = Class.generative;
409 } 426 }
410 class GenericClass<X, Y> { 427 class GenericClass<X, Y> {
411 GenericClass.generative(); 428 const GenericClass.generative();
412 factory GenericClass.fact() => null; 429 factory GenericClass.fact() => null;
413 factory GenericClass.redirect() = GenericClass.generative; 430 const factory GenericClass.redirect() = GenericClass<X, Y>.generative;
414 } 431 }
415 typedef Typedef(); 432 typedef Typedef();
416 typedef X GenericTypedef<X, Y>(Y y); 433 typedef X GenericTypedef<X, Y>(Y y);
417 ''', 434 ''',
418 }; 435 };
419 436
420 main(List<String> args) { 437 main(List<String> args) {
421 asyncTest(() async { 438 asyncTest(() async {
422 enableDebugMode(); 439 enableDebugMode();
423 Uri entryPoint = Uri.parse('memory:main.dart'); 440 Uri entryPoint = Uri.parse('memory:main.dart');
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 testResolutionImpactEquivalence( 472 testResolutionImpactEquivalence(
456 astImpact, kernelImpact, const CheckStrategy()); 473 astImpact, kernelImpact, const CheckStrategy());
457 } 474 }
458 475
459 /// Lax the precision of [impact] to meet expectancy of the corresponding impact 476 /// Lax the precision of [impact] to meet expectancy of the corresponding impact
460 /// generated from kernel. 477 /// generated from kernel.
461 ResolutionImpact laxImpact( 478 ResolutionImpact laxImpact(
462 Compiler compiler, AstElement element, ResolutionImpact impact) { 479 Compiler compiler, AstElement element, ResolutionImpact impact) {
463 ResolutionWorldImpactBuilder builder = 480 ResolutionWorldImpactBuilder builder =
464 new ResolutionWorldImpactBuilder('Lax impact of ${element}'); 481 new ResolutionWorldImpactBuilder('Lax impact of ${element}');
465 impact.staticUses.forEach(builder.registerStaticUse); 482 for (StaticUse staticUse in impact.staticUses) {
483 switch (staticUse.kind) {
484 case StaticUseKind.CONST_CONSTRUCTOR_INVOKE:
485 ConstructorElement constructor = staticUse.element;
486 ConstructorElement effectiveTarget = constructor.effectiveTarget;
487 DartType effectiveTargetType =
488 constructor.computeEffectiveTargetType(staticUse.type);
489 builder.registerStaticUse(
490 new StaticUse.typedConstructorInvoke(effectiveTarget, null, effectiv eTargetType));
Harry Terkelsen 2016/10/07 15:53:21 long line
Harry Terkelsen 2016/10/07 15:53:21 why do we lose the distinction between const and n
Johnni Winther 2016/10/10 09:58:12 Done.
Johnni Winther 2016/10/10 09:58:12 Fixed.
491 break;
492 default:
493 builder.registerStaticUse(staticUse);
494 break;
495 }
496 }
466 impact.dynamicUses.forEach(builder.registerDynamicUse); 497 impact.dynamicUses.forEach(builder.registerDynamicUse);
467 for (TypeUse typeUse in impact.typeUses) { 498 for (TypeUse typeUse in impact.typeUses) {
468 if (typeUse.type.isTypedef) { 499 if (typeUse.type.isTypedef) {
469 typeUse = new TypeUse.internal(typeUse.type.unaliased, typeUse.kind); 500 typeUse = new TypeUse.internal(typeUse.type.unaliased, typeUse.kind);
470 } 501 }
471 builder.registerTypeUse(typeUse); 502 builder.registerTypeUse(typeUse);
472 } 503 }
473 impact.constantLiterals.forEach(builder.registerConstantLiteral); 504 impact.constantLiterals.forEach(builder.registerConstantLiteral);
474 impact.constSymbolNames.forEach(builder.registerConstSymbolName); 505 impact.constSymbolNames.forEach(builder.registerConstSymbolName);
475 impact.listLiterals.forEach(builder.registerListLiteral); 506 impact.listLiterals.forEach(builder.registerListLiteral);
476 impact.mapLiterals.forEach(builder.registerMapLiteral); 507 impact.mapLiterals.forEach(builder.registerMapLiteral);
477 for (Feature feature in impact.features) { 508 for (Feature feature in impact.features) {
478 switch (feature) { 509 switch (feature) {
479 case Feature.STRING_INTERPOLATION: 510 case Feature.STRING_INTERPOLATION:
480 case Feature.STRING_JUXTAPOSITION: 511 case Feature.STRING_JUXTAPOSITION:
481 // These are both converted into a string concatenation in kernel so 512 // These are both converted into a string concatenation in kernel so
482 // we cannot tell the diferrence. 513 // we cannot tell the difference.
483 builder.registerFeature(Feature.STRING_INTERPOLATION); 514 builder.registerFeature(Feature.STRING_INTERPOLATION);
484 builder.registerFeature(Feature.STRING_JUXTAPOSITION); 515 builder.registerFeature(Feature.STRING_JUXTAPOSITION);
485 break; 516 break;
486 case Feature.FALL_THROUGH_ERROR: 517 case Feature.FALL_THROUGH_ERROR:
487 LibraryElement library = 518 LibraryElement library =
488 compiler.libraryLoader.lookupLibrary(Uris.dart_core); 519 compiler.libraryLoader.lookupLibrary(Uris.dart_core);
489 ClassElement cls = 520 ClassElement cls =
490 library.implementation.localLookup('FallThroughError'); 521 library.implementation.localLookup('FallThroughError');
491 ConstructorElement constructor = cls.lookupConstructor(''); 522 ConstructorElement constructor = cls.lookupConstructor('');
492 builder.registerTypeUse(new TypeUse.instantiation(cls.thisType)); 523 builder.registerStaticUse(new StaticUse.typedConstructorInvoke(
493 builder.registerStaticUse(new StaticUse.constructorInvoke( 524 constructor, CallStructure.NO_ARGS, cls.thisType));
494 constructor, CallStructure.NO_ARGS));
495 builder.registerFeature(Feature.THROW_EXPRESSION); 525 builder.registerFeature(Feature.THROW_EXPRESSION);
496 break; 526 break;
497 default: 527 default:
498 builder.registerFeature(feature); 528 builder.registerFeature(feature);
499 break; 529 break;
500 } 530 }
501 } 531 }
502 impact.nativeData.forEach(builder.registerNativeData); 532 impact.nativeData.forEach(builder.registerNativeData);
503 return builder; 533 return builder;
504 } 534 }
OLDNEW
« pkg/compiler/lib/src/universe/use.dart ('K') | « pkg/compiler/lib/src/util/util.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698