Skip to content

Commit b97c636

Browse files
authored
Merge pull request #1 from skrtks/local-symbols
Local symbols
2 parents 4c7e02d + c84ab10 commit b97c636

File tree

5 files changed

+67
-104
lines changed

5 files changed

+67
-104
lines changed

test/SourceKit/Indexing/index_locals.swift

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -7,80 +7,6 @@ func foo(a: Int, b: Double) {
77
var locVar = 1
88
}
99

10-
var globalVar = 2
1110

12-
class A : ExpressibleByIntegerLiteral {
13-
required init(integerLiteral value: IntegerLiteralType) {}
14-
}
15-
16-
func bar() {
17-
var locVar1: A = 1
18-
let locVar2 = 2
19-
foo(a: globalVar, b: Double(locVar2))
20-
let closure = { (arg1: Int, arg2: Int) -> Int in
21-
let locVar3 = 3
22-
let expr: Int = locVar2 + globalVar + arg1
23-
return expr
24-
}
25-
}
26-
27-
class X {
28-
func baz() {
29-
func inner(_ x: Int) -> Int { return x }
30-
var arr: [Int] = [1, 2, 3]
31-
if (globalVar > 2) {
32-
arr = arr.map { inner($0) }
33-
}
34-
}
35-
}
36-
37-
38-
// CHECK: function/Swift | foo(a:b:) | s:12index_locals3foo1a1bySi_SdtF | <no-cgname> | Def,Ref,Call,RelCall,RelCont - RelChild,RelCont
39-
// CHECK-NEXT: param/Swift | a | s:12index_locals3foo1a1bySi_SdtFACL_Sivp | <no-cgname> | Def,RelChild -
40-
// CHECK-NEXT: struct/Swift | Int | s:Si | <no-cgname> | Ref,RelCont -
41-
// CHECK-NEXT: param/Swift | b | s:12index_locals3foo1a1bySi_SdtFADL_Sdvp | <no-cgname> | Def,RelChild -
42-
// CHECK-NEXT: struct/Swift | Double | s:Sd | <no-cgname> | Ref,RelCont -
43-
// CHECK-NEXT: function/acc-get(local)/Swift | getter:locVar | s:12index_locals3foo1a1bySi_SdtF6locVarL_Sivg | <no-cgname> | Def,Impl,RelChild,RelAcc -
44-
// CHECK-NEXT: variable(local)/Swift | locVar | s:12index_locals3foo1a1bySi_SdtF6locVarL_Sivp | <no-cgname> | Def,RelChild - RelChild,RelAcc
11+
// CHECK: variable(local)/Swift | locVar | s:12index_locals3foo1a1bySi_SdtF6locVarL_Sivp | <no-cgname> | Def,RelChild - RelChild,RelAcc
4512
// CHECK-NEXT: function/acc-set(local)/Swift | setter:locVar | s:12index_locals3foo1a1bySi_SdtF6locVarL_Sivs | <no-cgname> | Def,Impl,RelChild,RelAcc -
46-
// CHECK-NEXT: function/acc-get/Swift | getter:globalVar | s:12index_locals9globalVarSivg | <no-cgname> | Def,Ref,Call,Impl,RelChild,RelCall,RelAcc,RelCont -
47-
// CHECK-NEXT: variable/Swift | globalVar | s:12index_locals9globalVarSivp | <no-cgname> | Def,Ref,Read,RelCont - RelChild,RelAcc
48-
// CHECK-NEXT: function/acc-set/Swift | setter:globalVar | s:12index_locals9globalVarSivs | <no-cgname> | Def,Impl,RelChild,RelAcc -
49-
// CHECK-NEXT: class/Swift | A | s:12index_locals1AC | <no-cgname> | Def,Ref,RelCont - RelChild,RelBase
50-
// CHECK-NEXT: protocol/Swift | ExpressibleByIntegerLiteral | s:s27ExpressibleByIntegerLiteralP | <no-cgname> | Ref,RelBase -
51-
// CHECK-NEXT: constructor/Swift | init(integerLiteral:) | s:12index_locals1AC14integerLiteralACSi_tcfc | <no-cgname> | Def,Ref,Call,Impl,RelChild,RelOver,RelCall,RelCont - RelChild,RelCont
52-
// CHECK-NEXT: constructor/Swift | init(integerLiteral:) | s:s27ExpressibleByIntegerLiteralP07integerD0x0cD4TypeQz_tcfc | <no-cgname> | - RelOver
53-
// CHECK-NEXT: param(local)/Swift | value | s:12index_locals1AC14integerLiteralACSi_tcfc5valueL_Sivp | <no-cgname> | Def,RelChild -
54-
// CHECK-NEXT: type-alias/Swift | IntegerLiteralType | s:s18IntegerLiteralTypea | <no-cgname> | Ref,RelCont -
55-
// CHECK-NEXT: function/Swift | bar() | s:12index_locals3baryyF | <no-cgname> | Def - RelChild,RelCall,RelCont
56-
// CHECK-NEXT: function/acc-get(local)/Swift | getter:locVar1 | s:12index_locals3baryyF7locVar1L_AA1ACvg | <no-cgname> | Def,Impl,RelChild,RelAcc -
57-
// CHECK-NEXT: variable(local)/Swift | locVar1 | s:12index_locals3baryyF7locVar1L_AA1ACvp | <no-cgname> | Def,RelChild - RelChild,RelAcc,RelCont
58-
// CHECK-NEXT: function/acc-set(local)/Swift | setter:locVar1 | s:12index_locals3baryyF7locVar1L_AA1ACvs | <no-cgname> | Def,Impl,RelChild,RelAcc -
59-
// CHECK-NEXT: function/acc-get(local)/Swift | getter:locVar2 | s:12index_locals3baryyF7locVar2L_Sivg | <no-cgname> | Def,Ref,Call,Impl,RelChild,RelCall,RelAcc,RelCont -
60-
// CHECK-NEXT: variable(local)/Swift | locVar2 | s:12index_locals3baryyF7locVar2L_Sivp | <no-cgname> | Def,Ref,Read,RelChild,RelCont - RelChild,RelAcc
61-
// CHECK-NEXT: function/acc-set(local)/Swift | setter:locVar2 | s:12index_locals3baryyF7locVar2L_Sivs | <no-cgname> | Def,Impl,RelChild,RelAcc -
62-
// CHECK-NEXT: constructor/Swift | init(_:) | s:SdySdSicfc | <no-cgname> | Ref,Call,RelCall,RelCont -
63-
// CHECK-NEXT: function/acc-get(local)/Swift | getter:closure | s:12index_locals3baryyF7closureL_yS2i_Sitcvg | <no-cgname> | Def,Impl,RelChild,RelAcc -
64-
// CHECK-NEXT: variable(local)/Swift | closure | s:12index_locals3baryyF7closureL_yS2i_Sitcvp | <no-cgname> | Def,RelChild - RelChild,RelAcc,RelCont
65-
// CHECK-NEXT: function/acc-set(local)/Swift | setter:closure | s:12index_locals3baryyF7closureL_yS2i_Sitcvs | <no-cgname> | Def,Impl,RelChild,RelAcc -
66-
// CHECK-NEXT: param(local)/Swift | arg1 | s:12index_locals3baryyFS2i_SitcfU_4arg1L_Sivp | <no-cgname> | Def,Ref,Read,RelChild,RelCont -
67-
// CHECK-NEXT: param(local)/Swift | arg2 | s:12index_locals3baryyFS2i_SitcfU_4arg2L_Sivp | <no-cgname> | Def,RelChild -
68-
// CHECK-NEXT: function/acc-get(local)/Swift | getter:locVar3 | s:12index_locals3baryyFS2i_SitcfU_7locVar3L_Sivg | <no-cgname> | Def,Impl,RelChild,RelAcc -
69-
// CHECK-NEXT: variable(local)/Swift | locVar3 | s:12index_locals3baryyFS2i_SitcfU_7locVar3L_Sivp | <no-cgname> | Def,RelChild - RelChild,RelAcc
70-
// CHECK-NEXT: function/acc-set(local)/Swift | setter:locVar3 | s:12index_locals3baryyFS2i_SitcfU_7locVar3L_Sivs | <no-cgname> | Def,Impl,RelChild,RelAcc -
71-
// CHECK-NEXT: function/acc-get(local)/Swift | getter:expr | s:12index_locals3baryyFS2i_SitcfU_4exprL_Sivg | <no-cgname> | Def,Ref,Call,Impl,RelChild,RelCall,RelAcc,RelCont -
72-
// CHECK-NEXT: variable(local)/Swift | expr | s:12index_locals3baryyFS2i_SitcfU_4exprL_Sivp | <no-cgname> | Def,Ref,Read,RelChild,RelCont - RelChild,RelAcc,RelCont
73-
// CHECK-NEXT: function/acc-set(local)/Swift | setter:expr | s:12index_locals3baryyFS2i_SitcfU_4exprL_Sivs | <no-cgname> | Def,Impl,RelChild,RelAcc -
74-
// CHECK-NEXT: static-method/infix-operator/Swift | +(_:_:) | s:Si1poiyS2i_SitFZ | <no-cgname> | Ref,Call,RelCall,RelCont -
75-
// CHECK-NEXT: constructor/Swift | init() | s:12index_locals1XCACycfc | <no-cgname> | Def,Impl,RelChild -
76-
// CHECK-NEXT: class/Swift | X | s:12index_locals1XC | <no-cgname> | Def - RelChild
77-
// CHECK-NEXT: instance-method/Swift | baz() | s:12index_locals1XC3bazyyF | <no-cgname> | Def,Dyn,RelChild - RelChild,RelCall,RelCont
78-
// CHECK-NEXT: function(local)/Swift | inner(_:) | s:12index_locals1XC3bazyyF5innerL_yS2iF | <no-cgname> | Def,Ref,Call,RelChild,RelCall,RelCont - RelChild,RelCont
79-
// CHECK-NEXT: param(local)/Swift | x | s:12index_locals1XC3bazyyF5innerL_yS2iF1xL_Sivp | <no-cgname> | Def,Ref,Read,RelChild,RelCont -
80-
// CHECK-NEXT: function/acc-get(local)/Swift | getter:arr | s:12index_locals1XC3bazyyF3arrL_SaySiGvg | <no-cgname> | Def,Ref,Call,Impl,RelChild,RelCall,RelAcc,RelCont -
81-
// CHECK-NEXT: variable(local)/Swift | arr | s:12index_locals1XC3bazyyF3arrL_SaySiGvp | <no-cgname> | Def,Ref,Read,Writ,RelChild,RelCont - RelChild,RelAcc,RelCont
82-
// CHECK-NEXT: function/acc-set(local)/Swift | setter:arr | s:12index_locals1XC3bazyyF3arrL_SaySiGvs | <no-cgname> | Def,Ref,Call,Impl,RelChild,RelCall,RelAcc,RelCont -
83-
// CHECK-NEXT: constructor/Swift | init(arrayLiteral:) | s:Sa12arrayLiteralSayxGxd_tcfc | <no-cgname> | Ref,Call,Impl,RelCall,RelCont -
84-
// CHECK-NEXT: static-method/infix-operator/Swift | >(_:_:) | s:Si1goiySbSi_SitFZ | <no-cgname> | Ref,Call,RelCall,RelCont -
85-
// CHECK-NEXT: instance-method/Swift | map(_:) | s:SlsE3mapySayqd__Gqd__7ElementQzKXEKlF | <no-cgname> | Ref,Call,Dyn,RelRec,RelCall,RelCont -
86-
// CHECK-NEXT: struct/Swift | Array | s:Sa | <no-cgname> | - RelRec

