Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: pkg/front_end/lib/incremental_kernel_generator.dart

Issue 2996843002: Add IncrementalKernelGenerator.acceptLastDelta()/rejectLastDelta(). (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/src/base/processed_options.dart'; 7 import 'package:front_end/src/base/processed_options.dart';
8 import 'package:front_end/src/fasta/compiler_context.dart';
8 import 'package:front_end/src/incremental_kernel_generator_impl.dart'; 9 import 'package:front_end/src/incremental_kernel_generator_impl.dart';
9 import 'package:front_end/src/fasta/compiler_context.dart';
10 import 'package:kernel/kernel.dart'; 10 import 'package:kernel/kernel.dart';
11 11
12 import 'compiler_options.dart'; 12 import 'compiler_options.dart';
13 13
14 /// The type of the function that clients can pass to track used files. 14 /// The type of the function that clients can pass to track used files.
15 /// 15 ///
16 /// When a file is first used during compilation, this function is called with 16 /// When a file is first used during compilation, this function is called with
17 /// the [Uri] of that file and [used] == `true`. The content of the file is not 17 /// the [Uri] of that file and [used] == `true`. The content of the file is not
18 /// read until the [Future] returned by the function completes. If, during a 18 /// read until the [Future] returned by the function completes. If, during a
19 /// subsequent compilation, a file that was being used is no longer used, then 19 /// subsequent compilation, a file that was being used is no longer used, then
(...skipping 21 matching lines...) Expand all
41 final Program newProgram; 41 final Program newProgram;
42 42
43 DeltaProgram(this.newProgram); 43 DeltaProgram(this.newProgram);
44 44
45 /// TODO(paulberry): add information about libraries that were removed. 45 /// TODO(paulberry): add information about libraries that were removed.
46 } 46 }
47 47
48 /// Interface for generating an initial kernel representation of a program and 48 /// Interface for generating an initial kernel representation of a program and
49 /// keeping it up to date as incremental changes are made. 49 /// keeping it up to date as incremental changes are made.
50 /// 50 ///
51 /// This class maintains an internal "previous program state"; each 51 /// This class maintains an internal "current program state"; each time
52 /// time [computeDelta] is called, it updates the previous program state and 52 /// [computeDelta] is called, it computes the "last program state" and libraries
53 /// produces a representation of what has changed. When there are few changes, 53 /// that were affected relative to the "current program state". When there are
54 /// a call to [computeDelta] should be much faster than compiling the whole 54 /// few changes, a call to [computeDelta] should be much faster than compiling
55 /// program from scratch. 55 /// the whole program from scratch.
56 ///
57 /// Each invocation of [computeDelta] must follow by invocation of either
Paul Berry 2017/08/10 18:03:39 "must be followed by"
scheglov 2017/08/10 19:28:39 Done.
58 /// [acceptLastDelta] or [rejectLastDelta]. [acceptLastDelta] makes the
59 /// "last program state" the "current program state". [rejectLastDelta] simply
60 /// discards the "last program state", so that the "current program state"
61 /// stays the same.
56 /// 62 ///
57 /// This class also maintains a set of "valid sources", which is a (possibly 63 /// This class also maintains a set of "valid sources", which is a (possibly
58 /// empty) subset of the sources constituting the previous program state. Files 64 /// empty) subset of the sources constituting the previous program state. Files
59 /// in this set are assumed to be unchanged since the last call to 65 /// in this set are assumed to be unchanged since the last call to
60 /// [computeDelta]. 66 /// [computeDelta].
61 /// 67 ///
62 /// Behavior is undefined if the client does not obey the following concurrency 68 /// Behavior is undefined if the client does not obey the following concurrency
63 /// restrictions: 69 /// restrictions:
64 /// - no two invocations of [computeDelta] may be outstanding at any given time. 70 /// - no two invocations of [computeDelta] may be outstanding at any given time.
65 /// - neither [invalidate] nor [invalidateAll] may be called while an invocation 71 /// - [invalidate] may not be called while an invocation of [computeDelta] is
66 /// of [computeDelta] is outstanding. 72 /// outstanding.
67 /// 73 ///
68 /// Not intended to be implemented or extended by clients. 74 /// Not intended to be implemented or extended by clients.
69 abstract class IncrementalKernelGenerator { 75 abstract class IncrementalKernelGenerator {
76 /// Notify the generator that the last [DeltaProgram] returned from the
77 /// [computeDelta] was accepted. So, the "last program state" becomes the
78 /// "current program state", and the next invocation of [computeDelta] will
79 /// not include the libraries of the last delta, unless these libraries are
80 /// affected by [invalidate] since the last [computeDelta].
81 void acceptLastDelta();
82
70 /// Generates a kernel representation of the changes to the program, assuming 83 /// Generates a kernel representation of the changes to the program, assuming
71 /// that all valid sources are unchanged since the last call to 84 /// that all valid sources are unchanged since the last call to
72 /// [computeDelta]. 85 /// [computeDelta].
73 /// 86 ///
74 /// Source files in the set of valid sources are guaranteed not to be re-read 87 /// Source files in the set of valid sources are guaranteed not to be re-read
75 /// from disk; they are assumed to be unchanged regardless of the state of the 88 /// from disk; they are assumed to be unchanged regardless of the state of the
76 /// filesystem. 89 /// filesystem.
77 /// 90 ///
78 /// If the future completes successfully, the previous file state is updated 91 /// If the future completes successfully, the previous file state is updated
79 /// and the set of valid sources is set to the set of all sources in the 92 /// and the set of valid sources is set to the set of all sources in the
80 /// program. 93 /// program.
81 /// 94 ///
82 /// If the future completes with an error (due to errors in the compiled 95 /// If the future completes with an error (due to errors in the compiled
83 /// source code), the caller may consider the previous file state and the set 96 /// source code), the caller may consider the previous file state and the set
84 /// of valid sources to be unchanged; this means that once the user fixes the 97 /// of valid sources to be unchanged; this means that once the user fixes the
85 /// errors, it is safe to call [computeDelta] again. 98 /// errors, it is safe to call [computeDelta] again.
99 ///
100 /// Each invocation of [computeDelta] must follow by invocation of either
Paul Berry 2017/08/10 18:03:39 "must be followed by"
scheglov 2017/08/10 19:28:39 Done.
101 /// [acceptLastDelta] or [rejectLastDelta].
86 Future<DeltaProgram> computeDelta(); 102 Future<DeltaProgram> computeDelta();
87 103
88 /// Remove the file associated with the given file [uri] from the set of 104 /// Remove the file associated with the given file [uri] from the set of
89 /// valid files. This guarantees that those files will be re-read on the 105 /// valid files. This guarantees that those files will be re-read on the
90 /// next call to [computeDelta]). 106 /// next call to [computeDelta]).
91 void invalidate(Uri uri); 107 void invalidate(Uri uri);
92 108
109 /// Notify the generator that the last [DeltaProgram] returned from the
110 /// [computeDelta] was rejected. The "last program state" is discared and
111 /// the "current program state" is kept unchanged.
112 void rejectLastDelta();
113
93 /// Creates an [IncrementalKernelGenerator] which is prepared to generate 114 /// Creates an [IncrementalKernelGenerator] which is prepared to generate
94 /// kernel representations of the program whose main library is in the given 115 /// kernel representations of the program whose main library is in the given
95 /// [entryPoint]. 116 /// [entryPoint].
96 /// 117 ///
97 /// The initial "previous program state" is an empty program containing no 118 /// The initial "previous program state" is an empty program containing no
98 /// code, and the initial set of valid sources is empty. To obtain a kernel 119 /// code, and the initial set of valid sources is empty. To obtain a kernel
99 /// representation of the program, call [computeDelta]. 120 /// representation of the program, call [computeDelta].
100 static Future<IncrementalKernelGenerator> newInstance( 121 static Future<IncrementalKernelGenerator> newInstance(
101 CompilerOptions options, Uri entryPoint, 122 CompilerOptions options, Uri entryPoint,
102 {WatchUsedFilesFn watch}) async { 123 {WatchUsedFilesFn watch}) async {
103 var processedOptions = new ProcessedOptions(options, false, [entryPoint]); 124 var processedOptions = new ProcessedOptions(options, false, [entryPoint]);
104 return await CompilerContext.runWithOptions(processedOptions, (_) async { 125 return await CompilerContext.runWithOptions(processedOptions, (_) async {
105 var uriTranslator = await processedOptions.getUriTranslator(); 126 var uriTranslator = await processedOptions.getUriTranslator();
106 var sdkOutlineBytes = await processedOptions.loadSdkSummaryBytes(); 127 var sdkOutlineBytes = await processedOptions.loadSdkSummaryBytes();
107 return new IncrementalKernelGeneratorImpl( 128 return new IncrementalKernelGeneratorImpl(
108 processedOptions, uriTranslator, sdkOutlineBytes, entryPoint, 129 processedOptions, uriTranslator, sdkOutlineBytes, entryPoint,
109 watch: watch); 130 watch: watch);
110 }); 131 });
111 } 132 }
112 } 133 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698