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

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

Issue 1930133002: Make parts hermetic, fixes #531 (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 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 | test/worker/worker_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/compiler/compiler.dart
diff --git a/lib/src/compiler/compiler.dart b/lib/src/compiler/compiler.dart
index 969cd6d3418fe877024ea24b64ff2cdede1b7a08..891cedeaf12cebd6a22afd6e6cdffea4691a35ad 100644
--- a/lib/src/compiler/compiler.dart
+++ b/lib/src/compiler/compiler.dart
@@ -2,9 +2,15 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+import 'dart:collection' show HashSet;
import 'package:args/args.dart' show ArgParser, ArgResults;
import 'package:analyzer/analyzer.dart'
- show AnalysisError, CompilationUnit, ErrorSeverity;
+ show
+ AnalysisError,
+ CompilationUnit,
+ CompileTimeErrorCode,
+ ErrorSeverity,
+ StaticWarningCode;
import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
import 'package:analyzer/src/generated/java_engine.dart' show AnalysisException;
import 'package:analyzer/src/generated/source_io.dart' show Source, SourceKind;
@@ -52,6 +58,10 @@ class ModuleCompiler {
var trees = <CompilationUnit>[];
var errors = <AnalysisError>[];
+ // Validate that all parts were explicitly passed in.
+ // If not, it's an error.
+ var explicitParts = new HashSet<Source>();
+ var usedParts = new HashSet<Source>();
for (var sourcePath in unit.sources) {
var sourceUri = Uri.parse(sourcePath);
if (sourceUri.scheme == '') {
@@ -64,7 +74,8 @@ class ModuleCompiler {
}
// Ignore parts. They need to be handled in the context of their library.
- if (context.getKindOf(source) == SourceKind.PART) {
+ if (context.computeKindOf(source) == SourceKind.PART) {
+ explicitParts.add(source);
continue;
}
@@ -74,11 +85,21 @@ class ModuleCompiler {
var library = resolvedTree.element.library;
for (var part in library.parts) {
+ if (!library.isInSdk) usedParts.add(part.source);
trees.add(context.resolveCompilationUnit(part.source, library));
errors.addAll(context.computeErrors(part.source));
}
}
+ // Check if all parts were explicitly passed in.
+ // Also verify all explicitly parts were used.
+ var missingParts = usedParts.difference(explicitParts);
+ var unusedParts = explicitParts.difference(usedParts);
+ errors.addAll(missingParts
+ .map((s) => new AnalysisError(s, 0, 0, missingPartErrorCode)));
+ errors.addAll(unusedParts
+ .map((s) => new AnalysisError(s, 0, 0, unusedPartWarningCode)));
+
sortErrors(context, errors);
var messages = <String>[];
for (var e in errors) {
@@ -269,3 +290,11 @@ class JSModuleFile {
return map;
}
}
+
+/// (Public for tests) the error code used when a part is missing.
+final missingPartErrorCode = const CompileTimeErrorCode(
+ 'MISSING_PART', 'The part was not supplied as an input to the compiler.');
+
+/// (Public for tests) the error code used when a part is unused.
+final unusedPartWarningCode = const StaticWarningCode(
+ 'UNUSED_PART', 'The part was not used by any libraries being compiled.');
« no previous file with comments | « no previous file | test/worker/worker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698