Clean up remove map_basic

This commit is contained in:
Noah committed 2020-10-19 23:55:56 -05:00
1 parent df28c022e1
commit b8ebd445f4
3 files changed
+13 -11

No files matched your search

+9 -10
View File
@@ -36,6 +36,9 @@ pub trait Constant: Sized {
fn into_data(self) -> ConstantData {
self.borrow_constant().into_data()
}
fn map_constant<Bag: ConstantBag>(self, bag: &Bag) -> Bag::Constant {
bag.make_constant(self.into_data())
}
}
impl Constant for ConstantData {
fn borrow_constant(&self) -> BorrowedConstant<Self> {
@@ -591,9 +594,13 @@ impl<C: Constant> CodeObject<C> {
Display(self)
}
fn _map_inner<U: Constant>(self, map: impl Fn(C) -> U) -> CodeObject<U> {
pub fn map_bag<Bag: ConstantBag>(self, bag: &Bag) -> CodeObject<Bag::Constant> {
CodeObject {
constants: self.constants.into_iter().map(map).collect(),
constants: self
.constants
.into_iter()
.map(|x| x.map_constant(bag))
.collect(),
instructions: self.instructions,
label_map: self.label_map,
@@ -610,10 +617,6 @@ impl<C: Constant> CodeObject<C> {
}
}
pub fn map_bag<Bag: ConstantBag>(self, bag: &Bag) -> CodeObject<Bag::Constant> {
self._map_inner(|x| bag.make_constant_borrowed(x.borrow_constant()))
}
pub fn map_clone_bag<Bag: ConstantBag>(&self, bag: &Bag) -> CodeObject<Bag::Constant> {
CodeObject {
constants: self
@@ -651,10 +654,6 @@ impl CodeObject<ConstantData> {
let data = bincode::serialize(&self).expect("Code object must be serializable");
lz4_compression::compress::compress(&data)
}
pub fn map_basic<Bag: ConstantBag>(self, bag: &Bag) -> CodeObject<Bag::Constant> {
self._map_inner(|x| bag.make_constant(x))
}
}
impl<C: Constant> fmt::Display for CodeObject<C> {
+3
View File
@@ -70,6 +70,9 @@ impl Constant for PyConstant {
fn borrow_constant(&self) -> BorrowedConstant<Self> {
borrow_obj_constant(&self.0)
}
fn map_constant<Bag: ConstantBag>(self, bag: &Bag) -> Bag::Constant {
bag.make_constant_borrowed(self.borrow_constant())
}
}
pub(crate) struct PyObjBag<'a>(pub &'a PyContext);
+1 -1
View File
@@ -407,7 +407,7 @@ impl PyContext {
}
pub fn map_codeobj(&self, code: bytecode::CodeObject) -> code::CodeObject {
code.map_basic(&code::PyObjBag(self))
code.map_bag(&code::PyObjBag(self))
}
pub fn add_tp_new_wrapper(&self, ty: &PyTypeRef) {