1
Fork 0

Add ty helper function for mir constants

This is in preparation of the `literal` field becoming an enum that distinguishes between type level constants and runtime constants
This commit is contained in:
Oli Scherer 2021-03-08 14:14:11 +00:00
parent d5eec653c0
commit 914df2a493
5 changed files with 9 additions and 10 deletions

View file

@ -231,7 +231,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) { fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) {
let check = match terminator.kind { let check = match terminator.kind {
mir::TerminatorKind::Call { func: mir::Operand::Constant(ref c), ref args, .. } => { mir::TerminatorKind::Call { func: mir::Operand::Constant(ref c), ref args, .. } => {
match *c.literal.ty.kind() { match *c.ty().kind() {
ty::FnDef(did, _) => Some((did, args)), ty::FnDef(did, _) => Some((did, args)),
_ => None, _ => None,
} }

View file

@ -635,12 +635,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
if i == 2 && intrinsic.as_str().starts_with("simd_shuffle") { if i == 2 && intrinsic.as_str().starts_with("simd_shuffle") {
if let mir::Operand::Constant(constant) = arg { if let mir::Operand::Constant(constant) = arg {
let c = self.eval_mir_constant(constant); let c = self.eval_mir_constant(constant);
let (llval, ty) = self.simd_shuffle_indices( let (llval, ty) =
&bx, self.simd_shuffle_indices(&bx, constant.span, constant.ty(), c);
constant.span,
constant.literal.ty,
c,
);
return OperandRef { return OperandRef {
val: Immediate(llval), val: Immediate(llval),
layout: bx.layout_of(ty), layout: bx.layout_of(ty),
@ -830,7 +826,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let const_value = self let const_value = self
.eval_mir_constant(constant) .eval_mir_constant(constant)
.unwrap_or_else(|_| span_bug!(span, "asm const cannot be resolved")); .unwrap_or_else(|_| span_bug!(span, "asm const cannot be resolved"));
let ty = constant.literal.ty; let ty = constant.ty();
let size = bx.layout_of(ty).size; let size = bx.layout_of(ty).size;
let scalar = match const_value { let scalar = match const_value {
ConstValue::Scalar(s) => s, ConstValue::Scalar(s) => s,

View file

@ -16,7 +16,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
constant: &mir::Constant<'tcx>, constant: &mir::Constant<'tcx>,
) -> Result<OperandRef<'tcx, Bx::Value>, ErrorHandled> { ) -> Result<OperandRef<'tcx, Bx::Value>, ErrorHandled> {
let val = self.eval_mir_constant(constant)?; let val = self.eval_mir_constant(constant)?;
let ty = self.monomorphize(constant.literal.ty); let ty = self.monomorphize(constant.ty());
Ok(OperandRef::from_const(bx, val, ty)) Ok(OperandRef::from_const(bx, val, ty))
} }

View file

@ -372,7 +372,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
(var_ty, var_kind) (var_ty, var_kind)
} }
mir::VarDebugInfoContents::Const(c) => { mir::VarDebugInfoContents::Const(c) => {
let ty = self.monomorphize(c.literal.ty); let ty = self.monomorphize(c.ty());
(ty, VariableKind::LocalVariable) (ty, VariableKind::LocalVariable)
} }
}; };

View file

@ -2421,6 +2421,9 @@ impl Constant<'tcx> {
_ => None, _ => None,
} }
} }
pub fn ty(&self) -> Ty<'tcx> {
self.literal.ty
}
} }
/// A collection of projections into user types. /// A collection of projections into user types.