Skip to content

Commit 49e371c

Browse files
committed
ASTScope: Remove crossCheckWithAST()
1 parent bbd79a2 commit 49e371c

File tree

2 files changed

+0
-131
lines changed

2 files changed

+0
-131
lines changed

include/swift/AST/ASTScope.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,6 @@ class ASTSourceFileScope final : public ASTScopeImpl {
496496

497497
const SourceFile *getSourceFile() const override;
498498
NullablePtr<const void> addressForPrinting() const override { return SF; }
499-
bool crossCheckWithAST();
500499

501500
protected:
502501
ASTScopeImpl *expandSpecifically(ScopeCreator &scopeCreator) override;

lib/AST/ASTScopeCreation.cpp

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -462,67 +462,6 @@ class ScopeCreator final {
462462
return -1 == signum;
463463
}
464464

465-
public:
466-
/// For debugging. Return true if scope tree contains all the decl contexts in
467-
/// the AST May modify the scope tree in order to update obsolete scopes.
468-
/// Likely slow.
469-
bool containsAllDeclContextsFromAST() {
470-
auto allDeclContexts = findLocalizableDeclContextsInAST();
471-
llvm::DenseMap<const DeclContext *, const ASTScopeImpl *> bogusDCs;
472-
sourceFileScope->preOrderDo([&](ASTScopeImpl *scope) {
473-
scope->expandAndBeCurrentDetectingRecursion(*this);
474-
});
475-
sourceFileScope->postOrderDo([&](ASTScopeImpl *scope) {
476-
if (auto *dc = scope->getDeclContext().getPtrOrNull()) {
477-
auto iter = allDeclContexts.find(dc);
478-
if (iter != allDeclContexts.end())
479-
++iter->second;
480-
else
481-
bogusDCs.insert({dc, scope});
482-
}
483-
});
484-
485-
auto printDecl = [&](const Decl *d) {
486-
llvm::errs() << "\ngetAsDecl() -> " << d << " ";
487-
d->getSourceRange().print(llvm::errs(), ctx.SourceMgr);
488-
llvm::errs() << " : ";
489-
d->dump(llvm::errs());
490-
llvm::errs() << "\n";
491-
};
492-
bool foundOmission = false;
493-
for (const auto &p : allDeclContexts) {
494-
if (p.second == 0) {
495-
if (auto *d = p.first->getAsDecl()) {
496-
if (isLocalizable(d)) {
497-
llvm::errs() << "\nASTScope tree omitted DeclContext: " << p.first
498-
<< " "
499-
<< ":\n";
500-
p.first->printContext(llvm::errs());
501-
printDecl(d);
502-
foundOmission = true;
503-
}
504-
} else {
505-
// If no decl, no source range, so no scope
506-
}
507-
}
508-
}
509-
for (const auto &dcAndScope : bogusDCs) {
510-
llvm::errs() << "ASTScope tree confabulated: " << dcAndScope.getFirst()
511-
<< ":\n";
512-
dcAndScope.getFirst()->printContext(llvm::errs());
513-
if (auto *d = dcAndScope.getFirst()->getAsDecl())
514-
printDecl(d);
515-
dcAndScope.getSecond()->print(llvm::errs(), 0, false);
516-
}
517-
return !foundOmission && bogusDCs.empty();
518-
}
519-
520-
private:
521-
/// Return a map of every DeclContext in the AST, and zero in the 2nd element.
522-
/// For debugging.
523-
llvm::DenseMap<const DeclContext *, unsigned>
524-
findLocalizableDeclContextsInAST() const;
525-
526465
public:
527466
SWIFT_DEBUG_DUMP { print(llvm::errs()); }
528467

@@ -1535,75 +1474,6 @@ IterableTypeBodyPortion::insertionPointForDeferredExpansion(
15351474

15361475
#pragma mark verification
15371476

1538-
namespace {
1539-
class LocalizableDeclContextCollector : public ASTWalker {
1540-
1541-
public:
1542-
llvm::DenseMap<const DeclContext *, unsigned> declContexts;
1543-
1544-
void record(const DeclContext *dc) {
1545-
if (dc)
1546-
declContexts.insert({dc, 0});
1547-
}
1548-
1549-
bool walkToDeclPre(Decl *D) override {
1550-
// catchForDebugging(D, "DictionaryBridging.swift", 694);
1551-
if (const auto *dc = dyn_cast<DeclContext>(D))
1552-
record(dc);
1553-
if (isa<IfConfigDecl>(D))
1554-
return false;
1555-
if (auto *pd = dyn_cast<ParamDecl>(D))
1556-
record(pd->getDefaultArgumentInitContext());
1557-
else if (auto *pbd = dyn_cast<PatternBindingDecl>(D))
1558-
recordInitializers(pbd);
1559-
else if (auto *vd = dyn_cast<VarDecl>(D)) {
1560-
vd->visitParsedAccessors([&](AccessorDecl *ad) {
1561-
ad->walk(*this);
1562-
});
1563-
}
1564-
return ASTWalker::walkToDeclPre(D);
1565-
}
1566-
1567-
std::pair<bool, Expr *> walkToExprPre(Expr *E) override {
1568-
if (const auto *ce = dyn_cast<ClosureExpr>(E))
1569-
record(ce);
1570-
return ASTWalker::walkToExprPre(E);
1571-
}
1572-
1573-
private:
1574-
void recordInitializers(PatternBindingDecl *pbd) {
1575-
for (auto idx : range(pbd->getNumPatternEntries()))
1576-
record(pbd->getInitContext(idx));
1577-
}
1578-
1579-
void catchForDebugging(Decl *D, const char *file, const unsigned line) {
1580-
auto &SM = D->getASTContext().SourceMgr;
1581-
auto loc = D->getStartLoc();
1582-
if (!loc.isValid())
1583-
return;
1584-
auto bufID = SM.findBufferContainingLoc(loc);
1585-
auto f = SM.getIdentifierForBuffer(bufID);
1586-
auto lin = SM.getLineAndColumnInBuffer(loc).first;
1587-
if (f.endswith(file) && lin == line)
1588-
if (isa<PatternBindingDecl>(D))
1589-
llvm::errs() << "*** catchForDebugging: " << lin << " ***\n";
1590-
}
1591-
};
1592-
} // end namespace
1593-
1594-
llvm::DenseMap<const DeclContext *, unsigned>
1595-
ScopeCreator::findLocalizableDeclContextsInAST() const {
1596-
LocalizableDeclContextCollector collector;
1597-
sourceFileScope->SF->walk(collector);
1598-
// Walker omits the top
1599-
collector.record(sourceFileScope->SF);
1600-
return collector.declContexts;
1601-
}
1602-
1603-
bool ASTSourceFileScope::crossCheckWithAST() {
1604-
return scopeCreator->containsAllDeclContextsFromAST();
1605-
}
1606-
16071477
void ast_scope::simple_display(llvm::raw_ostream &out,
16081478
const ScopeCreator *scopeCreator) {
16091479
scopeCreator->print(out);

0 commit comments

Comments
 (0)