Simplify DepGraph creation.
This commit is contained in:
parent
868c702d0c
commit
5f98e5ee56
2 changed files with 20 additions and 30 deletions
|
@ -21,8 +21,8 @@ pub enum LoadResult<T> {
|
||||||
Error { message: String },
|
Error { message: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LoadResult<(SerializedDepGraph, WorkProductMap)> {
|
impl<T: Default> LoadResult<T> {
|
||||||
pub fn open(self, sess: &Session) -> (SerializedDepGraph, WorkProductMap) {
|
pub fn open(self, sess: &Session) -> T {
|
||||||
match self {
|
match self {
|
||||||
LoadResult::Error { message } => {
|
LoadResult::Error { message } => {
|
||||||
sess.warn(&message);
|
sess.warn(&message);
|
||||||
|
@ -74,11 +74,14 @@ pub enum MaybeAsync<T> {
|
||||||
Sync(T),
|
Sync(T),
|
||||||
Async(std::thread::JoinHandle<T>),
|
Async(std::thread::JoinHandle<T>),
|
||||||
}
|
}
|
||||||
impl<T> MaybeAsync<T> {
|
|
||||||
pub fn open(self) -> std::thread::Result<T> {
|
impl<T> MaybeAsync<LoadResult<T>> {
|
||||||
|
pub fn open(self) -> LoadResult<T> {
|
||||||
match self {
|
match self {
|
||||||
MaybeAsync::Sync(result) => Ok(result),
|
MaybeAsync::Sync(result) => result,
|
||||||
MaybeAsync::Async(handle) => handle.join(),
|
MaybeAsync::Async(handle) => handle.join().unwrap_or_else(|e| LoadResult::Error {
|
||||||
|
message: format!("could not decode incremental cache: {:?}", e),
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,11 +119,8 @@ impl<'tcx> Queries<'tcx> {
|
||||||
|
|
||||||
pub fn dep_graph_future(&self) -> Result<&Query<Option<DepGraphFuture>>> {
|
pub fn dep_graph_future(&self) -> Result<&Query<Option<DepGraphFuture>>> {
|
||||||
self.dep_graph_future.compute(|| {
|
self.dep_graph_future.compute(|| {
|
||||||
Ok(self
|
let sess = self.session();
|
||||||
.session()
|
Ok(sess.opts.build_dep_graph().then(|| rustc_incremental::load_dep_graph(sess)))
|
||||||
.opts
|
|
||||||
.build_dep_graph()
|
|
||||||
.then(|| rustc_incremental::load_dep_graph(self.session())))
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,27 +192,17 @@ impl<'tcx> Queries<'tcx> {
|
||||||
|
|
||||||
pub fn dep_graph(&self) -> Result<&Query<DepGraph>> {
|
pub fn dep_graph(&self) -> Result<&Query<DepGraph>> {
|
||||||
self.dep_graph.compute(|| {
|
self.dep_graph.compute(|| {
|
||||||
Ok(match self.dep_graph_future()?.take() {
|
let sess = self.session();
|
||||||
None => DepGraph::new_disabled(),
|
let future_opt = self.dep_graph_future()?.take();
|
||||||
Some(future) => {
|
let dep_graph = future_opt
|
||||||
|
.and_then(|future| {
|
||||||
let (prev_graph, prev_work_products) =
|
let (prev_graph, prev_work_products) =
|
||||||
self.session().time("blocked_on_dep_graph_loading", || {
|
sess.time("blocked_on_dep_graph_loading", || future.open().open(sess));
|
||||||
future
|
|
||||||
.open()
|
|
||||||
.unwrap_or_else(|e| rustc_incremental::LoadResult::Error {
|
|
||||||
message: format!("could not decode incremental cache: {:?}", e),
|
|
||||||
})
|
|
||||||
.open(self.session())
|
|
||||||
});
|
|
||||||
|
|
||||||
rustc_incremental::build_dep_graph(
|
rustc_incremental::build_dep_graph(sess, prev_graph, prev_work_products)
|
||||||
self.session(),
|
})
|
||||||
prev_graph,
|
.unwrap_or_else(DepGraph::new_disabled);
|
||||||
prev_work_products,
|
Ok(dep_graph)
|
||||||
)
|
|
||||||
.unwrap_or_else(DepGraph::new_disabled)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue