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

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

Issue 1338783002: Show import chains for unsupported dart:* library imports. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Cleanup. Created 5 years, 3 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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.compiler_base; 5 library dart2js.compiler_base;
6 6
7 import 'dart:async' show 7 import 'dart:async' show
8 EventSink, 8 EventSink,
9 Future; 9 Future;
10 10
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 import 'tree/tree.dart' show 126 import 'tree/tree.dart' show
127 Node; 127 Node;
128 import 'typechecker.dart' show 128 import 'typechecker.dart' show
129 TypeCheckerTask; 129 TypeCheckerTask;
130 import 'types/types.dart' as ti; 130 import 'types/types.dart' as ti;
131 import 'universe/universe.dart' show 131 import 'universe/universe.dart' show
132 CallStructure, 132 CallStructure,
133 Selector, 133 Selector,
134 Universe; 134 Universe;
135 import 'util/util.dart' show 135 import 'util/util.dart' show
136 Link; 136 Link,
137 Setlet;
137 import 'world.dart' show 138 import 'world.dart' show
138 World; 139 World;
139 140
140 abstract class Compiler implements DiagnosticListener { 141 abstract class Compiler implements DiagnosticListener {
141 142
142 final Stopwatch totalCompileTime = new Stopwatch(); 143 final Stopwatch totalCompileTime = new Stopwatch();
143 int nextFreeClassId = 0; 144 int nextFreeClassId = 0;
144 World world; 145 World world;
145 Types types; 146 Types types;
146 _CompilerCoreTypes _coreTypes; 147 _CompilerCoreTypes _coreTypes;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 /// Generate output even when there are compile-time errors. 269 /// Generate output even when there are compile-time errors.
269 final bool generateCodeWithCompileTimeErrors; 270 final bool generateCodeWithCompileTimeErrors;
270 271
271 /// The compiler is run from the build bot. 272 /// The compiler is run from the build bot.
272 final bool testMode; 273 final bool testMode;
273 274
274 bool disableInlining = false; 275 bool disableInlining = false;
275 276
276 List<Uri> librariesToAnalyzeWhenRun; 277 List<Uri> librariesToAnalyzeWhenRun;
277 278
279 /// The set of platform libraries reported as unsupported.
280 ///
281 /// For instance when importing 'dart:io' without '--categories=Server'.
282 Set<Uri> disallowedLibraryUris = new Setlet<Uri>();
283
278 Tracer tracer; 284 Tracer tracer;
279 285
280 CompilerTask measuredTask; 286 CompilerTask measuredTask;
281 Element _currentElement; 287 Element _currentElement;
282 LibraryElement coreLibrary; 288 LibraryElement coreLibrary;
283 LibraryElement asyncLibrary; 289 LibraryElement asyncLibrary;
284 290
285 LibraryElement mainApp; 291 LibraryElement mainApp;
286 FunctionElement mainFunction; 292 FunctionElement mainFunction;
287 293
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 _coreTypes.streamClass = findRequiredElement(library, 'Stream'); 769 _coreTypes.streamClass = findRequiredElement(library, 'Stream');
764 } else if (uri == Uris.dart__native_typed_data) { 770 } else if (uri == Uris.dart__native_typed_data) {
765 typedDataClass = findRequiredElement(library, 'NativeTypedData'); 771 typedDataClass = findRequiredElement(library, 'NativeTypedData');
766 } else if (uri == js_backend.JavaScriptBackend.DART_JS_HELPER) { 772 } else if (uri == js_backend.JavaScriptBackend.DART_JS_HELPER) {
767 patchAnnotationClass = findRequiredElement(library, '_Patch'); 773 patchAnnotationClass = findRequiredElement(library, '_Patch');
768 nativeAnnotationClass = findRequiredElement(library, 'Native'); 774 nativeAnnotationClass = findRequiredElement(library, 'Native');
769 } 775 }
770 return backend.onLibraryScanned(library, loader); 776 return backend.onLibraryScanned(library, loader);
771 } 777 }
772 778
779 /// Compute the set of distinct import chains loading [uri] with
sigurdm 2015/09/14 12:34:57 /// Compute the set of distinct import chains to t
Johnni Winther 2015/09/14 13:23:39 Done.
780 /// [loadedLibraries].
781 Set<String> computeImportChainsFor(LoadedLibraries loadedLibraries, Uri uri) {
782 // TODO(johnniwinther): Move computation of dependencies to the library
783 // loader.
784 Uri rootUri = loadedLibraries.rootUri;
785 Set<String> importChains = new Set<String>();
786 // The maximum number of full imports chains to process.
787 final int chainLimit = 10000;
788 // The maximum number of imports chains to show.
789 final int compactChainLimit = verbose ? 20 : 10;
790 int chainCount = 0;
791 loadedLibraries.forEachImportChain(uri,
792 callback: (Link<Uri> importChainReversed) {
793 Link<CodeLocation> compactImportChain = const Link<CodeLocation>();
794 CodeLocation currentCodeLocation =
795 new UriLocation(importChainReversed.head);
796 compactImportChain = compactImportChain.prepend(currentCodeLocation);
797 for (Link<Uri> link = importChainReversed.tail;
798 !link.isEmpty;
799 link = link.tail) {
800 Uri uri = link.head;
801 if (!currentCodeLocation.inSameLocation(uri)) {
802 currentCodeLocation =
803 verbose ? new UriLocation(uri) : new CodeLocation(uri);
804 compactImportChain =
805 compactImportChain.prepend(currentCodeLocation);
806 }
807 }
808 String importChain =
809 compactImportChain.map((CodeLocation codeLocation) {
810 return codeLocation.relativize(rootUri);
811 }).join(' => ');
812
813 if (!importChains.contains(importChain)) {
814 if (importChains.length > compactChainLimit) {
815 importChains.add('...');
816 return false;
817 } else {
818 importChains.add(importChain);
819 }
820 }
821
822 chainCount++;
823 if (chainCount > chainLimit) {
824 // Assume there are more import chains.
825 importChains.add('...');
826 return false;
827 }
828 return true;
829 });
830 return importChains;
831 }
832
833 /// Register that [uri] was recognized but disallowed as a dependency.
834 ///
835 /// For instance import of 'dart:io' without '--categories=Server'.
836 void registerDisallowedLibraryUse(Uri uri) {
837 disallowedLibraryUris.add(uri);
838 }
839
773 /// This method is called when all new libraries loaded through 840 /// This method is called when all new libraries loaded through
774 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports 841 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports
775 /// have been computed. 842 /// have been computed.
776 /// 843 ///
777 /// [loadedLibraries] contains the newly loaded libraries. 844 /// [loadedLibraries] contains the newly loaded libraries.
778 /// 845 ///
779 /// The method returns a [Future] allowing for the loading of additional 846 /// The method returns a [Future] allowing for the loading of additional
780 /// libraries. 847 /// libraries.
781 Future onLibrariesLoaded(LoadedLibraries loadedLibraries) { 848 Future onLibrariesLoaded(LoadedLibraries loadedLibraries) {
782 return new Future.sync(() { 849 return new Future.sync(() {
850 for (Uri uri in disallowedLibraryUris) {
851 if (loadedLibraries.containsLibrary(uri)) {
852 Set<String> importChains =
853 computeImportChainsFor(loadedLibraries, Uri.parse('dart:io'));
854 reportInfo(NO_LOCATION_SPANNABLE,
855 MessageKind.DISALLOWED_LIBRARY_IMPORT,
856 {'uri': uri,
857 'importChain': importChains.join(
858 MessageTemplate.DISALLOWED_LIBRARY_IMPORT_PADDING)});
859 }
860 }
861
783 if (!loadedLibraries.containsLibrary(Uris.dart_core)) { 862 if (!loadedLibraries.containsLibrary(Uris.dart_core)) {
784 return null; 863 return null;
785 } 864 }
865
786 if (!enableExperimentalMirrors && 866 if (!enableExperimentalMirrors &&
787 loadedLibraries.containsLibrary(Uris.dart_mirrors)) { 867 loadedLibraries.containsLibrary(Uris.dart_mirrors)) {
788 // TODO(johnniwinther): Move computation of dependencies to the library 868 Set<String> importChains =
789 // loader. 869 computeImportChainsFor(loadedLibraries, Uris.dart_mirrors);
790 Uri rootUri = loadedLibraries.rootUri;
791 Set<String> importChains = new Set<String>();
792 // The maximum number of full imports chains to process.
793 final int chainLimit = 10000;
794 // The maximum number of imports chains to show.
795 final int compactChainLimit = verbose ? 20 : 10;
796 int chainCount = 0;
797 loadedLibraries.forEachImportChain(Uris.dart_mirrors,
798 callback: (Link<Uri> importChainReversed) {
799 Link<CodeLocation> compactImportChain = const Link<CodeLocation>();
800 CodeLocation currentCodeLocation =
801 new UriLocation(importChainReversed.head);
802 compactImportChain = compactImportChain.prepend(currentCodeLocation);
803 for (Link<Uri> link = importChainReversed.tail;
804 !link.isEmpty;
805 link = link.tail) {
806 Uri uri = link.head;
807 if (!currentCodeLocation.inSameLocation(uri)) {
808 currentCodeLocation =
809 verbose ? new UriLocation(uri) : new CodeLocation(uri);
810 compactImportChain =
811 compactImportChain.prepend(currentCodeLocation);
812 }
813 }
814 String importChain =
815 compactImportChain.map((CodeLocation codeLocation) {
816 return codeLocation.relativize(rootUri);
817 }).join(' => ');
818
819 if (!importChains.contains(importChain)) {
820 if (importChains.length > compactChainLimit) {
821 importChains.add('...');
822 return false;
823 } else {
824 importChains.add(importChain);
825 }
826 }
827
828 chainCount++;
829 if (chainCount > chainLimit) {
830 // Assume there are more import chains.
831 importChains.add('...');
832 return false;
833 }
834 return true;
835 });
836
837 if (!backend.supportsReflection) { 870 if (!backend.supportsReflection) {
838 reportError(NO_LOCATION_SPANNABLE, 871 reportError(NO_LOCATION_SPANNABLE,
839 MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_BY_BACKEND); 872 MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_BY_BACKEND);
840 } else { 873 } else {
841 reportWarning(NO_LOCATION_SPANNABLE, 874 reportWarning(NO_LOCATION_SPANNABLE,
842 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS, 875 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS,
843 {'importChain': importChains.join( 876 {'importChain': importChains.join(
844 MessageTemplate.IMPORT_EXPERIMENTAL_MIRRORS_PADDING)}); 877 MessageTemplate.IMPORT_EXPERIMENTAL_MIRRORS_PADDING)});
845 } 878 }
846 } 879 }
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after
1792 1825
1793 @override 1826 @override
1794 InterfaceType streamType([DartType elementType]) { 1827 InterfaceType streamType([DartType elementType]) {
1795 InterfaceType type = streamClass.computeType(compiler); 1828 InterfaceType type = streamClass.computeType(compiler);
1796 if (elementType == null) { 1829 if (elementType == null) {
1797 return streamClass.rawType; 1830 return streamClass.rawType;
1798 } 1831 }
1799 return type.createInstantiation([elementType]); 1832 return type.createInstantiation([elementType]);
1800 } 1833 }
1801 } 1834 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698