budget
stdlib/extra/budget.hk: scoped resource budgets.
scoped! runs a closure under a sub-quota carved from the caller's remaining step and byte budgets. It returns Err(sys.BudgetExceeded.Exceeded) at its own boundary when the sub-quota runs out, where the whole-run ceiling of --max-steps and --max-bytes faults the run. It is the in-language primitive for running untrusted or unbounded nested work, an embedded interpreter or a user-supplied predicate, under a bounded and recoverable ceiling.
Metering is a bytecode-tier facility. hanki check accepts a call, and hanki build refuses an executable that reaches one with H0666.
scoped!
def scoped!<T>(bytes: i64, steps: i64, body: !() -> T [e]) -> Result<T, sys.BudgetExceeded> [e]
Runs body under a sub-quota of bytes and steps, carved from the caller's remaining byte and step budgets: the child can never exceed the parent, and its spend debits the parent. Returns Ok with the body's value, or Err(sys.BudgetExceeded.Exceeded) the moment either sub-quota is spent. A bytes or steps of zero or less bounds that dimension to nothing. Calls nest, an inner sub-quota carved from the outer one, and the parent's remaining budget is restored on both exits.
@no-doctest: bytecode-tier only, and a stdlib doctest also runs in the AOT test harness, which refuses it with H0666; covered by crates/hanki-cli/tests/runtime/fuel.rs