mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-06 03:52:53 +00:00
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:
parent
d5eec653c0
commit
914df2a493
@ -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) {
|
||||
let check = match terminator.kind {
|
||||
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)),
|
||||
_ => None,
|
||||
}
|
||||
|
@ -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 let mir::Operand::Constant(constant) = arg {
|
||||
let c = self.eval_mir_constant(constant);
|
||||
let (llval, ty) = self.simd_shuffle_indices(
|
||||
&bx,
|
||||
constant.span,
|
||||
constant.literal.ty,
|
||||
c,
|
||||
);
|
||||
let (llval, ty) =
|
||||
self.simd_shuffle_indices(&bx, constant.span, constant.ty(), c);
|
||||
return OperandRef {
|
||||
val: Immediate(llval),
|
||||
layout: bx.layout_of(ty),
|
||||
@ -830,7 +826,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
let const_value = self
|
||||
.eval_mir_constant(constant)
|
||||
.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 scalar = match const_value {
|
||||
ConstValue::Scalar(s) => s,
|
||||
|
@ -16,7 +16,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
constant: &mir::Constant<'tcx>,
|
||||
) -> Result<OperandRef<'tcx, Bx::Value>, ErrorHandled> {
|
||||
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))
|
||||
}
|
||||
|
||||
|
@ -372,7 +372,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
(var_ty, var_kind)
|
||||
}
|
||||
mir::VarDebugInfoContents::Const(c) => {
|
||||
let ty = self.monomorphize(c.literal.ty);
|
||||
let ty = self.monomorphize(c.ty());
|
||||
(ty, VariableKind::LocalVariable)
|
||||
}
|
||||
};
|
||||
|
@ -2421,6 +2421,9 @@ impl Constant<'tcx> {
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
pub fn ty(&self) -> Ty<'tcx> {
|
||||
self.literal.ty
|
||||
}
|
||||
}
|
||||
|
||||
/// A collection of projections into user types.
|
||||
|
Loading…
Reference in New Issue
Block a user