Remove TypeckResults from InferCtxt

This commit is contained in:
Cameron Steffen 2022-09-09 13:01:06 -05:00
parent 4a68373217
commit 349415d1c6
67 changed files with 240 additions and 280 deletions

View file

@ -712,8 +712,8 @@ fn check_region_bounds_on_impl_item<'tcx>(
}
#[instrument(level = "debug", skip(infcx))]
fn extract_spans_for_error_reporting<'a, 'tcx>(
infcx: &infer::InferCtxt<'a, 'tcx>,
fn extract_spans_for_error_reporting<'tcx>(
infcx: &infer::InferCtxt<'tcx>,
terr: TypeError<'_>,
cause: &ObligationCause<'tcx>,
impl_m: &ty::AssocItem,

View file

@ -6,7 +6,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId;
use rustc_hir::HirIdMap;
use rustc_infer::infer;
use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt};
use rustc_infer::infer::{DefiningAnchor, InferCtxt, InferOk, TyCtxtInferExt};
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::visit::TypeVisitable;
use rustc_middle::ty::{self, Ty, TyCtxt};
@ -30,7 +30,7 @@ use std::ops::Deref;
/// `bar()` will each have their own `FnCtxt`, but they will
/// share the inherited fields.
pub struct Inherited<'a, 'tcx> {
pub(super) infcx: InferCtxt<'a, 'tcx>,
pub(super) infcx: InferCtxt<'tcx>,
pub(super) typeck_results: &'a RefCell<ty::TypeckResults<'tcx>>,
@ -71,7 +71,7 @@ pub struct Inherited<'a, 'tcx> {
}
impl<'a, 'tcx> Deref for Inherited<'a, 'tcx> {
type Target = InferCtxt<'a, 'tcx>;
type Target = InferCtxt<'tcx>;
fn deref(&self) -> &Self::Target {
&self.infcx
}
@ -83,6 +83,7 @@ impl<'a, 'tcx> Deref for Inherited<'a, 'tcx> {
pub struct InheritedBuilder<'tcx> {
infcx: infer::InferCtxtBuilder<'tcx>,
def_id: LocalDefId,
typeck_results: RefCell<ty::TypeckResults<'tcx>>,
}
impl<'tcx> Inherited<'_, 'tcx> {
@ -93,7 +94,7 @@ impl<'tcx> Inherited<'_, 'tcx> {
infcx: tcx
.infer_ctxt()
.ignoring_regions()
.with_fresh_in_progress_typeck_results(hir_owner)
.with_opaque_type_inference(DefiningAnchor::Bind(hir_owner.def_id))
.with_normalize_fn_sig_for_diagnostic(Lrc::new(move |infcx, fn_sig| {
if fn_sig.has_escaping_bound_vars() {
return fn_sig;
@ -117,6 +118,7 @@ impl<'tcx> Inherited<'_, 'tcx> {
})
})),
def_id,
typeck_results: RefCell::new(ty::TypeckResults::new(hir_owner)),
}
}
}
@ -127,16 +129,18 @@ impl<'tcx> InheritedBuilder<'tcx> {
F: for<'a> FnOnce(Inherited<'a, 'tcx>) -> R,
{
let def_id = self.def_id;
self.infcx.enter(|infcx| f(Inherited::new(infcx, def_id)))
self.infcx.enter(|infcx| f(Inherited::new(infcx, def_id, &self.typeck_results)))
}
}
impl<'a, 'tcx> Inherited<'a, 'tcx> {
fn new(infcx: InferCtxt<'a, 'tcx>, def_id: LocalDefId) -> Self {
fn new(
infcx: InferCtxt<'tcx>,
def_id: LocalDefId,
typeck_results: &'a RefCell<ty::TypeckResults<'tcx>>,
) -> Self {
let tcx = infcx.tcx;
let body_id = tcx.hir().maybe_body_owned_by(def_id);
let typeck_results =
infcx.in_progress_typeck_results.expect("building `FnCtxt` without typeck results");
Inherited {
typeck_results,

View file

@ -699,7 +699,7 @@ fn resolve_regions_with_wf_tys<'tcx>(
id: hir::HirId,
param_env: ty::ParamEnv<'tcx>,
wf_tys: &FxHashSet<Ty<'tcx>>,
add_constraints: impl for<'a> FnOnce(&'a InferCtxt<'a, 'tcx>, &'a RegionBoundPairs<'tcx>),
add_constraints: impl for<'a> FnOnce(&'a InferCtxt<'tcx>, &'a RegionBoundPairs<'tcx>),
) -> bool {
// Unfortunately, we have to use a new `InferCtxt` each call, because
// region constraints get added and solved there and we need to test each

View file

@ -700,7 +700,7 @@ impl Locatable for hir::HirId {
/// unresolved types and so forth.
struct Resolver<'cx, 'tcx> {
tcx: TyCtxt<'tcx>,
infcx: &'cx InferCtxt<'cx, 'tcx>,
infcx: &'cx InferCtxt<'tcx>,
span: &'cx dyn Locatable,
body: &'tcx hir::Body<'tcx>,

View file

@ -134,7 +134,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
/// - `typeck_results` --- typeck results for the code being analyzed
pub fn new(
delegate: &'a mut (dyn Delegate<'tcx> + 'a),
infcx: &'a InferCtxt<'a, 'tcx>,
infcx: &'a InferCtxt<'tcx>,
body_owner: LocalDefId,
param_env: ty::ParamEnv<'tcx>,
typeck_results: &'a ty::TypeckResults<'tcx>,

View file

@ -92,7 +92,7 @@ impl HirNode for hir::Pat<'_> {
#[derive(Clone)]
pub(crate) struct MemCategorizationContext<'a, 'tcx> {
pub(crate) typeck_results: &'a ty::TypeckResults<'tcx>,
infcx: &'a InferCtxt<'a, 'tcx>,
infcx: &'a InferCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
body_owner: LocalDefId,
upvars: Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>>,
@ -103,7 +103,7 @@ pub(crate) type McResult<T> = Result<T, ()>;
impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
/// Creates a `MemCategorizationContext`.
pub(crate) fn new(
infcx: &'a InferCtxt<'a, 'tcx>,
infcx: &'a InferCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
body_owner: LocalDefId,
typeck_results: &'a ty::TypeckResults<'tcx>,