local blocks are ubx’s answer to it. A local computes a value once, gives it a name, and makes it available anywhere in the stack as local.name. Unlike inputs — which come from outside the stack — locals are computed from values that already exist: other inputs, other locals, or any expression the compiler can resolve at compile time. They’re not runtime abstractions; they’re a compile-time convenience that disappears entirely in the generated code, replaced by the values they computed.
What you’ll learn
- How
localblocks compute and name reusable values - How to reference locals throughout your stack
- When to use a
localinstead of repeating an expression
Why this matters
Locals are especially powerful for shared tag maps. Define your standard tags once in a
local block and reference local.tags in every unit block — changing the tag schema in one place updates every resource in the stack.The source code
How it works
Locals are evaluated in the IR pass
During the AST → IRProgram pass,
local blocks are resolved into IRLocal nodes. Their values are expressions — strings, objects, references to inputs — all Resolved<T> since they don’t depend on resource outputs.References are inlined at compile time
When
local.prefix appears in a unit block attribute, the compiler substitutes the local’s expression inline. No runtime overhead — locals are a compile-time convenience, not a runtime abstraction.What ubx generates
Common mistakes
Run it
What you learned
local blocks compute named values that can be reused across the stackLocals are
Resolved<T> — they cannot reference resource outputsSeparating locals into
locals.iac keeps your computed values easy to find and updateNext steps
Multiple resources with deps
Reference one resource from another
local block reference
Full local block syntax
Full runnable example: github.com/ubiquex/ubx-examples/02-locals

