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

Unified Diff: pkg/compiler/lib/src/compiler.dart

Issue 2824123003: Make backend.setAnnotations (mostly) handle LibraryEntities. (Closed)
Patch Set: comments 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/backend.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/compiler.dart
diff --git a/pkg/compiler/lib/src/compiler.dart b/pkg/compiler/lib/src/compiler.dart
index 65620fda8e12fd01ac36f67a8728c26b339a147f..67c4e599583b097f982e000f18d9dcc0501bb249 100644
--- a/pkg/compiler/lib/src/compiler.dart
+++ b/pkg/compiler/lib/src/compiler.dart
@@ -380,37 +380,45 @@ abstract class Compiler {
backend.setAnnotations(library);
});
- for (Uri uri in resolvedUriTranslator.disallowedLibraryUris) {
- if (loadedLibraries.containsLibrary(uri)) {
- Set<String> importChains = computeImportChainsFor(loadedLibraries, uri);
- reporter.reportInfo(
- NO_LOCATION_SPANNABLE, MessageKind.DISALLOWED_LIBRARY_IMPORT, {
- 'uri': uri,
- 'importChain': importChains
- .join(MessageTemplate.DISALLOWED_LIBRARY_IMPORT_PADDING)
- });
+ // TODO(efortuna, sigmund): These validation steps should be done in the
+ // front end for the Kernel path since Kernel doesn't have the notion of
+ // imports (everything has already been resolved). (See
+ // https://github.com/dart-lang/sdk/issues/29368)
+ if (!options.useKernel && !options.loadFromDill) {
+ for (Uri uri in resolvedUriTranslator.disallowedLibraryUris) {
+ if (loadedLibraries.containsLibrary(uri)) {
+ Set<String> importChains =
+ computeImportChainsFor(loadedLibraries, uri);
+ reporter.reportInfo(
+ NO_LOCATION_SPANNABLE, MessageKind.DISALLOWED_LIBRARY_IMPORT, {
+ 'uri': uri,
+ 'importChain': importChains
+ .join(MessageTemplate.DISALLOWED_LIBRARY_IMPORT_PADDING)
+ });
+ }
}
- }
- if (loadedLibraries.containsLibrary(Uris.dart_core)) {
- bool importsMirrorsLibrary =
- loadedLibraries.containsLibrary(Uris.dart_mirrors);
- if (importsMirrorsLibrary && !backend.supportsReflection) {
- Set<String> importChains =
- computeImportChainsFor(loadedLibraries, Uris.dart_mirrors);
- reporter.reportErrorMessage(NO_LOCATION_SPANNABLE,
- MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_BY_BACKEND, {
- 'importChain': importChains
- .join(MessageTemplate.MIRRORS_NOT_SUPPORTED_BY_BACKEND_PADDING)
- });
- } else if (importsMirrorsLibrary && !options.enableExperimentalMirrors) {
- Set<String> importChains =
- computeImportChainsFor(loadedLibraries, Uris.dart_mirrors);
- reporter.reportWarningMessage(
- NO_LOCATION_SPANNABLE, MessageKind.IMPORT_EXPERIMENTAL_MIRRORS, {
- 'importChain': importChains
- .join(MessageTemplate.IMPORT_EXPERIMENTAL_MIRRORS_PADDING)
- });
+ if (loadedLibraries.containsLibrary(Uris.dart_core)) {
+ bool importsMirrorsLibrary =
+ loadedLibraries.containsLibrary(Uris.dart_mirrors);
+ if (importsMirrorsLibrary && !backend.supportsReflection) {
+ Set<String> importChains =
+ computeImportChainsFor(loadedLibraries, Uris.dart_mirrors);
+ reporter.reportErrorMessage(NO_LOCATION_SPANNABLE,
+ MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_BY_BACKEND, {
+ 'importChain': importChains
+ .join(MessageTemplate.MIRRORS_NOT_SUPPORTED_BY_BACKEND_PADDING)
+ });
+ } else if (importsMirrorsLibrary &&
+ !options.enableExperimentalMirrors) {
+ Set<String> importChains =
+ computeImportChainsFor(loadedLibraries, Uris.dart_mirrors);
+ reporter.reportWarningMessage(
+ NO_LOCATION_SPANNABLE, MessageKind.IMPORT_EXPERIMENTAL_MIRRORS, {
+ 'importChain': importChains
+ .join(MessageTemplate.IMPORT_EXPERIMENTAL_MIRRORS_PADDING)
+ });
+ }
}
}
backend.onLibrariesLoaded(loadedLibraries);
@@ -595,14 +603,12 @@ abstract class Compiler {
libraryLoader.libraries.where((LibraryEntity library) {
return !serialization.isDeserialized(library);
}).forEach((LibraryEntity library) {
- reporter
- .log('Enqueuing ${(library as LibraryElement).canonicalUri}');
+ reporter.log('Enqueuing ${library.canonicalUri}');
resolutionEnqueuer.applyImpact(computeImpactForLibrary(library));
});
} else if (analyzeAll) {
libraryLoader.libraries.forEach((LibraryEntity library) {
- reporter
- .log('Enqueuing ${(library as LibraryElement).canonicalUri}');
+ reporter.log('Enqueuing ${library.canonicalUri}');
resolutionEnqueuer.applyImpact(computeImpactForLibrary(library));
});
} else if (options.analyzeMain) {
@@ -647,18 +653,7 @@ abstract class Compiler {
return !serialization.isDeserialized(library);
}));
}
- if (options.analyzeOnly) {
- if (!analyzeAll && !compilationFailed) {
- // No point in reporting unused code when [analyzeAll] is true: all
- // code is artificially used.
- // If compilation failed, it is possible that the error prevents the
- // compiler from analyzing all the code.
- // TODO(johnniwinther): Reenable this when the reporting is more
- // precise.
- //reportUnusedCode();
- }
- return;
- }
+ if (options.analyzeOnly) return;
assert(mainFunction != null);
ClosedWorldRefiner closedWorldRefiner = closeResolution();
@@ -930,41 +925,6 @@ abstract class Compiler {
bool get isMockCompilation => false;
- void reportUnusedCode() {
- void checkLive(member) {
- if (member.isMalformed) return;
- if (member.isFunction) {
- if (!resolutionWorldBuilder.isMemberUsed(member)) {
- reporter.reportHintMessage(
- member, MessageKind.UNUSED_METHOD, {'name': member.name});
- }
- } else if (member.isClass) {
- if (!member.isResolved) {
- reporter.reportHintMessage(
- member, MessageKind.UNUSED_CLASS, {'name': member.name});
- } else {
- member.forEachLocalMember(checkLive);
- }
- } else if (member.isTypedef) {
- if (!member.isResolved) {
- reporter.reportHintMessage(
- member, MessageKind.UNUSED_TYPEDEF, {'name': member.name});
- }
- }
- }
-
- libraryLoader.libraries.forEach((LibraryEntity entity) {
- // TODO(ahe): Implement better heuristics to discover entry points of
- // packages and use that to discover unused implementation details in
- // packages.
- LibraryElement library = entity;
- if (library.isPlatformLibrary || library.isPackageLibrary) return;
- library.compilationUnits.forEach((unit) {
- unit.forEachLocalMember(checkLive);
- });
- });
- }
-
/// Helper for determining whether the current element is declared within
/// 'user code'.
///
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/backend.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698