Sync from rust 8e9c93df464b7ada3fc7a1c8ccddd9dcb24ee0a0
This commit is contained in:
commit
385003e4c1
@ -850,6 +850,7 @@ pub(crate) fn codegen_place<'tcx>(
|
|||||||
PlaceElem::Deref => {
|
PlaceElem::Deref => {
|
||||||
cplace = cplace.place_deref(fx);
|
cplace = cplace.place_deref(fx);
|
||||||
}
|
}
|
||||||
|
PlaceElem::OpaqueCast(ty) => cplace = cplace.place_opaque_cast(fx, ty),
|
||||||
PlaceElem::Field(field, _ty) => {
|
PlaceElem::Field(field, _ty) => {
|
||||||
cplace = cplace.place_field(fx, field);
|
cplace = cplace.place_field(fx, field);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
|||||||
use rustc_middle::mir::interpret::{
|
use rustc_middle::mir::interpret::{
|
||||||
read_target_uint, AllocId, ConstAllocation, ConstValue, ErrorHandled, GlobalAlloc, Scalar,
|
read_target_uint, AllocId, ConstAllocation, ConstValue, ErrorHandled, GlobalAlloc, Scalar,
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::ConstKind;
|
|
||||||
use rustc_span::DUMMY_SP;
|
use rustc_span::DUMMY_SP;
|
||||||
|
|
||||||
use cranelift_codegen::ir::GlobalValueData;
|
use cranelift_codegen::ir::GlobalValueData;
|
||||||
@ -41,36 +40,22 @@ impl ConstantCx {
|
|||||||
pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool {
|
pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool {
|
||||||
let mut all_constants_ok = true;
|
let mut all_constants_ok = true;
|
||||||
for constant in &fx.mir.required_consts {
|
for constant in &fx.mir.required_consts {
|
||||||
let const_ = match fx.monomorphize(constant.literal) {
|
let unevaluated = match fx.monomorphize(constant.literal) {
|
||||||
ConstantKind::Ty(ct) => ct,
|
ConstantKind::Ty(_) => unreachable!(),
|
||||||
|
ConstantKind::Unevaluated(uv, _) => uv,
|
||||||
ConstantKind::Val(..) => continue,
|
ConstantKind::Val(..) => continue,
|
||||||
};
|
};
|
||||||
match const_.kind() {
|
|
||||||
ConstKind::Value(_) => {}
|
if let Err(err) = fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None) {
|
||||||
ConstKind::Unevaluated(unevaluated) => {
|
all_constants_ok = false;
|
||||||
if let Err(err) =
|
match err {
|
||||||
fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None)
|
ErrorHandled::Reported(_) | ErrorHandled::Linted => {
|
||||||
{
|
fx.tcx.sess.span_err(constant.span, "erroneous constant encountered");
|
||||||
all_constants_ok = false;
|
}
|
||||||
match err {
|
ErrorHandled::TooGeneric => {
|
||||||
ErrorHandled::Reported(_) | ErrorHandled::Linted => {
|
span_bug!(constant.span, "codegen encountered polymorphic constant: {:?}", err);
|
||||||
fx.tcx.sess.span_err(constant.span, "erroneous constant encountered");
|
|
||||||
}
|
|
||||||
ErrorHandled::TooGeneric => {
|
|
||||||
span_bug!(
|
|
||||||
constant.span,
|
|
||||||
"codegen encountered polymorphic constant: {:?}",
|
|
||||||
err
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ConstKind::Param(_)
|
|
||||||
| ConstKind::Infer(_)
|
|
||||||
| ConstKind::Bound(_, _)
|
|
||||||
| ConstKind::Placeholder(_)
|
|
||||||
| ConstKind::Error(_) => unreachable!("{:?}", const_),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
all_constants_ok
|
all_constants_ok
|
||||||
@ -122,36 +107,28 @@ pub(crate) fn codegen_constant<'tcx>(
|
|||||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||||
constant: &Constant<'tcx>,
|
constant: &Constant<'tcx>,
|
||||||
) -> CValue<'tcx> {
|
) -> CValue<'tcx> {
|
||||||
let const_ = match fx.monomorphize(constant.literal) {
|
let (const_val, ty) = match fx.monomorphize(constant.literal) {
|
||||||
ConstantKind::Ty(ct) => ct,
|
ConstantKind::Ty(const_) => unreachable!("{:?}", const_),
|
||||||
ConstantKind::Val(val, ty) => return codegen_const_value(fx, val, ty),
|
ConstantKind::Unevaluated(mir::UnevaluatedConst { def, substs, promoted }, ty)
|
||||||
};
|
|
||||||
let const_val = match const_.kind() {
|
|
||||||
ConstKind::Value(valtree) => fx.tcx.valtree_to_const_val((const_.ty(), valtree)),
|
|
||||||
ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted })
|
|
||||||
if fx.tcx.is_static(def.did) =>
|
if fx.tcx.is_static(def.did) =>
|
||||||
{
|
{
|
||||||
assert!(substs.is_empty());
|
assert!(substs.is_empty());
|
||||||
assert!(promoted.is_none());
|
assert!(promoted.is_none());
|
||||||
|
|
||||||
return codegen_static_ref(fx, def.did, fx.layout_of(const_.ty())).to_cvalue(fx);
|
return codegen_static_ref(fx, def.did, fx.layout_of(ty)).to_cvalue(fx);
|
||||||
}
|
}
|
||||||
ConstKind::Unevaluated(unevaluated) => {
|
ConstantKind::Unevaluated(unevaluated, ty) => {
|
||||||
match fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None) {
|
match fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None) {
|
||||||
Ok(const_val) => const_val,
|
Ok(const_val) => (const_val, ty),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
span_bug!(constant.span, "erroneous constant not captured by required_consts");
|
span_bug!(constant.span, "erroneous constant not captured by required_consts");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ConstKind::Param(_)
|
ConstantKind::Val(val, ty) => (val, ty),
|
||||||
| ConstKind::Infer(_)
|
|
||||||
| ConstKind::Bound(_, _)
|
|
||||||
| ConstKind::Placeholder(_)
|
|
||||||
| ConstKind::Error(_) => unreachable!("{:?}", const_),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
codegen_const_value(fx, const_val, const_.ty())
|
codegen_const_value(fx, const_val, ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn codegen_const_value<'tcx>(
|
pub(crate) fn codegen_const_value<'tcx>(
|
||||||
@ -496,6 +473,9 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
|
|||||||
.eval_for_mir(fx.tcx, ParamEnv::reveal_all())
|
.eval_for_mir(fx.tcx, ParamEnv::reveal_all())
|
||||||
.try_to_value(fx.tcx),
|
.try_to_value(fx.tcx),
|
||||||
ConstantKind::Val(val, _) => Some(val),
|
ConstantKind::Val(val, _) => Some(val),
|
||||||
|
ConstantKind::Unevaluated(uv, _) => {
|
||||||
|
fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), uv, None).ok()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// FIXME(rust-lang/rust#85105): Casts like `IMM8 as u32` result in the const being stored
|
// FIXME(rust-lang/rust#85105): Casts like `IMM8 as u32` result in the const being stored
|
||||||
// inside a temporary before being passed to the intrinsic requiring the const argument.
|
// inside a temporary before being passed to the intrinsic requiring the const argument.
|
||||||
|
@ -625,6 +625,14 @@ impl<'tcx> CPlace<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn place_opaque_cast(
|
||||||
|
self,
|
||||||
|
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||||
|
ty: Ty<'tcx>,
|
||||||
|
) -> CPlace<'tcx> {
|
||||||
|
CPlace { inner: self.inner, layout: fx.layout_of(ty) }
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn place_field(
|
pub(crate) fn place_field(
|
||||||
self,
|
self,
|
||||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user