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

Unified Diff: pkg/front_end/lib/src/incremental_kernel_generator_impl.dart

Issue 2993393002: Enforce single computeDelta() invocation. (Closed)
Patch Set: Created 3 years, 4 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/front_end/lib/src/incremental_kernel_generator_impl.dart
diff --git a/pkg/front_end/lib/src/incremental_kernel_generator_impl.dart b/pkg/front_end/lib/src/incremental_kernel_generator_impl.dart
index 77cd524f5212305080fb4ea12fa7c1627e3e0b83..6c6c1aef7dcf1c02b117a5d8b00d4fe539615da5 100644
--- a/pkg/front_end/lib/src/incremental_kernel_generator_impl.dart
+++ b/pkg/front_end/lib/src/incremental_kernel_generator_impl.dart
@@ -36,6 +36,9 @@ class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
/// The [KernelDriver] that is used to compute kernels.
KernelDriver _driver;
+ /// Whether [computeDelta] is executing.
+ bool _isComputeDeltaExecuting = false;
+
/// The current signatures for libraries.
final Map<Uri, String> _currentSignatures = {};
@@ -77,69 +80,79 @@ class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
@override
Future<DeltaProgram> computeDelta() async {
- if (_lastSignatures != null) {
+ if (_isComputeDeltaExecuting) {
throw new StateError(
- 'The last delta must be either accepted or rejected.');
+ 'Another computeDelta() invocation is still executing.');
}
- _lastSignatures = {};
-
- return await _logger.runAsync('Compute delta', () async {
- KernelResult kernelResult = await _driver.getKernel(_entryPoint);
- List<LibraryCycleResult> results = kernelResult.results;
-
- // The file graph might have changed, perform GC.
- await _gc();
-
- // The set of affected library cycles (have different signatures).
- final affectedLibraryCycles = new Set<LibraryCycle>();
- for (LibraryCycleResult result in results) {
- for (Library library in result.kernelLibraries) {
- Uri uri = library.importUri;
- if (_currentSignatures[uri] != result.signature) {
- _lastSignatures[uri] = result.signature;
- affectedLibraryCycles.add(result.cycle);
+ _isComputeDeltaExecuting = true;
+
+ try {
+ if (_lastSignatures != null) {
+ throw new StateError(
+ 'The last delta must be either accepted or rejected.');
+ }
+ _lastSignatures = {};
+
+ return await _logger.runAsync('Compute delta', () async {
+ KernelResult kernelResult = await _driver.getKernel(_entryPoint);
+ List<LibraryCycleResult> results = kernelResult.results;
+
+ // The file graph might have changed, perform GC.
+ await _gc();
+
+ // The set of affected library cycles (have different signatures).
+ final affectedLibraryCycles = new Set<LibraryCycle>();
+ for (LibraryCycleResult result in results) {
+ for (Library library in result.kernelLibraries) {
+ Uri uri = library.importUri;
+ if (_currentSignatures[uri] != result.signature) {
+ _lastSignatures[uri] = result.signature;
+ affectedLibraryCycles.add(result.cycle);
+ }
}
}
- }
- // The set of affected library cycles (have different signatures),
- // or libraries that import or export affected libraries (so VM might
- // have inlined some code from affected libraries into them).
- final vmRequiredLibraryCycles = new Set<LibraryCycle>();
+ // The set of affected library cycles (have different signatures),
+ // or libraries that import or export affected libraries (so VM might
+ // have inlined some code from affected libraries into them).
+ final vmRequiredLibraryCycles = new Set<LibraryCycle>();
- void gatherVmRequiredLibraryCycles(LibraryCycle cycle) {
- if (vmRequiredLibraryCycles.add(cycle)) {
- cycle.directUsers.forEach(gatherVmRequiredLibraryCycles);
+ void gatherVmRequiredLibraryCycles(LibraryCycle cycle) {
+ if (vmRequiredLibraryCycles.add(cycle)) {
+ cycle.directUsers.forEach(gatherVmRequiredLibraryCycles);
+ }
}
- }
- affectedLibraryCycles.forEach(gatherVmRequiredLibraryCycles);
+ affectedLibraryCycles.forEach(gatherVmRequiredLibraryCycles);
- // Add required libraries.
- Program program = new Program(nameRoot: kernelResult.nameRoot);
- for (LibraryCycleResult result in results) {
- if (vmRequiredLibraryCycles.contains(result.cycle)) {
- for (Library library in result.kernelLibraries) {
- program.libraries.add(library);
- library.parent = program;
+ // Add required libraries.
+ Program program = new Program(nameRoot: kernelResult.nameRoot);
+ for (LibraryCycleResult result in results) {
+ if (vmRequiredLibraryCycles.contains(result.cycle)) {
+ for (Library library in result.kernelLibraries) {
+ program.libraries.add(library);
+ library.parent = program;
+ }
}
}
- }
- // Set the main method.
- if (program.libraries.isNotEmpty) {
- for (Library library in results.last.kernelLibraries) {
- if (library.importUri == _entryPoint) {
- program.mainMethod = library.procedures.firstWhere(
- (procedure) => procedure.name.name == 'main',
- orElse: () => null);
- break;
+ // Set the main method.
+ if (program.libraries.isNotEmpty) {
+ for (Library library in results.last.kernelLibraries) {
+ if (library.importUri == _entryPoint) {
+ program.mainMethod = library.procedures.firstWhere(
+ (procedure) => procedure.name.name == 'main',
+ orElse: () => null);
+ break;
+ }
}
}
- }
- return new DeltaProgram(program);
- });
+ return new DeltaProgram(program);
+ });
+ } finally {
+ _isComputeDeltaExecuting = false;
+ }
}
@override
@@ -153,7 +166,8 @@ class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
_lastSignatures = null;
}
- /// TODO(scheglov) document
+ /// Find files which are not referenced from the entry point and report
+ /// them to the watch function.
Future<Null> _gc() async {
var removedFiles = _driver.fsState.gc(_entryPoint);
if (removedFiles.isNotEmpty && _watchFn != null) {

Powered by Google App Engine
This is Rietveld 408576698