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

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

Issue 2871783002: Start using FileState/FileSystemState to provide consistent view. (Closed)
Patch Set: Created 3 years, 7 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 9739aa4473dbc6bc7c6ddf15c5d5c9ad2075c9ff..780852dfcb62b80e3885e65c1718588d0996fb9e 100644
--- a/pkg/front_end/lib/src/incremental_kernel_generator_impl.dart
+++ b/pkg/front_end/lib/src/incremental_kernel_generator_impl.dart
@@ -12,7 +12,9 @@ import 'package:front_end/src/fasta/dill/dill_target.dart';
import 'package:front_end/src/fasta/kernel/kernel_target.dart';
import 'package:front_end/src/fasta/ticker.dart';
import 'package:front_end/src/fasta/translate_uri.dart';
+import 'package:front_end/src/incremental/file_state.dart';
import 'package:kernel/kernel.dart' hide Source;
+import 'package:kernel/target/vm.dart';
dynamic unimplemented() {
// TODO(paulberry): get rid of this.
@@ -34,9 +36,16 @@ class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
/// etc.
final ProcessedOptions _options;
+ /// 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>();
+
/// The object that knows how to resolve "package:" and "dart:" URIs.
TranslateUri _uriTranslator;
+ /// The current file system state.
+ FileSystemState _fsState;
+
/// The cached SDK kernel.
DillTarget _sdkDillTarget;
@@ -45,13 +54,18 @@ class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
@override
Future<DeltaProgram> computeDelta(
{Future<Null> watch(Uri uri, bool used)}) async {
- _uriTranslator ??= await _options.getUriTranslator();
+ await _initialize();
+ await _ensureVmLibrariesLoaded();
+ await _refreshInvalidatedFiles();
+
+ // Ensure that the graph starting at the entry point is ready.
+ await _fsState.getFile(_entryPoint);
DillTarget sdkTarget = await _getSdkDillTarget();
// TODO(scheglov) Use it to also serve other package kernels.
- KernelTarget kernelTarget = new KernelTarget(_options.fileSystem, sdkTarget,
- _uriTranslator, _options.strongMode, null);
+ KernelTarget kernelTarget = new KernelTarget(_fsState.fileSystemView,
+ sdkTarget, _uriTranslator, _options.strongMode, null);
kernelTarget.read(_entryPoint);
// TODO(scheglov) Replace with a better API.
@@ -66,11 +80,25 @@ class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
}
@override
- void invalidate(String path) => unimplemented();
+ void invalidate(Uri uri) {
+ _invalidatedFiles.add(uri);
+ }
@override
void invalidateAll() => unimplemented();
+ /// Fasta unconditionally loads all VM libraries. In order to be able to
+ /// serve them using the file system view, we need to ask [_fsState] for
+ /// the corresponding files.
+ Future<Null> _ensureVmLibrariesLoaded() async {
+ List<String> extraLibraries = new VmTarget(null).extraRequiredLibraries;
+ for (String absoluteUriStr in extraLibraries) {
+ Uri absoluteUri = Uri.parse(absoluteUriStr);
+ Uri fileUri = _uriTranslator.translate(absoluteUri);
+ await _fsState.getFile(fileUri);
+ }
+ }
+
/// Return the [DillTarget] that is used inside of [KernelTarget] to
/// resynthesize SDK libraries.
Future<DillTarget> _getSdkDillTarget() async {
@@ -86,6 +114,24 @@ class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
}
return _sdkDillTarget;
}
+
+ /// Ensure that asynchronous data from options is ready.
+ ///
+ /// Ideally this data should be prepared in the constructor, but constructors
+ /// cannot be asynchronous.
Paul Berry 2017/05/08 22:10:49 Alternatively, we could change IncrementalKernelGe
scheglov 2017/05/09 00:16:29 ACK That's what I had in mind too.
+ Future<Null> _initialize() async {
+ _uriTranslator ??= await _options.getUriTranslator();
+ _fsState ??= new FileSystemState(_options.fileSystem, _uriTranslator);
+ }
+
+ /// Refresh all the invalidated files and update dependencies.
+ Future<Null> _refreshInvalidatedFiles() async {
+ for (Uri fileUri in _invalidatedFiles) {
+ FileState file = await _fsState.getFile(fileUri);
+ await file.refresh();
+ }
+ _invalidatedFiles.clear();
+ }
}
///// Clears canonical names of [NamedNode] references.

Powered by Google App Engine
This is Rietveld 408576698