Skip to content

Commit 1f1c575

Browse files
committed
Make the 'a lifetime on TyCtxt useless
1 parent 0076f58 commit 1f1c575

File tree

9 files changed

+51
-47
lines changed

9 files changed

+51
-47
lines changed

src/librustc/infer/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
3737
use ty::fold::TypeFoldable;
3838
use ty::relate::RelateResult;
3939
use ty::subst::{Kind, Substs};
40-
use ty::{self, GenericParamDefKind, Ty, TyCtxt};
40+
use ty::{self, GenericParamDefKind, Ty, TyCtxt, CtxtInterners};
4141
use ty::{FloatVid, IntVid, TyVid};
4242
use util::nodemap::FxHashMap;
4343

@@ -471,6 +471,7 @@ impl fmt::Display for FixupError {
471471
pub struct InferCtxtBuilder<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
472472
global_tcx: TyCtxt<'a, 'gcx, 'gcx>,
473473
arena: SyncDroplessArena,
474+
interners: Option<CtxtInterners<'tcx>>,
474475
fresh_tables: Option<RefCell<ty::TypeckTables<'tcx>>>,
475476
}
476477

@@ -479,6 +480,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'gcx> {
479480
InferCtxtBuilder {
480481
global_tcx: self,
481482
arena: SyncDroplessArena::default(),
483+
interners: None,
482484
fresh_tables: None,
483485
}
484486
}
@@ -519,10 +521,11 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
519521
let InferCtxtBuilder {
520522
global_tcx,
521523
ref arena,
524+
ref mut interners,
522525
ref fresh_tables,
523526
} = *self;
524527
let in_progress_tables = fresh_tables.as_ref();
525-
global_tcx.enter_local(arena, |tcx| {
528+
global_tcx.enter_local(arena, interners, |tcx| {
526529
f(InferCtxt {
527530
tcx,
528531
in_progress_tables,

src/librustc/ty/context.rs

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ use std::ops::{Deref, Bound};
7272
use std::iter;
7373
use std::sync::mpsc;
7474
use std::sync::Arc;
75+
use std::marker::PhantomData;
7576
use rustc_target::spec::abi;
7677
use syntax::ast::{self, NodeId};
7778
use syntax::attr;
@@ -86,13 +87,15 @@ use hir;
8687
pub struct AllArenas<'tcx> {
8788
pub global: WorkerLocal<GlobalArenas<'tcx>>,
8889
pub interner: SyncDroplessArena,
90+
global_ctxt: Option<GlobalCtxt<'tcx>>,
8991
}
9092

9193
impl<'tcx> AllArenas<'tcx> {
9294
pub fn new() -> Self {
9395
AllArenas {
9496
global: WorkerLocal::new(|_| GlobalArenas::default()),
9597
interner: SyncDroplessArena::default(),
98+
global_ctxt: None,
9699
}
97100
}
98101
}
@@ -869,12 +872,13 @@ pub struct FreeRegionInfo {
869872
/// [rustc guide]: https://rust-lang.github.io/rustc-guide/ty.html
870873
#[derive(Copy, Clone)]
871874
pub struct TyCtxt<'a, 'gcx: 'tcx, 'tcx: 'a> {
872-
gcx: &'a GlobalCtxt<'gcx>,
873-
interners: &'a CtxtInterners<'tcx>
875+
gcx: &'gcx GlobalCtxt<'gcx>,
876+
interners: &'tcx CtxtInterners<'tcx>,
877+
dummy: PhantomData<&'a ()>,
874878
}
875879

876-
impl<'a, 'gcx, 'tcx> Deref for TyCtxt<'a, 'gcx, 'tcx> {
877-
type Target = &'a GlobalCtxt<'gcx>;
880+
impl<'gcx> Deref for TyCtxt<'_, 'gcx, '_> {
881+
type Target = &'gcx GlobalCtxt<'gcx>;
878882
#[inline(always)]
879883
fn deref(&self) -> &Self::Target {
880884
&self.gcx
@@ -964,10 +968,11 @@ pub struct GlobalCtxt<'tcx> {
964968
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
965969
/// Get the global TyCtxt.
966970
#[inline]
967-
pub fn global_tcx(self) -> TyCtxt<'a, 'gcx, 'gcx> {
971+
pub fn global_tcx(self) -> TyCtxt<'gcx, 'gcx, 'gcx> {
968972
TyCtxt {
969973
gcx: self.gcx,
970974
interners: &self.gcx.global_interners,
975+
dummy: PhantomData,
971976
}
972977
}
973978

@@ -1105,7 +1110,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11051110
cstore: &'tcx CrateStoreDyn,
11061111
local_providers: ty::query::Providers<'tcx>,
11071112
extern_providers: ty::query::Providers<'tcx>,
1108-
arenas: &'tcx AllArenas<'tcx>,
1113+
arenas: &'tcx mut AllArenas<'tcx>,
11091114
resolutions: ty::Resolutions,
11101115
hir: hir_map::Map<'tcx>,
11111116
on_disk_query_result_cache: query::OnDiskCache<'tcx>,
@@ -1166,7 +1171,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11661171
Lrc::new(StableVec::new(v)));
11671172
}
11681173

1169-
let gcx = &GlobalCtxt {
1174+
arenas.global_ctxt = Some(GlobalCtxt {
11701175
sess: s,
11711176
cstore,
11721177
global_arenas: &arenas.global,
@@ -1209,7 +1214,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
12091214
alloc_map: Lock::new(interpret::AllocMap::new()),
12101215
tx_to_llvm_workers: Lock::new(tx),
12111216
output_filenames: Arc::new(output_filenames.clone()),
1212-
};
1217+
});
1218+
1219+
let gcx = arenas.global_ctxt.as_ref().unwrap();
12131220

12141221
sync::assert_send_val(&gcx);
12151222

@@ -1609,20 +1616,23 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
16091616
}
16101617
}
16111618

1612-
impl<'gcx: 'tcx, 'tcx> GlobalCtxt<'gcx> {
1619+
impl<'gcx> GlobalCtxt<'gcx> {
16131620
/// Call the closure with a local `TyCtxt` using the given arena.
1614-
pub fn enter_local<F, R>(
1615-
&self,
1621+
pub fn enter_local<'tcx, F, R>(
1622+
&'gcx self,
16161623
arena: &'tcx SyncDroplessArena,
1624+
interners: &'tcx mut Option<CtxtInterners<'tcx>>,
16171625
f: F
16181626
) -> R
16191627
where
1620-
F: for<'a> FnOnce(TyCtxt<'a, 'gcx, 'tcx>) -> R
1628+
F: FnOnce(TyCtxt<'tcx, 'gcx, 'tcx>) -> R,
1629+
'gcx: 'tcx,
16211630
{
1622-
let interners = CtxtInterners::new(arena);
1631+
*interners = Some(CtxtInterners::new(&arena));
16231632
let tcx = TyCtxt {
16241633
gcx: self,
1625-
interners: &interners,
1634+
interners: interners.as_ref().unwrap(),
1635+
dummy: PhantomData,
16261636
};
16271637
ty::tls::with_related_context(tcx.global_tcx(), |icx| {
16281638
let new_icx = ty::tls::ImplicitCtxt {
@@ -1631,8 +1641,8 @@ impl<'gcx: 'tcx, 'tcx> GlobalCtxt<'gcx> {
16311641
layout_depth: icx.layout_depth,
16321642
task: icx.task,
16331643
};
1634-
ty::tls::enter_context(&new_icx, |new_icx| {
1635-
f(new_icx.tcx)
1644+
ty::tls::enter_context(&new_icx, |_| {
1645+
f(tcx)
16361646
})
16371647
})
16381648
}
@@ -1872,6 +1882,7 @@ pub mod tls {
18721882

18731883
use std::fmt;
18741884
use std::mem;
1885+
use std::marker::PhantomData;
18751886
use syntax_pos;
18761887
use ty::query;
18771888
use errors::{Diagnostic, TRACK_DIAGNOSTICS};
@@ -1891,10 +1902,10 @@ pub mod tls {
18911902
/// you should also have access to an ImplicitCtxt through the functions
18921903
/// in this module.
18931904
#[derive(Clone)]
1894-
pub struct ImplicitCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
1905+
pub struct ImplicitCtxt<'a, 'gcx: 'tcx, 'tcx> {
18951906
/// The current TyCtxt. Initially created by `enter_global` and updated
18961907
/// by `enter_local` with a new local interner
1897-
pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
1908+
pub tcx: TyCtxt<'tcx, 'gcx, 'tcx>,
18981909

18991910
/// The current query job, if any. This is updated by start_job in
19001911
/// ty::query::plumbing when executing a query
@@ -2008,7 +2019,7 @@ pub mod tls {
20082019
/// creating a initial TyCtxt and ImplicitCtxt.
20092020
/// This happens once per rustc session and TyCtxts only exists
20102021
/// inside the `f` function.
2011-
pub fn enter_global<'gcx, F, R>(gcx: &GlobalCtxt<'gcx>, f: F) -> R
2022+
pub fn enter_global<'gcx, F, R>(gcx: &'gcx GlobalCtxt<'gcx>, f: F) -> R
20122023
where F: for<'a> FnOnce(TyCtxt<'a, 'gcx, 'gcx>) -> R
20132024
{
20142025
with_thread_locals(|| {
@@ -2024,6 +2035,7 @@ pub mod tls {
20242035
let tcx = TyCtxt {
20252036
gcx,
20262037
interners: &gcx.global_interners,
2038+
dummy: PhantomData,
20272039
};
20282040
let icx = ImplicitCtxt {
20292041
tcx,
@@ -2053,6 +2065,7 @@ pub mod tls {
20532065
let tcx = TyCtxt {
20542066
gcx,
20552067
interners: &gcx.global_interners,
2068+
dummy: PhantomData,
20562069
};
20572070
let icx = ImplicitCtxt {
20582071
query: None,

src/librustc/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub use self::binding::BindingMode;
8282
pub use self::binding::BindingMode::*;
8383

8484
pub use self::context::{TyCtxt, FreeRegionInfo, GlobalArenas, AllArenas, tls, keep_local};
85-
pub use self::context::{Lift, TypeckTables};
85+
pub use self::context::{Lift, TypeckTables, CtxtInterners};
8686

8787
pub use self::instance::{Instance, InstanceDef};
8888

src/librustc/ty/query/plumbing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
197197
let r = tls::with_related_context(tcx, move |current_icx| {
198198
// Update the ImplicitCtxt to point to our new query job
199199
let new_icx = tls::ImplicitCtxt {
200-
tcx,
200+
tcx: tcx.global_tcx(),
201201
query: Some(self.job.clone()),
202202
layout_depth: current_icx.layout_depth,
203203
task: current_icx.task,

src/librustc_driver/driver.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,6 @@ pub fn compile_input(
246246
}
247247
}
248248

249-
let arenas = AllArenas::new();
250-
251249
// Construct the HIR map
252250
let hir_map = time(sess, "indexing hir", || {
253251
hir_map::map_crate(sess, cstore, &mut hir_forest, &defs)
@@ -263,7 +261,6 @@ pub fn compile_input(
263261
sess,
264262
outdir,
265263
output,
266-
&arenas,
267264
&cstore,
268265
&hir_map,
269266
&analysis,
@@ -284,6 +281,8 @@ pub fn compile_input(
284281
None
285282
};
286283

284+
let mut arenas = AllArenas::new();
285+
287286
phase_3_run_analysis_passes(
288287
&*codegen_backend,
289288
control,
@@ -292,7 +291,7 @@ pub fn compile_input(
292291
hir_map,
293292
analysis,
294293
resolutions,
295-
&arenas,
294+
&mut arenas,
296295
&crate_name,
297296
&outputs,
298297
|tcx, analysis, rx, result| {
@@ -533,7 +532,6 @@ pub struct CompileState<'a, 'tcx: 'a> {
533532
pub output_filenames: Option<&'a OutputFilenames>,
534533
pub out_dir: Option<&'a Path>,
535534
pub out_file: Option<&'a Path>,
536-
pub arenas: Option<&'tcx AllArenas<'tcx>>,
537535
pub expanded_crate: Option<&'a ast::Crate>,
538536
pub hir_crate: Option<&'a hir::Crate>,
539537
pub hir_map: Option<&'a hir_map::Map<'tcx>>,
@@ -549,7 +547,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
549547
session,
550548
out_dir: out_dir.as_ref().map(|s| &**s),
551549
out_file: None,
552-
arenas: None,
553550
krate: None,
554551
registry: None,
555552
cstore: None,
@@ -605,7 +602,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
605602
session: &'tcx Session,
606603
out_dir: &'a Option<PathBuf>,
607604
out_file: &'a Option<PathBuf>,
608-
arenas: &'tcx AllArenas<'tcx>,
609605
cstore: &'tcx CStore,
610606
hir_map: &'a hir_map::Map<'tcx>,
611607
analysis: &'a ty::CrateAnalysis,
@@ -617,7 +613,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
617613
) -> Self {
618614
CompileState {
619615
crate_name: Some(crate_name),
620-
arenas: Some(arenas),
621616
cstore: Some(cstore),
622617
hir_map: Some(hir_map),
623618
analysis: Some(analysis),
@@ -1216,7 +1211,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(
12161211
hir_map: hir_map::Map<'tcx>,
12171212
mut analysis: ty::CrateAnalysis,
12181213
resolutions: Resolutions,
1219-
arenas: &'tcx AllArenas<'tcx>,
1214+
arenas: &'tcx mut AllArenas<'tcx>,
12201215
name: &str,
12211216
output_filenames: &OutputFilenames,
12221217
f: F,

src/librustc_driver/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,6 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
911911
&state.expanded_crate.take().unwrap(),
912912
state.crate_name.unwrap(),
913913
ppm,
914-
state.arenas.unwrap(),
915914
state.output_filenames.unwrap(),
916915
opt_uii.clone(),
917916
state.out_file);

0 commit comments

Comments
 (0)