| OLD | NEW |
| 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 import 'dart:io'; | 6 import 'dart:io'; |
| 7 | 7 |
| 8 import 'package:front_end/file_system.dart'; | 8 import 'package:front_end/file_system.dart'; |
| 9 import 'package:front_end/incremental_kernel_generator.dart'; | 9 import 'package:front_end/incremental_kernel_generator.dart'; |
| 10 import 'package:front_end/incremental_resolved_ast_generator.dart'; | 10 import 'package:front_end/incremental_resolved_ast_generator.dart'; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 signatureBuilder.addString(file.uri.toString()); | 152 signatureBuilder.addString(file.uri.toString()); |
| 153 // TODO(scheglov) use API signature | 153 // TODO(scheglov) use API signature |
| 154 signatureBuilder.addBytes(file.contentHash); | 154 signatureBuilder.addBytes(file.contentHash); |
| 155 } | 155 } |
| 156 signature = signatureBuilder.toHex(); | 156 signature = signatureBuilder.toHex(); |
| 157 } | 157 } |
| 158 | 158 |
| 159 _logger.writeln('Signature: $signature.'); | 159 _logger.writeln('Signature: $signature.'); |
| 160 String kernelKey = '$signature.kernel'; | 160 String kernelKey = '$signature.kernel'; |
| 161 | 161 |
| 162 /// We need kernel libraries for these URIs. | 162 // We need kernel libraries for these URIs. |
| 163 Set<Uri> libraryUris = new Set<Uri>(); | 163 Set<Uri> libraryUris = new Set<Uri>(); |
| 164 Map<Uri, FileState> libraryUriToFile = {}; | 164 Map<Uri, FileState> libraryUriToFile = {}; |
| 165 for (FileState library in cycle.libraries) { | 165 for (FileState library in cycle.libraries) { |
| 166 Uri uri = library.uri; | 166 Uri uri = library.uri; |
| 167 libraryUris.add(uri); | 167 libraryUris.add(uri); |
| 168 libraryUriToFile[uri] = library; | 168 libraryUriToFile[uri] = library; |
| 169 } | 169 } |
| 170 | 170 |
| 171 /// Check if there is already a bundle with these libraries. | 171 Future<Null> appendNewDillLibraries(Program program) async { |
| 172 List<DillLibraryBuilder> libraryBuilders = dillTarget.loader |
| 173 .appendLibraries(program, (uri) => libraryUris.contains(uri)); |
| 174 |
| 175 // Compute local scopes. |
| 176 await dillTarget.writeOutline(null); |
| 177 |
| 178 // Compute export scopes. |
| 179 _computeExportScopes(dillTarget, libraryUriToFile, libraryBuilders); |
| 180 } |
| 181 |
| 182 // Check if there is already a bundle with these libraries. |
| 172 List<int> bytes = _byteStore.get(kernelKey); | 183 List<int> bytes = _byteStore.get(kernelKey); |
| 173 if (bytes != null) { | 184 if (bytes != null) { |
| 174 return _logger.run('Read serialized libraries', () { | 185 return _logger.runAsync('Read serialized libraries', () async { |
| 175 var program = new Program(nameRoot: nameRoot); | 186 var program = new Program(nameRoot: nameRoot); |
| 176 var reader = new BinaryBuilder(bytes); | 187 var reader = new BinaryBuilder(bytes); |
| 177 reader.readProgram(program); | 188 reader.readProgram(program); |
| 178 | 189 |
| 179 List<DillLibraryBuilder> libraryBuilders = dillTarget.loader | 190 await appendNewDillLibraries(program); |
| 180 .appendLibraries(program, (uri) => libraryUris.contains(uri)); | |
| 181 _computeExportScopes(dillTarget, libraryUriToFile, libraryBuilders); | |
| 182 | 191 |
| 183 return new _LibraryCycleResult(cycle, signature, program.libraries); | 192 return new _LibraryCycleResult(cycle, signature, program.libraries); |
| 184 }); | 193 }); |
| 185 } | 194 } |
| 186 | 195 |
| 187 // Ask DILL to fill outlines using loaded libraries. | |
| 188 await dillTarget.writeOutline(null); | |
| 189 | |
| 190 // Create KernelTarget and configure it for compiling the cycle URIs. | 196 // Create KernelTarget and configure it for compiling the cycle URIs. |
| 191 KernelTarget kernelTarget = new KernelTarget(_fsState.fileSystemView, | 197 KernelTarget kernelTarget = new KernelTarget(_fsState.fileSystemView, |
| 192 dillTarget, _uriTranslator, _options.strongMode); | 198 dillTarget, _uriTranslator, _options.strongMode); |
| 193 for (FileState library in cycle.libraries) { | 199 for (FileState library in cycle.libraries) { |
| 194 kernelTarget.read(library.uri); | 200 kernelTarget.read(library.uri); |
| 195 } | 201 } |
| 196 | 202 |
| 197 // Compile the cycle libraries into a new full program. | 203 // Compile the cycle libraries into a new full program. |
| 198 Program program = await _logger.runAsync( | 204 Program program = await _logger |
| 199 'Compile ${cycle.libraries.length} cycle libraries', () async { | 205 .runAsync('Compile ${cycle.libraries.length} libraries', () async { |
| 200 await kernelTarget.writeOutline(null, nameRoot: nameRoot); | 206 await kernelTarget.writeOutline(null, nameRoot: nameRoot); |
| 201 return await kernelTarget.writeProgram(null); | 207 return await kernelTarget.writeProgram(null); |
| 202 }); | 208 }); |
| 203 | 209 |
| 204 // Add newly compiled libraries into DILL. | 210 // Add newly compiled libraries into DILL. |
| 211 await appendNewDillLibraries(program); |
| 212 |
| 205 List<Library> kernelLibraries = program.libraries | 213 List<Library> kernelLibraries = program.libraries |
| 206 .where((library) => libraryUris.contains(library.importUri)) | 214 .where((library) => libraryUris.contains(library.importUri)) |
| 207 .toList(); | 215 .toList(); |
| 208 List<DillLibraryBuilder> libraryBuilders = dillTarget.loader | |
| 209 .appendLibraries(program, (uri) => libraryUris.contains(uri)); | |
| 210 _computeExportScopes(dillTarget, libraryUriToFile, libraryBuilders); | |
| 211 | 216 |
| 212 _logger.run('Serialize ${kernelLibraries.length} libraries', () { | 217 _logger.run('Serialize ${kernelLibraries.length} libraries', () { |
| 213 program.unbindCanonicalNames(); | 218 program.unbindCanonicalNames(); |
| 214 List<int> bytes = _writeProgramBytes(program, kernelLibraries.contains); | 219 List<int> bytes = _writeProgramBytes(program, kernelLibraries.contains); |
| 215 _byteStore.put(kernelKey, bytes); | 220 _byteStore.put(kernelKey, bytes); |
| 216 _logger.writeln('Stored ${bytes.length} bytes.'); | 221 _logger.writeln('Stored ${bytes.length} bytes.'); |
| 217 }); | 222 }); |
| 218 | 223 |
| 219 return new _LibraryCycleResult(cycle, signature, kernelLibraries); | 224 return new _LibraryCycleResult(cycle, signature, kernelLibraries); |
| 220 }); | 225 }); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 /// TODO(scheglov) Use API signatures. | 284 /// TODO(scheglov) Use API signatures. |
| 280 /// TODO(scheglov) Or use tree shaking and compute signatures of outlines. | 285 /// TODO(scheglov) Or use tree shaking and compute signatures of outlines. |
| 281 final String signature; | 286 final String signature; |
| 282 | 287 |
| 283 /// Kernel libraries for libraries in the [cycle]. Dependencies are not | 288 /// Kernel libraries for libraries in the [cycle]. Dependencies are not |
| 284 /// included, they were returned as results for preceding cycles. | 289 /// included, they were returned as results for preceding cycles. |
| 285 final List<Library> kernelLibraries; | 290 final List<Library> kernelLibraries; |
| 286 | 291 |
| 287 _LibraryCycleResult(this.cycle, this.signature, this.kernelLibraries); | 292 _LibraryCycleResult(this.cycle, this.signature, this.kernelLibraries); |
| 288 } | 293 } |
| OLD | NEW |