Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Fix the logic of get_io #442

Merged
merged 3 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/builder/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,18 +429,13 @@ pub(crate) mod test {

#[test]
fn lift_node() -> Result<(), BuildError> {
let mut module_builder = ModuleBuilder::new();

let ab_extensions = ExtensionSet::from_iter(["A".into(), "B".into()]);
let c_extensions = ExtensionSet::singleton(&"C".into());
let abc_extensions = ab_extensions.clone().union(&c_extensions);

let parent_sig =
FunctionType::new(type_row![BIT], type_row![BIT]).with_extension_delta(&abc_extensions);
let mut parent = module_builder.define_function(
"parent",
parent_sig.with_input_extensions(ExtensionSet::new()),
)?;
let mut parent = DFGBuilder::new(parent_sig)?;

let add_c_sig = FunctionType::new(type_row![BIT], type_row![BIT])
.with_extension_delta(&c_extensions)
Expand Down Expand Up @@ -498,8 +493,7 @@ pub(crate) mod test {

let add_c = add_c.finish_with_outputs(wires)?;
let [w] = add_c.outputs_arr();
parent.finish_with_outputs([w])?;
module_builder.finish_hugr()?;
parent.finish_hugr_with_outputs([w])?;

Ok(())
}
Expand Down
10 changes: 10 additions & 0 deletions src/hugr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,14 @@ mod test {
trait Test: Send + Sync {}
impl Test for Hugr {}
}

#[test]
fn io_node() {
use crate::builder::test::simple_dfg_hugr;
use crate::hugr::views::HugrView;
use cool_asserts::assert_matches;

let hugr = simple_dfg_hugr();
assert_matches!(hugr.get_io(hugr.root()), Some(_));
}
}
2 changes: 1 addition & 1 deletion src/hugr/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ mod test {
assert_matches!(
handle,
Err(ValidationError::ExtensionError(
ExtensionError::TgtExceedsSrcExtensions { .. }
ExtensionError::ParentIOExtensionMismatch { .. }
))
);
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/hugr/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ where
#[inline]
fn get_io(&self, node: Node) -> Option<[Node; 2]> {
let op = self.get_nodetype(node);
if op.tag().is_superset(OpTag::DataflowParent) {
if OpTag::DataflowParent.is_superset(op.tag()) {
self.children(node).take(2).collect_vec().try_into().ok()
} else {
None
Expand Down
2 changes: 1 addition & 1 deletion src/ops/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub enum OpTag {
}

impl OpTag {
/// Returns true if the tag is more general than the given tag.
/// Returns true if this tag is more general than `other`.
#[inline]
pub const fn is_superset(self, other: OpTag) -> bool {
// We cannot call iter().any() or even do for loops in const fn yet.
Expand Down