Skip to content

Commit

Permalink
[fix] Adding output resources in DFG builder (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
croyzor authored Aug 8, 2023
1 parent cd6d6c9 commit ce78549
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/builder/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<T: AsMut<Hugr> + AsRef<Hugr>> DFGBuilder<T> {
parent,
match input_resources.map(|inp| inp.union(&signature.resource_reqs)) {
// TODO: Make this NodeType::open_resources
None => NodeType::pure(output),
None => NodeType::new(output, signature.resource_reqs),
Some(rs) => NodeType::new(output, rs),
},
)?;
Expand Down
24 changes: 22 additions & 2 deletions src/hugr/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,10 @@ mod test {
use cool_asserts::assert_matches;

use super::*;
use crate::builder::{BuildError, ModuleBuilder};
use crate::builder::{Container, Dataflow, DataflowSubContainer, HugrBuilder};
use crate::builder::{
BuildError, Container, DFGBuilder, Dataflow, DataflowHugr, DataflowSubContainer,
HugrBuilder, ModuleBuilder,
};
use crate::hugr::{HugrError, HugrMut, NodeType};
use crate::ops::dataflow::IOTrait;
use crate::ops::{self, LeafOp, OpType};
Expand Down Expand Up @@ -1280,4 +1282,22 @@ mod test {
assert_matches!(handle, Err(ValidationError::TgtExceedsSrcResources { .. }));
Ok(())
}

#[test]
fn parent_signature_mismatch() -> Result<(), BuildError> {
let main_signature = AbstractSignature::new_df(type_row![NAT], type_row![NAT])
.with_resource_delta(&ResourceSet::singleton(&"R".into()));

let builder = DFGBuilder::new(main_signature)?;
let [w] = builder.input_wires_arr();
let hugr = builder.finish_hugr_with_outputs([w]);

assert_matches!(
hugr,
Err(BuildError::InvalidHUGR(
ValidationError::TgtExceedsSrcResources { .. }
))
);
Ok(())
}
}

0 comments on commit ce78549

Please sign in to comment.