rm unnecessary OpaqueTypeDecl
wrapper
This commit is contained in:
parent
b4045a404e
commit
87f03a4238
7 changed files with 24 additions and 32 deletions
|
@ -155,12 +155,12 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
.opaque_type_storage
|
||||
.opaque_types
|
||||
.iter()
|
||||
.map(|(k, v)| (*k, v.hidden_type.ty))
|
||||
.map(|(k, v)| (*k, v.ty))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn take_opaque_types_for_query_response(&self) -> Vec<(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)> {
|
||||
self.take_opaque_types().into_iter().map(|(k, v)| (k, v.hidden_type.ty)).collect()
|
||||
self.take_opaque_types().into_iter().map(|(k, v)| (k, v.ty)).collect()
|
||||
}
|
||||
|
||||
/// Given the (canonicalized) result to a canonical query,
|
||||
|
|
|
@ -234,7 +234,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
|
|||
pub fn iter_opaque_types(
|
||||
&self,
|
||||
) -> impl Iterator<Item = (ty::OpaqueTypeKey<'tcx>, ty::OpaqueHiddenType<'tcx>)> + '_ {
|
||||
self.opaque_type_storage.opaque_types.iter().map(|(&k, v)| (k, v.hidden_type))
|
||||
self.opaque_type_storage.opaque_types.iter().map(|(&k, &v)| (k, v))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,20 +19,9 @@ use crate::traits::{self, Obligation, PredicateObligations};
|
|||
|
||||
mod table;
|
||||
|
||||
pub(crate) type OpaqueTypeMap<'tcx> = FxIndexMap<OpaqueTypeKey<'tcx>, OpaqueTypeDecl<'tcx>>;
|
||||
pub(crate) type OpaqueTypeMap<'tcx> = FxIndexMap<OpaqueTypeKey<'tcx>, OpaqueHiddenType<'tcx>>;
|
||||
pub(crate) use table::{OpaqueTypeStorage, OpaqueTypeTable};
|
||||
|
||||
/// Information about the opaque types whose values we
|
||||
/// are inferring in this function (these are the `impl Trait` that
|
||||
/// appear in the return type).
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct OpaqueTypeDecl<'tcx> {
|
||||
/// The hidden types that have been inferred for this opaque type.
|
||||
/// There can be multiple, but they are all `lub`ed together at the end
|
||||
/// to obtain the canonical hidden type.
|
||||
pub hidden_type: OpaqueHiddenType<'tcx>,
|
||||
}
|
||||
|
||||
impl<'tcx> InferCtxt<'tcx> {
|
||||
/// This is a backwards compatibility hack to prevent breaking changes from
|
||||
/// lazy TAIT around RPIT handling.
|
||||
|
|
|
@ -3,7 +3,7 @@ use rustc_middle::bug;
|
|||
use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, Ty};
|
||||
use tracing::instrument;
|
||||
|
||||
use super::{OpaqueTypeDecl, OpaqueTypeMap};
|
||||
use super::OpaqueTypeMap;
|
||||
use crate::infer::snapshot::undo_log::{InferCtxtUndoLogs, UndoLog};
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
|
@ -11,15 +11,19 @@ pub(crate) struct OpaqueTypeStorage<'tcx> {
|
|||
/// Opaque types found in explicit return types and their
|
||||
/// associated fresh inference variable. Writeback resolves these
|
||||
/// variables to get the concrete type, which can be used to
|
||||
/// 'de-opaque' OpaqueTypeDecl, after typeck is done with all functions.
|
||||
/// 'de-opaque' OpaqueHiddenType, after typeck is done with all functions.
|
||||
pub opaque_types: OpaqueTypeMap<'tcx>,
|
||||
}
|
||||
|
||||
impl<'tcx> OpaqueTypeStorage<'tcx> {
|
||||
#[instrument(level = "debug")]
|
||||
pub(crate) fn remove(&mut self, key: OpaqueTypeKey<'tcx>, idx: Option<OpaqueHiddenType<'tcx>>) {
|
||||
if let Some(idx) = idx {
|
||||
self.opaque_types.get_mut(&key).unwrap().hidden_type = idx;
|
||||
pub(crate) fn remove(
|
||||
&mut self,
|
||||
key: OpaqueTypeKey<'tcx>,
|
||||
prev: Option<OpaqueHiddenType<'tcx>>,
|
||||
) {
|
||||
if let Some(prev) = prev {
|
||||
*self.opaque_types.get_mut(&key).unwrap() = prev;
|
||||
} else {
|
||||
// FIXME(#120456) - is `swap_remove` correct?
|
||||
match self.opaque_types.swap_remove(&key) {
|
||||
|
@ -59,13 +63,12 @@ impl<'a, 'tcx> OpaqueTypeTable<'a, 'tcx> {
|
|||
key: OpaqueTypeKey<'tcx>,
|
||||
hidden_type: OpaqueHiddenType<'tcx>,
|
||||
) -> Option<Ty<'tcx>> {
|
||||
if let Some(decl) = self.storage.opaque_types.get_mut(&key) {
|
||||
let prev = std::mem::replace(&mut decl.hidden_type, hidden_type);
|
||||
if let Some(entry) = self.storage.opaque_types.get_mut(&key) {
|
||||
let prev = std::mem::replace(entry, hidden_type);
|
||||
self.undo_log.push(UndoLog::OpaqueTypes(key, Some(prev)));
|
||||
return Some(prev.ty);
|
||||
}
|
||||
let decl = OpaqueTypeDecl { hidden_type };
|
||||
self.storage.opaque_types.insert(key, decl);
|
||||
self.storage.opaque_types.insert(key, hidden_type);
|
||||
self.undo_log.push(UndoLog::OpaqueTypes(key, None));
|
||||
None
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue