Add take_value_list and put_value_list methods.

Any code that needs to manipulate a variable argument list on an
instruction will need to remove the instruction's value list first,
change the list, and then put it back on the instruction. This is
required to avoid fighting the borrow checker over mutable locks on the
DataFlowGraph and its value list pool.

Add a generated InstructionData::take_value_list() method which lifts
out and existing value list and returns it, levaing an empty list in its
place, like Option::take() does it.

Add a generated InstructionData::put_value_list() which puts it back,
verifying that no existing value list is overwritten.
This commit is contained in:
Jakob Stoklund Olesen
2017-03-13 14:07:14 -07:00
parent 404a88f581
commit 5f2e37e05c
2 changed files with 49 additions and 0 deletions

View File

@@ -47,6 +47,7 @@
//! reserved for the empty list which isn't allocated in the vector.
use std::marker::PhantomData;
use std::mem;
use entity_map::EntityRef;
@@ -273,6 +274,13 @@ impl<T: EntityRef> EntityList<T> {
self.index = 0;
}
/// Take all elements from this list and return them as a new list. Leave this list empty.
///
/// This is the equivalent of `Option::take()`.
pub fn take(&mut self) -> EntityList<T> {
mem::replace(self, Default::default())
}
/// Appends an element to the back of the list.
pub fn push(&mut self, element: T, pool: &mut ListPool<T>) {
let idx = self.index as usize;