paramhints

package
v1.5.11 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 7 Imported by: 0

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

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

func EnsureHintCapacity(hints []typ.Type, size int) []typ.Type

EnsureHintCapacity grows hint vector to at least size.

func IsInformativeHintType added in v1.5.6

func IsInformativeHintType(t typ.Type) bool

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

func MergeHintAt(hints []typ.Type, idx int, hint typ.Type, join HintJoinFn) ([]typ.Type, bool)

MergeHintAt normalizes and joins one hint into vector slot idx.

func MergeIntoSignature added in v1.5.8

func MergeIntoSignature(fn *ast.FunctionExpr, hints []typ.Type, sig *typ.Function) *typ.Function

MergeIntoSignature replaces unannotated parameter slots (and refinable top-like annotations) with call-site hints.

func NormalizeHintType added in v1.5.6

func NormalizeHintType(t typ.Type) typ.Type

NormalizeHintType applies canonical widening and soft-member pruning.

func WidenParamHintType

func WidenParamHintType(t typ.Type) typ.Type

Types

type HintJoinFn added in v1.5.6

type HintJoinFn func(prev, next typ.Type) typ.Type

Jump to

Keyboard shortcuts

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