Auto merge of #56601 - Zoxc:lifetime-killer, r=nikomatsakis
Make the 'a lifetime on TyCtxt useless cc @rust-lang/compiler r? @nikomatsakis
This commit is contained in:
commit
0a4a4ffc69
@ -37,7 +37,7 @@
|
||||
use ty::fold::TypeFoldable;
|
||||
use ty::relate::{RelateResult, TraitObjectMode};
|
||||
use ty::subst::{Kind, Substs};
|
||||
use ty::{self, GenericParamDefKind, Ty, TyCtxt};
|
||||
use ty::{self, GenericParamDefKind, Ty, TyCtxt, CtxtInterners};
|
||||
use ty::{FloatVid, IntVid, TyVid};
|
||||
use util::nodemap::FxHashMap;
|
||||
|
||||
@ -474,6 +474,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
pub struct InferCtxtBuilder<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
|
||||
global_tcx: TyCtxt<'a, 'gcx, 'gcx>,
|
||||
arena: SyncDroplessArena,
|
||||
interners: Option<CtxtInterners<'tcx>>,
|
||||
fresh_tables: Option<RefCell<ty::TypeckTables<'tcx>>>,
|
||||
trait_object_mode: TraitObjectMode,
|
||||
}
|
||||
@ -483,6 +484,7 @@ pub fn infer_ctxt(self) -> InferCtxtBuilder<'a, 'gcx, 'tcx> {
|
||||
InferCtxtBuilder {
|
||||
global_tcx: self,
|
||||
arena: SyncDroplessArena::default(),
|
||||
interners: None,
|
||||
fresh_tables: None,
|
||||
trait_object_mode: TraitObjectMode::NoSquash,
|
||||
}
|
||||
@ -531,10 +533,13 @@ pub fn enter<R>(&'tcx mut self, f: impl for<'b> FnOnce(InferCtxt<'b, 'gcx, 'tcx>
|
||||
global_tcx,
|
||||
trait_object_mode,
|
||||
ref arena,
|
||||
ref mut interners,
|
||||
ref fresh_tables,
|
||||
} = *self;
|
||||
let in_progress_tables = fresh_tables.as_ref();
|
||||
global_tcx.enter_local(arena, |tcx| {
|
||||
// Check that we haven't entered before
|
||||
assert!(interners.is_none());
|
||||
global_tcx.enter_local(arena, interners, |tcx| {
|
||||
f(InferCtxt {
|
||||
tcx,
|
||||
in_progress_tables,
|
||||
|
@ -72,6 +72,7 @@
|
||||
use std::iter;
|
||||
use std::sync::mpsc;
|
||||
use std::sync::Arc;
|
||||
use std::marker::PhantomData;
|
||||
use rustc_target::spec::abi;
|
||||
use syntax::ast::{self, NodeId};
|
||||
use syntax::attr;
|
||||
@ -86,6 +87,7 @@
|
||||
pub struct AllArenas<'tcx> {
|
||||
pub global: WorkerLocal<GlobalArenas<'tcx>>,
|
||||
pub interner: SyncDroplessArena,
|
||||
global_ctxt: Option<GlobalCtxt<'tcx>>,
|
||||
}
|
||||
|
||||
impl<'tcx> AllArenas<'tcx> {
|
||||
@ -93,6 +95,7 @@ pub fn new() -> Self {
|
||||
AllArenas {
|
||||
global: WorkerLocal::new(|_| GlobalArenas::default()),
|
||||
interner: SyncDroplessArena::default(),
|
||||
global_ctxt: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -869,12 +872,13 @@ pub struct FreeRegionInfo {
|
||||
/// [rustc guide]: https://rust-lang.github.io/rustc-guide/ty.html
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct TyCtxt<'a, 'gcx: 'tcx, 'tcx: 'a> {
|
||||
gcx: &'a GlobalCtxt<'gcx>,
|
||||
interners: &'a CtxtInterners<'tcx>
|
||||
gcx: &'gcx GlobalCtxt<'gcx>,
|
||||
interners: &'tcx CtxtInterners<'tcx>,
|
||||
dummy: PhantomData<&'a ()>,
|
||||
}
|
||||
|
||||
impl<'a, 'gcx, 'tcx> Deref for TyCtxt<'a, 'gcx, 'tcx> {
|
||||
type Target = &'a GlobalCtxt<'gcx>;
|
||||
impl<'gcx> Deref for TyCtxt<'_, 'gcx, '_> {
|
||||
type Target = &'gcx GlobalCtxt<'gcx>;
|
||||
#[inline(always)]
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.gcx
|
||||
@ -964,10 +968,11 @@ pub struct GlobalCtxt<'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
/// Get the global TyCtxt.
|
||||
#[inline]
|
||||
pub fn global_tcx(self) -> TyCtxt<'a, 'gcx, 'gcx> {
|
||||
pub fn global_tcx(self) -> TyCtxt<'gcx, 'gcx, 'gcx> {
|
||||
TyCtxt {
|
||||
gcx: self.gcx,
|
||||
interners: &self.gcx.global_interners,
|
||||
dummy: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
@ -1105,7 +1110,7 @@ pub fn create_and_enter<F, R>(s: &'tcx Session,
|
||||
cstore: &'tcx CrateStoreDyn,
|
||||
local_providers: ty::query::Providers<'tcx>,
|
||||
extern_providers: ty::query::Providers<'tcx>,
|
||||
arenas: &'tcx AllArenas<'tcx>,
|
||||
arenas: &'tcx mut AllArenas<'tcx>,
|
||||
resolutions: ty::Resolutions,
|
||||
hir: hir_map::Map<'tcx>,
|
||||
on_disk_query_result_cache: query::OnDiskCache<'tcx>,
|
||||
@ -1166,7 +1171,7 @@ pub fn create_and_enter<F, R>(s: &'tcx Session,
|
||||
Lrc::new(StableVec::new(v)));
|
||||
}
|
||||
|
||||
let gcx = &GlobalCtxt {
|
||||
arenas.global_ctxt = Some(GlobalCtxt {
|
||||
sess: s,
|
||||
cstore,
|
||||
global_arenas: &arenas.global,
|
||||
@ -1209,7 +1214,9 @@ pub fn create_and_enter<F, R>(s: &'tcx Session,
|
||||
alloc_map: Lock::new(interpret::AllocMap::new()),
|
||||
tx_to_llvm_workers: Lock::new(tx),
|
||||
output_filenames: Arc::new(output_filenames.clone()),
|
||||
};
|
||||
});
|
||||
|
||||
let gcx = arenas.global_ctxt.as_ref().unwrap();
|
||||
|
||||
sync::assert_send_val(&gcx);
|
||||
|
||||
@ -1609,20 +1616,25 @@ pub fn encode_metadata(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'gcx: 'tcx, 'tcx> GlobalCtxt<'gcx> {
|
||||
impl<'gcx> GlobalCtxt<'gcx> {
|
||||
/// Call the closure with a local `TyCtxt` using the given arena.
|
||||
pub fn enter_local<F, R>(
|
||||
&self,
|
||||
/// `interners` is a slot passed so we can create a CtxtInterners
|
||||
/// with the same lifetime as `arena`.
|
||||
pub fn enter_local<'tcx, F, R>(
|
||||
&'gcx self,
|
||||
arena: &'tcx SyncDroplessArena,
|
||||
interners: &'tcx mut Option<CtxtInterners<'tcx>>,
|
||||
f: F
|
||||
) -> R
|
||||
where
|
||||
F: for<'a> FnOnce(TyCtxt<'a, 'gcx, 'tcx>) -> R
|
||||
F: FnOnce(TyCtxt<'tcx, 'gcx, 'tcx>) -> R,
|
||||
'gcx: 'tcx,
|
||||
{
|
||||
let interners = CtxtInterners::new(arena);
|
||||
*interners = Some(CtxtInterners::new(&arena));
|
||||
let tcx = TyCtxt {
|
||||
gcx: self,
|
||||
interners: &interners,
|
||||
interners: interners.as_ref().unwrap(),
|
||||
dummy: PhantomData,
|
||||
};
|
||||
ty::tls::with_related_context(tcx.global_tcx(), |icx| {
|
||||
let new_icx = ty::tls::ImplicitCtxt {
|
||||
@ -1631,8 +1643,8 @@ pub fn enter_local<F, R>(
|
||||
layout_depth: icx.layout_depth,
|
||||
task: icx.task,
|
||||
};
|
||||
ty::tls::enter_context(&new_icx, |new_icx| {
|
||||
f(new_icx.tcx)
|
||||
ty::tls::enter_context(&new_icx, |_| {
|
||||
f(tcx)
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -1872,6 +1884,7 @@ pub mod tls {
|
||||
|
||||
use std::fmt;
|
||||
use std::mem;
|
||||
use std::marker::PhantomData;
|
||||
use syntax_pos;
|
||||
use ty::query;
|
||||
use errors::{Diagnostic, TRACK_DIAGNOSTICS};
|
||||
@ -1891,10 +1904,10 @@ pub mod tls {
|
||||
/// you should also have access to an ImplicitCtxt through the functions
|
||||
/// in this module.
|
||||
#[derive(Clone)]
|
||||
pub struct ImplicitCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
pub struct ImplicitCtxt<'a, 'gcx: 'tcx, 'tcx> {
|
||||
/// The current TyCtxt. Initially created by `enter_global` and updated
|
||||
/// by `enter_local` with a new local interner
|
||||
pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
pub tcx: TyCtxt<'tcx, 'gcx, 'tcx>,
|
||||
|
||||
/// The current query job, if any. This is updated by start_job in
|
||||
/// ty::query::plumbing when executing a query
|
||||
@ -2008,8 +2021,8 @@ pub fn enter_context<'a, 'gcx: 'tcx, 'tcx, F, R>(context: &ImplicitCtxt<'a, 'gcx
|
||||
/// creating a initial TyCtxt and ImplicitCtxt.
|
||||
/// This happens once per rustc session and TyCtxts only exists
|
||||
/// inside the `f` function.
|
||||
pub fn enter_global<'gcx, F, R>(gcx: &GlobalCtxt<'gcx>, f: F) -> R
|
||||
where F: for<'a> FnOnce(TyCtxt<'a, 'gcx, 'gcx>) -> R
|
||||
pub fn enter_global<'gcx, F, R>(gcx: &'gcx GlobalCtxt<'gcx>, f: F) -> R
|
||||
where F: FnOnce(TyCtxt<'gcx, 'gcx, 'gcx>) -> R
|
||||
{
|
||||
with_thread_locals(|| {
|
||||
// Update GCX_PTR to indicate there's a GlobalCtxt available
|
||||
@ -2024,6 +2037,7 @@ pub fn enter_global<'gcx, F, R>(gcx: &GlobalCtxt<'gcx>, f: F) -> R
|
||||
let tcx = TyCtxt {
|
||||
gcx,
|
||||
interners: &gcx.global_interners,
|
||||
dummy: PhantomData,
|
||||
};
|
||||
let icx = ImplicitCtxt {
|
||||
tcx,
|
||||
@ -2053,6 +2067,7 @@ pub unsafe fn with_global<F, R>(f: F) -> R
|
||||
let tcx = TyCtxt {
|
||||
gcx,
|
||||
interners: &gcx.global_interners,
|
||||
dummy: PhantomData,
|
||||
};
|
||||
let icx = ImplicitCtxt {
|
||||
query: None,
|
||||
|
@ -82,7 +82,7 @@
|
||||
pub use self::binding::BindingMode::*;
|
||||
|
||||
pub use self::context::{TyCtxt, FreeRegionInfo, GlobalArenas, AllArenas, tls, keep_local};
|
||||
pub use self::context::{Lift, TypeckTables};
|
||||
pub use self::context::{Lift, TypeckTables, CtxtInterners};
|
||||
|
||||
pub use self::instance::{Instance, InstanceDef};
|
||||
|
||||
|
@ -197,7 +197,7 @@ pub(super) fn start<'lcx, F, R>(
|
||||
let r = tls::with_related_context(tcx, move |current_icx| {
|
||||
// Update the ImplicitCtxt to point to our new query job
|
||||
let new_icx = tls::ImplicitCtxt {
|
||||
tcx,
|
||||
tcx: tcx.global_tcx(),
|
||||
query: Some(self.job.clone()),
|
||||
layout_depth: current_icx.layout_depth,
|
||||
task: current_icx.task,
|
||||
|
@ -246,8 +246,6 @@ macro_rules! controller_entry_point {
|
||||
}
|
||||
}
|
||||
|
||||
let arenas = AllArenas::new();
|
||||
|
||||
// Construct the HIR map
|
||||
let hir_map = time(sess, "indexing hir", || {
|
||||
hir_map::map_crate(sess, cstore, &mut hir_forest, &defs)
|
||||
@ -263,7 +261,6 @@ macro_rules! controller_entry_point {
|
||||
sess,
|
||||
outdir,
|
||||
output,
|
||||
&arenas,
|
||||
&cstore,
|
||||
&hir_map,
|
||||
&analysis,
|
||||
@ -284,6 +281,8 @@ macro_rules! controller_entry_point {
|
||||
None
|
||||
};
|
||||
|
||||
let mut arenas = AllArenas::new();
|
||||
|
||||
phase_3_run_analysis_passes(
|
||||
&*codegen_backend,
|
||||
control,
|
||||
@ -292,7 +291,7 @@ macro_rules! controller_entry_point {
|
||||
hir_map,
|
||||
analysis,
|
||||
resolutions,
|
||||
&arenas,
|
||||
&mut arenas,
|
||||
&crate_name,
|
||||
&outputs,
|
||||
|tcx, analysis, rx, result| {
|
||||
@ -533,7 +532,6 @@ pub struct CompileState<'a, 'tcx: 'a> {
|
||||
pub output_filenames: Option<&'a OutputFilenames>,
|
||||
pub out_dir: Option<&'a Path>,
|
||||
pub out_file: Option<&'a Path>,
|
||||
pub arenas: Option<&'tcx AllArenas<'tcx>>,
|
||||
pub expanded_crate: Option<&'a ast::Crate>,
|
||||
pub hir_crate: Option<&'a hir::Crate>,
|
||||
pub hir_map: Option<&'a hir_map::Map<'tcx>>,
|
||||
@ -549,7 +547,6 @@ fn empty(input: &'a Input, session: &'tcx Session, out_dir: &'a Option<PathBuf>)
|
||||
session,
|
||||
out_dir: out_dir.as_ref().map(|s| &**s),
|
||||
out_file: None,
|
||||
arenas: None,
|
||||
krate: None,
|
||||
registry: None,
|
||||
cstore: None,
|
||||
@ -605,7 +602,6 @@ fn state_after_hir_lowering(
|
||||
session: &'tcx Session,
|
||||
out_dir: &'a Option<PathBuf>,
|
||||
out_file: &'a Option<PathBuf>,
|
||||
arenas: &'tcx AllArenas<'tcx>,
|
||||
cstore: &'tcx CStore,
|
||||
hir_map: &'a hir_map::Map<'tcx>,
|
||||
analysis: &'a ty::CrateAnalysis,
|
||||
@ -617,7 +613,6 @@ fn state_after_hir_lowering(
|
||||
) -> Self {
|
||||
CompileState {
|
||||
crate_name: Some(crate_name),
|
||||
arenas: Some(arenas),
|
||||
cstore: Some(cstore),
|
||||
hir_map: Some(hir_map),
|
||||
analysis: Some(analysis),
|
||||
@ -1216,7 +1211,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(
|
||||
hir_map: hir_map::Map<'tcx>,
|
||||
mut analysis: ty::CrateAnalysis,
|
||||
resolutions: Resolutions,
|
||||
arenas: &'tcx AllArenas<'tcx>,
|
||||
arenas: &'tcx mut AllArenas<'tcx>,
|
||||
name: &str,
|
||||
output_filenames: &OutputFilenames,
|
||||
f: F,
|
||||
|
@ -911,7 +911,6 @@ fn build_controller(self: Box<Self>,
|
||||
&state.expanded_crate.take().unwrap(),
|
||||
state.crate_name.unwrap(),
|
||||
ppm,
|
||||
state.arenas.unwrap(),
|
||||
state.output_filenames.unwrap(),
|
||||
opt_uii.clone(),
|
||||
state.out_file);
|
||||
|
@ -202,7 +202,6 @@ fn call_with_pp_support_hir<'tcx, A, F>(
|
||||
hir_map: &hir_map::Map<'tcx>,
|
||||
analysis: &ty::CrateAnalysis,
|
||||
resolutions: &Resolutions,
|
||||
arenas: &'tcx AllArenas<'tcx>,
|
||||
output_filenames: &OutputFilenames,
|
||||
id: &str,
|
||||
f: F
|
||||
@ -228,6 +227,7 @@ fn call_with_pp_support_hir<'tcx, A, F>(
|
||||
PpmTyped => {
|
||||
let control = &driver::CompileController::basic();
|
||||
let codegen_backend = ::get_codegen_backend(sess);
|
||||
let mut arenas = AllArenas::new();
|
||||
abort_on_err(driver::phase_3_run_analysis_passes(&*codegen_backend,
|
||||
control,
|
||||
sess,
|
||||
@ -235,7 +235,7 @@ fn call_with_pp_support_hir<'tcx, A, F>(
|
||||
hir_map.clone(),
|
||||
analysis.clone(),
|
||||
resolutions.clone(),
|
||||
arenas,
|
||||
&mut arenas,
|
||||
id,
|
||||
output_filenames,
|
||||
|tcx, _, _, _| {
|
||||
@ -977,7 +977,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
|
||||
krate: &ast::Crate,
|
||||
crate_name: &str,
|
||||
ppm: PpMode,
|
||||
arenas: &'tcx AllArenas<'tcx>,
|
||||
output_filenames: &OutputFilenames,
|
||||
opt_uii: Option<UserIdentifiedItem>,
|
||||
ofile: Option<&Path>) {
|
||||
@ -988,7 +987,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
|
||||
analysis,
|
||||
resolutions,
|
||||
crate_name,
|
||||
arenas,
|
||||
output_filenames,
|
||||
ppm,
|
||||
opt_uii,
|
||||
@ -1026,7 +1024,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
|
||||
hir_map,
|
||||
analysis,
|
||||
resolutions,
|
||||
arenas,
|
||||
output_filenames,
|
||||
crate_name,
|
||||
move |annotation, krate| {
|
||||
@ -1050,7 +1047,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
|
||||
hir_map,
|
||||
analysis,
|
||||
resolutions,
|
||||
arenas,
|
||||
output_filenames,
|
||||
crate_name,
|
||||
move |_annotation, krate| {
|
||||
@ -1066,7 +1062,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
|
||||
hir_map,
|
||||
analysis,
|
||||
resolutions,
|
||||
arenas,
|
||||
output_filenames,
|
||||
crate_name,
|
||||
move |annotation, _| {
|
||||
@ -1100,7 +1095,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
|
||||
hir_map,
|
||||
analysis,
|
||||
resolutions,
|
||||
arenas,
|
||||
output_filenames,
|
||||
crate_name,
|
||||
move |_annotation, _krate| {
|
||||
@ -1130,7 +1124,6 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
|
||||
analysis: &ty::CrateAnalysis,
|
||||
resolutions: &Resolutions,
|
||||
crate_name: &str,
|
||||
arenas: &'tcx AllArenas<'tcx>,
|
||||
output_filenames: &OutputFilenames,
|
||||
ppm: PpMode,
|
||||
uii: Option<UserIdentifiedItem>,
|
||||
@ -1147,6 +1140,7 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
|
||||
|
||||
let control = &driver::CompileController::basic();
|
||||
let codegen_backend = ::get_codegen_backend(sess);
|
||||
let mut arenas = AllArenas::new();
|
||||
abort_on_err(driver::phase_3_run_analysis_passes(&*codegen_backend,
|
||||
control,
|
||||
sess,
|
||||
@ -1154,7 +1148,7 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
|
||||
hir_map.clone(),
|
||||
analysis.clone(),
|
||||
resolutions.clone(),
|
||||
arenas,
|
||||
&mut arenas,
|
||||
crate_name,
|
||||
output_filenames,
|
||||
|tcx, _, _, _| {
|
||||
|
@ -151,7 +151,7 @@ fn test_env_with_pool<F>(
|
||||
).expect("phase 2 aborted")
|
||||
};
|
||||
|
||||
let arenas = ty::AllArenas::new();
|
||||
let mut arenas = ty::AllArenas::new();
|
||||
let hir_map = hir_map::map_crate(&sess, &cstore, &mut hir_forest, &defs);
|
||||
|
||||
// Run just enough stuff to build a tcx.
|
||||
@ -168,7 +168,7 @@ fn test_env_with_pool<F>(
|
||||
&cstore,
|
||||
ty::query::Providers::default(),
|
||||
ty::query::Providers::default(),
|
||||
&arenas,
|
||||
&mut arenas,
|
||||
resolutions,
|
||||
hir_map,
|
||||
OnDiskCache::new_empty(sess.source_map()),
|
||||
|
@ -485,7 +485,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
|
||||
glob_map: if resolver.make_glob_map { Some(resolver.glob_map.clone()) } else { None },
|
||||
};
|
||||
|
||||
let arenas = AllArenas::new();
|
||||
let mut arenas = AllArenas::new();
|
||||
let hir_map = hir_map::map_crate(&sess, &*cstore, &mut hir_forest, &defs);
|
||||
let output_filenames = driver::build_output_filenames(&input,
|
||||
&None,
|
||||
@ -501,7 +501,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
|
||||
hir_map,
|
||||
analysis,
|
||||
resolutions,
|
||||
&arenas,
|
||||
&mut arenas,
|
||||
&name,
|
||||
&output_filenames,
|
||||
|tcx, analysis, _, result| {
|
||||
|
Loading…
Reference in New Issue
Block a user