sun::borrow_checker::Lifetime

sun::borrow_checker::Lifetime

class · Source (opens in a new tab)

class sun::borrow_checker::Lifetime

Represents the lifetime of a reference - how long it remains valid.

Lifetimes form a partial order based on scope containment.

Key invariants:

  • Static lifetime outlives everything
  • Param lifetimes outlive the function body (caller's scope)
  • Local lifetimes are bounded by their declaring scope
  • A reference's lifetime must not exceed its target's lifetime

Functions

Lifetime

Lifetime()

public · function · Source (opens in a new tab)

sun::borrow_checker::Lifetime::Lifetime()

Default constructor creates an anonymous lifetime.

Lifetime(Kind k, uint32_t id, std::string name, size_t depth)

private · function · Source (opens in a new tab)

sun::borrow_checker::Lifetime::Lifetime(Kind k, uint32_t id, std::string name, size_t depth)

Creates a lifetime identity with its scope depth and optional name.

Related: Kind

Public Functions

anonymous

public · function · static · Source (opens in a new tab)

static Lifetime sun::borrow_checker::Lifetime::anonymous(uint32_t id)

Create an anonymous lifetime with unique ID.

param

  • id: Unique identifier for this lifetime

Related: Lifetime

equals

public · function · Source (opens in a new tab)

bool sun::borrow_checker::Lifetime::equals(const Lifetime &other) const

Check if two lifetimes are equivalent (mutually outlive).

Related: Lifetime

getId

public · function · Source (opens in a new tab)

uint32_t sun::borrow_checker::Lifetime::getId() const

Returns the object identifier.

getKind

public · function · Source (opens in a new tab)

Kind sun::borrow_checker::Lifetime::getKind() const

Returns the type category used for semantic checks and dispatch.

Related: Kind

getName

public · function · Source (opens in a new tab)

const std::string & sun::borrow_checker::Lifetime::getName() const

Returns the declared name used to identify this object.

getScopeDepth

public · function · Source (opens in a new tab)

size_t sun::borrow_checker::Lifetime::getScopeDepth() const

Returns the scope depth stored by this object.

isAnonymous

public · function · Source (opens in a new tab)

bool sun::borrow_checker::Lifetime::isAnonymous() const

Check if this is an anonymous lifetime.

isLocal

public · function · Source (opens in a new tab)

bool sun::borrow_checker::Lifetime::isLocal() const

Check if this is a local variable lifetime.

isParam

public · function · Source (opens in a new tab)

bool sun::borrow_checker::Lifetime::isParam() const

Check if this is a parameter lifetime.

isStatic

public · function · Source (opens in a new tab)

bool sun::borrow_checker::Lifetime::isStatic() const

Check if this is a static lifetime.

local

public · function · static · Source (opens in a new tab)

static Lifetime sun::borrow_checker::Lifetime::local(const std::string &varName, size_t scopeDepth)

Create a lifetime bound to a local variable.

param

  • varName: The variable name (for error messages)

  • scopeDepth: The scope nesting level where declared

Related: Lifetime

outlives

public · function · Source (opens in a new tab)

bool sun::borrow_checker::Lifetime::outlives(const Lifetime &other) const

Check if this lifetime outlives another.

Returns true if this is valid everywhere other is valid.

Outlives relationships:

  • Static outlives everything
  • Param outlives Local (param lives in caller's scope)
  • Local at depth N outlives Local at depth M where N < M
  • Same-kind lifetimes with same name/id are equal (outlive each other)

Related: Lifetime

param

public · function · static · Source (opens in a new tab)

static Lifetime sun::borrow_checker::Lifetime::param(const std::string &paramName)

Create a lifetime bound to a function parameter.

param

  • paramName: The parameter name (for error messages)

Related: Lifetime

static_

public · function · static · Source (opens in a new tab)

static Lifetime sun::borrow_checker::Lifetime::static_()

Create a static lifetime (outlives everything).

Related: Lifetime

toString

public · function · Source (opens in a new tab)

std::string sun::borrow_checker::Lifetime::toString() const

Format lifetime for error messages.

Public Enums

Kind

public · enum · Source (opens in a new tab)

enum class sun::borrow_checker::Lifetime::Kind

The kind of lifetime determines its scope behavior.

Static

Static

'static - lives for the entire program (e.g., string literals, globals)

Param

Param

Bound to a function parameter - outlives the function body since the caller owns the referenced data.

Local

Local

Bound to a local variable - dies when variable goes out of scope.

Anonymous

Anonymous

Anonymous/inferred lifetime - assigned during analysis.

Private Fields

id_

private · variable · Source (opens in a new tab)

uint32_t sun::borrow_checker::Lifetime::id_

No documentation comment.

kind_

private · variable · Source (opens in a new tab)

Kind sun::borrow_checker::Lifetime::kind_

No documentation comment.

Related: Kind

name_

private · variable · Source (opens in a new tab)

std::string sun::borrow_checker::Lifetime::name_

No documentation comment.

scopeDepth_

private · variable · Source (opens in a new tab)

size_t sun::borrow_checker::Lifetime::scopeDepth_

No documentation comment.