Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -721,10 +721,7 @@ def insert_drops(hugr: Hugr[OpVarCov]) -> None:
data = hugr[node]
# Iterating over `node.outputs()` doesn't work reliably since it sometimes
# raises an `IncompleteOp` exception. Instead, we query the number of out ports
# and look them up by index. However, this method is *also* broken when
# inspecting `FuncDefn` nodes due to https://github.com/quantinuum/hugr/issues/2438.
if isinstance(data.op, ops.FuncDefn):
continue
# and look them up by index.
for i in range(hugr.num_out_ports(node)):
port = node.out(i)
kind = hugr.port_kind(port)
Expand Down
20 changes: 20 additions & 0 deletions tests/integration/test_drop_insertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,23 @@ def main() -> AffineTy:
hugr = main.compile_function()
assert num_drops(hugr) == 4
validate(hugr)


def test_drop_with_multiple_funcdefns(validate):
"""Regression test for https://github.com/quantinuum/guppylang/issues/1516.

Ensures insert_drops correctly iterates over FuncDefn nodes instead of
skipping them, and still inserts the right number of drops.
"""

@guppy
def helper() -> AffineTy:
return make()

@guppy
def main(x: AffineTy @ owned) -> None:
pass # x is dropped here

hugr = main.compile_function()
assert num_drops(hugr) == 1
validate(hugr)
Loading