diff --git a/hugr-core/src/extension/resolution/types.rs b/hugr-core/src/extension/resolution/types.rs index 128900e25..05997eb1b 100644 --- a/hugr-core/src/extension/resolution/types.rs +++ b/hugr-core/src/extension/resolution/types.rs @@ -58,7 +58,7 @@ pub(crate) fn collect_op_types_extensions( OpType::LoadConstant(lc) => collect_type_exts(&lc.datatype, &mut used, &mut missing), OpType::LoadFunction(lf) => { collect_signature_exts(lf.func_sig.body(), &mut used, &mut missing); - collect_signature_exts(&lf.signature, &mut used, &mut missing); + collect_signature_exts(&lf.instantiation, &mut used, &mut missing); } OpType::DFG(dfg) => collect_signature_exts(&dfg.signature, &mut used, &mut missing), OpType::OpaqueOp(op) => { diff --git a/hugr-core/src/extension/resolution/types_mut.rs b/hugr-core/src/extension/resolution/types_mut.rs index 7f8f16f4c..a45862042 100644 --- a/hugr-core/src/extension/resolution/types_mut.rs +++ b/hugr-core/src/extension/resolution/types_mut.rs @@ -69,7 +69,7 @@ pub fn resolve_op_types_extensions( } OpType::LoadFunction(lf) => { resolve_signature_exts(node, lf.func_sig.body_mut(), extensions, used_extensions)?; - resolve_signature_exts(node, &mut lf.signature, extensions, used_extensions)?; + resolve_signature_exts(node, &mut lf.instantiation, extensions, used_extensions)?; } OpType::DFG(dfg) => { resolve_signature_exts(node, &mut dfg.signature, extensions, used_extensions)? diff --git a/hugr-core/src/ops/dataflow.rs b/hugr-core/src/ops/dataflow.rs index be406eb1a..093857df6 100644 --- a/hugr-core/src/ops/dataflow.rs +++ b/hugr-core/src/ops/dataflow.rs @@ -7,10 +7,10 @@ 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; +use proptest_derive::Arbitrary; /// Trait implemented by all dataflow operations. pub trait DataflowOpTrait { @@ -347,7 +347,7 @@ pub struct LoadFunction { /// The type arguments that instantiate `func_sig`. pub type_args: Vec, /// 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 { @@ -358,7 +358,10 @@ impl DataflowOpTrait for LoadFunction { } fn signature(&self) -> Cow<'_, Signature> { - Cow::Borrowed(&self.signature) + Cow::Owned(Signature::new( + type_row![], + Type::new_function(self.instantiation.clone()), + )) } fn static_input(&self) -> Option { @@ -377,11 +380,10 @@ impl LoadFunction { ) -> Result { let type_args: Vec<_> = 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, }) } @@ -410,12 +412,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(), }) } } diff --git a/hugr-py/src/hugr/_serialization/ops.py b/hugr-py/src/hugr/_serialization/ops.py index aa573cb64..b0e15f1c9 100644 --- a/hugr-py/src/hugr/_serialization/ops.py +++ b/hugr-py/src/hugr/_serialization/ops.py @@ -367,18 +367,12 @@ class LoadFunction(DataflowOp): op: Literal["LoadFunction"] = "LoadFunction" func_sig: PolyFuncType type_args: list[stys.TypeArg] - signature: FunctionType + instantiation: FunctionType def deserialize(self) -> ops.LoadFunc: - signature = self.signature.deserialize() - assert len(signature.input) == 0 - (f_ty,) = signature.output - assert isinstance( - f_ty, tys.FunctionType - ), "Expected single function type output" return ops.LoadFunc( self.func_sig.deserialize(), - f_ty, + self.instantiation.deserialize(), deser_it(self.type_args), ) diff --git a/hugr-py/src/hugr/ops.py b/hugr-py/src/hugr/ops.py index 4e9b2d961..682b2afb7 100644 --- a/hugr-py/src/hugr/ops.py +++ b/hugr-py/src/hugr/ops.py @@ -1237,7 +1237,7 @@ def _to_serial(self, parent: Node) -> sops.LoadFunction: parent=parent.idx, func_sig=self.signature._to_serial(), type_args=ser_it(self.type_args), - signature=self.outer_signature()._to_serial(), + instantiation=self.instantiation._to_serial(), ) def outer_signature(self) -> tys.FunctionType: diff --git a/specification/schema/hugr_schema_live.json b/specification/schema/hugr_schema_live.json index 26c2f3bfc..5df9aa9fb 100644 --- a/specification/schema/hugr_schema_live.json +++ b/specification/schema/hugr_schema_live.json @@ -1054,7 +1054,7 @@ "title": "Type Args", "type": "array" }, - "signature": { + "instantiation": { "$ref": "#/$defs/FunctionType" } }, @@ -1062,7 +1062,7 @@ "parent", "func_sig", "type_args", - "signature" + "instantiation" ], "title": "LoadFunction", "type": "object" diff --git a/specification/schema/hugr_schema_strict_live.json b/specification/schema/hugr_schema_strict_live.json index 3ae0e3c28..9a28e6397 100644 --- a/specification/schema/hugr_schema_strict_live.json +++ b/specification/schema/hugr_schema_strict_live.json @@ -1054,7 +1054,7 @@ "title": "Type Args", "type": "array" }, - "signature": { + "instantiation": { "$ref": "#/$defs/FunctionType" } }, @@ -1062,7 +1062,7 @@ "parent", "func_sig", "type_args", - "signature" + "instantiation" ], "title": "LoadFunction", "type": "object" diff --git a/specification/schema/testing_hugr_schema_live.json b/specification/schema/testing_hugr_schema_live.json index 7696790dc..c7e80644e 100644 --- a/specification/schema/testing_hugr_schema_live.json +++ b/specification/schema/testing_hugr_schema_live.json @@ -1054,7 +1054,7 @@ "title": "Type Args", "type": "array" }, - "signature": { + "instantiation": { "$ref": "#/$defs/FunctionType" } }, @@ -1062,7 +1062,7 @@ "parent", "func_sig", "type_args", - "signature" + "instantiation" ], "title": "LoadFunction", "type": "object" diff --git a/specification/schema/testing_hugr_schema_strict_live.json b/specification/schema/testing_hugr_schema_strict_live.json index 0490b157d..08e37e707 100644 --- a/specification/schema/testing_hugr_schema_strict_live.json +++ b/specification/schema/testing_hugr_schema_strict_live.json @@ -1054,7 +1054,7 @@ "title": "Type Args", "type": "array" }, - "signature": { + "instantiation": { "$ref": "#/$defs/FunctionType" } }, @@ -1062,7 +1062,7 @@ "parent", "func_sig", "type_args", - "signature" + "instantiation" ], "title": "LoadFunction", "type": "object"