Chromium Code Reviews| 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 | 6 |
| 7 import 'package:front_end/incremental_kernel_generator.dart'; | 7 import 'package:front_end/incremental_kernel_generator.dart'; |
| 8 import 'package:front_end/src/base/performace_logger.dart'; | 8 import 'package:front_end/src/base/performace_logger.dart'; |
| 9 import 'package:front_end/src/base/processed_options.dart'; | 9 import 'package:front_end/src/base/processed_options.dart'; |
| 10 import 'package:front_end/src/fasta/uri_translator.dart'; | 10 import 'package:front_end/src/fasta/uri_translator.dart'; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 | 29 |
| 30 /// The URI of the program entry point. | 30 /// The URI of the program entry point. |
| 31 final Uri _entryPoint; | 31 final Uri _entryPoint; |
| 32 | 32 |
| 33 /// The function to notify when files become used or unused, or `null`. | 33 /// The function to notify when files become used or unused, or `null`. |
| 34 final WatchUsedFilesFn _watchFn; | 34 final WatchUsedFilesFn _watchFn; |
| 35 | 35 |
| 36 /// The [KernelDriver] that is used to compute kernels. | 36 /// The [KernelDriver] that is used to compute kernels. |
| 37 KernelDriver _driver; | 37 KernelDriver _driver; |
| 38 | 38 |
| 39 /// Latest compilation signatures produced by [computeDelta] for libraries. | 39 /// The current signatures for libraries. |
| 40 final Map<Uri, String> _latestSignature = {}; | 40 final Map<Uri, String> _currentSignatures = {}; |
| 41 | |
| 42 /// The signatures for libraries produced by the last [computeDelta], or | |
| 43 /// `null` if the last delta was either accepted or rejected. | |
| 44 Map<Uri, String> _lastSignatures; | |
| 41 | 45 |
| 42 /// The object that provides additional information for tests. | 46 /// The object that provides additional information for tests. |
| 43 _TestView _testView; | 47 _TestView _testView; |
| 44 | 48 |
| 45 IncrementalKernelGeneratorImpl(ProcessedOptions options, | 49 IncrementalKernelGeneratorImpl(ProcessedOptions options, |
| 46 UriTranslator uriTranslator, List<int> sdkOutlineBytes, this._entryPoint, | 50 UriTranslator uriTranslator, List<int> sdkOutlineBytes, this._entryPoint, |
| 47 {WatchUsedFilesFn watch}) | 51 {WatchUsedFilesFn watch}) |
| 48 : _logger = options.logger, | 52 : _logger = options.logger, |
| 49 _watchFn = watch { | 53 _watchFn = watch { |
| 50 _testView = new _TestView(this); | 54 _testView = new _TestView(this); |
| 51 | 55 |
| 52 Future<Null> onFileAdded(Uri uri) { | 56 Future<Null> onFileAdded(Uri uri) { |
| 53 if (_watchFn != null) { | 57 if (_watchFn != null) { |
| 54 return _watchFn(uri, true); | 58 return _watchFn(uri, true); |
| 55 } | 59 } |
| 56 return new Future.value(); | 60 return new Future.value(); |
| 57 } | 61 } |
| 58 | 62 |
| 59 _driver = new KernelDriver(options, uriTranslator, | 63 _driver = new KernelDriver(options, uriTranslator, |
| 60 sdkOutlineBytes: sdkOutlineBytes, fileAddedFn: onFileAdded); | 64 sdkOutlineBytes: sdkOutlineBytes, fileAddedFn: onFileAdded); |
| 61 } | 65 } |
| 62 | 66 |
| 63 /// Return the object that provides additional information for tests. | 67 /// Return the object that provides additional information for tests. |
| 64 @visibleForTesting | 68 @visibleForTesting |
| 65 _TestView get test => _testView; | 69 _TestView get test => _testView; |
| 66 | 70 |
| 67 @override | 71 @override |
| 72 void acceptLastDelta() { | |
| 73 _throwIfNoLastDelta(); | |
| 74 _currentSignatures.addAll(_lastSignatures); | |
| 75 _lastSignatures = null; | |
| 76 } | |
| 77 | |
| 78 @override | |
| 68 Future<DeltaProgram> computeDelta() async { | 79 Future<DeltaProgram> computeDelta() async { |
| 80 if (_lastSignatures != null) { | |
| 81 throw new StateError( | |
|
Siggi Cherem (dart-lang)
2017/08/10 18:31:15
question: instead of throwing, should we instead r
scheglov
2017/08/10 19:28:39
I don't know.
Outside of front_end I would use St
| |
| 82 'The last delta must be either accepted or rejected.'); | |
| 83 } | |
| 84 _lastSignatures = {}; | |
|
Siggi Cherem (dart-lang)
2017/08/10 18:31:15
it might be good to also enforce that accept/rejec
scheglov
2017/08/10 19:28:39
This is not a new contract, I will return to enfor
| |
| 85 | |
| 69 return await _logger.runAsync('Compute delta', () async { | 86 return await _logger.runAsync('Compute delta', () async { |
| 70 KernelResult kernelResult = await _driver.getKernel(_entryPoint); | 87 KernelResult kernelResult = await _driver.getKernel(_entryPoint); |
| 71 List<LibraryCycleResult> results = kernelResult.results; | 88 List<LibraryCycleResult> results = kernelResult.results; |
| 72 | 89 |
| 73 // The file graph might have changed, perform GC. | 90 // The file graph might have changed, perform GC. |
| 74 await _gc(); | 91 await _gc(); |
| 75 | 92 |
| 76 // The set of affected library cycles (have different signatures). | 93 // The set of affected library cycles (have different signatures). |
| 77 final affectedLibraryCycles = new Set<LibraryCycle>(); | 94 final affectedLibraryCycles = new Set<LibraryCycle>(); |
| 78 for (LibraryCycleResult result in results) { | 95 for (LibraryCycleResult result in results) { |
| 79 for (Library library in result.kernelLibraries) { | 96 for (Library library in result.kernelLibraries) { |
| 80 Uri uri = library.importUri; | 97 Uri uri = library.importUri; |
| 81 if (_latestSignature[uri] != result.signature) { | 98 if (_currentSignatures[uri] != result.signature) { |
| 82 _latestSignature[uri] = result.signature; | 99 _lastSignatures[uri] = result.signature; |
| 83 affectedLibraryCycles.add(result.cycle); | 100 affectedLibraryCycles.add(result.cycle); |
| 84 } | 101 } |
| 85 } | 102 } |
| 86 } | 103 } |
| 87 | 104 |
| 88 // The set of affected library cycles (have different signatures), | 105 // The set of affected library cycles (have different signatures), |
| 89 // or libraries that import or export affected libraries (so VM might | 106 // or libraries that import or export affected libraries (so VM might |
| 90 // have inlined some code from affected libraries into them). | 107 // have inlined some code from affected libraries into them). |
| 91 final vmRequiredLibraryCycles = new Set<LibraryCycle>(); | 108 final vmRequiredLibraryCycles = new Set<LibraryCycle>(); |
| 92 | 109 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 123 | 140 |
| 124 return new DeltaProgram(program); | 141 return new DeltaProgram(program); |
| 125 }); | 142 }); |
| 126 } | 143 } |
| 127 | 144 |
| 128 @override | 145 @override |
| 129 void invalidate(Uri uri) { | 146 void invalidate(Uri uri) { |
| 130 _driver.invalidate(uri); | 147 _driver.invalidate(uri); |
| 131 } | 148 } |
| 132 | 149 |
| 150 @override | |
| 151 void rejectLastDelta() { | |
| 152 _throwIfNoLastDelta(); | |
| 153 _lastSignatures = null; | |
| 154 } | |
| 155 | |
| 133 /// TODO(scheglov) document | 156 /// TODO(scheglov) document |
| 134 Future<Null> _gc() async { | 157 Future<Null> _gc() async { |
| 135 var removedFiles = _driver.fsState.gc(_entryPoint); | 158 var removedFiles = _driver.fsState.gc(_entryPoint); |
| 136 if (removedFiles.isNotEmpty && _watchFn != null) { | 159 if (removedFiles.isNotEmpty && _watchFn != null) { |
| 137 for (var removedFile in removedFiles) { | 160 for (var removedFile in removedFiles) { |
| 138 await _watchFn(removedFile.fileUri, false); | 161 await _watchFn(removedFile.fileUri, false); |
| 139 } | 162 } |
| 140 } | 163 } |
| 141 } | 164 } |
| 165 | |
| 166 /// Throw [StateError] if [_lastSignatures] is `null`, i.e. there is no | |
| 167 /// last delta - it either has not been computed yet, or has been already | |
| 168 /// accepted or rejected. | |
| 169 void _throwIfNoLastDelta() { | |
| 170 if (_lastSignatures == null) { | |
| 171 throw new StateError( | |
| 172 'The last delta has been already accepted or rejected.'); | |
|
Siggi Cherem (dart-lang)
2017/08/10 18:31:15
same question: report or throw?
| |
| 173 } | |
| 174 } | |
| 142 } | 175 } |
| 143 | 176 |
| 144 @visibleForTesting | 177 @visibleForTesting |
| 145 class _TestView { | 178 class _TestView { |
| 146 final IncrementalKernelGeneratorImpl _generator; | 179 final IncrementalKernelGeneratorImpl _generator; |
| 147 | 180 |
| 148 _TestView(this._generator); | 181 _TestView(this._generator); |
| 149 | 182 |
| 150 /// The [KernelDriver] that is used to actually compile. | 183 /// The [KernelDriver] that is used to actually compile. |
| 151 KernelDriver get driver => _generator._driver; | 184 KernelDriver get driver => _generator._driver; |
| 152 } | 185 } |
| OLD | NEW |