Skip to content

Commit a5d8b4d

Browse files
committed
rename mir::Constant -> mir::Const (to be consistent with ty::Const)
1 parent 0692db1 commit a5d8b4d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+276
-278
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_index::IndexSlice;
1313
use rustc_infer::infer::LateBoundRegionConversionTime;
1414
use rustc_middle::mir::tcx::PlaceTy;
1515
use rustc_middle::mir::{
16-
AggregateKind, CallSource, Constant, FakeReadCause, Local, LocalInfo, LocalKind, Location,
16+
AggregateKind, CallSource, Const, FakeReadCause, Local, LocalInfo, LocalKind, Location,
1717
Operand, Place, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator,
1818
TerminatorKind,
1919
};
@@ -101,7 +101,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
101101
let terminator = self.body[location.block].terminator();
102102
debug!("add_moved_or_invoked_closure_note: terminator={:?}", terminator);
103103
if let TerminatorKind::Call {
104-
func: Operand::Constant(box Constant { literal, .. }),
104+
func: Operand::Constant(box Const { literal, .. }),
105105
args,
106106
..
107107
} = &terminator.kind

compiler/rustc_borrowck/src/renumber.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::BorrowckInferCtxt;
44
use rustc_index::IndexSlice;
55
use rustc_infer::infer::NllRegionVariableOrigin;
66
use rustc_middle::mir::visit::{MutVisitor, TyContext};
7-
use rustc_middle::mir::Constant;
7+
use rustc_middle::mir::Const;
88
use rustc_middle::mir::{Body, Location, Promoted};
99
use rustc_middle::ty::GenericArgsRef;
1010
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
@@ -117,7 +117,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for RegionRenumberer<'a, 'tcx> {
117117
}
118118

