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

feat: Instantiate inferred extensions #461

Merged
merged 7 commits into from
Aug 31, 2023
12 changes: 6 additions & 6 deletions src/hugr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod serialize;
pub mod validate;
pub mod views;

use std::collections::{HashMap, VecDeque};
use std::collections::VecDeque;
use std::iter;

pub(crate) use self::hugrmut::HugrMut;
Expand Down Expand Up @@ -197,9 +197,9 @@ impl Hugr {
}

/// Infer extension requirements and add new information to `op_types` field
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a doclink to infer::infer_extensions here?
And, should the return type here be ExtensionSolution? (A typedef to the same type as here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be, yes. I was trying to distinguish the genuine solution (as ExtensionSolution) from the closure, but they really should be the same type regardless

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now addressed both of these in 8e55229 and 1802ccd, respectively

pub fn infer_extensions(
&mut self,
) -> Result<HashMap<(Node, Direction), ExtensionSet>, InferExtensionError> {
///
/// See [`infer_extensions`] for details on the "closure" value
pub fn infer_extensions(&mut self) -> Result<ExtensionSolution, InferExtensionError> {
let (solution, extension_closure) = infer_extensions(self)?;
self.instantiate_extensions(solution);
Ok(extension_closure)
Expand All @@ -214,10 +214,10 @@ impl Hugr {
.filter(|((_, dir), _)| *dir == Direction::Incoming)
{
let nodetype = self.op_types.try_get_mut(node.index).unwrap();
match nodetype.signature() {
match &nodetype.input_extensions {
None => nodetype.input_extensions = Some(input_extensions.clone()),
Some(existing_ext_reqs) => {
acl-cqc marked this conversation as resolved.
Show resolved Hide resolved
debug_assert_eq!(existing_ext_reqs.input_extensions, *input_extensions)
debug_assert_eq!(existing_ext_reqs, input_extensions)
}
}
}
Expand Down