Skip to content

[SourceKit] Guard DependencyStamps with a lock #58681

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
merged 1 commit into from
May 12, 2022

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented May 5, 2022

We might run into situations where matchesSourceState reads DependencyStamps while they are being written in buildASTUnit, causing a crash.

Guard DependencyStamps by a mutex to avoid this problem. We don’t need to provide any ordering guarantees about whether DependencyStamps have been computed in are accessed because we already assume that the dependencies shouldn't change (much) in the time between an ASTBuildOperation is created and until it produced an AST.

rdar://92748564

We might run into situations where `matchesSourceState` reads `DependencyStamps` while they are being written in `buildASTUnit`, causing a crash.

Guard `DependencyStamps` by a mutex to avoid this problem. We don’t need to provide any ordering guarantees about whether `DependencyStamps` have been computed in are accessed because we already assume that the dependencies shouldn't change (much) in the time between an `ASTBuildOperation` is created and until it produced an AST.

rdar://92748564
@ahoppen ahoppen requested a review from bnbarham May 5, 2022 08:49
@ahoppen
Copy link
Member Author

ahoppen commented May 5, 2022

@swift-ci Please smoke test

/// \c DependencyStamps contains the stamps of all module depenecies needed
/// for the AST build. These stamps are only known after the AST is built.
/// Before the AST has been built, we thus assume that all dependency stamps
/// match. This seems to be a reasonable assumption since the dependencies
/// shouldn't change (much) in the time between an \c ASTBuildOperation is
/// created and until it produced an AST.
/// Must only be accessed if \c DependencyStampsMtx has been claimed.
SmallVector<std::pair<std::string, BufferStamp>, 8> DependencyStamps = {};
Copy link
Contributor

Choose a reason for hiding this comment

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

There's quite a bit of shared state in this class in general. Is this the only other one that needs the lock? Should we just merge this one and ConsumersAndResultMtx and make it a SharedStateMtx or something?

@ahoppen ahoppen merged commit 0c33688 into swiftlang:main May 12, 2022
@ahoppen ahoppen deleted the pr/guard-dependency-stamps branch May 12, 2022 06:11
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