Documentation
¶
Overview ¶
Package model holds Loom's intermediate representation: providers and graphs expressed in terms of go/types, never in terms of strings or AST nodes alone.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasBinding ¶
HasBinding reports whether the provider already serves the interface t.
func SameConstructorHint ¶
SameConstructorHint explains the most common duplicate provider: one constructor listed twice in the same provider declaration.
loom.As already provides the concrete type as well as the interface, so the plain Provide beside it is redundant. Without this hint the provider list shows the same constructor name twice at two nearby positions, which reads like a bug in loom rather than a redundant line.
This covers only entries in one declaration. A graph may legitimately expose a constructor that a module already provides; see Parser.checkProviders.
typeString renders a type for display, so this package does not need to know how diagnostics format types.
func SameTypeArgs ¶
SameTypeArgs reports whether two providers instantiate the same generic declaration the same way, so Repository[User] and Repository[Article] are never treated as the same constructor.
Types ¶
type Graph ¶
type Graph struct {
// VarName is the package-level variable holding the declaration.
VarName string
// Name is the name of the generated initializer function.
Name string
// Target is the type the graph builds.
Target types.Type
// WithCtx reports whether loom.WithContext() was declared.
WithCtx bool
// Pos is the declaration's source position.
Pos token.Position
// Pkg is the package containing the declaration.
Pkg *packages.Package
// Providers are the flattened providers, in declaration order.
Providers []*Provider
}
Graph is a parsed dependency graph declaration.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index maps types to providers using go/types identity: equal types are determined by types.Identical, not by string comparison.
type Provider ¶
type Provider struct {
Kind Kind
// Name is the display name used in diagnostics and variable naming, such
// as "NewDB" or "config".
Name string
// Pos is the provider's source position: the reference in the graph
// declaration.
Pos token.Position
// DeclPos is the position where the constructor is defined.
DeclPos token.Position
// Modules records the named module expansion path that included this
// provider. It is empty for providers written directly in the graph.
Modules []string
// Output is the type of the value this provider produces.
Output types.Type
// Bindings are the interface types this provider also serves, set by
// loom.As[I](ctor). A graph may add one to a constructor a module already
// provides, which is how Wire's graph-level wire.Bind is expressed.
Bindings []types.Type
// Inputs are the constructor's parameter types, in order. For a variadic
// constructor the element type is used and Variadic is set.
Inputs []types.Type
Variadic bool
// HasError reports whether the constructor returns an error as its last
// result.
HasError bool
// Cleanup is the exact function type of the constructor's cleanup result,
// or nil. Its signature is normalized during code generation.
Cleanup types.Type
// Reference to the constructor, used to emit the call.
RefObj types.Object
RefPkg *types.Package
RefName string
TypeArgs []types.Type
// Value expression for KindValue.
Expr ast.Expr
// ExprPkg is the package in which Expr appears; its TypesInfo resolves the
// identifiers in Expr.
ExprPkg *packages.Package
}
Provider is a single value-producing node of a dependency graph.
func (*Provider) ModuleSuffix ¶
Targets lists every type this provider serves: its result plus each interface it is bound to. ModuleSuffix returns a concise provenance annotation for diagnostics.