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

Make TransitiveRelation thread safe. Avoid locking by using get_mut in some cases #48587

Merged
merged 1 commit into from
Mar 4, 2018

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Feb 27, 2018

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 27, 2018
@nikomatsakis
Copy link
Contributor

Hmm. This is a case where I suspect we could do better than the current design. I think I was just kinda' lazy before.

@nikomatsakis
Copy link
Contributor

I'll take a look.

@Zoxc
Copy link
Contributor Author

Zoxc commented Feb 27, 2018

I think this is only shared because of the free_region_map field of TypeckTables. What that still be there if we remove the old borrowck?

@nikomatsakis
Copy link
Contributor

@Zoxc no, I think that field goes away -- but I think the type is still used

@nikomatsakis
Copy link
Contributor

I just confirmed that it is not used from the MIR borrow check (though the type itself is used).

I think what I would prefer to do in this case is to have the cache always be up-to-date.

We could do this in two ways:

  • Remove the refcell. Clear cache to None (as today) on every mutation, but add a method to recompute the transitive cache. Panic if you try to "read" from the relation and the transitive cache is None. It is now on us to ensure we invoke the method at the right times, but it will eagerly panic if we forget.
  • Just update the cache every single time. This might be a bit of a perf hit because we'll come to a full transitive closure for every change, rather than waiting till everything is available, but honestly I doubt it.
  • Something like the first variant but where we have a "freeze" method that converts from an "in-progress" FRR to one that is transitiviely up to date. More complex but avoids possibility of dynamic error.

I guess between the two I lean towards the second, as it is more robust, and we can always handle it if that is some kind of perf hit.

Would you be up for that?

@Zoxc
Copy link
Contributor Author

Zoxc commented Mar 2, 2018

@Zoxc no, I think that field goes away -- but I think the type is still used

The question isn't whether or not it's used, but whether or not it's shared. That field is the reason it's shared, so if it goes away, we could just revert this patch.

I'd prefer to merge this and then later merge some other scheme backed by benchmarks if it turns out to actually be shared.

@nikomatsakis
Copy link
Contributor

@Zoxc

I'd prefer to merge this and then later merge some other scheme backed by benchmarks if it turns out to actually be shared.

It will not be shared in the future, that much is sure, but I think that we probably will not remove the old borrow checker "in time". Is there some central issue tracking the refactorings? I'm willing to land this change as long as long as there is a list somewhere of stuff to fix and it is on there =)

@Zoxc
Copy link
Contributor Author

Zoxc commented Mar 2, 2018

@nikomatsakis It is on this list.

@nikomatsakis
Copy link
Contributor

@Zoxc oh, great! I just made https://github.com/rust-lang/rust/issues/48685...maybe we can just link to that list from there? Or close one or the other.

@nikomatsakis
Copy link
Contributor

@Zoxc ok I added it to my list of 'pending refactorings' here #48685 -- I'll probably open up an issue with mentoring instructions at some point. In the meantime, let me review this...

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Mar 2, 2018

📌 Commit 89e55d1 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-review Status: Awaiting review from the assignee but also interested parties. labels Mar 2, 2018
Manishearth added a commit to Manishearth/rust that referenced this pull request Mar 3, 2018
…sakis

Make TransitiveRelation thread safe. Avoid locking by using get_mut in some cases

r? @nikomatsakis
@bors
Copy link
Contributor

bors commented Mar 4, 2018

⌛ Testing commit 89e55d1 with merge 9ff5cb5...

bors added a commit that referenced this pull request Mar 4, 2018
Make TransitiveRelation thread safe. Avoid locking by using get_mut in some cases

r? @nikomatsakis
@bors
Copy link
Contributor

bors commented Mar 4, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing 9ff5cb5 to master...

@bors bors merged commit 89e55d1 into rust-lang:master Mar 4, 2018
@Zoxc Zoxc deleted the transitive-relation branch March 7, 2018 00:54
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 22, 2022
get rid of `RefCell` in `TransitiveRelation`

This is one of the jobs in `Pending refactorings` in rust-lang#48685. The parallel-compiler's work has been suspended for quite some time, but I think I can pick it up gradually. I think this PR should be a start.

Regarding the refactoring of `TransitiveRelation`, `@nikomatsakis`  has proposed [two(three?) schemes](rust-lang#48587 (comment)). In order to satisfy both compilation efficiency and robustness, I think adding the `freeze` method may be the best solution, although it requires relatively more code changes.
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.

4 participants