From 41f34c89379fef5d29ef7bb8e2187c59979b1147 Mon Sep 17 00:00:00 2001 From: Joe Loser Date: Mon, 8 Jul 2024 16:03:39 -0500 Subject: [PATCH] [stdlib] Remove `Intable` from `StaticTuple.__getitem__` As mentioned at https://github.com/modularml/mojo/issues/2337#issuecomment-2212522543, 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 --- stdlib/src/utils/static_tuple.mojo | 12 ++++-------- stdlib/test/utils/test_tuple.mojo | 1 - 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/stdlib/src/utils/static_tuple.mojo b/stdlib/src/utils/static_tuple.mojo index d4974c1329..bd034a5ab6 100644 --- a/stdlib/src/utils/static_tuple.mojo +++ b/stdlib/src/utils/static_tuple.mojo @@ -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 diff --git a/stdlib/test/utils/test_tuple.mojo b/stdlib/test/utils/test_tuple.mojo index b35a6ae4f2..2f2ac70e3b 100644 --- a/stdlib/test/utils/test_tuple.mojo +++ b/stdlib/test/utils/test_tuple.mojo @@ -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():