Do not unnecessarily eval consts in codegen
This commit is contained in:
parent
da889684c8
commit
914193c8f4
8 changed files with 30 additions and 19 deletions
|
@ -115,9 +115,9 @@ fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
|||
let (source, target) =
|
||||
cx.tcx().struct_lockstep_tails_for_codegen(source, target, bx.param_env());
|
||||
match (source.kind(), target.kind()) {
|
||||
(&ty::Array(_, len), &ty::Slice(_)) => {
|
||||
cx.const_usize(len.eval_target_usize(cx.tcx(), ty::ParamEnv::reveal_all()))
|
||||
}
|
||||
(&ty::Array(_, len), &ty::Slice(_)) => cx.const_usize(
|
||||
len.try_to_target_usize(cx.tcx()).expect("expected monomorphic const in codegen"),
|
||||
),
|
||||
(&ty::Dynamic(data_a, _, src_dyn_kind), &ty::Dynamic(data_b, _, target_dyn_kind))
|
||||
if src_dyn_kind == target_dyn_kind =>
|
||||
{
|
||||
|
|
|
@ -188,7 +188,8 @@ fn push_debuginfo_type_name<'tcx>(
|
|||
_ => write!(
|
||||
output,
|
||||
",{}>",
|
||||
len.eval_target_usize(tcx, ty::ParamEnv::reveal_all())
|
||||
len.try_to_target_usize(tcx)
|
||||
.expect("expected monomorphic const in codegen")
|
||||
)
|
||||
.unwrap(),
|
||||
}
|
||||
|
@ -200,7 +201,8 @@ fn push_debuginfo_type_name<'tcx>(
|
|||
_ => write!(
|
||||
output,
|
||||
"; {}]",
|
||||
len.eval_target_usize(tcx, ty::ParamEnv::reveal_all())
|
||||
len.try_to_target_usize(tcx)
|
||||
.expect("expected monomorphic const in codegen")
|
||||
)
|
||||
.unwrap(),
|
||||
}
|
||||
|
|
|
@ -114,7 +114,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
|
||||
let count = self
|
||||
.monomorphize(count)
|
||||
.eval_target_usize(bx.cx().tcx(), ty::ParamEnv::reveal_all());
|
||||
.try_to_target_usize(bx.tcx())
|
||||
.expect("expected monomorphic const in codegen");
|
||||
|
||||
bx.write_operand_repeatedly(cg_elem, count, dest);
|
||||
}
|
||||
|
@ -803,7 +804,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
if let Some(index) = place.as_local() {
|
||||
if let LocalRef::Operand(op) = self.locals[index] {
|
||||
if let ty::Array(_, n) = op.layout.ty.kind() {
|
||||
let n = n.eval_target_usize(bx.cx().tcx(), ty::ParamEnv::reveal_all());
|
||||
let n = n
|
||||
.try_to_target_usize(bx.tcx())
|
||||
.expect("expected monomorphic const in codegen");
|
||||
return bx.cx().const_usize(n);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue