Skip to content

Commit

Permalink
Check CustomType has correct bound
Browse files Browse the repository at this point in the history
  • Loading branch information
acl-cqc committed Aug 29, 2023
1 parent ea70884 commit f797080
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
7 changes: 1 addition & 6 deletions src/builder/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,7 @@ pub(crate) mod test {
f_build.finish_with_outputs([id.out_wire(0)])?;
}

assert_eq!(
module_builder
.finish_hugr(&EMPTY_REG)?
.node_count(),
7
);
assert_eq!(module_builder.finish_hugr(&EMPTY_REG)?.node_count(), 7);

Ok(())
}
Expand Down
8 changes: 7 additions & 1 deletion src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::ops;
use crate::ops::custom::{ExtensionOp, OpaqueOp};
use crate::types::type_param::{check_type_arg, TypeArgError};
use crate::types::type_param::{TypeArg, TypeParam};
use crate::types::CustomType;
use crate::types::{CustomType, TypeBound};

mod infer;
pub use infer::{infer_extensions, ExtensionSolution, InferExtensionError};
Expand Down Expand Up @@ -81,6 +81,12 @@ pub enum SignatureError {
/// The Extension was found in the registry, but did not contain the Type(Def) referenced in the Signature
#[error("Extension '{exn}' did not contain expected TypeDef '{typ}'")]
ExtensionTypeNotFound { exn: SmolStr, typ: SmolStr },
/// The bound recorded for a CustomType doesn't match what the TypeDef would compute
#[error("Bound on CustomType did not match TypeDef")]
WrongBound {
actual: TypeBound,
expected: TypeBound,
},
}

/// Concrete instantiations of types and operations defined in extensions.
Expand Down
11 changes: 10 additions & 1 deletion src/extension/type_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,16 @@ impl TypeDef {
/// This function will return an error if the type of the instance does not
/// match the definition.
pub fn check_custom(&self, custom: &CustomType) -> Result<(), SignatureError> {
self.check_concrete_impl(custom)
self.check_concrete_impl(custom)?;
let calc_bound = self.bound(custom.args());
if calc_bound == custom.bound() {
Ok(())
} else {
Err(SignatureError::WrongBound {
expected: calc_bound,
actual: custom.bound(),
})
}
}

/// Instantiate a concrete [`CustomType`] by providing type arguments.
Expand Down

0 comments on commit f797080

Please sign in to comment.