fix: make miri pass

This commit is contained in:
Jonathan Kelley 2022-12-16 20:39:19 -08:00
parent 261d688b6e
commit ea9245b0f7
2 changed files with 34 additions and 31 deletions

View file

@ -155,21 +155,22 @@ impl<'b> VirtualDom {
// Replace components that have different render fns // Replace components that have different render fns
if left.render_fn != right.render_fn { if left.render_fn != right.render_fn {
todo!() let created = self.create_component_node(right_template, right, idx);
// let created = self.create_component_node(right_template, right, idx); let head = unsafe {
// let head = unsafe { self.scopes[left.scope.get().unwrap().0]
// self.scopes[left.scope.get().unwrap().0] .root_node()
// .root_node() .extend_lifetime_ref()
// .extend_lifetime_ref() };
// }; let last = match head {
// let last = match head { RenderReturn::Sync(Ok(node)) => self.find_last_element(node),
// RenderReturn::Sync(Ok(node)) => self.find_last_element(node), _ => todo!(),
// _ => todo!(), };
// }; self.mutations.push(Mutation::InsertAfter {
// self.mutations id: last,
// .push(Mutation::ReplaceWith { id, m: created }); m: created,
// self.drop_scope(left.scope.get().unwrap()); });
// return; self.remove_component_node(left, true);
return;
} }
// Make sure the new vcomponent has the right scopeid associated to it // Make sure the new vcomponent has the right scopeid associated to it
@ -240,14 +241,13 @@ impl<'b> VirtualDom {
/// } /// }
/// ``` /// ```
fn light_diff_templates(&mut self, left: &'b VNode<'b>, right: &'b VNode<'b>) { fn light_diff_templates(&mut self, left: &'b VNode<'b>, right: &'b VNode<'b>) {
self.replace(left, [right]); match matching_components(left, right) {
// match matching_components(left, right) { None => self.replace(left, [right]),
// None => self.replace(left, [right]), Some(components) => components
// Some(components) => components .into_iter()
// .into_iter() .enumerate()
// .enumerate() .for_each(|(idx, (l, r))| self.diff_vcomponent(l, r, right, idx)),
// .for_each(|(idx, (l, r))| self.diff_vcomponent(l, r, right, idx)), }
// }
} }
/// Diff the two text nodes /// Diff the two text nodes
@ -815,9 +815,6 @@ impl<'b> VirtualDom {
}; };
let props = self.scopes[scope.0].props.take(); let props = self.scopes[scope.0].props.take();
// let props: Option<Box<dyn AnyProps>> = comp.props.take();
println!("taking props... {:?}", scope);
self.dirty_scopes.remove(&DirtyScope { self.dirty_scopes.remove(&DirtyScope {
height: self.scopes[scope.0].height, height: self.scopes[scope.0].height,

View file

@ -25,8 +25,11 @@ use crate::{innerlude::VNode, ScopeState};
/// LazyNodes::new(|f| f.element("div", [], [], [] None)) /// LazyNodes::new(|f| f.element("div", [], [], [] None))
/// ``` /// ```
pub struct LazyNodes<'a, 'b> { pub struct LazyNodes<'a, 'b> {
#[cfg(not(miri))]
inner: SmallBox<dyn FnMut(&'a ScopeState) -> VNode<'a> + 'b, S16>,
#[cfg(miri)]
inner: Box<dyn FnMut(&'a ScopeState) -> VNode<'a> + 'b>, inner: Box<dyn FnMut(&'a ScopeState) -> VNode<'a> + 'b>,
// inner: SmallBox<dyn FnMut(&'a ScopeState) -> VNode<'a> + 'b, S16>,
} }
impl<'a, 'b> LazyNodes<'a, 'b> { impl<'a, 'b> LazyNodes<'a, 'b> {
@ -40,14 +43,17 @@ impl<'a, 'b> LazyNodes<'a, 'b> {
let mut slot = Some(val); let mut slot = Some(val);
Self { Self {
#[cfg(miri)]
inner: Box::new(move |f| { inner: Box::new(move |f| {
let val = slot.take().expect("cannot call LazyNodes twice"); let val = slot.take().expect("cannot call LazyNodes twice");
val(f) val(f)
}), }),
// inner: smallbox!(move |f| {
// let val = slot.take().expect("cannot call LazyNodes twice"); #[cfg(not(miri))]
// val(f) inner: smallbox!(move |f| {
// }), let val = slot.take().expect("cannot call LazyNodes twice");
val(f)
}),
} }
} }