OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library dart2js_incremental; | 5 library dart2js_incremental; |
6 | 6 |
7 import 'dart:async' show | 7 import 'dart:async' show |
8 Future; | 8 Future; |
9 | 9 |
10 import 'dart:profiler' show | 10 import 'dart:profiler' show |
(...skipping 11 matching lines...) Expand all Loading... |
22 import 'package:compiler/src/dart2jslib.dart' show | 22 import 'package:compiler/src/dart2jslib.dart' show |
23 NullSink; | 23 NullSink; |
24 | 24 |
25 import 'package:compiler/src/js_backend/js_backend.dart' show | 25 import 'package:compiler/src/js_backend/js_backend.dart' show |
26 JavaScriptBackend; | 26 JavaScriptBackend; |
27 | 27 |
28 import 'package:compiler/src/elements/elements.dart' show | 28 import 'package:compiler/src/elements/elements.dart' show |
29 LibraryElement; | 29 LibraryElement; |
30 | 30 |
31 import 'library_updater.dart' show | 31 import 'library_updater.dart' show |
| 32 IncrementalCompilerContext, |
32 LibraryUpdater, | 33 LibraryUpdater, |
33 Logger; | 34 Logger; |
34 | 35 |
35 import 'package:compiler/src/js/js.dart' as jsAst; | 36 import 'package:compiler/src/js/js.dart' as jsAst; |
36 | 37 |
37 part 'caching_compiler.dart'; | 38 part 'caching_compiler.dart'; |
38 | 39 |
39 const List<String> INCREMENTAL_OPTIONS = const <String>[ | 40 const List<String> INCREMENTAL_OPTIONS = const <String>[ |
40 '--disable-type-inference', | 41 '--disable-type-inference', |
41 '--incremental-support', | 42 '--incremental-support', |
42 '--no-source-maps', // TODO(ahe): Remove this. | 43 '--no-source-maps', // TODO(ahe): Remove this. |
43 ]; | 44 ]; |
44 | 45 |
45 class IncrementalCompiler { | 46 class IncrementalCompiler { |
46 final Uri libraryRoot; | 47 final Uri libraryRoot; |
47 final Uri packageRoot; | 48 final Uri packageRoot; |
48 final CompilerInputProvider inputProvider; | 49 final CompilerInputProvider inputProvider; |
49 final DiagnosticHandler diagnosticHandler; | 50 final DiagnosticHandler diagnosticHandler; |
50 final List<String> options; | 51 final List<String> options; |
51 final CompilerOutputProvider outputProvider; | 52 final CompilerOutputProvider outputProvider; |
52 final Map<String, dynamic> environment; | 53 final Map<String, dynamic> environment; |
53 final List<String> _updates = <String>[]; | 54 final List<String> _updates = <String>[]; |
| 55 final IncrementalCompilerContext _context = new IncrementalCompilerContext(); |
54 | 56 |
55 Compiler _compiler; | 57 Compiler _compiler; |
56 | 58 |
57 bool get compilerWasCancelled => _compiler.compilerWasCancelled; | 59 bool get compilerWasCancelled => _compiler.compilerWasCancelled; |
58 | 60 |
59 IncrementalCompiler({ | 61 IncrementalCompiler({ |
60 this.libraryRoot, | 62 this.libraryRoot, |
61 this.packageRoot, | 63 this.packageRoot, |
62 this.inputProvider, | 64 this.inputProvider, |
63 this.diagnosticHandler, | 65 this.diagnosticHandler, |
64 this.options, | 66 this.options, |
65 this.outputProvider, | 67 this.outputProvider, |
66 this.environment}) { | 68 this.environment}) { |
67 if (libraryRoot == null) { | 69 if (libraryRoot == null) { |
68 throw new ArgumentError('libraryRoot is null.'); | 70 throw new ArgumentError('libraryRoot is null.'); |
69 } | 71 } |
70 if (inputProvider == null) { | 72 if (inputProvider == null) { |
71 throw new ArgumentError('inputProvider is null.'); | 73 throw new ArgumentError('inputProvider is null.'); |
72 } | 74 } |
73 if (diagnosticHandler == null) { | 75 if (diagnosticHandler == null) { |
74 throw new ArgumentError('diagnosticHandler is null.'); | 76 throw new ArgumentError('diagnosticHandler is null.'); |
75 } | 77 } |
| 78 _context.incrementalCompiler = this; |
76 } | 79 } |
77 | 80 |
78 LibraryElement get mainApp => _compiler.mainApp; | 81 LibraryElement get mainApp => _compiler.mainApp; |
79 | 82 |
80 Compiler get compiler => _compiler; | 83 Compiler get compiler => _compiler; |
81 | 84 |
82 Future<bool> compile(Uri script) { | 85 Future<bool> compile(Uri script) { |
83 return _reuseCompiler(null).then((Compiler compiler) { | 86 return _reuseCompiler(null).then((Compiler compiler) { |
84 _compiler = compiler; | 87 _compiler = compiler; |
85 return compiler.run(script); | 88 return compiler.run(script); |
(...skipping 27 matching lines...) Expand all Loading... |
113 if (logVerbose == null) { | 116 if (logVerbose == null) { |
114 logVerbose = (_) {}; | 117 logVerbose = (_) {}; |
115 } | 118 } |
116 Future mappingInputProvider(Uri uri) { | 119 Future mappingInputProvider(Uri uri) { |
117 Uri updatedFile = updatedFiles[uri]; | 120 Uri updatedFile = updatedFiles[uri]; |
118 return inputProvider(updatedFile == null ? uri : updatedFile); | 121 return inputProvider(updatedFile == null ? uri : updatedFile); |
119 } | 122 } |
120 LibraryUpdater updater = new LibraryUpdater( | 123 LibraryUpdater updater = new LibraryUpdater( |
121 _compiler, | 124 _compiler, |
122 mappingInputProvider, | 125 mappingInputProvider, |
123 _compiler.mainApp.canonicalUri, | |
124 logTime, | 126 logTime, |
125 logVerbose); | 127 logVerbose, |
| 128 _context); |
| 129 _context.registerUriWithUpdates(updatedFiles.keys); |
126 Future<Compiler> future = _reuseCompiler(updater.reuseLibrary); | 130 Future<Compiler> future = _reuseCompiler(updater.reuseLibrary); |
127 return future.then((Compiler compiler) { | 131 return future.then((Compiler compiler) { |
128 _compiler = compiler; | 132 _compiler = compiler; |
129 if (compiler.compilationFailed) { | 133 if (compiler.compilationFailed) { |
130 return null; | 134 return null; |
131 } else { | 135 } else { |
132 String update = updater.computeUpdateJs(); | 136 String update = updater.computeUpdateJs(); |
133 _updates.add(update); | 137 _updates.add(update); |
134 return update; | 138 return update; |
135 } | 139 } |
136 }); | 140 }); |
137 } | 141 } |
138 | 142 |
139 String allUpdates() { | 143 String allUpdates() { |
140 jsAst.Node updates = jsAst.js.escapedString(_updates.join("")); | 144 jsAst.Node updates = jsAst.js.escapedString(_updates.join("")); |
141 | 145 |
142 jsAst.FunctionDeclaration mainRunner = jsAst.js.statement(r""" | 146 jsAst.FunctionDeclaration mainRunner = jsAst.js.statement(r""" |
143 function dartMainRunner(main, args) { | 147 function dartMainRunner(main, args) { |
144 $dart_unsafe_eval.patch(#); | 148 $dart_unsafe_eval.patch(#); |
145 return main(args); | 149 return main(args); |
146 }""", updates); | 150 }""", updates); |
147 | 151 |
148 | 152 |
149 jsAst.Printer printer = new jsAst.Printer(_compiler, null); | 153 jsAst.Printer printer = new jsAst.Printer(_compiler, null); |
150 printer.blockOutWithoutBraces(mainRunner); | 154 printer.blockOutWithoutBraces(mainRunner); |
151 return printer.outBuffer.getText(); | 155 return printer.outBuffer.getText(); |
152 } | 156 } |
153 } | 157 } |
OLD | NEW |