diff options
| author | Jonas Schievink <jonasschievink@gmail.com> | 2020-11-15 13:39:59 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-15 13:39:59 +0100 |
| commit | ce775bc4f68149461aed1789987a0ab90caf8cd7 (patch) | |
| tree | 24b8544fae7aa2a736fdd5e25e301b53b953f0a2 /compiler/rustc_middle | |
| parent | b0178f4cc78baecdde4255122f146e6d011f600d (diff) | |
| parent | 41c44b498f021f8028151109abf2805fa4269866 (diff) | |
| download | rust-ce775bc4f68149461aed1789987a0ab90caf8cd7.tar.gz rust-ce775bc4f68149461aed1789987a0ab90caf8cd7.zip | |
Rollup merge of #79036 - cjgillot:steal, r=oli-obk
Move Steal to rustc_data_structures.
Diffstat (limited to 'compiler/rustc_middle')
| -rw-r--r-- | compiler/rustc_middle/src/arena.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ich/impls_ty.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/context.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/mod.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/query/mod.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/steal.rs | 44 |
6 files changed, 4 insertions, 58 deletions
diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs index f6570cc95d2..672073b1d34 100644 --- a/compiler/rustc_middle/src/arena.rs +++ b/compiler/rustc_middle/src/arena.rs @@ -14,10 +14,10 @@ macro_rules! arena_types { [] layouts: rustc_target::abi::Layout, // AdtDef are interned and compared by address [] adt_def: rustc_middle::ty::AdtDef, - [] steal_mir: rustc_middle::ty::steal::Steal<rustc_middle::mir::Body<$tcx>>, + [] steal_mir: rustc_data_structures::steal::Steal<rustc_middle::mir::Body<$tcx>>, [decode] mir: rustc_middle::mir::Body<$tcx>, [] steal_promoted: - rustc_middle::ty::steal::Steal< + rustc_data_structures::steal::Steal< rustc_index::vec::IndexVec< rustc_middle::mir::Promoted, rustc_middle::mir::Body<$tcx> diff --git a/compiler/rustc_middle/src/ich/impls_ty.rs b/compiler/rustc_middle/src/ich/impls_ty.rs index 8f15c99f951..69bb4e23c4c 100644 --- a/compiler/rustc_middle/src/ich/impls_ty.rs +++ b/compiler/rustc_middle/src/ich/impls_ty.rs @@ -184,15 +184,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for ty::FloatVid { } } -impl<'a, T> HashStable<StableHashingContext<'a>> for ty::steal::Steal<T> -where - T: HashStable<StableHashingContext<'a>>, -{ - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - self.borrow().hash_stable(hcx, hasher); - } -} - impl<'a> HashStable<StableHashingContext<'a>> for crate::middle::privacy::AccessLevels { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 3838e1b006f..b29e6d4a967 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -14,7 +14,6 @@ use crate::mir::interpret::{self, Allocation, ConstValue, Scalar}; use crate::mir::{Body, Field, Local, Place, PlaceElem, ProjectionKind, Promoted}; use crate::traits; use crate::ty::query::{self, TyCtxtAt}; -use crate::ty::steal::Steal; use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, SubstsRef, UserSubsts}; use crate::ty::TyKind::*; use crate::ty::{ @@ -33,6 +32,7 @@ use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap}; use rustc_data_structures::stable_hasher::{ hash_stable_hashmap, HashStable, StableHasher, StableVec, }; +use rustc_data_structures::steal::Steal; use rustc_data_structures::sync::{self, Lock, Lrc, WorkerLocal}; use rustc_data_structures::unhash::UnhashMap; use rustc_errors::ErrorReported; diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index db11746971d..5e8a4a56db3 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -106,7 +106,6 @@ pub mod outlives; pub mod print; pub mod query; pub mod relate; -pub mod steal; pub mod subst; pub mod trait_def; pub mod util; diff --git a/compiler/rustc_middle/src/ty/query/mod.rs b/compiler/rustc_middle/src/ty/query/mod.rs index 7ba4d5a14df..187f86a52f4 100644 --- a/compiler/rustc_middle/src/ty/query/mod.rs +++ b/compiler/rustc_middle/src/ty/query/mod.rs @@ -28,13 +28,13 @@ use crate::traits::query::{ }; use crate::traits::specialization_graph; use crate::traits::{self, ImplSource}; -use crate::ty::steal::Steal; use crate::ty::subst::{GenericArg, SubstsRef}; use crate::ty::util::AlwaysRequiresDrop; use crate::ty::{self, AdtSizedConstraint, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt}; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_data_structures::stable_hasher::StableVec; +use rustc_data_structures::steal::Steal; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::Lrc; use rustc_errors::ErrorReported; diff --git a/compiler/rustc_middle/src/ty/steal.rs b/compiler/rustc_middle/src/ty/steal.rs deleted file mode 100644 index 224e76845d7..00000000000 --- a/compiler/rustc_middle/src/ty/steal.rs +++ /dev/null @@ -1,44 +0,0 @@ -use rustc_data_structures::sync::{MappedReadGuard, ReadGuard, RwLock}; - -/// The `Steal` struct is intended to used as the value for a query. -/// Specifically, we sometimes have queries (*cough* MIR *cough*) -/// where we create a large, complex value that we want to iteratively -/// update (e.g., optimize). We could clone the value for each -/// optimization, but that'd be expensive. And yet we don't just want -/// to mutate it in place, because that would spoil the idea that -/// queries are these pure functions that produce an immutable value -/// (since if you did the query twice, you could observe the mutations). -/// So instead we have the query produce a `&'tcx Steal<mir::Body<'tcx>>` -/// (to be very specific). Now we can read from this -/// as much as we want (using `borrow()`), but you can also -/// `steal()`. Once you steal, any further attempt to read will panic. -/// Therefore, we know that -- assuming no ICE -- nobody is observing -/// the fact that the MIR was updated. -/// -/// Obviously, whenever you have a query that yields a `Steal` value, -/// you must treat it with caution, and make sure that you know that -/// -- once the value is stolen -- it will never be read from again. -// -// FIXME(#41710): what is the best way to model linear queries? -pub struct Steal<T> { - value: RwLock<Option<T>>, -} - -impl<T> Steal<T> { - pub fn new(value: T) -> Self { - Steal { value: RwLock::new(Some(value)) } - } - - pub fn borrow(&self) -> MappedReadGuard<'_, T> { - ReadGuard::map(self.value.borrow(), |opt| match *opt { - None => bug!("attempted to read from stolen value"), - Some(ref v) => v, - }) - } - - pub fn steal(&self) -> T { - let value_ref = &mut *self.value.try_write().expect("stealing value which is locked"); - let value = value_ref.take(); - value.expect("attempt to read from stolen value") - } -} |
