ir

package
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package ir defines the resolved, target-independent representation consumed by every backend. Unlike syntax AST nodes, IR expressions carry semantic types and declarations contain normalized names.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array struct {
	ExprBase
	Elements []Expression
}

type Assignment

type Assignment struct {
	Base
	Target   Expression
	Operator string
	Value    Expression
}

type Attempt added in v0.2.0

type Attempt struct {
	ExprBase
	Value      Expression
	Body       []Statement
	BodyResult Expression
	Success    types.Type
	Fails      types.Type
}

Attempt captures every fallible effect produced by Value or Body and exposes it as Result<Success, Error>. BodyResult is the final value of a block attempt and is nil for a Void block.

type Attribute

type Attribute struct {
	Name      string
	Arguments []CallArgument
}

type Base

type Base struct {
	Span            token.Span
	TrailingComment string
}

func (Base) SourceSpan added in v0.2.4

func (b Base) SourceSpan() token.Span

type Binary

type Binary struct {
	ExprBase
	Left     Expression
	Operator string
	Right    Expression
}

type Block

type Block struct {
	ExprBase
	Parameters []string
	Body       []Statement
	Brace      bool
}

type Break

type Break struct{ Base }

type Call

type Call struct {
	ExprBase
	Callee    Expression
	Arguments []CallArgument
	Block     *Block
	Codec     *CodecSchema
	Fails     types.Type
}

type CallArgument

type CallArgument struct {
	Name  string
	Value Expression
	Splat string
}

type Case

type Case struct {
	ExprBase
	Value          Expression
	Leading        []Statement
	Branches       []CaseBranch
	Else           []Statement
	HasElse        bool
	TypeUnion      bool
	ElseResult     Expression
	ElseDiverges   bool
	ElseNarrowings []CaseBinding
}

type CaseBinding

type CaseBinding struct {
	Name      string
	Field     string
	Type      types.Type
	Generated bool
}

type CaseBranch

type CaseBranch struct {
	Base
	Value       Expression
	EnumName    string
	Member      string
	Bindings    []CaseBinding
	PayloadEnum bool
	TypePattern bool
	MatchType   types.Type
	Narrowings  []CaseBinding
	Body        []Statement
	Result      Expression
	Diverges    bool
}

type Class

type Class struct {
	Base
	Name           string
	TypeParameters []string
	External       bool
	Superclass     Expression
	Implements     []string
	Body           []Statement
}

type CodecField

type CodecField struct {
	Name     string
	WireName string
	Schema   *CodecSchema
}

type CodecSchema

type CodecSchema struct {
	Type      types.Type
	Kind      string
	Module    string
	Reference *Reference
	Element   *CodecSchema
	Fields    []CodecField
	RawType   types.Type
	RawValues []EnumRawValue
}

CodecSchema is the checked, target-independent value shape used by typed codecs and protocol bindings. Backends consume this schema instead of reflecting over a generated target type.

type Comment

type Comment struct {
	Base
	Text string
}

type Conversion added in v0.1.3

type Conversion struct {
	ExprBase
	Kind  ConversionKind
	Value Expression
}

type ConversionKind added in v0.1.3

type ConversionKind string
const IntegerToFloatConversion ConversionKind = "integer_to_float"
const NonNullableToNullableConversion ConversionKind = "non_nullable_to_nullable"
const NullableToNonNullableConversion ConversionKind = "nullable_to_non_nullable"
const PureFunctionToFallibleConversion ConversionKind = "pure_function_to_fallible"
const RangeToIterableConversion ConversionKind = "range_to_iterable"
const ResultFunctionToPromiseRejectionConversion ConversionKind = "result_function_to_promise_rejection"
const UnionIntegerToFloatConversion ConversionKind = "union_integer_to_float"

type Enum

type Enum struct {
	Base
	Name           string
	TypeParameters []string
	Body           []Statement
	RawType        types.Type
}

type EnumCall added in v0.2.1

