Skip to content

Commit 5da65ac

Browse files
authored
Merge pull request #21013 from nkcsgexi/doc-support
Sourcekit/DocSupport: include fully annotated generic signatures for extension decls.
2 parents f2d3cb0 + 93ec990 commit 5da65ac

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
@@ -1406,13 +1406,10 @@ void PrintAST::printSingleDepthOfGenericSignature(
14061406
}
14071407
} else {
14081408
Printer.callPrintStructurePre(PrintStructureKind::GenericRequirement);
1409-
if (second) {
1410-
Requirement substReq(req.getKind(), first, second);
1411-
printRequirement(substReq);
1412-
} else {
1413-
Requirement substReq(req.getKind(), first, req.getLayoutConstraint());
1414-
printRequirement(substReq);
1415-
}
1409+
1410+
// We don't substitute type for the printed requirement so that the
1411+
// printed requirement agrees with separately reported generic parameters.
1412+
printRequirement(req);
14161413
Printer.printStructurePost(PrintStructureKind::GenericRequirement);
14171414
}
14181415
}
@@ -4161,11 +4158,15 @@ void LayoutConstraintInfo::print(ASTPrinter &Printer,
41614158

41624159
void GenericSignature::print(raw_ostream &OS, PrintOptions Opts) const {
41634160
StreamPrinter Printer(OS);
4164-
PrintAST(Printer, Opts)
4165-
.printGenericSignature(this,
4166-
PrintAST::PrintParams |
4167-
PrintAST::PrintRequirements);
4161+
print(Printer, Opts);
4162+
}
4163+
4164+
void GenericSignature::print(ASTPrinter &Printer, PrintOptions Opts) const {
4165+
PrintAST(Printer, Opts).printGenericSignature(this,
4166+
PrintAST::PrintParams |
4167+
PrintAST::PrintRequirements);
41684168
}
4169+
41694170
void GenericSignature::dump() const {
41704171
print(llvm::errs());
41714172
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)