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

Unified Diff: pkg/front_end/lib/src/incremental/kernel_driver.dart

Issue 2976003002: Implement IncrementalKernelGeneratorImpl using KernelDriver. (Closed)
Patch Set: Created 3 years, 5 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 | pkg/front_end/lib/src/incremental_kernel_generator_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/incremental/kernel_driver.dart
diff --git a/pkg/front_end/lib/src/incremental_kernel_generator_impl.dart b/pkg/front_end/lib/src/incremental/kernel_driver.dart
similarity index 71%
copy from pkg/front_end/lib/src/incremental_kernel_generator_impl.dart
copy to pkg/front_end/lib/src/incremental/kernel_driver.dart
index daff92492b7f5bf6d67378210c91de80962cfde9..375f981dcf86f2ad5d41b2f2bea38ff623c9fa85 100644
--- a/pkg/front_end/lib/src/incremental_kernel_generator_impl.dart
+++ b/pkg/front_end/lib/src/incremental/kernel_driver.dart
@@ -5,10 +5,8 @@
import 'dart:async';
import 'package:front_end/file_system.dart';
-import 'package:front_end/incremental_kernel_generator.dart';
import 'package:front_end/src/base/api_signature.dart';
import 'package:front_end/src/base/performace_logger.dart';
-import 'package:front_end/src/base/processed_options.dart';
import 'package:front_end/src/fasta/dill/dill_library_builder.dart';
import 'package:front_end/src/fasta/dill/dill_target.dart';
import 'package:front_end/src/fasta/kernel/kernel_target.dart';
@@ -23,35 +21,33 @@ import 'package:kernel/target/targets.dart' show TargetFlags;
import 'package:kernel/target/vm_fasta.dart' show VmFastaTarget;
import 'package:meta/meta.dart';
-/// Implementation of [IncrementalKernelGenerator].
-///
-/// TODO(scheglov) Update the documentation.
+/// TODO(scheglov) document
+typedef Future<Null> KernelDriverFileAddedFn(Uri uri);
+
+/// This class computes [LibraryCycleResult]s for Dart files.
///
-/// Theory of operation: an instance of [IncrementalResolvedAstGenerator] is
-/// used to obtain resolved ASTs, and these are fed into kernel code generation
-/// logic.
-class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
+/// TODO(scheglov) Improve the documentation.
Paul Berry 2017/07/12 17:04:43 Would you mind adding documentation before landing
+class KernelDriver {
/// The version of data format, should be incremented on every format change.
static const int DATA_VERSION = 1;
- /// The compiler options, such as the [FileSystem], the SDK dill location,
- /// etc.
- final ProcessedOptions _options;
-
- /// The object that knows how to resolve "package:" and "dart:" URIs.
- final TranslateUri _uriTranslator;
-
/// The logger to report compilation progress.
final PerformanceLog _logger;
+ /// The [FileSystem] which should be used by the front end to access files.
+ final FileSystem _fileSystem;
+
/// The byte storage to get and put serialized data.
final ByteStore _byteStore;
- /// The URI of the program entry point.
- final Uri _entryPoint;
+ /// The object that knows how to resolve "package:" and "dart:" URIs.
+ final TranslateUri _uriTranslator;
+
+ /// Is `true` if strong mode analysis should be used.
+ final bool _strongMode;
- /// The function to notify when files become used or unused, or `null`.
- final WatchUsedFilesFn _watchFn;
+ /// TODO(scheglov) document
+ final KernelDriverFileAddedFn _fileAddedFn;
/// The salt to mix into all hashes used as keys for serialized data.
List<int> _salt;
@@ -59,9 +55,6 @@ class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
/// The current file system state.
FileSystemState _fsState;
- /// Latest compilation signatures produced by [computeDelta] for libraries.
- final Map<Uri, String> _latestSignature = {};
-
/// The set of absolute file URIs that were reported through [invalidate]
/// and not checked for actual changes yet.
final Set<Uri> _invalidatedFiles = new Set<Uri>();
@@ -69,38 +62,39 @@ class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
/// The object that provides additional information for tests.
final _TestView _testView = new _TestView();
- IncrementalKernelGeneratorImpl(
- this._options, this._uriTranslator, this._entryPoint,
- {WatchUsedFilesFn watch})
- : _logger = _options.logger,
- _byteStore = _options.byteStore,
- _watchFn = watch {
+ KernelDriver(this._logger, this._fileSystem, this._byteStore,
+ this._uriTranslator, this._strongMode,
+ {KernelDriverFileAddedFn fileAddedFn})
+ : _fileAddedFn = fileAddedFn {
_computeSalt();
Future<Null> onFileAdded(Uri uri) {
- if (_watchFn != null) {
- return _watchFn(uri, true);
+ if (_fileAddedFn != null) {
+ return _fileAddedFn(uri);
}
return new Future.value();
}
- _fsState = new FileSystemState(_options.byteStore, _options.fileSystem,
- _uriTranslator, _salt, onFileAdded);
+ _fsState = new FileSystemState(
+ _byteStore, _fileSystem, _uriTranslator, _salt, onFileAdded);
}
+ /// TODO(scheglov) document
+ FileSystemState get fsState => _fsState;
+
/// Return the object that provides additional information for tests.
@visibleForTesting
_TestView get test => _testView;
- @override
- Future<DeltaProgram> computeDelta() async {
+ /// TODO(scheglov) document
+ Future<KernelResult> getKernel(Uri uri) async {
return await _logger.runAsync('Compute delta', () async {
await _refreshInvalidatedFiles();
// Ensure that the graph starting at the entry point is ready.
FileState entryLibrary =
await _logger.runAsync('Build graph of files', () async {
- return await _fsState.getFile(_entryPoint);
+ return await _fsState.getFile(uri);
});
List<LibraryCycle> cycles = _logger.run('Compute library cycles', () {
@@ -113,77 +107,28 @@ class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
DillTarget dillTarget = new DillTarget(
new Ticker(isVerbose: false),
_uriTranslator,
- new VmFastaTarget(new TargetFlags(strongMode: _options.strongMode)));
+ new VmFastaTarget(new TargetFlags(strongMode: _strongMode)));
- List<_LibraryCycleResult> results = [];
+ List<LibraryCycleResult> results = [];
_testView.compiledCycles.clear();
await _logger.runAsync('Compute results for cycles', () async {
for (LibraryCycle cycle in cycles) {
- _LibraryCycleResult result =
+ LibraryCycleResult result =
await _compileCycle(nameRoot, dillTarget, cycle);
results.add(result);
}
});
- Program program = new Program(nameRoot: nameRoot);
-
- // 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 (_latestSignature[uri] != result.signature) {
- _latestSignature[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>();
-
- void gatherVmRequiredLibraryCycles(LibraryCycle cycle) {
- if (vmRequiredLibraryCycles.add(cycle)) {
- cycle.directUsers.forEach(gatherVmRequiredLibraryCycles);
- }
- }
-
- affectedLibraryCycles.forEach(gatherVmRequiredLibraryCycles);
-
- // Add required libraries.
- 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;
- }
- }
- }
-
- return new DeltaProgram(program);
+ return new KernelResult(nameRoot, results);
});
}
- @override
+ /// TODO(scheglov) document
void invalidate(Uri uri) {
_invalidatedFiles.add(uri);
}
- @override
+ /// TODO(scheglov) document
void invalidateAll() {
_invalidatedFiles.addAll(_fsState.fileUris);
}
@@ -191,7 +136,7 @@ class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
/// Ensure that [dillTarget] includes the [cycle] libraries. It already
/// contains all the libraries that sorted before the given [cycle] in
/// topological order. Return the result with the cycle libraries.
- Future<_LibraryCycleResult> _compileCycle(
+ Future<LibraryCycleResult> _compileCycle(
CanonicalName nameRoot, DillTarget dillTarget, LibraryCycle cycle) async {
return _logger.runAsync('Compile cycle $cycle', () async {
String signature = _getCycleSignature(cycle);
@@ -229,7 +174,7 @@ class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
await appendNewDillLibraries(program);
- return new _LibraryCycleResult(cycle, signature, program.libraries);
+ return new LibraryCycleResult(cycle, signature, program.libraries);
});
}
@@ -263,7 +208,7 @@ class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
_logger.writeln('Stored ${bytes.length} bytes.');
});
- return new _LibraryCycleResult(cycle, signature, kernelLibraries);
+ return new LibraryCycleResult(cycle, signature, kernelLibraries);
});
}
@@ -299,8 +244,7 @@ class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
void _computeSalt() {
var saltBuilder = new ApiSignature();
saltBuilder.addInt(DATA_VERSION);
- saltBuilder.addBool(_options.strongMode);
- saltBuilder.addString(_entryPoint.toString());
+ saltBuilder.addBool(_strongMode);
_salt = saltBuilder.toByteList();
}
@@ -354,20 +298,20 @@ class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
await file.refresh();
}
}
-
- // The file graph might have changed, perform GC.
- var removedFiles = _fsState.gc(_entryPoint);
- if (removedFiles.isNotEmpty && _watchFn != null) {
- for (var removedFile in removedFiles) {
- await _watchFn(removedFile.fileUri, false);
- }
- }
});
}
}
+/// TODO(scheglov) document
+class KernelResult {
+ final CanonicalName nameRoot;
+ final List<LibraryCycleResult> results;
+
+ KernelResult(this.nameRoot, this.results);
+}
+
/// Compilation result for a library cycle.
-class _LibraryCycleResult {
+class LibraryCycleResult {
final LibraryCycle cycle;
/// The signature of the result.
@@ -382,7 +326,7 @@ class _LibraryCycleResult {
/// are not included, but but references to those dependencies are included.
final List<Library> kernelLibraries;
- _LibraryCycleResult(this.cycle, this.signature, this.kernelLibraries);
+ LibraryCycleResult(this.cycle, this.signature, this.kernelLibraries);
}
@visibleForTesting
« no previous file with comments | « no previous file | pkg/front_end/lib/src/incremental_kernel_generator_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698