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

Conversation

QuietMisdreavus
Copy link
Contributor

Resolves rdar://103112656
Resolves #62457

When SourceKit gets a cursor symbol graph for an internal stdlib symbol, the declaration fragment printer hits an assertion because it hasn't actually printed anything. This is because the PrintOptions used by the printer sets SkipPrivateStdlibDecls and SkipUnderscoredStdlibProtocols. This is useful when generating a whole-module symbol graph, but is causing problems for SourceKit. This PR adds an option to SymbolGraphOptions that turns those options off for SourceKit, so that these symbols can get a symbol graph correctly generated.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

@@ -0,0 +1,9 @@
// RUN: %sourcekitd-test -req=cursor -req-opts=retrieve_symbol_graph=1 -pos=8:13 %s -- %s
Copy link
Member

Choose a reason for hiding this comment

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

Would it be useful to check the response here as well?

Also, not required, but I find it easier to follow if the RUN line is right above the place where you invoke sourcekitd test and then uses -pos=%(line + 1):13. That also makes it easier to edit the file because adding new lines above the cursor info position doesn’t shift everything around.

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 thought about editing the test to give it a relative line number, but i also copied the test verbatim from the issue, so i didn't want to mess with it too much. 🤷‍♀️

It would be simple enough to check the response, but IMO the important thing here is that we don't crash.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense to me 👍🏽

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test macOS

}

func test(lhs: AnyError) {
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.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

@QuietMisdreavus QuietMisdreavus merged commit d9c8dca into main Mar 28, 2023
@QuietMisdreavus QuietMisdreavus deleted the QuietMisdreavus/sourcekit-stdlib branch March 28, 2023 16:30
@QuietMisdreavus QuietMisdreavus restored the QuietMisdreavus/sourcekit-stdlib branch March 28, 2023 16:46
@QuietMisdreavus QuietMisdreavus deleted the QuietMisdreavus/sourcekit-stdlib branch March 28, 2023 16:46
QuietMisdreavus added a commit that referenced this pull request Mar 28, 2023
etcwilde pushed a commit to etcwilde/swift that referenced this pull request Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Symbolgraph crashes with Assertion failed: (NumFragments), function ~DeclarationFragmentPrinter, file DeclarationFragmentPrinter.h, line 143.
3 participants