Skip to content

Commit 5e2c7a9

Browse files
committed
Revert "Fix RelBase indexing with composite types"
This crashes with typealiases referenced across files. I will resubmit with a fix. See also #65545 This reverts commit 7a5e9dc.
1 parent 3368e71 commit 5e2c7a9

File tree

3 files changed

+6
-88
lines changed

3 files changed

+6
-88
lines changed

lib/Index/Index.cpp

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -878,10 +878,6 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
878878
auto AfterDollar = Loc.getAdvancedLoc(1);
879879
reportRef(Wrapped, AfterDollar, Info, None);
880880
}
881-
} else if (auto *TAD = dyn_cast<TypeAliasDecl>(D)) {
882-
TypeLoc TL(TAD->getUnderlyingTypeRepr(), TAD->getUnderlyingType());
883-
if (!reportRelatedTypeRef(TL, (SymbolRoleSet)SymbolRole::Reference, D, /*isImplicit=*/true, Loc))
884-
return false;
885881
}
886882

887883
return true;
@@ -966,18 +962,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
966962
bool startEntityDecl(ValueDecl *D);
967963

968964
bool reportRelatedRef(ValueDecl *D, SourceLoc Loc, bool isImplicit, SymbolRoleSet Relations, Decl *Related);
969-
970-
/// Report references for dependent types
971-
///
972-
/// NOTE: If the dependent type is a typealias, report the underlying types as well.
973-
///
974-
/// \param Ty The type being referenced.
975-
/// \param Relations The relationship between the referenced type and the passed Decl.
976-
/// \param Related The Decl that is referencing the type.
977-
/// \param isImplicit Whether the reference is implicit, such as for a typealias' underlying type.
978-
/// \param Loc The location of the reference, otherwise the location of the TypeLoc is used.
979-
bool reportRelatedTypeRef(const TypeLoc &Ty, SymbolRoleSet Relations, Decl *Related,
980-
bool isImplicit=false, SourceLoc Loc={});
965+
bool reportRelatedTypeRef(const TypeLoc &Ty, SymbolRoleSet Relations, Decl *Related);
981966
bool reportInheritedTypeRefs(
982967
ArrayRef<InheritedEntry> Inherited, Decl *Inheritee);
983968
NominalTypeDecl *getTypeLocAsNominalTypeDecl(const TypeLoc &Ty);
@@ -1393,37 +1378,20 @@ bool IndexSwiftASTWalker::reportInheritedTypeRefs(ArrayRef<InheritedEntry> Inher
13931378
return true;
13941379
}
13951380

