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

Side by Side Diff: pkg/compiler/lib/src/universe/codegen_world_builder.dart

Issue 2916893002: Handle int constant (Closed)
Patch Set: Created 3 years, 6 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) 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 part of world_builder; 5 part of world_builder;
6 6
7 /// World builder specific to codegen. 7 /// World builder specific to codegen.
8 /// 8 ///
9 /// This adds additional access to liveness of selectors and elements. 9 /// This adds additional access to liveness of selectors and elements.
10 abstract class CodegenWorldBuilder implements WorldBuilder { 10 abstract class CodegenWorldBuilder implements WorldBuilder {
(...skipping 30 matching lines...) Expand all
41 Iterable<FunctionEntity> get staticFunctionsNeedingGetter; 41 Iterable<FunctionEntity> get staticFunctionsNeedingGetter;
42 Iterable<FunctionEntity> get methodsNeedingSuperGetter; 42 Iterable<FunctionEntity> get methodsNeedingSuperGetter;
43 43
44 /// The set of all referenced static fields. 44 /// The set of all referenced static fields.
45 /// 45 ///
46 /// Invariant: Elements are declaration elements. 46 /// Invariant: Elements are declaration elements.
47 Iterable<FieldEntity> get allReferencedStaticFields; 47 Iterable<FieldEntity> get allReferencedStaticFields;
48 48
49 /// Set of methods in instantiated classes that are potentially closurized. 49 /// Set of methods in instantiated classes that are potentially closurized.
50 Iterable<FunctionEntity> get closurizedMembers; 50 Iterable<FunctionEntity> get closurizedMembers;
51
52 /// Register [constant] as needed for emission.
53 void addCompileTimeConstantForEmission(ConstantValue constant);
54
55 /// Returns a list of constants topologically sorted so that dependencies
56 /// appear before the dependent constant. [preSortCompare] is a comparator
Siggi Cherem (dart-lang) 2017/06/01 22:28:43 nit: remove extra whitespace at the beginning of t
Johnni Winther 2017/06/02 11:17:24 Done.
57 /// function that gives the constants a consistent order prior to the
58 /// topological sort which gives the constants an ordering that is less
59 /// sensitive to perturbations in the source code.
60 List<ConstantValue> getConstantsForEmission([preSortCompare]);
51 } 61 }
52 62
53 abstract class CodegenWorldBuilderImpl implements CodegenWorldBuilder { 63 abstract class CodegenWorldBuilderImpl implements CodegenWorldBuilder {
54 final ElementEnvironment _elementEnvironment; 64 final ElementEnvironment _elementEnvironment;
55 final NativeBasicData _nativeBasicData; 65 final NativeBasicData _nativeBasicData;
56 final ClosedWorld _world; 66 final ClosedWorld _world;
57 67
58 /// The set of all directly instantiated classes, that is, classes with a 68 /// The set of all directly instantiated classes, that is, classes with a
59 /// generative constructor that has been called directly and not only through 69 /// generative constructor that has been called directly and not only through
60 /// a super-call. 70 /// a super-call.
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 return true; 490 return true;
481 } 491 }
482 return false; 492 return false;
483 } 493 }
484 494
485 while (cls != null && processClass(cls)) { 495 while (cls != null && processClass(cls)) {
486 cls = _elementEnvironment.getSuperClass(cls); 496 cls = _elementEnvironment.getSuperClass(cls);
487 } 497 }
488 } 498 }
489 499
490 bool registerConstantUse(ConstantUse use); 500 /** Set of all registered compiled constants. */
Siggi Cherem (dart-lang) 2017/06/01 22:28:43 nit: switch to ///
Johnni Winther 2017/06/02 11:17:24 Done.
501 final Set<ConstantValue> compiledConstants = new Set<ConstantValue>();
502
503 void addCompileTimeConstantForEmission(ConstantValue constant) {
504 compiledConstants.add(constant);
505 }
506
507 /**
508 * Returns a list of constants topologically sorted so that dependencies
Siggi Cherem (dart-lang) 2017/06/01 22:28:43 delete comment? (use @override)
Johnni Winther 2017/06/02 11:17:24 Done.
509 * appear before the dependent constant. [preSortCompare] is a comparator
510 * function that gives the constants a consistent order prior to the
511 * topological sort which gives the constants an ordering that is less
512 * sensitive to perturbations in the source code.
513 */
514 List<ConstantValue> getConstantsForEmission([preSortCompare]) {
515 // We must emit dependencies before their uses.
516 Set<ConstantValue> seenConstants = new Set<ConstantValue>();
517 List<ConstantValue> result = new List<ConstantValue>();
518
519 void addConstant(ConstantValue constant) {
520 if (!seenConstants.contains(constant)) {
521 constant.getDependencies().forEach(addConstant);
522 assert(!seenConstants.contains(constant));
523 result.add(constant);
524 seenConstants.add(constant);
525 }
526 }
527
528 List<ConstantValue> sorted = compiledConstants.toList();
529 if (preSortCompare != null) {
530 sorted.sort(preSortCompare);
531 }
532 sorted.forEach(addConstant);
533 return result;
534 }
535
536 /// Register the constant [use] with this world builder. Returns `true` if
537 /// the constant use was new to the world.
538 bool registerConstantUse(ConstantUse use) {
539 if (use.kind == ConstantUseKind.DIRECT) {
540 addCompileTimeConstantForEmission(use.value);
541 }
542 return _constantValues.add(use.value);
543 }
491 } 544 }
492 545
493 class ElementCodegenWorldBuilderImpl extends CodegenWorldBuilderImpl { 546 class ElementCodegenWorldBuilderImpl extends CodegenWorldBuilderImpl {
494 final JavaScriptConstantCompiler _constants;
495
496 ElementCodegenWorldBuilderImpl( 547 ElementCodegenWorldBuilderImpl(
497 ElementEnvironment elementEnvironment, 548 ElementEnvironment elementEnvironment,
498 NativeBasicData nativeBasicData, 549 NativeBasicData nativeBasicData,
499 ClosedWorld world, 550 ClosedWorld world,
500 this._constants,
501 SelectorConstraintsStrategy selectorConstraintsStrategy) 551 SelectorConstraintsStrategy selectorConstraintsStrategy)
502 : super(elementEnvironment, nativeBasicData, world, 552 : super(elementEnvironment, nativeBasicData, world,
503 selectorConstraintsStrategy); 553 selectorConstraintsStrategy);
504 554
505 /// Calls [f] with every instance field, together with its declarer, in an 555 /// Calls [f] with every instance field, together with its declarer, in an
506 /// instance of [cls]. 556 /// instance of [cls].
507 void forEachInstanceField( 557 void forEachInstanceField(
508 ClassElement cls, void f(ClassEntity declarer, FieldEntity field)) { 558 ClassElement cls, void f(ClassEntity declarer, FieldEntity field)) {
509 cls.implementation 559 cls.implementation
510 .forEachInstanceField(f, includeSuperAndInjectedMembers: true); 560 .forEachInstanceField(f, includeSuperAndInjectedMembers: true);
(...skipping 23 matching lines...) Expand all
534 return super._getMemberUsage(member, memberUsed); 584 return super._getMemberUsage(member, memberUsed);
535 } 585 }
536 586
537 void registerStaticUse(StaticUse staticUse, MemberUsedCallback memberUsed) { 587 void registerStaticUse(StaticUse staticUse, MemberUsedCallback memberUsed) {
538 Element element = staticUse.element; 588 Element element = staticUse.element;
539 assert(element.isDeclaration, 589 assert(element.isDeclaration,
540 failedAt(element, "Element ${element} is not the declaration.")); 590 failedAt(element, "Element ${element} is not the declaration."));
541 super.registerStaticUse(staticUse, memberUsed); 591 super.registerStaticUse(staticUse, memberUsed);
542 } 592 }
543 593
544 /// Register the constant [use] with this world builder. Returns `true` if
545 /// the constant use was new to the world.
546 @override
547 bool registerConstantUse(ConstantUse use) {
548 if (use.kind == ConstantUseKind.DIRECT) {
549 _constants.addCompileTimeConstantForEmission(use.value);
550 }
551 return _constantValues.add(use.value);
552 }
553
554 void registerIsCheck(ResolutionDartType type) { 594 void registerIsCheck(ResolutionDartType type) {
555 // Even in checked mode, type annotations for return type and argument 595 // Even in checked mode, type annotations for return type and argument
556 // types do not imply type checks, so there should never be a check 596 // types do not imply type checks, so there should never be a check
557 // against the type variable of a typedef. 597 // against the type variable of a typedef.
558 assert(!type.isTypeVariable || !type.element.enclosingElement.isTypedef); 598 assert(!type.isTypeVariable || !type.element.enclosingElement.isTypedef);
559 super.registerIsCheck(type); 599 super.registerIsCheck(type);
560 } 600 }
561 } 601 }
562 602
563 class KernelCodegenWorldBuilder extends CodegenWorldBuilderImpl { 603 class KernelCodegenWorldBuilder extends CodegenWorldBuilderImpl {
564 KernelCodegenWorldBuilder( 604 KernelCodegenWorldBuilder(
565 ElementEnvironment elementEnvironment, 605 ElementEnvironment elementEnvironment,
566 NativeBasicData nativeBasicData, 606 NativeBasicData nativeBasicData,
567 ClosedWorld world, 607 ClosedWorld world,
568 SelectorConstraintsStrategy selectorConstraintsStrategy) 608 SelectorConstraintsStrategy selectorConstraintsStrategy)
569 : super(elementEnvironment, nativeBasicData, world, 609 : super(elementEnvironment, nativeBasicData, world,
570 selectorConstraintsStrategy); 610 selectorConstraintsStrategy);
571 611
572 @override 612 @override
573 bool registerConstantUse(ConstantUse use) {
574 throw new UnimplementedError(
575 'KernelCodegenWorldBuilder.registerConstantUse');
576 }
577
578 @override
579 void forEachParameter( 613 void forEachParameter(
580 FunctionEntity function, void f(DartType type, String name)) { 614 FunctionEntity function, void f(DartType type, String name)) {
581 throw new UnimplementedError('KernelCodegenWorldBuilder.forEachParameter'); 615 throw new UnimplementedError('KernelCodegenWorldBuilder.forEachParameter');
582 } 616 }
583 617
584 @override 618 @override
585 void forEachInstanceField( 619 void forEachInstanceField(
586 ClassEntity cls, void f(ClassEntity declarer, FieldEntity field)) { 620 ClassEntity cls, void f(ClassEntity declarer, FieldEntity field)) {
587 throw new UnimplementedError( 621 throw new UnimplementedError(
588 'KernelCodegenWorldBuilder.forEachInstanceField'); 622 'KernelCodegenWorldBuilder.forEachInstanceField');
589 } 623 }
590 } 624 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698