scriptalloc

package
v1.167.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

func Rewrite(file *syntax.File)

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.

Jump to

Keyboard shortcuts

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