From 8a670d773bccdea29b8f76249317a6e054d7c50a Mon Sep 17 00:00:00 2001 From: Jens Johansen Date: Fri, 30 Aug 2019 12:06:41 +0000 Subject: [PATCH] [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 Commit-Queue: Jens Johansen --- pkg/dev_compiler/lib/src/kernel/command.dart | 5 +++++ pkg/front_end/lib/src/api_unstable/bazel_worker.dart | 7 +++++-- pkg/front_end/lib/src/api_unstable/compiler_state.dart | 2 ++ pkg/front_end/lib/src/api_unstable/ddc.dart | 9 ++++++--- pkg/front_end/lib/src/api_unstable/util.dart | 10 ++++++++++ utils/bazel/kernel_worker.dart | 6 ++++++ 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/pkg/dev_compiler/lib/src/kernel/command.dart b/pkg/dev_compiler/lib/src/kernel/command.dart index b3f7916f296..bf38ecbebce 100644 --- a/pkg/dev_compiler/lib/src/kernel/command.dart +++ b/pkg/dev_compiler/lib/src/kernel/command.dart @@ -275,6 +275,11 @@ Future _compile(List args, doneInputSummaries = List(summaryModules.length); compilerState = await fe.initializeIncrementalCompiler( oldCompilerState, + { + "trackWidgetCreation=$trackWidgetCreation", + "multiRootScheme=${fileSystem.markerScheme}", + "multiRootRoots=${fileSystem.roots}", + }, doneInputSummaries, compileSdk, sourcePathToUri(getSdkPath()), diff --git a/pkg/front_end/lib/src/api_unstable/bazel_worker.dart b/pkg/front_end/lib/src/api_unstable/bazel_worker.dart index a36e27412ea..68939cdaf18 100644 --- a/pkg/front_end/lib/src/api_unstable/bazel_worker.dart +++ b/pkg/front_end/lib/src/api_unstable/bazel_worker.dart @@ -48,7 +48,7 @@ export '../fasta/severity.dart' show Severity; export 'compiler_state.dart' show InitializedCompilerState; -import 'util.dart' show equalMaps; +import 'util.dart' show equalMaps, equalSets; /// Initializes the compiler for a modular build. /// @@ -56,6 +56,7 @@ import 'util.dart' show equalMaps; /// as necessary based on [workerInputDigests]. Future initializeIncrementalCompiler( InitializedCompilerState oldState, + Set tags, Uri sdkSummary, Uri packagesFile, Uri librariesSpecificationUri, @@ -84,7 +85,8 @@ Future initializeIncrementalCompiler( if (oldState == null || oldState.incrementalCompiler == null || 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. startOver = true; @@ -212,6 +214,7 @@ Future initializeIncrementalCompiler( return new InitializedCompilerState(options, processedOpts, workerInputCache: workerInputCache, incrementalCompiler: incrementalCompiler, + tags: tags, libraryToInputDill: libraryToInputDill); } diff --git a/pkg/front_end/lib/src/api_unstable/compiler_state.dart b/pkg/front_end/lib/src/api_unstable/compiler_state.dart index 57fdac47a90..0852c60f64e 100644 --- a/pkg/front_end/lib/src/api_unstable/compiler_state.dart +++ b/pkg/front_end/lib/src/api_unstable/compiler_state.dart @@ -16,11 +16,13 @@ class InitializedCompilerState { final ProcessedOptions processedOpts; final Map workerInputCache; final IncrementalCompiler incrementalCompiler; + final Set tags; final Map libraryToInputDill; InitializedCompilerState(this.options, this.processedOpts, {this.workerInputCache, this.incrementalCompiler, + this.tags, this.libraryToInputDill}); } diff --git a/pkg/front_end/lib/src/api_unstable/ddc.dart b/pkg/front_end/lib/src/api_unstable/ddc.dart index a824182b748..585c73822c0 100644 --- a/pkg/front_end/lib/src/api_unstable/ddc.dart +++ b/pkg/front_end/lib/src/api_unstable/ddc.dart @@ -33,7 +33,7 @@ import '../kernel_generator_impl.dart' show generateKernel; import 'compiler_state.dart' show InitializedCompilerState, WorkerInputComponent, digestsEqual; -import 'util.dart' show equalLists, equalMaps; +import 'util.dart' show equalLists, equalMaps, equalSets; export '../api_prototype/compiler_options.dart' show CompilerOptions, parseExperimentalFlags, parseExperimentalArguments; @@ -134,6 +134,7 @@ Future initializeCompiler( Future initializeIncrementalCompiler( InitializedCompilerState oldState, + Set tags, List doneInputSummaries, bool compileSdk, Uri sdkRoot, @@ -169,8 +170,9 @@ Future initializeIncrementalCompiler( cachedSdkInput == null || !digestsEqual(cachedSdkInput.digest, sdkDigest) || !equalMaps(oldState.options.experimentalFlags, experiments) || - !equalMaps(oldState.options.environmentDefines, environmentDefines)) { - // No previous state. + !equalMaps(oldState.options.environmentDefines, environmentDefines) || + !equalSets(oldState.tags, tags)) { + // No - or immediately not correct - previous state. options = new CompilerOptions() ..compileSdk = compileSdk ..sdkRoot = sdkRoot @@ -283,6 +285,7 @@ Future initializeIncrementalCompiler( return new InitializedCompilerState(options, processedOpts, workerInputCache: workerInputCache, incrementalCompiler: incrementalCompiler, + tags: tags, libraryToInputDill: libraryToInputDill); } diff --git a/pkg/front_end/lib/src/api_unstable/util.dart b/pkg/front_end/lib/src/api_unstable/util.dart index 146ddd0c3f8..cc5f7fcdfa0 100644 --- a/pkg/front_end/lib/src/api_unstable/util.dart +++ b/pkg/front_end/lib/src/api_unstable/util.dart @@ -12,6 +12,16 @@ bool equalLists(List a, List b) { return true; } +bool equalSets(Set a, Set 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(Map a, Map b) { if (identical(a, b)) return true; if (a == null || b == null) return false; diff --git a/utils/bazel/kernel_worker.dart b/utils/bazel/kernel_worker.dart index a0e5af36e41..d18212b3286 100644 --- a/utils/bazel/kernel_worker.dart +++ b/utils/bazel/kernel_worker.dart @@ -272,6 +272,12 @@ Future computeKernel(List args, // TODO(sigmund): add support for experiments with the incremental compiler. state = await fe.initializeIncrementalCompiler( previousState, + { + "target=$targetName", + "trackWidgetCreation=$trackWidgetCreation", + "multiRootScheme=${fileSystem.markerScheme}", + "multiRootRoots=${fileSystem.roots}", + }, _toUri(parsedArgs['dart-sdk-summary']), _toUri(parsedArgs['packages-file']), _toUri(parsedArgs['libraries-file']),