type EnumCall struct {
	ExprBase
	EnumName  string
	Method    string
	Receiver  Expression
	Arguments []CallArgument
	Reference *Reference
	RawType   types.Type
	RawValues []EnumRawValue
	Fails     types.Type
}

EnumCall preserves source-level enum methods independently from backend enum representations. Generated raw_value/from_raw operations use the same node so every backend and the REPL share one checked semantic boundary.

type EnumConstruct

type EnumConstruct struct {
	ExprBase
	EnumName      string
	Member        string
	TypeArguments []types.Type
	Arguments     []Expression
	Reference     *Reference
}

EnumConstruct preserves nominal variant construction through lowering. It must not become an ordinary call because every backend uses a different runtime representation for payload enums.

type EnumMember

type EnumMember struct {
	Base
	Name     string
	Fields   []Parameter
	RawValue Expression
}

type EnumRawValue added in v0.2.1

type EnumRawValue struct {
	Member string
	Raw    string
}

type ExprBase

type ExprBase struct {
	Base
	Type types.Type
}

func NewExprBase

func NewExprBase(span token.Span, typ types.Type) ExprBase

func (ExprBase) ExprType

func (e ExprBase) ExprType() types.Type

type Expression

type Expression interface {
	ExprType() types.Type
	SourceSpan() token.Span
	// contains filtered or unexported methods
}

type ExpressionStatement

type ExpressionStatement struct {
	Base
	Expression Expression
}

type Extension added in v0.1.11

type Extension interface {
	ExtensionName() string
}

Extension is typed compile-time data contributed by a package integration. The core IR transports it without knowing package-specific schemas.

type Field

type Field struct {
	Base
	Name     string
	Type     types.Type
	Value    Expression
	ReadOnly bool
}

type Hash

type Hash struct {
	ExprBase
	Entries []HashEntry
}

type HashEntry

type HashEntry struct {
	Key   Expression
	Value Expression
}

type Identifier

type Identifier struct {
	ExprBase
	Name      string
	Owner     string
	Lexical   bool // Resolved to a lexical binding rather than a same-named member.
	Generated bool // Compiler-owned name that must bypass source identifier rewriting.
	Reference *Reference
}

type If

type If struct {
	ExprBase
	Condition    Expression
	Then         []Statement
	ThenResult   Expression
	ThenDiverges bool
	ElseIf       []IfBranch
	Else         []Statement
	ElseResult   Expression
	ElseDiverges bool
	HasElse      bool
}

type IfBranch

type IfBranch struct {
	Condition Expression
	Body      []Statement
	Result    Expression
	Diverges  bool
}

type Import

type Import struct {
	Base
	Path      string
	Symbols   []string
	Alias     string
	Namespace bool
	Kind      string
	Standard  bool
	Official  bool
	Platform  bool
	Native    bool
	Runtime   bool
	// RuntimeRequired records that generated code must load the compiler-owned
	// source module. Fully lowered intrinsics can leave this false.
	RuntimeRequired bool
	// Implicit identifies compiler-injected runtime dependencies that are not
	// source-visible imports. Language tooling must not offer their exports as
	// though the application imported them explicitly.
	Implicit bool
	// IntrinsicSymbols are lowered by the backend instead of being imported as
	// named functions from a compiler-owned source module.
	IntrinsicSymbols map[string]bool
	// RuntimeIndependentSymbols are the intrinsic subset that does not
	// reference the compiler-owned source module on any backend.
	RuntimeIndependentSymbols map[string]bool
	// SymbolKinds distinguishes value records from reference classes in
	// backends whose representation makes that distinction explicit.
	SymbolKinds map[string]string
	// SymbolTypes, SymbolParameters, and SymbolTypeParameters retain imported
	// declaration contracts for editor tooling even when the imported module has
	// no generated TypeRB IR.
	SymbolTypes          map[string]types.Type
	SymbolParameters     map[string][]types.Type
	SymbolTypeParameters map[string][]string
	// GeneratedTypeSymbols are target-package type exports referenced only by
	// imported declaration contracts. They are emitted as type-only imports but
	// stay invisible to source name resolution and editor completion.
	GeneratedTypeSymbols []string
}

