Skip to content

Commit 5f98e5e

Browse files
committed
Simplify DepGraph creation.
1 parent 868c702 commit 5f98e5e

File tree

2 files changed

+21
-31
lines changed

2 files changed

+21
-31
lines changed

compiler/rustc_incremental/src/persist/load.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ pub enum LoadResult<T> {
2121
Error { message: String },
2222
}
2323

24-
impl LoadResult<(SerializedDepGraph, WorkProductMap)> {
25-
pub fn open(self, sess: &Session) -> (SerializedDepGraph, WorkProductMap) {
24+
impl<T: Default> LoadResult<T> {
25+
pub fn open(self, sess: &Session) -> T {
2626
match self {
2727
LoadResult::Error { message } => {
2828
sess.warn(&message);
@@ -74,11 +74,14 @@ pub enum MaybeAsync<T> {
7474
Sync(T),
7575
Async(std::thread::JoinHandle<T>),
7676
}
77-
impl<T> MaybeAsync<T> {
78-
pub fn open(self) -> std::thread::Result<T> {
77+
78+
impl<T> MaybeAsync<LoadResult<T>> {
79+
pub fn open(self) -> LoadResult<T> {
7980
match self {
80-
MaybeAsync::Sync(result) => Ok(result),
81-
MaybeAsync::Async(handle) => handle.join(),
81+
MaybeAsync::Sync(result) => result,
82+
MaybeAsync::Async(handle) => handle.join().unwrap_or_else(|e| LoadResult::Error {
83+
message: format!("could not decode incremental cache: {:?}", e),
84+
}),
8285
}
8386
}
8487
}

compiler/rustc_interface/src/queries.rs

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,8 @@ impl<'tcx> Queries<'tcx> {
119119

120120
pub fn dep_graph_future(&self) -> Result<&Query<Option<DepGraphFuture>>> {
121121
self.dep_graph_future.compute(|| {
122-
Ok(self
123-
.session()
124-
.opts
125-
.build_dep_graph()
126-
.then(|| rustc_incremental::load_dep_graph(self.session())))
122+
let sess = self.session();
123+
Ok(sess.opts.build_dep_graph().then(|| rustc_incremental::load_dep_graph(sess)))
127124
})
128125
}
129126

@@ -195,27 +192,17 @@ impl<'tcx> Queries<'tcx> {
195192

196193
pub fn dep_graph(&self) -> Result<&Query<DepGraph>> {
197194
self.dep_graph.compute(|| {
198-
Ok(match self.dep_graph_future()?.take() {
199-
None => DepGraph::new_disabled(),
200-
Some(future) => {
195+
let sess = self.session();
196+
let future_opt = self.dep_graph_future()?.take();
197+
let dep_graph = future_opt
198+
.and_then(|future| {
201199
let (prev_graph, prev_work_products) =
202-
self.session().time("blocked_on_dep_graph_loading", || {
203-
future
204-
.open()
205-
.unwrap_or_else(|e| rustc_incremental::LoadResult::Error {
206-
message: format!("could not decode incremental cache: {:?}", e),
207-
})
208-
.open(self.session())
209-
});
210-
211-
rustc_incremental::build_dep_graph(
212-
self.session(),
213-
prev_graph,
214-
prev_work_products,
215-
)
216-
.unwrap_or_else(DepGraph::new_disabled)
217-
}
218-
})
200+
sess.time("blocked_on_dep_graph_loading", || future.open().open(sess));
201+
202+
rustc_incremental::build_dep_graph(sess, prev_graph, prev_work_products)
203+
})
204+
.unwrap_or_else(DepGraph::new_disabled);
205+
Ok(dep_graph)
219206
})
220207
}
221208

0 commit comments

Comments
 (0)