Skip to content

Commit ae24917

Browse files
authored
Merge pull request #21083 from nkcsgexi/doc-support-5.0
[5.0] cherry-pick sourcekit doc-support fixes
2 parents 565e767 + 31ae83b commit ae24917

File tree

13 files changed

+922
-881
lines changed

13 files changed

+922
-881
lines changed

include/swift/AST/GenericSignature.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ class alignas(1 << TypeAlignInBits) GenericSignature final
313313
ArrayRef<Requirement> requirements);
314314

315315
void print(raw_ostream &OS, PrintOptions Options = PrintOptions()) const;
316+
void print(ASTPrinter &Printer, PrintOptions Opts = PrintOptions()) const;
316317
void dump() const;
317318
std::string getAsString() const;
318319
};

lib/AST/ASTPrinter.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,13 +1391,10 @@ void PrintAST::printSingleDepthOfGenericSignature(
13911391
}
13921392
} else {
13931393
Printer.callPrintStructurePre(PrintStructureKind::GenericRequirement);
1394-
if (second) {
1395-
Requirement substReq(req.getKind(), first, second);
1396-
printRequirement(substReq);
1397-
} else {
1398-
Requirement substReq(req.getKind(), first, req.getLayoutConstraint());
1399-
printRequirement(substReq);
1400-
}
1394+
1395+
// We don't substitute type for the printed requirement so that the
1396+
// printed requirement agrees with separately reported generic parameters.
1397+
printRequirement(req);
14011398
Printer.printStructurePost(PrintStructureKind::GenericRequirement);
14021399
}
14031400
}
@@ -4135,11 +4132,15 @@ void LayoutConstraintInfo::print(ASTPrinter &Printer,
41354132

41364133
void GenericSignature::print(raw_ostream &OS, PrintOptions Opts) const {
41374134
StreamPrinter Printer(OS);
4138-
PrintAST(Printer, Opts)
4139-
.printGenericSignature(this,
4140-
PrintAST::PrintParams |
4141-
PrintAST::PrintRequirements);
4135+
print(Printer, Opts);
4136+
}
4137+
4138+
void GenericSignature::print(ASTPrinter &Printer, PrintOptions Opts) const {
4139+
PrintAST(Printer, Opts).printGenericSignature(this,
4140+
PrintAST::PrintParams |
4141+
PrintAST::PrintRequirements);
41424142
}
4143+
41434144
void GenericSignature::dump() const {
41444145
print(llvm::errs());
41454146
llvm::errs() << '\n';

test/IDE/print_ast_tc_decls.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ protocol ProtocolWithWhereClauseAndAssoc : QuxProtocol where Qux == Int {
13581358

13591359
// FIXME: this same type requirement with Self should be printed here
13601360
associatedtype A2 : QuxProtocol where A2.Qux == Self
1361-
// PREFER_TYPE_REPR_PRINTING-DAG: {{^}} associatedtype A2 : QuxProtocol where Self.A2.Qux == Self{{$}}
1361+
// PREFER_TYPE_REPR_PRINTING-DAG: {{^}} associatedtype A2 : QuxProtocol where Self == Self.A2.Qux{{$}}
13621362
}
13631363

13641364
#if true

test/IDE/print_synthesized_extensions.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,21 +237,21 @@ extension S13 : P5 {
237237
public func foo1() {}
238238
}
239239

240-
// CHECK1: <synthesized>extension <ref:Struct>S1</ref> where T : <ref:Protocol>P2</ref> {
240+
// CHECK1: <synthesized>extension <ref:Struct>S1</ref> where <ref:GenericTypeParam>Self</ref>.P2T1 : <ref:Protocol>P2</ref> {
241241
// CHECK1-NEXT: <decl:Func>public func <loc>p2member()</loc></decl>
242242
// CHECK1-NEXT: <decl:Func>public func <loc>ef1(<decl:Param>t: T</decl>)</loc></decl>
243243
// CHECK1-NEXT: <decl:Func>public func <loc>ef2(<decl:Param>t: <ref:Struct>S2</ref></decl>)</loc></decl>
244244
// CHECK1-NEXT: }</synthesized>
245245

246-
// CHECK2: <synthesized>extension <ref:Struct>S1</ref> where T : <ref:Protocol>P3</ref> {
246+
// CHECK2: <synthesized>extension <ref:Struct>S1</ref> where <ref:GenericTypeParam>Self</ref>.T1 : <ref:Protocol>P3</ref> {
247247
// CHECK2-NEXT: <decl:Func>public func <loc>p3Func(<decl:Param>i: <ref:Struct>Int</ref></decl>)</loc> -> <ref:Struct>Int</ref></decl>
248248
// CHECK2-NEXT: }</synthesized>
249249

250-
// CHECK3: <synthesized>extension <ref:Struct>S1</ref> where T == <ref:Struct>Int</ref> {
250+
// CHECK3: <synthesized>extension <ref:Struct>S1</ref> where <ref:GenericTypeParam>Self</ref>.T1 == <ref:Struct>Int</ref> {
251251
// CHECK3-NEXT: <decl:Func>public func <loc>p1IntFunc(<decl:Param>i: <ref:Struct>Int</ref></decl>)</loc> -> <ref:Struct>Int</ref></decl>
252252
// CHECK3-NEXT: }</synthesized>
253253

254-
// CHECK4: <synthesized>extension <ref:Struct>S1</ref> where T == <ref:Struct>S9</ref><<ref:Struct>Int</ref>> {
254+
// CHECK4: <synthesized>extension <ref:Struct>S1</ref> where <ref:GenericTypeParam>Self</ref>.T1 == <ref:Struct>S9</ref><<ref:Struct>Int</ref>> {
255255
// CHECK4-NEXT: <decl:Func>public func <loc>S9IntFunc()</loc></decl>
256256
// CHECK4-NEXT: }</synthesized>
257257

0 commit comments

Comments
 (0)