Skip to content

[SourceKit] Pass ResolvedCursorInfo as shared pointer instead of by value #63612

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

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Feb 13, 2023

As discussed in #62292 (comment).

This allows us to model the ResolvedCursorInfo types as a proper type hierarchy instead of having to store all values in the base ResolvedCursorInfo type.

rdar://102853071

@ahoppen ahoppen requested a review from bnbarham February 13, 2023 11:22
@ahoppen
Copy link
Member Author

ahoppen commented Feb 13, 2023

@swift-ci Please smoke test

@bnbarham
Copy link
Contributor

I haven't looked through it all, but is there some reason this can't be a unique_ptr? I would have thought the ownership wouldn't be that complicated here.

@@ -392,13 +395,13 @@ void swift::simple_display(llvm::raw_ostream &out, const CursorInfoOwner &owner)
}

void swift::ide::simple_display(llvm::raw_ostream &out,
const ide::ResolvedCursorInfo &info) {
if (info.isInvalid())
ide::ResolvedCursorInfoPtr info) {
Copy link
Contributor

@bnbarham bnbarham Feb 13, 2023

Choose a reason for hiding this comment

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

Seems weird to pass the shared pointer here given it just does a bunch of accesses, which I imagine is the case for most of the uses. Just pass const* instead?

@bnbarham
Copy link
Contributor

I haven't looked through it all, but is there some reason this can't be a unique_ptr? I would have thought the ownership wouldn't be that complicated here.

Ah. We cache the result, so we pretty much need to use a shared pointer here. Fair enough.

Comment on lines 2454 to 2455
dyn_cast<ResolvedValueRefCursorInfo>(&CursorInfo);
dyn_cast_cursor_info<ResolvedValueRefCursorInfo>(CursorInfo);
Copy link
Contributor

Choose a reason for hiding this comment

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

dyn_cast can take an intrusive pointer and returns a *. I don't think we need dyn_cast_cursor_info.

ResolvedCursorInfoPtr CursorInfo =
evaluateOrDefault(SrcFile.getASTContext().evaluator,
CursorInfoRequest{CursorInfoOwner(&SrcFile, Loc)},
new ResolvedCursorInfo());
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer this just be nullptr and remove the invalid state of ResolvedCursorInfo. Happy for that to be in a different PR though.

@ahoppen ahoppen force-pushed the ahoppen/resolved-cursor-info-by-reference branch from 015dedb to 464d38b Compare February 14, 2023 21:29
… value

This allows us to model the `ResolvedCursorInfo` types as a proper type hierarchy instead of having to store all values in the base `ResolvedCursorInfo` type.

rdar://102853071
@ahoppen ahoppen force-pushed the ahoppen/resolved-cursor-info-by-reference branch from 464d38b to ee26b4b Compare February 14, 2023 21:40
@ahoppen
Copy link
Member Author

ahoppen commented Feb 14, 2023

@swift-ci Please smoke test

const ResolvedValueRefCursorInfo &Info, bool AddRefactorings,
ResolvedValueRefCursorInfoPtr Info, bool AddRefactorings,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the only use of ResolvedValueRefCursorInfoPtr right? It could theoretically stay as a const ResolvedValueRefCursorInfo &Info and then just stack allocate ResolvedValueRefCursorInfo in the two callers. But also I strongly dislike all the callbacks here, so maybe this will make it easier to get rid of that later 🤷

Comment on lines 415 to 417
if (Result) {
Consumer.handleResults(*CursorInfo);
Consumer.handleResults(CursorInfo);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

CursorInfo could have been null here before 😅. I'm honestly not sure why it doesn't actually cause any issues though. It does on Linux with C++ stdlib assertions enabled. Anyway, looks like this fixes it (assuming handleResults handles nullptr).

@ahoppen
Copy link
Member Author

ahoppen commented Feb 15, 2023

@swift-ci Please smoke test macOS

@ahoppen ahoppen merged commit f210a8e into swiftlang:main Feb 15, 2023
@ahoppen ahoppen deleted the ahoppen/resolved-cursor-info-by-reference branch February 15, 2023 21:44
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.

2 participants