-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CodeCompletion] Fix an issue that causes an iterator to be invalidated while iterating #66517
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@swift-ci Please smoke test |
…ed while iterating In `SourceLookupCache::lookupVisibleDecls`, copy the top level values before iterating them. If we have 'addinitstotoplevel' enabled, calling 'addConstructorCallsForType' can cause macros to get expanded, which can then cause new members ot get added to 'TopLevelValues', invalidating the current iterator. I have not been able to reduce this to a test case that doesn’t rely on the `Observation` module in the SDK but here is the test case with which I was able to reproduce the issue very reliably. ```swift import Foundation import Observation @observable class MyObject {} extension MyObject {} // RUN: ~/sbin/sourcekitd-test \ // RUN: -req=complete.open \ // RUN: -req-opts=addinitstotoplevel=1 \ // RUN: -pos=8:1 \ // RUN: %s \ // RUN: -- \ // RUN: %s \ // RUN: -Xfrontend \ // RUN: -load-plugin-library \ // RUN: -Xfrontend \ // RUN: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins/libObservationMacros.dylib \ // RUN: -sdk \ // RUN: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk ``` rdar://109202157
ca942c2
to
0996342
Compare
@swift-ci Please test |
bnbarham
approved these changes
Jun 12, 2023
bnbarham
reviewed
Jun 12, 2023
|
||
void foundDecl(ValueDecl *VD, DeclVisibilityKind Reason, | ||
DynamicLookupInfo DynamicLookupInfo = {}) override { | ||
FoundDecls.push_back({VD, Reason, DynamicLookupInfo}); |
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.
Suggested change
FoundDecls.push_back({VD, Reason, DynamicLookupInfo}); | |
FoundDecls.emplace_back(VD, Reason, DynamicLookupInfo); |
bnbarham
reviewed
Jun 12, 2023
// | ||
// Technically `foundDecl` should not expand macros or discover new top level | ||
// members in any way because those newly discovered decls will not be added | ||
// to the code completion results. However, it's preferrable to miss results |
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.
Suggested change
// to the code completion results. However, it's preferrable to miss results | |
// to the code completion results. However, it's preferable to miss results |
rintaro
approved these changes
Jun 12, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In
SourceLookupCache::lookupVisibleDecls
, copy the top level values before iterating them.If we have 'addinitstotoplevel' enabled, calling 'addConstructorCallsForType' can cause macros to get expanded, which can then cause new members to get added to 'TopLevelValues', invalidating the current iterator.
I have not been able to reduce this to a test case that doesn’t rely on the
Observation
module in the SDK but here is the test case with which I was able to reproduce the issue very reliably.rdar://109202157