Skip to content

Commit

Permalink
Rename lvalue to place
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Dec 6, 2017
1 parent bf26b96 commit dd630a2
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 49 deletions.
30 changes: 15 additions & 15 deletions miri/fn_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub trait EvalContextExt<'tcx> {
&mut self,
def_id: DefId,
args: &[ValTy<'tcx>],
dest: Lvalue,
dest: Place,
dest_ty: Ty<'tcx>,
dest_block: mir::BasicBlock,
) -> EvalResult<'tcx>;
Expand All @@ -31,7 +31,7 @@ pub trait EvalContextExt<'tcx> {
fn call_missing_fn(
&mut self,
instance: ty::Instance<'tcx>,
destination: Option<(Lvalue, mir::BasicBlock)>,
destination: Option<(Place, mir::BasicBlock)>,
args: &[ValTy<'tcx>],
sig: ty::FnSig<'tcx>,
path: String,
Expand All @@ -40,20 +40,20 @@ pub trait EvalContextExt<'tcx> {
fn eval_fn_call(
&mut self,
instance: ty::Instance<'tcx>,
destination: Option<(Lvalue, mir::BasicBlock)>,
destination: Option<(Place, mir::BasicBlock)>,
args: &[ValTy<'tcx>],
span: Span,
sig: ty::FnSig<'tcx>,
) -> EvalResult<'tcx, bool>;

fn write_null(&mut self, dest: Lvalue, dest_ty: Ty<'tcx>) -> EvalResult<'tcx>;
fn write_null(&mut self, dest: Place, dest_ty: Ty<'tcx>) -> EvalResult<'tcx>;
}

impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator> {
fn eval_fn_call(
&mut self,
instance: ty::Instance<'tcx>,
destination: Option<(Lvalue, mir::BasicBlock)>,
destination: Option<(Place, mir::BasicBlock)>,
args: &[ValTy<'tcx>],
span: Span,
sig: ty::FnSig<'tcx>,
Expand All @@ -75,16 +75,16 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
Err(other) => return Err(other),
};

let (return_lvalue, return_to_block) = match destination {
Some((lvalue, block)) => (lvalue, StackPopCleanup::Goto(block)),
None => (Lvalue::undef(), StackPopCleanup::None),
let (return_place, return_to_block) = match destination {
Some((place, block)) => (place, StackPopCleanup::Goto(block)),
None => (Place::undef(), StackPopCleanup::None),
};

self.push_stack_frame(
instance,
span,
mir,
return_lvalue,
return_place,
return_to_block,
)?;

Expand All @@ -95,7 +95,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
&mut self,
def_id: DefId,
args: &[ValTy<'tcx>],
dest: Lvalue,
dest: Place,
dest_ty: Ty<'tcx>,
dest_block: mir::BasicBlock,
) -> EvalResult<'tcx> {
Expand Down Expand Up @@ -176,7 +176,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
f_instance,
mir.span,
mir,
Lvalue::undef(),
Place::undef(),
StackPopCleanup::Goto(dest_block),
)?;
let mut args = self.frame().mir.args_iter();
Expand All @@ -187,7 +187,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
.to_owned(),
),
)?;
let arg_dest = self.eval_lvalue(&mir::Place::Local(arg_local))?;
let arg_dest = self.eval_place(&mir::Place::Local(arg_local))?;
self.write_ptr(arg_dest, data, u8_ptr_ty)?;

assert!(args.next().is_none(), "__rust_maybe_catch_panic argument has more arguments than expected");
Expand Down Expand Up @@ -416,7 +416,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
};

// Figure out how large a pthread TLS key actually is. This is libc::pthread_key_t.
let key_type = args[0].ty.builtin_deref(true, ty::LvaluePreference::NoPreference)
let key_type = args[0].ty.builtin_deref(true, ty::PlacePreference::NoPreference)
.ok_or(EvalErrorKind::AbiViolation("Wrong signature used for pthread_key_create: First argument must be a raw pointer.".to_owned()))?.ty;
let key_size = self.type_layout(key_type)?.size;

Expand Down Expand Up @@ -516,7 +516,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
fn call_missing_fn(
&mut self,
instance: ty::Instance<'tcx>,
destination: Option<(Lvalue, mir::BasicBlock)>,
destination: Option<(Place, mir::BasicBlock)>,
args: &[ValTy<'tcx>],
sig: ty::FnSig<'tcx>,
path: String,
Expand Down Expand Up @@ -655,7 +655,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
return Ok(());
}

fn write_null(&mut self, dest: Lvalue, dest_ty: Ty<'tcx>) -> EvalResult<'tcx> {
fn write_null(&mut self, dest: Place, dest_ty: Ty<'tcx>) -> EvalResult<'tcx> {
self.write_primval(dest, PrimVal::Bytes(0), dest_ty)
}
}
32 changes: 16 additions & 16 deletions miri/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rustc::traits::Reveal;
use rustc::ty::layout::TyLayout;
use rustc::ty;

use rustc::mir::interpret::{EvalResult, Lvalue, LvalueExtra, PrimVal, PrimValKind, Value, Pointer,
use rustc::mir::interpret::{EvalResult, Place, PlaceExtra, PrimVal, PrimValKind, Value, Pointer,
HasMemory, AccessKind, EvalContext, PtrAndAlign, ValTy};

use helpers::EvalContextExt as HelperEvalContextExt;
Expand All @@ -13,7 +13,7 @@ pub trait EvalContextExt<'tcx> {
&mut self,
instance: ty::Instance<'tcx>,
args: &[ValTy<'tcx>],
dest: Lvalue,
dest: Place,
dest_layout: TyLayout<'tcx>,
target: mir::BasicBlock,
) -> EvalResult<'tcx>;
Expand All @@ -24,7 +24,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
&mut self,
instance: ty::Instance<'tcx>,
args: &[ValTy<'tcx>],
dest: Lvalue,
dest: Place,
dest_layout: TyLayout<'tcx>,
target: mir::BasicBlock,
) -> EvalResult<'tcx> {
Expand Down Expand Up @@ -119,7 +119,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
};
self.write_primval(dest, old, ty)?;
self.write_primval(
Lvalue::from_primval_ptr(ptr),
Place::from_primval_ptr(ptr),
change,
ty,
)?;
Expand All @@ -143,7 +143,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
};
self.write_value(valty, dest)?;
self.write_primval(
Lvalue::from_primval_ptr(ptr),
Place::from_primval_ptr(ptr),
change,
ty,
)?;
Expand Down Expand Up @@ -196,7 +196,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
};
// FIXME: what do atomics do on overflow?
let (val, _) = self.binary_op(op, old, ty, change, ty)?;
self.write_primval(Lvalue::from_primval_ptr(ptr), val, ty)?;
self.write_primval(Place::from_primval_ptr(ptr), val, ty)?;
}

"breakpoint" => unimplemented!(), // halt miri
Expand Down Expand Up @@ -240,8 +240,8 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
"discriminant_value" => {
let ty = substs.type_at(0);
let adt_ptr = args[0].into_ptr(&self.memory)?;
let lval = Lvalue::from_primval_ptr(adt_ptr);
let discr_val = self.read_discriminant_value(lval, ty)?;
let place = Place::from_primval_ptr(adt_ptr);
let discr_val = self.read_discriminant_value(place, ty)?;
self.write_primval(dest, PrimVal::Bytes(discr_val), dest_layout.ty)?;
}

Expand Down Expand Up @@ -336,12 +336,12 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
Ok(zero_val)
};
match dest {
Lvalue::Local { frame, local } => self.modify_local(frame, local, init)?,
Lvalue::Ptr {
Place::Local { frame, local } => self.modify_local(frame, local, init)?,
Place::Ptr {
ptr: PtrAndAlign { ptr, aligned: true },
extra: LvalueExtra::None,
extra: PlaceExtra::None,
} => self.memory.write_repeat(ptr, 0, size)?,
Lvalue::Ptr { .. } => {
Place::Ptr { .. } => {
bug!("init intrinsic tried to write to fat or unaligned ptr target")
}
}
Expand Down Expand Up @@ -623,12 +623,12 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
_ => Ok(Value::ByVal(PrimVal::Undef)),
};
match dest {
Lvalue::Local { frame, local } => self.modify_local(frame, local, uninit)?,
Lvalue::Ptr {
Place::Local { frame, local } => self.modify_local(frame, local, uninit)?,
Place::Ptr {
ptr: PtrAndAlign { ptr, aligned: true },
extra: LvalueExtra::None,
extra: PlaceExtra::None,
} => self.memory.mark_definedness(ptr, size, false)?,
Lvalue::Ptr { .. } => {
Place::Ptr { .. } => {
bug!("uninit intrinsic tried to write to fat or unaligned ptr target")
}
}
Expand Down
20 changes: 10 additions & 10 deletions miri/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ pub fn eval_main<'a, 'tcx: 'a>(
start_instance,
start_mir.span,
start_mir,
Lvalue::from_ptr(ret_ptr),
Place::from_ptr(ret_ptr),
StackPopCleanup::None,
)?;

let mut args = ecx.frame().mir.args_iter();

// First argument: pointer to main()
let main_ptr = ecx.memory_mut().create_fn_alloc(main_instance);
let dest = ecx.eval_lvalue(&mir::Place::Local(args.next().unwrap()))?;
let dest = ecx.eval_place(&mir::Place::Local(args.next().unwrap()))?;
let main_ty = main_instance.def.def_ty(ecx.tcx);
let main_ptr_ty = ecx.tcx.mk_fn_ptr(main_ty.fn_sig(ecx.tcx));
ecx.write_value(
Expand All @@ -99,13 +99,13 @@ pub fn eval_main<'a, 'tcx: 'a>(
)?;

// Second argument (argc): 1
let dest = ecx.eval_lvalue(&mir::Place::Local(args.next().unwrap()))?;
let dest = ecx.eval_place(&mir::Place::Local(args.next().unwrap()))?;
let ty = ecx.tcx.types.isize;
ecx.write_primval(dest, PrimVal::Bytes(1), ty)?;

// FIXME: extract main source file path
// Third argument (argv): &[b"foo"]
let dest = ecx.eval_lvalue(&mir::Place::Local(args.next().unwrap()))?;
let dest = ecx.eval_place(&mir::Place::Local(args.next().unwrap()))?;
let ty = ecx.tcx.mk_imm_ptr(ecx.tcx.mk_imm_ptr(ecx.tcx.types.u8));
let foo = ecx.memory.allocate_cached(b"foo\0");
let ptr_size = ecx.memory.pointer_size();
Expand All @@ -120,7 +120,7 @@ pub fn eval_main<'a, 'tcx: 'a>(
main_instance,
main_mir.span,
main_mir,
Lvalue::undef(),
Place::undef(),
StackPopCleanup::None,
)?;

Expand Down Expand Up @@ -195,7 +195,7 @@ impl<'tcx> Machine<'tcx> for Evaluator {
fn eval_fn_call<'a>(
ecx: &mut EvalContext<'a, 'tcx, Self>,
instance: ty::Instance<'tcx>,
destination: Option<(Lvalue, mir::BasicBlock)>,
destination: Option<(Place, mir::BasicBlock)>,
args: &[ValTy<'tcx>],
span: Span,
sig: ty::FnSig<'tcx>,
Expand All @@ -207,7 +207,7 @@ impl<'tcx> Machine<'tcx> for Evaluator {
ecx: &mut rustc::mir::interpret::EvalContext<'a, 'tcx, Self>,
instance: ty::Instance<'tcx>,
args: &[ValTy<'tcx>],
dest: Lvalue,
dest: Place,
dest_layout: TyLayout<'tcx>,
target: mir::BasicBlock,
) -> EvalResult<'tcx> {
Expand Down Expand Up @@ -237,7 +237,7 @@ impl<'tcx> Machine<'tcx> for Evaluator {
fn box_alloc<'a>(
ecx: &mut EvalContext<'a, 'tcx, Self>,
ty: ty::Ty<'tcx>,
dest: Lvalue,
dest: Place,
) -> EvalResult<'tcx> {
let size = ecx.type_size(ty)?.expect("box only works with sized types");
let align = ecx.type_align(ty)?;
Expand All @@ -261,7 +261,7 @@ impl<'tcx> Machine<'tcx> for Evaluator {
let usize = ecx.tcx.types.usize;

// First argument: size
let dest = ecx.eval_lvalue(&mir::Place::Local(args.next().unwrap()))?;
let dest = ecx.eval_place(&mir::Place::Local(args.next().unwrap()))?;
ecx.write_value(
ValTy {
value: Value::ByVal(PrimVal::Bytes(size as u128)),
Expand All @@ -271,7 +271,7 @@ impl<'tcx> Machine<'tcx> for Evaluator {
)?;

// Second argument: align
let dest = ecx.eval_lvalue(&mir::Place::Local(args.next().unwrap()))?;
let dest = ecx.eval_place(&mir::Place::Local(args.next().unwrap()))?;
ecx.write_value(
ValTy {
value: Value::ByVal(PrimVal::Bytes(align as u128)),
Expand Down
6 changes: 3 additions & 3 deletions miri/tls.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc::{ty, mir};

use super::{TlsKey, TlsEntry, EvalResult, EvalErrorKind, Pointer, Memory, Evaluator, Lvalue,
use super::{TlsKey, TlsEntry, EvalResult, EvalErrorKind, Pointer, Memory, Evaluator, Place,
StackPopCleanup, EvalContext};

pub trait MemoryExt<'tcx> {
Expand Down Expand Up @@ -119,13 +119,13 @@ impl<'a, 'tcx: 'a> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, Evaluator> {
instance,
mir.span,
mir,
Lvalue::undef(),
Place::undef(),
StackPopCleanup::None,
)?;
let arg_local = self.frame().mir.args_iter().next().ok_or(
EvalErrorKind::AbiViolation("TLS dtor does not take enough arguments.".to_owned()),
)?;
let dest = self.eval_lvalue(&mir::Place::Local(arg_local))?;
let dest = self.eval_place(&mir::Place::Local(arg_local))?;
let ty = self.tcx.mk_mut_ptr(self.tcx.types.u8);
self.write_ptr(dest, ptr, ty)?;

Expand Down
10 changes: 5 additions & 5 deletions tex/report/miri-report.tex
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ \section{Background}
The Rust compiler generates an instance of \rust{Mir} for each function [\autoref{fig:mir}]. Each
\rust{Mir} structure represents a control-flow graph for a given function, and contains a list of
``basic blocks'' which in turn contain a list of statements followed by a single terminator. Each
statement is of the form \rust{lvalue = rvalue}. An \rust{Lvalue} is used for referencing variables
statement is of the form \rust{place = rvalue}. An \rust{Place} is used for referencing variables
and calculating addresses such as when dereferencing pointers, accessing fields, or indexing arrays.
An \rust{Rvalue} represents the core set of operations possible in MIR, including reading a value
from an lvalue, performing math operations, creating new pointers, structures, and arrays, and so
from an place, performing math operations, creating new pointers, structures, and arrays, and so
on. Finally, a terminator decides where control will flow next, optionally based on the value of a
boolean or integer.

Expand All @@ -73,7 +73,7 @@ \section{Background}
}

struct Statement {
lvalue: Lvalue,
place: Place,
rvalue: Rvalue
}

Expand All @@ -99,7 +99,7 @@ \subsection{Basic operation}
To investigate the possibility of executing Rust at compile-time I wrote an interpreter for MIR
called Miri\footnote{\url{https://github.com/solson/miri}}. The structure of the interpreter closely
mirrors the structure of MIR itself. It starts executing a function by iterating the statement list
in the starting basic block, translating the lvalue into a pointer and using the rvalue to decide
in the starting basic block, translating the place into a pointer and using the rvalue to decide
what to write into that pointer. Evaluating the rvalue may involve reads (such as for the two sides
of a binary operation) or construction of new values. When the terminator is reached, it is used to
decide which basic block to jump to next. Finally, Miri repeats this entire process, reading
Expand Down Expand Up @@ -343,7 +343,7 @@ \subsection{Aggregates}
closures. Miri supports all common usage of all of these types. The main missing piece is to handle
\texttt{\#[repr(..)]} annotations which adjust the layout of a \rust{struct} or \rust{enum}.

\subsection{Lvalue projections}
\subsection{Place projections}

This category includes field accesses, dereferencing, accessing data in an \rust{enum} variant, and
indexing arrays. Miri supports all of these, including nested projections such as
Expand Down

0 comments on commit dd630a2

Please sign in to comment.