1
Fork 0

Make opaque type map key be of type OpaqueTypeKey

This commit is contained in:
Santiago Pastorino 2021-06-07 16:57:44 -03:00
parent 7294f49d52
commit 37ab718350
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF
5 changed files with 21 additions and 11 deletions

View file

@ -1282,7 +1282,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
.eq(output_ty, revealed_ty)?, .eq(output_ty, revealed_ty)?,
); );
for &(opaque_def_id, opaque_decl) in &opaque_type_map { for &(opaque_type_key, opaque_decl) in &opaque_type_map {
let opaque_def_id = opaque_type_key.def_id;
let resolved_ty = infcx.resolve_vars_if_possible(opaque_decl.concrete_ty); let resolved_ty = infcx.resolve_vars_if_possible(opaque_decl.concrete_ty);
let concrete_is_opaque = if let ty::Opaque(def_id, _) = resolved_ty.kind() { let concrete_is_opaque = if let ty::Opaque(def_id, _) = resolved_ty.kind() {
*def_id == opaque_def_id *def_id == opaque_def_id
@ -1377,7 +1378,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// prove that `T: Iterator` where `T` is the type we // prove that `T: Iterator` where `T` is the type we
// instantiated it with). // instantiated it with).
if let Some(opaque_type_map) = opaque_type_map { if let Some(opaque_type_map) = opaque_type_map {
for (opaque_def_id, opaque_decl) in opaque_type_map { for (opaque_type_key, opaque_decl) in opaque_type_map {
let opaque_def_id = opaque_type_key.def_id;
self.fully_perform_op( self.fully_perform_op(
locations, locations,
ConstraintCategory::OpaqueType, ConstraintCategory::OpaqueType,

View file

@ -17,7 +17,7 @@ use rustc_span::Span;
use std::ops::ControlFlow; use std::ops::ControlFlow;
pub type OpaqueTypeMap<'tcx> = VecMap<DefId, OpaqueTypeDecl<'tcx>>; pub type OpaqueTypeMap<'tcx> = VecMap<OpaqueTypeKey<'tcx>, OpaqueTypeDecl<'tcx>>;
/// Information about the opaque types whose values we /// Information about the opaque types whose values we
/// are inferring in this function (these are the `impl Trait` that /// are inferring in this function (these are the `impl Trait` that
@ -370,7 +370,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
) { ) {
debug!("constrain_opaque_types()"); debug!("constrain_opaque_types()");
for &(def_id, opaque_defn) in opaque_types { for &(opaque_type_key, opaque_defn) in opaque_types {
let OpaqueTypeKey { def_id, substs: _ } = opaque_type_key;
self.constrain_opaque_type( self.constrain_opaque_type(
def_id, def_id,
&opaque_defn, &opaque_defn,
@ -1041,7 +1042,12 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
// Use the same type variable if the exact same opaque type appears more // Use the same type variable if the exact same opaque type appears more
// than once in the return type (e.g., if it's passed to a type alias). // than once in the return type (e.g., if it's passed to a type alias).
if let Some(opaque_defn) = self.opaque_types.get(&def_id) { if let Some(opaque_defn) = self
.opaque_types
.iter()
.find(|(opaque_type_key, _)| opaque_type_key.def_id == def_id)
.map(|(_, opaque_defn)| opaque_defn)
{
debug!("instantiate_opaque_types: returning concrete ty {:?}", opaque_defn.concrete_ty); debug!("instantiate_opaque_types: returning concrete ty {:?}", opaque_defn.concrete_ty);
return opaque_defn.concrete_ty; return opaque_defn.concrete_ty;
} }
@ -1079,7 +1085,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
let definition_span = self.value_span; let definition_span = self.value_span;
self.opaque_types.insert( self.opaque_types.insert(
def_id, OpaqueTypeKey { def_id, substs },
OpaqueTypeDecl { OpaqueTypeDecl {
opaque_type: ty, opaque_type: ty,
substs, substs,

View file

@ -716,7 +716,8 @@ fn check_opaque_meets_bounds<'tcx>(
infcx.instantiate_opaque_types(def_id, hir_id, param_env, opaque_ty, span), infcx.instantiate_opaque_types(def_id, hir_id, param_env, opaque_ty, span),
); );
for (def_id, opaque_defn) in opaque_type_map { for (opaque_type_key, opaque_defn) in opaque_type_map {
let def_id = opaque_type_key.def_id;
match infcx match infcx
.at(&misc_cause, param_env) .at(&misc_cause, param_env)
.eq(opaque_defn.concrete_ty, tcx.type_of(def_id).subst(tcx, opaque_defn.substs)) .eq(opaque_defn.concrete_ty, tcx.type_of(def_id).subst(tcx, opaque_defn.substs))

View file

@ -4,12 +4,12 @@ use super::MaybeInProgressTables;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::vec_map::VecMap; use rustc_data_structures::vec_map::VecMap;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId}; use rustc_hir::def_id::{DefIdMap, LocalDefId};
use rustc_hir::HirIdMap; use rustc_hir::HirIdMap;
use rustc_infer::infer; use rustc_infer::infer;
use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt}; use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt};
use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, OpaqueTypeKey, Ty, TyCtxt};
use rustc_span::{self, Span}; use rustc_span::{self, Span};
use rustc_trait_selection::infer::InferCtxtExt as _; use rustc_trait_selection::infer::InferCtxtExt as _;
use rustc_trait_selection::opaque_types::OpaqueTypeDecl; use rustc_trait_selection::opaque_types::OpaqueTypeDecl;
@ -59,7 +59,7 @@ pub struct Inherited<'a, 'tcx> {
// 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' OpaqueTypeDecl, after typeck is done with all functions.
pub(super) opaque_types: RefCell<VecMap<DefId, OpaqueTypeDecl<'tcx>>>, pub(super) opaque_types: RefCell<VecMap<OpaqueTypeKey<'tcx>, OpaqueTypeDecl<'tcx>>>,
/// A map from inference variables created from opaque /// A map from inference variables created from opaque
/// type instantiations (`ty::Infer`) to the actual opaque /// type instantiations (`ty::Infer`) to the actual opaque

View file

@ -475,7 +475,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
} }
fn visit_opaque_types(&mut self, span: Span) { fn visit_opaque_types(&mut self, span: Span) {
for &(def_id, opaque_defn) in self.fcx.opaque_types.borrow().iter() { for &(opaque_type_key, opaque_defn) in self.fcx.opaque_types.borrow().iter() {
let OpaqueTypeKey { def_id, substs: _ } = opaque_type_key;
let hir_id = self.tcx().hir().local_def_id_to_hir_id(def_id.expect_local()); let hir_id = self.tcx().hir().local_def_id_to_hir_id(def_id.expect_local());
let instantiated_ty = self.resolve(opaque_defn.concrete_ty, &hir_id); let instantiated_ty = self.resolve(opaque_defn.concrete_ty, &hir_id);