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.library_updater; | 5 library dart2js_incremental.library_updater; |
6 | 6 |
7 import 'dart:async' show | 7 import 'dart:async' show |
8 Future; | 8 Future; |
9 | 9 |
10 import 'dart:convert' show | 10 import 'dart:convert' show |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 /// Used as tear-off passed to [LibraryLoaderTask.resetAsync]. | 79 /// Used as tear-off passed to [LibraryLoaderTask.resetAsync]. |
80 Future<bool> reuseLibrary(LibraryElement library) { | 80 Future<bool> reuseLibrary(LibraryElement library) { |
81 assert(compiler != null); | 81 assert(compiler != null); |
82 if (library.isPlatformLibrary || library.isPackageLibrary) { | 82 if (library.isPlatformLibrary || library.isPackageLibrary) { |
83 logTime('Reusing $library.'); | 83 logTime('Reusing $library.'); |
84 return new Future.value(true); | 84 return new Future.value(true); |
85 } else if (library != compiler.mainApp) { | 85 } else if (library != compiler.mainApp) { |
86 return new Future.value(false); | 86 return new Future.value(false); |
87 } | 87 } |
88 return inputProvider(uri).then((List<int> bytes) { | 88 return inputProvider(uri).then((bytes) { |
89 return canReuseLibrary(library, bytes); | 89 return canReuseLibrary(library, bytes); |
90 }); | 90 }); |
91 } | 91 } |
92 | 92 |
93 /// Returns true if [library] can be reused. | 93 /// Returns true if [library] can be reused. |
94 /// | 94 /// |
95 /// This methods also computes the [updates] (patches) needed to have | 95 /// This methods also computes the [updates] (patches) needed to have |
96 /// [library] reflect the modifications in [bytes]. | 96 /// [library] reflect the modifications in [bytes]. |
97 bool canReuseLibrary(LibraryElement library, List<int> bytes) { | 97 bool canReuseLibrary(LibraryElement library, bytes) { |
98 logTime('Attempting to reuse mainApp.'); | 98 logTime('Attempting to reuse mainApp.'); |
99 String newSource = UTF8.decode(bytes); | 99 String newSource = bytes is String ? bytes : UTF8.decode(bytes); |
100 logTime('Decoded UTF8'); | 100 logTime('Decoded UTF8'); |
101 | 101 |
102 // TODO(ahe): Can't use compiler.mainApp in general. | 102 // TODO(ahe): Can't use compiler.mainApp in general. |
103 if (false && newSource == compiler.mainApp.compilationUnit.script.text) { | 103 if (false && newSource == compiler.mainApp.compilationUnit.script.text) { |
104 // TODO(ahe): Need to update the compilationUnit's source code when | 104 // TODO(ahe): Need to update the compilationUnit's source code when |
105 // doing incremental analysis for this to work. | 105 // doing incremental analysis for this to work. |
106 logTime("Source didn't change"); | 106 logTime("Source didn't change"); |
107 return true; | 107 return true; |
108 } | 108 } |
109 | 109 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 updates.add(new FunctionUpdate(compiler, before, after)); | 181 updates.add(new FunctionUpdate(compiler, before, after)); |
182 return true; | 182 return true; |
183 } | 183 } |
184 | 184 |
185 List<Element> applyUpdates() { | 185 List<Element> applyUpdates() { |
186 return updates.map((Update update) => update.apply()).toList(); | 186 return updates.map((Update update) => update.apply()).toList(); |
187 } | 187 } |
188 | 188 |
189 String computeUpdateJs() { | 189 String computeUpdateJs() { |
190 List<Element> updatedElements = applyUpdates(); | 190 List<Element> updatedElements = applyUpdates(); |
191 compiler.progress.reset(); | 191 if (compiler.progress != null) { |
| 192 compiler.progress.reset(); |
| 193 } |
192 for (Element element in updatedElements) { | 194 for (Element element in updatedElements) { |
193 compiler.enqueuer.resolution.addToWorkList(element); | 195 compiler.enqueuer.resolution.addToWorkList(element); |
194 } | 196 } |
195 compiler.processQueue(compiler.enqueuer.resolution, null); | 197 compiler.processQueue(compiler.enqueuer.resolution, null); |
196 | 198 |
197 compiler.phase = Compiler.PHASE_DONE_RESOLVING; | 199 compiler.phase = Compiler.PHASE_DONE_RESOLVING; |
198 | 200 |
199 for (Element element in updatedElements) { | 201 for (Element element in updatedElements) { |
200 compiler.enqueuer.codegen.addToWorkList(element); | 202 compiler.enqueuer.codegen.addToWorkList(element); |
201 } | 203 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 before.getOrSet = after.getOrSet; | 283 before.getOrSet = after.getOrSet; |
282 } | 284 } |
283 | 285 |
284 /// Reset various caches and remove this element from the compiler's internal | 286 /// Reset various caches and remove this element from the compiler's internal |
285 /// state. | 287 /// state. |
286 void reuseElement() { | 288 void reuseElement() { |
287 compiler.forgetElement(before); | 289 compiler.forgetElement(before); |
288 before.reuseElement(); | 290 before.reuseElement(); |
289 } | 291 } |
290 } | 292 } |
OLD | NEW |