diff --git a/tests/integration/test_array.py b/tests/integration/test_array.py index 9973539a..66e76731 100644 --- a/tests/integration/test_array.py +++ b/tests/integration/test_array.py @@ -3,7 +3,7 @@ from guppylang.decorator import guppy from guppylang.module import GuppyModule -from guppylang.std.builtins import array, owned, mem_swap +from guppylang.std.builtins import array, owned, mem_swap, py from tests.util import compile_guppy from guppylang.std.quantum import qubit, discard @@ -113,7 +113,7 @@ def test_linear_subscript(validate): def foo(q: qubit) -> None: ... @guppy(module) - def main(qs: array[qubit, 42] @owned, i: int) -> array[qubit, 42]: + def main(qs: array[qubit, 42] @ owned, i: int) -> array[qubit, 42]: foo(qs[i]) return qs @@ -142,7 +142,7 @@ def test_multi_subscripts(validate): def foo(q1: qubit, q2: qubit) -> None: ... @guppy(module) - def main(qs: array[qubit, 42] @owned) -> array[qubit, 42]: + def main(qs: array[qubit, 42] @ owned) -> array[qubit, 42]: foo(qs[0], qs[1]) foo(qs[0], qs[0]) # Will panic at runtime return qs @@ -163,7 +163,7 @@ class S: def foo(q1: qubit, q2: qubit) -> None: ... @guppy(module) - def main(ss: array[S, 10] @owned) -> array[S, 10]: + def main(ss: array[S, 10] @ owned) -> array[S, 10]: # This will panic at runtime :( # To make this work, we would need to replace the qubits in the struct # with `qubit | None` and write back `None` after `q1` has been extracted... @@ -181,12 +181,10 @@ def test_nested_subscripts(validate): def foo(q: qubit) -> None: ... @guppy.declare(module) - def bar( - q1: qubit, q2: qubit, q3: qubit, q4: qubit - ) -> None: ... + def bar(q1: qubit, q2: qubit, q3: qubit, q4: qubit) -> None: ... @guppy(module) - def main(qs: array[array[qubit, 13], 42] @owned) -> array[array[qubit, 13], 42]: + def main(qs: array[array[qubit, 13], 42] @ owned) -> array[array[qubit, 13], 42]: foo(qs[0][0]) # The following should work *without* panicking at runtime! Accessing `qs[0][0]` # replaces one qubit with `None` but puts everything back into `qs` before @@ -221,7 +219,7 @@ class A: def foo(q1: qubit) -> None: ... @guppy(module) - def main(a: A @owned, i: int, j: int, k: int) -> A: + def main(a: A @ owned, i: int, j: int, k: int) -> A: foo(a.xs[i].ys[j][k].c) return a @@ -235,7 +233,7 @@ def test_generic_function(validate): n = guppy.nat_var("n", module=module) @guppy(module) - def foo(xs: array[T, n] @owned) -> array[T, n]: + def foo(xs: array[T, n] @ owned) -> array[T, n]: return xs @guppy(module) @@ -265,7 +263,7 @@ def test_exec_array(validate, run_int_fn): @guppy(module) def main() -> int: - a = array(1,2,3) + a = array(1, 2, 3) return a[0] + a[1] + a[2] package = module.compile() @@ -298,6 +296,7 @@ def test_mem_swap(validate): module = GuppyModule("test") module.load(qubit) + @guppy(module) def foo(x: qubit, y: qubit) -> None: mem_swap(x, y) @@ -310,3 +309,21 @@ def main() -> array[qubit, 2]: package = module.compile() validate(package) + + +# https://github.com/CQCL/hugr/issues/1826 +def test_array_const(validate, run_int_fn): + module = GuppyModule("test") + module.load_all(quantum) + + bools = [True, False] + + @guppy(module) + def main() -> int: + bs = py(bools) + return int(bs[0]) + + package = module.compile() + validate(package) + + run_int_fn(package, expected=1)