Skip to content

Commit e03c568

Browse files
authored
Merge pull request #61197 from bnbarham/skip-invalid-locations
[Index] Always skip invalid locations outside of modules
2 parents 210c68d + 88f0e75 commit e03c568

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

include/swift/Index/IndexSymbol.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ struct IndexSymbol : IndexRelation {
6565
SmallVector<IndexRelation, 3> Relations;
6666
unsigned line = 0;
6767
unsigned column = 0;
68-
Optional<unsigned> offset;
6968

7069
IndexSymbol() = default;
7170

lib/Index/Index.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
834834
return true;
835835

836836
IndexSymbol Info;
837-
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(Loc);
837+
std::tie(Info.line, Info.column) = getLineCol(Loc);
838838
Info.roles |= (unsigned)SymbolRole::Reference;
839839
Info.symInfo = getSymbolInfoForModule(Mod);
840840
getModuleNameAndUSR(Mod, Info.name, Info.USR);
@@ -949,13 +949,10 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
949949

950950
bool indexComment(const Decl *D);
951951

952-
std::tuple<unsigned, unsigned, Optional<unsigned>>
953-
getLineColAndOffset(SourceLoc Loc) {
952+
std::pair<unsigned, unsigned> getLineCol(SourceLoc Loc) {
954953
if (Loc.isInvalid())
955-
return std::make_tuple(0, 0, None);
956-
auto lineAndColumn = SrcMgr.getLineAndColumnInBuffer(Loc, BufferID);
957-
unsigned offset = SrcMgr.getLocOffsetInBuffer(Loc, BufferID);
958-
return std::make_tuple(lineAndColumn.first, lineAndColumn.second, offset);
954+
return std::make_pair(0, 0);
955+
return SrcMgr.getLineAndColumnInBuffer(Loc, BufferID);
959956
}
960957

961958
bool shouldIndex(ValueDecl *D, bool IsRef) const {
@@ -1604,8 +1601,13 @@ bool IndexSwiftASTWalker::reportImplicitConformance(ValueDecl *witness, ValueDec
16041601
bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
16051602
bool IsRef, IndexSymbol &Info) {
16061603
assert(D);
1604+
1605+
if (Loc.isInvalid() && !IsModuleFile)
1606+
return true;
1607+
16071608
if (Loc.isValid() && SrcMgr.findBufferContainingLoc(Loc) != BufferID)
16081609
return true;
1610+
16091611
if (auto *VD = dyn_cast<VarDecl>(D)) {
16101612
// Always base the symbol information on the canonical VarDecl
16111613
D = VD->getCanonicalVarDecl();
@@ -1618,23 +1620,21 @@ bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
16181620

16191621
// Cannot be extension, which is not a ValueDecl.
16201622

1623+
if (getNameAndUSR(D, /*ExtD=*/nullptr, Info.name, Info.USR))
1624+
return true;
1625+
std::tie(Info.line, Info.column) = getLineCol(Loc);
1626+
16211627
if (IsRef) {
16221628
Info.roles |= (unsigned)SymbolRole::Reference;
16231629
addContainedByRelationIfContained(Info);
16241630
} else {
16251631
Info.roles |= (unsigned)SymbolRole::Definition;
16261632
if (D->isImplicit())
16271633
Info.roles |= (unsigned)SymbolRole::Implicit;
1628-
}
1629-
1630-
if (getNameAndUSR(D, /*ExtD=*/nullptr, Info.name, Info.USR))
1631-
return true;
1632-
1633-
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(Loc);
1634-
if (!IsRef) {
16351634
if (auto Group = D->getGroupName())
16361635
Info.group = Group.getValue();
16371636
}
1637+
16381638
return false;
16391639
}
16401640

@@ -1651,7 +1651,7 @@ bool IndexSwiftASTWalker::initIndexSymbol(ExtensionDecl *ExtD, ValueDecl *Extend
16511651
if (getNameAndUSR(ExtendedD, ExtD, Info.name, Info.USR))
16521652
return true;
16531653

1654-
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(Loc);
1654+
std::tie(Info.line, Info.column) = getLineCol(Loc);
16551655
if (auto Group = ExtD->getGroupName())
16561656
Info.group = Group.getValue();
16571657
return false;
@@ -1786,7 +1786,7 @@ bool IndexSwiftASTWalker::indexComment(const Decl *D) {
17861786
OS << "t:" << tagName;
17871787
Info.USR = stringStorage.copyString(OS.str());
17881788
}
1789-
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(loc);
1789+
std::tie(Info.line, Info.column) = getLineCol(loc);
17901790
if (!IdxConsumer.startSourceEntity(Info) || !IdxConsumer.finishSourceEntity(Info.symInfo, Info.roles)) {
17911791
Cancelled = true;
17921792
break;

0 commit comments

Comments
 (0)