Skip to content

Commit

Permalink
Add #%deforestable to the de-expander
Browse files Browse the repository at this point in the history
A couple of things to note:

1. This de-expansion relies on the presence of the _name_ of the
original form in the syntax of `#%deforestable`. But we have already
discussed (meeting notes: "Playing Like a Grandmaster") that this is
only a temporary feature of its syntax and we would like to remove it,
as the compile-time metadata carried by the syntax (i.e., `info`)
should contain all relevant semantics. In particular, the
deforestation pass is intended to only operate in terms of stream
primitives such as "transformers" and "consumers" to which all surface
deforestable operations (such as `map` and `filter`) would translate.
And if the form is undeforested, code generation at the last stage of
compilation will use whatever implementation was provided by the user.
In either case, a literal name is not needed. But if we remove it, how
will we continue to "de-expand" this to provide a good error message?

2. The grammar of `#%deforestable` is slightly nontrivial and is
another reminder that we are in actuality encoding a duplicate grammar
here separately from the one already notated in Syntax Spec, and this
could be prone to bugs.
  • Loading branch information
countvajhula committed Jan 1, 2025
1 parent 6797eb3 commit 04589f2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion qi-lib/flow/extended/util.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
feedback
loop
loop2
clos)
clos
#%deforestable)
[(thread
expr ...)
#`(~> #,@(map prettify-flow-syntax (syntax->list #'(expr ...))))]
Expand Down Expand Up @@ -118,4 +119,5 @@
expr ...)
#`(clos #,@(map prettify-flow-syntax (syntax->list #'(expr ...))))]
[(esc expr) (prettify-flow-syntax #'expr)]
[(#%deforestable name _info ((~or* (~datum floe) (~datum expr)) expr) ...) #`(name #,@(map prettify-flow-syntax (syntax->list #'(expr ...))))]
[expr #'expr]))

0 comments on commit 04589f2

Please sign in to comment.