tools/SourceKit/include/SourceKit/Core/LangSupport.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,10 @@ struct RenameLocations {
881881
struct IndexStoreOptions {
882882
std::string IndexStorePath;
883883
std::string IndexUnitOutputPath;
884+
bool IgnoreClangModules = false;
885+
bool IncludeSystemModules = false;
886+
bool IgnoreStdlib = false;
887+
bool DisableImplicitModules = false;
884888
bool IncludeLocals = false;
885889
};
886890

tools/SourceKit/lib/SwiftLang/SwiftIndexing.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,11 @@ void SwiftLangSupport::indexSource(StringRef InputFile,
370370
}
371371

372372
static void emitIndexDataForSourceFile(SourceFile &PrimarySourceFile,
373-
StringRef IndexStorePath,
374-
StringRef IndexUnitOutputPath,
375-
bool IncludeLocals,
373+
IndexStoreOptions IndexOpts,
376374
const CompilerInstance &Instance) {
377375
const auto &Invocation = Instance.getInvocation();
378-
const auto &Opts = Invocation.getFrontendOptions();
376+
// FIXME: Compiler arguments should be the default for setting options, but this is currently broken (see PR #69076)
377+
// const auto &Opts = Invocation.getFrontendOptions();
379378

380379
bool isDebugCompilation;
381380
switch (Invocation.getSILOptions().OptMode) {
@@ -389,14 +388,15 @@ static void emitIndexDataForSourceFile(SourceFile &PrimarySourceFile,
389388
break;
390389
}
391390

392-
(void) index::indexAndRecord(&PrimarySourceFile, IndexUnitOutputPath,
393-
IndexStorePath,
394-
!Opts.IndexIgnoreClangModules,
395-
Opts.IndexSystemModules,
396-
Opts.IndexIgnoreStdlib,
397-
IncludeLocals,
391+
(void) index::indexAndRecord(&PrimarySourceFile,
392+
IndexOpts.IndexUnitOutputPath,
393+
IndexOpts.IndexStorePath,
394+
!IndexOpts.IgnoreClangModules,
395+
IndexOpts.IncludeSystemModules,
396+
IndexOpts.IgnoreStdlib,
397+
IndexOpts.IncludeLocals,
398398
isDebugCompilation,
399-
Opts.DisableImplicitModules,
399+
IndexOpts.DisableImplicitModules,
400400
Invocation.getTargetTriple(),
401401
*Instance.getDependencyTracker(),
402402
Invocation.getIRGenOptions().FilePrefixMap);
@@ -426,9 +426,7 @@ void SwiftLangSupport::indexToStore(
426426
void handlePrimaryAST(ASTUnitRef AstUnit) override {
427427
auto &SF = AstUnit->getPrimarySourceFile();
428428
auto &CI = AstUnit->getCompilerInstance();
429-
emitIndexDataForSourceFile(SF, Opts.IndexStorePath,
430-
Opts.IndexUnitOutputPath, Opts.IncludeLocals,
431-
CI);
429+
emitIndexDataForSourceFile(SF, Opts, CI);
432430
Receiver(RequestResult<IndexStoreInfo>::fromResult(IndexStoreInfo{}));
433431
}
434432

tools/SourceKit/tools/sourcekitd/lib/Service/Requests.cpp

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,48 @@ static void handleRequestIndex(const RequestDict &Req,
14211421
});
14221422
}
14231423
1424+
static std::optional<IndexStoreOptions>
1425+
getIndexStoreOpts(const RequestDict &Req, ResponseReceiver Rec) {
1426+
IndexStoreOptions Opts;
1427+
if (auto IndexStorePath = Req.getString(KeyIndexStorePath))
1428+
Opts.IndexStorePath = IndexStorePath->str();
1429+
else {
1430+
Rec(createErrorRequestInvalid("'key.index_store_path' is required"));
1431+
return std::nullopt;
1432+
}
1433+
1434+
if (auto IndexUnitOutputPath = Req.getString(KeyIndexUnitOutputPath))
1435+
Opts.IndexUnitOutputPath = IndexUnitOutputPath->str();
1436+
else {
1437+
Rec(createErrorRequestInvalid("'key.index_unit_output_path' is required"));
1438+
return std::nullopt;
1439+
}
1440+
1441+
if (auto IncludeLocals = Req.getOptionalInt64(KeyIncludeLocals)) {
1442+
Opts.IncludeLocals = IncludeLocals.value() > 0;
1443+
}
1444+
1445+
if (auto IgnoreClangModules = Req.getOptionalInt64(KeyIgnoreClangModules)) {
1446+
Opts.IgnoreClangModules = IgnoreClangModules.value() > 0;
1447+
}
1448+
1449+
if (auto IncludeSystemModules =
1450+
Req.getOptionalInt64(KeyIncludeSystemModules)) {
1451+
Opts.IncludeSystemModules = IncludeSystemModules.value() > 0;
1452+
}
1453+
1454+
if (auto IgnoreStdlib = Req.getOptionalInt64(KeyIgnoreStdlib)) {
1455+
Opts.IgnoreStdlib = IgnoreStdlib.value() > 0;
1456+
}
1457+
1458+
if (auto DisableImplicitModules =
1459+
Req.getOptionalInt64(KeyDisableImplicitModules)) {
1460+
Opts.DisableImplicitModules = DisableImplicitModules.value() > 0;
1461+
}
1462+
1463+
return Opts;
1464+
}
1465+
14241466
static void handleRequestIndexToStore(
14251467
const RequestDict &Req, SourceKitCancellationToken CancellationToken,
14261468
ResponseReceiver Rec) {
@@ -1433,26 +1475,15 @@ static void handleRequestIndexToStore(
14331475
if (!PrimaryFilePath)
14341476
return;
14351477
1436-
IndexStoreOptions Opts;
1437-
if (auto IndexStorePath = Req.getString(KeyIndexStorePath))
1438-
Opts.IndexStorePath = IndexStorePath->str();
1439-
else
1440-
return Rec(createErrorRequestInvalid("'key.index_store_path' is required"));
1441-
1442-
if (auto IndexUnitOutputPath = Req.getString(KeyIndexUnitOutputPath))
1443-
Opts.IndexUnitOutputPath = IndexUnitOutputPath->str();
1444-
else
1445-
return Rec(createErrorRequestInvalid("'key.index_unit_output_path' is required"));
1446-
1447-
if (auto IncludeLocals = Req.getOptionalInt64(KeyIncludeLocals)) {
1448-
Opts.IncludeLocals = IncludeLocals.value() > 0;
1449-
}
1478+
std::optional<IndexStoreOptions> Opts = getIndexStoreOpts(Req, Rec);
1479+
if (!Opts)
1480+
return;
14501481
14511482
SmallVector<const char *, 0> Args;
14521483
if (getCompilerArgumentsForRequestOrEmitError(Req, Args, Rec))
14531484
return;
14541485
LangSupport &Lang = getGlobalContext().getSwiftLangSupport();
1455-
Lang.indexToStore(*PrimaryFilePath, Args, std::move(Opts),
1486+
Lang.indexToStore(*PrimaryFilePath, Args, std::move(*Opts),
14561487
CancellationToken,
14571488
[Rec](const RequestResult<IndexStoreInfo> &Result) {
14581489
if (Result.isCancelled())

utils/gyb_sourcekit_support/UIDs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ def __init__(self, internal_name, external_name):
215215
KEY('IndexStorePath', 'key.index_store_path'),
216216
KEY('IndexUnitOutputPath', 'key.index_unit_output_path'),
217217
KEY('IncludeLocals', 'key.include_locals'),
218+
KEY('IgnoreClangModules', 'key.ignore_clang_modules'),
219+
KEY('IncludeSystemModules', 'key.include_system_modules'),
220+
KEY('IgnoreStdlib', 'key.ignore_stdlib'),
221+
KEY('DisableImplicitModules', 'key.disable_implicit_modules'),
218222
]
219223

220224

0 commit comments

Comments
 (0)