Skip to content

Commit

Permalink
Remove GlobalCtxt::enter_local
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Jun 28, 2020
1 parent 3b4a3d6 commit 4d978af
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 46 deletions.
36 changes: 17 additions & 19 deletions src/librustc_infer/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ impl<'tcx> fmt::Display for FixupError<'tcx> {
/// Necessary because we can't write the following bound:
/// `F: for<'b, 'tcx> where 'tcx FnOnce(InferCtxt<'b, 'tcx>)`.
pub struct InferCtxtBuilder<'tcx> {
global_tcx: TyCtxt<'tcx>,
tcx: TyCtxt<'tcx>,
fresh_tables: Option<RefCell<ty::TypeckTables<'tcx>>>,
}

Expand All @@ -580,7 +580,7 @@ pub trait TyCtxtInferExt<'tcx> {

impl TyCtxtInferExt<'tcx> for TyCtxt<'tcx> {
fn infer_ctxt(self) -> InferCtxtBuilder<'tcx> {
InferCtxtBuilder { global_tcx: self, fresh_tables: None }
InferCtxtBuilder { tcx: self, fresh_tables: None }
}
}

Expand Down Expand Up @@ -616,24 +616,22 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
}

pub fn enter<R>(&mut self, f: impl for<'a> FnOnce(InferCtxt<'a, 'tcx>) -> R) -> R {
let InferCtxtBuilder { global_tcx, ref fresh_tables } = *self;
let InferCtxtBuilder { tcx, ref fresh_tables } = *self;
let in_progress_tables = fresh_tables.as_ref();
global_tcx.enter_local(|tcx| {
f(InferCtxt {
tcx,
in_progress_tables,
inner: RefCell::new(InferCtxtInner::new()),
lexical_region_resolutions: RefCell::new(None),
selection_cache: Default::default(),
evaluation_cache: Default::default(),
reported_trait_errors: Default::default(),
reported_closure_mismatch: Default::default(),
tainted_by_errors_flag: Cell::new(false),
err_count_on_creation: tcx.sess.err_count(),
in_snapshot: Cell::new(false),
skip_leak_check: Cell::new(false),
universe: Cell::new(ty::UniverseIndex::ROOT),
})
f(InferCtxt {
tcx,
in_progress_tables,
inner: RefCell::new(InferCtxtInner::new()),
lexical_region_resolutions: RefCell::new(None),
selection_cache: Default::default(),
evaluation_cache: Default::default(),
reported_trait_errors: Default::default(),
reported_closure_mismatch: Default::default(),
tainted_by_errors_flag: Cell::new(false),
err_count_on_creation: tcx.sess.err_count(),
in_snapshot: Cell::new(false),
skip_leak_check: Cell::new(false),
universe: Cell::new(ty::UniverseIndex::ROOT),
})
}
}
Expand Down
32 changes: 5 additions & 27 deletions src/librustc_middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1553,28 +1553,6 @@ impl<'tcx> TyCtxt<'tcx> {
}
}

impl<'tcx> GlobalCtxt<'tcx> {
/// Calls the closure with a local `TyCtxt` using the given arena.
/// `interners` is a slot passed so we can create a CtxtInterners
/// with the same lifetime as `arena`.
pub fn enter_local<F, R>(&'tcx self, f: F) -> R
where
F: FnOnce(TyCtxt<'tcx>) -> R,
{
let tcx = TyCtxt { gcx: self };
ty::tls::with_related_context(tcx, |icx| {
let new_icx = ty::tls::ImplicitCtxt {
tcx,
query: icx.query,
diagnostics: icx.diagnostics,
layout_depth: icx.layout_depth,
task_deps: icx.task_deps,
};
ty::tls::enter_context(&new_icx, |_| f(tcx))
})
}
}

/// A trait implemented for all `X<'a>` types that can be safely and
/// efficiently converted to `X<'tcx>` as long as they are part of the
/// provided `TyCtxt<'tcx>`.
Expand Down Expand Up @@ -1811,11 +1789,11 @@ pub mod tls {
with_context_opt(|opt_context| f(opt_context.expect("no ImplicitCtxt stored in tls")))
}

/// Allows access to the current `ImplicitCtxt` whose tcx field has the same global
/// interner as the tcx argument passed in. This means the closure is given an `ImplicitCtxt`
/// with the same `'tcx` lifetime as the `TyCtxt` passed in.
/// This will panic if you pass it a `TyCtxt` which has a different global interner from
/// the current `ImplicitCtxt`'s `tcx` field.
/// Allows access to the current `ImplicitCtxt` whose tcx field is the same as the tcx argument
/// passed in. This means the closure is given an `ImplicitCtxt` with the same `'tcx` lifetime
/// as the `TyCtxt` passed in.
/// This will panic if you pass it a `TyCtxt` which is different from the current
/// `ImplicitCtxt`'s `tcx` field.
#[inline]
pub fn with_related_context<'tcx, F, R>(tcx: TyCtxt<'tcx>, f: F) -> R
where
Expand Down

0 comments on commit 4d978af

Please sign in to comment.