Skip to content

Sourcekit/DocSupport: include fully annotated generic signatures for extension decls. #21013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/swift/AST/GenericSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ class alignas(1 << TypeAlignInBits) GenericSignature final
ArrayRef<Requirement> requirements);

void print(raw_ostream &OS, PrintOptions Options = PrintOptions()) const;
void print(ASTPrinter &Printer, PrintOptions Opts = PrintOptions()) const;
void dump() const;
std::string getAsString() const;
};
Expand Down
23 changes: 12 additions & 11 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1406,13 +1406,10 @@ void PrintAST::printSingleDepthOfGenericSignature(
}
} else {
Printer.callPrintStructurePre(PrintStructureKind::GenericRequirement);
if (second) {
Requirement substReq(req.getKind(), first, second);
printRequirement(substReq);
} else {
Requirement substReq(req.getKind(), first, req.getLayoutConstraint());
printRequirement(substReq);
}

// We don't substitute type for the printed requirement so that the
// printed requirement agrees with separately reported generic parameters.
printRequirement(req);
Printer.printStructurePost(PrintStructureKind::GenericRequirement);
}
}
Expand Down Expand Up @@ -4160,11 +4157,15 @@ void LayoutConstraintInfo::print(ASTPrinter &Printer,

void GenericSignature::print(raw_ostream &OS, PrintOptions Opts) const {
StreamPrinter Printer(OS);
PrintAST(Printer, Opts)
.printGenericSignature(this,
PrintAST::PrintParams |
PrintAST::PrintRequirements);
print(Printer, Opts);
}

void GenericSignature::print(ASTPrinter &Printer, PrintOptions Opts) const {
PrintAST(Printer, Opts).printGenericSignature(this,
PrintAST::PrintParams |
PrintAST::PrintRequirements);
}

void GenericSignature::dump() const {
print(llvm::errs());
llvm::errs() << '\n';
Expand Down
2 changes: 1 addition & 1 deletion test/IDE/print_ast_tc_decls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ protocol ProtocolWithWhereClauseAndAssoc : QuxProtocol where Qux == Int {

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

#if true
Expand Down
8 changes: 4 additions & 4 deletions test/IDE/print_synthesized_extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,21 +237,21 @@ extension S13 : P5 {
public func foo1() {}
}

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

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

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

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

Expand Down
Loading