Skip to content

Commit 2cc1204

Browse files
committed
[Evaluator] Remove hasActiveResolveMacroRequest().
1 parent 393b4ce commit 2cc1204

File tree

3 files changed

+8
-45
lines changed

3 files changed

+8
-45
lines changed

include/swift/AST/Evaluator.h

-22
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,6 @@ class Evaluator {
208208
/// is treated as a stack and is used to detect cycles.
209209
llvm::SetVector<ActiveRequest> activeRequests;
210210

211-
/// How many `ResolveMacroRequest` requests are active.
212-
///
213-
/// This allows us to quickly determine whether there is any
214-
/// `ResolveMacroRequest` active in the active request stack.
215-
/// It saves us from a linear scan through `activeRequests` when
216-
/// we need to determine this information.
217-
///
218-
/// Why on earth would we need to determine this information?
219-
/// Please see the extended comment that goes with the constructor
220-
/// of `UnqualifiedLookupRequest`.
221-
unsigned numActiveResolveMacroRequests = 0;
222-
223211
/// A cache that stores the results of requests.
224212
evaluator::RequestCache cache;
225213

@@ -342,16 +330,6 @@ class Evaluator {
342330
return activeRequests.count(ActiveRequest(request));
343331
}
344332

345-
/// Determine whether there is any active "resolve macro" request
346-
/// on the request stack.
347-
///
348-
/// Why on earth would we need to determine this information?
349-
/// Please see the extended comment that goes with the constructor
350-
/// of `UnqualifiedLookupRequest`.
351-
bool hasActiveResolveMacroRequest() const {
352-
return numActiveResolveMacroRequests > 0;
353-
}
354-
355333
private:
356334
/// Diagnose a cycle detected in the evaluation of the given
357335
/// request.

lib/AST/Evaluator.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ Evaluator::Evaluator(DiagnosticEngine &diags, const LangOptions &opts)
6363
bool Evaluator::checkDependency(const ActiveRequest &request) {
6464
// Record this as an active request.
6565
if (activeRequests.insert(request)) {
66-
if (request.getAs<ResolveMacroRequest>())
67-
++numActiveResolveMacroRequests;
6866
return false;
6967
}
7068

@@ -74,9 +72,6 @@ bool Evaluator::checkDependency(const ActiveRequest &request) {
7472
}
7573

7674
void Evaluator::finishedRequest(const ActiveRequest &request) {
77-
if (request.getAs<ResolveMacroRequest>())
78-
--numActiveResolveMacroRequests;
79-
8075
assert(activeRequests.back() == request);
8176
activeRequests.pop_back();
8277
}

lib/AST/NameLookupRequests.cpp

+8-18
Original file line numberDiff line numberDiff line change
@@ -519,24 +519,14 @@ swift::extractNearestSourceLoc(CustomRefCountingOperationDescriptor desc) {
519519
// macros, because doing so trivially creates a cyclic dependency amongst the
520520
// macro expansions that will be detected by the request-evaluator.
521521
//
522-
// Our lookup requests don't always have enough information to answer the
523-
// question "is this part of an argument to a macro?", so we do a much simpler,
524-
// more efficient, and not-entirely-sound hack based on the request-evaluator.
525-
// Specifically, if we are in the process of resolving a macro (which is
526-
// determined by checking for the presence of a `ResolveMacroRequest` in the
527-
// request-evaluator stack), then we adjust the options used for the name
528-
// lookup request we are forming to exclude macro expansions. The evaluation
529-
// of that request will then avoid expanding any macros, and not produce any
530-
// results that involve entries in already-expanded macros. By adjusting the
531-
// request itself, we still distinguish between requests that can and cannot
532-
// look into macro expansions, so it doesn't break caching for those immediate
533-
// requests.
534-
//
535-
// Over time, we should seek to replace this heuristic with a location-based
536-
// check, where we use ASTScope to determine whether we are inside a macro
537-
// argument. This existing check might still be useful because it's going to
538-
// be faster than a location-based query, but the location-based query can be
539-
// fully correct.
522+
// We use source locations to answer the question "is this part of an argument
523+
// to a macro?" through `namelookup::isInMacroArgument`. If the answer is yes,
524+
// then we adjust the options used for the name lookup request we are forming
525+
// to exclude macro expansions. The evaluation of that request will then avoid
526+
// expanding any macros, and not produce any results that involve entries in
527+
// already-expanded macros. By adjusting the request itself, we still
528+
// distinguish between requests that can and cannot look into macro expansions,
529+
// so it doesn't break caching for those immediate requests.
540530

541531
/// Exclude macros in the unqualified lookup descriptor if we need to.
542532
static UnqualifiedLookupDescriptor excludeMacrosIfNeeded(

0 commit comments

Comments
 (0)