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

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

Issue 2869563002: Initial version of Fasta based IncrementalKernelGenerator. (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 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:analyzer/dart/ast/ast.dart'; 7 import 'package:front_end/compiler_options.dart';
8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 8 import 'package:front_end/file_system.dart';
9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/error/error.dart';
11 import 'package:analyzer/src/generated/engine.dart';
12 import 'package:analyzer/src/generated/source.dart';
13 import 'package:front_end/incremental_kernel_generator.dart'; 9 import 'package:front_end/incremental_kernel_generator.dart';
14 import 'package:front_end/incremental_resolved_ast_generator.dart'; 10 import 'package:front_end/incremental_resolved_ast_generator.dart';
15 import 'package:front_end/src/base/processed_options.dart'; 11 import 'package:front_end/src/fasta/dill/dill_target.dart';
16 import 'package:front_end/src/base/source.dart'; 12 import 'package:front_end/src/fasta/kernel/kernel_target.dart';
17 import 'package:front_end/src/incremental_resolved_ast_generator_impl.dart'; 13 import 'package:front_end/src/fasta/ticker.dart';
18 import 'package:analyzer/src/kernel/loader.dart'; 14 import 'package:front_end/src/fasta/translate_uri.dart';
19 import 'package:kernel/kernel.dart' hide Source; 15 import 'package:kernel/kernel.dart' hide Source;
20 16
21 dynamic unimplemented() { 17 dynamic unimplemented() {
22 // TODO(paulberry): get rid of this. 18 // TODO(paulberry): get rid of this.
23 throw new UnimplementedError(); 19 throw new UnimplementedError();
24 } 20 }
25 21
26 DartOptions _convertOptions(ProcessedOptions options) {
27 // TODO(paulberry): make sure options.compileSdk is handled correctly.
28 return new DartOptions(
29 strongMode: true, // TODO(paulberry): options.strongMode,
30 sdk: null, // TODO(paulberry): _uriToPath(options.sdkRoot, options),
31 sdkSummary:
32 null, // TODO(paulberry): options.compileSdk ? null : _uriToPath(optio ns.sdkSummary, options),
33 packagePath:
34 null, // TODO(paulberry): _uriToPath(options.packagesFileUri, options) ,
35 declaredVariables: null // TODO(paulberry): options.declaredVariables
36 );
37 }
38
39 /// Implementation of [IncrementalKernelGenerator]. 22 /// Implementation of [IncrementalKernelGenerator].
40 /// 23 ///
24 /// TODO(scheglov) Update the documentation.
25 ///
41 /// Theory of operation: an instance of [IncrementalResolvedAstGenerator] is 26 /// Theory of operation: an instance of [IncrementalResolvedAstGenerator] is
42 /// used to obtain resolved ASTs, and these are fed into kernel code generation 27 /// used to obtain resolved ASTs, and these are fed into kernel code generation
43 /// logic. 28 /// logic.
44 ///
45 /// Note that the kernel doesn't expect to take resolved ASTs as a direct input;
46 /// it expects to request resolved ASTs from an [AnalysisContext]. To deal with
47 /// this, we create [_AnalysisContextProxy] which returns the resolved ASTs when
48 /// requested. TODO(paulberry): Make this unnecessary.
49 class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator { 29 class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator {
50 final IncrementalResolvedAstGenerator _resolvedAstGenerator; 30 /// The URI of the program entry point.
51 final ProcessedOptions _options; 31 final Uri _entryPoint;
52 32
53 IncrementalKernelGeneratorImpl(Uri source, ProcessedOptions options) 33 /// The compiler options, such as the [FileSystem], the SDK dill location,
54 : _resolvedAstGenerator = 34 final CompilerOptions _options;
55 new IncrementalResolvedAstGeneratorImpl(source, options), 35
56 _options = options; 36 /// The object that knows how to translate URIs in Dart files into the
37 /// file system URIs.
38 TranslateUri _uriTranslator;
39
40 /// The cached SDK kernel.
41 DillTarget _sdkDillTarget;
42
43 IncrementalKernelGeneratorImpl(this._entryPoint, this._options);
57 44
58 @override 45 @override
59 Future<DeltaProgram> computeDelta( 46 Future<DeltaProgram> computeDelta(
60 {Future<Null> watch(Uri uri, bool used)}) async { 47 {Future<Null> watch(Uri uri, bool used)}) async {
61 var deltaLibraries = await _resolvedAstGenerator.computeDelta(); 48 // TODO(scheglov) Should we move `TranslateUri` creation outside
62 var kernelOptions = _convertOptions(_options); 49 // of this class and make it an option or a parameter of the generator?
63 var packages = null; // TODO(paulberry) 50 // Maybe rework and restore ProcessedOptions?
Paul Berry 2017/05/07 14:17:40 Moving creation of TranslateUri to ProcessedOption
scheglov 2017/05/07 17:38:49 Done.
64 var kernels = <Uri, Program>{}; 51 _uriTranslator ??= await TranslateUri.parse(
65 for (Uri uri in deltaLibraries.newState.keys) { 52 _options.fileSystem, null, _options.packagesFileUri);
66 // The kernel generation code doesn't currently support building a kernel 53 _uriTranslator.dartLibraries.addAll(_options.dartLibraries);
67 // directly from resolved ASTs--it wants to query an analysis context. So 54
68 // we provide it with a proxy analysis context that feeds it the resolved 55 DillTarget sdkTarget = await _getSdkDillTarget();
69 // ASTs. 56 // TODO(scheglov) Use it to also serve other package kernels.
70 var strongMode = true; // TODO(paulberry): set this correctly 57
71 var analysisOptions = new _AnalysisOptionsProxy(strongMode); 58 KernelTarget kernelTarget = new KernelTarget(_options.fileSystem, sdkTarget,
72 var context = 59 _uriTranslator, _options.strongMode, null);
73 new _AnalysisContextProxy(deltaLibraries.newState, analysisOptions); 60 kernelTarget.read(_entryPoint);
74 var program = new Program(); 61
75 var loader = 62 // TODO(scheglov) Replace with a better API.
76 new DartLoader(program, kernelOptions, packages, context: context); 63 // Firstly, we don't "write" anything here.
77 loader.loadLibrary(uri); 64 // Secondly, it catches all the exceptions and write them to `stderr`.
78 kernels[uri] = program; 65 // This is too interactive and not API-clients friendly.
79 // TODO(paulberry) rework watch invocation to eliminate race condition, 66 await kernelTarget.writeOutline(null);
80 // include part source files, and prevent watch from being a bottleneck 67
81 if (watch != null) await watch(uri, true); 68 // TODO(scheglov) Replace with a better API.
82 } 69 Program program = await kernelTarget.writeProgram(null);
83 // TODO(paulberry) invoke watch with used=false for each unused source 70 return new DeltaProgram({_entryPoint: program});
84 return new DeltaProgram(kernels);
85 } 71 }
86 72
87 @override 73 @override
88 void invalidate(String path) => _resolvedAstGenerator.invalidate(path); 74 void invalidate(String path) => unimplemented();
89 75
90 @override 76 @override
91 void invalidateAll() => _resolvedAstGenerator.invalidateAll(); 77 void invalidateAll() => unimplemented();
92 }
93 78
94 class _AnalysisContextProxy implements AnalysisContext { 79 /// Return the [DillTarget] that is used inside of [KernelTarget] to
95 final Map<Uri, Map<Uri, CompilationUnit>> _resolvedLibraries; 80 /// resynthesize SDK libraries.
96 81 Future<DillTarget> _getSdkDillTarget() async {
97 @override 82 if (_sdkDillTarget == null) {
98 final _SourceFactoryProxy sourceFactory = new _SourceFactoryProxy(); 83 _sdkDillTarget =
99 84 new DillTarget(new Ticker(isVerbose: false), _uriTranslator);
100 @override 85 // TODO(scheglov) Read the SDK kernel.
101 final AnalysisOptions analysisOptions; 86 // _sdkDillTarget.read(options.sdkSummary);
102 87 // await _sdkDillTarget.writeOutline(null);
103 _AnalysisContextProxy(this._resolvedLibraries, this.analysisOptions); 88 } else {
104 89 // Program sdkProgram = _sdkDillTarget.loader.program;
105 List<AnalysisError> computeErrors(Source source) { 90 // sdkProgram.visitChildren(new _ClearCanonicalNamesVisitor());
106 // TODO(paulberry): do we need to return errors sometimes? 91 }
107 return []; 92 return _sdkDillTarget;
108 }
109
110 LibraryElement computeLibraryElement(Source source) {
111 assert(_resolvedLibraries.containsKey(source.uri));
112 return resolutionMap
113 .elementDeclaredByCompilationUnit(
114 _resolvedLibraries[source.uri][source.uri])
115 .library;
116 }
117
118 noSuchMethod(Invocation invocation) => unimplemented();
119
120 CompilationUnit resolveCompilationUnit(
121 Source unitSource, LibraryElement library) {
122 var unit = _resolvedLibraries[library.source.uri][unitSource.uri];
123 assert(unit != null);
124 return unit;
125 } 93 }
126 } 94 }
127 95
128 class _AnalysisOptionsProxy implements AnalysisOptions { 96 ///// Clears canonical names of [NamedNode] references.
129 final bool strongMode; 97 //class _ClearCanonicalNamesVisitor extends Visitor {
130 98 // defaultNode(Node node) {
131 _AnalysisOptionsProxy(this.strongMode); 99 // if (node is NamedNode) {
132 100 // node.reference.canonicalName = null;
133 noSuchMethod(Invocation invocation) => unimplemented(); 101 // }
134 } 102 // node.visitChildren(this);
135 103 // }
136 class _SourceFactoryProxy implements SourceFactory { 104 //}
137 Source forUri2(Uri absoluteUri) => new _SourceProxy(absoluteUri);
138
139 noSuchMethod(Invocation invocation) => unimplemented();
140 }
141
142 class _SourceProxy extends BasicSource {
143 _SourceProxy(Uri uri) : super(uri);
144
145 noSuchMethod(Invocation invocation) => unimplemented();
146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698