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

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/kernel_target.dart

Issue 2904203003: Don't recreate CoreTypes in transformers. Pass it in. (Closed)
Patch Set: Don't create CoreTypes in createOutlines() on InputError. 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) 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 fasta.kernel_target; 5 library fasta.kernel_target;
6 6
7 import 'dart:async' show Future; 7 import 'dart:async' show Future;
8 8
9 import 'dart:io' show File; 9 import 'dart:io' show File;
10 10
(...skipping 22 matching lines...) Expand all
33 Program, 33 Program,
34 Source, 34 Source,
35 StringLiteral, 35 StringLiteral,
36 SuperInitializer, 36 SuperInitializer,
37 Throw, 37 Throw,
38 TypeParameter, 38 TypeParameter,
39 VariableDeclaration, 39 VariableDeclaration,
40 VariableGet, 40 VariableGet,
41 VoidType; 41 VoidType;
42 42
43 import 'package:kernel/core_types.dart' show CoreTypes;
44 import 'package:kernel/transformations/erasure.dart' show Erasure; 43 import 'package:kernel/transformations/erasure.dart' show Erasure;
45 44
46 import 'package:kernel/transformations/continuation.dart' as transformAsync; 45 import 'package:kernel/transformations/continuation.dart' as transformAsync;
47 46
48 import 'package:kernel/transformations/mixin_full_resolution.dart' as mix; 47 import 'package:kernel/transformations/mixin_full_resolution.dart' as mix;
49 48
50 import 'package:kernel/type_algebra.dart' show substitute; 49 import 'package:kernel/type_algebra.dart' show substitute;
51 50
52 import '../source/source_loader.dart' show SourceLoader; 51 import '../source/source_loader.dart' show SourceLoader;
53 52
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 } 652 }
654 653
655 /// Run all transformations that are needed when building a program for the 654 /// Run all transformations that are needed when building a program for the
656 /// first time. 655 /// first time.
657 void runBuildTransformations() { 656 void runBuildTransformations() {
658 transformMixinApplications(); 657 transformMixinApplications();
659 otherTransformations(); 658 otherTransformations();
660 } 659 }
661 660
662 void transformMixinApplications() { 661 void transformMixinApplications() {
663 mix.transformLibraries(backendTarget, loader.libraries); 662 mix.transformLibraries(backendTarget, loader.coreTypes, loader.libraries);
664 ticker.logMs("Transformed mixin applications"); 663 ticker.logMs("Transformed mixin applications");
665 } 664 }
666 665
667 void otherTransformations() { 666 void otherTransformations() {
668 // TODO(ahe): Don't generate type variables in the first place. 667 // TODO(ahe): Don't generate type variables in the first place.
669 if (!strongMode) { 668 if (!strongMode) {
670 _program.accept(new Erasure()); 669 _program.accept(new Erasure());
671 ticker.logMs("Erased type variables in generic methods"); 670 ticker.logMs("Erased type variables in generic methods");
672 } 671 }
673 var coreTypes = new CoreTypes(_program);
674 // TODO(kmillikin): Make this run on a per-method basis. 672 // TODO(kmillikin): Make this run on a per-method basis.
675 transformAsync.transformLibraries(coreTypes, loader.libraries); 673 transformAsync.transformLibraries(loader.coreTypes, loader.libraries);
676 ticker.logMs("Transformed async methods"); 674 ticker.logMs("Transformed async methods");
677 } 675 }
678 676
679 void verify() { 677 void verify() {
680 var verifyErrors = verifyProgram(_program); 678 var verifyErrors = verifyProgram(_program);
681 errors.addAll(verifyErrors.map((error) => '$error')); 679 errors.addAll(verifyErrors.map((error) => '$error'));
682 ticker.logMs("Verified program"); 680 ticker.logMs("Verified program");
683 } 681 }
684 682
685 /// Tree-shakes most code from the [dillTarget] by visiting all other 683 /// Tree-shakes most code from the [dillTarget] by visiting all other
686 /// libraries in [_program] and marking the APIs from the [dillTarget] 684 /// libraries in [_program] and marking the APIs from the [dillTarget]
687 /// libraries that are in use. 685 /// libraries that are in use.
688 /// 686 ///
689 /// Note: while it's likely we'll do some trimming of programs for modular 687 /// Note: while it's likely we'll do some trimming of programs for modular
690 /// compilation, it is unclear at this time when and how that trimming should 688 /// compilation, it is unclear at this time when and how that trimming should
691 /// happen. We are likely going to remove the extra visitor my either marking 689 /// happen. We are likely going to remove the extra visitor my either marking
692 /// things while code is built, or by handling tree-shaking after the fact 690 /// things while code is built, or by handling tree-shaking after the fact
693 /// (e.g. during serialization). 691 /// (e.g. during serialization).
694 trimDependenciesInProgram() { 692 trimDependenciesInProgram() {
695 var toShake = 693 var toShake =
696 dillTarget.loader.libraries.map((lib) => lib.importUri).toSet(); 694 dillTarget.loader.libraries.map((lib) => lib.importUri).toSet();
697 var isIncluded = (Uri uri) => !toShake.contains(uri); 695 var isIncluded = (Uri uri) => !toShake.contains(uri);
698 var data = new RetainedDataBuilder(); 696 var data = new RetainedDataBuilder();
699 // TODO(sigmund): replace this step with data that is directly computed from 697 // TODO(sigmund): replace this step with data that is directly computed from
700 // the builders: we should know the tree-shaking roots without having to do 698 // the builders: we should know the tree-shaking roots without having to do
701 // a second visit over the tree. 699 // a second visit over the tree.
702 new RootsMarker(data).run(_program, isIncluded); 700 new RootsMarker(loader.coreTypes, data).run(_program, isIncluded);
703 trimProgram(_program, data, isIncluded); 701 trimProgram(_program, data, isIncluded);
704 } 702 }
705 703
706 /// Return `true` if the given [library] was built by this [KernelTarget] 704 /// Return `true` if the given [library] was built by this [KernelTarget]
707 /// from sources, and not loaded from a [DillTarget]. 705 /// from sources, and not loaded from a [DillTarget].
708 bool isSourceLibrary(Library library) { 706 bool isSourceLibrary(Library library) {
709 return loader.libraries.contains(library); 707 return loader.libraries.contains(library);
710 } 708 }
711 } 709 }
712 710
713 /// Looks for a constructor call that matches `super()` from a constructor in 711 /// Looks for a constructor call that matches `super()` from a constructor in
714 /// [cls]. Such a constructor may have optional arguments, but no required 712 /// [cls]. Such a constructor may have optional arguments, but no required
715 /// arguments. 713 /// arguments.
716 Constructor defaultSuperConstructor(Class cls) { 714 Constructor defaultSuperConstructor(Class cls) {
717 Class superclass = cls.superclass; 715 Class superclass = cls.superclass;
718 while (superclass != null && superclass.isMixinApplication) { 716 while (superclass != null && superclass.isMixinApplication) {
719 superclass = superclass.superclass; 717 superclass = superclass.superclass;
720 } 718 }
721 for (Constructor constructor in superclass.constructors) { 719 for (Constructor constructor in superclass.constructors) {
722 if (constructor.name.name.isEmpty) { 720 if (constructor.name.name.isEmpty) {
723 return constructor.function.requiredParameterCount == 0 721 return constructor.function.requiredParameterCount == 0
724 ? constructor 722 ? constructor
725 : null; 723 : null;
726 } 724 }
727 } 725 }
728 return null; 726 return null;
729 } 727 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/kernel_outline_shaker.dart ('k') | pkg/kernel/bin/transform.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698