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

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

Issue 1803303002: Move all flags to CompilerOptions (first step to stop passing the compiler to (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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
Index: pkg/compiler/lib/src/compiler.dart
diff --git a/pkg/compiler/lib/src/compiler.dart b/pkg/compiler/lib/src/compiler.dart
index 9bfb7ebe917bbc29dac6a02814db96783e84a2f4..0f82fc349b650e63dd6a172ac06e4f2b04ac5eef 100644
--- a/pkg/compiler/lib/src/compiler.dart
+++ b/pkg/compiler/lib/src/compiler.dart
@@ -184,42 +184,8 @@ abstract class Compiler {
final Registry mirrorDependencies =
new ResolutionRegistry(null, new TreeElementMapping(null));
- final bool enableMinification;
-
- final bool useFrequencyNamer;
-
- /// When `true` emits URIs in the reflection metadata.
- final bool preserveUris;
-
- final bool enableTypeAssertions;
- final bool enableUserAssertions;
- final bool trustTypeAnnotations;
- final bool trustPrimitives;
- final bool trustJSInteropTypeAnnotations;
- final bool disableTypeInferenceFlag;
- final Uri deferredMapUri;
- final bool dumpInfo;
- final bool useContentSecurityPolicy;
- final bool enableExperimentalMirrors;
- final bool enableAssertMessage;
-
- /**
- * The maximum size of a concrete type before it widens to dynamic during
- * concrete type inference.
- */
- final int maxConcreteTypeSize;
- final bool analyzeAllFlag;
- final bool analyzeOnly;
-
- /// If true, disable tree-shaking for the main script.
- final bool analyzeMain;
-
- /**
- * If true, skip analysis of method bodies and field initializers. Implies
- * [analyzeOnly].
- */
- final bool analyzeSignaturesOnly;
- final bool enableNativeLiveTypeAnalysis;
+ /// Options provided from command-line arguments.
+ final api.CompilerOptions options;
/**
* If true, stop compilation after type inference is complete. Used for
@@ -227,49 +193,9 @@ abstract class Compiler {
*/
bool stopAfterTypeInference = false;
- /**
- * If [:true:], comment tokens are collected in [commentMap] during scanning.
- */
- final bool preserveComments;
-
- /// Use the new CPS based backend end. This flag works for both the Dart and
- /// JavaScript backend.
- final bool useCpsIr;
-
- /**
- * Is the compiler in verbose mode.
- */
- final bool verbose;
-
- /**
- * URI of the main source map if the compiler is generating source
- * maps.
- */
- final Uri sourceMapUri;
-
- /**
- * URI of the main output if the compiler is generating source maps.
- */
- final Uri outputUri;
-
- /// If `true`, some values are cached for reuse in incremental compilation.
- /// Incremental compilation is basically calling [run] more than once.
- final bool hasIncrementalSupport;
-
- /// If `true` native extension syntax is supported by the frontend.
- final bool allowNativeExtensions;
-
/// Output provider from user of Compiler API.
api.CompilerOutput userOutputProvider;
- /// Generate output even when there are compile-time errors.
- final bool generateCodeWithCompileTimeErrors;
-
- /// The compiler is run from the build bot.
- final bool testMode;
-
- bool disableInlining = false;
-
List<Uri> librariesToAnalyzeWhenRun;
/// The set of platform libraries reported as unsupported.
@@ -380,7 +306,6 @@ abstract class Compiler {
DeferredLoadTask deferredLoadTask;
MirrorUsageAnalyzerTask mirrorUsageAnalyzerTask;
DumpInfoTask dumpInfoTask;
- String buildId;
/// A customizable filter that is applied to enqueued work items.
QueueFilter enqueuerFilter = new QueueFilter();
@@ -391,9 +316,6 @@ abstract class Compiler {
static const String CREATE_INVOCATION_MIRROR =
'createInvocationMirror';
- static const String UNDETERMINED_BUILD_ID =
- "build number could not be determined";
-
bool enabledRuntimeType = false;
bool enabledFunctionApply = false;
bool enabledInvokeOn = false;
@@ -404,7 +326,7 @@ abstract class Compiler {
Stopwatch progress;
bool get shouldPrintProgress {
- return verbose && progress.elapsedMilliseconds > 500;
+ return options.verbose && progress.elapsedMilliseconds > 500;
}
static const int PHASE_SCANNING = 0;
@@ -424,74 +346,25 @@ abstract class Compiler {
compilationFailedInternal = value;
}
- /// Set by the backend if real reflection is detected in use of dart:mirrors.
- bool disableTypeInferenceForMirrors = false;
-
- Compiler({this.enableTypeAssertions: false,
- this.enableUserAssertions: false,
- this.trustTypeAnnotations: false,
- this.trustPrimitives: false,
- this.trustJSInteropTypeAnnotations: false,
- bool disableTypeInferenceFlag: false,
- this.maxConcreteTypeSize: 5,
- this.enableMinification: false,
- this.preserveUris: false,
- this.enableNativeLiveTypeAnalysis: false,
- bool emitJavaScript: true,
- bool dart2dartMultiFile: false,
- bool generateSourceMap: true,
- bool analyzeAllFlag: false,
- bool analyzeOnly: false,
- this.analyzeMain: false,
- bool analyzeSignaturesOnly: false,
- this.preserveComments: false,
- this.useCpsIr: false,
- this.useFrequencyNamer: false,
- this.verbose: false,
- this.sourceMapUri: null,
- this.outputUri: null,
- this.buildId: UNDETERMINED_BUILD_ID,
- this.deferredMapUri: null,
- this.dumpInfo: false,
- bool useStartupEmitter: false,
- bool enableConditionalDirectives: false,
- bool useNewSourceInfo: false,
- this.useContentSecurityPolicy: false,
- bool hasIncrementalSupport: false,
- this.enableExperimentalMirrors: false,
- this.enableAssertMessage: false,
- this.allowNativeExtensions: false,
- this.generateCodeWithCompileTimeErrors: false,
- this.testMode: false,
- DiagnosticOptions diagnosticOptions,
- api.CompilerOutput outputProvider,
- List<String> strips: const []})
- : this.disableTypeInferenceFlag =
- disableTypeInferenceFlag || !emitJavaScript,
- this.analyzeOnly =
- analyzeOnly || analyzeSignaturesOnly || analyzeAllFlag,
- this.analyzeSignaturesOnly = analyzeSignaturesOnly,
- this.analyzeAllFlag = analyzeAllFlag,
- this.hasIncrementalSupport = hasIncrementalSupport,
- cacheStrategy = new CacheStrategy(hasIncrementalSupport),
+ Compiler({api.CompilerOptions options,
+ api.CompilerOutput outputProvider})
+ : this.options = options,
+ this.cacheStrategy = new CacheStrategy(options.hasIncrementalSupport),
this.userOutputProvider = outputProvider == null
? const NullCompilerOutput() : outputProvider {
- if (hasIncrementalSupport) {
- // TODO(ahe): This is too much. Any method from platform and package
- // libraries can be inlined.
- disableInlining = true;
- }
+
world = new World(this);
// TODO(johnniwinther): Initialize core types in [initializeCoreClasses] and
// make its field final.
- _reporter = new _CompilerDiagnosticReporter(this, diagnosticOptions);
+ _reporter = new _CompilerDiagnosticReporter(
+ this, options.diagnosticOptions);
_parsing = new _CompilerParsing(this);
_resolution = new _CompilerResolution(this);
_coreTypes = new _CompilerCoreTypes(_resolution);
types = new Types(_resolution);
tracer = new Tracer(this, this.outputProvider);
- if (verbose) {
+ if (options.verbose) {
progress = new Stopwatch()..start();
}
@@ -499,17 +372,17 @@ abstract class Compiler {
// for global dependencies.
globalDependencies = new GlobalDependencyRegistry(this);
- if (emitJavaScript) {
+ if (options.emitJavaScript) {
js_backend.JavaScriptBackend jsBackend =
new js_backend.JavaScriptBackend(
- this, generateSourceMap: generateSourceMap,
- useStartupEmitter: useStartupEmitter,
- useNewSourceInfo: useNewSourceInfo);
+ this, generateSourceMap: options.generateSourceMap,
+ useStartupEmitter: options.useStartupEmitter,
+ useNewSourceInfo: options.useNewSourceInfo);
backend = jsBackend;
} else {
- backend = new dart_backend.DartBackend(this, strips,
- multiFile: dart2dartMultiFile);
- if (dumpInfo) {
+ backend = new dart_backend.DartBackend(this, options.strips,
+ multiFile: options.dart2dartMultiFile);
+ if (options.dumpInfo) {
throw new ArgumentError('--dump-info is not supported for dart2dart.');
}
}
@@ -519,11 +392,11 @@ abstract class Compiler {
serialization = new SerializationTask(this),
scanner = new ScannerTask(this),
dietParser = new DietParserTask(
- this, enableConditionalDirectives: enableConditionalDirectives),
+ this, enableConditionalDirectives: options.enableConditionalDirectives),
parser = new ParserTask(
- this, enableConditionalDirectives: enableConditionalDirectives),
+ this, enableConditionalDirectives: options.enableConditionalDirectives),
patchParser = new PatchParserTask(
- this, enableConditionalDirectives: enableConditionalDirectives),
+ this, enableConditionalDirectives: options.enableConditionalDirectives),
resolver = new ResolverTask(this, backend.constantCompilerTask),
closureToClassMapper = new closureMapping.ClosureTask(this),
checker = new TypeCheckerTask(this),
@@ -542,15 +415,12 @@ abstract class Compiler {
Universe get resolverWorld => enqueuer.resolution.universe;
Universe get codegenWorld => enqueuer.codegen.universe;
- bool get hasBuildId => buildId != UNDETERMINED_BUILD_ID;
-
- bool get analyzeAll => analyzeAllFlag || compileAll;
+ bool get analyzeAll => options.analyzeAll || compileAll;
bool get compileAll => false;
- bool get disableTypeInference {
- return disableTypeInferenceFlag || compilationFailed;
- }
+ bool get disableTypeInference =>
+ options.disableTypeInference || compilationFailed;
int getNextFreeClassId() => nextFreeClassId++;
@@ -641,7 +511,7 @@ abstract class Compiler {
// The maximum number of full imports chains to process.
final int chainLimit = 10000;
// The maximum number of imports chains to show.
- final int compactChainLimit = verbose ? 20 : 10;
+ final int compactChainLimit = options.verbose ? 20 : 10;
int chainCount = 0;
loadedLibraries.forEachImportChain(uri,
callback: (Link<Uri> importChainReversed) {
@@ -655,7 +525,7 @@ abstract class Compiler {
Uri uri = link.head;
if (!currentCodeLocation.inSameLocation(uri)) {
currentCodeLocation =
- verbose ? new UriLocation(uri) : new CodeLocation(uri);
+ options.verbose ? new UriLocation(uri) : new CodeLocation(uri);
compactImportChain =
compactImportChain.prepend(currentCodeLocation);
}
@@ -728,7 +598,7 @@ abstract class Compiler {
MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_BY_BACKEND,
{'importChain': importChains.join(
MessageTemplate.MIRRORS_NOT_SUPPORTED_BY_BACKEND_PADDING)});
- } else if (importsMirrorsLibrary && !enableExperimentalMirrors) {
+ } else if (importsMirrorsLibrary && !options.enableExperimentalMirrors) {
Set<String> importChains =
computeImportChainsFor(loadedLibraries, Uris.dart_mirrors);
reporter.reportWarningMessage(
@@ -742,7 +612,7 @@ abstract class Compiler {
functionApplyMethod =
coreClasses.functionClass.lookupLocalMember('apply');
- if (preserveComments) {
+ if (options.preserveComments) {
return libraryLoader.loadLibrary(Uris.dart_mirrors)
.then((LibraryElement libraryElement) {
documentClass = libraryElement.find('Comment');
@@ -863,20 +733,20 @@ abstract class Compiler {
.add(selector);
}
- assert(uri != null || analyzeOnly || hasIncrementalSupport);
+ assert(uri != null || options.analyzeOnly || options.hasIncrementalSupport);
return new Future.sync(() {
if (librariesToAnalyzeWhenRun != null) {
return Future.forEach(librariesToAnalyzeWhenRun, (libraryUri) {
- reporter.log('Analyzing $libraryUri ($buildId)');
+ reporter.log('Analyzing $libraryUri (${options.buildId})');
return libraryLoader.loadLibrary(libraryUri);
});
}
}).then((_) {
if (uri != null) {
- if (analyzeOnly) {
- reporter.log('Analyzing $uri ($buildId)');
+ if (options.analyzeOnly) {
+ reporter.log('Analyzing $uri (${options.buildId})');
} else {
- reporter.log('Compiling $uri ($buildId)');
+ reporter.log('Compiling $uri (${options.buildId})');
}
return libraryLoader.loadLibrary(uri).then((LibraryElement library) {
mainApp = library;
@@ -893,7 +763,7 @@ abstract class Compiler {
Element main = mainApp.findExported(Identifiers.main);
ErroneousElement errorElement = null;
if (main == null) {
- if (analyzeOnly) {
+ if (options.analyzeOnly) {
if (!analyzeAll) {
errorElement = new ErroneousElementX(
MessageKind.CONSIDER_ANALYZE_ALL, {'main': Identifiers.main},
@@ -937,7 +807,7 @@ abstract class Compiler {
}
}
if (mainFunction == null) {
- if (errorElement == null && !analyzeOnly && !analyzeAll) {
+ if (errorElement == null && !options.analyzeOnly && !analyzeAll) {
reporter.internalError(mainApp, "Problem with '${Identifiers.main}'.");
} else {
mainFunction = errorElement;
@@ -962,8 +832,8 @@ abstract class Compiler {
Future<LibraryElement> analyzeUri(
Uri libraryUri,
{bool skipLibraryWithPartOfTag: true}) {
- assert(analyzeMain);
- reporter.log('Analyzing $libraryUri ($buildId)');
+ assert(options.analyzeMain);
+ reporter.log('Analyzing $libraryUri (${options.buildId})');
return libraryLoader.loadLibrary(
libraryUri, skipFileWithPartOfTag: true).then(
(LibraryElement library) {
@@ -988,7 +858,7 @@ abstract class Compiler {
deferredLoadTask.beforeResolution(this);
impactStrategy = backend.createImpactStrategy(
supportDeferredLoad: deferredLoadTask.isProgramSplit,
- supportDumpInfo: dumpInfo);
+ supportDumpInfo: options.dumpInfo);
phase = PHASE_RESOLVING;
if (analyzeAll) {
@@ -996,7 +866,7 @@ abstract class Compiler {
reporter.log('Enqueuing ${library.canonicalUri}');
fullyEnqueueLibrary(library, enqueuer.resolution);
});
- } else if (analyzeMain) {
+ } else if (options.analyzeMain) {
if (mainApp != null) {
fullyEnqueueLibrary(mainApp, enqueuer.resolution);
}
@@ -1018,13 +888,13 @@ abstract class Compiler {
_reporter.reportSuppressedMessagesSummary();
if (compilationFailed){
- if (!generateCodeWithCompileTimeErrors) return;
+ if (!options.generateCodeWithCompileTimeErrors) return;
if (!backend.enableCodegenWithErrorsIfSupported(NO_LOCATION_SPANNABLE)) {
return;
}
}
- if (analyzeOnly) {
+ if (options.analyzeOnly) {
if (!analyzeAll && !compilationFailed) {
// No point in reporting unused code when [analyzeAll] is true: all
// code is artificially used.
@@ -1070,7 +940,7 @@ abstract class Compiler {
int programSize = backend.assembleProgram();
- if (dumpInfo) {
+ if (options.dumpInfo) {
dumpInfoTask.reportSize(programSize);
dumpInfoTask.dumpInfo();
}
@@ -1141,7 +1011,7 @@ abstract class Compiler {
}
world.addToWorkList(main);
}
- if (verbose) {
+ if (options.verbose) {
progress.reset();
}
emptyQueue(world);
@@ -1261,7 +1131,7 @@ abstract class Compiler {
];
bool markCompilationAsFailed(DiagnosticMessage message, api.Diagnostic kind) {
- if (testMode) {
+ if (options.testMode) {
// When in test mode, i.e. on the build-bot, we always stop compilation.
return true;
}
@@ -1470,7 +1340,7 @@ abstract class Compiler {
EventSink<String> outputProvider(String name, String extension) {
if (compilationFailed) {
- if (!generateCodeWithCompileTimeErrors || testMode) {
+ if (!options.generateCodeWithCompileTimeErrors || options.testMode) {
// Disable output in test mode: The build bot currently uses the time
// stamp of the generated file to determine whether the output is
// up-to-date.
@@ -1978,7 +1848,7 @@ class _CompilerDiagnosticReporter extends DiagnosticReporter {
void pleaseReportCrash() {
print(
MessageTemplate.TEMPLATES[MessageKind.PLEASE_REPORT_THE_CRASH]
- .message({'buildId': compiler.buildId}));
+ .message({'buildId': compiler.options.buildId}));
}
/// Finds the approximate [Element] for [node]. [currentElement] is used as
@@ -2126,7 +1996,7 @@ class _CompilerResolution implements Resolution {
assert(invariant(element, !element.isSynthesized || tree == null));
ResolutionImpact resolutionImpact =
compiler.resolver.resolve(element);
- if (tree != null && !compiler.analyzeSignaturesOnly) {
+ if (tree != null && !compiler.options.analyzeSignaturesOnly) {
// TODO(het): don't do this if suppressWarnings is on, currently we have
// to do it because the typechecker also sets types
// Only analyze nodes with a corresponding [TreeElements].

Powered by Google App Engine
This is Rietveld 408576698