type Index

type Index struct {
	ExprBase
	Receiver Expression
	Index    Expression
}

type Interface

type Interface struct {
	Base
	Name    string
	Methods []*Method
}

type InterpolatedString

type InterpolatedString struct {
	ExprBase
	Raw   string
	Parts []StringPart
}

type Iterate

type Iterate struct {
	Base
	Source          Expression
	Operation       string
	Intrinsic       string
	SliceSize       Expression
	WithIndex       bool
	Bindings        []IterationBinding
	Body            []Statement
	Result          *IterationResult
	Fails           types.Type
	EffectSuccess   types.Type
	CaptureEffect   bool
	UnhandledEffect bool
}

type IterationBinding added in v0.1.8

type IterationBinding struct {
	Name string
	Type types.Type
}

Iterate is a structured loop rather than a callback invocation. Backends can therefore preserve TypeRB control-flow semantics inside an each block. Bindings retain the checked type of every source-level block parameter.

type IterationResult added in v0.2.0

type IterationResult struct {
	Variable *Variable
	Target   Expression
	Return   bool
	Type     types.Type
}

type JSXAttribute added in v0.2.3

type JSXAttribute struct {
	Name    string
	Value   Expression
	Boolean bool
}

type JSXChild added in v0.2.3

type JSXChild interface {
	// contains filtered or unexported methods
}

type JSXElement added in v0.2.3

type JSXElement struct {
	ExprBase
	Name       string
	Component  Expression
	Attributes []JSXAttribute
	Children   []JSXChild
	Fragment   bool
}

type JSXExpression added in v0.2.3

type JSXExpression struct {
	Value Expression
}

type JSXText added in v0.2.3

type JSXText struct {
	Text string
}

type Lambda added in v0.2.3

type Lambda struct {
	ExprBase
	Parameters  []Parameter
	SuccessType types.Type
	ReturnType  types.Type
	Fails       types.Type
	Body        []Statement
}

Lambda is a first-class lexical function. Parameters and result remain target-independent so every backend can emit its native closure form.

type Literal

type Literal struct {
	ExprBase
	Kind string
	Raw  string
}

type Member

type Member struct {
	ExprBase
	Receiver  Expression
	Name      string
	Safe      bool
	Namespace bool
	// ClassField distinguishes storage-backed class properties from methods and
	// record fields so backends can preserve both `value.name` and `value.name()`.
	ClassField bool
	// UnionAlternatives asks representation-sensitive backends to project a
	// common data member from an erased union value.
	UnionAlternatives []UnionMemberAlternative
	Reference         *Reference
}

type Method

type Method struct {
	Base
	Name           string
	External       bool
	TargetName     string
	TypeParameters []string
	Parameters     []Parameter
	Alternatives   []MethodSignature
	SuccessType    types.Type
	ReturnType     types.Type
	Fails          types.Type
	Body           []Statement
	Class          bool
	// Property exposes an external member without call syntax. Loadable
	// properties additionally provide load(), reload(), and loaded?() controls.
	Property bool
	Loadable bool
}

type MethodSignature added in v0.2.0

type MethodSignature struct {
	Parameters []Parameter
	ReturnType types.Type
	Variadic   bool
}

type Module

type Module struct {
	Base
	Name string
	Body []Statement
}

type Native

type Native struct {
	Base
	Text string
}

type NativeBlock

type NativeBlock struct {
	Base
	Header string
	Body   []Statement
	Closer string
}

type NativeExpression

type NativeExpression struct {
	ExprBase
	Text string
}

type Next

type Next struct{ Base }

type Parameter

type Parameter struct {
	Name                 string
	Type                 types.Type
	Default              Expression
	Keyword              bool
	Rest                 bool
	KeywordRest          bool
	LiteralValues        []string
	LiteralArrays        [][]string
	LiteralArrayElements []string
}

