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

Side by Side Diff: pkg/front_end/lib/src/incremental_kernel_generator_impl.dart

Issue 2865253003: (Reland) Start using FileState/FileSystemState to provide consistent view. (Closed)
Patch Set: New changes. 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:front_end/file_system.dart'; 7 import 'package:front_end/file_system.dart';
8 import 'package:front_end/incremental_kernel_generator.dart'; 8 import 'package:front_end/incremental_kernel_generator.dart';
9 import 'package:front_end/incremental_resolved_ast_generator.dart'; 9 import 'package:front_end/incremental_resolved_ast_generator.dart';
10 import 'package:front_end/src/base/processed_options.dart'; 10 import 'package:front_end/src/base/processed_options.dart';
11 import 'package:front_end/src/fasta/dill/dill_target.dart'; 11 import 'package:front_end/src/fasta/dill/dill_target.dart';
12 import 'package:front_end/src/fasta/kernel/kernel_target.dart'; 12 import 'package:front_end/src/fasta/kernel/kernel_target.dart';
13 import 'package:front_end/src/fasta/ticker.dart'; 13 import 'package:front_end/src/fasta/ticker.dart';
14 import 'package:front_end/src/fasta/translate_uri.dart'; 14 import 'package:front_end/src/fasta/translate_uri.dart';
15 import 'package:front_end/src/incremental/file_state.dart';
15 import 'package:kernel/kernel.dart' hide Source; 16 import 'package:kernel/kernel.dart' hide Source;
17 import 'package:kernel/target/vm.dart';
16 18
17 dynamic unimplemented() { 19 dynamic unimplemented() {
18 // TODO(paulberry): get rid of this. 20 // TODO(paulberry): get rid of this.
19 throw new UnimplementedError(); 21 throw new UnimplementedError();
20 } 22 }
21 23
22 /// Implementation of [IncrementalKernelGenerator]. 24 /// Implementation of [IncrementalKernelGenerator].
23 /// 25 ///
24 /// TODO(scheglov) Update the documentation. 26 /// TODO(scheglov) Update the documentation.
25 /// 27 ///
26 /// Theory of operation: an instance of [IncrementalResolvedAstGenerator] is 28 /// Theory of operation: an instance of [IncrementalResolvedAstGenerator] is
27 /// used to obtain resolved ASTs, and these are fed into kernel code generation 29 /// used to obtain resolved ASTs, and these are fed into kernel code generation
28 /// logic. 30 /// logic.
29 class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator { 31 class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
30 /// The URI of the program entry point. 32 /// The URI of the program entry point.
31 final Uri _entryPoint; 33 final Uri _entryPoint;
32 34
33 /// The compiler options, such as the [FileSystem], the SDK dill location, 35 /// The compiler options, such as the [FileSystem], the SDK dill location,
34 /// etc. 36 /// etc.
35 final ProcessedOptions _options; 37 final ProcessedOptions _options;
36 38
39 /// The set of absolute file URIs that were reported through [invalidate]
40 /// and not checked for actual changes yet.
41 final Set<Uri> _invalidatedFiles = new Set<Uri>();
42
37 /// The object that knows how to resolve "package:" and "dart:" URIs. 43 /// The object that knows how to resolve "package:" and "dart:" URIs.
38 TranslateUri _uriTranslator; 44 TranslateUri _uriTranslator;
39 45
46 /// The current file system state.
47 FileSystemState _fsState;
48
40 /// The cached SDK kernel. 49 /// The cached SDK kernel.
41 DillTarget _sdkDillTarget; 50 DillTarget _sdkDillTarget;
42 51
43 IncrementalKernelGeneratorImpl(this._entryPoint, this._options); 52 IncrementalKernelGeneratorImpl(this._entryPoint, this._options);
44 53
45 @override 54 @override
46 Future<DeltaProgram> computeDelta( 55 Future<DeltaProgram> computeDelta(
47 {Future<Null> watch(Uri uri, bool used)}) async { 56 {Future<Null> watch(Uri uri, bool used)}) async {
48 _uriTranslator ??= await _options.getUriTranslator(); 57 await _initialize();
58 await _ensureVmLibrariesLoaded();
59 await _refreshInvalidatedFiles();
60
61 // Ensure that the graph starting at the entry point is ready.
62 await _fsState.getFile(_entryPoint);
49 63
50 DillTarget sdkTarget = await _getSdkDillTarget(); 64 DillTarget sdkTarget = await _getSdkDillTarget();
51 // TODO(scheglov) Use it to also serve other package kernels. 65 // TODO(scheglov) Use it to also serve other package kernels.
52 66
53 KernelTarget kernelTarget = new KernelTarget(_options.fileSystem, sdkTarget, 67 KernelTarget kernelTarget = new KernelTarget(_fsState.fileSystemView,
54 _uriTranslator, _options.strongMode, null); 68 sdkTarget, _uriTranslator, _options.strongMode, null);
55 kernelTarget.read(_entryPoint); 69 kernelTarget.read(_entryPoint);
56 70
57 // TODO(scheglov) Replace with a better API. 71 // TODO(scheglov) Replace with a better API.
58 // Firstly, we don't "write" anything here. 72 // Firstly, we don't "write" anything here.
59 // Secondly, it catches all the exceptions and write them to `stderr`. 73 // Secondly, it catches all the exceptions and write them to `stderr`.
60 // This is too interactive and not API-clients friendly. 74 // This is too interactive and not API-clients friendly.
61 await kernelTarget.writeOutline(null); 75 await kernelTarget.writeOutline(null);
62 76
63 // TODO(scheglov) Replace with a better API. 77 // TODO(scheglov) Replace with a better API.
64 Program program = await kernelTarget.writeProgram(null); 78 Program program = await kernelTarget.writeProgram(null);
65 return new DeltaProgram(program); 79 return new DeltaProgram(program);
66 } 80 }
67 81
68 @override 82 @override
69 void invalidate(String path) => unimplemented(); 83 void invalidate(Uri uri) {
84 _invalidatedFiles.add(uri);
85 }
70 86
71 @override 87 @override
72 void invalidateAll() => unimplemented(); 88 void invalidateAll() => unimplemented();
73 89
90 /// Fasta unconditionally loads all VM libraries. In order to be able to
91 /// serve them using the file system view, we need to ask [_fsState] for
92 /// the corresponding files.
93 Future<Null> _ensureVmLibrariesLoaded() async {
94 List<String> extraLibraries = new VmTarget(null).extraRequiredLibraries;
95 for (String absoluteUriStr in extraLibraries) {
96 Uri absoluteUri = Uri.parse(absoluteUriStr);
97 Uri fileUri = _uriTranslator.translate(absoluteUri);
98 await _fsState.getFile(fileUri);
99 }
100 }
101
74 /// Return the [DillTarget] that is used inside of [KernelTarget] to 102 /// Return the [DillTarget] that is used inside of [KernelTarget] to
75 /// resynthesize SDK libraries. 103 /// resynthesize SDK libraries.
76 Future<DillTarget> _getSdkDillTarget() async { 104 Future<DillTarget> _getSdkDillTarget() async {
77 if (_sdkDillTarget == null) { 105 if (_sdkDillTarget == null) {
78 _sdkDillTarget = 106 _sdkDillTarget =
79 new DillTarget(new Ticker(isVerbose: false), _uriTranslator); 107 new DillTarget(new Ticker(isVerbose: false), _uriTranslator);
80 // TODO(scheglov) Read the SDK kernel. 108 // TODO(scheglov) Read the SDK kernel.
81 // _sdkDillTarget.read(options.sdkSummary); 109 // _sdkDillTarget.read(options.sdkSummary);
82 // await _sdkDillTarget.writeOutline(null); 110 // await _sdkDillTarget.writeOutline(null);
83 } else { 111 } else {
84 // Program sdkProgram = _sdkDillTarget.loader.program; 112 // Program sdkProgram = _sdkDillTarget.loader.program;
85 // sdkProgram.visitChildren(new _ClearCanonicalNamesVisitor()); 113 // sdkProgram.visitChildren(new _ClearCanonicalNamesVisitor());
86 } 114 }
87 return _sdkDillTarget; 115 return _sdkDillTarget;
88 } 116 }
117
118 /// Ensure that asynchronous data from options is ready.
119 ///
120 /// Ideally this data should be prepared in the constructor, but constructors
121 /// cannot be asynchronous.
122 Future<Null> _initialize() async {
123 _uriTranslator ??= await _options.getUriTranslator();
124 _fsState ??= new FileSystemState(_options.fileSystem, _uriTranslator);
125 }
126
127 /// Refresh all the invalidated files and update dependencies.
128 Future<Null> _refreshInvalidatedFiles() async {
129 for (Uri fileUri in _invalidatedFiles) {
130 FileState file = await _fsState.getFile(fileUri);
131 await file.refresh();
132 }
133 _invalidatedFiles.clear();
134 }
89 } 135 }
90 136
91 ///// Clears canonical names of [NamedNode] references. 137 ///// Clears canonical names of [NamedNode] references.
92 //class _ClearCanonicalNamesVisitor extends Visitor { 138 //class _ClearCanonicalNamesVisitor extends Visitor {
93 // defaultNode(Node node) { 139 // defaultNode(Node node) {
94 // if (node is NamedNode) { 140 // if (node is NamedNode) {
95 // node.reference.canonicalName = null; 141 // node.reference.canonicalName = null;
96 // } 142 // }
97 // node.visitChildren(this); 143 // node.visitChildren(this);
98 // } 144 // }
99 //} 145 //}
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/incremental/file_state.dart ('k') | pkg/front_end/test/incremental_kernel_generator_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698