From fe19a014ffbafdb27b1fbb6bfec7ea41f553b3be Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Wed, 7 Dec 2016 20:58:48 -0800 Subject: [PATCH] Move lvalue data structures out of eval_context. --- src/eval_context.rs | 62 +------------------------------- src/lib.rs | 9 +++-- src/lvalue.rs | 69 ++++++++++++++++++++++++++++++++++++ src/step.rs | 3 +- src/terminator/intrinsics.rs | 3 +- src/terminator/mod.rs | 3 +- 6 files changed, 82 insertions(+), 67 deletions(-) create mode 100644 src/lvalue.rs diff --git a/src/eval_context.rs b/src/eval_context.rs index ab6bda12677..2605732d526 100644 --- a/src/eval_context.rs +++ b/src/eval_context.rs @@ -13,6 +13,7 @@ use rustc_data_structures::indexed_vec::Idx; use syntax::codemap::{self, DUMMY_SP}; use error::{EvalError, EvalResult}; +use lvalue::{Global, GlobalId, Lvalue, LvalueExtra}; use memory::{Memory, Pointer}; use primval::{self, PrimVal, PrimValKind}; @@ -96,67 +97,6 @@ pub struct Frame<'tcx> { pub stmt: usize, } -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub enum Lvalue<'tcx> { - /// An lvalue referring to a value allocated in the `Memory` system. - Ptr { - ptr: Pointer, - extra: LvalueExtra, - }, - - /// An lvalue referring to a value on the stack. Represented by a stack frame index paired with - /// a Mir local index. - Local { - frame: usize, - local: mir::Local, - }, - - Global(GlobalId<'tcx>), - - // TODO(solson): None/Never? -} - -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub enum LvalueExtra { - None, - Length(u64), - Vtable(Pointer), - DowncastVariant(usize), -} - -#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] -/// Uniquely identifies a specific constant or static -pub struct GlobalId<'tcx> { - /// the def id of the constant/static or in case of promoteds, the def id of the function they belong to - pub(super) def_id: DefId, - - /// In case of statics and constants this is `Substs::empty()`, so only promoteds and associated - /// constants actually have something useful here. We could special case statics and constants, - /// but that would only require more branching when working with constants, and not bring any - /// real benefits. - pub(super) substs: &'tcx Substs<'tcx>, - - /// The promoted index for this global, if it is a promoted. - pub(super) promoted: Option, -} - -#[derive(Copy, Clone, Debug)] -pub struct Global<'tcx> { - data: Option, - mutable: bool, - ty: Ty<'tcx>, -} - -impl<'tcx> Global<'tcx> { - pub(super) fn uninitialized(ty: Ty<'tcx>) -> Self { - Global { - data: None, - mutable: true, - ty: ty, - } - } -} - #[derive(Clone, Debug, Eq, PartialEq, Hash)] pub enum StackPopCleanup { /// The stackframe existed to compute the initial value of a static/constant, make sure it diff --git a/src/lib.rs b/src/lib.rs index a54839b4537..697c4ffa302 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,6 +25,7 @@ extern crate byteorder; mod cast; mod error; mod eval_context; +mod lvalue; mod memory; mod primval; mod step; @@ -32,7 +33,6 @@ mod terminator; mod value; mod vtable; - pub use error::{ EvalError, EvalResult, @@ -41,8 +41,6 @@ pub use error::{ pub use eval_context::{ EvalContext, Frame, - Lvalue, - LvalueExtra, ResourceLimits, StackPopCleanup, Value, @@ -50,6 +48,11 @@ pub use eval_context::{ run_mir_passes, }; +pub use lvalue::{ + Lvalue, + LvalueExtra, +}; + pub use memory::{ Memory, Pointer, diff --git a/src/lvalue.rs b/src/lvalue.rs new file mode 100644 index 00000000000..ad3de8a6f4f --- /dev/null +++ b/src/lvalue.rs @@ -0,0 +1,69 @@ +use rustc::hir::def_id::DefId; +use rustc::mir; +use rustc::ty::Ty; +use rustc::ty::subst::Substs; + +use memory::Pointer; +use eval_context::Value; + +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub enum Lvalue<'tcx> { + /// An lvalue referring to a value allocated in the `Memory` system. + Ptr { + ptr: Pointer, + extra: LvalueExtra, + }, + + /// An lvalue referring to a value on the stack. Represented by a stack frame index paired with + /// a Mir local index. + Local { + frame: usize, + local: mir::Local, + }, + + /// An lvalue referring to a global + Global(GlobalId<'tcx>), +} + +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub enum LvalueExtra { + None, + Length(u64), + Vtable(Pointer), + DowncastVariant(usize), +} + +/// Uniquely identifies a specific constant or static. +#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] +pub struct GlobalId<'tcx> { + /// For a constant or static, the `DefId` of the item itself. + /// For a promoted global, the `DefId` of the function they belong to. + pub(super) def_id: DefId, + + /// For statics and constants this is `Substs::empty()`, so only promoteds and associated + /// constants actually have something useful here. We could special case statics and constants, + /// but that would only require more branching when working with constants, and not bring any + /// real benefits. + pub(super) substs: &'tcx Substs<'tcx>, + + /// The index for promoted globals within their function's `Mir`. + pub(super) promoted: Option, +} + +#[derive(Copy, Clone, Debug)] +pub struct Global<'tcx> { + pub(super) data: Option, + pub(super) mutable: bool, + pub(super) ty: Ty<'tcx>, +} + +impl<'tcx> Global<'tcx> { + pub(super) fn uninitialized(ty: Ty<'tcx>) -> Self { + Global { + data: None, + mutable: true, + ty: ty, + } + } +} + diff --git a/src/step.rs b/src/step.rs index fba8e48731c..ddd6c40e4c7 100644 --- a/src/step.rs +++ b/src/step.rs @@ -11,7 +11,8 @@ use rustc::mir; use rustc::ty::{subst, self}; use error::{EvalResult, EvalError}; -use eval_context::{GlobalId, EvalContext, Lvalue, StackPopCleanup, Global, MirRef}; +use eval_context::{EvalContext, StackPopCleanup, MirRef}; +use lvalue::{Global, GlobalId, Lvalue}; use syntax::codemap::Span; impl<'a, 'tcx> EvalContext<'a, 'tcx> { diff --git a/src/terminator/intrinsics.rs b/src/terminator/intrinsics.rs index 75ca778d39c..9a2939001a1 100644 --- a/src/terminator/intrinsics.rs +++ b/src/terminator/intrinsics.rs @@ -5,7 +5,8 @@ use rustc::ty::subst::Substs; use rustc::ty::{self, Ty}; use error::{EvalError, EvalResult}; -use eval_context::{EvalContext, Lvalue, LvalueExtra}; +use eval_context::EvalContext; +use lvalue::{Lvalue, LvalueExtra}; use primval::{self, PrimVal, PrimValKind}; use value::Value; diff --git a/src/terminator/mod.rs b/src/terminator/mod.rs index d47166651c8..0f2484fa9f6 100644 --- a/src/terminator/mod.rs +++ b/src/terminator/mod.rs @@ -9,7 +9,8 @@ use syntax::codemap::{DUMMY_SP, Span}; use syntax::{ast, attr}; use error::{EvalError, EvalResult}; -use eval_context::{EvalContext, Lvalue, IntegerExt, StackPopCleanup, LvalueExtra, monomorphize_field_ty}; +use eval_context::{EvalContext, IntegerExt, StackPopCleanup, monomorphize_field_ty}; +use lvalue::{Lvalue, LvalueExtra}; use memory::Pointer; use primval::PrimVal; use value::Value;