Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
Development · Evolving reference

Types

Identifies one nominal semantic type across compatible builds.

Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. Read the status →

Module std.reflection

import std.reflection;

Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.

StableTypeId

pub struct StableTypeId

Identifies one nominal semantic type across compatible builds.

The opaque Copyable value is a 128-bit identity, not an address, layout hash, serialization schema, or permission token.

StableTypeId.High

pub High: u64;

Returns the high-order 64 identity bits. Return: Exact unsigned bits.

StableTypeId.Low

pub Low: u64;

Returns the low-order 64 identity bits. Return: Exact unsigned bits.

ParameterSignature

pub final class ParameterSignature

Describes one exact parameter type and passing mode for lookup.

ParameterSignature.Type

pub Type: TypeInfo;

Returns the exact semantic parameter type. Return: Nonowning descriptor.

ParameterSignature.Mode

pub Mode: ParameterMode;

Returns the exact passing mode. Return: Stable ParameterMode.

ParameterSignature.Create

pub static fn Create(
        Type: TypeInfo,
        Mode: ParameterMode
    ) -> ParameterSignature

Creates one exact lookup parameter entry. Type: Registered exact semantic type descriptor. Mode: Required parameter passing mode. Return: Copyable signature entry with no allocation or retention.

MethodSignature

pub final class MethodSignature

Describes one exact reflected method shape for deterministic lookup.

This Copyable view borrows Parameters; callers keep that slice alive and unchanged through the one lookup operation. It performs no overload ranking.

MethodSignature.IsStatic

pub IsStatic: bool;

Reports static versus instance shape. Return: True for no receiver.

MethodSignature.Parameters

pub Parameters: readonly ParameterSignature[];

Borrows ordered exact parameter entries. Return: Nonretaining slice.

MethodSignature.ResultType

pub ResultType: TypeInfo;

Returns the exact result type, including Void. Return: Descriptor handle.

MethodSignature.ResultMode

pub ResultMode: ReturnMode;

Returns exact result passing mode. Return: Stable ReturnMode.

MethodSignature.Create

pub static fn Create(
        IsStatic: bool,
        Parameters: readonly ParameterSignature[],
        ResultType: TypeInfo,
        ResultMode: ReturnMode
    ) -> MethodSignature

Creates a nonretaining exact lookup signature. IsStatic: True only for a no-receiver callable. Parameters: Ordered entries kept live through lookup. ResultType: Exact result semantic type. ResultMode: Exact result passing mode. Return: Copyable borrowed signature view.

TypeInfo

pub final class TypeInfo

References immutable registered metadata for one exact semantic type.

TypeInfo is opaque and Copyable. It retains no user value and remains valid for the process or owning JIT session. Enumeration is deterministic and every At operation returns none only when its index is out of range.

TypeInfo.Kind

pub Kind: TypeKind;

Returns semantic type category. Return: Stable TypeKind.

TypeInfo.Name

pub Name: str;

Borrows unqualified display name. Return: Registered immutable UTF-8.

TypeInfo.QualifiedName

pub QualifiedName: str;

Borrows type-qualified name. Return: Registered immutable UTF-8.

TypeInfo.ModulePath

pub ModulePath: str;

Borrows declaring module path. Return: Registered immutable UTF-8.

TypeInfo.StableId

pub StableId: StableTypeId;

Returns stable semantic identity. Return: 128-bit StableTypeId.

TypeInfo.ByteSize

pub ByteSize: usize;

Returns selected complete-value size. Return: Target byte count.

TypeInfo.Alignment

pub Alignment: usize;

Returns selected complete-value alignment. Return: Nonzero power-of-two bytes.

TypeInfo.IsOpaque

pub IsOpaque: bool;

Reports whether authored layout is intentionally hidden. Return: Opaque-layout state.

TypeInfo.BaseCount

pub readonly fn BaseCount() -> usize

Counts concrete base descriptors. Return: Deterministic count.

TypeInfo.BaseAt

pub readonly fn BaseAt(Index: usize) -> TypeInfo?

Selects one concrete base descriptor. Index: Zero-based index. Return: Descriptor or none when out of range.

TypeInfo.InterfaceCount

pub readonly fn InterfaceCount() -> usize

Counts implemented interface descriptors. Return: Deterministic count.

TypeInfo.InterfaceAt

pub readonly fn InterfaceAt(Index: usize) -> TypeInfo?

Selects one implemented interface. Index: Zero-based index. Return: Descriptor or none.

TypeInfo.GenericArgumentCount

pub readonly fn GenericArgumentCount() -> usize

Counts materialized generic arguments. Return: Ordered argument count.

TypeInfo.GenericArgumentAt

pub readonly fn GenericArgumentAt(Index: usize) -> TypeInfo?

Selects one materialized generic argument. Index: Zero-based index. Return: Descriptor or none.

