@@ -1606,6 +1606,13 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
1606
1606
}
1607
1607
1608
1608
impl < ' gcx : ' tcx , ' tcx > GlobalCtxt < ' gcx > {
1609
+ pub fn tcx ( & self ) -> TyCtxt < ' _ , ' gcx , ' gcx > {
1610
+ TyCtxt {
1611
+ gcx : self ,
1612
+ interners : & self . global_interners ,
1613
+ }
1614
+ }
1615
+
1609
1616
/// Call the closure with a local `TyCtxt` using the given arena.
1610
1617
pub fn enter_local < F , R > (
1611
1618
& self ,
@@ -1616,21 +1623,9 @@ impl<'gcx: 'tcx, 'tcx> GlobalCtxt<'gcx> {
1616
1623
F : for < ' a > FnOnce ( TyCtxt < ' a , ' gcx , ' tcx > ) -> R
1617
1624
{
1618
1625
let interners = CtxtInterners :: new ( arena) ;
1619
- let tcx = TyCtxt {
1626
+ f ( TyCtxt {
1620
1627
gcx : self ,
1621
1628
interners : & interners,
1622
- } ;
1623
- ty:: tls:: with_related_context ( tcx. global_tcx ( ) , |icx| {
1624
- let new_icx = ty:: tls:: ImplicitCtxt {
1625
- tcx,
1626
- query : icx. query ,
1627
- diagnostics : icx. diagnostics ,
1628
- layout_depth : icx. layout_depth ,
1629
- task : icx. task ,
1630
- } ;
1631
- ty:: tls:: enter_context ( & new_icx, |new_icx| {
1632
- f ( new_icx. tcx )
1633
- } )
1634
1629
} )
1635
1630
}
1636
1631
}
@@ -1888,10 +1883,10 @@ pub mod tls {
1888
1883
/// you should also have access to an ImplicitCtxt through the functions
1889
1884
/// in this module.
1890
1885
#[ derive( Clone ) ]
1891
- pub struct ImplicitCtxt < ' a , ' gcx : ' a + ' tcx , ' tcx : ' a > {
1886
+ pub struct ImplicitCtxt < ' a , ' gcx > {
1892
1887
/// The current TyCtxt. Initially created by `enter_global` and updated
1893
1888
/// by `enter_local` with a new local interner
1894
- pub tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
1889
+ pub gcx : & ' a GlobalCtxt < ' gcx > ,
1895
1890
1896
1891
/// The current query job, if any. This is updated by start_job in
1897
1892
/// ty::query::plumbing when executing a query
@@ -2010,9 +2005,9 @@ pub mod tls {
2010
2005
2011
2006
/// Sets `context` as the new current ImplicitCtxt for the duration of the function `f`
2012
2007
#[ inline]
2013
- pub fn enter_context < ' a , ' gcx : ' tcx , ' tcx , F , R > ( context : & ImplicitCtxt < ' a , ' gcx , ' tcx > ,
2008
+ pub fn enter_context < ' a , ' gcx , F , R > ( context : & ImplicitCtxt < ' a , ' gcx > ,
2014
2009
f : F ) -> R
2015
- where F : FnOnce ( & ImplicitCtxt < ' a , ' gcx , ' tcx > ) -> R
2010
+ where F : FnOnce ( & ImplicitCtxt < ' a , ' gcx > ) -> R
2016
2011
{
2017
2012
set_tlv ( context as * const _ as usize , || {
2018
2013
f ( & context)
@@ -2041,7 +2036,7 @@ pub mod tls {
2041
2036
interners : & gcx. global_interners ,
2042
2037
} ;
2043
2038
let icx = ImplicitCtxt {
2044
- tcx ,
2039
+ gcx ,
2045
2040
query : None ,
2046
2041
diagnostics : None ,
2047
2042
layout_depth : 0 ,
@@ -2073,7 +2068,7 @@ pub mod tls {
2073
2068
let icx = ImplicitCtxt {
2074
2069
query : None ,
2075
2070
diagnostics : None ,
2076
- tcx ,
2071
+ gcx ,
2077
2072
layout_depth : 0 ,
2078
2073
task : & OpenTask :: Ignore ,
2079
2074
} ;
@@ -2083,25 +2078,25 @@ pub mod tls {
2083
2078
/// Allows access to the current ImplicitCtxt in a closure if one is available
2084
2079
#[ inline]
2085
2080
pub fn with_context_opt < F , R > ( f : F ) -> R
2086
- where F : for <' a , ' gcx , ' tcx > FnOnce ( Option < & ImplicitCtxt < ' a , ' gcx , ' tcx > > ) -> R
2081
+ where F : for <' a , ' gcx > FnOnce ( Option < & ImplicitCtxt < ' a , ' gcx > > ) -> R
2087
2082
{
2088
2083
let context = get_tlv ( ) ;
2089
2084
if context == 0 {
2090
2085
f ( None )
2091
2086
} else {
2092
2087
// We could get a ImplicitCtxt pointer from another thread.
2093
2088
// Ensure that ImplicitCtxt is Sync
2094
- sync:: assert_sync :: < ImplicitCtxt < ' _ , ' _ , ' _ > > ( ) ;
2089
+ sync:: assert_sync :: < ImplicitCtxt < ' _ , ' _ > > ( ) ;
2095
2090
2096
- unsafe { f ( Some ( & * ( context as * const ImplicitCtxt < ' _ , ' _ , ' _ > ) ) ) }
2091
+ unsafe { f ( Some ( & * ( context as * const ImplicitCtxt < ' _ , ' _ > ) ) ) }
2097
2092
}
2098
2093
}
2099
2094
2100
2095
/// Allows access to the current ImplicitCtxt.
2101
2096
/// Panics if there is no ImplicitCtxt available
2102
2097
#[ inline]
2103
2098
pub fn with_context < F , R > ( f : F ) -> R
2104
- where F : for <' a , ' gcx , ' tcx > FnOnce ( & ImplicitCtxt < ' a , ' gcx , ' tcx > ) -> R
2099
+ where F : for <' a , ' gcx > FnOnce ( & ImplicitCtxt < ' a , ' gcx > ) -> R
2105
2100
{
2106
2101
with_context_opt ( |opt_context| f ( opt_context. expect ( "no ImplicitCtxt stored in tls" ) ) )
2107
2102
}
@@ -2112,35 +2107,14 @@ pub mod tls {
2112
2107
/// This will panic if you pass it a TyCtxt which has a different global interner from
2113
2108
/// the current ImplicitCtxt's tcx field.
2114
2109
#[ inline]
2115
- pub fn with_related_context < ' a , ' gcx , ' tcx1 , F , R > ( tcx : TyCtxt < ' a , ' gcx , ' tcx1 > , f : F ) -> R
2116
- where F : for <' b , ' tcx2 > FnOnce ( & ImplicitCtxt < ' b , ' gcx , ' tcx2 > ) -> R
2110
+ pub fn with_related_context < ' a , ' gcx , ' tcx , F , R > ( tcx : TyCtxt < ' a , ' gcx , ' tcx > , f : F ) -> R
2111
+ where F : for < ' b > FnOnce ( & ImplicitCtxt < ' b , ' gcx > ) -> R
2117
2112
{
2118
2113
with_context ( |context| {
2119
2114
unsafe {
2120
2115
let gcx = tcx. gcx as * const _ as usize ;
2121
- assert ! ( context. tcx. gcx as * const _ as usize == gcx) ;
2122
- let context: & ImplicitCtxt < ' _ , ' _ , ' _ > = mem:: transmute ( context) ;
2123
- f ( context)
2124
- }
2125
- } )
2126
- }
2127
-
2128
- /// Allows access to the current ImplicitCtxt whose tcx field has the same global
2129
- /// interner and local interner as the tcx argument passed in. This means the closure
2130
- /// is given an ImplicitCtxt with the same 'tcx and 'gcx lifetimes as the TyCtxt passed in.
2131
- /// This will panic if you pass it a TyCtxt which has a different global interner or
2132
- /// a different local interner from the current ImplicitCtxt's tcx field.
2133
- #[ inline]
2134
- pub fn with_fully_related_context < ' a , ' gcx , ' tcx , F , R > ( tcx : TyCtxt < ' a , ' gcx , ' tcx > , f : F ) -> R
2135
- where F : for < ' b > FnOnce ( & ImplicitCtxt < ' b , ' gcx , ' tcx > ) -> R
2136
- {
2137
- with_context ( |context| {
2138
- unsafe {
2139
- let gcx = tcx. gcx as * const _ as usize ;
2140
- let interners = tcx. interners as * const _ as usize ;
2141
- assert ! ( context. tcx. gcx as * const _ as usize == gcx) ;
2142
- assert ! ( context. tcx. interners as * const _ as usize == interners) ;
2143
- let context: & ImplicitCtxt < ' _ , ' _ , ' _ > = mem:: transmute ( context) ;
2116
+ assert ! ( context. gcx as * const _ as usize == gcx) ;
2117
+ let context: & ImplicitCtxt < ' _ , ' _ > = mem:: transmute ( context) ;
2144
2118
f ( context)
2145
2119
}
2146
2120
} )
@@ -2150,18 +2124,18 @@ pub mod tls {
2150
2124
/// Panics if there is no ImplicitCtxt available
2151
2125
#[ inline]
2152
2126
pub fn with < F , R > ( f : F ) -> R
2153
- where F : for <' a , ' gcx , ' tcx > FnOnce ( TyCtxt < ' a , ' gcx , ' tcx > ) -> R
2127
+ where F : for <' a , ' gcx > FnOnce ( TyCtxt < ' a , ' gcx , ' gcx > ) -> R
2154
2128
{
2155
- with_context ( |context| f ( context. tcx ) )
2129
+ with_context ( |context| f ( context. gcx . tcx ( ) ) )
2156
2130
}
2157
2131
2158
2132
/// Allows access to the TyCtxt in the current ImplicitCtxt.
2159
2133
/// The closure is passed None if there is no ImplicitCtxt available
2160
2134
#[ inline]
2161
2135
pub fn with_opt < F , R > ( f : F ) -> R
2162
- where F : for <' a , ' gcx , ' tcx > FnOnce ( Option < TyCtxt < ' a , ' gcx , ' tcx > > ) -> R
2136
+ where F : for <' a , ' gcx > FnOnce ( Option < TyCtxt < ' a , ' gcx , ' gcx > > ) -> R
2163
2137
{
2164
- with_context_opt ( |opt_context| f ( opt_context. map ( |context| context. tcx ) ) )
2138
+ with_context_opt ( |opt_context| f ( opt_context. map ( |context| context. gcx . tcx ( ) ) ) )
2165
2139
}
2166
2140
}
2167
2141
0 commit comments