type Program

type Program struct {
	Mode              string
	SourcePath        string
	Package           string
	ModulePath        string
	GoModule          string
	RubyLoader        string
	TypeScriptRuntime string
	UsesJSX           bool
	Declarations      *declaration.Catalog
	Extensions        []Extension
	Statements        []Statement
}

type Range

type Range struct {
	ExprBase
	Start     Expression
	End       Expression
	Exclusive bool
}

type Record

type Record struct {
	Base
	Name           string
	TypeParameters []string
	Body           []Statement
}

type RecordField

type RecordField struct {
	Base
	Name       string
	Type       types.Type
	Attributes []Attribute
}

type Reference

type Reference struct {
	Package        string
	Alias          string
	Symbol         string
	ExportKind     string
	Intrinsic      string
	ReceiverMethod bool
}

Reference identifies a symbol resolved from an import or the portable prelude. Intrinsic is non-empty for compiler-known standard/platform calls; project references use Package, Alias, Symbol, and ExportKind for target-specific qualification.

type Return

type Return struct {
	Base
	Value Expression
}

type Statement

type Statement interface {
	SourceSpan() token.Span
	// contains filtered or unexported methods
}

type StringPart

type StringPart struct {
	Text       string
	Expression Expression
}

type StructuredBlock added in v0.2.0

type StructuredBlock struct {
	Base
	Call             *Call
	Intrinsic        string
	Bindings         []IterationBinding
	Body             []Statement
	Value            Expression
	Result           *StructuredBlockResult
	Fails            types.Type
	EffectSuccess    types.Type
	PropagateSuccess types.Type
	CaptureEffect    bool
	UnhandledEffect  bool
}

type StructuredBlockResult added in v0.2.0

type StructuredBlockResult struct {
	Variable *Variable
	Target   Expression
	Return   bool
	Type     types.Type
}

StructuredBlock keeps a compiler-owned, value-producing block call as a typed control-flow boundary. Backends decide how the intrinsic acquires and releases its scoped resource, while the block body and result remain normal TypeRB IR.

type Symbol

type Symbol struct {
	ExprBase
	Name string
	Raw  string
}

type Temporary added in v0.1.9

type Temporary struct {
	Base
	Name string
	Type types.Type
}

Temporary declares an uninitialized compiler-owned local. Portable source cannot construct this node; backend normalization uses it when a value- producing control-flow expression must be emitted as enclosing statements.

type Transform

type Transform struct {
	ExprBase
	Source      Expression
	Operation   string
	Initial     Expression
	WithIndex   bool
	Item        string
	Index       string
	Accumulator string
	ItemType    types.Type
	Body        []Statement
	Result      Expression
}

Transform is a value-producing collection operation. It is distinct from a target callback so checker-derived item/result types and block semantics are retained until backend lowering.

type TypeAlias added in v0.2.0

type TypeAlias struct {
	Base
	Name           string
	TypeParameters []string
	Target         types.Type
	Variants       []EnumMember
}

type TypeApply

type TypeApply struct {
	ExprBase
	Receiver       Expression
	Arguments      []types.Type
	Owner          string
	OwnerArguments []types.Type
	Kind           string
}

type Unary

type Unary struct {
	ExprBase
	Operator string
	Operand  Expression
}

type UnhandledEffect added in v0.2.0

type UnhandledEffect struct {
	ExprBase
	Value Expression
	Fails types.Type
}

UnhandledEffect marks a fallible expression evaluated by an interactive host. The REPL unwraps success and reports failure without terminating the session; project builds never produce this node.

type UnionMemberAlternative added in v0.2.3

type UnionMemberAlternative struct {
	Type       types.Type
	MemberType types.Type
}

type Variable

type Variable struct {
	Base
	Name     string
	Type     types.Type
	Value    Expression
	Mutable  bool
	Constant bool
	Owner    string
}

type While

type While struct {
	Base
	Condition Expression
	Body      []Statement
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL