Unify validity checks into a single query
Previously, there were two queries to check whether a type allows the 0x01 or zeroed bitpattern. I am planning on adding a further initness to check, truly uninit for MaybeUninit, which would make this three queries. This seems overkill for such a small feature, so this PR unifies them into one.
This commit is contained in:
parent
b869e84e58
commit
025d2a147f
11 changed files with 89 additions and 67 deletions
|
@ -11,7 +11,7 @@ use rustc_middle::mir::{
|
|||
BinOp, NonDivergingIntrinsic,
|
||||
};
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::layout::LayoutOf as _;
|
||||
use rustc_middle::ty::layout::{InitKind, LayoutOf as _};
|
||||
use rustc_middle::ty::subst::SubstsRef;
|
||||
use rustc_middle::ty::{Ty, TyCtxt};
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
|
@ -437,7 +437,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
if intrinsic_name == sym::assert_zero_valid {
|
||||
let should_panic = !self
|
||||
.tcx
|
||||
.permits_zero_init(self.param_env.and(ty))
|
||||
.check_validity_of_init((InitKind::Zero, self.param_env.and(ty)))
|
||||
.map_err(|_| err_inval!(TooGeneric))?;
|
||||
|
||||
if should_panic {
|
||||
|
@ -454,7 +454,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
if intrinsic_name == sym::assert_mem_uninitialized_valid {
|
||||
let should_panic = !self
|
||||
.tcx
|
||||
.permits_uninit_init(self.param_env.and(ty))
|
||||
.check_validity_of_init((
|
||||
InitKind::UninitMitigated0x01Fill,
|
||||
self.param_env.and(ty),
|
||||
))
|
||||
.map_err(|_| err_inval!(TooGeneric))?;
|
||||
|
||||
if should_panic {
|
||||
|
|
|
@ -38,7 +38,6 @@ use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
|
|||
use rustc_macros::fluent_messages;
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_target::abi::InitKind;
|
||||
|
||||
fluent_messages! { "../locales/en-US.ftl" }
|
||||
|
||||
|
@ -62,9 +61,7 @@ pub fn provide(providers: &mut Providers) {
|
|||
let (param_env, value) = param_env_and_value.into_parts();
|
||||
const_eval::deref_mir_constant(tcx, param_env, value)
|
||||
};
|
||||
providers.permits_uninit_init = |tcx, param_env_and_ty| {
|
||||
util::might_permit_raw_init(tcx, param_env_and_ty, InitKind::UninitMitigated0x01Fill)
|
||||
providers.check_validity_of_init = |tcx, (init_kind, param_env_and_ty)| {
|
||||
util::might_permit_raw_init(tcx, init_kind, param_env_and_ty)
|
||||
};
|
||||
providers.permits_zero_init =
|
||||
|tcx, param_env_and_ty| util::might_permit_raw_init(tcx, param_env_and_ty, InitKind::Zero);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use rustc_middle::ty::layout::{LayoutCx, LayoutError, LayoutOf, TyAndLayout};
|
||||
use rustc_middle::ty::layout::{InitKind, LayoutCx, LayoutError, LayoutOf, TyAndLayout};
|
||||
use rustc_middle::ty::{ParamEnv, ParamEnvAnd, Ty, TyCtxt};
|
||||
use rustc_session::Limit;
|
||||
use rustc_target::abi::{Abi, FieldsShape, InitKind, Scalar, Variants};
|
||||
use rustc_target::abi::{Abi, FieldsShape, Scalar, Variants};
|
||||
|
||||
use crate::const_eval::{CheckAlignment, CompileTimeInterpreter};
|
||||
use crate::interpret::{InterpCx, MemoryKind, OpTy};
|
||||
|
@ -20,8 +20,8 @@ use crate::interpret::{InterpCx, MemoryKind, OpTy};
|
|||
/// to the full uninit check).
|
||||
pub fn might_permit_raw_init<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
param_env_and_ty: ParamEnvAnd<'tcx, Ty<'tcx>>,
|
||||
kind: InitKind,
|
||||
param_env_and_ty: ParamEnvAnd<'tcx, Ty<'tcx>>,
|
||||
) -> Result<bool, LayoutError<'tcx>> {
|
||||
if tcx.sess.opts.unstable_opts.strict_init_checks {
|
||||
might_permit_raw_init_strict(tcx.layout_of(param_env_and_ty)?, tcx, kind)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue