ir

package
v0.0.0-...-b18c8dd Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TagServicePrefix is the prefix for desugared tag service IDs
	TagServicePrefix = "__tagged_with."
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Argument

type Argument struct {
	Kind ArgumentKind
	Type types.Type // Expected parameter type

	// Value based on kind
	Service     *Service     // For ServiceRef
	Parameter   *Parameter   // For ParamRef
	Tag         *Tag         // For Tagged
	Literal     LiteralValue // For Literal
	Inner       *Argument    // For Spread (wraps another argument)
	GoRef       *GoRef       // For GoRef
	FieldAccess *FieldAccess // For FieldAccess
}

Argument is a resolved constructor argument.

type ArgumentKind

type ArgumentKind int

ArgumentKind indicates the type of argument.

const (
	LiteralArg ArgumentKind = iota
	ServiceRefArg
	ParamRefArg
	TaggedArg
	SpreadArg
	GoRefArg
	FieldAccessArg
)

type Builder

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

Builder constructs an IR Container from raw config.

func NewBuilder

func NewBuilder(resolver TypeResolver) *Builder

NewBuilder creates a new IR builder.

func (*Builder) Build

func (b *Builder) Build(cfg *di.Config) (*Container, error)

Build constructs the IR Container using a multi-phase approach.

type Constructor

type Constructor struct {
	Kind ConstructorKind
	Func *types.Func // For FuncConstructor
	Args []*Argument

	// For method constructors
	Receiver *Service // The service whose method is called

	// For generic constructors
	TypeArgs []types.Type // Resolved type arguments for generic functions

	// Signature info
	Params       []types.Type
	ResultType   types.Type
	ReturnsError bool
	Variadic     bool // True if function/method has variadic parameters
}

Constructor defines how a service is constructed.

func (*Constructor) Clone

func (c *Constructor) Clone() *Constructor

type ConstructorKind

type ConstructorKind int

ConstructorKind indicates the type of constructor.

const (
	FuncConstructor ConstructorKind = iota
	MethodConstructor
)

type Container

type Container struct {
	Services   map[string]*Service
	Parameters map[string]*Parameter
	// contains filtered or unexported fields
}

Container is the fully resolved intermediate representation of a DI container.

func NewContainer

func NewContainer() *Container

func (*Container) ParamGetters

func (c *Container) ParamGetters() map[string]string

ParamGetters returns parameter getter methods needed by the container.

func (*Container) ServiceIDsPostOrder

func (c *Container) ServiceIDsPostOrder() []string

func (*Container) ServicesPostOrder

func (c *Container) ServicesPostOrder() iter.Seq[*Service]

ServicesPostOrder returns an iterator that yields services in post-order (dependencies before dependents). This is useful for operations that need to process dependencies before their dependents.

type DurationValue

type DurationValue time.Duration

DurationValue represents a parsed duration.

type FieldAccess

type FieldAccess struct {
	Service    *Service   // Non-nil for @service targets
	GoRef      *GoRef     // Non-nil for !go: targets
	FieldNames []string   // Field chain, e.g. ["Database", "DSN"]
	ResultType types.Type // Type of the final field
}

FieldAccess holds a field access expression on a service or Go symbol.

type GoRef

type GoRef struct {
	Object types.Object // *types.Var or *types.Const
}

GoRef holds a reference to a package-level variable or constant.

type LiteralType

type LiteralType int

LiteralType indicates the type of literal.

const (
	StringLiteral LiteralType = iota
	IntLiteral
	FloatLiteral
	BoolLiteral
	NullLiteral
	DurationLiteral
)

type LiteralValue

type LiteralValue struct {
	Type  LiteralType
	Value interface{} // string, int64, float64, bool, or nil
}

LiteralValue holds a typed literal value.

type Parameter

type Parameter struct {
	Name  string
	Type  types.Type
	Value LiteralValue
}

Parameter is a resolved parameter definition.

func (*Parameter) GetterMethod

func (p *Parameter) GetterMethod() string

GetterMethod returns the Provider method name for this parameter's type.

type Phase

type Phase interface {
	Apply(cfg *di.Config, container *Container) error
}

type Service

type Service struct {
	ID   string
	Type types.Type

	// Construction
	Constructor *Constructor
	Alias       *Service // If this is an alias, points to target service

	// Lifecycle
	Shared        bool
	Public        bool
	Autoconfigure bool

	// Tags
	Tags []*ServiceTag

	// Computed
	Dependencies []*Service // Direct dependencies (resolved)
}

Service is a fully resolved service definition.

func (*Service) Clone

func (s *Service) Clone() *Service

func (*Service) IsAlias

func (s *Service) IsAlias() bool

IsAlias returns true if this service is an alias.

type ServiceTag

type ServiceTag struct {
	Tag        *Tag
	Attributes map[string]interface{}
}

ServiceTag is a tag attached to a service.

type Tag

type Tag struct {
	Name          string
	ElementType   types.Type
	SortBy        string
	Public        bool
	Autoconfigure bool
	Services      []*Service // Services with this tag (sorted by priority)
}

Tag is a resolved tag definition.

type TypeResolver

type TypeResolver interface {
	LookupType(typeStr string) (types.Type, error)
	LookupFunc(pkgPath, name string) (*types.Func, error)
	LookupMethod(recv types.Type, name string) (*types.Func, error)
	LookupVar(pkgPath, name string) (types.Object, error)
	// InstantiateFunc instantiates a generic function with the given type arguments.
	// Returns the instantiated signature. typeArgs are type strings to resolve.
	InstantiateFunc(fn *types.Func, typeArgs []string) (*types.Signature, []types.Type, error)
}

TypeResolver resolves type strings to Go types.

Jump to

Keyboard shortcuts

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