From 18fae7b2e5744f9a177482e268967a9c7a171425 Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 1 Apr 2022 12:08:57 +0200 Subject: [PATCH 1/3] update comments --- compiler/rustc_infer/src/infer/canonical/mod.rs | 1 - compiler/rustc_infer/src/infer/mod.rs | 6 +++--- compiler/rustc_typeck/src/check/inherited.rs | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_infer/src/infer/canonical/mod.rs b/compiler/rustc_infer/src/infer/canonical/mod.rs index 7985686798519..c7fa2527eb2f3 100644 --- a/compiler/rustc_infer/src/infer/canonical/mod.rs +++ b/compiler/rustc_infer/src/infer/canonical/mod.rs @@ -49,7 +49,6 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { /// At the end of processing, the substitution S (once /// canonicalized) then represents the values that you computed /// for each of the canonical inputs to your query. - pub fn instantiate_canonical_with_fresh_inference_vars( &self, span: Span, diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index bd59bf4dea883..8ad4805f94f39 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -558,9 +558,9 @@ impl<'tcx> fmt::Display for FixupError<'tcx> { } } -/// Helper type of a temporary returned by `tcx.infer_ctxt()`. -/// Necessary because we can't write the following bound: -/// `F: for<'b, 'tcx> where 'tcx FnOnce(InferCtxt<'b, 'tcx>)`. +/// A temporary returned by `tcx.infer_ctxt()`. This is necessary +/// for multiple `InferCtxt` to share the same `in_progress_typeck_results` +/// without using `Rc` or something similar. pub struct InferCtxtBuilder<'tcx> { tcx: TyCtxt<'tcx>, fresh_typeck_results: Option>>, diff --git a/compiler/rustc_typeck/src/check/inherited.rs b/compiler/rustc_typeck/src/check/inherited.rs index e7cfa3a7c1493..62ca728868b45 100644 --- a/compiler/rustc_typeck/src/check/inherited.rs +++ b/compiler/rustc_typeck/src/check/inherited.rs @@ -68,9 +68,9 @@ impl<'a, 'tcx> Deref for Inherited<'a, 'tcx> { } } -/// Helper type of a temporary returned by `Inherited::build(...)`. -/// Necessary because we can't write the following bound: -/// `F: for<'b, 'tcx> where 'tcx FnOnce(Inherited<'b, 'tcx>)`. +/// A temporary returned by `Inherited::build(...)`. This is necessary +/// for multiple `InferCtxt` to share the same `in_progress_typeck_results` +/// without using `Rc` or something similar. pub struct InheritedBuilder<'tcx> { infcx: infer::InferCtxtBuilder<'tcx>, def_id: LocalDefId, From c2b5a7ea522672a01b089c159f9b2c3e36d9f4dd Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 1 Apr 2022 12:41:35 +0200 Subject: [PATCH 2/3] remove `unify_key::replace_if_possible` --- compiler/rustc_infer/src/infer/combine.rs | 11 +++----- compiler/rustc_infer/src/infer/freshen.rs | 10 +++---- compiler/rustc_infer/src/infer/mod.rs | 2 -- compiler/rustc_middle/src/infer/unify_key.rs | 27 ++----------------- .../rustc_typeck/src/check/fn_ctxt/mod.rs | 2 +- .../rustc_typeck/src/check/method/probe.rs | 2 +- 6 files changed, 11 insertions(+), 43 deletions(-) diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index 41995ca509ef6..86229dbfad746 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -27,15 +27,12 @@ use super::glb::Glb; use super::lub::Lub; use super::sub::Sub; use super::type_variable::TypeVariableValue; -use super::unify_key::replace_if_possible; -use super::unify_key::{ConstVarValue, ConstVariableValue}; -use super::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; use super::{InferCtxt, MiscVariable, TypeTrace}; - use crate::traits::{Obligation, PredicateObligations}; - use rustc_data_structures::sso::SsoHashMap; use rustc_hir::def_id::DefId; +use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue}; +use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; use rustc_middle::traits::ObligationCause; use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation}; @@ -140,8 +137,8 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> { return Ok(a); } - let a = replace_if_possible(&mut self.inner.borrow_mut().const_unification_table(), a); - let b = replace_if_possible(&mut self.inner.borrow_mut().const_unification_table(), b); + let a = self.shallow_resolve(a); + let b = self.shallow_resolve(b); let a_is_expected = relation.a_is_expected(); diff --git a/compiler/rustc_infer/src/infer/freshen.rs b/compiler/rustc_infer/src/infer/freshen.rs index e9d3b6a8aa1a4..0a11a81c29425 100644 --- a/compiler/rustc_infer/src/infer/freshen.rs +++ b/compiler/rustc_infer/src/infer/freshen.rs @@ -30,17 +30,13 @@ //! solving a set of constraints. In contrast, the type inferencer assigns a value to each type //! variable only once, and it does so as soon as it can, so it is reasonable to ask what the type //! inferencer knows "so far". - +use super::InferCtxt; +use rustc_data_structures::fx::FxHashMap; +use rustc_middle::infer::unify_key::ToType; use rustc_middle::ty::fold::TypeFolder; use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable}; - -use rustc_data_structures::fx::FxHashMap; - use std::collections::hash_map::Entry; -use super::unify_key::ToType; -use super::InferCtxt; - pub struct TypeFreshener<'a, 'tcx> { infcx: &'a InferCtxt<'a, 'tcx>, ty_freshen_count: u32, diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 8ad4805f94f39..cefe7aae396b4 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -70,8 +70,6 @@ mod sub; pub mod type_variable; mod undo_log; -pub use rustc_middle::infer::unify_key; - #[must_use] #[derive(Debug)] pub struct InferOk<'tcx, T> { diff --git a/compiler/rustc_middle/src/infer/unify_key.rs b/compiler/rustc_middle/src/infer/unify_key.rs index dd303aaada900..7859922d50347 100644 --- a/compiler/rustc_middle/src/infer/unify_key.rs +++ b/compiler/rustc_middle/src/infer/unify_key.rs @@ -1,13 +1,8 @@ -use crate::ty::{self, InferConst, Ty, TyCtxt}; -use rustc_data_structures::snapshot_vec; -use rustc_data_structures::undo_log::UndoLogs; -use rustc_data_structures::unify::{ - self, EqUnifyValue, InPlace, NoError, UnificationTable, UnifyKey, UnifyValue, -}; +use crate::ty::{self, Ty, TyCtxt}; +use rustc_data_structures::unify::{EqUnifyValue, NoError, UnifyKey, UnifyValue}; use rustc_span::def_id::DefId; use rustc_span::symbol::Symbol; use rustc_span::Span; - use std::cmp; use std::marker::PhantomData; @@ -167,21 +162,3 @@ impl<'tcx> UnifyValue for ConstVarValue<'tcx> { } impl<'tcx> EqUnifyValue for ty::Const<'tcx> {} - -pub fn replace_if_possible<'tcx, V, L>( - table: &mut UnificationTable, V, L>>, - c: ty::Const<'tcx>, -) -> ty::Const<'tcx> -where - V: snapshot_vec::VecLike>>, - L: UndoLogs>>>, -{ - if let ty::ConstKind::Infer(InferConst::Var(vid)) = c.val() { - match table.probe_value(vid).val.known() { - Some(c) => c, - None => c, - } - } else { - c - } -} diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs index 6c55f8212940e..55a5eb966c222 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs @@ -14,7 +14,7 @@ use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_infer::infer; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; -use rustc_infer::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; +use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::{self, Const, Ty, TyCtxt}; diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index e3782fe5911df..6edcc12bcf5a6 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -15,8 +15,8 @@ use rustc_hir::def::Namespace; use rustc_infer::infer::canonical::OriginalQueryValues; use rustc_infer::infer::canonical::{Canonical, QueryResponse}; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; -use rustc_infer::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; use rustc_infer::infer::{self, InferOk, TyCtxtInferExt}; +use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; use rustc_middle::middle::stability; use rustc_middle::ty::fast_reject::{simplify_type, TreatParams}; use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef}; From 389c83b47407747ec96153e04c35717e3ce4d82a Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 1 Apr 2022 12:57:24 +0200 Subject: [PATCH 3/3] remove unused incorrect `EqUnifyValue` impl --- compiler/rustc_middle/src/infer/unify_key.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compiler/rustc_middle/src/infer/unify_key.rs b/compiler/rustc_middle/src/infer/unify_key.rs index 7859922d50347..f2627885d030d 100644 --- a/compiler/rustc_middle/src/infer/unify_key.rs +++ b/compiler/rustc_middle/src/infer/unify_key.rs @@ -1,5 +1,5 @@ use crate::ty::{self, Ty, TyCtxt}; -use rustc_data_structures::unify::{EqUnifyValue, NoError, UnifyKey, UnifyValue}; +use rustc_data_structures::unify::{NoError, UnifyKey, UnifyValue}; use rustc_span::def_id::DefId; use rustc_span::symbol::Symbol; use rustc_span::Span; @@ -160,5 +160,3 @@ impl<'tcx> UnifyValue for ConstVarValue<'tcx> { }) } } - -impl<'tcx> EqUnifyValue for ty::Const<'tcx> {}