119119
#[instrument(skip(self), level = "debug")]
120-
fn visit_constant(&mut self, constant: &mut Constant<'tcx>, location: Location) {
120+
fn visit_constant(&mut self, constant: &mut Const<'tcx>, location: Location) {
121121
let literal = constant.literal;
122122
constant.literal = self.renumber_regions(literal, || RegionCtxt::Location(location));
123123
debug!("constant: {:#?}", constant);

compiler/rustc_borrowck/src/type_check/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
302302
self.sanitize_place(place, location, context);
303303
}
304304

305-
fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
305+
fn visit_constant(&mut self, constant: &Const<'tcx>, location: Location) {
306306
debug!(?constant, ?location, "visit_constant");
307307

308308
self.super_constant(constant, location);
@@ -347,13 +347,13 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
347347
} else {
348348
let tcx = self.tcx();
349349
let maybe_uneval = match constant.literal {
350-
ConstantKind::Ty(ct) => match ct.kind() {
350+
ConstKind::Ty(ct) => match ct.kind() {
351351
ty::ConstKind::Unevaluated(_) => {
352-
bug!("should not encounter unevaluated ConstantKind::Ty here, got {:?}", ct)
352+
bug!("should not encounter unevaluated ConstKind::Ty here, got {:?}", ct)
353353
}
354354
_ => None,
355355
},
356-
ConstantKind::Unevaluated(uv, _) => Some(uv),
356+
ConstKind::Unevaluated(uv, _) => Some(uv),
357357
_ => None,
358358
};
359359

@@ -1802,8 +1802,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18021802

18031803
if let Operand::Constant(constant) = op {
18041804
let maybe_uneval = match constant.literal {
1805-
ConstantKind::Val(..) | ConstantKind::Ty(_) => None,
1806-
ConstantKind::Unevaluated(uv, _) => Some(uv),
1805+
ConstKind::Val(..) | ConstKind::Ty(_) => None,
1806+
ConstKind::Unevaluated(uv, _) => Some(uv),
18071807
};
18081808

18091809
if let Some(uv) = maybe_uneval {

compiler/rustc_codegen_cranelift/src/constant.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
44
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
55
use rustc_middle::mir::interpret::{read_target_uint, AllocId, GlobalAlloc, Scalar};
6-
use rustc_middle::mir::ConstValue;
6+
use rustc_middle::mir::Const;
77

88
use cranelift_module::*;
99

@@ -64,7 +64,7 @@ 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: &Const<'tcx>,
6868
) -> (ConstValue<'tcx>, Ty<'tcx>) {
6969
let cv = fx.monomorphize(constant.literal);
7070
// This cannot fail because we checked all required_consts in advance.
@@ -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: &Const<'tcx>,
8080
) -> CValue<'tcx> {
8181
let (const_val, ty) = eval_mir_constant(fx, constant);
8282
codegen_const_value(fx, const_val, ty)

compiler/rustc_codegen_ssa/src/mir/constant.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,37 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
1313
pub fn eval_mir_constant_to_operand(
1414
&self,
1515
bx: &mut Bx,
16-
constant: &mir::Constant<'tcx>,
16+
constant: &mir::Const<'tcx>,
1717
) -> OperandRef<'tcx, Bx::Value> {
1818
let val = self.eval_mir_constant(constant);
1919
let ty = self.monomorphize(constant.ty());
2020
OperandRef::from_const(bx, val, ty)
2121
}
2222

23-
pub fn eval_mir_constant(&self, constant: &mir::Constant<'tcx>) -> mir::ConstValue<'tcx> {
23+
pub fn eval_mir_constant(&self, constant: &mir::Const<'tcx>) -> mir::ConstValue<'tcx> {
2424
self.monomorphize(constant.literal)
2525
.eval(self.cx.tcx(), ty::ParamEnv::reveal_all(), Some(constant.span))
2626
.expect("erroneous constant not captured by required_consts")
2727
}
2828

2929
/// This is a convenience helper for `simd_shuffle_indices`. It has the precondition
30-
/// that the given `constant` is an `ConstantKind::Unevaluated` and must be convertible to
30+
/// that the given `constant` is an `ConstKind::Unevaluated` and must be convertible to
3131
/// a `ValTree`. If you want a more general version of this, talk to `wg-const-eval` on zulip.
3232
///
3333
/// Note that this function is cursed, since usually MIR consts should not be evaluated to valtrees!
3434
pub fn eval_unevaluated_mir_constant_to_valtree(
3535
&self,
36-
constant: &mir::Constant<'tcx>,
36+
constant: &mir::Const<'tcx>,
3737
) -> Result<Option<ty::ValTree<'tcx>>, ErrorHandled> {
3838
let uv = match self.monomorphize(constant.literal) {
39-
mir::ConstantKind::Unevaluated(uv, _) => uv.shrink(),
40-
mir::ConstantKind::Ty(c) => match c.kind() {
39+
mir::ConstKind::Unevaluated(uv, _) => uv.shrink(),
40+
mir::ConstKind::Ty(c) => match c.kind() {
4141
// A constant that came from a const generic but was then used as an argument to old-style
4242
// simd_shuffle (passing as argument instead of as a generic param).
4343
rustc_type_ir::ConstKind::Value(valtree) => return Ok(Some(valtree)),
4444
other => span_bug!(constant.span, "{other:#?}"),
4545
},
46-
// We should never encounter `ConstantKind::Val` unless MIR opts (like const prop) evaluate
46+
// We should never encounter `ConstKind::Val` unless MIR opts (like const prop) evaluate
4747
// a constant and write that value back into `Operand`s. This could happen, but is unlikely.
4848
// Also: all users of `simd_shuffle` are on unstable and already need to take a lot of care
4949
// around intrinsics. For an issue to happen here, it would require a macro expanding to a
@@ -65,7 +65,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
6565
pub fn simd_shuffle_indices(
6666
&mut self,
6767
bx: &Bx,
68-
constant: &mir::Constant<'tcx>,
68+
constant: &mir::Const<'tcx>,
6969
) -> (Bx::Value, Ty<'tcx>) {
7070
let ty = self.monomorphize(constant.ty());
7171
let val = self

compiler/rustc_const_eval/src/interpret/eval_context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
10891089

10901090
pub fn eval_mir_constant(
10911091
&self,
1092-
val: &mir::ConstantKind<'tcx>,
1092+
val: &mir::ConstKind<'tcx>,
10931093
span: Option<Span>,
10941094
layout: Option<TyAndLayout<'tcx>>,
10951095
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -347,19 +347,19 @@ where
347347

348348
// Check the qualifs of the value of `const` items.
349349
let uneval = match constant.literal {
350-
ConstantKind::Ty(ct)
350+
ConstKind::Ty(ct)
351351
if matches!(
352352
ct.kind(),
353353
ty::ConstKind::Param(_) | ty::ConstKind::Error(_) | ty::ConstKind::Value(_)
354354
) =>
355355
{
356356
None
357357
}
358-
ConstantKind::Ty(c) => {
358+
ConstKind::Ty(c) => {
359359
bug!("expected ConstKind::Param or ConstKind::Value here, found {:?}", c)
360360
}
361-
ConstantKind::Unevaluated(uv, _) => Some(uv),
362-
ConstantKind::Val(..) => None,
361+
ConstKind::Unevaluated(uv, _) => Some(uv),
362+
ConstKind::Val(..) => None,
363363
};
364364

365365
if let Some(mir::UnevaluatedConst { def, args: _, promoted }) = uneval {

compiler/rustc_const_eval/src/transform/promote_consts.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -766,10 +766,10 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
766766
if self.keep_original {
767767
rhs.clone()
768768
} else {
769-
let unit = Rvalue::Use(Operand::Constant(Box::new(Constant {
769+
let unit = Rvalue::Use(Operand::Constant(Box::new(Const {
770770
span: statement.source_info.span,
771771
user_ty: None,
772-
literal: ConstantKind::zero_sized(self.tcx.types.unit),
772+
literal: ConstKind::zero_sized(self.tcx.types.unit),
773773
})));
774774
mem::replace(rhs, unit)
775775
},
@@ -844,10 +844,10 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
844844
let args = tcx.erase_regions(GenericArgs::identity_for_item(tcx, def));
845845
let uneval = mir::UnevaluatedConst { def, args, promoted: Some(promoted_id) };
846846

847-
Operand::Constant(Box::new(Constant {
847+
Operand::Constant(Box::new(Const {
848848
span,
849849
user_ty: None,
850-
literal: ConstantKind::Unevaluated(uneval, ty),
850+
literal: ConstKind::Unevaluated(uneval, ty),
851851
}))
852852
};
853853

@@ -1041,7 +1041,7 @@ pub fn is_const_fn_in_array_repeat_expression<'tcx>(
10411041
if let Some(Terminator { kind: TerminatorKind::Call { func, destination, .. }, .. }) =
10421042
&block.terminator
10431043
{
1044-
if let Operand::Constant(box Constant { literal, .. }) = func {
1044+
if let Operand::Constant(box Const { literal, .. }) = func {
10451045
if let ty::FnDef(def_id, _) = *literal.ty().kind() {
10461046
if destination == place {
10471047
if ccx.tcx.is_const_fn(def_id) {

compiler/rustc_middle/src/mir/consts.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl<'tcx> ConstValue<'tcx> {
176176
177177
#[derive(Clone, Copy, PartialEq, TyEncodable, TyDecodable, Hash, HashStable)]
178178
#[derive(TypeFoldable, TypeVisitable)]
179-
pub struct Constant<'tcx> {
179+
pub struct Const<'tcx> {
180180
pub span: Span,
181181

182182
/// Optional user-given type: for something like
@@ -186,12 +186,12 @@ pub struct Constant<'tcx> {
186186
/// Needed for NLL to impose user-given type constraints.
187187
pub user_ty: Option<UserTypeAnnotationIndex>,
188188

189-
pub literal: ConstantKind<'tcx>,
189+
pub literal: ConstKind<'tcx>,
190190
}
191191

192192
#[derive(Clone, Copy, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable, Debug)]
193193
#[derive(TypeFoldable, TypeVisitable)]
194-
pub enum ConstantKind<'tcx> {
194+
pub enum ConstKind<'tcx> {
195195
/// This constant came from the type system.
196196
///
197197
/// Any way of turning `ty::Const` into `ConstValue` should go through `valtree_to_const_val`;
@@ -212,7 +212,7 @@ pub enum ConstantKind<'tcx> {
212212
Val(ConstValue<'tcx>, Ty<'tcx>),
213213
}
214214

215-
impl<'tcx> Constant<'tcx> {
215+
impl<'tcx> Const<'tcx> {
216216
pub fn check_static_ptr(&self, tcx: TyCtxt<'_>) -> Option<DefId> {
217217
match self.literal.try_to_scalar() {
218218
Some(Scalar::Ptr(ptr, _size)) => match tcx.global_alloc(ptr.provenance) {
@@ -231,27 +231,27 @@ impl<'tcx> Constant<'tcx> {
231231
}
232232
}
233233

234-
impl<'tcx> ConstantKind<'tcx> {
234+
impl<'tcx> ConstKind<'tcx> {
235235
#[inline(always)]
236236
pub fn ty(&self) -> Ty<'tcx> {
237237
match self {
238-
ConstantKind::Ty(c) => c.ty(),
239-
ConstantKind::Val(_, ty) | ConstantKind::Unevaluated(_, ty) => *ty,
238+
ConstKind::Ty(c) => c.ty(),
239+
ConstKind::Val(_, ty) | ConstKind::Unevaluated(_, ty) => *ty,
240240
}
241241
}
242242

243243
#[inline]
244244
pub fn try_to_scalar(self) -> Option<Scalar> {
245245
match self {
246-
ConstantKind::Ty(c) => match c.kind() {
246+
ConstKind::Ty(c) => match c.kind() {
247247
ty::ConstKind::Value(valtree) => match valtree {
248248
ty::ValTree::Leaf(scalar_int) => Some(Scalar::Int(scalar_int)),
249249
ty::ValTree::Branch(_) => None,
250250
},
251251
_ => None,
252252
},
253-
ConstantKind::Val(val, _) => val.try_to_scalar(),
254-
ConstantKind::Unevaluated(..) => None,
253+
ConstKind::Val(val, _) => val.try_to_scalar(),
254+
ConstKind::Unevaluated(..) => None,
255255
}
256256
}
257257

@@ -278,17 +278,17 @@ impl<'tcx> ConstantKind<'tcx> {
278278
span: Option<Span>,
279279
) -> Result<ConstValue<'tcx>, ErrorHandled> {
280280
match self {
281-
ConstantKind::Ty(c) => {
281+
ConstKind::Ty(c) => {
282282
// We want to consistently have a "clean" value for type system constants (i.e., no
283283
// data hidden in the padding), so we always go through a valtree here.
284284
let val = c.eval(tcx, param_env, span)?;
285285
Ok(tcx.valtree_to_const_val((self.ty(), val)))
286286
}
287-
ConstantKind::Unevaluated(uneval, _) => {
287+
ConstKind::Unevaluated(uneval, _) => {
288288
// FIXME: We might want to have a `try_eval`-like function on `Unevaluated`
289289
tcx.const_eval_resolve(param_env, uneval, span)
290290
}
291-
ConstantKind::Val(val, _) => Ok(val),
291+
ConstKind::Val(val, _) => Ok(val),
292292
}
293293
}
294294

@@ -407,7 +407,7 @@ impl<'tcx> ConstantKind<'tcx> {
407407
Self::Val(val, ty)
408408
}
409409

410-
/// Literals are converted to `ConstantKindVal`, const generic parameters are eagerly
410+
/// Literals are converted to `ConstKind::Val`, const generic parameters are eagerly
411411
/// converted to a constant, everything else becomes `Unevaluated`.
412412
#[instrument(skip(tcx), level = "debug", ret)]
413413
pub fn from_anon_const(
@@ -543,13 +543,13 @@ impl<'tcx> UnevaluatedConst<'tcx> {
543543
}
544544
}
545545

546-
impl<'tcx> Debug for Constant<'tcx> {
546+
impl<'tcx> Debug for Const<'tcx> {
547547
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
548548
write!(fmt, "{self}")
549549
}
550550
}
551551

552-
impl<'tcx> Display for Constant<'tcx> {
552+
impl<'tcx> Display for Const<'tcx> {
553553
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
554554
match self.ty().kind() {
555555
ty::FnDef(..) => {}
@@ -559,13 +559,13 @@ impl<'tcx> Display for Constant<'tcx> {
559559
}
560560
}
561561

562-
impl<'tcx> Display for ConstantKind<'tcx> {
562+
impl<'tcx> Display for ConstKind<'tcx> {
563563
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
564564
match *self {
565-
ConstantKind::Ty(c) => pretty_print_const(c, fmt, true),
566-
ConstantKind::Val(val, ty) => pretty_print_const_value(val, ty, fmt),
565+
ConstKind::Ty(c) => pretty_print_const(c, fmt, true),
566+
ConstKind::Val(val, ty) => pretty_print_const_value(val, ty, fmt),
567567
// FIXME(valtrees): Correctly print mir constants.
568-
ConstantKind::Unevaluated(..) => {
568+
ConstKind::Unevaluated(..) => {
569569
fmt.write_str("_")?;
570570
Ok(())
571571
}

compiler/rustc_middle/src/mir/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ pub struct Body<'tcx> {
318318

319319
/// Constants that are required to evaluate successfully for this MIR to be well-formed.
320320
/// We hold in this field all the constants we are not able to evaluate yet.
321-
pub required_consts: Vec<Constant<'tcx>>,
321+
pub required_consts: Vec<Const<'tcx>>,
322322

323323
/// Does this body use generic parameters. This is used for the `ConstEvaluatable` check.
324324
///
@@ -585,7 +585,7 @@ impl<'tcx> Body<'tcx> {
585585
&self,
586586
tcx: TyCtxt<'tcx>,
587587
param_env: ty::ParamEnv<'tcx>,
588-
normalize_const: impl Fn(ConstantKind<'tcx>) -> Result<ConstantKind<'tcx>, ErrorHandled>,
588+
normalize_const: impl Fn(ConstKind<'tcx>) -> Result<ConstKind<'tcx>, ErrorHandled>,
589589
) -> Result<(), ErrorHandled> {
590590
// For now, the only thing we have to check is is to ensure that all the constants used in
591591
// the body successfully evaluate.
@@ -1096,7 +1096,7 @@ impl<'tcx> LocalDecl<'tcx> {
10961096
pub enum VarDebugInfoContents<'tcx> {
10971097
/// This `Place` only contains projection which satisfy `can_use_in_debuginfo`.
10981098
Place(Place<'tcx>),
1099-
Const(Constant<'tcx>),
1099+
Const(Const<'tcx>),
11001100
}
11011101

11021102
impl<'tcx> Debug for VarDebugInfoContents<'tcx> {

0 commit comments

Comments
 (0)