Skip to content

Qi Compiler Sync Dec 9 2022

Siddhartha Kasivajhula edited this page Dec 15, 2022 · 5 revisions

Completed Initial Bindings Support

Qi Compiler Sync Dec 9 2022

Adjacent meetings: Previous | Up | Next

Summary

We completed initial support for binding single and multiple values in Qi!

Background

Last time, we declared scoping rules for bindings in the language. We still needed to:

  1. Properly discern host language expressions during expansion and compilation to avoid attempting to transform such expressions as part of the bindings implementation (we referred to this as the "unbounded nesting problem" in previous meeting notes)
  2. Support binding multiple values in the (as ...) binding form.

Binding Classes as a Kind of Syntax Parameter

As groundwork for the implementation, Michael added a new racket-var binding class to syntax-spec ("the artist formerly known as ..." OK I think we all know this at this point). Since Qi's variables are exactly the same as Racket variables, it was no longer necessary to define a custom qi-var binding class anymore, and we just used this newly created one.

Binding classes are analogous to syntax parameters in that they lend syntax special meaning only in certain contexts and not in others. They can be used to implement nontrivial compilation of bindings, for instance, to constrain the scope of bindings to certain forms. We don't need such customizations in Qi at this time.

Tagging Host Language Expressions

Syntax-spec also added a new #%host-expression tag for components of expressions that are known to be host-language syntax. This supports the compiler handling such forms in a special way. In particular, this allowed us to avoid doing the bindings transformation to binding references when we encountered a host language expression. To do this, we implemented a new find-and-map function to apply the bindings transformation by walking the tree from the root down to the leaves. This way, we can decide whether to apply the transformation or not depending on whether there is a wrapping #%host-expression form, addressing (1) above.

Binding Multiple Values

We declared in the expander that the as form can accept any number of identifiers, and then modified the compiler to apply the bindings transformation to each of these identifiers. This now supports (~> (1 2) (as v w) (~a "The sum of " v " and " w " is " (+ v w))).

Next Steps

This completes the initial proof-of-concept support for bindings in Qi (pending review and testing, of course)! Next:

  • Add docs for syntax-spec, now that it has a name and its syntax has begun to exhibit a certain unity. Michael on the current state of docs: "There are some docs, just no English." [There are formal grammars for various forms 😄]
  • Get the bindings PR ready for review towards merging it into the compiler integration branch.
  • Review the initial design for bindings and see what other bindings cases we could support next.
  • Re-generate the benchmarks showing the performance difference of each Qi form with respect to the main branch, so that we can take stock and start restoring parity towards merging back to main.

Attendees

Michael, Sid

Clone this wiki locally