TypeInfo.AttributeCount

pub readonly fn AttributeCount() -> usize

Counts attached reflected attributes. Return: Deterministic count.

TypeInfo.AttributeAt

pub readonly fn AttributeAt(Index: usize) -> AttributeInfo?

Selects one reflected attribute. Index: Zero-based index. Return: Descriptor or none.

TypeInfo.AttributeSite

pub readonly fn AttributeSite() -> AttributeSiteInfo?

Returns the emitted attribute site for this type. Return: Canonical site or none.

TypeInfo.EffectiveAttributeCount

pub readonly fn EffectiveAttributeCount() -> usize

Counts direct and inherited retained type attributes. Return: Effective count.

TypeInfo.EffectiveAttributeAt

pub readonly fn EffectiveAttributeAt(Index: usize) -> AttributeInfo?

Selects one effective type attribute. Index: Zero-based index. Return: Attribute or none.

TypeInfo.Attributes

pub readonly fn Attributes() -> TypeAttributeView

Enumerates direct type attributes in declaration order. Return: Fresh nonowning view.

TypeInfo.EffectiveAttributes

pub readonly fn EffectiveAttributes() -> TypeEffectiveAttributeView

Enumerates effective attributes in published order. Return: Independent nonowning view.

TypeInfo.AttributesOf

pub readonly fn AttributesOf<A>() -> TypeFilteredAttributeView<A>

Enumerates direct attributes of one exact type. A: Attribute selector. Return: Independent filtered view.

TypeInfo.EffectiveAttributesOf

pub readonly fn EffectiveAttributesOf<A>() -> TypeEffectiveFilteredAttributeView<A>

Enumerates effective attributes of one exact type. A: Attribute selector. Return: Independent filtered view.

TypeInfo.FirstAttribute

pub readonly fn FirstAttribute<A>() -> FrozenAttribute<A>?

Finds the first direct final value of one exact attribute type. A: Attribute type. Return: Generation-borrowed typed view or none.

TypeInfo.FirstEffectiveAttribute

pub readonly fn FirstEffectiveAttribute<A>() -> FrozenAttribute<A>?

Finds the first effective final value of one exact attribute type. A: Attribute type. Return: Generation-borrowed typed view or none.

TypeInfo.HasEffectiveAttribute

pub readonly fn HasEffectiveAttribute<A>() -> bool

Tests one exact effective attribute type. A: Attribute selector. Return: True when effective.

TypeInfo.HasAttribute

pub readonly fn HasAttribute<A>() -> bool

Tests one exact direct attribute type. A: Attribute selector. Return: True when attached directly.

TypeInfo.Fields

pub readonly fn Fields() -> FieldView

Enumerates inherited authored fields without allocation. Return: Fresh field view.

TypeInfo.Fields

pub readonly fn Fields(Query: MemberQuery) -> FieldView

Enumerates fields under an explicit query policy. Query: Member selection. Return: Fresh field view.

TypeInfo.Properties

pub readonly fn Properties() -> PropertyView

Enumerates inherited authored properties without allocation. Return: Fresh property view.

TypeInfo.Properties

pub readonly fn Properties(Query: MemberQuery) -> PropertyView

Enumerates properties under an explicit query policy. Query: Member selection. Return: Fresh property view.

TypeInfo.Methods

pub readonly fn Methods() -> MethodView

Enumerates inherited authored methods without allocation. Return: Fresh method view.

TypeInfo.Methods

pub readonly fn Methods(Query: MemberQuery) -> MethodView

Enumerates methods under an explicit query policy. Query: Member selection. Return: Fresh method view.

TypeInfo.FieldCount

pub readonly fn FieldCount(Query: MemberQuery) -> usize

Counts fields selected by one exact query. Query: Enumeration policy. Return: Deterministic count.

TypeInfo.FieldAt

pub readonly fn FieldAt(Query: MemberQuery, Index: usize) -> FieldInfo?

Selects one field. Query: Enumeration policy. Index: Zero-based index. Return: Descriptor or none.

TypeInfo.FindField

pub readonly fn FindField(
        Name: str,
        Query: MemberQuery
    ) -> Result<FieldInfo, LookupError>

Finds one exact field name. Name: Exact UTF-8 bytes. Query: Enumeration policy. Return: Descriptor or lookup error.

TypeInfo.FindField

pub readonly fn FindField(Name: str) -> Result<FieldInfo, LookupError>

Finds an inherited authored field by exact name. Name: Exact UTF-8 bytes. Return: Descriptor or lookup error.

TypeInfo.PropertyCount

pub readonly fn PropertyCount(Query: MemberQuery) -> usize

Counts properties selected by one exact query. Query: Enumeration policy. Return: Deterministic count.

TypeInfo.PropertyAt

pub readonly fn PropertyAt(
        Query: MemberQuery,
        Index: usize
    ) -> PropertyInfo?

