@@ -1632,7 +1632,6 @@ pub mod tls {
16321632 use crate :: ty:: query;
16331633 use rustc_data_structures:: sync:: { self , Lock } ;
16341634 use rustc_data_structures:: thin_vec:: ThinVec ;
1635- use rustc_data_structures:: OnDrop ;
16361635 use rustc_errors:: Diagnostic ;
16371636 use std:: mem;
16381637
@@ -1649,8 +1648,7 @@ pub mod tls {
16491648 /// in this module.
16501649 #[ derive( Clone ) ]
16511650 pub struct ImplicitCtxt < ' a , ' tcx > {
1652- /// The current `TyCtxt`. Initially created by `enter_global` and updated
1653- /// by `enter_local` with a new local interner.
1651+ /// The current `TyCtxt`.
16541652 pub tcx : TyCtxt < ' tcx > ,
16551653
16561654 /// The current query job, if any. This is updated by `JobOwner::start` in
@@ -1669,6 +1667,13 @@ pub mod tls {
16691667 pub task_deps : Option < & ' a Lock < TaskDeps > > ,
16701668 }
16711669
1670+ impl < ' a , ' tcx > ImplicitCtxt < ' a , ' tcx > {
1671+ pub fn new ( gcx : & ' tcx GlobalCtxt < ' tcx > ) -> Self {
1672+ let tcx = TyCtxt { gcx } ;
1673+ ImplicitCtxt { tcx, query : None , diagnostics : None , layout_depth : 0 , task_deps : None }
1674+ }
1675+ }
1676+
16721677 /// Sets Rayon's thread-local variable, which is preserved for Rayon jobs
16731678 /// to `value` during the call to `f`. It is restored to its previous value after.
16741679 /// This is used to set the pointer to the new `ImplicitCtxt`.
@@ -1682,7 +1687,7 @@ pub mod tls {
16821687 /// This is used to get the pointer to the current `ImplicitCtxt`.
16831688 #[ cfg( parallel_compiler) ]
16841689 #[ inline]
1685- fn get_tlv ( ) -> usize {
1690+ pub fn get_tlv ( ) -> usize {
16861691 rayon_core:: tlv:: get ( )
16871692 }
16881693
@@ -1699,7 +1704,7 @@ pub mod tls {
16991704 #[ inline]
17001705 fn set_tlv < F : FnOnce ( ) -> R , R > ( value : usize , f : F ) -> R {
17011706 let old = get_tlv ( ) ;
1702- let _reset = OnDrop ( move || TLV . with ( |tlv| tlv. set ( old) ) ) ;
1707+ let _reset = rustc_data_structures :: OnDrop ( move || TLV . with ( |tlv| tlv. set ( old) ) ) ;
17031708 TLV . with ( |tlv| tlv. set ( value) ) ;
17041709 f ( )
17051710 }
@@ -1720,50 +1725,6 @@ pub mod tls {
17201725 set_tlv ( context as * const _ as usize , || f ( & context) )
17211726 }
17221727
1723- /// Enters `GlobalCtxt` by setting up librustc_ast callbacks and
1724- /// creating a initial `TyCtxt` and `ImplicitCtxt`.
1725- /// This happens once per rustc session and `TyCtxt`s only exists
1726- /// inside the `f` function.
1727- pub fn enter_global < ' tcx , F , R > ( gcx : & ' tcx GlobalCtxt < ' tcx > , f : F ) -> R
1728- where
1729- F : FnOnce ( TyCtxt < ' tcx > ) -> R ,
1730- {
1731- // Update `GCX_PTR` to indicate there's a `GlobalCtxt` available.
1732- GCX_PTR . with ( |lock| {
1733- * lock. lock ( ) = gcx as * const _ as usize ;
1734- } ) ;
1735- // Set `GCX_PTR` back to 0 when we exit.
1736- let _on_drop = OnDrop ( move || {
1737- GCX_PTR . with ( |lock| * lock. lock ( ) = 0 ) ;
1738- } ) ;
1739-
1740- let tcx = TyCtxt { gcx } ;
1741- let icx =
1742- ImplicitCtxt { tcx, query : None , diagnostics : None , layout_depth : 0 , task_deps : None } ;
1743- enter_context ( & icx, |_| f ( tcx) )
1744- }
1745-
1746- scoped_thread_local ! {
1747- /// Stores a pointer to the `GlobalCtxt` if one is available.
1748- /// This is used to access the `GlobalCtxt` in the deadlock handler given to Rayon.
1749- pub static GCX_PTR : Lock <usize >
1750- }
1751-
1752- /// Creates a `TyCtxt` and `ImplicitCtxt` based on the `GCX_PTR` thread local.
1753- /// This is used in the deadlock handler.
1754- pub unsafe fn with_global < F , R > ( f : F ) -> R
1755- where
1756- F : for < ' tcx > FnOnce ( TyCtxt < ' tcx > ) -> R ,
1757- {
1758- let gcx = GCX_PTR . with ( |lock| * lock. lock ( ) ) ;
1759- assert ! ( gcx != 0 ) ;
1760- let gcx = & * ( gcx as * const GlobalCtxt < ' _ > ) ;
1761- let tcx = TyCtxt { gcx } ;
1762- let icx =
1763- ImplicitCtxt { query : None , diagnostics : None , tcx, layout_depth : 0 , task_deps : None } ;
1764- enter_context ( & icx, |_| f ( tcx) )
1765- }
1766-
17671728 /// Allows access to the current `ImplicitCtxt` in a closure if one is available.
17681729 #[ inline]
17691730 pub fn with_context_opt < F , R > ( f : F ) -> R
0 commit comments