Skip to content

Commit 0447f91

Browse files
committed
Let load_query_result_cache take a &DefPathTable
This allows removing a confusing mem::replace in create_global_ctxt
1 parent 18d1b3f commit 0447f91

File tree

4 files changed

+16
-27
lines changed

4 files changed

+16
-27
lines changed

compiler/rustc_incremental/src/persist/load.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Code to save/load the dep-graph from files.
22
33
use rustc_data_structures::fx::FxHashMap;
4-
use rustc_hir::definitions::Definitions;
4+
use rustc_hir::definitions::DefPathTable;
55
use rustc_middle::dep_graph::{PreviousDepGraph, SerializedDepGraph, WorkProduct, WorkProductId};
66
use rustc_middle::ty::query::OnDiskCache;
77
use rustc_serialize::opaque::Decoder;
@@ -198,7 +198,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
198198
/// creating an empty cache if it could not be loaded.
199199
pub fn load_query_result_cache<'a>(
200200
sess: &'a Session,
201-
definitions: &Definitions,
201+
def_path_table: &DefPathTable,
202202
) -> Option<OnDiskCache<'a>> {
203203
if sess.opts.incremental.is_none() {
204204
return None;
@@ -212,7 +212,7 @@ pub fn load_query_result_cache<'a>(
212212
sess.is_nightly_build(),
213213
) {
214214
LoadResult::Ok { data: (bytes, start_pos) } => {
215-
Some(OnDiskCache::new(sess, bytes, start_pos, definitions))
215+
Some(OnDiskCache::new(sess, bytes, start_pos, def_path_table))
216216
}
217217
_ => Some(OnDiskCache::new_empty(sess.source_map())),
218218
}

compiler/rustc_interface/src/passes.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use rustc_data_structures::{box_region_allow_access, declare_box_region_type, pa
1313
use rustc_errors::{ErrorReported, PResult};
1414
use rustc_expand::base::ExtCtxt;
1515
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
16-
use rustc_hir::definitions::Definitions;
1716
use rustc_hir::Crate;
1817
use rustc_index::vec::IndexVec;
1918
use rustc_lint::LintStore;
@@ -51,7 +50,7 @@ use std::io::{self, BufWriter, Write};
5150
use std::lazy::SyncLazy;
5251
use std::path::PathBuf;
5352
use std::rc::Rc;
54-
use std::{env, fs, iter, mem};
53+
use std::{env, fs, iter};
5554

5655
pub fn parse<'a>(sess: &'a Session, input: &Input) -> PResult<'a, ast::Crate> {
5756
let krate = sess.time("parse_crate", || match input {
@@ -761,20 +760,18 @@ pub fn create_global_ctxt<'tcx>(
761760
lint_store: Lrc<LintStore>,
762761
krate: &'tcx Crate<'tcx>,
763762
dep_graph: DepGraph,
764-
mut resolver_outputs: ResolverOutputs,
763+
resolver_outputs: ResolverOutputs,
765764
outputs: OutputFilenames,
766765
crate_name: &str,
767766
queries: &'tcx OnceCell<TcxQueries<'tcx>>,
768767
global_ctxt: &'tcx OnceCell<GlobalCtxt<'tcx>>,
769768
arena: &'tcx WorkerLocal<Arena<'tcx>>,
770769
) -> QueryContext<'tcx> {
771770
let sess = &compiler.session();
772-
let defs: &'tcx Definitions = arena.alloc(mem::replace(
773-
&mut resolver_outputs.definitions,
774-
Definitions::new(crate_name, sess.local_crate_disambiguator()),
775-
));
776771

777-
let query_result_on_disk_cache = rustc_incremental::load_query_result_cache(sess, defs);
772+
let def_path_table = resolver_outputs.definitions.def_path_table();
773+
let query_result_on_disk_cache =
774+
rustc_incremental::load_query_result_cache(sess, def_path_table);
778775

779776
let codegen_backend = compiler.codegen_backend();
780777
let mut local_providers = *DEFAULT_QUERY_PROVIDERS;
@@ -804,7 +801,6 @@ pub fn create_global_ctxt<'tcx>(
804801
arena,
805802
resolver_outputs,
806803
krate,
807-
defs,
808804
dep_graph,
809805
query_result_on_disk_cache,
810806
queries.as_dyn(),

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,6 @@ impl<'tcx> TyCtxt<'tcx> {
11221122
arena: &'tcx WorkerLocal<Arena<'tcx>>,
11231123
resolutions: ty::ResolverOutputs,
11241124
krate: &'tcx hir::Crate<'tcx>,
1125-
definitions: &'tcx Definitions,
11261125
dep_graph: DepGraph,
11271126
on_disk_cache: Option<query::OnDiskCache<'tcx>>,
11281127
queries: &'tcx dyn query::QueryEngine<'tcx>,
@@ -1164,7 +1163,7 @@ impl<'tcx> TyCtxt<'tcx> {
11641163
glob_map: resolutions.glob_map,
11651164
extern_prelude: resolutions.extern_prelude,
11661165
untracked_crate: krate,
1167-
definitions,
1166+
definitions: arena.alloc(resolutions.definitions),
11681167
on_disk_cache,
11691168
queries,
11701169
query_caches: query::QueryCaches::default(),

compiler/rustc_middle/src/ty/query/on_disk_cache.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use rustc_data_structures::thin_vec::ThinVec;
1010
use rustc_data_structures::unhash::UnhashMap;
1111
use rustc_errors::Diagnostic;
1212
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, LOCAL_CRATE};
13-
use rustc_hir::definitions::DefPathHash;
14-
use rustc_hir::definitions::Definitions;
13+
use rustc_hir::definitions::{DefPathHash, DefPathTable};
1514
use rustc_index::vec::{Idx, IndexVec};
1615
use rustc_query_system::dep_graph::DepContext;
1716
use rustc_query_system::query::QueryContext;
@@ -167,22 +166,13 @@ crate struct RawDefId {
167166
pub index: u32,
168167
}
169168

170-
fn make_local_def_path_hash_map(definitions: &Definitions) -> UnhashMap<DefPathHash, LocalDefId> {
171-
UnhashMap::from_iter(
172-
definitions
173-
.def_path_table()
174-
.all_def_path_hashes_and_def_ids(LOCAL_CRATE)
175-
.map(|(hash, def_id)| (hash, def_id.as_local().unwrap())),
176-
)
177-
}
178-
179169
impl<'sess> OnDiskCache<'sess> {
180170
/// Creates a new `OnDiskCache` instance from the serialized data in `data`.
181171
pub fn new(
182172
sess: &'sess Session,
183173
data: Vec<u8>,
184174
start_pos: usize,
185-
definitions: &Definitions,
175+
def_path_table: &DefPathTable,
186176
) -> Self {
187177
debug_assert!(sess.opts.incremental.is_some());
188178

@@ -220,7 +210,11 @@ impl<'sess> OnDiskCache<'sess> {
220210
hygiene_context: Default::default(),
221211
foreign_def_path_hashes: footer.foreign_def_path_hashes,
222212
latest_foreign_def_path_hashes: Default::default(),
223-
local_def_path_hash_to_def_id: make_local_def_path_hash_map(definitions),
213+
local_def_path_hash_to_def_id: UnhashMap::from_iter(
214+
def_path_table
215+
.all_def_path_hashes_and_def_ids(LOCAL_CRATE)
216+
.map(|(hash, def_id)| (hash, def_id.as_local().unwrap())),
217+
),
224218
def_path_hash_to_def_id_cache: Default::default(),
225219
}
226220
}

0 commit comments

Comments
 (0)