Skip to content

Commit

Permalink
[External] [stdlib] Move tuple.mojo off unroll (#42022)
Browse files Browse the repository at this point in the history
[External] [stdlib] Move `tuple.mojo` off `unroll`

Remove the use of the `unroll` function from `tuple.mojo` in favour of
`@parameter if`.

Co-authored-by: soraros <soraros@users.noreply.github.com>
Closes #3055
MODULAR_ORIG_COMMIT_REV_ID: baea5b29de0ece95a79023028832195891fd3af8
  • Loading branch information
soraros authored and modularbot committed Jun 27, 2024
1 parent 9187a0e commit 4e76e84
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions stdlib/src/builtin/tuple.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,14 @@ struct Tuple[*element_types: Movable](Sized, Movable):
__get_mvalue_as_litref(self.storage)
)

# Move each element into the tuple storage.
@parameter
fn initialize_elt[idx: Int]():
UnsafePointer.address_of(storage[idx]).move_pointee_into(
UnsafePointer.address_of(self[idx])
for i in range(Self.__len__()):
UnsafePointer.address_of(storage[i]).move_pointee_into(
UnsafePointer.address_of(self[i])
)

# Move each element into the tuple storage.
unroll[initialize_elt, Self.__len__()]()

# Mark the elements as already destroyed.
# Mark the elements as destroyed.
storage._is_owned = False

fn __del__(owned self):
Expand All @@ -89,10 +87,8 @@ struct Tuple[*element_types: Movable](Sized, Movable):
# Run the destructor on each member, the destructor of !kgen.pack is
# trivial and won't do anything.
@parameter
fn destroy_elt[idx: Int]():
UnsafePointer.address_of(self[idx]).destroy_pointee()

unroll[destroy_elt, Self.__len__()]()
for i in range(Self.__len__()):
UnsafePointer.address_of(self[i]).destroy_pointee()

@always_inline("nodebug")
fn __moveinit__(inout self, owned existing: Self):
Expand All @@ -107,13 +103,11 @@ struct Tuple[*element_types: Movable](Sized, Movable):
)

@parameter
fn initialize_elt[idx: Int]():
UnsafePointer.address_of(existing[idx]).move_pointee_into(
UnsafePointer.address_of(self[idx])
for i in range(Self.__len__()):
UnsafePointer.address_of(existing[i]).move_pointee_into(
UnsafePointer.address_of(self[i])
)

unroll[initialize_elt, Self.__len__()]()

@always_inline
@staticmethod
fn __len__() -> Int:
Expand Down

0 comments on commit 4e76e84

Please sign in to comment.