Skip to content
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

Don't hold the predecessor cache lock longer than necessary #71392

Merged
merged 3 commits into from
Apr 26, 2020

Conversation

ecstatic-morse
Copy link
Contributor

@ecstatic-morse ecstatic-morse commented Apr 21, 2020

#71044 returns a LockGuard with the predecessor cache to callers of Body::predecessors. As a result, the lock around the predecessor cache could be held for an arbitrarily long time. This PR uses reference counting for ownership of the predecessor cache, meaning the lock is only ever held within PredecessorCache::compute. Checking this API for potential sources of deadlock is much easier now, since we no longer have to consider its consumers, only its internals.

This required removing predecessors_for, since there is no equivalent to LockGuard::map for Arc and Rc. I believe this could be emulated with owning_ref::{Arc,Rc}Ref, but I don't think it's necessary. Also, we continue to return an opaque type from Body::predecessors with the lifetime of the Body, not 'static.

This depends on #71044. Only the last two commits are new.

r? @nikomatsakis

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 21, 2020
@ecstatic-morse ecstatic-morse changed the title Don't hold the predecessor cache lock for longer than necessary Don't hold the predecessor cache lock longer than necessary Apr 21, 2020
@bors
Copy link
Contributor

bors commented Apr 22, 2020

☔ The latest upstream changes (presumably #71323) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

r=me on the last two commits, thanks @ecstatic-morse !

@nikomatsakis nikomatsakis added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 22, 2020
@nikomatsakis
Copy link
Contributor

@bors delegate=ecstatic-morse

@bors
Copy link
Contributor

bors commented Apr 22, 2020

✌️ @ecstatic-morse can now approve this pull request

There is no `Arc::map` equivalent to `LockGuard::map`
...instead of a `LockGuard` which means the lock is held for longer than
necessary.
@ecstatic-morse
Copy link
Contributor Author

Rebased and restricted visibility of the PredecessorCache type. Should be good to go.

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Apr 23, 2020

📌 Commit 34dfbc3 has been approved by nikomatsakis

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 23, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 24, 2020
…he-arc, r=nikomatsakis

Don't hold the predecessor cache lock longer than necessary

rust-lang#71044 returns a `LockGuard` with the predecessor cache to callers of `Body::predecessors`. As a result, the lock around the predecessor cache could be held for an arbitrarily long time. This PR uses reference counting for ownership of the predecessor cache, meaning the lock is only ever held within `PredecessorCache::compute`. Checking this API for potential sources of deadlock is much easier now, since we no longer have to consider its consumers, only its internals.

This required removing `predecessors_for`, since there is no equivalent to `LockGuard::map` for `Arc` and `Rc`. I believe this could be emulated with `owning_ref::{Arc,Rc}Ref`, but I don't think it's necessary. Also, we continue to return an opaque type from `Body::predecessors` with the lifetime of the `Body`, not `'static`.

This depends on rust-lang#71044. Only the last two commits are new.

r? @nikomatsakis
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 25, 2020
…he-arc, r=nikomatsakis

Don't hold the predecessor cache lock longer than necessary

rust-lang#71044 returns a `LockGuard` with the predecessor cache to callers of `Body::predecessors`. As a result, the lock around the predecessor cache could be held for an arbitrarily long time. This PR uses reference counting for ownership of the predecessor cache, meaning the lock is only ever held within `PredecessorCache::compute`. Checking this API for potential sources of deadlock is much easier now, since we no longer have to consider its consumers, only its internals.

This required removing `predecessors_for`, since there is no equivalent to `LockGuard::map` for `Arc` and `Rc`. I believe this could be emulated with `owning_ref::{Arc,Rc}Ref`, but I don't think it's necessary. Also, we continue to return an opaque type from `Body::predecessors` with the lifetime of the `Body`, not `'static`.

This depends on rust-lang#71044. Only the last two commits are new.

r? @nikomatsakis
This was referenced Apr 25, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 26, 2020
Rollup of 5 pull requests

Successful merges:

 - rust-lang#70043 (Add all remaining `DefKind`s.)
 - rust-lang#71140 ([breaking change] Disallow statics initializing themselves)
 - rust-lang#71392 (Don't hold the predecessor cache lock longer than necessary)
 - rust-lang#71541 (Add regression test for rust-lang#26376)
 - rust-lang#71554 (Replace thread_local with generator resume arguments in box_region.)

Failed merges:

r? @ghost
@bors bors merged commit 98a43ca into rust-lang:master Apr 26, 2020
@ecstatic-morse ecstatic-morse deleted the body-predecessor-cache-arc branch October 6, 2020 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants