|
2 | 2 |
|
3 | 3 | #![allow(rustc::usage_of_ty_tykind)]
|
4 | 4 |
|
| 5 | +pub mod tls; |
| 6 | + |
5 | 7 | use crate::arena::Arena;
|
6 | 8 | use crate::dep_graph::{DepGraph, DepKindStruct};
|
7 | 9 | use crate::infer::canonical::{CanonicalVarInfo, CanonicalVarInfos};
|
@@ -1212,178 +1214,6 @@ CloneLiftImpls! { for<'tcx> {
|
1212 | 1214 | Constness, traits::WellFormedLoc, ImplPolarity, crate::mir::ReturnConstraint,
|
1213 | 1215 | } }
|
1214 | 1216 |
|
1215 |
| -pub mod tls { |
1216 |
| - use super::{ptr_eq, GlobalCtxt, TyCtxt}; |
1217 |
| - |
1218 |
| - use crate::dep_graph::TaskDepsRef; |
1219 |
| - use crate::ty::query; |
1220 |
| - use rustc_data_structures::sync::{self, Lock}; |
1221 |
| - use rustc_errors::Diagnostic; |
1222 |
| - use std::mem; |
1223 |
| - use thin_vec::ThinVec; |
1224 |
| - |
1225 |
| - #[cfg(not(parallel_compiler))] |
1226 |
| - use std::cell::Cell; |
1227 |
| - |
1228 |
| - #[cfg(parallel_compiler)] |
1229 |
| - use rustc_rayon_core as rayon_core; |
1230 |
| - |
1231 |
| - /// This is the implicit state of rustc. It contains the current |
1232 |
| - /// `TyCtxt` and query. It is updated when creating a local interner or |
1233 |
| - /// executing a new query. Whenever there's a `TyCtxt` value available |
1234 |
| - /// you should also have access to an `ImplicitCtxt` through the functions |
1235 |
| - /// in this module. |
1236 |
| - #[derive(Clone)] |
1237 |
| - pub struct ImplicitCtxt<'a, 'tcx> { |
1238 |
| - /// The current `TyCtxt`. |
1239 |
| - pub tcx: TyCtxt<'tcx>, |
1240 |
| - |
1241 |
| - /// The current query job, if any. This is updated by `JobOwner::start` in |
1242 |
| - /// `ty::query::plumbing` when executing a query. |
1243 |
| - pub query: Option<query::QueryJobId>, |
1244 |
| - |
1245 |
| - /// Where to store diagnostics for the current query job, if any. |
1246 |
| - /// This is updated by `JobOwner::start` in `ty::query::plumbing` when executing a query. |
1247 |
| - pub diagnostics: Option<&'a Lock<ThinVec<Diagnostic>>>, |
1248 |
| - |
1249 |
| - /// Used to prevent queries from calling too deeply. |
1250 |
| - pub query_depth: usize, |
1251 |
| - |
1252 |
| - /// The current dep graph task. This is used to add dependencies to queries |
1253 |
| - /// when executing them. |
1254 |
| - pub task_deps: TaskDepsRef<'a>, |
1255 |
| - } |
1256 |
| - |
1257 |
| - impl<'a, 'tcx> ImplicitCtxt<'a, 'tcx> { |
1258 |
| - pub fn new(gcx: &'tcx GlobalCtxt<'tcx>) -> Self { |
1259 |
| - let tcx = TyCtxt { gcx }; |
1260 |
| - ImplicitCtxt { |
1261 |
| - tcx, |
1262 |
| - query: None, |
1263 |
| - diagnostics: None, |
1264 |
| - query_depth: 0, |
1265 |
| - task_deps: TaskDepsRef::Ignore, |
1266 |
| - } |
1267 |
| - } |
1268 |
| - } |
1269 |
| - |
1270 |
| - /// Sets Rayon's thread-local variable, which is preserved for Rayon jobs |
1271 |
| - /// to `value` during the call to `f`. It is restored to its previous value after. |
1272 |
| - /// This is used to set the pointer to the new `ImplicitCtxt`. |
1273 |
| - #[cfg(parallel_compiler)] |
1274 |
| - #[inline] |
1275 |
| - fn set_tlv<F: FnOnce() -> R, R>(value: usize, f: F) -> R { |
1276 |
| - rayon_core::tlv::with(value, f) |
1277 |
| - } |
1278 |
| - |
1279 |
| - /// Gets Rayon's thread-local variable, which is preserved for Rayon jobs. |
1280 |
| - /// This is used to get the pointer to the current `ImplicitCtxt`. |
1281 |
| - #[cfg(parallel_compiler)] |
1282 |
| - #[inline] |
1283 |
| - pub fn get_tlv() -> usize { |
1284 |
| - rayon_core::tlv::get() |
1285 |
| - } |
1286 |
| - |
1287 |
| - #[cfg(not(parallel_compiler))] |
1288 |
| - thread_local! { |
1289 |
| - /// A thread local variable that stores a pointer to the current `ImplicitCtxt`. |
1290 |
| - static TLV: Cell<usize> = const { Cell::new(0) }; |
1291 |
| - } |
1292 |
| - |
1293 |
| - /// Sets TLV to `value` during the call to `f`. |
1294 |
| - /// It is restored to its previous value after. |
1295 |
| - /// This is used to set the pointer to the new `ImplicitCtxt`. |
1296 |
| - #[cfg(not(parallel_compiler))] |
1297 |
| - #[inline] |
1298 |
| - fn set_tlv<F: FnOnce() -> R, R>(value: usize, f: F) -> R { |
1299 |
| - let old = get_tlv(); |
1300 |
| - let _reset = rustc_data_structures::OnDrop(move || TLV.with(|tlv| tlv.set(old))); |
1301 |
| - TLV.with(|tlv| tlv.set(value)); |
1302 |
| - f() |
1303 |
| - } |
1304 |
| - |
1305 |
| - /// Gets the pointer to the current `ImplicitCtxt`. |
1306 |
| - #[cfg(not(parallel_compiler))] |
1307 |
| - #[inline] |
1308 |
| - fn get_tlv() -> usize { |
1309 |
| - TLV.with(|tlv| tlv.get()) |
1310 |
| - } |
1311 |
| - |
1312 |
| - /// Sets `context` as the new current `ImplicitCtxt` for the duration of the function `f`. |
1313 |
| - #[inline] |
1314 |
| - pub fn enter_context<'a, 'tcx, F, R>(context: &ImplicitCtxt<'a, 'tcx>, f: F) -> R |
1315 |
| - where |
1316 |
| - F: FnOnce(&ImplicitCtxt<'a, 'tcx>) -> R, |
1317 |
| - { |
1318 |
| - set_tlv(context as *const _ as usize, || f(&context)) |
1319 |
| - } |
1320 |
| - |
1321 |
| - /// Allows access to the current `ImplicitCtxt` in a closure if one is available. |
1322 |
| - #[inline] |
1323 |
| - pub fn with_context_opt<F, R>(f: F) -> R |
1324 |
| - where |
1325 |
| - F: for<'a, 'tcx> FnOnce(Option<&ImplicitCtxt<'a, 'tcx>>) -> R, |
1326 |
| - { |
1327 |
| - let context = get_tlv(); |
1328 |
| - if context == 0 { |
1329 |
| - f(None) |
1330 |
| - } else { |
1331 |
| - // We could get an `ImplicitCtxt` pointer from another thread. |
1332 |
| - // Ensure that `ImplicitCtxt` is `Sync`. |
1333 |
| - sync::assert_sync::<ImplicitCtxt<'_, '_>>(); |
1334 |
| - |
1335 |
| - unsafe { f(Some(&*(context as *const ImplicitCtxt<'_, '_>))) } |
1336 |
| - } |
1337 |
| - } |
1338 |
| - |
1339 |
| - /// Allows access to the current `ImplicitCtxt`. |
1340 |
| - /// Panics if there is no `ImplicitCtxt` available. |
1341 |
| - #[inline] |
1342 |
| - pub fn with_context<F, R>(f: F) -> R |
1343 |
| - where |
1344 |
| - F: for<'a, 'tcx> FnOnce(&ImplicitCtxt<'a, 'tcx>) -> R, |
1345 |
| - { |
1346 |
| - with_context_opt(|opt_context| f(opt_context.expect("no ImplicitCtxt stored in tls"))) |
1347 |
| - } |
1348 |
| - |
1349 |
| - /// Allows access to the current `ImplicitCtxt` whose tcx field is the same as the tcx argument |
1350 |
| - /// passed in. This means the closure is given an `ImplicitCtxt` with the same `'tcx` lifetime |
1351 |
| - /// as the `TyCtxt` passed in. |
1352 |
| - /// This will panic if you pass it a `TyCtxt` which is different from the current |
1353 |
| - /// `ImplicitCtxt`'s `tcx` field. |
1354 |
| - #[inline] |
1355 |
| - pub fn with_related_context<'tcx, F, R>(tcx: TyCtxt<'tcx>, f: F) -> R |
1356 |
| - where |
1357 |
| - F: FnOnce(&ImplicitCtxt<'_, 'tcx>) -> R, |
1358 |
| - { |
1359 |
| - with_context(|context| unsafe { |
1360 |
| - assert!(ptr_eq(context.tcx.gcx, tcx.gcx)); |
1361 |
| - let context: &ImplicitCtxt<'_, '_> = mem::transmute(context); |
1362 |
| - f(context) |
1363 |
| - }) |
1364 |
| - } |
1365 |
| - |
1366 |
| - /// Allows access to the `TyCtxt` in the current `ImplicitCtxt`. |
1367 |
| - /// Panics if there is no `ImplicitCtxt` available. |
1368 |
| - #[inline] |
1369 |
| - pub fn with<F, R>(f: F) -> R |
1370 |
| - where |
1371 |
| - F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> R, |
1372 |
| - { |
1373 |
| - with_context(|context| f(context.tcx)) |
1374 |
| - } |
1375 |
| - |
1376 |
| - /// Allows access to the `TyCtxt` in the current `ImplicitCtxt`. |
1377 |
| - /// The closure is passed None if there is no `ImplicitCtxt` available. |
1378 |
| - #[inline] |
1379 |
| - pub fn with_opt<F, R>(f: F) -> R |
1380 |
| - where |
1381 |
| - F: for<'tcx> FnOnce(Option<TyCtxt<'tcx>>) -> R, |
1382 |
| - { |
1383 |
| - with_context_opt(|opt_context| f(opt_context.map(|context| context.tcx))) |
1384 |
| - } |
1385 |
| -} |
1386 |
| - |
1387 | 1217 | macro_rules! sty_debug_print {
|
1388 | 1218 | ($fmt: expr, $ctxt: expr, $($variant: ident),*) => {{
|
1389 | 1219 | // Curious inner module to allow variant names to be used as
|
@@ -2416,12 +2246,6 @@ pub struct DeducedParamAttrs {
|
2416 | 2246 | pub read_only: bool,
|
2417 | 2247 | }
|
2418 | 2248 |
|
2419 |
| -// We are comparing types with different invariant lifetimes, so `ptr::eq` |
2420 |
| -// won't work for us. |
2421 |
| -fn ptr_eq<T, U>(t: *const T, u: *const U) -> bool { |
2422 |
| - t as *const () == u as *const () |
2423 |
| -} |
2424 |
| - |
2425 | 2249 | pub fn provide(providers: &mut ty::query::Providers) {
|
2426 | 2250 | providers.module_reexports =
|
2427 | 2251 | |tcx, id| tcx.resolutions(()).reexport_map.get(&id).map(|v| &v[..]);
|
|
0 commit comments