Skip to content

Commit

Permalink
fix: replace ouroboros with self_cell (#1171)
Browse files Browse the repository at this point in the history
  • Loading branch information
novacrazy authored Jun 12, 2023
1 parent f602cd7 commit b0a23be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion leptos_reactive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ web-sys = { version = "0.3", optional = true, features = [
] }
cfg-if = "1"
indexmap = "1"
ouroboros = { version = "0.15.6", default-features = false }
self_cell = "1.0.0"

[dev-dependencies]
criterion = { version = "0.4.0", features = ["html_reports"] }
Expand Down
24 changes: 12 additions & 12 deletions leptos_reactive/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ impl Runtime {
}
}

#[allow(clippy::await_holding_refcell_ref)] // not using this part of ouroboros
pub(crate) fn mark_dirty(&self, node: NodeId) {
//crate::macros::debug_warn!("marking {node:?} dirty");
let mut nodes = self.nodes.borrow_mut();
Expand Down Expand Up @@ -217,23 +216,24 @@ impl Runtime {
* `Check` or `DirtyMarked`.
*
* Because `RefCell`, borrowing the iterators all at once is difficult,
* so a self-referential struct is used instead. ouroboros produces safe
* so a self-referential struct is used instead. self_cell produces safe
* code, but it would not be recommended to use this outside of this
* algorithm.
*/

#[ouroboros::self_referencing]
struct RefIter<'a> {
set: std::cell::Ref<'a, FxIndexSet<NodeId>>,
type Dependent<'a> = indexmap::set::Iter<'a, NodeId>;

// Boxes the iterator internally
#[borrows(set)]
#[covariant]
iter: indexmap::set::Iter<'this, NodeId>,
self_cell::self_cell! {
struct RefIter<'a> {
owner: std::cell::Ref<'a, FxIndexSet<NodeId>>,

#[not_covariant] // avoids extra codegen, harmless to mark it as such
dependent: Dependent,
}
}

/// Due to the limitations of ouroboros, we cannot borrow the
/// stack and iter simultaneously, or directly within the loop,
/// Due to the limitations of self-referencing, we cannot borrow the
/// stack and iter simultaneously within the closure or the loop,
/// therefore this must be used to command the outside scope
/// of what to do.
enum IterResult<'a> {
Expand All @@ -251,7 +251,7 @@ impl Runtime {
}

while let Some(iter) = stack.last_mut() {
let res = iter.with_iter_mut(|iter| {
let res = iter.with_dependent_mut(|_, iter| {
let Some(mut child) = iter.next().copied() else {
return IterResult::Empty;
};
Expand Down

0 comments on commit b0a23be

Please sign in to comment.