Skip to content

Commit f7c4931

Browse files
committed
Reuse the Pointer type instead of passing reassembling it at many use sites
1 parent b2bf37a commit f7c4931

File tree

11 files changed

+20
-23
lines changed

11 files changed

+20
-23
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ impl_stable_hash_for!(
307307
impl<'tcx> for enum mir::interpret::ConstValue<'tcx> [ mir::interpret::ConstValue ] {
308308
Scalar(val),
309309
Slice(a, b),
310-
ByRef(id, alloc, offset),
310+
ByRef(ptr, alloc),
311311
}
312312
);
313313
impl_stable_hash_for!(struct crate::mir::interpret::RawConst<'tcx> {

src/librustc/mir/interpret/value.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ pub enum ConstValue<'tcx> {
3131
/// it.
3232
Slice(Scalar, u64),
3333

34-
/// An allocation together with an offset into the allocation.
35-
/// Invariant: the `AllocId` matches the allocation.
36-
ByRef(AllocId, &'tcx Allocation, Size),
34+
/// An allocation together with a pointer into the allocation.
35+
ByRef(Pointer, &'tcx Allocation),
3736
}
3837

3938
#[cfg(target_arch = "x86_64")]

src/librustc/ty/structural_impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,8 @@ impl<'a, 'tcx> Lift<'tcx> for ConstValue<'a> {
499499
match *self {
500500
ConstValue::Scalar(x) => Some(ConstValue::Scalar(x)),
501501
ConstValue::Slice(x, y) => Some(ConstValue::Slice(x, y)),
502-
ConstValue::ByRef(x, alloc, z) => Some(ConstValue::ByRef(
503-
x, alloc.lift_to_tcx(tcx)?, z,
502+
ConstValue::ByRef(ptr, alloc) => Some(ConstValue::ByRef(
503+
ptr, alloc.lift_to_tcx(tcx)?,
504504
)),
505505
}
506506
}

src/librustc_codegen_llvm/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn codegen_static_initializer(
7171
let static_ = cx.tcx.const_eval(param_env.and(cid))?;
7272

7373
let alloc = match static_.val {
74-
ConstValue::ByRef(_, alloc, n) if n.bytes() == 0 => alloc,
74+
ConstValue::ByRef(ptr, alloc) if ptr.offset.bytes() == 0 => alloc,
7575
_ => bug!("static const eval returned {:#?}", static_),
7676
};
7777
Ok((const_alloc_to_llvm(cx, alloc), alloc))

src/librustc_codegen_ssa/mir/operand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
101101
let b_llval = bx.cx().const_usize(b);
102102
OperandValue::Pair(a_llval, b_llval)
103103
},
104-
ConstValue::ByRef(_, alloc, offset) => {
105-
return Ok(bx.load_operand(bx.cx().from_const_alloc(layout, alloc, offset)));
104+
ConstValue::ByRef(ptr, alloc) => {
105+
return Ok(bx.load_operand(bx.cx().from_const_alloc(layout, alloc, ptr.offset)));
106106
},
107107
};
108108

src/librustc_codegen_ssa/mir/place.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,8 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
417417
let layout = cx.layout_of(self.monomorphize(&ty));
418418
match bx.tcx().const_eval(param_env.and(cid)) {
419419
Ok(val) => match val.val {
420-
mir::interpret::ConstValue::ByRef(_, alloc, offset) => {
421-
bx.cx().from_const_alloc(layout, alloc, offset)
420+
mir::interpret::ConstValue::ByRef(ptr, alloc) => {
421+
bx.cx().from_const_alloc(layout, alloc, ptr.offset)
422422
}
423423
_ => bug!("promoteds should have an allocation: {:?}", val),
424424
},

src/librustc_mir/const_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub fn op_to_const<'tcx>(
9696
// FIXME shouldn't it be the case that `mark_static_initialized` has already
9797
// interned this? I thought that is the entire point of that `FinishStatic` stuff?
9898
let alloc = ecx.tcx.intern_const_alloc(alloc);
99-
ConstValue::ByRef(ptr.alloc_id, alloc, ptr.offset)
99+
ConstValue::ByRef(ptr, alloc)
100100
},
101101
Ok(Immediate::Scalar(x)) =>
102102
ConstValue::Scalar(x.not_undef()?),

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ use rustc::ty::{self, Ty, TyCtxt, TypeFoldable, Const};
172172
use rustc::ty::layout::{Integer, IntegerExt, VariantIdx, Size};
173173

174174
use rustc::mir::Field;
175-
use rustc::mir::interpret::{ConstValue, Pointer, Scalar};
175+
use rustc::mir::interpret::{ConstValue, Scalar};
176176
use rustc::util::common::ErrorReported;
177177

178178
use syntax::attr::{SignedInt, UnsignedInt};
@@ -214,9 +214,8 @@ impl<'a, 'tcx> LiteralExpander<'a, 'tcx> {
214214
match (val, &crty.sty, &rty.sty) {
215215
// the easy case, deref a reference
216216
(ConstValue::Scalar(Scalar::Ptr(p)), x, y) if x == y => ConstValue::ByRef(
217-
p.alloc_id,
217+
p,
218218
self.tcx.alloc_map.lock().unwrap_memory(p.alloc_id),
219-
p.offset,
220219
),
221220
// unsize array to slice if pattern is array but match value or other patterns are slice
222221
(ConstValue::Scalar(Scalar::Ptr(p)), ty::Array(t, n), ty::Slice(u)) => {
@@ -1428,15 +1427,14 @@ fn slice_pat_covered_by_const<'tcx>(
14281427
suffix: &[Pattern<'tcx>]
14291428
) -> Result<bool, ErrorReported> {
14301429
let data: &[u8] = match (const_val.val, &const_val.ty.sty) {
1431-
(ConstValue::ByRef(id, alloc, offset), ty::Array(t, n)) => {
1430+
(ConstValue::ByRef(ptr, alloc), ty::Array(t, n)) => {
14321431
if *t != tcx.types.u8 {
14331432
// FIXME(oli-obk): can't mix const patterns with slice patterns and get
14341433
// any sort of exhaustiveness/unreachable check yet
14351434
// This solely means that we don't lint about unreachable patterns, even if some
14361435
// are definitely unreachable.
14371436
return Ok(false);
14381437
}
1439-
let ptr = Pointer::new(id, offset);
14401438
let n = n.assert_usize(tcx).unwrap();
14411439
alloc.get_bytes(&tcx, ptr, Size::from_bytes(n)).unwrap()
14421440
},
@@ -1778,8 +1776,8 @@ fn specialize<'p, 'a: 'p, 'tcx: 'a>(
17781776
let (opt_ptr, n, ty) = match value.ty.sty {
17791777
ty::TyKind::Array(t, n) => {
17801778
match value.val {
1781-
ConstValue::ByRef(id, alloc, offset) => (
1782-
Some((Pointer::new(id, offset), alloc)),
1779+
ConstValue::ByRef(ptr, alloc) => (
1780+
Some((ptr, alloc)),
17831781
n.unwrap_usize(cx.tcx),
17841782
t,
17851783
),

src/librustc_mir/interpret/operand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,11 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
591591
self.layout_of(ty)
592592
})?;
593593
let op = match val.val {
594-
ConstValue::ByRef(id, alloc, offset) => {
594+
ConstValue::ByRef(ptr, alloc) => {
595595
// We rely on mutability being set correctly in that allocation to prevent writes
596596
// where none should happen -- and for `static mut`, we copy on demand anyway.
597597
Operand::Indirect(
598-
MemPlace::from_ptr(Pointer::new(id, offset), alloc.align)
598+
MemPlace::from_ptr(ptr, alloc.align)
599599
).with_default_tag()
600600
},
601601
ConstValue::Slice(a, b) =>

src/librustc_mir/monomorphize/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ fn collect_const<'a, 'tcx>(
12571257
ConstValue::Slice(Scalar::Ptr(ptr), _) |
12581258
ConstValue::Scalar(Scalar::Ptr(ptr)) =>
12591259
collect_miri(tcx, ptr.alloc_id, output),
1260-
ConstValue::ByRef(_id, alloc, _offset) => {
1260+
ConstValue::ByRef(_ptr, alloc) => {
12611261
for &((), id) in alloc.relocations.values() {
12621262
collect_miri(tcx, id, output);
12631263
}

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt, id: DefId, span: Span) {
14641464
};
14651465
let param_env = ty::ParamEnv::reveal_all();
14661466
if let Ok(static_) = tcx.const_eval(param_env.and(cid)) {
1467-
let alloc = if let ConstValue::ByRef(_, allocation, _) = static_.val {
1467+
let alloc = if let ConstValue::ByRef(_, allocation) = static_.val {
14681468
allocation
14691469
} else {
14701470
bug!("Matching on non-ByRef static")

0 commit comments

Comments
 (0)