Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A task function is now given as a `fn` pointer to ensure that it carries no state. Each fn can take two arguments, because that worked out to be convenient -- these two arguments must be of some type that is `DepGraphSafe`, a new trait that is intended to prevent "leaking" information into the task that was derived from tracked state. 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. 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
1 parent
f573db4
commit 4b6b544
Showing
11 changed files
with
155 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,70 @@ | ||
// 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; | ||
|
||
use super::graph::DepGraph; | ||
|
||
/// The `DepGraphSafe` auto 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, which will | ||
/// create reads in the dep-graph whenever the trait loads anything | ||
/// that might depend on the input program. | ||
pub trait DepGraphSafe { | ||
fn read(&self, graph: &DepGraph); | ||
} | ||
|
||
impl DepGraphSafe for BodyId { | ||
fn read(&self, _graph: &DepGraph) { | ||
// a BodyId on its own doesn't give access to any particular state | ||
} | ||
} | ||
|
||
impl DepGraphSafe for NodeId { | ||
fn read(&self, _graph: &DepGraph) { | ||
// a DefId doesn't give any particular state | ||
} | ||
} | ||
|
||
impl DepGraphSafe for DefId { | ||
fn read(&self, _graph: &DepGraph) { | ||
// a DefId doesn't give any particular state | ||
} | ||
} | ||
|
||
impl<'a, 'gcx, 'tcx> DepGraphSafe for TyCtxt<'a, 'gcx, 'tcx> { | ||
fn read(&self, _graph: &DepGraph) { | ||
} | ||
} | ||
|
||
impl<A, B> DepGraphSafe for (A, B) | ||
where A: DepGraphSafe, B: DepGraphSafe | ||
{ | ||
fn read(&self, graph: &DepGraph) { | ||
self.0.read(graph); | ||
self.1.read(graph); | ||
} | ||
} | ||
|
||
impl DepGraphSafe for () { | ||
fn read(&self, _graph: &DepGraph) { | ||
} | ||
} | ||
|
||
/// A convenient override. We should phase out usage of this over | ||
/// time. | ||
pub struct AssertDepGraphSafe<T>(pub T); | ||
impl<T> DepGraphSafe for AssertDepGraphSafe<T> { | ||
fn read(&self, _graph: &DepGraph) { | ||
} | ||
} |
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
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