IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

origin

Defines Mojo's origin types.

An origin is a compile-time value that names the variable a reference borrows from, and whether that reference permits mutation. The compiler uses origins to check that a reference never outlives the value it points to, enforce mutable exclusivity between references, and destroy values as soon as their last use.

Most origins are inferred automatically—from ref arguments, from parametric types like Pointer and Span, or from origin_of(). Reach for Origin and its aliases (ImmOrigin, MutOrigin, ImmUntrackedOrigin, MutUntrackedOrigin, ImmStaticOrigin) when an API needs to name an origin explicitly.

For the full picture, see the lifetimes guide.

comptime values

AnyOrigin

comptime AnyOrigin[*, mut: Bool] = SomeUnsafeAnyOrigin

An origin that might access any memory value.

Parameters

  • mut (Bool): Whether the origin is mutable.

ImmOrigin

comptime ImmOrigin = ImmOrigin

Immutable origin reference type.

ImmStaticOrigin

comptime ImmStaticOrigin = ImmStaticOrigin

An origin for strings and other always-immutable static constants.

ImmUnsafeAnyOrigin

comptime ImmUnsafeAnyOrigin = ImmUnsafeAnyOrigin

The immutable universal origin that might alias any memory value.

This is an unsafe escape hatch slated for removal. See UnsafeAnyOrigin.

ImmUntrackedOrigin

comptime ImmUntrackedOrigin = ImmUntrackedOrigin

An immutable origin the lifetime checker does not track.

ImmutAnyOrigin

comptime ImmutAnyOrigin = ImmUnsafeAnyOrigin

The immutable origin that might access any memory value.

MutAnyOrigin

comptime MutAnyOrigin = MutUnsafeAnyOrigin

The mutable origin that might access any memory value.

MutOrigin

comptime MutOrigin = MutOrigin

Mutable origin reference type.

MutUnsafeAnyOrigin

comptime MutUnsafeAnyOrigin = MutUnsafeAnyOrigin

The mutable universal origin that might alias any memory value.

This is an unsafe escape hatch slated for removal. See UnsafeAnyOrigin.

MutUntrackedOrigin

comptime MutUntrackedOrigin = MutUntrackedOrigin

A mutable origin the lifetime checker does not track.

OriginSet

comptime OriginSet = LITOriginSet

A set of origin parameters.

UnsafeAnyOrigin

comptime UnsafeAnyOrigin[*, mut: Bool] = SomeUnsafeAnyOrigin

The universal origin: an unsafe origin that might alias any memory value.

Because a reference with this origin might alias any live value, it forces the lifetime checker into its most conservative behavior, defeating the guarantees the origin system is meant to provide:

  • It extends unrelated lifetimes. Every other value in scope is kept alive for as long as the reference is live, even values it never points to, effectively halting ASAP destruction.
  • It hides unused-variable warnings, since the compiler treats every in-scope variable as potentially aliased.
  • It disables mutable exclusivity checking, since the compiler cannot prove which value the reference aliases.

Safety: This is a temporary compiler escape hatch from Mojo's early days, not a capability to reach for. It will never be stabilized and is slated for deprecation and removal. The Unsafe prefix marks every use as a place to migrate away from; prefer a concrete origin so the compiler can continue to track lifetimes and exclusivity.

Parameters

  • mut (Bool): Whether the origin is mutable.

UntrackedOrigin

comptime UntrackedOrigin[*, mut: Bool] = UntrackedOrigin[mut]

An origin the lifetime checker does not track, because it aliases no existing value.

An untracked origin is the empty origin: it promises the reference aliases no value the compiler is managing, so there is nothing for the lifetime checker to track or extend. That is exactly the behavior you want when interfacing with memory from outside the Mojo program. For example, the pointer returned by alloc() carries an untracked origin, because the allocated block aliases no Mojo-owned value.

Parameters

  • mut (Bool): Whether the origin is mutable.

Structs

  • Origin: This represents a origin reference for a memory value.