Skip to content

Commit

Permalink
[stdlib] Use UnsafePointer in simd.mojo and vector.mojo
Browse files Browse the repository at this point in the history
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
  • Loading branch information
gabrieldemarmiesse committed Apr 25, 2024
1 parent 684efe5 commit 8291822
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion stdlib/src/builtin/simd.mojo
Expand Up @@ -1461,7 +1461,7 @@ struct SIMD[type: DType, size: Int = simdwidthof[type]()](
"invalid index in the shuffle operation",
]()
var ptr = __mlir_op.`pop.array.gep`(
Pointer.address_of(array).address, idx.value
UnsafePointer.address_of(array).value, idx.value
)
__mlir_op.`pop.store`(val, ptr)

Expand Down
16 changes: 8 additions & 8 deletions stdlib/src/collections/vector.mojo
Expand Up @@ -19,7 +19,7 @@ from collections.vector import InlinedFixedVector
```
"""

from memory import Pointer, Reference
from memory import UnsafePointer, Reference

from utils import StaticTuple

Expand All @@ -32,13 +32,13 @@ from utils import StaticTuple
struct _VecIter[
type: AnyRegType,
vec_type: AnyRegType,
deref: fn (Pointer[vec_type], Int) -> type,
deref: fn (UnsafePointer[vec_type], Int) -> type,
](Sized):
"""Iterator for any random-access container"""

var i: Int
var size: Int
var vec: Pointer[vec_type]
var vec: UnsafePointer[vec_type]

fn __next__(inout self) -> type:
self.i += 1
Expand Down Expand Up @@ -100,7 +100,7 @@ struct InlinedFixedVector[
alias static_data_type = StaticTuple[type, size]
var static_data: Self.static_data_type
"""The underlying static storage, used for small vectors."""
var dynamic_data: Pointer[type]
var dynamic_data: UnsafePointer[type]
"""The underlying dynamic storage, used to grow large vectors."""
var current_size: Int
"""The number of elements in the vector."""
Expand All @@ -117,9 +117,9 @@ struct InlinedFixedVector[
capacity: The requested maximum capacity of the vector.
"""
self.static_data = Self.static_data_type() # Undef initialization
self.dynamic_data = Pointer[type]()
self.dynamic_data = UnsafePointer[type]()
if capacity > Self.static_size:
self.dynamic_data = Pointer[type].alloc(capacity - size)
self.dynamic_data = UnsafePointer[type].alloc(capacity - size)
self.current_size = 0
self.capacity = capacity

Expand Down Expand Up @@ -231,7 +231,7 @@ struct InlinedFixedVector[
self.current_size = 0

@staticmethod
fn _deref_iter_impl(selfptr: Pointer[Self], i: Int) -> type:
fn _deref_iter_impl(selfptr: UnsafePointer[Self], i: Int, /) -> type:
return selfptr[][i]

alias _iterator = _VecIter[type, Self, Self._deref_iter_impl]
Expand All @@ -243,5 +243,5 @@ struct InlinedFixedVector[
An iterator to the start of the vector.
"""
return Self._iterator(
0, self.current_size, Reference(self).get_legacy_pointer()
0, self.current_size, UnsafePointer(Reference(self))
)

0 comments on commit 8291822

Please sign in to comment.