Skip to content

Commit dc9583b

Browse files
committed
rename ConstValue::ByRef → Indirect
1 parent 50ad68a commit dc9583b

File tree

14 files changed

+21
-19
lines changed

14 files changed

+21
-19
lines changed

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ pub(crate) fn codegen_const_value<'tcx>(
222222
CValue::by_val(val, layout)
223223
}
224224
},
225-
ConstValue::ByRef { alloc_id, offset } => {
225+
ConstValue::Indirect { alloc_id, offset } => {
226226
let alloc = fx.tcx.global_alloc(alloc_id).unwrap_memory();
227227
// FIXME: avoid creating multiple allocations for the same AllocId?
228228
CValue::by_ref(

compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
172172
.expect("simd_shuffle idx not const");
173173

174174
let idx_bytes = match idx_const {
175-
ConstValue::ByRef { alloc_id, offset } => {
175+
ConstValue::Indirect { alloc_id, offset } => {
176176
let alloc = fx.tcx.global_alloc(alloc_id).unwrap_memory();
177177
let size = Size::from_bytes(
178178
4 * ret_lane_count, /* size_of([u32; ret_lane_count]) */

compiler/rustc_codegen_ssa/src/mir/operand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
116116
let b_llval = bx.const_usize((end - start) as u64);
117117
OperandValue::Pair(a_llval, b_llval)
118118
}
119-
ConstValue::ByRef { alloc_id, offset } => {
119+
ConstValue::Indirect { alloc_id, offset } => {
120120
let alloc = bx.tcx().global_alloc(alloc_id).unwrap_memory();
121121
// FIXME: should we attempt to avoid building the same AllocId multiple times?
122122
return Self::from_const_alloc(bx, layout, alloc, offset);

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub(super) fn op_to_const<'tcx>(
148148
let to_const_value = |mplace: &MPlaceTy<'_>| {
149149
debug!("to_const_value(mplace: {:?})", mplace);
150150
match mplace.ptr().into_parts() {
151-
(Some(alloc_id), offset) => ConstValue::ByRef { alloc_id, offset },
151+
(Some(alloc_id), offset) => ConstValue::Indirect { alloc_id, offset },
152152
(None, offset) => {
153153
assert!(mplace.layout.is_zst());
154154
assert_eq!(

compiler/rustc_const_eval/src/interpret/operand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
756756
};
757757
let layout = from_known_layout(self.tcx, self.param_env, layout, || self.layout_of(ty))?;
758758
let op = match val_val {
759-
ConstValue::ByRef { alloc_id, offset } => {
759+
ConstValue::Indirect { alloc_id, offset } => {
760760
// We rely on mutability being set correctly in that allocation to prevent writes
761761
// where none should happen.
762762
let ptr = self.global_base_pointer(Pointer::new(alloc_id, offset))?;

compiler/rustc_middle/src/mir/interpret/value.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ pub enum ConstValue<'tcx> {
3838
/// Only used for ZSTs.
3939
ZeroSized,
4040

41-
/// Used only for `&[u8]` and `&str`
41+
/// Used only for `&[u8]` and `&str`.
42+
///
43+
/// This is worth the optimization since Rust has literals of that type.
4244
Slice { data: ConstAllocation<'tcx>, start: usize, end: usize },
4345

44-
/// A value not represented/representable by `Scalar` or `Slice`
45-
ByRef {
46+
/// A value not represented/representable by the other variants, needs to be stored in-memory.
47+
Indirect {
4648
/// The backing memory of the value. May contain more memory than needed for just the value
4749
/// if this points into some other larger ConstValue.
4850
///
@@ -62,7 +64,7 @@ impl<'tcx> ConstValue<'tcx> {
6264
#[inline]
6365
pub fn try_to_scalar(&self) -> Option<Scalar<AllocId>> {
6466
match *self {
65-
ConstValue::ByRef { .. } | ConstValue::Slice { .. } | ConstValue::ZeroSized => None,
67+
ConstValue::Indirect { .. } | ConstValue::Slice { .. } | ConstValue::ZeroSized => None,
6668
ConstValue::Scalar(val) => Some(val),
6769
}
6870
}

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2883,7 +2883,7 @@ fn pretty_print_const_value<'tcx>(
28832883
_ => {}
28842884
}
28852885
}
2886-
(ConstValue::ByRef { alloc_id, offset }, ty::Array(t, n)) if *t == u8_type => {
2886+
(ConstValue::Indirect { alloc_id, offset }, ty::Array(t, n)) if *t == u8_type => {
28872887
let n = n.try_to_bits(tcx.data_layout.pointer_size).unwrap();
28882888
let alloc = tcx.global_alloc(alloc_id).unwrap_memory();
28892889
// cast is ok because we already checked for pointer size (32 or 64 bit) above

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
460460
ConstValue::ZeroSized => "<ZST>".to_string(),
461461
ConstValue::Scalar(s) => format!("Scalar({s:?})"),
462462
ConstValue::Slice { .. } => "Slice(..)".to_string(),
463-
ConstValue::ByRef { .. } => "ByRef(..)".to_string(),
463+
ConstValue::Indirect { .. } => "ByRef(..)".to_string(),
464464
};
465465

466466
let fmt_valtree = |valtree: &ty::ValTree<'tcx>| match valtree {
@@ -708,7 +708,7 @@ pub fn write_allocations<'tcx>(
708708
}
709709
ConstValue::ZeroSized => Either::Left(Either::Right(std::iter::empty())),
710710
ConstValue::Slice { data, .. } => Either::Right(alloc_ids_from_alloc(data)),
711-
ConstValue::ByRef { alloc_id, .. } => {
711+
ConstValue::Indirect { alloc_id, .. } => {
712712
Either::Left(Either::Left(std::iter::once(alloc_id)))
713713
}
714714
}

compiler/rustc_mir_transform/src/const_prop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
152152
#[inline(always)]
153153
fn enforce_alignment(_ecx: &InterpCx<'mir, 'tcx, Self>) -> CheckAlignment {
154154
// We do not check for alignment to avoid having to carry an `Align`
155-
// in `ConstValue::ByRef`.
155+
// in `ConstValue::Indirect`.
156156
CheckAlignment::No
157157
}
158158

@@ -578,7 +578,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
578578
.ok()?;
579579

580580
let literal = ConstantKind::Val(
581-
ConstValue::ByRef { alloc_id, offset: Size::ZERO },
581+
ConstValue::Indirect { alloc_id, offset: Size::ZERO },
582582
value.layout.ty,
583583
);
584584
Some(Operand::Constant(Box::new(Constant {

compiler/rustc_mir_transform/src/large_enums.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl EnumSizeOpt {
153153
span,
154154
user_ty: None,
155155
literal: ConstantKind::Val(
156-
interpret::ConstValue::ByRef { alloc_id, offset: Size::ZERO },
156+
interpret::ConstValue::Indirect { alloc_id, offset: Size::ZERO },
157157
tmp_ty,
158158
),
159159
};

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,7 @@ fn collect_const_value<'tcx>(
14701470
) {
14711471
match value {
14721472
ConstValue::Scalar(Scalar::Ptr(ptr, _size)) => collect_alloc(tcx, ptr.provenance, output),
1473-
ConstValue::ByRef { alloc_id, .. } => collect_alloc(tcx, alloc_id, output),
1473+
ConstValue::Indirect { alloc_id, .. } => collect_alloc(tcx, alloc_id, output),
14741474
ConstValue::Slice { data, start: _, end: _ } => {
14751475
for &id in data.inner().provenance().ptrs().values() {
14761476
collect_alloc(tcx, id, output);

compiler/rustc_smir/src/rustc_smir/alloc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub fn new_allocation<'tcx>(
7272
.unwrap();
7373
allocation.stable(tables)
7474
}
75-
ConstValue::ByRef { alloc_id, offset } => {
75+
ConstValue::Indirect { alloc_id, offset } => {
7676
let alloc = tables.tcx.global_alloc(alloc_id).unwrap_memory();
7777
let ty_size = tables
7878
.tcx

src/tools/clippy/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ fn path_to_matched_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option<Ve
232232
cx.tcx.type_of(def_id).instantiate_identity(),
233233
),
234234
Res::Def(DefKind::Const, def_id) => match cx.tcx.const_eval_poly(def_id).ok()? {
235-
ConstValue::ByRef { alloc, offset } if offset.bytes() == 0 => {
235+
ConstValue::Indirect { alloc, offset } if offset.bytes() == 0 => {
236236
read_mir_alloc_def_path(cx, alloc.inner(), cx.tcx.type_of(def_id).instantiate_identity())
237237
},
238238
_ => None,

src/tools/clippy/clippy_utils/src/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ pub fn miri_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::ConstantKind<'t
684684
},
685685
_ => None,
686686
},
687-
mir::ConstantKind::Val(ConstValue::ByRef { alloc_id, offset: _ }, _) => {
687+
mir::ConstantKind::Val(ConstValue::Indirect { alloc_id, offset: _ }, _) => {
688688
let alloc = lcx.tcx.global_alloc(alloc_id).unwrap_memory();
689689
match result.ty().kind() {
690690
ty::Adt(adt_def, _) if adt_def.is_struct() => Some(Constant::Adt(result)),

0 commit comments

Comments
 (0)