Skip to main content

struct

Reference

Defines a non-nullable safe reference.

Parameters

  • type (AnyType): Type of the underlying data.
  • is_mutable (i1): Whether the referenced data may be mutated through this.
  • lifetime (lifetime<is_mutable>): The lifetime of the reference.
  • address_space (AddressSpace): The address space of the referenced data.

Fields

  • value (!lit.ref<:trait<@stdlib::@builtin::@anytype::@AnyType> *"type", mut=is_mutable, lifetime, #lit.struct.extract<:@stdlib::@builtin::@int::@Int #lit.struct.extract<:@stdlib::@memory::@reference::@AddressSpace address_space, "_value">, "value">>): The underlying MLIR reference.

Implemented traits

AnyType, Copyable, Movable

Methods

__init__

__init__(inout self: Self, /, value: !lit.ref<:trait<_stdlib::_builtin::_anytype::_AnyType> *"type", mut=is_mutable, lifetime, #lit.struct.extract<:_stdlib::_builtin::_int::_Int #lit.struct.extract<:_stdlib::_memory::_reference::_AddressSpace address_space, "_value">, "value">>)

Constructs a Reference from the MLIR reference.

Args:

  • value (!lit.ref<:trait<_stdlib::_builtin::_anytype::_AnyType> *"type", mut=is_mutable, lifetime, #lit.struct.extract<:_stdlib::_builtin::_int::_Int #lit.struct.extract<:_stdlib::_memory::_reference::_AddressSpace address_space, "_value">, "value">>): The MLIR reference.

__refitem__

__refitem__(self: Self) -> !lit.ref<:trait<_stdlib::_builtin::_anytype::_AnyType> *"type", mut=is_mutable, lifetime, #lit.struct.extract<:_stdlib::_builtin::_int::_Int #lit.struct.extract<:_stdlib::_memory::_reference::_AddressSpace address_space, "_value">, "value">>

Enable subscript syntax ref[] to access the element.

Returns:

The MLIR reference for the Mojo compiler to use.

__mlir_ref__

__mlir_ref__(self: Self) -> !lit.ref<:trait<_stdlib::_builtin::_anytype::_AnyType> *"type", mut=is_mutable, lifetime, #lit.struct.extract<:_stdlib::_builtin::_int::_Int #lit.struct.extract<:_stdlib::_memory::_reference::_AddressSpace address_space, "_value">, "value">>

Enable the Mojo compiler to see into Reference.

Returns:

The MLIR reference for the Mojo compiler to use.

get_legacy_pointer

get_legacy_pointer(self: Self) -> LegacyPointer[type, address_space]

Constructs a Pointer from a safe reference.

Returns:

Constructed Pointer object.

unsafe_bitcast

unsafe_bitcast[new_element_type: AnyType = type, /, address_space: AddressSpace = address_space](self: Self) -> Reference[$0, is_mutable, lifetime, $1]

Cast the reference to one of another element type and AddressSpace, but the same lifetime and mutability.

Parameters:

  • new_element_type (AnyType): The result type.
  • address_space (AddressSpace): The address space of the result.

Returns:

The new reference.