Make OpaqueTypeKey the key of opaque types map
This commit is contained in:
parent
3405725e00
commit
7f8cad2019
10 changed files with 134 additions and 98 deletions
|
@ -2,7 +2,6 @@
|
|||
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::graph::dominators::Dominators;
|
||||
use rustc_data_structures::vec_map::VecMap;
|
||||
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorReported};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
|
@ -26,7 +25,7 @@ use either::Either;
|
|||
use smallvec::SmallVec;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::BTreeMap;
|
||||
use std::iter::{self, FromIterator};
|
||||
use std::iter;
|
||||
use std::mem;
|
||||
use std::rc::Rc;
|
||||
|
||||
|
@ -442,7 +441,7 @@ fn do_mir_borrowck<'a, 'tcx>(
|
|||
}
|
||||
|
||||
let result = BorrowCheckResult {
|
||||
concrete_opaque_types: VecMap::from_iter(opaque_type_values.into_iter()),
|
||||
concrete_opaque_types: opaque_type_values,
|
||||
closure_requirements: opt_closure_req,
|
||||
used_mut_upvars: mbcx.used_mut_upvars,
|
||||
};
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
//! The entry point of the NLL borrow checker.
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::vec_map::VecMap;
|
||||
use rustc_errors::Diagnostic;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_infer::infer::InferCtxt;
|
||||
use rustc_middle::mir::{
|
||||
BasicBlock, Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location,
|
||||
Promoted,
|
||||
};
|
||||
use rustc_middle::ty::{self, RegionKind, RegionVid};
|
||||
use rustc_middle::ty::{self, OpaqueTypeKey, RegionKind, RegionVid};
|
||||
use rustc_span::symbol::sym;
|
||||
use std::env;
|
||||
use std::fmt::Debug;
|
||||
|
@ -47,7 +46,7 @@ crate type PoloniusOutput = Output<RustcFacts>;
|
|||
/// closure requirements to propagate, and any generated errors.
|
||||
crate struct NllOutput<'tcx> {
|
||||
pub regioncx: RegionInferenceContext<'tcx>,
|
||||
pub opaque_type_values: FxHashMap<DefId, ty::ResolvedOpaqueTy<'tcx>>,
|
||||
pub opaque_type_values: VecMap<OpaqueTypeKey<'tcx>, ty::ResolvedOpaqueTy<'tcx>>,
|
||||
pub polonius_output: Option<Rc<PoloniusOutput>>,
|
||||
pub opt_closure_req: Option<ClosureRegionRequirements<'tcx>>,
|
||||
pub nll_errors: RegionErrors<'tcx>,
|
||||
|
@ -367,7 +366,7 @@ pub(super) fn dump_annotation<'a, 'tcx>(
|
|||
body: &Body<'tcx>,
|
||||
regioncx: &RegionInferenceContext<'tcx>,
|
||||
closure_region_requirements: &Option<ClosureRegionRequirements<'_>>,
|
||||
opaque_type_values: &FxHashMap<DefId, ty::ResolvedOpaqueTy<'tcx>>,
|
||||
opaque_type_values: &VecMap<OpaqueTypeKey<'tcx>, ty::ResolvedOpaqueTy<'tcx>>,
|
||||
errors_buffer: &mut Vec<Diagnostic>,
|
||||
) {
|
||||
let tcx = infcx.tcx;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_data_structures::vec_map::VecMap;
|
||||
use rustc_infer::infer::InferCtxt;
|
||||
use rustc_middle::ty::{self, TyCtxt, TypeFoldable};
|
||||
use rustc_middle::ty::{self, OpaqueTypeKey, TyCtxt, TypeFoldable};
|
||||
use rustc_span::Span;
|
||||
use rustc_trait_selection::opaque_types::InferCtxtExt;
|
||||
|
||||
|
@ -51,12 +50,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
pub(in crate::borrow_check) fn infer_opaque_types(
|
||||
&self,
|
||||
infcx: &InferCtxt<'_, 'tcx>,
|
||||
opaque_ty_decls: FxHashMap<DefId, ty::ResolvedOpaqueTy<'tcx>>,
|
||||
opaque_ty_decls: VecMap<OpaqueTypeKey<'tcx>, ty::ResolvedOpaqueTy<'tcx>>,
|
||||
span: Span,
|
||||
) -> FxHashMap<DefId, ty::ResolvedOpaqueTy<'tcx>> {
|
||||
) -> VecMap<OpaqueTypeKey<'tcx>, ty::ResolvedOpaqueTy<'tcx>> {
|
||||
opaque_ty_decls
|
||||
.into_iter()
|
||||
.map(|(opaque_def_id, ty::ResolvedOpaqueTy { concrete_type, substs })| {
|
||||
.map(|(opaque_type_key, ty::ResolvedOpaqueTy { concrete_type, substs })| {
|
||||
debug!(?concrete_type, ?substs);
|
||||
|
||||
let mut subst_regions = vec![self.universal_regions.fr_static];
|
||||
|
@ -110,14 +109,15 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
|
||||
debug!(?universal_concrete_type, ?universal_substs);
|
||||
|
||||
let opaque_type_key =
|
||||
OpaqueTypeKey { def_id: opaque_type_key.def_id, substs: universal_substs };
|
||||
let remapped_type = infcx.infer_opaque_definition_from_instantiation(
|
||||
opaque_def_id,
|
||||
universal_substs,
|
||||
opaque_type_key,
|
||||
universal_concrete_type,
|
||||
span,
|
||||
);
|
||||
(
|
||||
opaque_def_id,
|
||||
opaque_type_key,
|
||||
ty::ResolvedOpaqueTy { concrete_type: remapped_type, substs: universal_substs },
|
||||
)
|
||||
})
|
||||
|
|
|
@ -7,9 +7,10 @@ use either::Either;
|
|||
|
||||
use rustc_data_structures::frozen::Frozen;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::vec_map::VecMap;
|
||||
use rustc_errors::struct_span_err;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use rustc_infer::infer::canonical::QueryRegionConstraints;
|
||||
|
@ -27,8 +28,8 @@ use rustc_middle::ty::cast::CastTy;
|
|||
use rustc_middle::ty::fold::TypeFoldable;
|
||||
use rustc_middle::ty::subst::{GenericArgKind, Subst, SubstsRef, UserSubsts};
|
||||
use rustc_middle::ty::{
|
||||
self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, RegionVid, ToPredicate, Ty,
|
||||
TyCtxt, UserType, UserTypeAnnotationIndex, WithConstness,
|
||||
self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, OpaqueTypeKey, RegionVid,
|
||||
ToPredicate, Ty, TyCtxt, UserType, UserTypeAnnotationIndex, WithConstness,
|
||||
};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_target::abi::VariantIdx;
|
||||
|
@ -818,7 +819,7 @@ struct TypeChecker<'a, 'tcx> {
|
|||
reported_errors: FxHashSet<(Ty<'tcx>, Span)>,
|
||||
borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>,
|
||||
universal_region_relations: &'a UniversalRegionRelations<'tcx>,
|
||||
opaque_type_values: FxHashMap<DefId, ty::ResolvedOpaqueTy<'tcx>>,
|
||||
opaque_type_values: VecMap<OpaqueTypeKey<'tcx>, ty::ResolvedOpaqueTy<'tcx>>,
|
||||
}
|
||||
|
||||
struct BorrowCheckContext<'a, 'tcx> {
|
||||
|
@ -833,7 +834,7 @@ struct BorrowCheckContext<'a, 'tcx> {
|
|||
crate struct MirTypeckResults<'tcx> {
|
||||
crate constraints: MirTypeckRegionConstraints<'tcx>,
|
||||
pub(in crate::borrow_check) universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
|
||||
crate opaque_type_values: FxHashMap<DefId, ty::ResolvedOpaqueTy<'tcx>>,
|
||||
crate opaque_type_values: VecMap<OpaqueTypeKey<'tcx>, ty::ResolvedOpaqueTy<'tcx>>,
|
||||
}
|
||||
|
||||
/// A collection of region constraints that must be satisfied for the
|
||||
|
@ -978,7 +979,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
borrowck_context,
|
||||
reported_errors: Default::default(),
|
||||
universal_region_relations,
|
||||
opaque_type_values: FxHashMap::default(),
|
||||
opaque_type_values: VecMap::default(),
|
||||
};
|
||||
checker.check_user_type_annotations();
|
||||
checker
|
||||
|
@ -1240,7 +1241,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
let param_env = self.param_env;
|
||||
let body = self.body;
|
||||
let concrete_opaque_types = &tcx.typeck(anon_owner_def_id).concrete_opaque_types;
|
||||
let mut opaque_type_values = Vec::new();
|
||||
let mut opaque_type_values = VecMap::new();
|
||||
|
||||
debug!("eq_opaque_type_and_type: mir_def_id={:?}", body.source.def_id());
|
||||
let opaque_type_map = self.fully_perform_op(
|
||||
|
@ -1288,7 +1289,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
} else {
|
||||
false
|
||||
};
|
||||
let opaque_defn_ty = match concrete_opaque_types.get(&opaque_def_id) {
|
||||
|
||||
let opaque_type_key =
|
||||
OpaqueTypeKey { def_id: opaque_def_id, substs: opaque_decl.substs };
|
||||
let opaque_defn_ty = match concrete_opaque_types
|
||||
.iter()
|
||||
.find(|(opaque_type_key, _)| opaque_type_key.def_id == opaque_def_id)
|
||||
.map(|(_, resolved_opaque_ty)| resolved_opaque_ty)
|
||||
{
|
||||
None => {
|
||||
if !concrete_is_opaque {
|
||||
tcx.sess.delay_span_bug(
|
||||
|
@ -1322,13 +1330,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
.at(&ObligationCause::dummy(), param_env)
|
||||
.eq(opaque_decl.concrete_ty, renumbered_opaque_defn_ty)?,
|
||||
);
|
||||
opaque_type_values.push((
|
||||
opaque_def_id,
|
||||
opaque_type_values.insert(
|
||||
opaque_type_key,
|
||||
ty::ResolvedOpaqueTy {
|
||||
concrete_type: renumbered_opaque_defn_ty,
|
||||
substs: opaque_decl.substs,
|
||||
},
|
||||
));
|
||||
);
|
||||
} else {
|
||||
// We're using an opaque `impl Trait` type without
|
||||
// 'revealing' it. For example, code like this:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue