Skip to content

Commit bfb98d8

Browse files
committed
AST: Add some comments to EvaluatorDependencies.h
1 parent 349bc13 commit bfb98d8

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

include/swift/AST/EvaluatorDependencies.h

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ struct DependencyRecorder;
4747
/// A \c DependencyCollector defines an abstract write-only buffer of
4848
/// \c Reference objects. References are added to a collector during the write
4949
/// phase of request evaluation (in \c writeDependencySink) with the various
50-
/// \c add* functions below..
50+
/// \c add* functions below.
5151
///
52-
/// A \c DependencyCollector cannot be created directly. You must invoke
53-
/// \c DependencyRecorder::record, which will wire a dependency collector into
54-
/// the provided continuation block.
52+
/// A \c DependencyCollector should not be created directly; instances are
53+
/// vended by the request evaluator infrastructure itself.
5554
struct DependencyCollector {
5655
friend DependencyRecorder;
5756

@@ -174,28 +173,58 @@ struct DependencyRecorder {
174173
friend DependencyCollector;
175174

176175
private:
176+
/// References recorded while evaluating a dependency source request for each
177+
/// source file. This map is updated upon completion of a dependency source
178+
/// request, and includes all references from each downstream request as well.
177179
llvm::DenseMap<SourceFile *,
178180
llvm::DenseSet<DependencyCollector::Reference,
179181
DependencyCollector::Reference::Info>>
180182
fileReferences;
183+
184+
/// References recorded while evaluating each request. This map is populated
185+
/// upon completion of each request, and includes all references from each
186+
/// downstream request as well. Note that uncached requests don't appear as
187+
/// keys in this map; their references are charged to the innermost cached
188+
/// active request.
181189
llvm::DenseMap<AnyRequest, std::vector<DependencyCollector::Reference>>
182190
requestReferences;
191+
192+
/// Stack of references from each cached active request. When evaluating a
193+
/// dependency sink request, we update the innermost set of references.
194+
/// Upon completion of a request, we union the completed request's references
195+
/// with the next innermost active request.
183196
std::vector<llvm::DenseSet<DependencyCollector::Reference,
184197
DependencyCollector::Reference::Info>>
185198
activeRequestReferences;
186199

187200
#ifndef NDEBUG
201+
/// Used to catch places where a request's writeDependencySink() method
202+
/// kicks off another request, which would break invariants, so we
203+
/// disallow this from happening.
188204
bool isRecording = false;
189205
#endif
190206

191207
public:
208+
/// Push a new empty set onto the activeRequestReferences stack.
192209
void beginRequest(const swift::ActiveRequest &req);
210+
211+
/// Pop the activeRequestReferences stack, and insert recorded references
212+
/// into the requestReferences map, as well as the next innermost entry in
213+
/// activeRequestReferences.
193214
void endRequest(const swift::ActiveRequest &req);
215+
216+
/// When replaying a request whose value has already been cached, we need
217+
/// to update the innermost set in the activeRequestReferences stack.
194218
void replayCachedRequest(const swift::ActiveRequest &req);
219+
220+
/// Upon completion of a dependency source request, we update the
221+
/// fileReferences map.
195222
void handleDependencySourceRequest(const swift::ActiveRequest &req,
196223
SourceFile *source);
197224

198225
private:
226+
/// Add an entry to the innermost set on the activeRequestReferences stack.
227+
/// Called from the DependencyCollector.
199228
void recordDependency(const DependencyCollector::Reference &ref);
200229

201230
public:
@@ -205,6 +234,10 @@ struct DependencyRecorder {
205234
/// Enumerates the set of references associated with a given source file,
206235
/// passing them to the given enumeration callback.
207236
///
237+
/// Only makes sense to call once all dependency sources associated with this
238+
/// source file have already been evaluated, otherwise the map will obviously
239+
/// be incomplete.
240+
///
208241
/// The order of enumeration is completely undefined. It is the responsibility
209242
/// of callers to ensure they are order-invariant or are sorting the result.
210243
void enumerateReferencesInFile(const SourceFile *SF,

0 commit comments

Comments
 (0)