Skip to content

Commit 1ad450f

Browse files
authored
fix: Fixed two bugs in import/export of function operations (#2324)
This PR fixes two bugs: The first bug exported the type `LoadFunc` nodes incorrectly from Python. The second imported the type of `core.call_indirect` operations incorrectly.
1 parent cae9ab1 commit 1ad450f

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

hugr-core/src/import.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,8 +966,10 @@ impl<'a> Context<'a> {
966966
node_data: &'a table::Node<'a>,
967967
parent: Node,
968968
) -> Result<Node, ImportError> {
969-
if let Some([_, _]) = self.match_symbol(operation, model::CORE_CALL_INDIRECT)? {
970-
let signature = self.get_node_signature(node_id)?;
969+
if let Some([inputs, outputs]) = self.match_symbol(operation, model::CORE_CALL_INDIRECT)? {
970+
let inputs = self.import_type_row(inputs)?;
971+
let outputs = self.import_type_row(outputs)?;
972+
let signature = Signature::new(inputs, outputs);
971973
let optype = OpType::CallIndirect(CallIndirect { signature });
972974
let node = self.make_node(node_id, optype, parent)?;
973975
return Ok(node);

hugr-py/src/hugr/model/export.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ def export_node(self, node: Node) -> model.Node | None:
213213
)
214214

215215
case LoadFunc() as op:
216-
signature = op.instantiation.to_model()
216+
signature = op.outer_signature().to_model()
217+
instantiation = op.instantiation.to_model()
217218
func_args = cast(
218219
list[model.Term], [type.to_model() for type in op.type_args]
219220
)
@@ -227,10 +228,10 @@ def export_node(self, node: Node) -> model.Node | None:
227228

228229
return model.Node(
229230
operation=model.CustomOp(
230-
model.Apply("core.load_const", [signature, func])
231+
model.Apply("core.load_const", [instantiation, func])
231232
),
232233
signature=signature,
233-
inputs=inputs,
234+
inputs=[],
234235
outputs=outputs,
235236
meta=meta,
236237
)

0 commit comments

Comments
 (0)