Skip to content

[CodeCompletion] Workaround fast-completion issue in UnqualifiedLookup #29763

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

rintaro
Copy link
Member

@rintaro rintaro commented Feb 11, 2020

In fast-completion, a function body can be replaced with another function body parsed from a new buffer. In such cases, during typechecking the expressions in the new function body, a source location range check in UnqualifiedLookup didn't work well because they are not from the same
buffer.

This patch workaround it by skipping the source range checks and returns 'success' in such cases.

rdar://problem/58881999

@rintaro
Copy link
Member Author

rintaro commented Feb 11, 2020

@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented Feb 11, 2020

@davidungar Based on our offline conversation, I just added a workaround code that only kicks in code completions.

// happen from the 'loc' that is in a different buffer from the 'decl'.
// In such cases, look for members because we know 'loc' is inside a
// function body in the 'decl'.
if (SM.getCodeCompletionBufferID() != 0U) {
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 suggest a convenience API hasCodeCompletionBuffer() so that the caller doesn't have to remember what return value to check for.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a great suggestion! I second it.

Copy link
Contributor

@davidungar davidungar left a comment

Choose a reason for hiding this comment

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

Thanks for sticking with this! I think that this fix will be much better for future maintainers (including me!) to deal with.


// If a code completion happens inside a function body, some lookups may
// happen from the 'loc' that is in a different buffer from the 'decl'.
// In such cases, look for members because we know 'loc' is inside a
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment would be slightly clearer to me by added the words "of the 'decl'" after "look for members".
In other words: "In such cases, look for members of the 'decl' because we know 'loc' is inside a function body in the 'decl'."

// happen from the 'loc' that is in a different buffer from the 'decl'.
// In such cases, look for members because we know 'loc' is inside a
// function body in the 'decl'.
if (SM.getCodeCompletionBufferID() != 0U) {
Copy link
Contributor

Choose a reason for hiding this comment

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

That's a great suggestion! I second it.

In fast-completion, a function body can be replaced with another function
body parsed from a new buffer. In such cases, during typechecking the
expressions in the *new* function body, a source location range check in
UnqualifiedLookup didn't work well because they are not from the same
buffer.

This patch workaround it by skipping the source range checks and returns
'success' in such cases.

rdar://problem/58881999
@rintaro rintaro force-pushed the ide-unqualifiedlookup-rdar58881999 branch from 72e1aba to ff2ccd4 Compare February 12, 2020 18:52
@rintaro
Copy link
Member Author

rintaro commented Feb 12, 2020

@swift-ci Please smoke test

@rintaro rintaro merged commit 0976e39 into swiftlang:master Feb 12, 2020
@rintaro rintaro deleted the ide-unqualifiedlookup-rdar58881999 branch February 12, 2020 20:36
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