Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mojo/stdlib/src/base64/_b64encode.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ fn load_incomplete_simd[
DType.uint8, simd_width
]:
var result = SIMD[DType.uint8, simd_width](0)
var tmp_buffer_pointer = UnsafePointer.address_of(result).bitcast[UInt8]()
var tmp_buffer_pointer = UnsafePointer(to=result).bitcast[UInt8]()
memcpy(dest=tmp_buffer_pointer, src=pointer, count=nb_of_elements_to_load)
return result

Expand Down
4 changes: 2 additions & 2 deletions mojo/stdlib/src/builtin/io.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ struct _fdopen[mode: StaticString = "a"]:
Int,
OpaquePointer,
](
UnsafePointer.address_of(buffer),
UnsafePointer.address_of(UInt64(0)),
UnsafePointer(to=buffer),
UnsafePointer(to=UInt64(0)),
ord(delimiter),
self.handle,
)
Expand Down
8 changes: 4 additions & 4 deletions mojo/stdlib/src/builtin/list_literal.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ struct VariadicListMem[
var tmp = value
# We need to bitcast different argument conventions to a consistent
# representation. This is ugly but effective.
self.value = UnsafePointer.address_of(tmp).bitcast[Self._mlir_type]()[]
self.value = UnsafePointer(to=tmp).bitcast[Self._mlir_type]()[]
self._is_owned = False

# Provide support for variadics of *owned* arguments. The reference will
Expand All @@ -363,7 +363,7 @@ struct VariadicListMem[
var tmp = value
# We need to bitcast different argument conventions to a consistent
# representation. This is ugly but effective.
self.value = UnsafePointer.address_of(tmp).bitcast[Self._mlir_type]()[]
self.value = UnsafePointer(to=tmp).bitcast[Self._mlir_type]()[]
self._is_owned = True

@always_inline
Expand Down Expand Up @@ -395,7 +395,7 @@ struct VariadicListMem[
# destroy in backwards order to match how arguments are normally torn
# down when CheckLifetimes is left to its own devices.
for i in reversed(range(len(self))):
UnsafePointer.address_of(self[i]).destroy_pointee()
UnsafePointer(to=self[i]).destroy_pointee()

# ===-------------------------------------------------------------------===#
# Trait implementations
Expand Down Expand Up @@ -522,7 +522,7 @@ struct VariadicPack[

@parameter
for i in reversed(range(Self.__len__())):
UnsafePointer.address_of(self[i]).destroy_pointee()
UnsafePointer(to=self[i]).destroy_pointee()

# ===-------------------------------------------------------------------===#
# Trait implementations
Expand Down
4 changes: 2 additions & 2 deletions mojo/stdlib/src/builtin/simd.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -1919,7 +1919,7 @@ struct SIMD[dtype: DType, size: Int](
if is_big_endian() != big_endian:
value = byte_swap(value)

var ptr = UnsafePointer.address_of(value)
var ptr = UnsafePointer(to=value)
var array = InlineArray[Byte, dtype.sizeof()](fill=0)

memcpy(array.unsafe_ptr(), ptr.bitcast[Byte](), dtype.sizeof())
Expand Down Expand Up @@ -2020,7 +2020,7 @@ struct SIMD[dtype: DType, size: Int](
__get_mvalue_as_litref(array)
)

var array_ptr = UnsafePointer.address_of(array)
var array_ptr = UnsafePointer(to=array)

@parameter
for idx in range(output_size):
Expand Down
14 changes: 7 additions & 7 deletions mojo/stdlib/src/builtin/tuple.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ struct Tuple[*element_types: CollectionElement](Sized, CollectionElement):
# Move each element into the tuple storage.
@parameter
for i in range(Self.__len__()):
UnsafePointer.address_of(storage[i]).move_pointee_into(
UnsafePointer.address_of(self[i])
UnsafePointer(to=storage[i]).move_pointee_into(
UnsafePointer(to=self[i])
)

# Do not destroy the elements when 'storage' goes away.
Expand All @@ -90,7 +90,7 @@ struct Tuple[*element_types: CollectionElement](Sized, CollectionElement):
# trivial and won't do anything.
@parameter
for i in range(Self.__len__()):
UnsafePointer.address_of(self[i]).destroy_pointee()
UnsafePointer(to=self[i]).destroy_pointee()

@always_inline("nodebug")
fn __copyinit__(out self, existing: Self):
Expand All @@ -106,7 +106,7 @@ struct Tuple[*element_types: CollectionElement](Sized, CollectionElement):

@parameter
for i in range(Self.__len__()):
UnsafePointer.address_of(self[i]).init_pointee_copy(existing[i])
UnsafePointer(to=self[i]).init_pointee_copy(existing[i])

@always_inline
fn copy(self) -> Self:
Expand All @@ -131,8 +131,8 @@ struct Tuple[*element_types: CollectionElement](Sized, CollectionElement):

@parameter
for i in range(Self.__len__()):
UnsafePointer.address_of(existing[i]).move_pointee_into(
UnsafePointer.address_of(self[i])
UnsafePointer(to=existing[i]).move_pointee_into(
UnsafePointer(to=self[i])
)
# Note: The destructor on `existing` is auto-disabled in a moveinit.

Expand Down Expand Up @@ -175,7 +175,7 @@ struct Tuple[*element_types: CollectionElement](Sized, CollectionElement):
"""
# Return a reference to an element at the specified index, propagating
# mutability of self.
var storage_kgen_ptr = UnsafePointer.address_of(self.storage).address
var storage_kgen_ptr = UnsafePointer(to=self.storage).address

# KGenPointer to the element.
var elt_kgen_ptr = __mlir_op.`kgen.pack.gep`[index = idx.value](
Expand Down
2 changes: 1 addition & 1 deletion mojo/stdlib/src/collections/deque.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ struct Deque[ElementType: CollectionElement](

for i in range(args_length):
dst = self._data + i
UnsafePointer.address_of(elements[i]).move_pointee_into(dst)
UnsafePointer(to=elements[i]).move_pointee_into(dst)

# Do not destroy the elements when their backing storage goes away.
__disable_del elements
Expand Down
2 changes: 1 addition & 1 deletion mojo/stdlib/src/collections/dict.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ struct _DictValueIter[
# Cast through a pointer to grant additional mutability because
# _DictEntryIter.next erases it.
return Self.ref_type(
to=UnsafePointer.address_of(entry_ref[].value).origin_cast[
to=UnsafePointer(to=entry_ref[].value).origin_cast[
origin=dict_origin
]()[]
)
Expand Down
6 changes: 3 additions & 3 deletions mojo/stdlib/src/collections/inline_array.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ struct InlineArray[
# Move each element into the array storage.
@parameter
for i in range(size):
UnsafePointer.address_of(storage[i]).move_pointee_into(ptr)
UnsafePointer(to=storage[i]).move_pointee_into(ptr)
ptr += 1

# Do not destroy the elements when their backing storage goes away.
Expand Down Expand Up @@ -462,7 +462,7 @@ struct InlineArray[
size,
)
var ptr = __mlir_op.`pop.array.gep`(
UnsafePointer.address_of(self._array).address,
UnsafePointer(to=self._array).address,
i,
)
return UnsafePointer(ptr)[]
Expand Down Expand Up @@ -499,7 +499,7 @@ struct InlineArray[
print(ptr[0]) # Prints 1
```
"""
return UnsafePointer.address_of(self._array).bitcast[Self.ElementType]()
return UnsafePointer(to=self._array).bitcast[Self.ElementType]()

@always_inline
fn __contains__[
Expand Down
8 changes: 4 additions & 4 deletions mojo/stdlib/src/collections/linked_list.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ struct LinkedList[
var length = len(elements)

for i in range(length):
var src = UnsafePointer.address_of(elements[i])
var src = UnsafePointer(to=elements[i])
var node = Self._NodePointer.alloc(1)
if not node:
abort("Out of memory")
var dst = UnsafePointer.address_of(node[].value)
var dst = UnsafePointer(to=node[].value)
src.move_pointee_into(dst)
node[].next = Self._NodePointer()
node[].prev = self._tail
Expand Down Expand Up @@ -258,7 +258,7 @@ struct LinkedList[
var addr = Self._NodePointer.alloc(1)
if not addr:
abort("Out of memory")
var value_ptr = UnsafePointer.address_of(addr[].value)
var value_ptr = UnsafePointer(to=addr[].value)
value_ptr.init_pointee_move(value^)
addr[].prev = self._tail
addr[].next = Self._NodePointer()
Expand Down Expand Up @@ -512,7 +512,7 @@ struct LinkedList[
var node = Self._NodePointer.alloc(1)
if not node:
abort("Out of memory")
var data = UnsafePointer.address_of(node[].value)
var data = UnsafePointer(to=node[].value)
data[] = elem^
node[].next = next
node[].prev = current
Expand Down
4 changes: 2 additions & 2 deletions mojo/stdlib/src/collections/list.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False](
self = Self(capacity=length)

for i in range(length):
var src = UnsafePointer.address_of(elements[i])
var src = UnsafePointer(to=elements[i])
var dest = self.data + i

src.move_pointee_into(dest)
Expand Down Expand Up @@ -646,7 +646,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False](
"""
debug_assert(count <= value.size, "count must be <= value.size")
self.reserve(self._len + count)
var v_ptr = UnsafePointer.address_of(value).bitcast[Scalar[D]]()
var v_ptr = UnsafePointer(to=value).bitcast[Scalar[D]]()
memcpy(self._unsafe_next_uninit_ptr(), v_ptr, count)
self._len += count

Expand Down
2 changes: 1 addition & 1 deletion mojo/stdlib/src/memory/arc.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ struct ArcPointer[T: Movable](
The `UnsafePointer` to the pointee.
"""
# TODO: consider removing this method.
return UnsafePointer.address_of(self._inner[].payload)
return UnsafePointer(to=self._inner[].payload)

fn count(self) -> UInt64:
"""Count the amount of current references.
Expand Down
2 changes: 1 addition & 1 deletion mojo/stdlib/src/memory/maybe_uninitialized.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ struct UnsafeMaybeUninitialized[ElementType: AnyType](
Returns:
A pointer to the underlying element.
"""
return UnsafePointer.address_of(self._array).bitcast[Self.ElementType]()
return UnsafePointer(to=self._array).bitcast[Self.ElementType]()

@always_inline
fn assume_initialized_destroy(mut self):
Expand Down
6 changes: 2 additions & 4 deletions mojo/stdlib/src/memory/pointer.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,7 @@ struct Pointer[
Returns:
True if the two pointers are equal and False otherwise.
"""
return UnsafePointer.address_of(self[]) == UnsafePointer.address_of(
rhs[]
)
return UnsafePointer(to=self[]) == UnsafePointer(to=rhs[])

@__unsafe_disable_nested_origin_exclusivity
@always_inline("nodebug")
Expand All @@ -464,4 +462,4 @@ struct Pointer[
Returns:
The string representation of the Pointer.
"""
return String(UnsafePointer.address_of(self[]))
return String(UnsafePointer(to=self[]))
2 changes: 1 addition & 1 deletion mojo/stdlib/src/memory/span.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ struct Span[
"""

self._data = (
UnsafePointer.address_of(array)
UnsafePointer(to=array)
.bitcast[T]()
.address_space_cast[address_space]()
)
Expand Down
12 changes: 6 additions & 6 deletions mojo/stdlib/src/os/atomic.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ struct Atomic[dtype: DType, *, scope: StaticString = ""]:
Returns:
The original value before addition.
"""
var value_addr = UnsafePointer.address_of(self.value)
var value_addr = UnsafePointer(to=self.value)
return Self._fetch_add(value_addr, rhs)

@always_inline
Expand Down Expand Up @@ -195,7 +195,7 @@ struct Atomic[dtype: DType, *, scope: StaticString = ""]:
Returns:
The original value before subtraction.
"""
var value_addr = UnsafePointer.address_of(self.value.value)
var value_addr = UnsafePointer(to=self.value.value)
return __mlir_op.`pop.atomic.rmw`[
bin_op = __mlir_attr.`#pop<bin_op sub>`,
ordering = __mlir_attr.`#pop<atomic_ordering seq_cst>`,
Expand Down Expand Up @@ -239,15 +239,15 @@ struct Atomic[dtype: DType, *, scope: StaticString = ""]:
@parameter
if dtype.is_integral():
return _compare_exchange_weak_integral_impl[scope=scope](
UnsafePointer.address_of(self.value), expected, desired
UnsafePointer(to=self.value), expected, desired
)

# For the floating point case, we need to bitcast the floating point
# values to their integral representation and perform the atomic
# operation on that.

alias integral_type = _integral_type_of[dtype]()
var value_integral_addr = UnsafePointer.address_of(self.value).bitcast[
var value_integral_addr = UnsafePointer(to=self.value).bitcast[
Scalar[integral_type]
]()
var expected_integral = bitcast[integral_type](expected)
Expand Down Expand Up @@ -294,7 +294,7 @@ struct Atomic[dtype: DType, *, scope: StaticString = ""]:
"""
constrained[dtype.is_numeric(), "the input type must be arithmetic"]()

Self.max(UnsafePointer.address_of(self.value), rhs)
Self.max(UnsafePointer(to=self.value), rhs)

@staticmethod
@always_inline
Expand Down Expand Up @@ -335,7 +335,7 @@ struct Atomic[dtype: DType, *, scope: StaticString = ""]:

constrained[dtype.is_numeric(), "the input type must be arithmetic"]()

Self.min(UnsafePointer.address_of(self.value), rhs)
Self.min(UnsafePointer(to=self.value), rhs)


# ===-----------------------------------------------------------------------===#
Expand Down
2 changes: 1 addition & 1 deletion mojo/stdlib/src/python/_bindings.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn python_type_object[
)

# Construct a Python 'type' object from our type spec.
var type_obj = cpython.PyType_FromSpec(UnsafePointer.address_of(type_spec))
var type_obj = cpython.PyType_FromSpec(UnsafePointer(to=type_spec))

if type_obj.is_null():
Python.throw_python_exception_if_error_state(cpython)
Expand Down
16 changes: 8 additions & 8 deletions mojo/stdlib/src/python/_cpython.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ struct PyObjectPtr(CollectionElement):
var mojo_obj_ptr = self.unchecked_cast_to_mojo_object[T]()

# TODO(MSTDL-950): Should use something like `addr_of!`
return UnsafePointer[T].address_of(mojo_obj_ptr[].mojo_value)
return UnsafePointer[T](to=mojo_obj_ptr[].mojo_value)

fn is_null(self) -> Bool:
"""Check if the pointer is null.
Expand Down Expand Up @@ -1030,12 +1030,12 @@ struct CPython:
var key = PyObjectPtr()
var value = PyObjectPtr()
var v = p
var position = UnsafePointer[Int].address_of(v)
var position = UnsafePointer[Int](to=v)
var result = self.lib.call["PyDict_Next", c_int](
dictionary,
position,
UnsafePointer.address_of(key),
UnsafePointer.address_of(value),
UnsafePointer(to=key),
UnsafePointer(to=value),
)

self.log(
Expand Down Expand Up @@ -1777,7 +1777,7 @@ struct CPython:
var length = Int(0)
var ptr = self.lib.call[
"PyUnicode_AsUTF8AndSize", UnsafePointer[c_char]
](py_object, UnsafePointer.address_of(length)).bitcast[UInt8]()
](py_object, UnsafePointer(to=length)).bitcast[UInt8]()
return StringSlice[__origin_of(py_object.unsized_obj_ptr.origin)](
ptr=ptr, length=length
)
Expand Down Expand Up @@ -1807,9 +1807,9 @@ struct CPython:
var traceback = PyObjectPtr()

self.lib.call["PyErr_Fetch"](
UnsafePointer.address_of(type),
UnsafePointer.address_of(value),
UnsafePointer.address_of(traceback),
UnsafePointer(to=type),
UnsafePointer(to=value),
UnsafePointer(to=traceback),
)
var r = value

Expand Down
2 changes: 1 addition & 1 deletion mojo/stdlib/src/python/python_object.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,7 @@ struct PythonObject(
An `UnsafePointer` for the underlying Python data.
"""
var tmp = Int(self)
var result = UnsafePointer.address_of(tmp).bitcast[
var result = UnsafePointer(to=tmp).bitcast[
UnsafePointer[Scalar[dtype]]
]()[]
_ = tmp
Expand Down
Loading