@@ -1632,7 +1632,6 @@ pub mod tls {
1632
1632
use crate :: ty:: query;
1633
1633
use rustc_data_structures:: sync:: { self , Lock } ;
1634
1634
use rustc_data_structures:: thin_vec:: ThinVec ;
1635
- use rustc_data_structures:: OnDrop ;
1636
1635
use rustc_errors:: Diagnostic ;
1637
1636
use std:: mem;
1638
1637
@@ -1649,8 +1648,7 @@ pub mod tls {
1649
1648
/// in this module.
1650
1649
#[ derive( Clone ) ]
1651
1650
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`.
1654
1652
pub tcx : TyCtxt < ' tcx > ,
1655
1653
1656
1654
/// The current query job, if any. This is updated by `JobOwner::start` in
@@ -1669,6 +1667,13 @@ pub mod tls {
1669
1667
pub task_deps : Option < & ' a Lock < TaskDeps > > ,
1670
1668
}
1671
1669
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
+
1672
1677
/// Sets Rayon's thread-local variable, which is preserved for Rayon jobs
1673
1678
/// to `value` during the call to `f`. It is restored to its previous value after.
1674
1679
/// This is used to set the pointer to the new `ImplicitCtxt`.
@@ -1682,7 +1687,7 @@ pub mod tls {
1682
1687
/// This is used to get the pointer to the current `ImplicitCtxt`.
1683
1688
#[ cfg( parallel_compiler) ]
1684
1689
#[ inline]
1685
- fn get_tlv ( ) -> usize {
1690
+ pub fn get_tlv ( ) -> usize {
1686
1691
rayon_core:: tlv:: get ( )
1687
1692
}
1688
1693
@@ -1699,7 +1704,7 @@ pub mod tls {
1699
1704
#[ inline]
1700
1705
fn set_tlv < F : FnOnce ( ) -> R , R > ( value : usize , f : F ) -> R {
1701
1706
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) ) ) ;
1703
1708
TLV . with ( |tlv| tlv. set ( value) ) ;
1704
1709
f ( )
1705
1710
}
@@ -1720,50 +1725,6 @@ pub mod tls {
1720
1725
set_tlv ( context as * const _ as usize , || f ( & context) )
1721
1726
}
1722
1727
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
-
1767
1728
/// Allows access to the current `ImplicitCtxt` in a closure if one is available.
1768
1729
#[ inline]
1769
1730
pub fn with_context_opt < F , R > ( f : F ) -> R
0 commit comments