| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import 'dart:async'; | |
| 6 | |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | |
| 8 import 'package:front_end/src/base/processed_options.dart'; | |
| 9 import 'package:front_end/src/incremental_resolved_ast_generator_impl.dart'; | |
| 10 | |
| 11 import 'compiler_options.dart'; | |
| 12 | |
| 13 /// Represents the difference between "old" and "new" states of a program. | |
| 14 /// | |
| 15 /// Not intended to be implemented or extended by clients. | |
| 16 class DeltaLibraries { | |
| 17 /// The new state of the program, as a two-layer map. | |
| 18 /// | |
| 19 /// The outer map key is the library URI. The inner map key is the | |
| 20 /// compilation unit (part) URI. The map values are the resolved compilation | |
| 21 /// units. | |
| 22 /// | |
| 23 /// Libraries whose resolved AST is known to be unchanged since the last | |
| 24 /// [DeltaLibraries] are not included. | |
| 25 final Map<Uri, Map<Uri, CompilationUnit>> newState; | |
| 26 | |
| 27 DeltaLibraries(this.newState); | |
| 28 | |
| 29 /// TODO(paulberry): add information about libraries that were removed. | |
| 30 } | |
| 31 | |
| 32 /// Interface for generating an initial resolved representation of a program and | |
| 33 /// keeping it up to date as incremental changes are made. | |
| 34 /// | |
| 35 /// This class maintains an internal "previous program state"; each | |
| 36 /// time [computeDelta] is called, it updates the previous program state and | |
| 37 /// produces a representation of what has changed. When there are few changes, | |
| 38 /// a call to [computeDelta] should be much faster than compiling the whole | |
| 39 /// program from scratch. | |
| 40 /// | |
| 41 /// This class also maintains a set of "valid sources", which is a (possibly | |
| 42 /// empty) subset of the sources constituting the previous program state. Files | |
| 43 /// in this set are assumed to be unchanged since the last call to | |
| 44 /// [computeDelta]. | |
| 45 /// | |
| 46 /// Behavior is undefined if the client does not obey the following concurrency | |
| 47 /// restrictions: | |
| 48 /// - no two invocations of [computeDelta] may be outstanding at any given time. | |
| 49 /// - neither [invalidate] nor [invalidateAll] may be called while an invocation | |
| 50 /// of [computeDelta] is outstanding. | |
| 51 /// | |
| 52 /// Not intended to be implemented or extended by clients. | |
| 53 abstract class IncrementalResolvedAstGenerator { | |
| 54 /// Creates an [IncrementalResolvedAstGenerator] which is prepared to generate | |
| 55 /// resolved ASTs for the program whose main library is in the given | |
| 56 /// [source]. | |
| 57 /// | |
| 58 /// No file system access is performed by this constructor; the initial | |
| 59 /// "previous program state" is an empty program containing no code, and the | |
| 60 /// initial set of valid sources is empty. To obtain a resolved AST | |
| 61 /// representation of the program, call [computeDelta]. | |
| 62 factory IncrementalResolvedAstGenerator( | |
| 63 Uri source, CompilerOptions options) => | |
| 64 new IncrementalResolvedAstGeneratorImpl( | |
| 65 source, new ProcessedOptions(options)); | |
| 66 | |
| 67 /// Generates a resolved AST representation of the changes to the program, | |
| 68 /// assuming that all valid sources are unchanged since the last call to | |
| 69 /// [computeDelta]. | |
| 70 /// | |
| 71 /// Source files in the set of valid sources are guaranteed not to be re-read | |
| 72 /// from disk; they are assumed to be unchanged regardless of the state of the | |
| 73 /// filesystem. | |
| 74 /// | |
| 75 /// If the future completes successfully, the previous file state is updated | |
| 76 /// and the set of valid sources is set to the set of all sources in the | |
| 77 /// program. | |
| 78 /// | |
| 79 /// If the future completes with an error (due to errors in the compiled | |
| 80 /// source code), the caller may consider the previous file state and the set | |
| 81 /// of valid sources to be unchanged; this means that once the user fixes the | |
| 82 /// errors, it is safe to call [computeDelta] again. | |
| 83 Future<DeltaLibraries> computeDelta(); | |
| 84 | |
| 85 /// Remove any source file(s) associated with the given file path from the set | |
| 86 /// of valid sources. This guarantees that those files will be re-read on the | |
| 87 /// next call to [computeDelta]). | |
| 88 void invalidate(String path); | |
| 89 | |
| 90 /// Remove all source files from the set of valid sources. This guarantees | |
| 91 /// that all files will be re-read on the next call to [computeDelta]. | |
| 92 /// | |
| 93 /// Note that this does not erase the previous program state; the next time | |
| 94 /// [computeDelta] is called, if parts of the program are discovered to be | |
| 95 /// unchanged, parts of the previous program state will still be re-used to | |
| 96 /// speed up compilation. | |
| 97 void invalidateAll(); | |
| 98 } | |
| OLD | NEW |