1396-
bool IndexSwiftASTWalker::reportRelatedTypeRef(const TypeLoc &Ty, SymbolRoleSet Relations,
1397-
Decl *Related, bool Implicit, SourceLoc Loc) {
1398-
if (auto *composite = llvm::dyn_cast_or_null<CompositionTypeRepr>(Ty.getTypeRepr())) {
1399-
SourceLoc IdLoc = Loc.isValid() ? Loc : composite->getSourceLoc();
1400-
for (auto *Type : composite->getTypes()) {
1401-
if (!reportRelatedTypeRef(Type, Relations, Related, /*isImplicit=*/Implicit, IdLoc))
1402-
return false;
1403-
}
1404-
1405-
return true;
1406-
} else if (auto *declRefTR = dyn_cast_or_null<DeclRefTypeRepr>(Ty.getTypeRepr())) {
1407-
SourceLoc IdLoc = Loc.isValid() ? Loc : declRefTR->getLoc();
1381+
bool IndexSwiftASTWalker::reportRelatedTypeRef(const TypeLoc &Ty, SymbolRoleSet Relations, Decl *Related) {
1382+
if (auto *declRefTR = dyn_cast_or_null<DeclRefTypeRepr>(Ty.getTypeRepr())) {
1383+
SourceLoc IdLoc = declRefTR->getLoc();
14081384
NominalTypeDecl *NTD = nullptr;
1409-
bool isImplicit = Implicit;
1385+
bool isImplicit = false;
14101386
if (auto *VD = declRefTR->getBoundDecl()) {
14111387
if (auto *TAD = dyn_cast<TypeAliasDecl>(VD)) {
14121388
IndexSymbol Info;
1413-
if (isImplicit)
1414-
Info.roles |= (unsigned)SymbolRole::Implicit;
14151389
if (!reportRef(TAD, IdLoc, Info, None))
14161390
return false;
14171391
if (auto Ty = TAD->getUnderlyingType()) {
14181392
NTD = Ty->getAnyNominal();
14191393
isImplicit = true;
14201394
}
1421-
1422-
if (isa_and_nonnull<CompositionTypeRepr>(TAD->getUnderlyingTypeRepr())) {
1423-
TypeLoc TL(TAD->getUnderlyingTypeRepr(), TAD->getUnderlyingType());
1424-
if (!reportRelatedTypeRef(TL, Relations, Related, /*isImplicit=*/true, IdLoc))
1425-
return false;
1426-
}
14271395
} else {
14281396
NTD = dyn_cast<NominalTypeDecl>(VD);
14291397
}

test/Index/conformances.swift

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protocol P3 {
5757
func meth2() // CHECK: [[@LINE]]:8 | instance-method/Swift | meth2() | [[P3_meth2_USR:.*]] | Def
5858
}
5959

60-
class BaseMultiConf { // CHECK: [[@LINE]]:7 | class/Swift | BaseMultiConf | [[BaseMultiConf_USR:.*]] | Def
60+
class BaseMultiConf {
6161
func meth2() {} // CHECK: [[@LINE]]:8 | instance-method/Swift | meth2() | [[BaseMultiConf_meth2_USR:.*]] | Def
6262
}
6363
extension SubMultiConf {
@@ -79,49 +79,6 @@ class SubMultiConf: BaseMultiConf,P2,P1,P3 { // CHECK: [[@LINE]]:7 | class/Swift
7979
// CHECK-NOT: [[@LINE-13]]:7 | instance-method
8080
}
8181

82-
class CompositionType: BaseMultiConf & P1 { // CHECK: [[@LINE]]:7 | class/Swift | CompositionType | [[CompositionType_USR:.*]] | Def
83-
// CHECK: [[@LINE-1]]:24 | class/Swift | BaseMultiConf | [[BaseMultiConf_USR]] | Ref,RelBase | rel: 1
84-
// CHECK: [[@LINE-2]]:24 | protocol/Swift | P1 | [[P1_USR]] | Ref,RelBase | rel: 1
85-
func foo() {}
86-
}
87-
88-
typealias CompositionTypeAlias = BaseMultiConf & P1 // CHECK: [[@LINE]]:11 | type-alias/Swift | CompositionTypeAlias | [[CompositionTypeAlias_USR:.*]] | Def
89-
// CHECK: [[@LINE-1]]:34 | class/Swift | BaseMultiConf | [[BaseMultiConf_USR]] | Ref | rel: 0
90-
// CHECK: [[@LINE-2]]:50 | protocol/Swift | P1 | [[P1_USR]] | Ref | rel: 0
91-
92-
class CompositionTypeViaAlias: CompositionTypeAlias { // CHECK: [[@LINE]]:7 | class/Swift | CompositionTypeViaAlias | [[CompositionTypeViaAlias_USR:.*]] | Def
93-
// CHECK: [[@LINE-1]]:32 | type-alias/Swift | CompositionTypeAlias | [[CompositionTypeAlias_USR]] | Ref | rel: 0
94-
// CHECK: [[@LINE-2]]:32 | class/Swift | BaseMultiConf | [[BaseMultiConf_USR]] | Ref,Impl,RelBase | rel: 1
95-
// CHECK: [[@LINE-3]]:32 | protocol/Swift | P1 | [[P1_USR]] | Ref,Impl,RelBase | rel: 1
96-
func foo() {}
97-
}
98-
99-
typealias NestedCompositionTypeAlias = CompositionTypeAlias & P2 // CHECK: [[@LINE]]:11 | type-alias/Swift | NestedCompositionTypeAlias | [[NestedCompositionTypeAlias_USR:.*]] | Def
100-
// CHECK: [[@LINE-1]]:40 | type-alias/Swift | CompositionTypeAlias | [[CompositionTypeAlias_USR]] | Ref | rel: 0
101-
// CHECK: [[@LINE-2]]:40 | class/Swift | BaseMultiConf | [[BaseMultiConf_USR]] | Ref,Impl | rel: 1
102-
// CHECK: [[@LINE-3]]:40 | protocol/Swift | P1 | [[P1_USR]] | Ref,Impl | rel: 1
103-
// CHECK: [[@LINE-4]]:63 | protocol/Swift | P2 | [[P2_USR]] | Ref | rel: 0
104-
105-
class CompositionViaNestedAlias: NestedCompositionTypeAlias { // CHECK: [[@LINE]]:7 | class/Swift | CompositionViaNestedAlias | [[CompositionViaNestedAlias_USR:.*]] | Def
106-
// CHECK: [[@LINE-1]]:34 | type-alias/Swift | NestedCompositionTypeAlias | [[NestedCompositionTypeAlias_USR]] | Ref | rel: 0
107-
// CHECK: [[@LINE-2]]:34 | class/Swift | BaseMultiConf | [[BaseMultiConf_USR]] | Ref,Impl,RelBase | rel: 1
108-
// CHECK: [[@LINE-3]]:34 | protocol/Swift | P1 | [[P1_USR]] | Ref,Impl,RelBase | rel: 1
109-
// CHECK: [[@LINE-4]]:34 | protocol/Swift | P2 | [[P2_USR]] | Ref,Impl,RelBase | rel: 1
110-
func foo() {}
111-
}
112-
113-
typealias ProtocolsOnly = P1 & P2 // CHECK: [[@LINE]]:11 | type-alias/Swift | ProtocolsOnly | [[ProtocolsOnly_USR:.*]] | Def
114-
// CHECK: [[@LINE-1]]:27 | protocol/Swift | P1 | [[P1_USR]] | Ref | rel: 0
115-
// CHECK: [[@LINE-2]]:32 | protocol/Swift | P2 | [[P2_USR]] | Ref | rel: 0
116-
117-
class NoInherited {} // CHECK: [[@LINE]]:7 | class/Swift | NoInherited | [[NoInherited_USR:.*]] | Def
118-
extension NoInherited: ProtocolsOnly {} // CHECK: [[@LINE]]:11 | class/Swift | NoInherited | [[NoInherited_USR:.*]] | Ref
119-
// CHECK: [[@LINE-1]]:24 | type-alias/Swift | ProtocolsOnly | [[ProtocolsOnly_USR]] | Ref | rel: 0
120-
// CHECK: [[@LINE-2]]:24 | protocol/Swift | P1 | [[P1_USR]] | Ref,Impl | rel: 1
121-
// CHECK: [[@LINE-3]]:24 | protocol/Swift | P2 | [[P2_USR]] | Ref,Impl | rel: 1
122-
123-
struct WithCodable: Codable {} // CHECK: [[@LINE]]:21 | type-alias/Swift | Codable | [[Codable_USR:.*]] | Ref | rel: 0
124-
12582
protocol InheritingP: P1 { // CHECK: [[@LINE]]:10 | protocol/Swift | InheritingP | [[InheritingP_USR:.*]] | Def
12683
func foo() // CHECK: [[@LINE]]:8 | instance-method/Swift | foo() | [[InheritingP_foo_USR:.*]] | Def,Dyn,RelChild,RelOver | rel: 2
12784
// CHECK-NEXT: RelOver | instance-method/Swift | foo() | s:14swift_ide_test2P1P3fooyyF

test/SourceKit/Indexing/index.swift.response

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -455,13 +455,6 @@
455455
key.usr: <usr>,
456456
key.line: 50,
457457
key.column: 19
458-
},
459-
{
460-
key.kind: source.lang.swift.ref.class,
461-
key.usr: <usr>,
462-
key.line: 50,
463-
key.column: 19,
464-
key.is_implicit: 1
465458
}
466459
],
467460
key.effective_access: source.decl.effective_access.internal

0 commit comments

Comments
 (0)