mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Revert "implement eager normalization in a fresh context during typeck"
This reverts commit 04f2c0191e.
This commit is contained in:
@@ -140,9 +140,8 @@ pub fn sup<T>(
|
||||
ty::Contravariant,
|
||||
actual,
|
||||
self.cause.span,
|
||||
&mut |alias| {
|
||||
self.infcx.try_eagerly_normalize_alias(self.param_env, self.cause.span, alias)
|
||||
},
|
||||
// TODO: should normalize
|
||||
&mut |_alias| self.infcx.next_ty_var(self.cause.span),
|
||||
)
|
||||
.map(|goals| self.goals_to_obligations(goals))
|
||||
} else {
|
||||
@@ -176,9 +175,8 @@ pub fn sub<T>(
|
||||
ty::Covariant,
|
||||
actual,
|
||||
self.cause.span,
|
||||
&mut |alias| {
|
||||
self.infcx.try_eagerly_normalize_alias(self.param_env, self.cause.span, alias)
|
||||
},
|
||||
// TODO: should normalize
|
||||
&mut |_alias| self.infcx.next_ty_var(self.cause.span),
|
||||
)
|
||||
.map(|goals| self.goals_to_obligations(goals))
|
||||
} else {
|
||||
@@ -231,9 +229,8 @@ pub fn eq_trace<T>(
|
||||
ty::Invariant,
|
||||
actual,
|
||||
self.cause.span,
|
||||
&mut |alias| {
|
||||
self.infcx.try_eagerly_normalize_alias(self.param_env, self.cause.span, alias)
|
||||
},
|
||||
// TODO: should normalize
|
||||
&mut |_alias| self.infcx.next_ty_var(self.cause.span),
|
||||
)
|
||||
.map(|goals| self.goals_to_obligations(goals))
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::{fmt, mem};
|
||||
use std::fmt;
|
||||
|
||||
pub use at::DefineOpaqueTypes;
|
||||
use free_regions::RegionRelations;
|
||||
@@ -21,7 +21,6 @@
|
||||
use rustc_macros::extension;
|
||||
pub use rustc_macros::{TypeFoldable, TypeVisitable};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::hooks::TypeErasedInfcx;
|
||||
use rustc_middle::infer::canonical::{CanonicalQueryInput, CanonicalVarValues};
|
||||
use rustc_middle::mir::ConstraintCategory;
|
||||
use rustc_middle::traits::select;
|
||||
@@ -1529,16 +1528,6 @@ pub fn ty_or_const_infer_var_changed(&self, infer_var: TyOrConstInferVar) -> boo
|
||||
}
|
||||
}
|
||||
|
||||
pub fn try_eagerly_normalize_alias<'a>(
|
||||
&'a self,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
span: Span,
|
||||
alias: ty::AliasTy<'tcx>,
|
||||
) -> Ty<'tcx> {
|
||||
let erased = unsafe { mem::transmute::<_, TypeErasedInfcx<'a, 'tcx>>(self) };
|
||||
self.tcx.try_eagerly_normalize_alias(erased, param_env, span, alias)
|
||||
}
|
||||
|
||||
/// Attach a callback to be invoked on each root obligation evaluated in the new trait solver.
|
||||
pub fn attach_obligation_inspector(&self, inspector: ObligationInspector<'tcx>) {
|
||||
debug_assert!(
|
||||
|
||||
@@ -300,7 +300,8 @@ fn register_alias_relate_predicate(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) {
|
||||
))]);
|
||||
}
|
||||
|
||||
fn try_eagerly_normalize_alias(&mut self, alias: ty::AliasTy<'tcx>) -> Ty<'tcx> {
|
||||
self.infcx.try_eagerly_normalize_alias(self.param_env(), self.span(), alias)
|
||||
fn try_eagerly_normalize_alias(&mut self, _alias: ty::AliasTy<'tcx>) -> Ty<'tcx> {
|
||||
// TODO: this should actually normalize
|
||||
self.infcx.next_ty_var(self.span())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -904,7 +904,7 @@ pub fn write_interface<'tcx>(tcx: TyCtxt<'tcx>) {
|
||||
rustc_hir_typeck::provide(&mut providers.queries);
|
||||
ty::provide(&mut providers.queries);
|
||||
traits::provide(&mut providers.queries);
|
||||
solve::provide(providers);
|
||||
solve::provide(&mut providers.queries);
|
||||
rustc_passes::provide(&mut providers.queries);
|
||||
rustc_traits::provide(&mut providers.queries);
|
||||
rustc_ty_utils::provide(&mut providers.queries);
|
||||
|
||||
@@ -3,16 +3,14 @@
|
||||
//! similar to queries, but queries come with a lot of machinery for caching and incremental
|
||||
//! compilation, whereas hooks are just plain function pointers without any of the query magic.
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use rustc_hir::def_id::{DefId, DefPathHash};
|
||||
use rustc_session::StableCrateId;
|
||||
use rustc_span::def_id::{CrateNum, LocalDefId};
|
||||
use rustc_span::{ExpnHash, ExpnId, Span};
|
||||
use rustc_span::{ExpnHash, ExpnId};
|
||||
|
||||
use crate::mir;
|
||||
use crate::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex};
|
||||
use crate::ty::{Ty, TyCtxt};
|
||||
use crate::{mir, ty};
|
||||
|
||||
macro_rules! declare_hooks {
|
||||
($($(#[$attr:meta])*hook $name:ident($($arg:ident: $K:ty),*) -> $V:ty;)*) => {
|
||||
@@ -117,24 +115,6 @@ fn clone(&self) -> Self { *self }
|
||||
encoder: &mut CacheEncoder<'_, 'tcx>,
|
||||
query_result_index: &mut EncodedDepNodeIndex
|
||||
) -> ();
|
||||
|
||||
/// Tries to normalize an alias, ignoring any errors.
|
||||
///
|
||||
/// Generalization with the new trait solver calls into this,
|
||||
/// when generalizing outside of the trait solver in `hir_typeck`.
|
||||
hook try_eagerly_normalize_alias(
|
||||
type_erased_infcx: TypeErasedInfcx<'_, 'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
span: Span,
|
||||
alias: ty::AliasTy<'tcx>
|
||||
) -> Ty<'tcx>;
|
||||
}
|
||||
|
||||
// `repr(transparent)` so we can transmute a `&'a Infcx<'tcx>` to this struct.
|
||||
#[repr(transparent)]
|
||||
pub struct TypeErasedInfcx<'a, 'tcx> {
|
||||
_infcx: *const (),
|
||||
phantom: PhantomData<&'a mut &'tcx ()>,
|
||||
}
|
||||
|
||||
#[cold]
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
use std::mem;
|
||||
|
||||
use rustc_infer::infer::InferCtxt;
|
||||
use rustc_infer::traits::{Obligation, ObligationCause};
|
||||
use rustc_middle::hooks::TypeErasedInfcx;
|
||||
pub use rustc_next_trait_solver::solve::*;
|
||||
|
||||
mod delegate;
|
||||
@@ -18,13 +13,10 @@
|
||||
deeply_normalize, deeply_normalize_with_skipped_universes,
|
||||
deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals,
|
||||
};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_middle::util::Providers;
|
||||
use rustc_span::Span;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
pub use select::InferCtxtSelectExt;
|
||||
|
||||
use crate::traits::ObligationCtxt;
|
||||
|
||||
fn evaluate_root_goal_for_proof_tree_raw<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
canonical_input: CanonicalInput<TyCtxt<'tcx>>,
|
||||
@@ -35,46 +27,6 @@ fn evaluate_root_goal_for_proof_tree_raw<'tcx>(
|
||||
)
|
||||
}
|
||||
|
||||
fn try_eagerly_normalize_alias<'a, 'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
type_erased_infcx: TypeErasedInfcx<'a, 'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
span: Span,
|
||||
alias: ty::AliasTy<'tcx>,
|
||||
) -> Ty<'tcx> {
|
||||
let infcx = unsafe {
|
||||
mem::transmute::<TypeErasedInfcx<'a, 'tcx>, &'a InferCtxt<'tcx>>(type_erased_infcx)
|
||||
};
|
||||
|
||||
let ocx = ObligationCtxt::new(infcx);
|
||||
|
||||
let infer_term = infcx.next_ty_var(span);
|
||||
|
||||
// Dummy because we ignore the error anyway.
|
||||
// We do provide a span, because this span is used when registering opaque types.
|
||||
// For example, if we don't provide a span here, some diagnostics talking about TAIT will refer to a dummy span.
|
||||
let cause = ObligationCause::dummy_with_span(span);
|
||||
let obligation = Obligation::new(
|
||||
tcx,
|
||||
// we ignore the error anyway
|
||||
ObligationCause::dummy(),
|
||||
param_env,
|
||||
ty::PredicateKind::AliasRelate(
|
||||
alias.to_ty(tcx).into(),
|
||||
infer_term.into(),
|
||||
ty::AliasRelationDirection::Equate,
|
||||
),
|
||||
);
|
||||
|
||||
ocx.register_obligation(obligation);
|
||||
|
||||
// This only tries to eagerly resolve, if it errors we don't care.
|
||||
let _ = ocx.try_evaluate_obligations();
|
||||
|
||||
infcx.resolve_vars_if_possible(infer_term)
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
providers.hooks.try_eagerly_normalize_alias = try_eagerly_normalize_alias;
|
||||
providers.queries.evaluate_root_goal_for_proof_tree_raw = evaluate_root_goal_for_proof_tree_raw;
|
||||
*providers = Providers { evaluate_root_goal_for_proof_tree_raw, ..*providers };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user