rm unnecessary OpaqueTypeDecl
wrapper
This commit is contained in:
parent
b4045a404e
commit
87f03a4238
7 changed files with 24 additions and 32 deletions
|
@ -25,8 +25,8 @@ pub(super) fn take_opaques_and_register_member_constraints<'tcx>(
|
||||||
let opaque_types = infcx
|
let opaque_types = infcx
|
||||||
.take_opaque_types()
|
.take_opaque_types()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(opaque_type_key, decl)| {
|
.map(|(opaque_type_key, hidden_type)| {
|
||||||
let hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
|
let hidden_type = infcx.resolve_vars_if_possible(hidden_type);
|
||||||
register_member_constraints(
|
register_member_constraints(
|
||||||
typeck,
|
typeck,
|
||||||
&mut member_constraints,
|
&mut member_constraints,
|
||||||
|
|
|
@ -436,9 +436,9 @@ fn check_opaque_meets_bounds<'tcx>(
|
||||||
} else {
|
} else {
|
||||||
// Check that any hidden types found during wf checking match the hidden types that `type_of` sees.
|
// Check that any hidden types found during wf checking match the hidden types that `type_of` sees.
|
||||||
for (mut key, mut ty) in infcx.take_opaque_types() {
|
for (mut key, mut ty) in infcx.take_opaque_types() {
|
||||||
ty.hidden_type.ty = infcx.resolve_vars_if_possible(ty.hidden_type.ty);
|
ty.ty = infcx.resolve_vars_if_possible(ty.ty);
|
||||||
key = infcx.resolve_vars_if_possible(key);
|
key = infcx.resolve_vars_if_possible(key);
|
||||||
sanity_check_found_hidden_type(tcx, key, ty.hidden_type)?;
|
sanity_check_found_hidden_type(tcx, key, ty)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1873,7 +1873,7 @@ pub(super) fn check_coroutine_obligations(
|
||||||
// Check that any hidden types found when checking these stalled coroutine obligations
|
// Check that any hidden types found when checking these stalled coroutine obligations
|
||||||
// are valid.
|
// are valid.
|
||||||
for (key, ty) in infcx.take_opaque_types() {
|
for (key, ty) in infcx.take_opaque_types() {
|
||||||
let hidden_type = infcx.resolve_vars_if_possible(ty.hidden_type);
|
let hidden_type = infcx.resolve_vars_if_possible(ty);
|
||||||
let key = infcx.resolve_vars_if_possible(key);
|
let key = infcx.resolve_vars_if_possible(key);
|
||||||
sanity_check_found_hidden_type(tcx, key, hidden_type)?;
|
sanity_check_found_hidden_type(tcx, key, hidden_type)?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -562,9 +562,9 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
||||||
// types or by using this function at the end of writeback and running it as a
|
// types or by using this function at the end of writeback and running it as a
|
||||||
// fixpoint.
|
// fixpoint.
|
||||||
let opaque_types = self.fcx.infcx.clone_opaque_types();
|
let opaque_types = self.fcx.infcx.clone_opaque_types();
|
||||||
for (opaque_type_key, decl) in opaque_types {
|
for (opaque_type_key, hidden_type) in opaque_types {
|
||||||
let hidden_type = self.resolve(decl.hidden_type, &decl.hidden_type.span);
|
let hidden_type = self.resolve(hidden_type, &hidden_type.span);
|
||||||
let opaque_type_key = self.resolve(opaque_type_key, &decl.hidden_type.span);
|
let opaque_type_key = self.resolve(opaque_type_key, &hidden_type.span);
|
||||||
|
|
||||||
if !self.fcx.next_trait_solver() {
|
if !self.fcx.next_trait_solver() {
|
||||||
if let ty::Alias(ty::Opaque, alias_ty) = hidden_type.ty.kind()
|
if let ty::Alias(ty::Opaque, alias_ty) = hidden_type.ty.kind()
|
||||||
|
|
|
@ -155,12 +155,12 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
.opaque_type_storage
|
.opaque_type_storage
|
||||||
.opaque_types
|
.opaque_types
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(k, v)| (*k, v.hidden_type.ty))
|
.map(|(k, v)| (*k, v.ty))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn take_opaque_types_for_query_response(&self) -> Vec<(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)> {
|
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,
|
/// Given the (canonicalized) result to a canonical query,
|
||||||
|
|
|
@ -234,7 +234,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
|
||||||
pub fn iter_opaque_types(
|
pub fn iter_opaque_types(
|
||||||
&self,
|
&self,
|
||||||
) -> impl Iterator<Item = (ty::OpaqueTypeKey<'tcx>, ty::OpaqueHiddenType<'tcx>)> + '_ {
|
) -> 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;
|
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};
|
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> {
|
impl<'tcx> InferCtxt<'tcx> {
|
||||||
/// This is a backwards compatibility hack to prevent breaking changes from
|
/// This is a backwards compatibility hack to prevent breaking changes from
|
||||||
/// lazy TAIT around RPIT handling.
|
/// lazy TAIT around RPIT handling.
|
||||||
|
|
|
@ -3,7 +3,7 @@ use rustc_middle::bug;
|
||||||
use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, Ty};
|
use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, Ty};
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
use super::{OpaqueTypeDecl, OpaqueTypeMap};
|
use super::OpaqueTypeMap;
|
||||||
use crate::infer::snapshot::undo_log::{InferCtxtUndoLogs, UndoLog};
|
use crate::infer::snapshot::undo_log::{InferCtxtUndoLogs, UndoLog};
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone)]
|
#[derive(Default, Debug, Clone)]
|
||||||
|
@ -11,15 +11,19 @@ pub(crate) struct OpaqueTypeStorage<'tcx> {
|
||||||
/// Opaque types found in explicit return types and their
|
/// Opaque types found in explicit return types and their
|
||||||
/// associated fresh inference variable. Writeback resolves these
|
/// associated fresh inference variable. Writeback resolves these
|
||||||
/// variables to get the concrete type, which can be used to
|
/// 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>,
|
pub opaque_types: OpaqueTypeMap<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> OpaqueTypeStorage<'tcx> {
|
impl<'tcx> OpaqueTypeStorage<'tcx> {
|
||||||
#[instrument(level = "debug")]
|
#[instrument(level = "debug")]
|
||||||
pub(crate) fn remove(&mut self, key: OpaqueTypeKey<'tcx>, idx: Option<OpaqueHiddenType<'tcx>>) {
|
pub(crate) fn remove(
|
||||||
if let Some(idx) = idx {
|
&mut self,
|
||||||
self.opaque_types.get_mut(&key).unwrap().hidden_type = idx;
|
key: OpaqueTypeKey<'tcx>,
|
||||||
|
prev: Option<OpaqueHiddenType<'tcx>>,
|
||||||
|
) {
|
||||||
|
if let Some(prev) = prev {
|
||||||
|
*self.opaque_types.get_mut(&key).unwrap() = prev;
|
||||||
} else {
|
} else {
|
||||||
// FIXME(#120456) - is `swap_remove` correct?
|
// FIXME(#120456) - is `swap_remove` correct?
|
||||||
match self.opaque_types.swap_remove(&key) {
|
match self.opaque_types.swap_remove(&key) {
|
||||||
|
@ -59,13 +63,12 @@ impl<'a, 'tcx> OpaqueTypeTable<'a, 'tcx> {
|
||||||
key: OpaqueTypeKey<'tcx>,
|
key: OpaqueTypeKey<'tcx>,
|
||||||
hidden_type: OpaqueHiddenType<'tcx>,
|
hidden_type: OpaqueHiddenType<'tcx>,
|
||||||
) -> Option<Ty<'tcx>> {
|
) -> Option<Ty<'tcx>> {
|
||||||
if let Some(decl) = self.storage.opaque_types.get_mut(&key) {
|
if let Some(entry) = self.storage.opaque_types.get_mut(&key) {
|
||||||
let prev = std::mem::replace(&mut decl.hidden_type, hidden_type);
|
let prev = std::mem::replace(entry, hidden_type);
|
||||||
self.undo_log.push(UndoLog::OpaqueTypes(key, Some(prev)));
|
self.undo_log.push(UndoLog::OpaqueTypes(key, Some(prev)));
|
||||||
return Some(prev.ty);
|
return Some(prev.ty);
|
||||||
}
|
}
|
||||||
let decl = OpaqueTypeDecl { hidden_type };
|
self.storage.opaque_types.insert(key, hidden_type);
|
||||||
self.storage.opaque_types.insert(key, decl);
|
|
||||||
self.undo_log.push(UndoLog::OpaqueTypes(key, None));
|
self.undo_log.push(UndoLog::OpaqueTypes(key, None));
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue