Help us shape the future of Go! Take the 2026 Go Developer Survey

typifier

package
v0.21.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package typifier types the expressions of an IR function: Rust naga's Typifier (front/mod.rs) with the rules of proc::ResolveContext::resolve (proc/typifier.rs). The validator's callers, every backend and the WGSL frontend type expressions with it; no stage keeps types of its own in the IR.

A Typifier holds one TypeResolution per expression of one function, in arena order. Grow types the expressions it does not have yet, each from the resolutions of its operands, which it already holds: one linear pass, memoized, with no recursion.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Expression ir.ExpressionHandle
	Err        error
}

Error is a failure to type an expression (Rust's ResolveError, with the expression it is about).

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the reason.

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module holds the typifier of every function and entry point of a module: what a backend's Compile types once before it writes the module.

func ForModule

func ForModule(m *ir.Module) (*Module, error)

ForModule types every function and entry point of m.

func (*Module) Function

func (mt *Module) Function(fn *ir.Function) *Typifier

Function returns the typifier of fn, one of the module's functions or entry point functions, or nil for any other function.

type Typifier

type Typifier struct {
	// contains filtered or unexported fields
}

Typifier holds the type of every expression of a function up to Len. The zero value is empty and ready to use.

func Function

func Function(m *ir.Module, fn *ir.Function) (*Typifier, error)

Function returns a Typifier that has typed every expression of fn.

func (*Typifier) Get

Get returns the type of expression h, which Grow has typed.

func (*Typifier) Grow

func (t *Typifier) Grow(m *ir.Module, fn *ir.Function, upTo ir.ExpressionHandle) error

Grow types every expression of fn below upTo that t has not typed yet, in arena order. A pass that appends expressions to fn calls it again to type them, as Rust's Typifier::grow.

The IR a frontend makes refers only to earlier expressions. The DXIL backend's passes also refer forward: an inlined call's result loads a later return slot, an alias stands for a later phi, a phi merges values of a loop's later iteration. Grow types such an expression once the expression it reads is typed, after the expressions that follow it; a phi takes the type of the first incoming value that is typed, since every incoming value has the phi's type.

On an error t keeps what it had before the call.

func (*Typifier) Inner

func (t *Typifier) Inner(m *ir.Module, h ir.ExpressionHandle) ir.TypeInner

Inner returns the type of expression h as a TypeInner of m.

func (*Typifier) Invalidate

func (t *Typifier) Invalidate(m *ir.Module, fn *ir.Function, h ir.ExpressionHandle) error

Invalidate types expression h, which t has typed, again from what fn's arena holds now: for a pass that rewrote h in place (Rust's Typifier::invalidate). The expressions h reads keep their types.

func (*Typifier) Len

func (t *Typifier) Len() int

Len returns the number of expressions t has typed: the first Len expressions of the function.

func (*Typifier) Reset

func (t *Typifier) Reset()

Reset empties t, for a new function.

Jump to

Keyboard shortcuts

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