Remove elements from the todo list the correct way in constant.rs
This commit is contained in:
parent
c40788c1b2
commit
49d24a6333
@ -170,3 +170,7 @@ fn int_to_float(a: u8, b: i32) -> (f64, f32) {
|
||||
fn make_array() -> [u8; 3] {
|
||||
[42, 0, 5]
|
||||
}
|
||||
|
||||
fn some_promoted_tuple() -> &'static (&'static str, &'static str) {
|
||||
&("abc", "some")
|
||||
}
|
||||
|
@ -59,11 +59,26 @@ pub trait Mul<RHS = Self> {
|
||||
impl Mul for u8 {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(self, rhs: Self) -> Self {
|
||||
fn mul(self, rhs: Self) -> Self::Output {
|
||||
self * rhs
|
||||
}
|
||||
}
|
||||
|
||||
#[lang = "sub"]
|
||||
pub trait Sub<RHS = Self> {
|
||||
type Output;
|
||||
|
||||
fn sub(self, rhs: RHS) -> Self::Output;
|
||||
}
|
||||
|
||||
impl Sub for usize {
|
||||
type Output = Self;
|
||||
|
||||
fn sub(self, rhs: Self) -> Self {
|
||||
self - rhs
|
||||
}
|
||||
}
|
||||
|
||||
#[lang = "bitor"]
|
||||
pub trait BitOr<RHS = Self> {
|
||||
type Output;
|
||||
|
@ -104,17 +104,7 @@ fn trans_const_place<'a, 'tcx: 'a>(
|
||||
) -> CPlace<'tcx> {
|
||||
let ty = fx.monomorphize(&const_.ty);
|
||||
let layout = fx.layout_of(ty);
|
||||
if !fx
|
||||
.tcx
|
||||
.sess
|
||||
.crate_types
|
||||
.get()
|
||||
.contains(&CrateType::Executable)
|
||||
{
|
||||
// TODO: cranelift-module api seems to be used wrong,
|
||||
// thus causing panics for some consts, so this disables it
|
||||
return CPlace::Addr(fx.bcx.ins().iconst(types::I64, 0), layout);
|
||||
}
|
||||
|
||||
let alloc = fx.tcx.const_value_to_allocation(const_);
|
||||
//println!("const value: {:?} allocation: {:?}", value, alloc);
|
||||
let alloc_id = fx.tcx.alloc_map.lock().allocate(alloc);
|
||||
@ -161,10 +151,16 @@ fn get_global_for_alloc_id<'a, 'tcx: 'a, B: Backend + 'a>(
|
||||
let mut todo = HashMap::new();
|
||||
define_global_for_alloc_id(module, cx, alloc_id, &mut todo);
|
||||
|
||||
while let Some((alloc_id, data_id)) = {
|
||||
let next = todo.drain().next();
|
||||
next
|
||||
} {
|
||||
loop {
|
||||
let (alloc_id, data_id) = {
|
||||
if let Some(alloc_id) = todo.keys().next().map(|alloc_id| *alloc_id) {
|
||||
let data_id = todo.remove(&alloc_id).unwrap();
|
||||
(alloc_id, data_id)
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
println!(
|
||||
"cur: {:?}:{:?} todo: {:?} done: {:?}",
|
||||
alloc_id, data_id, todo, cx.done
|
||||
|
Loading…
x
Reference in New Issue
Block a user