{"modulePath":"github.com/txn2/mcp-data-platform","version":"v1.171.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package scriptalloc\n\nPackage 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.\n\nA 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.\n\nIt 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.\n\n## Functions\n\n```go\nfunc Bind(env starlark.StringDict) starlark.StringDict\n```\nBind 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.\n\n```go\nfunc Rewrite(file *syntax.File)\n```\nRewrite routes, in place, every operation in file that can build a large value in one step through the globals Bind binds:\n\n  - \\`x \\* y\\` and \\`x + y\\`;\n  - \\`name \\*= y\\` and \\`name += y\\` (the in-place add keeps extending a list in place);\n  - \\`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;\n  - \\`x.replace(...)\\`, \\`x.join(...)\\`, \\`x.extend(...)\\`, \\`x.split(...)\\`, \\`x.rsplit(...)\\` and \\`x.splitlines(...)\\`.\n\nPositions 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.\n\n","path":"github.com/txn2/mcp-data-platform/internal/platform/scriptalloc","name":"scriptalloc","synopsis":"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.","isRedistributable":true}
