Skip to content

Commit

Permalink
[stdlib] Remove Intable from StaticTuple.__getitem__
Browse files Browse the repository at this point in the history
As mentioned at
#2337 (comment), we've
pivoted a bit and moved away from `Intable` for offsets in `__getitem__`
implementations now that we have `Indexer`.  Fix this last use of `__getitem__`
that works on a `Intable` type to use `Int` explicitly.

MODULAR_ORIG_COMMIT_REV_ID: 87e2eca61466072aa0e36741296cb1d8fbc0eaed
  • Loading branch information
JoeLoser authored and modularbot committed Jul 10, 2024
1 parent 80ab61c commit 41f34c8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
12 changes: 4 additions & 8 deletions stdlib/src/utils/static_tuple.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -193,25 +193,21 @@ struct StaticTuple[element_type: AnyTrivialRegType, size: Int](Sized):
self = tmp

@always_inline("nodebug")
fn __getitem__[intable: Intable](self, index: intable) -> Self.element_type:
fn __getitem__(self, idx: Int) -> Self.element_type:
"""Returns the value of the tuple at the given dynamic index.
Parameters:
intable: The intable type.
Args:
index: The index into the tuple.
idx: The index into the tuple.
Returns:
The value at the specified position.
"""
var offset = int(index)
debug_assert(offset < size, "index must be within bounds")
debug_assert(idx < size, "index must be within bounds")
# Copy the array so we can get its address, because we can't take the
# address of 'self' in a non-mutating method.
var arrayCopy = self.array
var ptr = __mlir_op.`pop.array.gep`(
UnsafePointer.address_of(arrayCopy).address, offset.value
UnsafePointer.address_of(arrayCopy).address, idx.value
)
var result = Pointer(ptr)[]
_ = arrayCopy
Expand Down
1 change: 0 additions & 1 deletion stdlib/test/utils/test_tuple.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def test_static_tuple():

assert_equal(tup3[0], 1)
assert_equal(tup3[Int(0)], 1)
assert_equal(tup3[Int64(0)], 1)


def test_static_int_tuple():
Expand Down

0 comments on commit 41f34c8

Please sign in to comment.