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

Add tombstone checks to make sure incr-comp reads aren't dirtied #40362

Closed
wants to merge 1 commit into from

Conversation

cramertj
Copy link
Member

@cramertj cramertj commented Mar 8, 2017

Part of #40305.

r? @nikomatsakis

@nikomatsakis nikomatsakis self-assigned this Mar 8, 2017
@@ -134,7 +175,7 @@ impl<M: DepTrackingMapConfig> MemoizationMap for RefCell<DepTrackingMap<M>> {
/// accesses the body of the item `item`, so we register a read
/// from `Hir(item_def_id)`.
fn memoize<OP>(&self, key: M::Key, op: OP) -> M::Value
where OP: FnOnce() -> M::Value
where OP: FnOnce() -> Option<M::Value>
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks to me like there is no longer a need for this part of the diff -- that is, we can make memoize() take a closure that returns just M::Value again

Copy link
Member Author

@cramertj cramertj Mar 8, 2017

Choose a reason for hiding this comment

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

It's a little hard to see because of how the diff reads on Github, but this call to memoize has a closure that returns None.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I thought @eddyb refactored that use. I wonder if we want to do so in this PR instead. Right now what happens is that we request AssociatedItem(X), which is some summary information about some item X that is part of an impl or trait:

impl Foo {
    type A;
    type X;
    fn b() { ... }
}

To do this, we go up to the enclosing impl (the one shown there) and then iterate over its list of items. Right now, since we are iterating anyway, we would compute the associated item info for A and b() while we're at it (to avoid an O(n^2) blow-up, basically). We have been talking though about trying to refactor into finer-grained tasks that don't have this idea of generating "N results" from one execution.

We could thus change this code to not generate N outputs but just find the one item we actually want. It would be O(N^2) but N here is typically very small.

And we do plan to rework things over time that would mitigate -- for example, moving to a newer system where we wouldn't have to be so careful about our dependencies. The whole motivation here was to only read from the impl when computing this data, and not the items themselves. This way, if the item X changes, we don't have to consider the value as dirty (the parts of X that would affect this value are copied into the impl and hashed there too). But we want to move to a system where we would recompute this value (which is cheap) and then see that, indeed, it has not changed.

Copy link
Member

Choose a reason for hiding this comment

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

The best fix IMO is to move AssociatedItem into the HIR where it belongs.

// this is the memoization pattern: for that, use `memoize()`
// below
#[cfg(debug_assertions)]
assert!(!self.tombstones.borrow().contains(&k),
Copy link
Member

Choose a reason for hiding this comment

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

The following lines should probably be wrapped in a block.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I misread. But a debug_assert() would be more concise.

@nikomatsakis
Copy link
Contributor

All right, let's land this. I have been doing some investigation and these changes would definitely be useful. We can always factor away the Option thing from memoize() later.

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Mar 17, 2017

📌 Commit 1ef95aa has been approved by nikomatsakis

@nikomatsakis
Copy link
Contributor

@bors r-

@nikomatsakis
Copy link
Contributor

Actually, what I said is still true, but I'd like a chance to do a bit more experiments, maybe chat with @cramertj a bit -- after all, this diff is fairly minor, will be easily rebased.

@bors
Copy link
Contributor

bors commented Mar 20, 2017

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

@nikomatsakis
Copy link
Contributor

I'm going to close this and instead we'll pursue the strategy of removing the use of methods other than DepTrackingMap::memoize (and in general converting to queries)

@cramertj cramertj deleted the incr-comp-tombstone branch September 21, 2017 16:10
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.

5 participants