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

budget

package
v0.0.0-...-0800e44 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package budget counts the work and the size of a compile against their limits. A Limit says how far a count may go, or that nothing bounds it, and a Budget counts what is spent against one (GitHub #785).

Every count the compile holds to a limit counts through it, so "unbounded" has one spelling, the zero Limit, and no sum passes math.MaxInt. A depth, a chain's hops or a constant compared beside the one loop it bounds needs neither and stays beside its check. What crossing a limit does stays with the site that counts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Budget

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

Budget counts what is spent against a Limit. The zero Budget is unbounded and has spent nothing. It is a value: a copy counts on its own.

func New

func New(l Limit) Budget

New returns a Budget of l with nothing spent.

func (*Budget) Exhaust

func (b *Budget) Exhaust()

Exhaust spends all that is left and one more, so nothing fits, an unbounded budget included: for a count that has found it would never end.

func (*Budget) Exhausted

func (b *Budget) Exhausted() bool

Exhausted reports whether the budget is past its limit, was exhausted, or was charged what no count is.

func (*Budget) Limit

func (b *Budget) Limit() Limit

Limit returns the Limit the budget counts against.

func (*Budget) Remaining

func (b *Budget) Remaining() Limit

Remaining returns the Limit on what may yet be spent: what is left of a bounded limit, nothing once exhausted, and no bound under an unbounded one.

func (*Budget) Spend

func (b *Budget) Spend(n int) bool

Spend charges n and reports whether the budget is still within its limit. The count is held at math.MaxInt. A negative n is no charge a count makes, as an overflowed product would be, so it exhausts the budget: the safe direction.

func (*Budget) Spent

func (b *Budget) Spent() int

Spent returns what has been charged, held at math.MaxInt.

type Limit

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

Limit is how far a count may go: at most some number, or without bound. The zero Limit is unbounded, so an options field a caller leaves unset bounds nothing, as every internal options type the compiler projects its public budgets onto has it.

func AtMost

func AtMost(n int) Limit

AtMost returns the Limit a count crosses once it passes n. A negative n is taken as zero, which admits nothing: the safe direction, where the public spelling would read a negative budget as none at all.

func FromOption

func FromOption(value, def int) Limit

FromOption returns the Limit a budget set as openapi.Limits spells one: value itself, def where value is zero, and unbounded where it is negative. It is the one place that spelling is read.

func Unbounded

func Unbounded() Limit

Unbounded returns the Limit no count crosses.

func (Limit) Admits

func (l Limit) Admits(n int) bool

Admits reports whether a count of n is within l.

func (Limit) Cap

func (l Limit) Cap() int

Cap returns l as the bound of a loop: its most, or math.MaxInt where l is unbounded, which no count of what memory holds reaches.

func (Limit) Max

func (l Limit) Max() (int, bool)

Max returns the most a count may reach under l, and false where l is unbounded.

func (Limit) Past

func (l Limit) Past() int

Past returns the least count l does not admit, which is as far as a count need go to tell that it crosses l, or math.MaxInt where no int is past l.

func (Limit) Plus

func (l Limit) Plus(o Limit) Limit

Plus returns the Limit on two counts taken together, one within l and one within o: their sum, held at math.MaxInt, or unbounded where either is.

Jump to

Keyboard shortcuts

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