rename statics/Constant/ConstantId/ConstantKind to [gG]lobal*
This commit is contained in:
parent
f6bbea0f08
commit
d3b3c56b07
2 changed files with 34 additions and 34 deletions
|
@ -41,7 +41,7 @@ pub struct EvalContext<'a, 'tcx: 'a> {
|
||||||
memory: Memory<'a, 'tcx>,
|
memory: Memory<'a, 'tcx>,
|
||||||
|
|
||||||
/// Precomputed statics, constants and promoteds.
|
/// Precomputed statics, constants and promoteds.
|
||||||
statics: HashMap<ConstantId<'tcx>, Constant<'tcx>>,
|
globals: HashMap<GlobalId<'tcx>, Global<'tcx>>,
|
||||||
|
|
||||||
/// The virtual call stack.
|
/// The virtual call stack.
|
||||||
stack: Vec<Frame<'a, 'tcx>>,
|
stack: Vec<Frame<'a, 'tcx>>,
|
||||||
|
@ -112,7 +112,7 @@ pub enum Lvalue<'tcx> {
|
||||||
local: mir::Local,
|
local: mir::Local,
|
||||||
},
|
},
|
||||||
|
|
||||||
Static(ConstantId<'tcx>),
|
Static(GlobalId<'tcx>),
|
||||||
|
|
||||||
// TODO(solson): None/Never?
|
// TODO(solson): None/Never?
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ pub enum CachedMir<'mir, 'tcx: 'mir> {
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||||
/// Uniquely identifies a specific constant or static
|
/// Uniquely identifies a specific constant or static
|
||||||
pub struct ConstantId<'tcx> {
|
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
|
/// the def id of the constant/static or in case of promoteds, the def id of the function they belong to
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
/// In case of statics and constants this is `Substs::empty()`, so only promoteds and associated
|
/// In case of statics and constants this is `Substs::empty()`, so only promoteds and associated
|
||||||
|
@ -141,26 +141,26 @@ pub struct ConstantId<'tcx> {
|
||||||
/// but that would only require more branching when working with constants, and not bring any
|
/// but that would only require more branching when working with constants, and not bring any
|
||||||
/// real benefits.
|
/// real benefits.
|
||||||
substs: &'tcx Substs<'tcx>,
|
substs: &'tcx Substs<'tcx>,
|
||||||
kind: ConstantKind,
|
kind: GlobalKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||||
enum ConstantKind {
|
enum GlobalKind {
|
||||||
Promoted(mir::Promoted),
|
Promoted(mir::Promoted),
|
||||||
/// Statics, constants and associated constants
|
/// Statics, constants and associated constants
|
||||||
Global,
|
Global,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub struct Constant<'tcx> {
|
pub struct Global<'tcx> {
|
||||||
data: Option<Value>,
|
data: Option<Value>,
|
||||||
mutable: bool,
|
mutable: bool,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Constant<'tcx> {
|
impl<'tcx> Global<'tcx> {
|
||||||
fn uninitialized(ty: Ty<'tcx>) -> Self {
|
fn uninitialized(ty: Ty<'tcx>) -> Self {
|
||||||
Constant {
|
Global {
|
||||||
data: None,
|
data: None,
|
||||||
mutable: true,
|
mutable: true,
|
||||||
ty: ty,
|
ty: ty,
|
||||||
|
@ -188,7 +188,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
mir_map: mir_map,
|
mir_map: mir_map,
|
||||||
mir_cache: RefCell::new(DefIdMap()),
|
mir_cache: RefCell::new(DefIdMap()),
|
||||||
memory: Memory::new(&tcx.data_layout, memory_size),
|
memory: Memory::new(&tcx.data_layout, memory_size),
|
||||||
statics: HashMap::new(),
|
globals: HashMap::new(),
|
||||||
stack: Vec::new(),
|
stack: Vec::new(),
|
||||||
stack_limit: stack_limit,
|
stack_limit: stack_limit,
|
||||||
}
|
}
|
||||||
|
@ -400,7 +400,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
let frame = self.stack.pop().expect("tried to pop a stack frame, but there were none");
|
let frame = self.stack.pop().expect("tried to pop a stack frame, but there were none");
|
||||||
match frame.return_to_block {
|
match frame.return_to_block {
|
||||||
StackPopCleanup::Freeze => if let Lvalue::Static(id) = frame.return_lvalue {
|
StackPopCleanup::Freeze => if let Lvalue::Static(id) = frame.return_lvalue {
|
||||||
let static_value = self.statics
|
let static_value = self.globals
|
||||||
.get_mut(&id)
|
.get_mut(&id)
|
||||||
.expect("static should have been cached (freeze)");
|
.expect("static should have been cached (freeze)");
|
||||||
if let Value::ByRef(ptr) = static_value.data.expect("static should have been initialized") {
|
if let Value::ByRef(ptr) = static_value.data.expect("static should have been initialized") {
|
||||||
|
@ -842,20 +842,20 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
// function items are zero sized
|
// function items are zero sized
|
||||||
Value::ByRef(self.memory.allocate(0, 0)?)
|
Value::ByRef(self.memory.allocate(0, 0)?)
|
||||||
} else {
|
} else {
|
||||||
let cid = ConstantId {
|
let cid = GlobalId {
|
||||||
def_id: def_id,
|
def_id: def_id,
|
||||||
substs: substs,
|
substs: substs,
|
||||||
kind: ConstantKind::Global,
|
kind: GlobalKind::Global,
|
||||||
};
|
};
|
||||||
self.read_lvalue(Lvalue::Static(cid))?
|
self.read_lvalue(Lvalue::Static(cid))?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Literal::Promoted { index } => {
|
Literal::Promoted { index } => {
|
||||||
let cid = ConstantId {
|
let cid = GlobalId {
|
||||||
def_id: self.frame().def_id,
|
def_id: self.frame().def_id,
|
||||||
substs: self.substs(),
|
substs: self.substs(),
|
||||||
kind: ConstantKind::Promoted(index),
|
kind: GlobalKind::Promoted(index),
|
||||||
};
|
};
|
||||||
self.read_lvalue(Lvalue::Static(cid))?
|
self.read_lvalue(Lvalue::Static(cid))?
|
||||||
}
|
}
|
||||||
|
@ -890,7 +890,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
Lvalue::Local { frame, local } => {
|
Lvalue::Local { frame, local } => {
|
||||||
self.stack[frame].get_local(local).ok_or(EvalError::ReadUndefBytes)
|
self.stack[frame].get_local(local).ok_or(EvalError::ReadUndefBytes)
|
||||||
}
|
}
|
||||||
Lvalue::Static(cid) => self.statics
|
Lvalue::Static(cid) => self.globals
|
||||||
.get(&cid)
|
.get(&cid)
|
||||||
.expect("static not cached")
|
.expect("static not cached")
|
||||||
.data
|
.data
|
||||||
|
@ -912,10 +912,10 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
|
|
||||||
Static(def_id) => {
|
Static(def_id) => {
|
||||||
let substs = subst::Substs::empty(self.tcx);
|
let substs = subst::Substs::empty(self.tcx);
|
||||||
let cid = ConstantId {
|
let cid = GlobalId {
|
||||||
def_id: def_id,
|
def_id: def_id,
|
||||||
substs: substs,
|
substs: substs,
|
||||||
kind: ConstantKind::Global,
|
kind: GlobalKind::Global,
|
||||||
};
|
};
|
||||||
Lvalue::Static(cid)
|
Lvalue::Static(cid)
|
||||||
}
|
}
|
||||||
|
@ -1123,7 +1123,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
Lvalue::Ptr { .. } => lvalue,
|
Lvalue::Ptr { .. } => lvalue,
|
||||||
Lvalue::Static(cid) => {
|
Lvalue::Static(cid) => {
|
||||||
let static_val = *self.statics.get(&cid).expect("static not cached");
|
let static_val = *self.globals.get(&cid).expect("static not cached");
|
||||||
match static_val.data {
|
match static_val.data {
|
||||||
Some(Value::ByRef(ptr)) => Lvalue::from_ptr(ptr),
|
Some(Value::ByRef(ptr)) => Lvalue::from_ptr(ptr),
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -1134,8 +1134,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
if !static_val.mutable {
|
if !static_val.mutable {
|
||||||
self.memory.freeze(ptr.alloc_id)?;
|
self.memory.freeze(ptr.alloc_id)?;
|
||||||
}
|
}
|
||||||
let lval = self.statics.get_mut(&cid).expect("already checked");
|
let lval = self.globals.get_mut(&cid).expect("already checked");
|
||||||
*lval = Constant {
|
*lval = Global {
|
||||||
data: Some(Value::ByRef(ptr)),
|
data: Some(Value::ByRef(ptr)),
|
||||||
.. static_val
|
.. static_val
|
||||||
};
|
};
|
||||||
|
@ -1223,7 +1223,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Lvalue::Static(cid) => {
|
Lvalue::Static(cid) => {
|
||||||
let static_val = self.statics.get_mut(&cid).expect("static not cached");
|
let static_val = self.globals.get_mut(&cid).expect("static not cached");
|
||||||
assert!(static_val.mutable);
|
assert!(static_val.mutable);
|
||||||
static_val.data = Some(Value::ByVal(val));
|
static_val.data = Some(Value::ByVal(val));
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1239,11 +1239,11 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||||
) -> EvalResult<'tcx, ()> {
|
) -> EvalResult<'tcx, ()> {
|
||||||
match dest {
|
match dest {
|
||||||
Lvalue::Static(cid) => {
|
Lvalue::Static(cid) => {
|
||||||
let dest = *self.statics.get_mut(&cid).expect("static should be cached");
|
let dest = *self.globals.get_mut(&cid).expect("static should be cached");
|
||||||
assert!(dest.mutable);
|
assert!(dest.mutable);
|
||||||
self.write_value_possibly_by_val(
|
self.write_value_possibly_by_val(
|
||||||
src_val,
|
src_val,
|
||||||
|this, val| *this.statics.get_mut(&cid).expect("already checked") = Constant { data: Some(val), ..dest },
|
|this, val| *this.globals.get_mut(&cid).expect("already checked") = Global { data: Some(val), ..dest },
|
||||||
dest.data,
|
dest.data,
|
||||||
dest_ty,
|
dest_ty,
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,12 +4,12 @@
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
CachedMir,
|
CachedMir,
|
||||||
ConstantId,
|
GlobalId,
|
||||||
EvalContext,
|
EvalContext,
|
||||||
Lvalue,
|
Lvalue,
|
||||||
ConstantKind,
|
GlobalKind,
|
||||||
StackPopCleanup,
|
StackPopCleanup,
|
||||||
Constant,
|
Global,
|
||||||
};
|
};
|
||||||
use error::EvalResult;
|
use error::EvalResult;
|
||||||
use rustc::mir::repr as mir;
|
use rustc::mir::repr as mir;
|
||||||
|
@ -119,17 +119,17 @@ struct ConstantExtractor<'a, 'b: 'a, 'tcx: 'b> {
|
||||||
|
|
||||||
impl<'a, 'b, 'tcx> ConstantExtractor<'a, 'b, 'tcx> {
|
impl<'a, 'b, 'tcx> ConstantExtractor<'a, 'b, 'tcx> {
|
||||||
fn global_item(&mut self, def_id: DefId, substs: &'tcx subst::Substs<'tcx>, span: Span, immutable: bool) {
|
fn global_item(&mut self, def_id: DefId, substs: &'tcx subst::Substs<'tcx>, span: Span, immutable: bool) {
|
||||||
let cid = ConstantId {
|
let cid = GlobalId {
|
||||||
def_id: def_id,
|
def_id: def_id,
|
||||||
substs: substs,
|
substs: substs,
|
||||||
kind: ConstantKind::Global,
|
kind: GlobalKind::Global,
|
||||||
};
|
};
|
||||||
if self.ecx.statics.contains_key(&cid) {
|
if self.ecx.globals.contains_key(&cid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.try(|this| {
|
self.try(|this| {
|
||||||
let mir = this.ecx.load_mir(def_id)?;
|
let mir = this.ecx.load_mir(def_id)?;
|
||||||
this.ecx.statics.insert(cid, Constant::uninitialized(mir.return_ty));
|
this.ecx.globals.insert(cid, Global::uninitialized(mir.return_ty));
|
||||||
let cleanup = if immutable && !mir.return_ty.type_contents(this.ecx.tcx).interior_unsafe() {
|
let cleanup = if immutable && !mir.return_ty.type_contents(this.ecx.tcx).interior_unsafe() {
|
||||||
StackPopCleanup::Freeze
|
StackPopCleanup::Freeze
|
||||||
} else {
|
} else {
|
||||||
|
@ -167,18 +167,18 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ConstantExtractor<'a, 'b, 'tcx> {
|
||||||
},
|
},
|
||||||
mir::Literal::Promoted { index } => {
|
mir::Literal::Promoted { index } => {
|
||||||
let mir = self.mir.promoted[index].clone();
|
let mir = self.mir.promoted[index].clone();
|
||||||
let cid = ConstantId {
|
let cid = GlobalId {
|
||||||
def_id: self.def_id,
|
def_id: self.def_id,
|
||||||
substs: self.substs,
|
substs: self.substs,
|
||||||
kind: ConstantKind::Promoted(index),
|
kind: GlobalKind::Promoted(index),
|
||||||
};
|
};
|
||||||
if self.ecx.statics.contains_key(&cid) {
|
if self.ecx.globals.contains_key(&cid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.try(|this| {
|
self.try(|this| {
|
||||||
let mir = CachedMir::Owned(Rc::new(mir));
|
let mir = CachedMir::Owned(Rc::new(mir));
|
||||||
let ty = this.ecx.monomorphize(mir.return_ty, this.substs);
|
let ty = this.ecx.monomorphize(mir.return_ty, this.substs);
|
||||||
this.ecx.statics.insert(cid, Constant::uninitialized(ty));
|
this.ecx.globals.insert(cid, Global::uninitialized(ty));
|
||||||
this.ecx.push_stack_frame(this.def_id,
|
this.ecx.push_stack_frame(this.def_id,
|
||||||
constant.span,
|
constant.span,
|
||||||
mir,
|
mir,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue