Documentation
¶
Overview ¶
Package paramhints infers parameter types from call site arguments.
This package analyzes function call sites to infer parameter types for functions without explicit type annotations. When a function is called with known-type arguments, those types hint at the parameter types.
Hint Collection ¶
For each call site:
foo(123, "bar") -- hints: param1=number, param2=string
The package collects argument types and associates them with parameter positions. Multiple call sites contribute hints that are joined.
Hint Merging ¶
When multiple calls provide conflicting hints:
foo(1) -- hints: param1=number
foo("a") -- hints: param1=string
The hints are joined to produce: param1 = number | string
Integration ¶
Parameter hints feed into function signature inference, providing types for parameters that lack explicit annotations.
Index ¶
- func BuildParamHintSigView(store api.StoreView, graph *cfg.Graph, parent *scope.State, ...) map[*ast.FunctionExpr][]typ.Type
- func EnsureHintCapacity(hints []typ.Type, size int) []typ.Type
- func IsInformativeHintType(t typ.Type) bool
- func MergeCallArgHintAt(hints []typ.Type, idx int, argType typ.Type, join HintJoinFn, ...) ([]typ.Type, bool)
- func MergeHintAt(hints []typ.Type, idx int, hint typ.Type, join HintJoinFn) ([]typ.Type, bool)
- func MergeIntoSignature(fn *ast.FunctionExpr, hints []typ.Type, sig *typ.Function) *typ.Function
- func NormalizeHintType(t typ.Type) typ.Type
- func WidenParamHintType(t typ.Type) typ.Type
- type HintJoinFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildParamHintSigView ¶
func BuildParamHintSigView( store api.StoreView, graph *cfg.Graph, parent *scope.State, stdlib *scope.State, ) map[*ast.FunctionExpr][]typ.Type
BuildParamHintSigView builds a function-expression keyed hint map for this graph. It merges per-iteration scratch hints with symbol-based hints from the store. Scratch hints take precedence over symbol-derived hints.
func EnsureHintCapacity ¶ added in v1.5.6
EnsureHintCapacity grows hint vector to at least size.
func IsInformativeHintType ¶ added in v1.5.6
IsInformativeHintType reports whether a type carries useful call-site information for parameter hint propagation.
It intentionally rejects top-like and empty placeholder shapes that tend to poison hints, while preserving structured hints such as maps/arrays with partial information (for example `{[string]: any[]}`).
func MergeCallArgHintAt ¶ added in v1.5.8
func MergeCallArgHintAt(hints []typ.Type, idx int, argType typ.Type, join HintJoinFn, unknownOnNil bool) ([]typ.Type, bool)
MergeCallArgHintAt merges a call-argument observation into a parameter hint slot. Unlike MergeHintAt, unresolved/top-like argument observations are preserved as uncertainty evidence so later literal calls cannot over-specialize unannotated parameters.
func MergeHintAt ¶ added in v1.5.6
MergeHintAt normalizes and joins one hint into vector slot idx.
func MergeIntoSignature ¶ added in v1.5.8
MergeIntoSignature replaces unannotated parameter slots (and refinable top-like annotations) with call-site hints.
func NormalizeHintType ¶ added in v1.5.6
NormalizeHintType applies canonical widening and soft-member pruning.