mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-01 12:37:37 +00:00

Use constant eval to do strict mem::uninit/zeroed validity checks I'm not sure about the code organisation here, I just dumped the check in rustc_const_eval at the root. Not hard to move it elsewhere, in any case. Also, this means cranelift codegen intrinsics lose the strict checks, since they don't seem to depend on rustc_const_eval, and I didn't see a point in keeping around two copies. I also left comments in the is_zero_valid methods about "uhhh help how do i do this", those apply to both methods equally. Also rustc_codegen_ssa now depends on rustc_const_eval... is this okay? Pinging `@RalfJung` since you were the one who mentioned this to me, so I'm assuming you're interested. Haven't had a chance to run full tests on this since it's really warm, and it's 1AM, I'll check out any failures/comments in the morning :)
69 lines
2.2 KiB
Rust
69 lines
2.2 KiB
Rust
/*!
|
|
|
|
Rust MIR: a lowered representation of Rust.
|
|
|
|
*/
|
|
|
|
#![feature(assert_matches)]
|
|
#![feature(box_patterns)]
|
|
#![feature(control_flow_enum)]
|
|
#![feature(decl_macro)]
|
|
#![feature(exact_size_is_empty)]
|
|
#![cfg_attr(bootstrap, feature(let_chains))]
|
|
#![feature(let_else)]
|
|
#![feature(map_try_insert)]
|
|
#![feature(min_specialization)]
|
|
#![feature(slice_ptr_get)]
|
|
#![feature(option_get_or_insert_default)]
|
|
#![feature(never_type)]
|
|
#![feature(trait_alias)]
|
|
#![feature(trusted_len)]
|
|
#![feature(trusted_step)]
|
|
#![feature(try_blocks)]
|
|
#![feature(yeet_expr)]
|
|
#![feature(is_some_with)]
|
|
#![recursion_limit = "256"]
|
|
#![allow(rustc::potential_query_instability)]
|
|
|
|
#[macro_use]
|
|
extern crate tracing;
|
|
#[macro_use]
|
|
extern crate rustc_middle;
|
|
|
|
pub mod const_eval;
|
|
mod errors;
|
|
pub mod interpret;
|
|
mod might_permit_raw_init;
|
|
pub mod transform;
|
|
pub mod util;
|
|
|
|
use rustc_middle::ty;
|
|
use rustc_middle::ty::query::Providers;
|
|
use rustc_target::abi::InitKind;
|
|
|
|
pub fn provide(providers: &mut Providers) {
|
|
const_eval::provide(providers);
|
|
providers.eval_to_const_value_raw = const_eval::eval_to_const_value_raw_provider;
|
|
providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
|
|
providers.const_caller_location = const_eval::const_caller_location;
|
|
providers.eval_to_valtree = |tcx, param_env_and_value| {
|
|
let (param_env, raw) = param_env_and_value.into_parts();
|
|
const_eval::eval_to_valtree(tcx, param_env, raw)
|
|
};
|
|
providers.try_destructure_mir_constant = |tcx, param_env_and_value| {
|
|
let (param_env, value) = param_env_and_value.into_parts();
|
|
const_eval::try_destructure_mir_constant(tcx, param_env, value).ok()
|
|
};
|
|
providers.valtree_to_const_val = |tcx, (ty, valtree)| {
|
|
const_eval::valtree_to_const_value(tcx, ty::ParamEnv::empty().and(ty), valtree)
|
|
};
|
|
providers.deref_mir_constant = |tcx, param_env_and_value| {
|
|
let (param_env, value) = param_env_and_value.into_parts();
|
|
const_eval::deref_mir_constant(tcx, param_env, value)
|
|
};
|
|
providers.permits_uninit_init =
|
|
|tcx, ty| might_permit_raw_init::might_permit_raw_init(tcx, ty, InitKind::Uninit);
|
|
providers.permits_zero_init =
|
|
|tcx, ty| might_permit_raw_init::might_permit_raw_init(tcx, ty, InitKind::Zero);
|
|
}
|