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

incr.comp.: Remove DepGraph::write() and its callers #42192

Merged

Conversation

michaelwoerister
Copy link
Member

After months of yak shaving, we are finally there :)

The existence of DepGraph::write() was one of the two main ways for introducing cycles into the dep-graph -- something we need to avoid in the future. The other way, re-opening nodes to add more edges, is next on the list.

r? @nikomatsakis

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.

Looks good, left a nit.

}

pub fn try_get(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K)
-> Result<$V, CycleError<'a, $tcx>> {
tcx.dep_graph.read(Self::to_dep_node(&key));
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we should move this read() into the body of try_get_with; basically into the most "fundamental" spot. (In that case, you could only execute it if the cache lookup succeeds, which I think makes the overall logic of this code cleaner anyhow.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, but a force does not give you access to the value...

@nikomatsakis
Copy link
Contributor

(r=me with that change)

@aidanhs aidanhs added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 24, 2017
@@ -180,6 +182,20 @@ impl<'tcx> Value<'tcx> for ty::SymbolName {
}
}

struct QueryMap<D: QueryDescription> {
phantom: PhantomData<D>,
map: FxHashMap<D::Key, D::Value>,
Copy link
Member

Choose a reason for hiding this comment

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

Can we just use FxHashMap directly in the macro and perhaps even avoid having a trait for Key/Value altogether?

Copy link
Member Author

Choose a reason for hiding this comment

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

I like the idea but that would complicate the define_map_struct macro. Since all of this will be refactored in the near future anyway, I think it's OK to do this in a later PR.

-> Self {
Maps {
providers,
query_stack: RefCell::new(vec![]),
$($name: RefCell::new(DepTrackingMap::new(dep_graph.clone()))),*
$($name: RefCell::new(QueryMap::new())),*
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if there's a way to get rid of the RefCell's here - perhaps a type with a very simple foolproof API based on Cell - something that requires a trait implemented for Copy types and Rc (which can't run arbitrary code when cloning), perhaps? It would probably have to be in its own module to prevent accidental bypass.

Copy link
Member Author

Choose a reason for hiding this comment

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

The advantage being that we would get rid of the runtime check? Sounds intriguing :)

Copy link
Member

Choose a reason for hiding this comment

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

I always expected it to be possible, it's just a matter of reducing the footprint to introduce a sound abstraction.

@michaelwoerister
Copy link
Member Author

@bors r=nikomatsakis

Added a comment about the read in try_get, as requested by @nikomatsakis.

@bors
Copy link
Contributor

bors commented May 29, 2017

📌 Commit c150301 has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented May 29, 2017

⌛ Testing commit c150301 with merge d78c2b4...

bors added a commit that referenced this pull request May 29, 2017
…, r=nikomatsakis

incr.comp.: Remove DepGraph::write() and its callers

After months of yak shaving, we are finally there `:)`

The existence of `DepGraph::write()` was one of the two main ways for introducing cycles into the dep-graph -- something we need to avoid in the future. The other way, re-opening nodes to add more edges, is next on the list.

r? @nikomatsakis
@bors
Copy link
Contributor

bors commented May 29, 2017

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

@bors bors merged commit c150301 into rust-lang:master May 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants