1
Fork 0

Move opaque type cache into InferCtxt

This commit is contained in:
Oli Scherer 2021-07-26 16:57:18 +00:00
parent 1f94abcda6
commit d99805982b
7 changed files with 102 additions and 107 deletions

View file

@ -385,8 +385,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
value_span,
));
let mut opaque_types = self.opaque_types.borrow_mut();
let mut opaque_types_vars = self.opaque_types_vars.borrow_mut();
let mut infcx = self.infcx.inner.borrow_mut();
for (ty, decl) in opaque_type_map {
if let Some(feature) = feature {
@ -402,8 +401,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
}
let _ = opaque_types.insert(ty, decl);
let _ = opaque_types_vars.insert(decl.concrete_ty, decl.opaque_type);
let _ = infcx.opaque_types.insert(ty, decl);
let _ = infcx.opaque_types_vars.insert(decl.concrete_ty, decl.opaque_type);
}
value
@ -726,7 +725,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// We treat this as a non-defining use by making the inference
// variable fall back to the opaque type itself.
if let FallbackMode::All = mode {
if let Some(opaque_ty) = self.opaque_types_vars.borrow().get(ty) {
if let Some(opaque_ty) = self.infcx.inner.borrow().opaque_types_vars.get(ty) {
debug!(
"fallback_if_possible: falling back opaque type var {:?} to {:?}",
ty, opaque_ty

View file

@ -1,18 +1,15 @@
use super::callee::DeferredCallResolution;
use super::MaybeInProgressTables;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::vec_map::VecMap;
use rustc_hir as hir;
use rustc_hir::def_id::{DefIdMap, LocalDefId};
use rustc_hir::HirIdMap;
use rustc_infer::infer;
use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt};
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::{self, OpaqueTypeKey, Ty, TyCtxt};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::{self, Span};
use rustc_trait_selection::infer::InferCtxtExt as _;
use rustc_trait_selection::opaque_types::OpaqueTypeDecl;
use rustc_trait_selection::traits::{self, ObligationCause, TraitEngine, TraitEngineExt};
use std::cell::RefCell;
@ -55,19 +52,6 @@ pub struct Inherited<'a, 'tcx> {
pub(super) deferred_generator_interiors:
RefCell<Vec<(hir::BodyId, Ty<'tcx>, hir::GeneratorKind)>>,
// 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.
pub(super) opaque_types: RefCell<VecMap<OpaqueTypeKey<'tcx>, OpaqueTypeDecl<'tcx>>>,
/// A map from inference variables created from opaque
/// type instantiations (`ty::Infer`) to the actual opaque
/// type (`ty::Opaque`). Used during fallback to map unconstrained
/// opaque type inference variables to their corresponding
/// opaque type.
pub(super) opaque_types_vars: RefCell<FxHashMap<Ty<'tcx>, Ty<'tcx>>>,
pub(super) body_id: Option<hir::BodyId>,
}
@ -124,8 +108,6 @@ impl Inherited<'a, 'tcx> {
deferred_call_resolutions: RefCell::new(Default::default()),
deferred_cast_checks: RefCell::new(Vec::new()),
deferred_generator_interiors: RefCell::new(Vec::new()),
opaque_types: RefCell::new(Default::default()),
opaque_types_vars: RefCell::new(Default::default()),
body_id,
}
}

View file

@ -291,10 +291,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
self.visit_body(body);
self.visit_region_obligations(body_id.hir_id);
self.constrain_opaque_types(
&self.fcx.opaque_types.borrow(),
self.outlives_environment.free_region_map(),
);
self.constrain_opaque_types(self.outlives_environment.free_region_map());
}
fn visit_region_obligations(&mut self, hir_id: hir::HirId) {

View file

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