Skip to content

Commit ff544cc

Browse files
authored
Merge pull request swiftlang#9131 from akyrtzi/index-implicit-ctors2
[index] Make sure that we index implicit constructors
2 parents ce2abf1 + b48377b commit ff544cc

18 files changed

+195
-32
lines changed

lib/AST/SourceEntityWalker.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ bool SemaAnnotator::walkToDeclPre(Decl *D) {
9494
bool IsExtension = false;
9595

9696
if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
97-
if (VD->hasName())
97+
if (VD->hasName() && !VD->isImplicit())
9898
NameLen = VD->getName().getLength();
9999

100100
} else if (ExtensionDecl *ED = dyn_cast<ExtensionDecl>(D)) {
@@ -495,7 +495,9 @@ bool SemaAnnotator::passCallArgNames(Expr *Fn, TupleExpr *TupleE) {
495495
}
496496

497497
bool SemaAnnotator::shouldIgnore(Decl *D, bool &ShouldVisitChildren) {
498-
if (D->isImplicit() && !isa<PatternBindingDecl>(D)) {
498+
if (D->isImplicit() &&
499+
!isa<PatternBindingDecl>(D) &&
500+
!isa<ConstructorDecl>(D)) {
499501
ShouldVisitChildren = false;
500502
return true;
501503
}

lib/IDE/SwiftSourceDocInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,8 @@ struct RangeResolver::Implementation {
550550
class CompleteWalker : public SourceEntityWalker {
551551
Implementation *Impl;
552552
bool walkToDeclPre(Decl *D, CharSourceRange Range) override {
553+
if (D->isImplicit())
554+
return false;
553555
Impl->analyzeDecl(D);
554556
return true;
555557
}
@@ -801,6 +803,8 @@ bool RangeResolver::walkToStmtPre(Stmt *S) {
801803
};
802804

803805
bool RangeResolver::walkToDeclPre(Decl *D, CharSourceRange Range) {
806+
if (D->isImplicit())
807+
return false;
804808
if (!Impl->shouldEnter(D))
805809
return false;
806810
Impl->analyze(D);

lib/Index/Index.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
464464
}
465465

466466
bool shouldIndex(ValueDecl *D, bool IsRef) const {
467-
if (D->isImplicit())
467+
if (D->isImplicit() && !isa<ConstructorDecl>(D))
468468
return false;
469469
if (!IdxConsumer.indexLocals() && isLocalSymbol(D) && (!isa<ParamDecl>(D) || IsRef))
470470
return false;
@@ -1004,6 +1004,8 @@ bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
10041004
addRelation(Info, (unsigned)SymbolRole::RelationContainedBy, Parent);
10051005
} else {
10061006
Info.roles |= (unsigned)SymbolRole::Definition;
1007+
if (D->isImplicit())
1008+
Info.roles |= (unsigned)SymbolRole::Implicit;
10071009
}
10081010

10091011
if (getNameAndUSR(D, /*ExtD=*/nullptr, Info.name, Info.USR))

lib/Migrator/SyntacticMigratorPass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ struct SyntacticMigratorPass::Implementation : public SourceEntityWalker {
390390
}
391391

392392
bool walkToDeclPre(Decl *D, CharSourceRange Range) override {
393+
if (D->isImplicit())
394+
return true;
393395
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(D)) {
394396
for (auto *Item: getRelatedDiffItems(AFD)) {
395397
if (auto *DiffItem = dyn_cast<CommonDiffItem>(Item)) {

test/IDE/reconstruct_type_from_mangled_name.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ struct Mystruct1 {
66
// CHECK: decl: func s1f1() -> Int
77
var intField = 3
88
// CHECK: decl: var intField: Int
9+
// CHECK: decl: init(intField: Int)
10+
// CHECK: decl: init()
911
}
1012
struct MyStruct2 {
1113
// CHECK: decl: struct MyStruct2
@@ -21,23 +23,21 @@ class Myclass1 {
2123
// CHECK: decl: class Myclass1
2224
var intField = 4
2325
// CHECK: decl: var intField: Int
26+
// CHECK: decl: init()
2427
}
2528

2629
func f1() {
2730
// CHECK: decl: func f1()
2831
var s1ins = Mystruct1() // Implicit ctor
2932
// CHECK: decl: var s1ins: Mystruct1
30-
// CHECK: dref: init() for 'Mystruct1'
3133
_ = Mystruct1(intField: 1) // Implicit ctor
32-
// CHECK: dref: init(intField: Int) for 'Mystruct1'
3334

3435
s1ins.intField = 34
3536
// CHECK: type: Mystruct1
3637
// CHECK: type: Int
3738

3839
var c1ins = Myclass1()
3940
// CHECK: decl: var c1ins: Myclass1
40-
// CHECK: dref: init() for 'Myclass1'
4141
// CHECK: type: Myclass1
4242

4343
c1ins.intField = 3
@@ -258,13 +258,12 @@ func hasLocalDecls() {
258258

259259
// FIXME
260260
// CHECK: decl: FAILURE for 'LocalType'
261+
// The following is the implicit ctor
262+
// CHECK: decl: FAILURE for ''
261263
struct LocalType {}
262264

263265
// CHECK: decl: FAILURE for 'LocalAlias'
264266
typealias LocalAlias = LocalType
265-
266-
// CHECK: dref: FAILURE for 'LocalType'
267-
let x: LocalAlias = LocalType()
268267
}
269268

270269
fileprivate struct VeryPrivateData {}

test/Index/Inputs/cross_language.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ -(void)someMethFromObjC;
1212
void test1() {
1313
MyCls1 *o = [[MyCls1 alloc] init];
1414
// CHECK: [[@LINE-1]]:3 | class/Swift | MyCls1 | [[MyCls1_USR]] |
15-
// CHECK: [[@LINE-2]]:31 | instance-method/Swift | init | c:@M@cross_language@objc(cs)MyCls1(im)init |
15+
// CHECK: [[@LINE-2]]:31 | instance-method/Swift | init | [[MyCls1_init_USR]] |
1616
// CHECK: [[@LINE-3]]:17 | class/Swift | MyCls1 | [[MyCls1_USR]] |
1717
[o someMeth];
1818
// CHECK: [[@LINE-1]]:6 | instance-method/Swift | someMeth | [[MyCls1_someMeth_USR]] |

test/Index/cross_language.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import Foundation
1919
// CHECK: [[@LINE-1]]:20 | class/Swift | MyCls1 | [[MyCls1_USR:.*]] | Def
2020
@objc public func someMeth() {}
2121
// CHECK: [[@LINE-1]]:21 | instance-method/Swift | someMeth() | [[MyCls1_someMeth_USR:.*]] | Def
22+
// CHECK: [[@LINE-4]]:38 | constructor/Swift | init() | [[MyCls1_init_USR:.*]] | Def,Impl,RelChild,RelOver | rel: 2
23+
// CHECK-NEXT: RelOver | constructor/Swift | init() | c:objc(cs)NSObject(im)init
24+
// CHECK-NEXT: RelChild | class/Swift | MyCls1 | [[MyCls1_USR]]
2225
}
2326

2427
@objc public class MyCls2 : NSObject {

test/Index/index_module.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,21 @@ public var someGlobal: Int = 0
1616
public func someFunc() {}
1717
// CHECK: [[@LINE-1]]:13 | function/Swift | someFunc() | [[SOMEFUNC_USR:.*]] | Def | rel: 0
1818

19+
public class CCC {}
20+
// CHECK: [[@LINE-1]]:14 | class/Swift | CCC | [[CCC_USR:.*]] | Def | rel: 0
21+
// CHECK: [[@LINE-2]]:14 | constructor/Swift | init() | [[CCC_init_USR:.*]] | Def,Impl,RelChild | rel: 1
22+
// CHECK-NEXT: RelChild | class/Swift | CCC | [[CCC_USR]]
23+
1924
// --- Check the module ---
2025

26+
// CHECK: 0:0 | function/Swift | someFunc() | [[SOMEFUNC_USR]] | Def | rel: 0
27+
28+
// CHECK: 0:0 | class/Swift | CCC | [[CCC_USR]] | Def | rel: 0
29+
// CHECK: 0:0 | constructor/Swift | init() | [[CCC_init_USR]] | Def,Impl,RelChild | rel: 1
30+
// CHECK-NEXT: RelChild | class/Swift | CCC | [[CCC_USR]]
31+
2132
// CHECK: 0:0 | variable/Swift | someGlobal | [[SOMEGLOBAL_USR]] | Def | rel: 0
2233
// CHECK: 0:0 | function/acc-get/Swift | getter:someGlobal | [[SOMEGLOBAL_GET_USR:.*]] | Def,Impl,RelChild,RelAcc | rel: 1
2334
// CHECK-NEXT: RelChild,RelAcc | variable/Swift | someGlobal | [[SOMEGLOBAL_USR]]
2435
// CHECK: 0:0 | function/acc-set/Swift | setter:someGlobal | [[SOMEGLOBAL_SET_USR:.*]] | Def,Impl,RelChild,RelAcc | rel: 1
2536
// CHECK-NEXT: RelChild,RelAcc | variable/Swift | someGlobal | [[SOMEGLOBAL_USR]]
26-
27-
// CHECK: 0:0 | function/Swift | someFunc() | [[SOMEFUNC_USR]] | Def | rel: 0

test/Index/kinds.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,16 @@ typealias C1Alias = C1
242242
// CHECK: [[@LINE+2]]:15 | class/Swift | C1 | [[C1_USR]] | Ref,Impl,RelBase | rel: 1
243243
// CHECK-NEXT: RelBase | class/Swift | SubC1 | [[SubC1_USR]]
244244
class SubC1 : C1Alias {}
245+
246+
struct ImplCtors {
247+
// CHECK: [[@LINE-1]]:8 | struct/Swift | ImplCtors | [[ImplCtors_USR:.*]] | Def | rel: 0
248+
// CHECK: [[@LINE-2]]:8 | constructor/Swift | init(x:) | [[ImplCtors_init_with_param_USR:.*]] | Def,Impl,RelChild | rel: 1
249+
// CHECK-NEXT: RelChild | struct/Swift | ImplCtors | [[ImplCtors_USR]]
250+
// CHECK: [[@LINE-4]]:8 | constructor/Swift | init() | [[ImplCtors_init_USR:.*]] | Def,Impl,RelChild | rel: 1
251+
// CHECK-NEXT: RelChild | struct/Swift | ImplCtors | [[ImplCtors_USR]]
252+
var x = 0
253+
}
254+
_ = ImplCtors()
255+
// CHECK: [[@LINE-1]]:5 | constructor/Swift | init() | [[ImplCtors_init_USR]] | Ref,Call | rel: 0
256+
_ = ImplCtors(x:0)
257+
// CHECK: [[@LINE-1]]:5 | constructor/Swift | init(x:) | [[ImplCtors_init_with_param_USR]] | Ref,Call | rel: 0

test/SourceKit/DocSupport/doc_source_file.swift.response

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,15 +2353,7 @@
23532353
key.usr: "s:8__main__3CC2C9subscriptS2icfg",
23542354
key.offset: 1162,
23552355
key.length: 25,
2356-
key.fully_annotated_decl: "<decl.function.accessor.getter><decl.name>get</decl.name> {}</decl.function.accessor.getter>",
2357-
key.entities: [
2358-
{
2359-
key.kind: source.lang.swift.decl.var.local,
2360-
key.name: "i",
2361-
key.offset: 1144,
2362-
key.length: 3
2363-
}
2364-
]
2356+
key.fully_annotated_decl: "<decl.function.accessor.getter><decl.name>get</decl.name> {}</decl.function.accessor.getter>"
23652357
},
23662358
{
23672359
key.kind: source.lang.swift.decl.function.accessor.setter,
@@ -2375,12 +2367,6 @@
23752367
key.name: "vvv",
23762368
key.offset: 1152,
23772369
key.length: 3
2378-
},
2379-
{
2380-
key.kind: source.lang.swift.decl.var.local,
2381-
key.name: "i",
2382-
key.offset: 1144,
2383-
key.length: 3
23842370
}
23852371
]
23862372
}

0 commit comments

Comments
 (0)