diff --git a/guppylang/compiler/stmt_compiler.py b/guppylang/compiler/stmt_compiler.py index 9132268c..fabe64b4 100644 --- a/guppylang/compiler/stmt_compiler.py +++ b/guppylang/compiler/stmt_compiler.py @@ -95,9 +95,9 @@ def _assign_tuple(self, lhs: TupleUnpack, port: Wire) -> None: starred_ports = ( ports[len(left) : -len(right)] if right else ports[len(left) :] ) - opt_ty = ht.Option(get_element_type(array_ty).to_hugr()) - opts = [self.builder.add_op(ops.Tag(1, opt_ty), p) for p in starred_ports] - array = self.builder.add_op(array_new(opt_ty, len(opts)), *opts) + elt = get_element_type(array_ty).to_hugr() + opts = [self.builder.add_op(ops.Some(elt), p) for p in starred_ports] + array = self.builder.add_op(array_new(ht.Option(elt), len(opts)), *opts) self._assign(starred, array) @_assign.register diff --git a/guppylang/std/_internal/compiler/array.py b/guppylang/std/_internal/compiler/array.py index b3195874..ecb298b3 100644 --- a/guppylang/std/_internal/compiler/array.py +++ b/guppylang/std/_internal/compiler/array.py @@ -166,11 +166,12 @@ def build_classical_array(self, elems: list[Wire]) -> Wire: def build_linear_array(self, elems: list[Wire]) -> Wire: """Lowers a call to `array.__new__` for linear arrays.""" - elem_opt_ty = ht.Option(self.elem_ty) elem_opts = [ - self.builder.add_op(ops.Tag(1, elem_opt_ty), elem) for elem in elems + self.builder.add_op(ops.Some(self.elem_ty), elem) for elem in elems ] - return self.builder.add_op(array_new(elem_opt_ty, len(elems)), *elem_opts) + return self.builder.add_op( + array_new(ht.Option(self.elem_ty), len(elems)), *elem_opts + ) def compile(self, args: list[Wire]) -> list[Wire]: if self.elem_ty.type_bound() == ht.TypeBound.Any: @@ -232,7 +233,7 @@ def build_classical_setitem( # See https://github.com/CQCL/guppylang/issues/629 elem_opt_ty = ht.Option(self.elem_ty) idx = self.builder.add_op(convert_itousize(), idx) - elem_opt = self.builder.add_op(ops.Tag(1, elem_opt_ty), elem) + elem_opt = self.builder.add_op(ops.Some(self.elem_ty), elem) result = self.builder.add_op( array_set(elem_opt_ty, self.length), array, idx, elem_opt ) @@ -246,7 +247,7 @@ def build_linear_setitem( """Lowers a call to `array.__setitem__` for linear arrays.""" # Embed the element into an optional elem_opt_ty = ht.Option(self.elem_ty) - elem = self.builder.add_op(ops.Tag(1, elem_opt_ty), elem) + elem = self.builder.add_op(ops.Some(self.elem_ty), elem) idx = self.builder.add_op(convert_itousize(), idx) result = self.builder.add_op( array_set(elem_opt_ty, self.length), array, idx, elem diff --git a/guppylang/std/_internal/compiler/list.py b/guppylang/std/_internal/compiler/list.py index 27414d5e..ccccef0d 100644 --- a/guppylang/std/_internal/compiler/list.py +++ b/guppylang/std/_internal/compiler/list.py @@ -181,7 +181,7 @@ def build_linear_setitem( """Lowers a call to `array.__setitem__` for linear arrays.""" # Embed the element into an optional elem_opt_ty = ht.Option(elem_ty) - elem = self.builder.add_op(ops.Tag(1, elem_opt_ty), elem) + elem = self.builder.add_op(ops.Some(elem_ty), elem) idx = self.builder.add_op(convert_itousize(), idx) list_wire, result = self.builder.add_op( list_set(elem_opt_ty), list_wire, idx, elem @@ -274,7 +274,7 @@ def build_linear_push( """Lowers a call to `list.push` for linear lists.""" # Wrap element into an optional elem_opt_ty = ht.Option(elem_ty) - elem_opt = self.builder.add_op(ops.Tag(1, elem_opt_ty), elem) + elem_opt = self.builder.add_op(ops.Some(elem_ty), elem) list_wire = self.builder.add_op(list_push(elem_opt_ty), list_wire, elem_opt) return CallReturnWires(regular_returns=[], inout_returns=[list_wire]) @@ -337,6 +337,6 @@ def _list_new_linear( lst = builder.load(ListVal([], elem_ty=elem_opt_ty)) push_op = list_push(elem_opt_ty) for elem in args: - elem_opt = builder.add_op(ops.Tag(1, elem_opt_ty), elem) + elem_opt = builder.add_op(ops.Some(elem_type), elem) lst = builder.add_op(push_op, lst, elem_opt) return lst