Selects one property. Query: Enumeration policy. Index: Zero-based index. Return: Descriptor or none.

TypeInfo.FindProperty

pub readonly fn FindProperty(
        Name: str,
        Query: MemberQuery
    ) -> Result<PropertyInfo, LookupError>

Finds one exact property name. Name: Exact UTF-8 bytes. Query: Enumeration policy. Return: Descriptor or lookup error.

TypeInfo.FindProperty

pub readonly fn FindProperty(Name: str) -> Result<PropertyInfo, LookupError>

Finds an inherited authored property by exact name. Name: Exact UTF-8 bytes. Return: Descriptor or lookup error.

TypeInfo.MethodCount

pub readonly fn MethodCount(Query: MemberQuery) -> usize

Counts methods selected by one exact query. Query: Enumeration policy. Return: Deterministic count.

TypeInfo.MethodAt

pub readonly fn MethodAt(Query: MemberQuery, Index: usize) -> MethodInfo?

Selects one method. Query: Enumeration policy. Index: Zero-based index. Return: Descriptor or none.

TypeInfo.FindMethod

pub readonly fn FindMethod(
        Name: str,
        Signature: MethodSignature&,
        Query: MemberQuery
    ) -> Result<MethodInfo, LookupError>

Finds one method by exact name and exact static signature. Name: Exact UTF-8 method name. Signature: Borrowed exact signature retained only for the call. Query: Enumeration policy. Return: Exact descriptor, NotFound, or Ambiguous; no overload ranking.

TypeInfo.BindMethod

pub readonly fn BindMethod<R, each P>(Name: str) -> Result<BoundMethod<R>, InvocationStatus>

Finds and binds one exact instance method by name and typed signature. R: Exact owned, void, or borrowed result type. P: Ordered value types or parameter-mode markers. Name: Exact UTF-8 method name. Return: Authenticated nonowning method binding or lookup/validation status.

Example

module example.reflection_named_binding;
from std.reflection import TypeOf, ReadParameter, RefRead;
class Reader {
    pub init() {}
    pub readonly fn Read(Value: readonly i32&) -> i32 { return Value; }
    pub static fn Answer() -> i32 { return 42; }
}
pub fn Main() -> i32 {
    let Instance = Reader();
    let Input: i32 = 42;
    switch TypeOf<Reader>().BindMethod<i32, ReadParameter<i32>>("Read") {
        case .Ok { Value = Bound } => {
            switch Bound.Call(Instance, RefRead(Input)) {
                case .Ok { Value = Answer } => {
                    if Answer != 42 { return 1; }
                }
                case .Err { Error = _ } => return 2;
            }
        }
        case .Err { Error = _ } => return 3;
    }
    switch TypeOf<Reader>().BindStaticMethod<i32>("Answer") {
        case .Ok { Value = Bound } => {
            switch Bound.CallStatic() {
                case .Ok { Value = Answer } => return Answer;
                case .Err { Error = _ } => return 4;
            }
        }
        case .Err { Error = _ } => return 5;
    }
}

TypeInfo.BindMethod

pub readonly fn BindMethod<R, each P>(Name: str, Query: MemberQuery) -> Result<BoundMethod<R>, InvocationStatus>

Binds an exact instance method under one query. R: Exact result. P: Exact parameter modes. Name: Exact name. Query: Enumeration policy. Return: Bound method or status.

TypeInfo.BindMethod

pub readonly fn BindMethod<R, each P>(Name: str, Query: MemberQuery, Access: PrivateAccess) -> Result<BoundMethod<R>, InvocationStatus>

Binds an exact instance method under query and access policies. R: Exact result. P: Exact parameter modes. Name: Exact name. Query: Enumeration policy. Access: Private access authority. Return: Bound method or status.

TypeInfo.BindStaticMethod

pub readonly fn BindStaticMethod<R, each P>(Name: str) -> Result<BoundMethod<R>, InvocationStatus>

Binds an exact static method by name. R: Exact result. P: Exact parameter modes. Name: Exact name. Return: Bound method or status.

TypeInfo.BindStaticMethod

pub readonly fn BindStaticMethod<R, each P>(Name: str, Query: MemberQuery) -> Result<BoundMethod<R>, InvocationStatus>

Binds an exact static method under one query. R: Exact result. P: Exact parameter modes. Name: Exact name. Query: Enumeration policy. Return: Bound method or status.

TypeInfo.BindStaticMethod

pub readonly fn BindStaticMethod<R, each P>(Name: str, Query: MemberQuery, Access: PrivateAccess) -> Result<BoundMethod<R>, InvocationStatus>

Binds an exact static method under query and access policies. R: Exact result. P: Exact parameter modes. Name: Exact name. Query: Enumeration policy. Access: Private access authority. Return: Bound method or status.

Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library