Thread a ParamEnv down to might_permit_raw_init
This commit is contained in:
parent
662199f125
commit
5bfad5cc85
8 changed files with 45 additions and 22 deletions
|
@ -6,7 +6,7 @@ use rustc_middle::mir::{
|
|||
BinOp, Body, Constant, ConstantKind, LocalDecls, Operand, Place, ProjectionElem, Rvalue,
|
||||
SourceInfo, Statement, StatementKind, Terminator, TerminatorKind, UnOp,
|
||||
};
|
||||
use rustc_middle::ty::{self, layout::TyAndLayout, ParamEnv, SubstsRef, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, layout::TyAndLayout, ParamEnv, ParamEnvAnd, SubstsRef, Ty, TyCtxt};
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
|
||||
pub struct InstCombine;
|
||||
|
@ -231,7 +231,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
|
|||
// Check this is a foldable intrinsic before we query the layout of our generic parameter
|
||||
let Some(assert_panics) = intrinsic_assert_panics(intrinsic_name) else { return; };
|
||||
let Ok(layout) = self.tcx.layout_of(self.param_env.and(ty)) else { return; };
|
||||
if assert_panics(self.tcx, layout) {
|
||||
if assert_panics(self.tcx, self.param_env.and(layout)) {
|
||||
// If we know the assert panics, indicate to later opts that the call diverges
|
||||
*target = None;
|
||||
} else {
|
||||
|
@ -243,18 +243,25 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
|
|||
|
||||
fn intrinsic_assert_panics<'tcx>(
|
||||
intrinsic_name: Symbol,
|
||||
) -> Option<fn(TyCtxt<'tcx>, TyAndLayout<'tcx>) -> bool> {
|
||||
fn inhabited_predicate<'tcx>(_tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>) -> bool {
|
||||
) -> Option<fn(TyCtxt<'tcx>, ParamEnvAnd<'tcx, TyAndLayout<'tcx>>) -> bool> {
|
||||
fn inhabited_predicate<'tcx>(
|
||||
_tcx: TyCtxt<'tcx>,
|
||||
param_env_and_layout: ParamEnvAnd<'tcx, TyAndLayout<'tcx>>,
|
||||
) -> bool {
|
||||
let (_param_env, layout) = param_env_and_layout.into_parts();
|
||||
layout.abi.is_uninhabited()
|
||||
}
|
||||
fn zero_valid_predicate<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>) -> bool {
|
||||
!tcx.permits_zero_init(layout)
|
||||
fn zero_valid_predicate<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
param_env_and_layout: ParamEnvAnd<'tcx, TyAndLayout<'tcx>>,
|
||||
) -> bool {
|
||||
!tcx.permits_zero_init(param_env_and_layout)
|
||||
}
|
||||
fn mem_uninitialized_valid_predicate<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
layout: TyAndLayout<'tcx>,
|
||||
param_env_and_layout: ParamEnvAnd<'tcx, TyAndLayout<'tcx>>,
|
||||
) -> bool {
|
||||
!tcx.permits_uninit_init(layout)
|
||||
!tcx.permits_uninit_init(param_env_and_layout)
|
||||
}
|
||||
|
||||
match intrinsic_name {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue