Skip to content

Commit 85ae227

Browse files
committed
ASTScope: Remove hacks for PatternBindingDecls with invalid source ranges
1 parent 51a4a91 commit 85ae227

File tree

3 files changed

+3
-107
lines changed

3 files changed

+3
-107
lines changed

lib/AST/ASTScopeCreation.cpp

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,6 @@ class ScopeCreator final {
273273
// Implicit nodes may not have source information for name lookup.
274274
if (!isLocalizable(d))
275275
return false;
276-
/// In \c Parser::parseDeclVarGetSet fake PBDs are created. Ignore them.
277-
/// Example:
278-
/// \code
279-
/// class SR10903 { static var _: Int { 0 } }
280-
/// \endcode
281276

282277
// Commented out for
283278
// validation-test/compiler_crashers_fixed/27962-swift-rebindselfinconstructorexpr-getcalledconstructor.swift
@@ -502,9 +497,6 @@ class ScopeCreator final {
502497
std::vector<ASTNode> expandIfConfigClausesThenCullAndSortElementsOrMembers(
503498
ArrayRef<ASTNode> input) const {
504499
auto cleanedupNodes = sortBySourceRange(cull(expandIfConfigClauses(input)));
505-
// TODO: uncomment when working on not creating two pattern binding decls at
506-
// same location.
507-
// findCollidingPatterns(cleanedupNodes);
508500
return cleanedupNodes;
509501
}
510502

@@ -562,73 +554,6 @@ class ScopeCreator final {
562554
return culled;
563555
}
564556

565-
/// TODO: The parser yields two decls at the same source loc with the same
566-
/// kind. TODO: me when fixing parser's proclivity to create two
567-
/// PatternBindingDecls at the same source location, then move this to
568-
/// ASTVerifier.
569-
///
570-
/// In all cases the first pattern seems to carry the initializer, and the
571-
/// second, the accessor
572-
void findCollidingPatterns(ArrayRef<ASTNode> input) const {
573-
auto dumpPBD = [&](PatternBindingDecl *pbd, const char *which) {
574-
llvm::errs() << "*** " << which
575-
<< " pbd isImplicit: " << pbd->isImplicit()
576-
<< ", #entries: " << pbd->getNumPatternEntries() << " :";
577-
pbd->getSourceRange().print(llvm::errs(), pbd->getASTContext().SourceMgr,
578-
false);
579-
llvm::errs() << "\n";
580-
llvm::errs() << "init: " << pbd->getInit(0) << "\n";
581-
if (pbd->getInit(0)) {
582-
llvm::errs() << "SR (init): ";
583-
pbd->getInit(0)->getSourceRange().print(
584-
llvm::errs(), pbd->getASTContext().SourceMgr, false);
585-
llvm::errs() << "\n";
586-
pbd->getInit(0)->dump(llvm::errs(), 0);
587-
}
588-
llvm::errs() << "vars:\n";
589-
pbd->getPattern(0)->forEachVariable([&](VarDecl *vd) {
590-
llvm::errs() << " " << vd->getName()
591-
<< " implicit: " << vd->isImplicit()
592-
<< " #accs: " << vd->getAllAccessors().size()
593-
<< "\nSR (var):";
594-
vd->getSourceRange().print(llvm::errs(), pbd->getASTContext().SourceMgr,
595-
false);
596-
llvm::errs() << "\nSR (braces)";
597-
vd->getBracesRange().print(llvm::errs(), pbd->getASTContext().SourceMgr,
598-
false);
599-
llvm::errs() << "\n";
600-
for (auto *a : vd->getAllAccessors()) {
601-
llvm::errs() << "SR (acc): ";
602-
a->getSourceRange().print(llvm::errs(),
603-
pbd->getASTContext().SourceMgr, false);
604-
llvm::errs() << "\n";
605-
a->dump(llvm::errs(), 0);
606-
}
607-
});
608-
};
609-
610-
Decl *lastD = nullptr;
611-
for (auto n : input) {
612-
auto *d = n.dyn_cast<Decl *>();
613-
if (!d || !lastD || lastD->getStartLoc() != d->getStartLoc() ||
614-
lastD->getKind() != d->getKind()) {
615-
lastD = d;
616-
continue;
617-
}
618-
if (auto *pbd = dyn_cast<PatternBindingDecl>(lastD))
619-
dumpPBD(pbd, "prev");
620-
if (auto *pbd = dyn_cast<PatternBindingDecl>(d)) {
621-
dumpPBD(pbd, "curr");
622-
ASTScope_unreachable("found colliding pattern binding decls");
623-
}
624-
llvm::errs() << "Two same kind decls at same loc: \n";
625-
lastD->dump(llvm::errs());
626-
llvm::errs() << "and\n";
627-
d->dump(llvm::errs());
628-
ASTScope_unreachable("Two same kind decls; unexpected kinds");
629-
}
630-
}
631-
632557
/// Templated to work on either ASTNodes, Decl*'s, or whatnot.
633558
template <typename Rangeable>
634559
std::vector<Rangeable>
@@ -962,24 +887,6 @@ class NodeAdder
962887
: DeclVisibilityKind::LocalVariable;
963888
auto *insertionPoint = parentScope;
964889
for (auto i : range(patternBinding->getNumPatternEntries())) {
965-
// TODO: Won't need to do so much work to avoid creating one without
966-
// a SourceRange once parser is fixed to not create two
967-
// PatternBindingDecls with same locaiton and getSourceRangeOfThisASTNode
968-
// for PatternEntryDeclScope is simplified to use the PatternEntry's
969-
// source range.
970-
if (!patternBinding->getOriginalInit(i)) {
971-
bool found = false;
972-
patternBinding->getPattern(i)->forEachVariable([&](VarDecl *vd) {
973-
if (!vd->isImplicit())
974-
found = true;
975-
else
976-
found |= llvm::any_of(vd->getAllAccessors(), [&](AccessorDecl *a) {
977-
return isLocalizable(a);
978-
});
979-
});
980-
if (!found)
981-
continue;
982-
}
983890
insertionPoint =
984891
scopeCreator
985892
.ifUniqueConstructExpandAndInsert<PatternEntryDeclScope>(

lib/AST/ASTScopeSourceRange.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -247,16 +247,6 @@ SourceRange DefaultArgumentInitializerScope::getSourceRangeOfThisASTNode(
247247

248248
SourceRange PatternEntryDeclScope::getSourceRangeOfThisASTNode(
249249
const bool omitAssertions) const {
250-
// TODO: Once the creation of two PatternBindingDecls at same location is
251-
// eliminated, the following may be able to be simplified.
252-
if (!getChildren().empty()) { // why needed???
253-
bool hasOne = false;
254-
getPattern()->forEachVariable([&](VarDecl *) { hasOne = true; });
255-
if (!hasOne)
256-
return SourceRange(); // just the init
257-
if (!getPatternEntry().getInit())
258-
return SourceRange(); // just the var decls
259-
}
260250
return getPatternEntry().getSourceRange();
261251
}
262252

test/SourceKit/DocumentStructure/structure.swift.empty.response

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -573,11 +573,10 @@
573573
key.kind: source.lang.swift.decl.var.global,
574574
key.accessibility: source.lang.swift.accessibility.internal,
575575
key.setter_accessibility: source.lang.swift.accessibility.internal,
576-
key.name: "Qtys",
577576
key.offset: 1079,
578-
key.length: 15,
579-
key.nameoffset: 1089,
580-
key.namelength: 4
577+
key.length: 3,
578+
key.nameoffset: 1079,
579+
key.namelength: 0
581580
},
582581
{
583582
key.kind: source.lang.swift.stmt.foreach,

0 commit comments

Comments
 (0)