Mojo trait
RegisterPassable
A marker trait to denote the type to be register passable.
The compiler treats the type that conforms to this trait with the following constraints:
-
the value struct doesn’t have “identity” - you can’t take the address of self on read convention methods. This is allows the compiler to pass it in registers.
-
The type implicitly conforms to Movable and the compiler synthesizes a trivial move constructor. The compiler needs to be able to move around values of the type by loading and storing them. A custom defined moveinit is not allowed.
-
Compiler checks that any stored member (
vars) also conforms to this trait. It wouldn’t be possible to provide identity for a contained member if the container doesn’t have identity. -
The type can choose whether it wants to be Copyable or not.
struct Foo(RegisterPassable):
...Implemented traits
comptime members
__moveinit__is_trivial
comptime __moveinit__is_trivial
A flag (often compiler generated) to indicate whether the implementation of __moveinit__ is trivial.
The implementation of __moveinit__ is considered to be trivial if:
- The struct has a compiler-generated
__moveinit__and all its fields have a trivial__moveinit__method.
In practice, it means the value can be moved by moving the bits from one location to another without side effects.
Required methods
__moveinit__
__moveinit__(out self: _Self, deinit existing: _Self, /)
Create a new instance of the value by moving the value of another.
Args:
- existing (
_Self): The value to move.
Returns:
_Self
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!