-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Index synthesized wrapper refs by substituting the Clang decl. #80074
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I was looking at this I was wondering how/if cursor info handles this case. That then brought me to https://github.com/swiftlang/swift/blob/main/lib/AST/USRGeneration.cpp#L187 (added in 62f30d5).
We've apparently run into this before, where previously both the static variable and the enumerator had the same USR and that causes other issues (as then there's no way to uniquely identify the struct/enum and property/enumerator). I need to think about this a bit more - the USR returned from cursor info for these has to match the USR we add to the index.
I had also considered emitting index data for the synthesized declarations. It became complex because the Swift indexing components don't emit ideal data from the Module with the Clang decls. For example, file references are disabled when indexing a module without Swift source files. I think it could make sense to emit the synthesized declarations. I previously enabled that for decls synthesized from Swift (e.g. the synthesized Codable conformance). |
I think my preference here would just be to move that USR adjustment logic into |
Is the intent for the USR for the synthesized struct type and its static accessors use the USRs of the Clang enum and enum constants (respectively), for the index data and cursor info? And in the doc info output, the struct and accessors have unique USRs that are different from the underlying Clang enum and enum constants? That seems feasible but I'm not sure how to move that USR adjustment. After I remove the adjustment logic from |
Yeah, for anything that doesn't specifically need the synthesized Swift declarations, which is just documentation I believe (so doc info + symbol graph).
I don't have much better of an idea here other than passing a flag through (and then we could keep it there). Pretty ugly though :( Any other ideas @hamishknight? |
5bd6840
to
cdd65d1
Compare
cdd65d1
to
d0407f3
Compare
That sounds reasonable to me. I added a flag and, I think, got it working in those places. I noticed that symbol graph wasn't specifically testing for the USR of the synthesized declarations, so I updated the relevant test to check that. I wrote the @bnbarham Can you take another look and let me know what you think? Thanks! |
Yeah, I'm okay with passing a flag through |
…equesting the Swift USR. The Error enum synthesized declarations, e.g. the struct and its static accessors, should generally appear to be identical to the underlying Clang definitions. There are some specific use cases where the synthesized declarations are necessary though. I've added an option for USR generation to override the Clang node and emit the USR of the synthesized Swift declaration. This is used by SwiftDocSupport so that the USRs of the synthesized declarations are emitted. Fixes 79912
d0407f3
to
b57e0b3
Compare
I think I have everything updated. Please take another look. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last comment, but otherwise this LGTM, thanks!
…allow requesting the Swift USR.
// MyError | ||
// CHECK-DAG: "precise": "s:SC11MyErrorCodeLeV" | ||
|
||
// MyError.errFirst | ||
// CHECK-DAG: "precise": "s:SC11MyErrorCodeLeV8errFirstSoAAVvpZ" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating this test! This would have been my only concern with this PR, but it looks like that's settled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One tiny fix-up, otherwise LGTM. Thanks @dylansturg!
Co-authored-by: Ben Barham <[email protected]>
@swift-ci please test |
@swift-ci test |
The goal of this change is replace the references to synthesized declarations, whose definitions are never contained in the indexstore, with references to the underlying declarations which are contained in the indexstore. The current behavior prevents code navigation from the references to the declaration.
Reference: #79912
This has a weird outcome, where a reference to the
Code
enum inside of the synthesized struct can emit 2 references to the underlying enum. There's an example in the test case, whereTestError.Code
is referenced.Fixes #79912