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

Side by Side Diff: pkg/kernel/lib/analyzer/loader.dart

Issue 2562923002: Use sdk summaries in front_end/kernel_generator. (Closed)
Patch Set: lint: dartfmt Created 4 years 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
« no previous file with comments | « pkg/front_end/tool/perf.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 library kernel.analyzer.loader; 4 library kernel.analyzer.loader;
5 5
6 import 'dart:async'; 6 import 'dart:async';
7 import 'dart:io' as io; 7 import 'dart:io' as io;
8 8
9 import 'package:analyzer/analyzer.dart'; 9 import 'package:analyzer/analyzer.dart';
10 import 'package:analyzer/file_system/file_system.dart'; 10 import 'package:analyzer/file_system/file_system.dart';
11 import 'package:analyzer/file_system/physical_file_system.dart'; 11 import 'package:analyzer/file_system/physical_file_system.dart';
12 import 'package:analyzer/source/package_map_resolver.dart'; 12 import 'package:analyzer/source/package_map_resolver.dart';
13 import 'package:analyzer/src/dart/scanner/scanner.dart'; 13 import 'package:analyzer/src/dart/scanner/scanner.dart';
14 import 'package:analyzer/src/dart/sdk/sdk.dart'; 14 import 'package:analyzer/src/dart/sdk/sdk.dart';
15 import 'package:analyzer/src/generated/engine.dart'; 15 import 'package:analyzer/src/generated/engine.dart';
16 import 'package:analyzer/src/generated/parser.dart'; 16 import 'package:analyzer/src/generated/parser.dart';
17 import 'package:analyzer/src/generated/sdk.dart'; 17 import 'package:analyzer/src/generated/sdk.dart';
18 import 'package:analyzer/src/generated/source_io.dart'; 18 import 'package:analyzer/src/generated/source_io.dart';
19 import 'package:analyzer/src/summary/summary_sdk.dart';
19 import 'package:kernel/application_root.dart'; 20 import 'package:kernel/application_root.dart';
20 import 'package:package_config/discovery.dart'; 21 import 'package:package_config/discovery.dart';
21 import 'package:package_config/packages.dart'; 22 import 'package:package_config/packages.dart';
22 23
23 import '../ast.dart' as ast; 24 import '../ast.dart' as ast;
24 import '../repository.dart'; 25 import '../repository.dart';
25 import '../target/targets.dart' show Target; 26 import '../target/targets.dart' show Target;
26 import '../type_algebra.dart'; 27 import '../type_algebra.dart';
27 import 'analyzer.dart'; 28 import 'analyzer.dart';
28 import 'ast_from_analyzer.dart'; 29 import 'ast_from_analyzer.dart';
29 30
30 /// Options passed to the Dart frontend. 31 /// Options passed to the Dart frontend.
31 class DartOptions { 32 class DartOptions {
32 /// True if user code should be loaded in strong mode. 33 /// True if user code should be loaded in strong mode.
33 bool strongMode; 34 bool strongMode;
34 35
35 /// True if the Dart SDK should be loaded in strong mode. 36 /// True if the Dart SDK should be loaded in strong mode.
36 bool strongModeSdk; 37 bool strongModeSdk;
38
39 /// Path to the sdk sources, ignored if sdkSummary is provided.
37 String sdk; 40 String sdk;
41
42 /// Path to a summary of the sdk sources.
43 String sdkSummary;
44
45 /// Path to the `.packages` file.
38 String packagePath; 46 String packagePath;
47
48 /// Root used to relativize app file-urls, making them machine agnostic.
39 ApplicationRoot applicationRoot; 49 ApplicationRoot applicationRoot;
50
40 Map<Uri, Uri> customUriMappings; 51 Map<Uri, Uri> customUriMappings;
52
53 /// Environment definitions provided via `-Dkey=value`.
41 Map<String, String> declaredVariables; 54 Map<String, String> declaredVariables;
42 55
43 DartOptions( 56 DartOptions(
44 {bool strongMode: false, 57 {bool strongMode: false,
45 bool strongModeSdk, 58 bool strongModeSdk,
46 this.sdk, 59 this.sdk,
60 this.sdkSummary,
47 this.packagePath, 61 this.packagePath,
48 ApplicationRoot applicationRoot, 62 ApplicationRoot applicationRoot,
49 Map<Uri, Uri> customUriMappings, 63 Map<Uri, Uri> customUriMappings,
50 Map<String, String> declaredVariables}) 64 Map<String, String> declaredVariables})
51 : this.customUriMappings = customUriMappings ?? <Uri, Uri>{}, 65 : this.customUriMappings = customUriMappings ?? <Uri, Uri>{},
52 this.declaredVariables = declaredVariables ?? <String, String>{}, 66 this.declaredVariables = declaredVariables ?? <String, String>{},
53 this.strongMode = strongMode, 67 this.strongMode = strongMode,
54 this.strongModeSdk = strongModeSdk ?? strongMode, 68 this.strongModeSdk = strongModeSdk ?? strongMode,
55 this.applicationRoot = applicationRoot ?? new ApplicationRoot.none(); 69 this.applicationRoot = applicationRoot ?? new ApplicationRoot.none();
56 } 70 }
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 if (error.errorCode is CompileTimeErrorCode || 627 if (error.errorCode is CompileTimeErrorCode ||
614 error.errorCode is ParserErrorCode || 628 error.errorCode is ParserErrorCode ||
615 error.errorCode is ScannerErrorCode || 629 error.errorCode is ScannerErrorCode ||
616 error.errorCode is StrongModeCode) { 630 error.errorCode is StrongModeCode) {
617 lines ??= context.computeLineInfo(source); 631 lines ??= context.computeLineInfo(source);
618 errors.add(formatErrorMessage(error, source.shortName, lines)); 632 errors.add(formatErrorMessage(error, source.shortName, lines));
619 } 633 }
620 } 634 }
621 } 635 }
622 636
623 void loadEverything({Target target}) { 637 void loadEverything({Target target, bool compileSdk}) {
624 ensureLibraryIsLoaded(getLibraryReference(getDartCoreLibrary())); 638 compileSdk ??= true;
625 if (target != null) { 639 if (compileSdk) {
626 for (var uri in target.extraRequiredLibraries) { 640 ensureLibraryIsLoaded(getLibraryReference(getDartCoreLibrary()));
627 var library = _findLibraryElement(uri); 641 if (target != null) {
628 if (library == null) { 642 for (var uri in target.extraRequiredLibraries) {
629 errors.add('Could not find required library $uri'); 643 var library = _findLibraryElement(uri);
630 continue; 644 if (library == null) {
645 errors.add('Could not find required library $uri');
646 continue;
647 }
648 ensureLibraryIsLoaded(getLibraryReference(library));
631 } 649 }
632 ensureLibraryIsLoaded(getLibraryReference(library));
633 } 650 }
634 } 651 }
635 for (int i = 0; i < repository.libraries.length; ++i) { 652 for (int i = 0; i < repository.libraries.length; ++i) {
636 ensureLibraryIsLoaded(repository.libraries[i]); 653 var library = repository.libraries[i];
654 if (compileSdk || library.importUri.scheme != 'dart') {
655 ensureLibraryIsLoaded(library);
656 }
637 } 657 }
638 } 658 }
639 659
640 /// Builds a list of sources that have been loaded. 660 /// Builds a list of sources that have been loaded.
641 /// 661 ///
642 /// This operation may be expensive and should only be used for diagnostics. 662 /// This operation may be expensive and should only be used for diagnostics.
643 List<String> getLoadedFileNames() { 663 List<String> getLoadedFileNames() {
644 var list = <String>[]; 664 var list = <String>[];
645 for (var library in repository.libraries) { 665 for (var library in repository.libraries) {
646 LibraryElement element = context.computeLibraryElement(context 666 LibraryElement element = context.computeLibraryElement(context
647 .sourceFactory 667 .sourceFactory
648 .forUri2(applicationRoot.absoluteUri(library.importUri))); 668 .forUri2(applicationRoot.absoluteUri(library.importUri)));
649 for (var unit in element.units) { 669 for (var unit in element.units) {
650 list.add(unit.source.fullName); 670 list.add(unit.source.fullName);
651 } 671 }
652 } 672 }
653 return list; 673 return list;
654 } 674 }
655 675
656 void _iterateWorklist() { 676 void _iterateWorklist() {
657 while (temporaryClassWorklist.isNotEmpty) { 677 while (temporaryClassWorklist.isNotEmpty) {
658 var element = temporaryClassWorklist.removeLast(); 678 var element = temporaryClassWorklist.removeLast();
659 promoteToTypeLevel(element); 679 promoteToTypeLevel(element);
660 } 680 }
661 } 681 }
662 682
663 ast.Program loadProgram(Uri mainLibrary, {Target target}) { 683 ast.Program loadProgram(Uri mainLibrary, {Target target, bool compileSdk}) {
664 ast.Library library = repository 684 ast.Library library = repository
665 .getLibraryReference(applicationRoot.relativeUri(mainLibrary)); 685 .getLibraryReference(applicationRoot.relativeUri(mainLibrary));
666 ensureLibraryIsLoaded(library); 686 ensureLibraryIsLoaded(library);
667 loadEverything(target: target); 687 loadEverything(target: target, compileSdk: compileSdk);
668 var program = new ast.Program(repository.libraries); 688 var program = new ast.Program(repository.libraries);
669 program.mainMethod = library.procedures.firstWhere( 689 program.mainMethod = library.procedures.firstWhere(
670 (member) => member.name?.name == 'main', 690 (member) => member.name?.name == 'main',
671 orElse: () => null); 691 orElse: () => null);
672 for (LibraryElement libraryElement in libraryElements) { 692 for (LibraryElement libraryElement in libraryElements) {
673 for (CompilationUnitElement compilationUnitElement 693 for (CompilationUnitElement compilationUnitElement
674 in libraryElement.units) { 694 in libraryElement.units) {
675 var source = compilationUnitElement.source; 695 var source = compilationUnitElement.source;
676 LineInfo lineInfo = context.computeLineInfo(source); 696 LineInfo lineInfo = context.computeLineInfo(source);
677 program.uriToLineStarts["file://${source.fullName}"] = 697 program.uriToLineStarts["file://${source.fullName}"] =
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 AnalysisOptions createAnalysisOptions(bool strongMode) { 776 AnalysisOptions createAnalysisOptions(bool strongMode) {
757 return new AnalysisOptionsImpl() 777 return new AnalysisOptionsImpl()
758 ..strongMode = strongMode 778 ..strongMode = strongMode
759 ..generateImplicitErrors = false 779 ..generateImplicitErrors = false
760 ..generateSdkErrors = false 780 ..generateSdkErrors = false
761 ..preserveComments = false 781 ..preserveComments = false
762 ..hint = false 782 ..hint = false
763 ..enableSuperMixins = true; 783 ..enableSuperMixins = true;
764 } 784 }
765 785
766 DartSdk createDartSdk(String path, {bool strongMode}) { 786 DartSdk createDartSdk(String path, {bool strongMode, bool isSummary}) {
787 if (isSummary) {
788 return new SummaryBasedDartSdk(path, strongMode);
789 }
767 var resources = PhysicalResourceProvider.INSTANCE; 790 var resources = PhysicalResourceProvider.INSTANCE;
768 return new FolderBasedDartSdk(resources, resources.getFolder(path)) 791 return new FolderBasedDartSdk(resources, resources.getFolder(path))
769 ..context 792 ..context
770 .analysisOptions 793 .analysisOptions
771 .setCrossContextOptionsFrom(createAnalysisOptions(strongMode)); 794 .setCrossContextOptionsFrom(createAnalysisOptions(strongMode));
772 } 795 }
773 796
774 class CustomUriResolver extends UriResolver { 797 class CustomUriResolver extends UriResolver {
775 final ResourceUriResolver _resourceUriResolver; 798 final ResourceUriResolver _resourceUriResolver;
776 final Map<Uri, Uri> _customUrlMappings; 799 final Map<Uri, Uri> _customUrlMappings;
(...skipping 22 matching lines...) Expand all
799 return _resourceUriResolver.resolveAbsolute(mapped, actualUri); 822 return _resourceUriResolver.resolveAbsolute(mapped, actualUri);
800 } 823 }
801 824
802 Uri restoreAbsolute(Source source) { 825 Uri restoreAbsolute(Source source) {
803 return _resourceUriResolver.restoreAbsolute(source); 826 return _resourceUriResolver.restoreAbsolute(source);
804 } 827 }
805 } 828 }
806 829
807 AnalysisContext createContext(DartOptions options, Packages packages, 830 AnalysisContext createContext(DartOptions options, Packages packages,
808 {DartSdk dartSdk}) { 831 {DartSdk dartSdk}) {
809 dartSdk ??= createDartSdk(options.sdk, strongMode: options.strongModeSdk); 832 bool fromSummary = options.sdkSummary != null;
833 dartSdk ??= createDartSdk(fromSummary ? options.sdkSummary : options.sdk,
834 strongMode: options.strongModeSdk, isSummary: fromSummary);
810 835
811 var resourceProvider = PhysicalResourceProvider.INSTANCE; 836 var resourceProvider = PhysicalResourceProvider.INSTANCE;
812 var resourceUriResolver = new ResourceUriResolver(resourceProvider); 837 var resourceUriResolver = new ResourceUriResolver(resourceProvider);
813 List<UriResolver> resolvers = []; 838 List<UriResolver> resolvers = [];
814 var customUriMappings = options.customUriMappings; 839 var customUriMappings = options.customUriMappings;
815 if (customUriMappings != null && customUriMappings.length > 0) { 840 if (customUriMappings != null && customUriMappings.length > 0) {
816 resolvers 841 resolvers
817 .add(new CustomUriResolver(resourceUriResolver, customUriMappings)); 842 .add(new CustomUriResolver(resourceUriResolver, customUriMappings));
818 } 843 }
819 resolvers.add(new DartUriResolver(dartSdk)); 844 resolvers.add(new DartUriResolver(dartSdk));
(...skipping 11 matching lines...) Expand all
831 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext() 856 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext()
832 ..sourceFactory = new SourceFactory(resolvers) 857 ..sourceFactory = new SourceFactory(resolvers)
833 ..analysisOptions = createAnalysisOptions(options.strongMode); 858 ..analysisOptions = createAnalysisOptions(options.strongMode);
834 859
835 options.declaredVariables.forEach((String name, String value) { 860 options.declaredVariables.forEach((String name, String value) {
836 context.declaredVariables.define(name, value); 861 context.declaredVariables.define(name, value);
837 }); 862 });
838 863
839 return context; 864 return context;
840 } 865 }
OLDNEW
« no previous file with comments | « pkg/front_end/tool/perf.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698