9.0

3.2 Representing Static Information🔗ℹ

Static information for an expression or binding is represented in key–value form and encoded within syntax objects at expansion time. When static information is associated with a binding, it is propagated to each use of the bound variable, so we can refer to an expression E that has static information without loss of generality.

A macro defined with expr.macro can associate arbitrary key–value static information with its result using statinfo_meta.wrap. More generally, any macro that produces or manipulates an expression can add static information to the expression using statinfo_meta.wrap. A macro can consult static information for an expression using statinfo_meta.lookup and related functions. Predefined Rhombus forms use these operations internally; for example, :: expands to an expression that has static information provided by the annotation after ::.

The statinfo.key forms binds an identifier for use as a static-information key. Rhombus built-in forms use several built-in keys that can be accessed as identifier-valued variables like statinfo_meta.dot_provider_key:

See Static Information for additional predefined keys.

Static information from different sources sometimes needs to be merged, and merging takes one of two forms: and mode or or mode. Most obviously, and mode is used when combining static information from annotations via the && operator, and or mode for combining with ||. For example, satisfying the annotation List.of(Int) || List.of(String) implies the static information of List, at least. Another example of and mode is in def bind = expr, where both bind and expr can supply static information about the binding, and both sets of information will apply to uses of the defined names. Another example of or mode isin if test_expr | then_expr | else_expr, where the overall if form has static information thatis common to both then_expr and else_expr. When a new static-information key is defined with statinfo.key, then compile-time merging functions are provided in ~and and ~or clauses.