Skip to content

Commit 914df2a

Browse files
committed
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
1 parent d5eec65 commit 914df2a

File tree

5 files changed

+9
-10
lines changed

5 files changed

+9
-10
lines changed

compiler/rustc_codegen_ssa/src/mir/analyze.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
231231
fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) {
232232
let check = match terminator.kind {
233233
mir::TerminatorKind::Call { func: mir::Operand::Constant(ref c), ref args, .. } => {
234-
match *c.literal.ty.kind() {
234+
match *c.ty().kind() {
235235
ty::FnDef(did, _) => Some((did, args)),
236236
_ => None,
237237
}

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -635,12 +635,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
635635
if i == 2 && intrinsic.as_str().starts_with("simd_shuffle") {
636636
if let mir::Operand::Constant(constant) = arg {
637637
let c = self.eval_mir_constant(constant);
638-
let (llval, ty) = self.simd_shuffle_indices(
639-
&bx,
640-
constant.span,
641-
constant.literal.ty,
642-
c,
643-
);
638+
let (llval, ty) =
639+
self.simd_shuffle_indices(&bx, constant.span, constant.ty(), c);
644640
return OperandRef {
645641
val: Immediate(llval),
646642
layout: bx.layout_of(ty),
@@ -830,7 +826,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
830826
let const_value = self
831827
.eval_mir_constant(constant)
832828
.unwrap_or_else(|_| span_bug!(span, "asm const cannot be resolved"));
833-
let ty = constant.literal.ty;
829+
let ty = constant.ty();
834830
let size = bx.layout_of(ty).size;
835831
let scalar = match const_value {
836832
ConstValue::Scalar(s) => s,

compiler/rustc_codegen_ssa/src/mir/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
1616
constant: &mir::Constant<'tcx>,
1717
) -> Result<OperandRef<'tcx, Bx::Value>, ErrorHandled> {
1818
let val = self.eval_mir_constant(constant)?;
19-
let ty = self.monomorphize(constant.literal.ty);
19+
let ty = self.monomorphize(constant.ty());
2020
Ok(OperandRef::from_const(bx, val, ty))
2121
}
2222

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
372372
(var_ty, var_kind)
373373
}
374374
mir::VarDebugInfoContents::Const(c) => {
375-
let ty = self.monomorphize(c.literal.ty);
375+
let ty = self.monomorphize(c.ty());
376376
(ty, VariableKind::LocalVariable)
377377
}
378378
};

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,6 +2421,9 @@ impl Constant<'tcx> {
24212421
_ => None,
24222422
}
24232423
}
2424+
pub fn ty(&self) -> Ty<'tcx> {
2425+
self.literal.ty
2426+
}
24242427
}
24252428

24262429
/// A collection of projections into user types.

0 commit comments

Comments
 (0)