Skip to content

[5.4][Runtime] Fix race condition in protocol conformance lookups that caused false negatives. #35850

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

mikeash
Copy link
Contributor

@mikeash mikeash commented Feb 9, 2021

Cherry-pick of #35836 to 5.4 branch.

In the uncached case, we'd scan conformances, cache them, then re-query the cache. This worked fine when the cache always grew, but now we clear the cache when loading new Swift images into the process. If that happens between the scan and the re-query, we lose the entry and return a false negative.

Instead, track what we've found in the scan in a separate local table, then query that after completing the scan.

While we're in there, fix a bug in TypeLookupError where operator= accidentally copied this->Context instead of other.Context. This caused the runtime to crash when trying to print error messages due to the false negative.

Add a no-parameter constructor to TypeLookupErrorOr<> to distinguish the case where it's being initialized with nothing from the case where it's being initialized with nullptr.

rdar://72865822

…sed false negatives.

In the uncached case, we'd scan conformances, cache them, then re-query the cache. This worked fine when the cache always grew, but now we clear the cache when loading new Swift images into the process. If that happens between the scan and the re-query, we lose the entry and return a false negative.

Instead, track what we've found in the scan in a separate local table, then query that after completing the scan.

While we're in there, fix a bug in TypeLookupError where operator= accidentally copied this->Context instead of other.Context. This caused the runtime to crash when trying to print error messages due to the false negative.

Add a no-parameter constructor to TypeLookupErrorOr<> to distinguish the case where it's being initialized with nothing from the case where it's being initialized with nullptr.

rdar://72865822

(cherry picked from commit 3a2ea08)
@mikeash mikeash requested a review from tbkka February 9, 2021 14:27
@mikeash mikeash requested a review from a team as a code owner February 9, 2021 14:27
@mikeash
Copy link
Contributor Author

mikeash commented Feb 9, 2021

@swift-ci please test

if (!found.first)
C.cacheResult(type, protocol, found.second, snapshot.count());
// If there's no entry here, move up to the superclass (if any).
if (!foundWitness)
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this test will fail to distinguish between "value not found" and "NULL found".

Copy link
Contributor

@grynspan grynspan Feb 9, 2021

Choose a reason for hiding this comment

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

Oh, C is not the same as foundWitnesses. foundWitnesses is local. It's a local variable. It's a variable that's only used locally.

@mikeash mikeash merged commit 0c5ee32 into swiftlang:release/5.4 Feb 9, 2021
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