Skip to content

Commit 8ad28cd

Browse files
committed
Machine: make self-like parameters come first
1 parent b43eb42 commit 8ad28cd

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/librustc_mir/const_eval.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc::hir::def::DefKind;
1111
use rustc::hir::def_id::DefId;
1212
use rustc::mir::interpret::{ConstEvalErr, ErrorHandled, ScalarMaybeUndef};
1313
use rustc::mir;
14-
use rustc::ty::{self, TyCtxt, query::TyCtxtAt};
14+
use rustc::ty::{self, TyCtxt};
1515
use rustc::ty::layout::{self, LayoutOf, VariantIdx};
1616
use rustc::ty::subst::Subst;
1717
use rustc::traits::Reveal;
@@ -398,27 +398,27 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
398398
}
399399

400400
fn find_foreign_static(
401+
_tcx: TyCtxt<'tcx>,
401402
_def_id: DefId,
402-
_tcx: TyCtxtAt<'tcx>,
403403
) -> InterpResult<'tcx, Cow<'tcx, Allocation<Self::PointerTag>>> {
404404
err!(ReadForeignStatic)
405405
}
406406

407407
#[inline(always)]
408408
fn tag_allocation<'b>(
409+
_memory: &Memory<'mir, 'tcx, Self>,
409410
_id: AllocId,
410411
alloc: Cow<'b, Allocation>,
411412
_kind: Option<MemoryKind<!>>,
412-
_memory: &Memory<'mir, 'tcx, Self>,
413413
) -> (Cow<'b, Allocation<Self::PointerTag>>, Self::PointerTag) {
414414
// We do not use a tag so we can just cheaply forward the allocation
415415
(alloc, ())
416416
}
417417

418418
#[inline(always)]
419419
fn tag_static_base_pointer(
420-
_id: AllocId,
421420
_memory: &Memory<'mir, 'tcx, Self>,
421+
_id: AllocId,
422422
) -> Self::PointerTag {
423423
()
424424
}

src/librustc_mir/interpret/machine.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::hash::Hash;
77

88
use rustc::hir::def_id::DefId;
99
use rustc::mir;
10-
use rustc::ty::{self, query::TyCtxtAt};
10+
use rustc::ty::{self, TyCtxt};
1111

1212
use super::{
1313
Allocation, AllocId, InterpResult, Scalar, AllocationExtra,
@@ -136,8 +136,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
136136
///
137137
/// This allocation will then be fed to `tag_allocation` to initialize the "extra" state.
138138
fn find_foreign_static(
139+
tcx: TyCtxt<'tcx>,
139140
def_id: DefId,
140-
tcx: TyCtxtAt<'tcx>,
141141
) -> InterpResult<'tcx, Cow<'tcx, Allocation>>;
142142

143143
/// Called for all binary operations on integer(-like) types when one operand is a pointer
@@ -174,10 +174,10 @@ pub trait Machine<'mir, 'tcx>: Sized {
174174
/// For static allocations, the tag returned must be the same as the one returned by
175175
/// `tag_static_base_pointer`.
176176
fn tag_allocation<'b>(
177+
memory: &Memory<'mir, 'tcx, Self>,
177178
id: AllocId,
178179
alloc: Cow<'b, Allocation>,
179180
kind: Option<MemoryKind<Self::MemoryKinds>>,
180-
memory: &Memory<'mir, 'tcx, Self>,
181181
) -> (Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>, Self::PointerTag);
182182

183183
/// Return the "base" tag for the given static allocation: the one that is used for direct
@@ -186,8 +186,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
186186
/// Be aware that requesting the `Allocation` for that `id` will lead to cycles
187187
/// for cyclic statics!
188188
fn tag_static_base_pointer(
189-
id: AllocId,
190189
memory: &Memory<'mir, 'tcx, Self>,
190+
id: AllocId,
191191
) -> Self::PointerTag;
192192

193193
/// Executes a retagging operation
@@ -210,8 +210,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
210210
) -> InterpResult<'tcx>;
211211

212212
fn int_to_ptr(
213-
int: u64,
214213
_mem: &Memory<'mir, 'tcx, Self>,
214+
int: u64,
215215
) -> InterpResult<'tcx, Pointer<Self::PointerTag>> {
216216
if int == 0 {
217217
err!(InvalidNullPointerUsage)
@@ -221,8 +221,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
221221
}
222222

223223
fn ptr_to_int(
224-
_ptr: Pointer<Self::PointerTag>,
225224
_mem: &Memory<'mir, 'tcx, Self>,
225+
_ptr: Pointer<Self::PointerTag>,
226226
) -> InterpResult<'tcx, u64> {
227227
err!(ReadPointerAsBytes)
228228
}

src/librustc_mir/interpret/memory.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
117117

118118
#[inline]
119119
pub fn tag_static_base_pointer(&self, ptr: Pointer) -> Pointer<M::PointerTag> {
120-
ptr.with_tag(M::tag_static_base_pointer(ptr.alloc_id, &self))
120+
ptr.with_tag(M::tag_static_base_pointer(&self, ptr.alloc_id))
121121
}
122122

123123
pub fn create_fn_alloc(&mut self, instance: Instance<'tcx>) -> Pointer<M::PointerTag> {
@@ -150,7 +150,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
150150
kind: MemoryKind<M::MemoryKinds>,
151151
) -> Pointer<M::PointerTag> {
152152
let id = self.tcx.alloc_map.lock().reserve();
153-
let (alloc, tag) = M::tag_allocation(id, Cow::Owned(alloc), Some(kind), &self);
153+
let (alloc, tag) = M::tag_allocation(&self, id, Cow::Owned(alloc), Some(kind));
154154
self.alloc_map.insert(id, (kind, alloc.into_owned()));
155155
Pointer::from(id).with_tag(tag)
156156
}
@@ -384,7 +384,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
384384
// We got a "lazy" static that has not been computed yet.
385385
if tcx.is_foreign_item(def_id) {
386386
trace!("static_alloc: foreign item {:?}", def_id);
387-
M::find_foreign_static(def_id, tcx)?
387+
M::find_foreign_static(tcx.tcx, def_id)?
388388
} else {
389389
trace!("static_alloc: Need to compute {:?}", def_id);
390390
let instance = Instance::mono(tcx.tcx, def_id);
@@ -414,10 +414,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
414414
// We got tcx memory. Let the machine figure out whether and how to
415415
// turn that into memory with the right pointer tag.
416416
Ok(M::tag_allocation(
417+
memory,
417418
id, // always use the ID we got as input, not the "hidden" one.
418419
alloc,
419420
M::STATIC_KIND.map(MemoryKind::Machine),
420-
memory
421421
).0)
422422
}
423423

@@ -890,7 +890,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
890890
) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
891891
match scalar {
892892
Scalar::Ptr(ptr) => Ok(ptr),
893-
_ => M::int_to_ptr(scalar.to_usize(self)?, self)
893+
_ => M::int_to_ptr(&self, scalar.to_usize(self)?)
894894
}
895895
}
896896

@@ -901,7 +901,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
901901
) -> InterpResult<'tcx, u128> {
902902
match scalar.to_bits_or_ptr(size, self) {
903903
Ok(bits) => Ok(bits),
904-
Err(ptr) => Ok(M::ptr_to_int(ptr, self)? as u128)
904+
Err(ptr) => Ok(M::ptr_to_int(&self, ptr)? as u128)
905905
}
906906
}
907907
}

0 commit comments

Comments
 (0)