forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#40308 - nikomatsakis:incr-comp-isolate-task, …
…r=mw first pass at isolating dep-graph tasks This intentionally leaves `DepGraph::in_task()`, the more common form, alone. Eventually all uses of `DepGraph::in_task()` should be ported to `with_task()`, but I wanted to start with a smaller subset. I also used `AssertDepGraphSafe` on the closures that are found in trans. This is because the types there are non-trivial and I wanted to lay down the mechanism and come back to the more subtle cases. The current approach taken in this PR has a downside: it is necessary to manually "reify" fn types into fn pointers when starting a task, like so: dep_graph.with_task(..., task_fn as fn(_)) this is because `with_task` takes some type `T` that implements `DepGraphTask` rather than taking a `fn()` type directly. *This* is so that we can accept closure and also so that we can accept fns with multiple arities. I am not sure this is the right approach. Originally I wanted to use closures bound by an auto trait, but that approach has some limitations: - the trait cannot have a `read()` method; since the current method is unused, that may not be a problem. - more importantly, we would want the auto trait to be "undefined" for all types *by default* -- that is, this use case doesn't really fit the typical auto trait scenario. For example, imagine that there is a `u32` loaded out of a `hir::Node` -- we don't really want to be passing that `u32` into the task!
- Loading branch information
Showing
10 changed files
with
169 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use hir::BodyId; | ||
use hir::def_id::DefId; | ||
use syntax::ast::NodeId; | ||
use ty::TyCtxt; | ||
|
||
/// The `DepGraphSafe` trait is used to specify what kinds of values | ||
/// are safe to "leak" into a task. The idea is that this should be | ||
/// only be implemented for things like the tcx as well as various id | ||
/// types, which will create reads in the dep-graph whenever the trait | ||
/// loads anything that might depend on the input program. | ||
pub trait DepGraphSafe { | ||
} | ||
|
||
/// A `BodyId` on its own doesn't give access to any particular state. | ||
/// You must fetch the state from the various maps or generate | ||
/// on-demand queries, all of which create reads. | ||
impl DepGraphSafe for BodyId { | ||
} | ||
|
||
/// A `NodeId` on its own doesn't give access to any particular state. | ||
/// You must fetch the state from the various maps or generate | ||
/// on-demand queries, all of which create reads. | ||
impl DepGraphSafe for NodeId { | ||
} | ||
|
||
/// A `DefId` on its own doesn't give access to any particular state. | ||
/// You must fetch the state from the various maps or generate | ||
/// on-demand queries, all of which create reads. | ||
impl DepGraphSafe for DefId { | ||
} | ||
|
||
/// The type context itself can be used to access all kinds of tracked | ||
/// state, but those accesses should always generate read events. | ||
impl<'a, 'gcx, 'tcx> DepGraphSafe for TyCtxt<'a, 'gcx, 'tcx> { | ||
} | ||
|
||
/// Tuples make it easy to build up state. | ||
impl<A, B> DepGraphSafe for (A, B) | ||
where A: DepGraphSafe, B: DepGraphSafe | ||
{ | ||
} | ||
|
||
/// No data here! :) | ||
impl DepGraphSafe for () { | ||
} | ||
|
||
/// A convenient override that lets you pass arbitrary state into a | ||
/// task. Every use should be accompanied by a comment explaining why | ||
/// it makes sense (or how it could be refactored away in the future). | ||
pub struct AssertDepGraphSafe<T>(pub T); | ||
|
||
impl<T> DepGraphSafe for AssertDepGraphSafe<T> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters