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 ¶
- type Array
- type Assignment
- type Attribute
- type Base
- type Binary
- type Block
- type Break
- type Call
- type CallArgument
- type Case
- type CaseBinding
- type CaseBranch
- type Class
- type CodecField
- type CodecSchema
- type Comment
- type Conversion
- type ConversionKind
- type Enum
- type EnumCall
- type EnumConstruct
- type EnumMember
- type EnumRawValue
- type ExprBase
- type Expression
- type ExpressionStatement
- type Extension
- type Field
- type Hash
- type HashEntry
- type Identifier
- type If
- type IfBranch
- type Import
- type Index
- type Interface
- type InterpolatedString
- type Iterate
- type IterationBinding
- type IterationResult
- type JSXAttribute
- type JSXChild
- type JSXElement
- type JSXExpression
- type JSXText
- type Lambda
- type Literal
- type Member
- type MemberContract
- type Method
- type MethodSignature
- type Module
- type Native
- type NativeBlock
- type NativeExpression
- type Newtype
- type NewtypeMethodCall
- type Next
- type Parameter
- type Program
- type Range
- type Record
- type RecordConstruct
- type RecordField
- type RecordFieldContract
- type Reference
- type Return
- type RuntimeBinding
- type Statement
- type StringPart
- type StructuredBlock
- type StructuredBlockResult
- type Symbol
- type Temporary
- type Transform
- type TypeAlias
- type TypeApply
- type TypeContract
- type Unary
- type UnionMemberAlternative
- type Variable
- type While
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 Attribute ¶
type Attribute struct {
Name string
Arguments []CallArgument
}
type Base ¶
func (Base) SourceSpan ¶ added in v0.2.4
type Binary ¶
type Binary struct {
ExprBase
Left Expression
Operator string
Right Expression
}
type Call ¶
type Call struct {
ExprBase
Callee Expression
Arguments []CallArgument
CallSignature []callsignature.Parameter
Block *Block
Codec *CodecSchema
DeclarationOnly bool
// NewtypeMethod selects a statically dispatched authored nominal member.
// Storage erasure must not turn it into a representation method call.
NewtypeMethod *NewtypeMethodCall
// PresentType is the call result after a safe-navigation receiver is known
// to be non-nil. It remains zero for ordinary calls.
PresentType types.Type
}
func (*Call) NewtypeReceiver ¶ added in v0.4.4
func (c *Call) NewtypeReceiver() Expression
NewtypeReceiver follows the normalized callee, never a duplicate receiver expression that could bypass safe-navigation or evaluate-once lowering.
type CallArgument ¶
type CallArgument struct {
Name string
Value Expression
Splat string
// Field is populated for enum construction after positional and named-only
// arguments have been bound to their declared payload fields.
Field 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 CaseBranch ¶
type CaseBranch struct {
Base
Value Expression
Alternatives []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
Declaration identity.Declaration
Name string
TypeParameters []string
External bool
Superclass Expression
Implements []types.Type
// ResolvedImplements is parallel to Implements and expands transparent
// aliases for semantic dispatch without changing generated source types.
ResolvedImplements []types.Type
// ImplementReferences is parallel to Implements and retains the resolved
// module identity for imported interfaces.
ImplementReferences []*Reference
// ResolvedImplementReferences is parallel to ResolvedImplements.
ResolvedImplementReferences []*Reference
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 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 NewtypeConstructionConversion ConversionKind = "newtype_construction"
const NewtypeValueConversion ConversionKind = "newtype_value"
const NonNullableToNullableConversion ConversionKind = "non_nullable_to_nullable"
const NullableToNonNullableConversion ConversionKind = "nullable_to_non_nullable"
const PromiseRejectionToResultConversion ConversionKind = "promise_rejection_to_result"
const RangeToIterableConversion ConversionKind = "range_to_iterable"
const ResultFunctionToPromiseRejectionConversion ConversionKind = "result_function_to_promise_rejection"
const UnionIntegerToFloatConversion ConversionKind = "union_integer_to_float"
type EnumCall ¶ added in v0.2.1
type EnumCall struct {
ExprBase
EnumName string
Owner string
OwnerIdentity identity.Declaration
Method string
Receiver Expression
Arguments []CallArgument
CallSignature []callsignature.Parameter
Reference *Reference
RawType types.Type
RawValues []EnumRawValue
}
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. Owner preserves the exact local declaration identity across namespaces.
type EnumConstruct ¶
type EnumConstruct struct {
ExprBase
EnumName string
Owner string
Declaration identity.Declaration
Member string
TypeArguments []types.Type
Arguments []CallArgument
CallSignature []callsignature.Parameter
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
Attributes []Attribute
}
type EnumRawValue ¶ added in v0.2.1
type Expression ¶
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 HashEntry ¶
type HashEntry struct {
Key Expression
Value Expression
}
type Identifier ¶
type Identifier struct {
ExprBase
Name string
Owner string
Declaration identity.Declaration
Dispatch identity.Dispatch
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
// DeclaredPath retains the source spelling when Path is resolved to a
// canonical module identity. Language tooling uses it to link imports.
DeclaredPath string
Symbols []string
// SymbolAliases maps exported declaration names to their source-local
// bindings for named imports and aliased bare roots.
SymbolAliases map[string]string
// NestedTypeSymbols maps canonical owned declaration names to their
// source-local qualified spelling through an imported declaration root.
NestedTypeSymbols map[string]string
Alias string
QualifiedRoot string
UsedSymbols []string
Namespace bool
Kind string
Standard bool
Official bool
Platform bool
Native bool
Runtime bool
// RuntimeRequired records that generated code must load the source module
// for compiler-owned runtime behavior. 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][]callsignature.Parameter
SymbolTypeParameters map[string][]string
// RecordDefaults identifies imported records whose generated constructor
// owns one or more source defaults. TypeScript uses this to retain a value
// import for construction while ordinary records remain type-only imports.
RecordDefaults map[string]bool
// TypeContracts retain the structural declarations referenced by native
// package signatures so editor tooling can instantiate their members.
TypeContracts map[string]TypeContract
// 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
// RuntimeSymbols map semantic declaration exports to separately validated
// target-native runtime functions. Their signatures remain in SymbolTypes
// and SymbolParameters.
RuntimeSymbols map[string]RuntimeBinding
}
type Index ¶
type Index struct {
ExprBase
Receiver Expression
Index Expression
}
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, EffectSuccess, and CaptureEffect describe only a compiler-declared
// structured Result boundary. They do not represent function effects.
Fails types.Type
EffectSuccess types.Type
CaptureEffect bool
ResultBoundary bool
}
type IterationBinding ¶ added in v0.1.8
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 Lambda ¶ added in v0.2.3
Lambda is a first-class lexical function. Parameters and result remain target-independent so every backend can emit its native closure form.
type Member ¶
type Member struct {
ExprBase
Receiver Expression
Name string
Declaration identity.Declaration
Dispatch identity.Dispatch
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
// PresentType is the member's type after a safe-navigation receiver is
// known to be non-nil. It remains zero for ordinary member access.
PresentType types.Type
// UnionAlternatives asks representation-sensitive backends to project a
// common data member from an erased union value.
UnionAlternatives []UnionMemberAlternative
Reference *Reference
}
type MemberContract ¶ added in v0.2.26
type Method ¶
type Method struct {
Base
Declaration identity.Declaration
Dispatch identity.Dispatch
Name string
External bool
TargetName string
TypeParameters []string
Parameters []Parameter
Alternatives []MethodSignature
ReturnType 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 Module ¶
type Module struct {
Base
Declaration identity.Declaration
Name string
Body []Statement
}
type NativeExpression ¶
type NewtypeMethodCall ¶ added in v0.4.4
type Range ¶
type Range struct {
ExprBase
Start Expression
End Expression
Exclusive bool
}
type RecordConstruct ¶ added in v0.3.44
type RecordConstruct struct {
ExprBase
Declaration identity.Declaration
Target Expression
TypeArguments []types.Type
Arguments []CallArgument
Fields []RecordFieldContract
}
RecordConstruct preserves checked record construction independently from an ordinary callable invocation. Declaration owns semantic identity, while Target retains only the authored/import projection needed by backends. Arguments retain authored evaluation order and Fields retain declaration order, because record defaults require both orders.
type RecordField ¶
type RecordFieldContract ¶ added in v0.3.44
type Reference ¶
type Reference struct {
Package string
Alias string
Symbol string
Declaration identity.Declaration
Dispatch identity.Dispatch
// Owner and ClassMember distinguish imported type-member dispatch from a
// package function and preserve the source class/instance member kind.
Owner string
ClassMember bool
PackageRoot bool
ExportKind string
Intrinsic string
ReceiverMethod bool
Runtime *RuntimeBinding
}
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 RuntimeBinding ¶ added in v0.3.23
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, EffectSuccess, and CaptureEffect describe only the structured
// Result boundary declared by the provider.
Fails types.Type
EffectSuccess types.Type
PropagateSuccess types.Type
CaptureEffect 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 Temporary ¶ added in v0.1.9
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
Limit 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
Declaration identity.Declaration
Name string
TypeParameters []string
AuthoredTarget types.Type
// AuthoredTargetReference identifies the declaration named directly in
// source, independently of the fully expanded semantic target.
AuthoredTargetReference *Reference
Target types.Type
// TargetReference retains the declaration that owns the semantically
// expanded target so transparent aliases share one declaration identity.
TargetReference *Reference
Variants []EnumMember
}
type TypeContract ¶ added in v0.2.26
type TypeContract struct {
TypeParameters []string
AliasTarget *types.Type
Members map[string]MemberContract
}
type Unary ¶
type Unary struct {
ExprBase
Operator string
Operand Expression
}
type UnionMemberAlternative ¶ added in v0.2.3
type While ¶
type While struct {
Base
Condition Expression
Body []Statement
}