mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
additional TypingEnv
cleanups
This commit is contained in:
parent
d61effe58f
commit
002efeb72a
@ -22,7 +22,7 @@ use rustc_middle::mir::BinOp;
|
|||||||
use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem};
|
use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem};
|
||||||
use rustc_middle::query::Providers;
|
use rustc_middle::query::Providers;
|
||||||
use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutOf, TyAndLayout};
|
use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutOf, TyAndLayout};
|
||||||
use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypingMode};
|
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_session::config::{self, CrateType, EntryFnType, OptLevel, OutputType};
|
use rustc_session::config::{self, CrateType, EntryFnType, OptLevel, OutputType};
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
@ -119,7 +119,8 @@ pub fn validate_trivial_unsize<'tcx>(
|
|||||||
) -> bool {
|
) -> bool {
|
||||||
match (source_data.principal(), target_data.principal()) {
|
match (source_data.principal(), target_data.principal()) {
|
||||||
(Some(hr_source_principal), Some(hr_target_principal)) => {
|
(Some(hr_source_principal), Some(hr_target_principal)) => {
|
||||||
let infcx = tcx.infer_ctxt().build(TypingMode::PostAnalysis);
|
let (infcx, param_env) =
|
||||||
|
tcx.infer_ctxt().build_with_typing_env(ty::TypingEnv::fully_monomorphized());
|
||||||
let universe = infcx.universe();
|
let universe = infcx.universe();
|
||||||
let ocx = ObligationCtxt::new(&infcx);
|
let ocx = ObligationCtxt::new(&infcx);
|
||||||
infcx.enter_forall(hr_target_principal, |target_principal| {
|
infcx.enter_forall(hr_target_principal, |target_principal| {
|
||||||
@ -130,7 +131,7 @@ pub fn validate_trivial_unsize<'tcx>(
|
|||||||
);
|
);
|
||||||
let Ok(()) = ocx.eq_trace(
|
let Ok(()) = ocx.eq_trace(
|
||||||
&ObligationCause::dummy(),
|
&ObligationCause::dummy(),
|
||||||
ty::ParamEnv::reveal_all(),
|
param_env,
|
||||||
ToTrace::to_trace(
|
ToTrace::to_trace(
|
||||||
&ObligationCause::dummy(),
|
&ObligationCause::dummy(),
|
||||||
hr_target_principal,
|
hr_target_principal,
|
||||||
|
@ -1193,9 +1193,9 @@ fn compare_self_type<'tcx>(
|
|||||||
ty::AssocItemContainer::Trait => tcx.types.self_param,
|
ty::AssocItemContainer::Trait => tcx.types.self_param,
|
||||||
};
|
};
|
||||||
let self_arg_ty = tcx.fn_sig(method.def_id).instantiate_identity().input(0);
|
let self_arg_ty = tcx.fn_sig(method.def_id).instantiate_identity().input(0);
|
||||||
let param_env = ty::ParamEnv::reveal_all();
|
let (infcx, param_env) = tcx
|
||||||
|
.infer_ctxt()
|
||||||
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
|
.build_with_typing_env(ty::TypingEnv::non_body_analysis(tcx, method.def_id));
|
||||||
let self_arg_ty = tcx.liberate_late_bound_regions(method.def_id, self_arg_ty);
|
let self_arg_ty = tcx.liberate_late_bound_regions(method.def_id, self_arg_ty);
|
||||||
let can_eq_self = |ty| infcx.can_eq(param_env, untransformed_self_ty, ty);
|
let can_eq_self = |ty| infcx.can_eq(param_env, untransformed_self_ty, ty);
|
||||||
match ExplicitSelf::determine(self_arg_ty, can_eq_self) {
|
match ExplicitSelf::determine(self_arg_ty, can_eq_self) {
|
||||||
|
@ -459,10 +459,7 @@ impl<'tcx> Body<'tcx> {
|
|||||||
typing_mode: ty::TypingMode::non_body_analysis(),
|
typing_mode: ty::TypingMode::non_body_analysis(),
|
||||||
param_env: tcx.param_env(self.source.def_id()),
|
param_env: tcx.param_env(self.source.def_id()),
|
||||||
},
|
},
|
||||||
MirPhase::Runtime(_) => TypingEnv {
|
MirPhase::Runtime(_) => TypingEnv::post_analysis(tcx, self.source.def_id()),
|
||||||
typing_mode: ty::TypingMode::PostAnalysis,
|
|
||||||
param_env: tcx.param_env_reveal_all_normalized(self.source.def_id()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ use rustc_hir::LangItem;
|
|||||||
use rustc_middle::bug;
|
use rustc_middle::bug;
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::ty::layout::ValidityRequirement;
|
use rustc_middle::ty::layout::ValidityRequirement;
|
||||||
use rustc_middle::ty::{self, GenericArgsRef, ParamEnv, Ty, TyCtxt, layout};
|
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, layout};
|
||||||
use rustc_span::sym;
|
use rustc_span::sym;
|
||||||
use rustc_span::symbol::Symbol;
|
use rustc_span::symbol::Symbol;
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ impl<'tcx> crate::MirPass<'tcx> for InstSimplify {
|
|||||||
let ctx = InstSimplifyContext {
|
let ctx = InstSimplifyContext {
|
||||||
tcx,
|
tcx,
|
||||||
local_decls: &body.local_decls,
|
local_decls: &body.local_decls,
|
||||||
param_env: tcx.param_env_reveal_all_normalized(body.source.def_id()),
|
typing_env: body.typing_env(tcx),
|
||||||
};
|
};
|
||||||
let preserve_ub_checks =
|
let preserve_ub_checks =
|
||||||
attr::contains_name(tcx.hir().krate_attrs(), sym::rustc_preserve_ub_checks);
|
attr::contains_name(tcx.hir().krate_attrs(), sym::rustc_preserve_ub_checks);
|
||||||
@ -66,13 +66,7 @@ impl<'tcx> crate::MirPass<'tcx> for InstSimplify {
|
|||||||
struct InstSimplifyContext<'a, 'tcx> {
|
struct InstSimplifyContext<'a, 'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
local_decls: &'a LocalDecls<'tcx>,
|
local_decls: &'a LocalDecls<'tcx>,
|
||||||
param_env: ParamEnv<'tcx>,
|
typing_env: ty::TypingEnv<'tcx>,
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> InstSimplifyContext<'_, 'tcx> {
|
|
||||||
fn typing_env(&self) -> ty::TypingEnv<'tcx> {
|
|
||||||
ty::TypingEnv { typing_mode: ty::TypingMode::PostAnalysis, param_env: self.param_env }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> InstSimplifyContext<'_, 'tcx> {
|
impl<'tcx> InstSimplifyContext<'_, 'tcx> {
|
||||||
@ -354,7 +348,7 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let known_is_valid =
|
let known_is_valid =
|
||||||
intrinsic_assert_panics(self.tcx, self.typing_env(), args[0], intrinsic_name);
|
intrinsic_assert_panics(self.tcx, self.typing_env, args[0], intrinsic_name);
|
||||||
match known_is_valid {
|
match known_is_valid {
|
||||||
// We don't know the layout or it's not validity assertion at all, don't touch it
|
// We don't know the layout or it's not validity assertion at all, don't touch it
|
||||||
None => {}
|
None => {}
|
||||||
|
@ -233,11 +233,11 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
|
|||||||
let key = self.tcx.def_key(impl_def_id);
|
let key = self.tcx.def_key(impl_def_id);
|
||||||
let parent_def_id = DefId { index: key.parent.unwrap(), ..impl_def_id };
|
let parent_def_id = DefId { index: key.parent.unwrap(), ..impl_def_id };
|
||||||
|
|
||||||
let mut param_env = self.tcx.param_env_reveal_all_normalized(impl_def_id);
|
let mut typing_env = ty::TypingEnv::post_analysis(self.tcx, impl_def_id);
|
||||||
if !args.is_empty() {
|
if !args.is_empty() {
|
||||||
param_env = EarlyBinder::bind(param_env).instantiate(self.tcx, args);
|
typing_env.param_env =
|
||||||
|
EarlyBinder::bind(typing_env.param_env).instantiate(self.tcx, args);
|
||||||
}
|
}
|
||||||
let typing_env = ty::TypingEnv { typing_mode: ty::TypingMode::PostAnalysis, param_env };
|
|
||||||
|
|
||||||
match &mut impl_trait_ref {
|
match &mut impl_trait_ref {
|
||||||
Some(impl_trait_ref) => {
|
Some(impl_trait_ref) => {
|
||||||
|
@ -698,8 +698,8 @@ fn replace_param_and_infer_args_with_placeholder<'tcx>(
|
|||||||
/// used during analysis.
|
/// used during analysis.
|
||||||
pub fn impossible_predicates<'tcx>(tcx: TyCtxt<'tcx>, predicates: Vec<ty::Clause<'tcx>>) -> bool {
|
pub fn impossible_predicates<'tcx>(tcx: TyCtxt<'tcx>, predicates: Vec<ty::Clause<'tcx>>) -> bool {
|
||||||
debug!("impossible_predicates(predicates={:?})", predicates);
|
debug!("impossible_predicates(predicates={:?})", predicates);
|
||||||
let infcx = tcx.infer_ctxt().build(TypingMode::PostAnalysis);
|
let (infcx, param_env) =
|
||||||
let param_env = ty::ParamEnv::reveal_all();
|
tcx.infer_ctxt().build_with_typing_env(ty::TypingEnv::fully_monomorphized());
|
||||||
let ocx = ObligationCtxt::new(&infcx);
|
let ocx = ObligationCtxt::new(&infcx);
|
||||||
let predicates = ocx.normalize(&ObligationCause::dummy(), param_env, predicates);
|
let predicates = ocx.normalize(&ObligationCause::dummy(), param_env, predicates);
|
||||||
for predicate in predicates {
|
for predicate in predicates {
|
||||||
|
@ -9,8 +9,7 @@ use rustc_infer::traits::util::PredicateSet;
|
|||||||
use rustc_middle::bug;
|
use rustc_middle::bug;
|
||||||
use rustc_middle::query::Providers;
|
use rustc_middle::query::Providers;
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
self, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeVisitableExt, TypingMode, Upcast,
|
self, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeVisitableExt, Upcast, VtblEntry,
|
||||||
VtblEntry,
|
|
||||||
};
|
};
|
||||||
use rustc_span::{DUMMY_SP, Span, sym};
|
use rustc_span::{DUMMY_SP, Span, sym};
|
||||||
use smallvec::{SmallVec, smallvec};
|
use smallvec::{SmallVec, smallvec};
|
||||||
@ -442,8 +441,8 @@ fn trait_refs_are_compatible<'tcx>(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let infcx = tcx.infer_ctxt().build(TypingMode::PostAnalysis);
|
let (infcx, param_env) =
|
||||||
let param_env = ty::ParamEnv::reveal_all();
|
tcx.infer_ctxt().build_with_typing_env(ty::TypingEnv::fully_monomorphized());
|
||||||
let ocx = ObligationCtxt::new(&infcx);
|
let ocx = ObligationCtxt::new(&infcx);
|
||||||
let hr_source_principal =
|
let hr_source_principal =
|
||||||
ocx.normalize(&ObligationCause::dummy(), param_env, hr_vtable_principal);
|
ocx.normalize(&ObligationCause::dummy(), param_env, hr_vtable_principal);
|
||||||
|
Loading…
Reference in New Issue
Block a user