fix: it compiles again

This commit is contained in:
Jonathan Kelley committed 2021-11-09 02:11:44 -05:00
1 parent 0e6c845690
commit 77686ba329
5 files changed
+265 -306

No files matched your search

+209 -281
View File
File diff suppressed because it is too large. Load diff
+11 -6
View File
@@ -368,8 +368,13 @@ pub struct VComponent<'src> {
pub(crate) bump_props: *const (),
// during the "teardown" process we'll take the caller out so it can be dropped properly
pub(crate) caller: Option<VCompCaller<'src>>,
pub(crate) comparator: Option<BumpBox<'src, dyn Fn(&VComponent) -> bool + 'src>>,
// pub(crate) caller: Option<VCompCaller<'src>>,
pub(crate) caller: &'src dyn Fn(&'src Scope) -> Element,
pub(crate) comparator: Option<&'src dyn Fn(&VComponent) -> bool>,
pub(crate) drop_props: RefCell<Option<BumpBox<'src, dyn FnMut()>>>,
// pub(crate) comparator: Option<BumpBox<'src, dyn Fn(&VComponent) -> bool + 'src>>,
}
pub struct VSuspended<'a> {
@@ -588,26 +593,26 @@ impl<'a> NodeFactory<'a> {
let key = key.map(|f| self.raw_text(f).0);
let caller: &'a mut dyn Fn(&Scope) -> Element =
let caller: &'a mut dyn Fn(&'a Scope) -> Element =
bump.alloc(move |scope: &Scope| -> Element {
log::debug!("calling component renderr {:?}", scope.our_arena_idx);
let props: &'_ P = unsafe { &*(bump_props as *const P) };
let res = component(scope, props);
// let res = component((Context { scope }, props));
unsafe { std::mem::transmute(res) }
res
});
let can_memoize = P::IS_STATIC;
VNode::Component(bump.alloc(VComponent {
user_fc,
comparator,
comparator: Some(comparator),
bump_props,
caller,
key,
can_memoize,
drop_props,
associated_scope: Cell::new(None),
hard_allocation: Cell::new(None),
}))
}
+1 -1
View File
@@ -67,7 +67,7 @@ pub struct Scope {
pub(crate) old_root: RefCell<Option<NodeLink>>,
pub(crate) new_root: RefCell<Option<NodeLink>>,
pub(crate) caller: *mut dyn Fn(&Scope) -> Element,
pub(crate) caller: *const dyn Fn(&Scope) -> Element,
/*
we care about:
+6 -1
View File
@@ -44,10 +44,15 @@ impl ScopeArena {
unsafe { Some(&*self.scopes[id.0]) }
}
// this is unsafe
pub unsafe fn get_scope_mut(&self, id: &ScopeId) -> Option<*mut Scope> {
Some(self.scopes[id.0])
}
pub fn new_with_key(
&mut self,
fc_ptr: *const (),
caller: *mut dyn Fn(&Scope) -> Element,
caller: *const dyn Fn(&Scope) -> Element,
parent_scope: Option<*mut Scope>,
height: u32,
subtree: u32,
+38 -17
View File
@@ -63,7 +63,7 @@ pub struct VirtualDom {
_root_caller: *mut dyn Fn(&Scope) -> Element,
pub(crate) scopes: ScopeArena,
pub(crate) scopes: Box<ScopeArena>,
receiver: UnboundedReceiver<SchedulerMsg>,
pub(crate) sender: UnboundedSender<SchedulerMsg>,
@@ -152,7 +152,7 @@ impl VirtualDom {
let base_scope = scopes.new_with_key(root as _, caller_ref, None, 0, 0);
Self {
scopes,
scopes: Box::new(scopes),
base_scope,
receiver,
// todo: clean this up manually?
@@ -358,13 +358,13 @@ impl VirtualDom {
}
}
let mut diff_state: DiffState = DiffState::new(Mutations::new());
let scopes = &self.scopes;
let mut diff_state = DiffState::new(scopes);
let mut ran_scopes = FxHashSet::default();
// todo: the 2021 version of rust will let us not have to force the borrow
let scopes = &self.scopes;
// let scopes = &self.scopes;
// Sort the scopes by height. Theoretically, we'll de-duplicate scopes by height
self.dirty_scopes
.retain(|id| scopes.get_scope(id).is_some());
@@ -394,7 +394,10 @@ impl VirtualDom {
}
}
let work_completed = self.scopes.work(&mut diff_state, &mut deadline);
// let scopes = &mut self.scopes;
let work_completed = diff_state.work(&mut deadline);
// let work_completed = crate::diff::work(&mut diff_state, &mut deadline);
// let work_completed = crate::diff::work(&mut diff_state, &mut deadline);
if work_completed {
let DiffState {
@@ -440,20 +443,25 @@ impl VirtualDom {
/// apply_edits(edits);
/// ```
pub fn rebuild(&mut self) -> Mutations {
let mut diff_machine = DiffState::new(Mutations::new());
let mut diff_state = DiffState::new(&self.scopes);
let scope_id = self.base_scope;
if self.scopes.run_scope(&scope_id) {
diff_machine
.stack
.create_node(self.scopes.fin_head(&scope_id), MountType::Append);
todo!();
// diff_state
// .stack
// .create_node(self.scopes.fin_head(&scope_id), MountType::Append);
diff_machine.stack.scope_stack.push(scope_id);
// diff_state.stack.scope_stack.push(scope_id);
self.scopes.work(&mut diff_machine, || false);
let work_completed = diff_state.work(|| false);
// let scopes = &mut self.scopes;
//
// let work_completed = crate::diff::work(&mut diff_state, || false);
// self.scopes.work(&mut diff_machine, || false);
}
diff_machine.mutations
diff_state.mutations
}
/// Compute a manual diff of the VirtualDOM between states.
@@ -494,15 +502,28 @@ impl VirtualDom {
log::debug!("hard diff {:?}", scope_id);
if self.scopes.run_scope(scope_id) {
let mut diff_machine = DiffState::new(Mutations::new());
let mut diff_machine = DiffState::new(&self.scopes);
diff_machine.force_diff = true;
self.scopes.diff_scope(&mut diff_machine, scope_id);
let work_completed = diff_machine.work(|| false);
// let scopes = &mut self.scopes;
// crate::diff::diff_scope(&mut diff_machine, scope_id);
// self.scopes.diff_scope(&mut diff_machine, scope_id);
dbg!(&diff_machine.mutations);
// dbg!(&diff_machine.mutations);
// let DiffState {
// mutations,
// stack,
// seen_scopes,
// force_diff,
// ..
// } = mutations;
Some(diff_machine.mutations)
// let mutations = diff_machine.mutations;
// Some(unsafe { std::mem::transmute(mutations) })
todo!()
} else {
None
}