8.12

5.1 Representing Static Information🔗ℹ

Static information for an expression or binding is represented in key–value form. 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.

Rhombus uses several built-in static-information keys:

Static information is associated to a binding through a binding operator/macro, and it can be associated to an expression through a binding or through an expression operator/macro that adds static information to its parsed form (i.e., expansion). For example, the :: operator associates static information through an annotation. An annotation pairs a predicate with a set of static information to associate with any variable that is bound with the annotation. That’s why a binding p :: Posn makes every reference to p a dot provider: the annotation Posn indicates that every binding with the annotation gets a dot provider to access x and y. When :: is used in an expression, then static information indicated by the annotation is similarly associated with the overall :: expression, which is why e :: Posn is a dot provider for any expression e. Function-call forms and map-reference forms similarly attach static information to their parsed forms, sometimes, based on static information attached to the first subexpression.

Note that static information is associated with an expression, not a value. So, if Posn is passed as an argument to a function (instead of being called directly as a constructor), then the function ultimately receives a value and knows nothing of the expression that generated the value. That is, no part of the function’s implementation can take advantage of the fact that directly calling Posn would have formed a dot provider. The function might have an annotation on its argument that indicates a dot-provider constructor, but that’s a feature of the formal argument, and not of an actual value.