Skip to content

Commit fd7d59d

Browse files
committed
[CursorInfo] Add a synthesized field
Mark implicit declarations with a `synthesized` field, since while we still want them to have a cursor info result (eg. for their USR to find possible overrides), it's likely that clients will want to treat them differently to results that have a real location in source. An alternative could be to remove the location entirely, but: - the module name would also have to be removed to prevent wasted lookups in the generated interface - having the location could still be useful as the location that caused the synthesized declaration (though at the moment only synthesized initializers have a location) Resolves rdar://84990655
1 parent 4592132 commit fd7d59d

File tree

6 files changed

+44
-0
lines changed

6 files changed

+44
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
struct Synthesized: Hashable {
2+
let a: Int
3+
// RUN: %sourcekitd-test -req=cursor -pos=%(line-1):10 %s -- %s -target %target-triple | %FileCheck -check-prefix=INT %s
4+
// INT: Int
5+
// INT-NEXT: s:Si
6+
// INT-NOT: SYNTHESIZED
7+
}
8+
9+
func synthesized(hasher: inout Hasher) {
10+
let s = Synthesized(a: 1)
11+
// RUN: %sourcekitd-test -req=cursor -pos=%(line-1):11 %s -- %s -target %target-triple | %FileCheck -check-prefix=INIT %s
12+
// INIT: Synthesized
13+
// INIT-NEXT: s:18cursor_synthesized11SynthesizedV
14+
// INIT-NOT: SYNTHESIZED
15+
// INIT: SECONDARY SYMBOLS BEGIN
16+
// INIT: init(a:)
17+
// INIT-NEXT: s:18cursor_synthesized11SynthesizedV1aACSi_tcfc
18+
// INIT: SYNTHESIZED
19+
// INIT: -----
20+
// INIT: SECONDARY SYMBOLS END
21+
22+
_ = s.hashValue
23+
// RUN: %sourcekitd-test -req=cursor -pos=%(line-1):9 %s -- %s -target %target-triple | %FileCheck -check-prefix=HASH_VALUE %s
24+
// HASH_VALUE: hashValue
25+
// HASH_VALUE-NEXT: s:18cursor_synthesized11SynthesizedV9hashValueSivp
26+
// HASH_VALUE: SYNTHESIZED
27+
28+
_ = s.hash(into: &hasher)
29+
// RUN: %sourcekitd-test -req=cursor -pos=%(line-1):9 %s -- %s -target %target-triple | %FileCheck -check-prefix=HASH %s
30+
// HASH: hash(into:)
31+
// HASH-NEXT: s:18cursor_synthesized11SynthesizedV4hash4intoys6HasherVz_tF
32+
// HASH: SYNTHESIZED
33+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ struct CursorSymbolInfo {
486486

487487
bool IsSystem = false;
488488
bool IsDynamic = false;
489+
bool IsSynthesized = false;
489490

490491
llvm::Optional<unsigned> ParentNameOffset;
491492
};

tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,8 @@ fillSymbolInfo(CursorSymbolInfo &Symbol, const DeclInfo &DInfo,
11141114

11151115
Symbol.IsSystem = DInfo.VD->getModuleContext()->isSystemModule();
11161116
Symbol.IsDynamic = DInfo.IsDynamic;
1117+
Symbol.IsSynthesized = DInfo.VD->isImplicit();
1118+
11171119
Symbol.ParentNameOffset = getParamParentNameOffset(DInfo.VD, CursorLoc);
11181120

11191121
return llvm::Error::success();

tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,7 @@ struct ResponseSymbolInfo {
17111711
std::vector<const char *> ReceiverUSRs;
17121712
bool IsSystem = false;
17131713
bool IsDynamic = false;
1714+
bool IsSynthesized = false;
17141715
unsigned ParentOffset = 0;
17151716

17161717
static ResponseSymbolInfo read(sourcekitd_variant_t Info) {
@@ -1802,6 +1803,8 @@ struct ResponseSymbolInfo {
18021803
Symbol.IsSystem = sourcekitd_variant_dictionary_get_bool(Info, KeyIsSystem);
18031804
Symbol.IsDynamic =
18041805
sourcekitd_variant_dictionary_get_bool(Info, KeyIsDynamic);
1806+
Symbol.IsSynthesized =
1807+
sourcekitd_variant_dictionary_get_bool(Info, KeyIsSynthesized);
18051808

18061809
Symbol.ParentOffset =
18071810
sourcekitd_variant_dictionary_get_int64(Info, KeyParentLoc);
@@ -1864,6 +1867,8 @@ struct ResponseSymbolInfo {
18641867
}
18651868
if (IsDynamic)
18661869
OS << "DYNAMIC\n";
1870+
if (IsSynthesized)
1871+
OS << "SYNTHESIZED\n";
18671872
if (ParentOffset) {
18681873
OS << "PARENT OFFSET: " << ParentOffset << "\n";
18691874
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,6 +1910,8 @@ static void addCursorSymbolInfo(const CursorSymbolInfo &Symbol,
19101910
Elem.setBool(KeyIsSystem, true);
19111911
if (Symbol.IsDynamic)
19121912
Elem.setBool(KeyIsDynamic, true);
1913+
if (Symbol.IsSynthesized)
1914+
Elem.setBool(KeyIsSynthesized, true);
19131915

19141916
if (Symbol.ParentNameOffset)
19151917
Elem.set(KeyParentLoc, Symbol.ParentNameOffset.getValue());

utils/gyb_sourcekit_support/UIDs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ def __init__(self, internal_name, external_name):
202202
# Before executing the actual request wait x ms. The request can be canceled
203203
# in this time. For cancellation testing purposes.
204204
KEY('SimulateLongRequest', 'key.simulate_long_request'),
205+
KEY('IsSynthesized', 'key.is_synthesized'),
205206
]
206207

207208

0 commit comments

Comments
 (0)