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

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

Issue 2824123003: Make backend.setAnnotations (mostly) handle LibraryEntities. (Closed)
Patch Set: . Created 3 years, 8 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 Future; 7 import 'dart:async' show Future;
8 8
9 import '../compiler_new.dart' as api; 9 import '../compiler_new.dart' as api;
10 import 'closure.dart' as closureMapping show ClosureTask; 10 import 'closure.dart' as closureMapping show ClosureTask;
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 /// 373 ///
374 /// [loadedLibraries] contains the newly loaded libraries. 374 /// [loadedLibraries] contains the newly loaded libraries.
375 /// 375 ///
376 /// The method returns a [Future] allowing for the loading of additional 376 /// The method returns a [Future] allowing for the loading of additional
377 /// libraries. 377 /// libraries.
378 LoadedLibraries processLoadedLibraries(LoadedLibraries loadedLibraries) { 378 LoadedLibraries processLoadedLibraries(LoadedLibraries loadedLibraries) {
379 loadedLibraries.forEachLibrary((LibraryEntity library) { 379 loadedLibraries.forEachLibrary((LibraryEntity library) {
380 backend.setAnnotations(library); 380 backend.setAnnotations(library);
381 }); 381 });
382 382
383 for (Uri uri in resolvedUriTranslator.disallowedLibraryUris) { 383 // TODO(efortuna, sigmund): These validation steps should be done in the
384 if (loadedLibraries.containsLibrary(uri)) { 384 // front end for the Kernel path since Kernel doesn't have the notion of
385 Set<String> importChains = computeImportChainsFor(loadedLibraries, uri); 385 // imports (everything has already been resolved). (See
386 reporter.reportInfo( 386 // https://github.com/dart-lang/sdk/issues/29368)
387 NO_LOCATION_SPANNABLE, MessageKind.DISALLOWED_LIBRARY_IMPORT, { 387 if (loadedLibraries.rootLibrary is LibraryElement) {
Siggi Cherem (dart-lang) 2017/04/19 15:36:29 nit: I prefer to make this check as if (!option
Emily Fortuna 2017/04/19 22:35:45 Done.
388 'uri': uri, 388 for (Uri uri in resolvedUriTranslator.disallowedLibraryUris) {
389 'importChain': importChains 389 if (loadedLibraries.containsLibrary(uri)) {
390 .join(MessageTemplate.DISALLOWED_LIBRARY_IMPORT_PADDING) 390 Set<String> importChains =
391 }); 391 computeImportChainsFor(loadedLibraries, uri);
392 reporter.reportInfo(
393 NO_LOCATION_SPANNABLE, MessageKind.DISALLOWED_LIBRARY_IMPORT, {
394 'uri': uri,
395 'importChain': importChains
396 .join(MessageTemplate.DISALLOWED_LIBRARY_IMPORT_PADDING)
397 });
398 }
392 } 399 }
393 }
394 400
395 if (loadedLibraries.containsLibrary(Uris.dart_core)) { 401 if (loadedLibraries.containsLibrary(Uris.dart_core)) {
396 bool importsMirrorsLibrary = 402 bool importsMirrorsLibrary =
397 loadedLibraries.containsLibrary(Uris.dart_mirrors); 403 loadedLibraries.containsLibrary(Uris.dart_mirrors);
398 if (importsMirrorsLibrary && !backend.supportsReflection) { 404 if (importsMirrorsLibrary && !backend.supportsReflection) {
399 Set<String> importChains = 405 Set<String> importChains =
400 computeImportChainsFor(loadedLibraries, Uris.dart_mirrors); 406 computeImportChainsFor(loadedLibraries, Uris.dart_mirrors);
401 reporter.reportErrorMessage(NO_LOCATION_SPANNABLE, 407 reporter.reportErrorMessage(NO_LOCATION_SPANNABLE,
402 MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_BY_BACKEND, { 408 MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_BY_BACKEND, {
403 'importChain': importChains 409 'importChain': importChains
404 .join(MessageTemplate.MIRRORS_NOT_SUPPORTED_BY_BACKEND_PADDING) 410 .join(MessageTemplate.MIRRORS_NOT_SUPPORTED_BY_BACKEND_PADDING)
405 }); 411 });
406 } else if (importsMirrorsLibrary && !options.enableExperimentalMirrors) { 412 } else if (importsMirrorsLibrary &&
407 Set<String> importChains = 413 !options.enableExperimentalMirrors) {
408 computeImportChainsFor(loadedLibraries, Uris.dart_mirrors); 414 Set<String> importChains =
409 reporter.reportWarningMessage( 415 computeImportChainsFor(loadedLibraries, Uris.dart_mirrors);
410 NO_LOCATION_SPANNABLE, MessageKind.IMPORT_EXPERIMENTAL_MIRRORS, { 416 reporter.reportWarningMessage(
411 'importChain': importChains 417 NO_LOCATION_SPANNABLE, MessageKind.IMPORT_EXPERIMENTAL_MIRRORS, {
412 .join(MessageTemplate.IMPORT_EXPERIMENTAL_MIRRORS_PADDING) 418 'importChain': importChains
413 }); 419 .join(MessageTemplate.IMPORT_EXPERIMENTAL_MIRRORS_PADDING)
420 });
421 }
414 } 422 }
415 } 423 }
416 backend.onLibrariesLoaded(loadedLibraries); 424 backend.onLibrariesLoaded(loadedLibraries);
417 return loadedLibraries; 425 return loadedLibraries;
418 } 426 }
419 427
420 // TODO(johnniwinther): Move this to [PatchParser] when it is moved to the 428 // TODO(johnniwinther): Move this to [PatchParser] when it is moved to the
421 // [JavaScriptBackend]. Currently needed for testing. 429 // [JavaScriptBackend]. Currently needed for testing.
422 String get patchVersion => backend.patchVersion; 430 String get patchVersion => backend.patchVersion;
423 431
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 supportDeferredLoad: deferredLoadTask.isProgramSplit, 596 supportDeferredLoad: deferredLoadTask.isProgramSplit,
589 supportDumpInfo: options.dumpInfo, 597 supportDumpInfo: options.dumpInfo,
590 supportSerialization: serialization.supportSerialization); 598 supportSerialization: serialization.supportSerialization);
591 599
592 phase = PHASE_RESOLVING; 600 phase = PHASE_RESOLVING;
593 resolutionEnqueuer.applyImpact(mainImpact); 601 resolutionEnqueuer.applyImpact(mainImpact);
594 if (options.resolveOnly) { 602 if (options.resolveOnly) {
595 libraryLoader.libraries.where((LibraryEntity library) { 603 libraryLoader.libraries.where((LibraryEntity library) {
596 return !serialization.isDeserialized(library); 604 return !serialization.isDeserialized(library);
597 }).forEach((LibraryEntity library) { 605 }).forEach((LibraryEntity library) {
598 reporter 606 reporter.log('Enqueuing ${library.canonicalUri}');
599 .log('Enqueuing ${(library as LibraryElement).canonicalUri}');
Siggi Cherem (dart-lang) 2017/04/19 15:36:29 thx!
600 resolutionEnqueuer.applyImpact(computeImpactForLibrary(library)); 607 resolutionEnqueuer.applyImpact(computeImpactForLibrary(library));
601 }); 608 });
602 } else if (analyzeAll) { 609 } else if (analyzeAll) {
603 libraryLoader.libraries.forEach((LibraryEntity library) { 610 libraryLoader.libraries.forEach((LibraryEntity library) {
604 reporter 611 reporter.log('Enqueuing ${library.canonicalUri}');
605 .log('Enqueuing ${(library as LibraryElement).canonicalUri}');
606 resolutionEnqueuer.applyImpact(computeImpactForLibrary(library)); 612 resolutionEnqueuer.applyImpact(computeImpactForLibrary(library));
607 }); 613 });
608 } else if (options.analyzeMain) { 614 } else if (options.analyzeMain) {
609 if (mainApp != null) { 615 if (mainApp != null) {
610 resolutionEnqueuer.applyImpact(computeImpactForLibrary(mainApp)); 616 resolutionEnqueuer.applyImpact(computeImpactForLibrary(mainApp));
611 } 617 }
612 if (librariesToAnalyzeWhenRun != null) { 618 if (librariesToAnalyzeWhenRun != null) {
613 for (Uri libraryUri in librariesToAnalyzeWhenRun) { 619 for (Uri libraryUri in librariesToAnalyzeWhenRun) {
614 resolutionEnqueuer.applyImpact(computeImpactForLibrary( 620 resolutionEnqueuer.applyImpact(computeImpactForLibrary(
615 libraryLoader.lookupLibrary(libraryUri))); 621 libraryLoader.lookupLibrary(libraryUri)));
(...skipping 24 matching lines...) Expand all
640 646
641 if (options.resolveOnly && !compilationFailed) { 647 if (options.resolveOnly && !compilationFailed) {
642 reporter.log('Serializing to ${options.resolutionOutput}'); 648 reporter.log('Serializing to ${options.resolutionOutput}');
643 serialization.serializeToSink( 649 serialization.serializeToSink(
644 userOutputProvider.createOutputSink( 650 userOutputProvider.createOutputSink(
645 '', 'data', api.OutputType.serializationData), 651 '', 'data', api.OutputType.serializationData),
646 libraryLoader.libraries.where((LibraryEntity library) { 652 libraryLoader.libraries.where((LibraryEntity library) {
647 return !serialization.isDeserialized(library); 653 return !serialization.isDeserialized(library);
648 })); 654 }));
649 } 655 }
650 if (options.analyzeOnly) { 656 if (options.analyzeOnly) {
Siggi Cherem (dart-lang) 2017/04/19 15:36:29 nit - we can now remove the braces and make this a
Emily Fortuna 2017/04/19 22:35:45 Done.
651 if (!analyzeAll && !compilationFailed) {
652 // No point in reporting unused code when [analyzeAll] is true: all
653 // code is artificially used.
654 // If compilation failed, it is possible that the error prevents the
655 // compiler from analyzing all the code.
656 // TODO(johnniwinther): Reenable this when the reporting is more
657 // precise.
658 //reportUnusedCode();
659 }
660 return; 657 return;
661 } 658 }
662 assert(mainFunction != null); 659 assert(mainFunction != null);
663 660
664 ClosedWorldRefiner closedWorldRefiner = closeResolution(); 661 ClosedWorldRefiner closedWorldRefiner = closeResolution();
665 ClosedWorld closedWorld = closedWorldRefiner.closedWorld; 662 ClosedWorld closedWorld = closedWorldRefiner.closedWorld;
666 663
667 reporter.log('Inferring types...'); 664 reporter.log('Inferring types...');
668 globalInference.runGlobalTypeInference( 665 globalInference.runGlobalTypeInference(
669 mainFunction, closedWorld, closedWorldRefiner); 666 mainFunction, closedWorld, closedWorldRefiner);
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 Element lookupElementIn(ScopeContainerElement container, String name) { 920 Element lookupElementIn(ScopeContainerElement container, String name) {
924 Element element = container.localLookup(name); 921 Element element = container.localLookup(name);
925 if (element == null) { 922 if (element == null) {
926 throw 'Could not find $name in $container'; 923 throw 'Could not find $name in $container';
927 } 924 }
928 return element; 925 return element;
929 } 926 }
930 927
931 bool get isMockCompilation => false; 928 bool get isMockCompilation => false;
932 929
933 void reportUnusedCode() {
934 void checkLive(member) {
935 if (member.isMalformed) return;
936 if (member.isFunction) {
937 if (!resolutionWorldBuilder.isMemberUsed(member)) {
938 reporter.reportHintMessage(
939 member, MessageKind.UNUSED_METHOD, {'name': member.name});
940 }
941 } else if (member.isClass) {
942 if (!member.isResolved) {
943 reporter.reportHintMessage(
944 member, MessageKind.UNUSED_CLASS, {'name': member.name});
945 } else {
946 member.forEachLocalMember(checkLive);
947 }
948 } else if (member.isTypedef) {
949 if (!member.isResolved) {
950 reporter.reportHintMessage(
951 member, MessageKind.UNUSED_TYPEDEF, {'name': member.name});
952 }
953 }
954 }
955
956 libraryLoader.libraries.forEach((LibraryEntity entity) {
957 // TODO(ahe): Implement better heuristics to discover entry points of
958 // packages and use that to discover unused implementation details in
959 // packages.
960 LibraryElement library = entity;
961 if (library.isPlatformLibrary || library.isPackageLibrary) return;
962 library.compilationUnits.forEach((unit) {
963 unit.forEachLocalMember(checkLive);
964 });
965 });
966 }
967
968 /// Helper for determining whether the current element is declared within 930 /// Helper for determining whether the current element is declared within
969 /// 'user code'. 931 /// 'user code'.
970 /// 932 ///
971 /// See [inUserCode] for what defines 'user code'. 933 /// See [inUserCode] for what defines 'user code'.
972 bool currentlyInUserCode() { 934 bool currentlyInUserCode() {
973 return inUserCode(currentElement); 935 return inUserCode(currentElement);
974 } 936 }
975 937
976 /// Helper for determining whether [element] is declared within 'user code'. 938 /// Helper for determining whether [element] is declared within 'user code'.
977 /// 939 ///
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after
1998 ResolutionFunctionType getLocalFunctionType(LocalFunctionElement function) { 1960 ResolutionFunctionType getLocalFunctionType(LocalFunctionElement function) {
1999 return function.type; 1961 return function.type;
2000 } 1962 }
2001 1963
2002 @override 1964 @override
2003 ResolutionDartType getUnaliasedType(ResolutionDartType type) { 1965 ResolutionDartType getUnaliasedType(ResolutionDartType type) {
2004 type.computeUnaliased(_resolution); 1966 type.computeUnaliased(_resolution);
2005 return type.unaliased; 1967 return type.unaliased;
2006 } 1968 }
2007 } 1969 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/backend.dart » ('j') | pkg/compiler/lib/src/kernel/world_builder.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698