Skip to content

Commit

Permalink
fix!: Replace LoadFunction::signature with `LoadFunction::instantia…
Browse files Browse the repository at this point in the history
…tion`

Closes #1755

BREAKING CHANGE: The `LoadFunction::signature` field is removed. Replace
uses with `DataflowOpTrait::signature()`.
  • Loading branch information
doug-q committed Dec 10, 2024
1 parent 97e4625 commit 802d361
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion hugr-core/src/extension/resolution/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn update_op_types_extensions(
}
OpType::LoadFunction(lf) => {
update_signature_exts(node, lf.func_sig.body_mut(), extensions, used_extensions)?;
update_signature_exts(node, &mut lf.signature, extensions, used_extensions)?;
update_signature_exts(node, &mut lf.instantiation, extensions, used_extensions)?;
}
OpType::DFG(dfg) => {
update_signature_exts(node, &mut dfg.signature, extensions, used_extensions)?
Expand Down
15 changes: 7 additions & 8 deletions hugr-core/src/ops/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{impl_op_name, OpTag, OpTrait};
use crate::extension::{ExtensionRegistry, ExtensionSet, SignatureError};
use crate::ops::StaticTag;
use crate::types::{EdgeKind, PolyFuncType, Signature, Type, TypeArg, TypeRow};
use crate::IncomingPort;
use crate::{type_row, IncomingPort};

#[cfg(test)]
use ::proptest_derive::Arbitrary;
Expand Down Expand Up @@ -341,7 +341,7 @@ pub struct LoadFunction {
/// The type arguments that instantiate `func_sig`.
pub type_args: Vec<TypeArg>,
/// The instantiation of `func_sig`.
pub signature: Signature, // Cache, so we can fail in try_new() not in signature()
pub instantiation: Signature, // Cache, so we can fail in try_new() not in signature()
}
impl_op_name!(LoadFunction);
impl DataflowOpTrait for LoadFunction {
Expand All @@ -352,7 +352,7 @@ impl DataflowOpTrait for LoadFunction {
}

fn signature(&self) -> Signature {
self.signature.clone()
Signature::new(type_row![], Type::new_function(self.instantiation.clone()))
}

fn static_input(&self) -> Option<EdgeKind> {
Expand All @@ -371,11 +371,10 @@ impl LoadFunction {
) -> Result<Self, SignatureError> {
let type_args = type_args.into();
let instantiation = func_sig.instantiate(&type_args, exts)?;
let signature = Signature::new(TypeRow::new(), vec![Type::new_function(instantiation)]);
Ok(Self {
func_sig,
type_args,
signature,
instantiation,
})
}

Expand Down Expand Up @@ -404,12 +403,12 @@ impl LoadFunction {
self.type_args.clone(),
extension_registry,
)?;
if other.signature == self.signature {
if other.instantiation == self.instantiation {
Ok(())
} else {
Err(SignatureError::LoadFunctionIncorrectlyAppliesType {
cached: self.signature.clone(),
expected: other.signature.clone(),
cached: self.instantiation.clone(),
expected: other.instantiation.clone(),
})
}
}
Expand Down

0 comments on commit 802d361

Please sign in to comment.