Skip to content

[SymbolGraphGen] allow SourceKit to print declarations for private stdlib symbols #64556

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
Mar 28, 2023
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
6 changes: 6 additions & 0 deletions include/swift/SymbolGraphGen/SymbolGraphOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ struct SymbolGraphOptions {
/// along with "extensionTo" relationships instead of directly associating
/// members and conformances with the extended nominal.
bool EmitExtensionBlockSymbols = false;

/// Whether to print information for private symbols in the standard library.
/// This should be left as `false` when printing a full-module symbol graph,
/// but SourceKit should be able to load the information when pulling symbol
/// information for individual queries.
bool PrintPrivateStdlibSymbols = false;
};

} // end namespace symbolgraphgen
Expand Down
4 changes: 2 additions & 2 deletions lib/SymbolGraphGen/SymbolGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ PrintOptions SymbolGraph::getDeclarationFragmentsPrintOptions() const {
Opts.PrintFunctionRepresentationAttrs =
PrintOptions::FunctionRepresentationMode::None;
Opts.PrintUserInaccessibleAttrs = false;
Opts.SkipPrivateStdlibDecls = true;
Opts.SkipUnderscoredStdlibProtocols = true;
Opts.SkipPrivateStdlibDecls = !Walker.Options.PrintPrivateStdlibSymbols;
Opts.SkipUnderscoredStdlibProtocols = !Walker.Options.PrintPrivateStdlibSymbols;
Opts.PrintGenericRequirements = true;
Opts.PrintInherited = false;
Opts.ExplodeEnumCaseDecls = true;
Expand Down
48 changes: 48 additions & 0 deletions test/SourceKit/CursorInfo/issue-62457-symbol-graph-crash.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
struct AnyError: Swift.Error {
let error: Swift.Error
}

func test(lhs: AnyError) {
// RUN: %sourcekitd-test -req=cursor -req-opts=retrieve_symbol_graph=1 -pos=%(line + 1):13 %s -- %s | %FileCheck %s
lhs.error._code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some checks that the symbol graph looks reasonable? Could name the test something like private-stdlib-symbol-graph.swift.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see Alex beat me to that. I really do think the response is more relevant than the fact it crashed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some lines to test the declaration fragments, since that's what was crashing SymbolGraphGen.

}

// CHECK: SYMBOL GRAPH BEGIN

// CHECK: "declarationFragments": [
// CHECK-NEXT: {
// CHECK-NEXT: "kind": "keyword",
// CHECK-NEXT: "spelling": "var"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "kind": "text",
// CHECK-NEXT: "spelling": " "
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "kind": "identifier",
// CHECK-NEXT: "spelling": "_code"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "kind": "text",
// CHECK-NEXT: "spelling": ": "
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "kind": "typeIdentifier",
// CHECK-NEXT: "preciseIdentifier": "s:Si",
// CHECK-NEXT: "spelling": "Int"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "kind": "text",
// CHECK-NEXT: "spelling": " { "
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "kind": "keyword",
// CHECK-NEXT: "spelling": "get"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "kind": "text",
// CHECK-NEXT: "spelling": " }"
// CHECK-NEXT: }
// CHECK-NEXT: ]

// CHECK: SYMBOL GRAPH END
1 change: 1 addition & 0 deletions tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,7 @@ fillSymbolInfo(CursorSymbolInfo &Symbol, const DeclInfo &DInfo,
Options.MinimumAccessLevel = AccessLevel::Private;
Options.IncludeSPISymbols = true;
Options.IncludeClangDocs = true;
Options.PrintPrivateStdlibSymbols = true;

symbolgraphgen::printSymbolGraphForDecl(DInfo.VD, DInfo.BaseType,
DInfo.InSynthesizedExtension,
Expand Down