@@ -47,11 +47,10 @@ struct DependencyRecorder;
47
47
// / A \c DependencyCollector defines an abstract write-only buffer of
48
48
// / \c Reference objects. References are added to a collector during the write
49
49
// / phase of request evaluation (in \c writeDependencySink) with the various
50
- // / \c add* functions below..
50
+ // / \c add* functions below.
51
51
// /
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.
55
54
struct DependencyCollector {
56
55
friend DependencyRecorder;
57
56
@@ -174,28 +173,58 @@ struct DependencyRecorder {
174
173
friend DependencyCollector;
175
174
176
175
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.
177
179
llvm::DenseMap<SourceFile *,
178
180
llvm::DenseSet<DependencyCollector::Reference,
179
181
DependencyCollector::Reference::Info>>
180
182
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.
181
189
llvm::DenseMap<AnyRequest, std::vector<DependencyCollector::Reference>>
182
190
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.
183
196
std::vector<llvm::DenseSet<DependencyCollector::Reference,
184
197
DependencyCollector::Reference::Info>>
185
198
activeRequestReferences;
186
199
187
200
#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.
188
204
bool isRecording = false ;
189
205
#endif
190
206
191
207
public:
208
+ // / Push a new empty set onto the activeRequestReferences stack.
192
209
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.
193
214
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.
194
218
void replayCachedRequest (const swift::ActiveRequest &req);
219
+
220
+ // / Upon completion of a dependency source request, we update the
221
+ // / fileReferences map.
195
222
void handleDependencySourceRequest (const swift::ActiveRequest &req,
196
223
SourceFile *source);
197
224
198
225
private:
226
+ // / Add an entry to the innermost set on the activeRequestReferences stack.
227
+ // / Called from the DependencyCollector.
199
228
void recordDependency (const DependencyCollector::Reference &ref);
200
229
201
230
public:
@@ -205,6 +234,10 @@ struct DependencyRecorder {
205
234
// / Enumerates the set of references associated with a given source file,
206
235
// / passing them to the given enumeration callback.
207
236
// /
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
+ // /
208
241
// / The order of enumeration is completely undefined. It is the responsibility
209
242
// / of callers to ensure they are order-invariant or are sorting the result.
210
243
void enumerateReferencesInFile (const SourceFile *SF,
0 commit comments