Skip to content

Commit f738a57

Browse files
committed
ASTScope: Remove DeclVisibilityKind parameter from AbstractASTScopeDeclConsumer::consume()
It wasn't used for anything, and it was always set based on whether the declaration in question was a GenericTypeParamDecl, a ParamDecl, or something else.
1 parent 8168dda commit f738a57

File tree

4 files changed

+22
-33
lines changed

4 files changed

+22
-33
lines changed

include/swift/AST/ASTScope.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,6 @@ class ASTScopeImpl {
444444
// It is not an instance variable or inherited type.
445445

446446
static bool lookupLocalBindingsInPattern(const Pattern *p,
447-
DeclVisibilityKind vis,
448447
DeclConsumer consumer);
449448

450449
/// When lookup must stop before the outermost scope, return the scope to stop

include/swift/AST/NameLookup.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ class AbstractASTScopeDeclConsumer {
603603
/// of type -vs- instance lookup results.
604604
///
605605
/// \return true if the lookup should be stopped at this point.
606-
virtual bool consume(ArrayRef<ValueDecl *> values, DeclVisibilityKind vis,
606+
virtual bool consume(ArrayRef<ValueDecl *> values,
607607
NullablePtr<DeclContext> baseDC = nullptr) = 0;
608608

609609
/// Look for members of a nominal type or extension scope.
@@ -644,7 +644,7 @@ class ASTScopeDeclGatherer : public AbstractASTScopeDeclConsumer {
644644
public:
645645
virtual ~ASTScopeDeclGatherer() = default;
646646

647-
bool consume(ArrayRef<ValueDecl *> values, DeclVisibilityKind vis,
647+
bool consume(ArrayRef<ValueDecl *> values,
648648
NullablePtr<DeclContext> baseDC = nullptr) override;
649649

650650
/// Eventually this functionality should move into ASTScopeLookup

lib/AST/ASTScopeLookup.cpp

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ bool ASTScopeImpl::lookInGenericParametersOf(
222222
SmallVector<ValueDecl *, 32> bindings;
223223
for (auto *param : paramList.get()->getParams())
224224
bindings.push_back(param);
225-
if (consumer.consume(bindings, DeclVisibilityKind::GenericParameter))
225+
if (consumer.consume(bindings))
226226
return true;
227227
return false;
228228
}
@@ -289,28 +289,26 @@ PatternEntryInitializerScope::getLookupParent() const {
289289

290290
bool GenericParamScope::lookupLocalsOrMembers(DeclConsumer consumer) const {
291291
auto *param = paramList->getParams()[index];
292-
return consumer.consume({param}, DeclVisibilityKind::GenericParameter);
292+
return consumer.consume({param});
293293
}
294294

295295
bool PatternEntryDeclScope::lookupLocalsOrMembers(DeclConsumer consumer) const {
296296
if (vis != DeclVisibilityKind::LocalVariable)
297297
return false; // look in self type will find this later
298-
return lookupLocalBindingsInPattern(getPattern(), vis, consumer);
298+
return lookupLocalBindingsInPattern(getPattern(), consumer);
299299
}
300300

301301
bool ForEachPatternScope::lookupLocalsOrMembers(DeclConsumer consumer) const {
302-
return lookupLocalBindingsInPattern(
303-
stmt->getPattern(), DeclVisibilityKind::LocalVariable, consumer);
302+
return lookupLocalBindingsInPattern(stmt->getPattern(), consumer);
304303
}
305304

306305
bool CaseLabelItemScope::lookupLocalsOrMembers(DeclConsumer consumer) const {
307-
return lookupLocalBindingsInPattern(
308-
item.getPattern(), DeclVisibilityKind::LocalVariable, consumer);
306+
return lookupLocalBindingsInPattern(item.getPattern(), consumer);
309307
}
310308

311309
bool CaseStmtBodyScope::lookupLocalsOrMembers(DeclConsumer consumer) const {
312310
for (auto *var : stmt->getCaseBodyVariablesOrEmptyArray())
313-
if (consumer.consume({var}, DeclVisibilityKind::LocalVariable))
311+
if (consumer.consume({var}))
314312
return true;
315313

316314
return false;
@@ -320,13 +318,12 @@ bool FunctionBodyScope::lookupLocalsOrMembers(
320318
DeclConsumer consumer) const {
321319
if (auto *paramList = decl->getParameters()) {
322320
for (auto *paramDecl : *paramList)
323-
if (consumer.consume({paramDecl}, DeclVisibilityKind::FunctionParameter))
321+
if (consumer.consume({paramDecl}))
324322
return true;
325323
}
326324

327325
if (decl->getDeclContext()->isTypeContext()) {
328-
return consumer.consume({decl->getImplicitSelfDecl()},
329-
DeclVisibilityKind::FunctionParameter);
326+
return consumer.consume({decl->getImplicitSelfDecl()});
330327
}
331328

332329
// Consider \c var t: T { (did/will/)get/set { ... t }}
@@ -335,7 +332,7 @@ bool FunctionBodyScope::lookupLocalsOrMembers(
335332
// then t needs to be found as a local binding:
336333
if (auto *accessor = dyn_cast<AccessorDecl>(decl)) {
337334
if (auto *storage = accessor->getStorage())
338-
if (consumer.consume({storage}, DeclVisibilityKind::LocalVariable))
335+
if (consumer.consume({storage}))
339336
return true;
340337
}
341338

@@ -346,7 +343,7 @@ bool SpecializeAttributeScope::lookupLocalsOrMembers(
346343
DeclConsumer consumer) const {
347344
if (auto *params = whatWasSpecialized->getGenericParams())
348345
for (auto *param : params->getParams())
349-
if (consumer.consume({param}, DeclVisibilityKind::GenericParameter))
346+
if (consumer.consume({param}))
350347
return true;
351348
return false;
352349
}
@@ -356,7 +353,7 @@ bool DifferentiableAttributeScope::lookupLocalsOrMembers(
356353
auto visitAbstractFunctionDecl = [&](AbstractFunctionDecl *afd) {
357354
if (auto *params = afd->getGenericParams())
358355
for (auto *param : params->getParams())
359-
if (consumer.consume({param}, DeclVisibilityKind::GenericParameter))
356+
if (consumer.consume({param}))
360357
return true;
361358
return false;
362359
};
@@ -371,7 +368,7 @@ bool DifferentiableAttributeScope::lookupLocalsOrMembers(
371368
}
372369

373370
bool BraceStmtScope::lookupLocalsOrMembers(DeclConsumer consumer) const {
374-
if (consumer.consume(localFuncsAndTypes, DeclVisibilityKind::LocalVariable))
371+
if (consumer.consume(localFuncsAndTypes))
375372
return true;
376373

377374
if (consumer.consumePossiblyNotInScope(localVars))
@@ -390,18 +387,15 @@ bool PatternEntryInitializerScope::lookupLocalsOrMembers(
390387
decl->getInitContext(0));
391388
if (initContext) {
392389
if (auto *selfParam = initContext->getImplicitSelfDecl()) {
393-
return consumer.consume({selfParam},
394-
DeclVisibilityKind::FunctionParameter);
390+
return consumer.consume({selfParam});
395391
}
396392
}
397393
return false;
398394
}
399395

400396
bool CaptureListScope::lookupLocalsOrMembers(DeclConsumer consumer) const {
401397
for (auto &e : expr->getCaptureList()) {
402-
if (consumer.consume(
403-
{e.Var},
404-
DeclVisibilityKind::LocalVariable)) // or FunctionParameter??
398+
if (consumer.consume({e.Var}))
405399
return true;
406400
}
407401
return false;
@@ -410,26 +404,24 @@ bool CaptureListScope::lookupLocalsOrMembers(DeclConsumer consumer) const {
410404
bool ClosureParametersScope::lookupLocalsOrMembers(
411405
DeclConsumer consumer) const {
412406
for (auto param : *closureExpr->getParameters())
413-
if (consumer.consume({param}, DeclVisibilityKind::FunctionParameter))
407+
if (consumer.consume({param}))
414408
return true;
415409
return false;
416410
}
417411

418412
bool ConditionalClausePatternUseScope::lookupLocalsOrMembers(
419413
DeclConsumer consumer) const {
420-
return lookupLocalBindingsInPattern(
421-
pattern, DeclVisibilityKind::LocalVariable, consumer);
414+
return lookupLocalBindingsInPattern(pattern, consumer);
422415
}
423416

424417
bool ASTScopeImpl::lookupLocalBindingsInPattern(const Pattern *p,
425-
DeclVisibilityKind vis,
426418
DeclConsumer consumer) {
427419
if (!p)
428420
return false;
429421
bool isDone = false;
430422
p->forEachVariable([&](VarDecl *var) {
431423
if (!isDone)
432-
isDone = consumer.consume({var}, vis);
424+
isDone = consumer.consume({var});
433425
});
434426
return isDone;
435427
}

lib/AST/UnqualifiedLookup.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class ASTScopeDeclConsumerForUnqualifiedLookup
211211

212212
void maybeUpdateSelfDC(VarDecl *var);
213213

214-
bool consume(ArrayRef<ValueDecl *> values, DeclVisibilityKind vis,
214+
bool consume(ArrayRef<ValueDecl *> values,
215215
NullablePtr<DeclContext> baseDC = nullptr) override;
216216

217217
bool consumePossiblyNotInScope(ArrayRef<VarDecl *> vars) override;
@@ -561,8 +561,7 @@ void ASTScopeDeclConsumerForUnqualifiedLookup::maybeUpdateSelfDC(
561561
}
562562

563563
bool ASTScopeDeclConsumerForUnqualifiedLookup::consume(
564-
ArrayRef<ValueDecl *> values, DeclVisibilityKind vis,
565-
NullablePtr<DeclContext> baseDC) {
564+
ArrayRef<ValueDecl *> values, NullablePtr<DeclContext> baseDC) {
566565
for (auto *value: values) {
567566
if (factory.isOriginallyTypeLookup && !isa<TypeDecl>(value))
568567
continue;
@@ -609,7 +608,6 @@ bool ASTScopeDeclConsumerForUnqualifiedLookup::consumePossiblyNotInScope(
609608
}
610609

611610
bool ASTScopeDeclGatherer::consume(ArrayRef<ValueDecl *> valuesArg,
612-
DeclVisibilityKind,
613611
NullablePtr<DeclContext>) {
614612
for (auto *v: valuesArg)
615613
values.push_back(v);
@@ -768,7 +766,7 @@ class ASTScopeDeclConsumerForLocalLookup
768766
: name(name), stopAfterInnermostBraceStmt(stopAfterInnermostBraceStmt),
769767
results(results) {}
770768

771-
bool consume(ArrayRef<ValueDecl *> values, DeclVisibilityKind vis,
769+
bool consume(ArrayRef<ValueDecl *> values,
772770
NullablePtr<DeclContext> baseDC) override {
773771
for (auto *value: values) {
774772
if (!value->getName().matchesRef(name))

0 commit comments

Comments
 (0)