Documentation
¶
Overview ¶
Package scriptalloc routes the operations that can build a large value in one interpreter step through checks against the run's memory budget, so the value that would take a run past it is refused before it is allocated.
A run's memory is measured at host calls and every few thousand steps (scriptguard.PaceSteps), which bounds what a run builds a little at a time. It does not bound one operation that allocates a great deal at once: a repeat ([0] * n), a concatenation repeated (s = s + s), a list extended by itself, a replacement or a join that multiplies its input, or a range turned into a list. Each of those is routed here, sizes the value it is about to build, and asks scriptguard.Reserve first.
It has to be a rewrite, for the reason scriptprintf gives: Starlark evaluates operators and a value's methods inside the interpreter, with no hook a predeclared value can take. The names the rewrite calls are not identifiers, so a script can neither call nor shadow them.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bind ¶
func Bind(env starlark.StringDict) starlark.StringDict
Bind returns env with the rewrite's globals bound, and the builtins that materialize an iterable replaced by ones that size it first. A name env already binds is left as env binds it.
func Rewrite ¶
Rewrite routes, in place, every operation in file that can build a large value in one step through the globals Bind binds:
- `x * y` and `x + y`;
- `name *= y` and `name += y` (the in-place add keeps extending a list in place);
- `x[k] *= y` and `x[k] += y`, as one call taking x and k once, so a target with a side effect is evaluated once as it is natively;
- `x.replace(...)`, `x.join(...)`, `x.extend(...)`, `x.split(...)`, `x.rsplit(...)` and `x.splitlines(...)`.
Positions are kept: each call is placed at the operator or the method name, so an error is reported where the script wrote it. An augmented assignment to a field (s.f += y) is left alone: no Starlark value a script holds has a field that can be assigned.
Types ¶
This section is empty.