Move GlobalCtxt::finish to TyCtxt
This allows us to call GlobalCtxt::finish exactly once.
This commit is contained in:
parent
87802536f4
commit
954cd79ced
2 changed files with 54 additions and 54 deletions
|
@ -718,19 +718,17 @@ pub fn create_and_enter_global_ctxt<T>(
|
||||||
let arena = WorkerLocal::new(|_| Arena::default());
|
let arena = WorkerLocal::new(|_| Arena::default());
|
||||||
let hir_arena = WorkerLocal::new(|_| rustc_hir::Arena::default());
|
let hir_arena = WorkerLocal::new(|_| rustc_hir::Arena::default());
|
||||||
|
|
||||||
let gcx = create_global_ctxt(compiler, krate, &gcx_cell, &arena, &hir_arena);
|
create_and_enter_global_ctxt_inner(compiler, krate, &gcx_cell, &arena, &hir_arena, f)
|
||||||
let ret = gcx.enter(f);
|
|
||||||
gcx.finish();
|
|
||||||
ret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_global_ctxt<'tcx>(
|
fn create_and_enter_global_ctxt_inner<'tcx, T>(
|
||||||
compiler: &'tcx Compiler,
|
compiler: &'tcx Compiler,
|
||||||
mut krate: rustc_ast::Crate,
|
mut krate: rustc_ast::Crate,
|
||||||
gcx_cell: &'tcx OnceLock<GlobalCtxt<'tcx>>,
|
gcx_cell: &'tcx OnceLock<GlobalCtxt<'tcx>>,
|
||||||
arena: &'tcx WorkerLocal<Arena<'tcx>>,
|
arena: &'tcx WorkerLocal<Arena<'tcx>>,
|
||||||
hir_arena: &'tcx WorkerLocal<rustc_hir::Arena<'tcx>>,
|
hir_arena: &'tcx WorkerLocal<rustc_hir::Arena<'tcx>>,
|
||||||
) -> &'tcx GlobalCtxt<'tcx> {
|
f: impl FnOnce(TyCtxt<'tcx>) -> T,
|
||||||
|
) -> T {
|
||||||
let sess = &compiler.sess;
|
let sess = &compiler.sess;
|
||||||
|
|
||||||
rustc_builtin_macros::cmdline_attrs::inject(
|
rustc_builtin_macros::cmdline_attrs::inject(
|
||||||
|
@ -778,43 +776,45 @@ fn create_global_ctxt<'tcx>(
|
||||||
|
|
||||||
let incremental = dep_graph.is_fully_enabled();
|
let incremental = dep_graph.is_fully_enabled();
|
||||||
|
|
||||||
sess.time("setup_global_ctxt", || {
|
let qcx = gcx_cell.get_or_init(move || {
|
||||||
let qcx = gcx_cell.get_or_init(move || {
|
TyCtxt::create_global_ctxt(
|
||||||
TyCtxt::create_global_ctxt(
|
sess,
|
||||||
sess,
|
crate_types,
|
||||||
crate_types,
|
stable_crate_id,
|
||||||
stable_crate_id,
|
arena,
|
||||||
arena,
|
hir_arena,
|
||||||
hir_arena,
|
untracked,
|
||||||
untracked,
|
dep_graph,
|
||||||
dep_graph,
|
rustc_query_impl::query_callbacks(arena),
|
||||||
rustc_query_impl::query_callbacks(arena),
|
rustc_query_impl::query_system(
|
||||||
rustc_query_impl::query_system(
|
providers.queries,
|
||||||
providers.queries,
|
providers.extern_queries,
|
||||||
providers.extern_queries,
|
query_result_on_disk_cache,
|
||||||
query_result_on_disk_cache,
|
incremental,
|
||||||
incremental,
|
),
|
||||||
),
|
providers.hooks,
|
||||||
providers.hooks,
|
compiler.current_gcx.clone(),
|
||||||
compiler.current_gcx.clone(),
|
)
|
||||||
)
|
});
|
||||||
});
|
|
||||||
|
|
||||||
qcx.enter(|tcx| {
|
qcx.enter(|tcx| {
|
||||||
let feed = tcx.create_crate_num(stable_crate_id).unwrap();
|
let feed = tcx.create_crate_num(stable_crate_id).unwrap();
|
||||||
assert_eq!(feed.key(), LOCAL_CRATE);
|
assert_eq!(feed.key(), LOCAL_CRATE);
|
||||||
feed.crate_name(crate_name);
|
feed.crate_name(crate_name);
|
||||||
|
|
||||||
let feed = tcx.feed_unit_query();
|
let feed = tcx.feed_unit_query();
|
||||||
feed.features_query(tcx.arena.alloc(rustc_expand::config::features(
|
feed.features_query(tcx.arena.alloc(rustc_expand::config::features(
|
||||||
sess,
|
sess,
|
||||||
&pre_configured_attrs,
|
&pre_configured_attrs,
|
||||||
crate_name,
|
crate_name,
|
||||||
)));
|
)));
|
||||||
feed.crate_for_resolver(tcx.arena.alloc(Steal::new((krate, pre_configured_attrs))));
|
feed.crate_for_resolver(tcx.arena.alloc(Steal::new((krate, pre_configured_attrs))));
|
||||||
feed.output_filenames(Arc::new(outputs));
|
feed.output_filenames(Arc::new(outputs));
|
||||||
});
|
|
||||||
qcx
|
let res = f(tcx);
|
||||||
|
// FIXME maybe run finish even when a fatal error occured? or at least tcx.alloc_self_profile_query_strings()?
|
||||||
|
tcx.finish();
|
||||||
|
res
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1374,19 +1374,6 @@ impl<'tcx> GlobalCtxt<'tcx> {
|
||||||
|
|
||||||
tls::enter_context(&icx, || f(icx.tcx))
|
tls::enter_context(&icx, || f(icx.tcx))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn finish(&'tcx self) {
|
|
||||||
// We assume that no queries are run past here. If there are new queries
|
|
||||||
// after this point, they'll show up as "<unknown>" in self-profiling data.
|
|
||||||
self.enter(|tcx| tcx.alloc_self_profile_query_strings());
|
|
||||||
|
|
||||||
self.enter(|tcx| tcx.save_dep_graph());
|
|
||||||
self.enter(|tcx| tcx.query_key_hash_verify_all());
|
|
||||||
|
|
||||||
if let Err((path, error)) = self.dep_graph.finish_encoding() {
|
|
||||||
self.sess.dcx().emit_fatal(crate::error::FailedWritingFile { path: &path, error });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is used to get a reference to a `GlobalCtxt` if one is available.
|
/// This is used to get a reference to a `GlobalCtxt` if one is available.
|
||||||
|
@ -2120,6 +2107,19 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
pub fn local_opaque_ty_origin(self, def_id: LocalDefId) -> hir::OpaqueTyOrigin<LocalDefId> {
|
pub fn local_opaque_ty_origin(self, def_id: LocalDefId) -> hir::OpaqueTyOrigin<LocalDefId> {
|
||||||
self.hir().expect_opaque_ty(def_id).origin
|
self.hir().expect_opaque_ty(def_id).origin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn finish(self) {
|
||||||
|
// We assume that no queries are run past here. If there are new queries
|
||||||
|
// after this point, they'll show up as "<unknown>" in self-profiling data.
|
||||||
|
self.alloc_self_profile_query_strings();
|
||||||
|
|
||||||
|
self.save_dep_graph();
|
||||||
|
self.query_key_hash_verify_all();
|
||||||
|
|
||||||
|
if let Err((path, error)) = self.dep_graph.finish_encoding() {
|
||||||
|
self.sess.dcx().emit_fatal(crate::error::FailedWritingFile { path: &path, error });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! nop_lift {
|
macro_rules! nop_lift {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue