Skip to content

Commit 1351de3

Browse files
Rollup merge of #115972 - RalfJung:const-consistency, r=oli-obk
rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const Also, be more consistent with the `to/eval_bits` methods... we had some that take a type and some that take a size, and then sometimes the one that takes a type is called `bits_for_ty`. Turns out that `ty::Const`/`mir::ConstKind` carry their type with them, so we don't need to even pass the type to those `eval_bits` functions at all. However this is not properly consistent yet: in `ty` we have most of the methods on `ty::Const`, but in `mir` we have them on `mir::ConstKind`. And indeed those two types are the ones that correspond to each other. So `mir::ConstantKind` should actually be renamed to `mir::Const`. But what to do with `mir::Constant`? It carries around a span, that's really more like a constant operand that appears as a MIR operand... it's more suited for `syntax.rs` than `consts.rs`, but the bigger question is, which name should it get if we want to align the `mir` and `ty` types? `ConstOperand`? `ConstOp`? `Literal`? It's not a literal but it has a field called `literal` so it would at least be consistently wrong-ish... ``@oli-obk`` any ideas?
2 parents dd48b5e + 0e02cab commit 1351de3

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Diff for: src/constant.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ pub(crate) fn codegen_tls_ref<'tcx>(
6464

6565
pub(crate) fn eval_mir_constant<'tcx>(
6666
fx: &FunctionCx<'_, '_, 'tcx>,
67-
constant: &Constant<'tcx>,
67+
constant: &ConstOperand<'tcx>,
6868
) -> (ConstValue<'tcx>, Ty<'tcx>) {
69-
let cv = fx.monomorphize(constant.literal);
69+
let cv = fx.monomorphize(constant.const_);
7070
// This cannot fail because we checked all required_consts in advance.
7171
let val = cv
7272
.eval(fx.tcx, ty::ParamEnv::reveal_all(), Some(constant.span))
@@ -76,7 +76,7 @@ pub(crate) fn eval_mir_constant<'tcx>(
7676

7777
pub(crate) fn codegen_constant_operand<'tcx>(
7878
fx: &mut FunctionCx<'_, '_, 'tcx>,
79-
constant: &Constant<'tcx>,
79+
constant: &ConstOperand<'tcx>,
8080
) -> CValue<'tcx> {
8181
let (const_val, ty) = eval_mir_constant(fx, constant);
8282
codegen_const_value(fx, const_val, ty)

Diff for: src/inline_asm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ pub(crate) fn codegen_inline_asm<'tcx>(
252252
CInlineAsmOperand::Const { value }
253253
}
254254
InlineAsmOperand::SymFn { ref value } => {
255-
let literal = fx.monomorphize(value.literal);
256-
if let ty::FnDef(def_id, args) = *literal.ty().kind() {
255+
let const_ = fx.monomorphize(value.const_);
256+
if let ty::FnDef(def_id, args) = *const_.ty().kind() {
257257
let instance = ty::Instance::resolve_for_fn_ptr(
258258
fx.tcx,
259259
ty::ParamEnv::reveal_all(),

0 commit comments

Comments
 (0)