Skip to content

Commit

Permalink
fix recursisve node checks for custom inverses
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Nov 11, 2024
1 parent efecea4 commit df674ae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "uiua"
readme = "readme.md"
repository = "https://github.com/uiua-lang/uiua"
rust-version = "1.78"
version = "0.14.0-dev.1"
version = "0.14.0-dev.2"

[dependencies]
# Core dependencies
Expand Down
16 changes: 16 additions & 0 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ impl CustomInverse {
}
})
}
/// Iterate over all nodes
pub fn nodes(&self) -> impl Iterator<Item = &SigNode> {
(self.normal.as_ref().into_iter())
.chain(self.un.as_ref())
.chain(self.anti.as_ref())
.chain(self.under.as_ref().into_iter().flat_map(|(b, a)| [a, b]))
}
}

impl Default for Node {
Expand Down Expand Up @@ -611,6 +618,9 @@ impl Node {
Node::Switch { branches, .. } => branches
.iter()
.all(|br| recurse(&br.node, purity, asm, visited)),
Node::CustomInverse(cust, _) => (cust.normal.as_ref().ok())
.or(cust.un.as_ref())
.is_some_and(|sn| recurse(&sn.node, purity, asm, visited)),
_ => true,
};
visited.truncate(len);
Expand Down Expand Up @@ -651,6 +661,9 @@ impl Node {
Node::Switch { branches, .. } => {
branches.iter().all(|br| recurse(&br.node, asm, visited))
}
Node::CustomInverse(cust, _) => (cust.normal.as_ref().ok())
.or(cust.un.as_ref())
.is_some_and(|sn| recurse(&sn.node, asm, visited)),
_ => true,
};
visited.truncate(len);
Expand All @@ -675,6 +688,9 @@ impl Node {
Node::Switch { branches, .. } => {
branches.iter().any(|br| recurse(&br.node, asm, visited))
}
Node::CustomInverse(cust, _) => (cust.normal.as_ref().ok())
.or(cust.un.as_ref())
.is_some_and(|sn| recurse(&sn.node, asm, visited)),
_ => false,
};
visited.truncate(len);
Expand Down

0 comments on commit df674ae

Please sign in to comment.