Skip to content

[RelatedIdents] Fix an assertion failure if two invalid declarations have the same base name #73468

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

ahoppen
Copy link
Member

@ahoppen ahoppen commented May 6, 2024

For example, the following declarations have the same USR with a single ERROR_TYPE parameter despite being distinct declarations.

func bar(body: Invalid) {}
func bar(ignoreCase: Bool, body: Invalid) {}

We originally intended to check the USR so that local rename behaves more like global rename, which also looks symbols up by USR. But the above example proves that assumption wrong.

rdar://126803702

@ahoppen
Copy link
Member Author

ahoppen commented May 6, 2024

@swift-ci Please smoke test

Copy link
Contributor

@bnbarham bnbarham left a comment

Choose a reason for hiding this comment

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

Nice find!

@@ -195,6 +195,7 @@ swift::ide::getRenameInfo(ResolvedCursorInfoPtr cursorInfo) {

class RenameRangeCollector : public IndexDataConsumer {
StringRef usr;
SmallString<64> displayName;
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason not to treat this the same as usr? ie. local smallstring and copy into string storage? I haven't looked at where usr is used and if there's a good reason we're doing that anyway, so this really is a genuine question and not just rhetorically asking you to change it 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

I was writing a whole paragraph about how usr is returned and thus needs to be in stringStorage anyway and how name is only used locally so no need to waste space in stringStorage for it, only that I now realized that name is returned and usr is not. 😅

Changed both to use SmallString<64> as a member of RenameRangeCollector because it simplifies the code.

usr = stringStorage->copyString(usrStorage.str());

llvm::raw_svector_ostream nameOS(displayName);
index::printDisplayName(D, nameOS);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really have to expose printDisplayName here? It just handles getters/setters, which presumably we don't care about here anyway (ie. can this just be D->getName()?)

Copy link
Member Author

@ahoppen ahoppen May 7, 2024

Choose a reason for hiding this comment

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

I would prefer to, yes. Less because we need it right now and more to be future-proof. If we modify printDisplayName in the future without remembering to change the call here, we would be missing results from related idents.

@ahoppen ahoppen force-pushed the related-idents-of-invalid-decls-with-same-base-name branch from ade4b2a to df035eb Compare May 7, 2024 04:36
@ahoppen
Copy link
Member Author

ahoppen commented May 7, 2024

@swift-ci Please smoke test

…have the same base name

For example, the following declarations have the same USR with a single ERROR_TYPE parameter despite being distinct declarations.

```swift
func bar(body: Invalid) {}
func bar(ignoreCase: Bool, body: Invalid) {}
```

We originally intended to check the USR so that local rename behaves more like global rename, which also looks symbols up by USR. But the above example proves that assumption wrong.

rdar://126803702
@ahoppen ahoppen force-pushed the related-idents-of-invalid-decls-with-same-base-name branch from df035eb to 1a67c61 Compare May 8, 2024 01:17
@ahoppen
Copy link
Member Author

ahoppen commented May 8, 2024

@swift-ci Please smoke test

@ahoppen
Copy link
Member Author

ahoppen commented May 8, 2024

@swift-ci Please smoke test

@ahoppen ahoppen merged commit 39886be into swiftlang:main May 8, 2024
@ahoppen ahoppen deleted the related-idents-of-invalid-decls-with-same-base-name branch May 8, 2024 22:25
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.

3 participants