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

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: Create CoreTypes in AnalyzerLoader. 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' 47 import 'package:kernel/transformations/mixin_full_resolution.dart'
49 show MixinFullResolution; 48 show MixinFullResolution;
50 49
51 import 'package:kernel/type_algebra.dart' show substitute; 50 import 'package:kernel/type_algebra.dart' show substitute;
52 51
53 import '../source/source_loader.dart' show SourceLoader; 52 import '../source/source_loader.dart' show SourceLoader;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 loader.resolveConstructors(); 246 loader.resolveConstructors();
248 loader.finishTypeVariables(objectClassBuilder); 247 loader.finishTypeVariables(objectClassBuilder);
249 _program = 248 _program =
250 link(new List<Library>.from(loader.libraries), nameRoot: nameRoot); 249 link(new List<Library>.from(loader.libraries), nameRoot: nameRoot);
251 loader.computeHierarchy(_program); 250 loader.computeHierarchy(_program);
252 loader.checkOverrides(sourceClasses); 251 loader.checkOverrides(sourceClasses);
253 loader.prepareInitializerInference(); 252 loader.prepareInitializerInference();
254 loader.performInitializerInference(); 253 loader.performInitializerInference();
255 } on InputError catch (e) { 254 } on InputError catch (e) {
256 handleInputError(e, isFullProgram: false); 255 handleInputError(e, isFullProgram: false);
256 // TODO(scheglov) Normally we create CoreTypes and ClassHierarchy.
257 // But if there is an exception, they are not created, and when we later
258 // blindly continue with buildProgram(), we crash.
259 loader.computeHierarchy(_program);
ahe 2017/05/29 14:08:46 If there's an InputError during buildOutlines, we
scheglov 2017/05/30 00:06:10 "We shouldn't call" as "It is a known existing pro
ahe 2017/05/30 09:35:14 I didn't know about it before seeing this change.
scheglov 2017/05/30 16:10:21 Well, it is a pre-existing problem. My feeling is
ahe 2017/05/31 11:20:16 I completely understand why you get that feeling w
scheglov 2017/05/31 16:49:37 Nice. Thank you. I removed this workaround.
257 } catch (e, s) { 260 } catch (e, s) {
258 return reportCrash(e, s, loader?.currentUriForCrashReporting); 261 return reportCrash(e, s, loader?.currentUriForCrashReporting);
259 } 262 }
260 return _program; 263 return _program;
261 } 264 }
262 265
263 /// Build the kernel representation of the program loaded by this target. The 266 /// Build the kernel representation of the program loaded by this target. The
264 /// program will contain full bodies for the code loaded from sources, and 267 /// program will contain full bodies for the code loaded from sources, and
265 /// only references to the code loaded by the [DillTarget], which may or may 268 /// only references to the code loaded by the [DillTarget], which may or may
266 /// not include method bodies (depending on what was loaded into that target, 269 /// not include method bodies (depending on what was loaded into that target,
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 } 658 }
656 659
657 /// Run all transformations that are needed when building a program for the 660 /// Run all transformations that are needed when building a program for the
658 /// first time. 661 /// first time.
659 void runBuildTransformations() { 662 void runBuildTransformations() {
660 transformMixinApplications(); 663 transformMixinApplications();
661 otherTransformations(); 664 otherTransformations();
662 } 665 }
663 666
664 void transformMixinApplications() { 667 void transformMixinApplications() {
665 new MixinFullResolution(backendTarget).transform(_program); 668 new MixinFullResolution(backendTarget, loader.coreTypes)
669 .transform(_program);
666 ticker.logMs("Transformed mixin applications"); 670 ticker.logMs("Transformed mixin applications");
667 } 671 }
668 672
669 void otherTransformations() { 673 void otherTransformations() {
670 // TODO(ahe): Don't generate type variables in the first place. 674 // TODO(ahe): Don't generate type variables in the first place.
671 if (!strongMode) { 675 if (!strongMode) {
672 _program.accept(new Erasure()); 676 _program.accept(new Erasure());
673 ticker.logMs("Erased type variables in generic methods"); 677 ticker.logMs("Erased type variables in generic methods");
674 } 678 }
675 var coreTypes = new CoreTypes(_program);
676 // TODO(kmillikin): Make this run on a per-method basis. 679 // TODO(kmillikin): Make this run on a per-method basis.
677 transformAsync.transformLibraries(coreTypes, loader.libraries); 680 transformAsync.transformLibraries(loader.coreTypes, loader.libraries);
678 ticker.logMs("Transformed async methods"); 681 ticker.logMs("Transformed async methods");
679 } 682 }
680 683
681 void verify() { 684 void verify() {
682 var verifyErrors = verifyProgram(_program); 685 var verifyErrors = verifyProgram(_program);
683 errors.addAll(verifyErrors.map((error) => '$error')); 686 errors.addAll(verifyErrors.map((error) => '$error'));
684 ticker.logMs("Verified program"); 687 ticker.logMs("Verified program");
685 } 688 }
686 689
687 /// Tree-shakes most code from the [dillTarget] by visiting all other 690 /// Tree-shakes most code from the [dillTarget] by visiting all other
688 /// libraries in [_program] and marking the APIs from the [dillTarget] 691 /// libraries in [_program] and marking the APIs from the [dillTarget]
689 /// libraries that are in use. 692 /// libraries that are in use.
690 /// 693 ///
691 /// Note: while it's likely we'll do some trimming of programs for modular 694 /// Note: while it's likely we'll do some trimming of programs for modular
692 /// compilation, it is unclear at this time when and how that trimming should 695 /// compilation, it is unclear at this time when and how that trimming should
693 /// happen. We are likely going to remove the extra visitor my either marking 696 /// happen. We are likely going to remove the extra visitor my either marking
694 /// things while code is built, or by handling tree-shaking after the fact 697 /// things while code is built, or by handling tree-shaking after the fact
695 /// (e.g. during serialization). 698 /// (e.g. during serialization).
696 trimDependenciesInProgram() { 699 trimDependenciesInProgram() {
697 var toShake = 700 var toShake =
698 dillTarget.loader.libraries.map((lib) => lib.importUri).toSet(); 701 dillTarget.loader.libraries.map((lib) => lib.importUri).toSet();
699 var isIncluded = (Uri uri) => !toShake.contains(uri); 702 var isIncluded = (Uri uri) => !toShake.contains(uri);
700 var data = new RetainedDataBuilder(); 703 var data = new RetainedDataBuilder();
701 // TODO(sigmund): replace this step with data that is directly computed from 704 // TODO(sigmund): replace this step with data that is directly computed from
702 // the builders: we should know the tree-shaking roots without having to do 705 // the builders: we should know the tree-shaking roots without having to do
703 // a second visit over the tree. 706 // a second visit over the tree.
704 new RootsMarker(data).run(_program, isIncluded); 707 new RootsMarker(loader.coreTypes, data).run(_program, isIncluded);
705 trimProgram(_program, data, isIncluded); 708 trimProgram(_program, data, isIncluded);
706 } 709 }
707 710
708 /// Return `true` if the given [library] was built by this [KernelTarget] 711 /// Return `true` if the given [library] was built by this [KernelTarget]
709 /// from sources, and not loaded from a [DillTarget]. 712 /// from sources, and not loaded from a [DillTarget].
710 bool isSourceLibrary(Library library) { 713 bool isSourceLibrary(Library library) {
711 return loader.libraries.contains(library); 714 return loader.libraries.contains(library);
712 } 715 }
713 } 716 }
714 717
715 /// Looks for a constructor call that matches `super()` from a constructor in 718 /// Looks for a constructor call that matches `super()` from a constructor in
716 /// [cls]. Such a constructor may have optional arguments, but no required 719 /// [cls]. Such a constructor may have optional arguments, but no required
717 /// arguments. 720 /// arguments.
718 Constructor defaultSuperConstructor(Class cls) { 721 Constructor defaultSuperConstructor(Class cls) {
719 Class superclass = cls.superclass; 722 Class superclass = cls.superclass;
720 while (superclass != null && superclass.isMixinApplication) { 723 while (superclass != null && superclass.isMixinApplication) {
721 superclass = superclass.superclass; 724 superclass = superclass.superclass;
722 } 725 }
723 for (Constructor constructor in superclass.constructors) { 726 for (Constructor constructor in superclass.constructors) {
724 if (constructor.name.name.isEmpty) { 727 if (constructor.name.name.isEmpty) {
725 return constructor.function.requiredParameterCount == 0 728 return constructor.function.requiredParameterCount == 0
726 ? constructor 729 ? constructor
727 : null; 730 : null;
728 } 731 }
729 } 732 }
730 return null; 733 return null;
731 } 734 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698