[CFE/bazel/DDC] Match 'tags' to reuse compiler state

This CL introduces 'tags' as a way to distinguish different setups and
be able to throw away previous state when it cannot be used.
These tags are - for now - basically filled up with the roots used for
the multi root filesystem, the idea being, that if they have changed we
cannot reuse the old state.

Change-Id: I19e069513ce3836f5bc6abf047e4359836fc7e09
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114945
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
This commit is contained in:
Jens Johansen 2019-08-30 12:06:41 +00:00 committed by commit-bot@chromium.org
parent a024685f3a
commit 8a670d773b
6 changed files with 34 additions and 5 deletions

View file

@ -275,6 +275,11 @@ Future<CompilerResult> _compile(List<String> args,
doneInputSummaries = List<Component>(summaryModules.length); doneInputSummaries = List<Component>(summaryModules.length);
compilerState = await fe.initializeIncrementalCompiler( compilerState = await fe.initializeIncrementalCompiler(
oldCompilerState, oldCompilerState,
{
"trackWidgetCreation=$trackWidgetCreation",
"multiRootScheme=${fileSystem.markerScheme}",
"multiRootRoots=${fileSystem.roots}",
},
doneInputSummaries, doneInputSummaries,
compileSdk, compileSdk,
sourcePathToUri(getSdkPath()), sourcePathToUri(getSdkPath()),

View file

@ -48,7 +48,7 @@ export '../fasta/severity.dart' show Severity;
export 'compiler_state.dart' show InitializedCompilerState; export 'compiler_state.dart' show InitializedCompilerState;
import 'util.dart' show equalMaps; import 'util.dart' show equalMaps, equalSets;
/// Initializes the compiler for a modular build. /// Initializes the compiler for a modular build.
/// ///
@ -56,6 +56,7 @@ import 'util.dart' show equalMaps;
/// as necessary based on [workerInputDigests]. /// as necessary based on [workerInputDigests].
Future<InitializedCompilerState> initializeIncrementalCompiler( Future<InitializedCompilerState> initializeIncrementalCompiler(
InitializedCompilerState oldState, InitializedCompilerState oldState,
Set<String> tags,
Uri sdkSummary, Uri sdkSummary,
Uri packagesFile, Uri packagesFile,
Uri librariesSpecificationUri, Uri librariesSpecificationUri,
@ -84,7 +85,8 @@ Future<InitializedCompilerState> initializeIncrementalCompiler(
if (oldState == null || if (oldState == null ||
oldState.incrementalCompiler == null || oldState.incrementalCompiler == null ||
oldState.incrementalCompiler.outlineOnly != outlineOnly || oldState.incrementalCompiler.outlineOnly != outlineOnly ||
!equalMaps(oldState.options.experimentalFlags, experimentalFlags)) { !equalMaps(oldState.options.experimentalFlags, experimentalFlags) ||
!equalSets(oldState.tags, tags)) {
// No - or immediately not correct - previous state. // No - or immediately not correct - previous state.
startOver = true; startOver = true;
@ -212,6 +214,7 @@ Future<InitializedCompilerState> initializeIncrementalCompiler(
return new InitializedCompilerState(options, processedOpts, return new InitializedCompilerState(options, processedOpts,
workerInputCache: workerInputCache, workerInputCache: workerInputCache,
incrementalCompiler: incrementalCompiler, incrementalCompiler: incrementalCompiler,
tags: tags,
libraryToInputDill: libraryToInputDill); libraryToInputDill: libraryToInputDill);
} }

View file

@ -16,11 +16,13 @@ class InitializedCompilerState {
final ProcessedOptions processedOpts; final ProcessedOptions processedOpts;
final Map<Uri, WorkerInputComponent> workerInputCache; final Map<Uri, WorkerInputComponent> workerInputCache;
final IncrementalCompiler incrementalCompiler; final IncrementalCompiler incrementalCompiler;
final Set<String> tags;
final Map<Uri, Uri> libraryToInputDill; final Map<Uri, Uri> libraryToInputDill;
InitializedCompilerState(this.options, this.processedOpts, InitializedCompilerState(this.options, this.processedOpts,
{this.workerInputCache, {this.workerInputCache,
this.incrementalCompiler, this.incrementalCompiler,
this.tags,
this.libraryToInputDill}); this.libraryToInputDill});
} }

View file

@ -33,7 +33,7 @@ import '../kernel_generator_impl.dart' show generateKernel;
import 'compiler_state.dart' import 'compiler_state.dart'
show InitializedCompilerState, WorkerInputComponent, digestsEqual; show InitializedCompilerState, WorkerInputComponent, digestsEqual;
import 'util.dart' show equalLists, equalMaps; import 'util.dart' show equalLists, equalMaps, equalSets;
export '../api_prototype/compiler_options.dart' export '../api_prototype/compiler_options.dart'
show CompilerOptions, parseExperimentalFlags, parseExperimentalArguments; show CompilerOptions, parseExperimentalFlags, parseExperimentalArguments;
@ -134,6 +134,7 @@ Future<InitializedCompilerState> initializeCompiler(
Future<InitializedCompilerState> initializeIncrementalCompiler( Future<InitializedCompilerState> initializeIncrementalCompiler(
InitializedCompilerState oldState, InitializedCompilerState oldState,
Set<String> tags,
List<Component> doneInputSummaries, List<Component> doneInputSummaries,
bool compileSdk, bool compileSdk,
Uri sdkRoot, Uri sdkRoot,
@ -169,8 +170,9 @@ Future<InitializedCompilerState> initializeIncrementalCompiler(
cachedSdkInput == null || cachedSdkInput == null ||
!digestsEqual(cachedSdkInput.digest, sdkDigest) || !digestsEqual(cachedSdkInput.digest, sdkDigest) ||
!equalMaps(oldState.options.experimentalFlags, experiments) || !equalMaps(oldState.options.experimentalFlags, experiments) ||
!equalMaps(oldState.options.environmentDefines, environmentDefines)) { !equalMaps(oldState.options.environmentDefines, environmentDefines) ||
// No previous state. !equalSets(oldState.tags, tags)) {
// No - or immediately not correct - previous state.
options = new CompilerOptions() options = new CompilerOptions()
..compileSdk = compileSdk ..compileSdk = compileSdk
..sdkRoot = sdkRoot ..sdkRoot = sdkRoot
@ -283,6 +285,7 @@ Future<InitializedCompilerState> initializeIncrementalCompiler(
return new InitializedCompilerState(options, processedOpts, return new InitializedCompilerState(options, processedOpts,
workerInputCache: workerInputCache, workerInputCache: workerInputCache,
incrementalCompiler: incrementalCompiler, incrementalCompiler: incrementalCompiler,
tags: tags,
libraryToInputDill: libraryToInputDill); libraryToInputDill: libraryToInputDill);
} }

View file

@ -12,6 +12,16 @@ bool equalLists<T>(List<T> a, List<T> b) {
return true; return true;
} }
bool equalSets<K>(Set<K> a, Set<K> b) {
if (identical(a, b)) return true;
if (a == null || b == null) return false;
if (a.length != b.length) return false;
for (K entry in a) {
if (!b.contains(entry)) return false;
}
return true;
}
bool equalMaps<K, V>(Map<K, V> a, Map<K, V> b) { bool equalMaps<K, V>(Map<K, V> a, Map<K, V> b) {
if (identical(a, b)) return true; if (identical(a, b)) return true;
if (a == null || b == null) return false; if (a == null || b == null) return false;

View file

@ -272,6 +272,12 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
// TODO(sigmund): add support for experiments with the incremental compiler. // TODO(sigmund): add support for experiments with the incremental compiler.
state = await fe.initializeIncrementalCompiler( state = await fe.initializeIncrementalCompiler(
previousState, previousState,
{
"target=$targetName",
"trackWidgetCreation=$trackWidgetCreation",
"multiRootScheme=${fileSystem.markerScheme}",
"multiRootRoots=${fileSystem.roots}",
},
_toUri(parsedArgs['dart-sdk-summary']), _toUri(parsedArgs['dart-sdk-summary']),
_toUri(parsedArgs['packages-file']), _toUri(parsedArgs['packages-file']),
_toUri(parsedArgs['libraries-file']), _toUri(parsedArgs['libraries-file']),