# Today's Qi meeting notes

**URL:** https://racket.discourse.group/t/todays-qi-meeting-notes/2323
**Category:** General
**Tags:** event, qi
**Created:** [September 17, 2023, 5:25pm UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323 "2023-09-17T17:25:43Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![countvajhula](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/countvajhula/32/65_2.png) [@countvajhula](https://racket.discourse.group/u/countvajhula)
#### Post date: [September 17, 2023, 5:25pm UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323/1 "2023-09-17T17:25:43Z")

</div>

Hi all,  
We've been sharing these meeting notes privately among attendees and enthusiasts, but some of us felt it would be fun and useful to share them on here, so we'll start doing that. The Qi compiler project has really picked up steam lately and there are lots of very interesting avenues for exploration. They are open to all -- come on by!

Here are the latest notes (actually from Friday -- but the topic is so that this can be reused weekly).

[A Long Stream is Not Easily Exhausted](https://github.com/drym-org/qi/wiki/Qi-Compiler-Sync-Sept-15-2023)

We try to have fun summary names for each meeting to help us remember what they were about. This one references a Chinese proverb.

Enjoy!

---

<div class="post-metadata">

### Author: ![dominik.pantucek](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/dominik.pantucek/32/144_2.png) [@dominik.pantucek](https://racket.discourse.group/u/dominik.pantucek)
#### Post date: [September 17, 2023, 5:42pm UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323/2 "2023-09-17T17:42:01Z")

</div>

Hey, thanks for placing it here so quickly.

I was (one of) requesting this, because:

I found more (future) issues with fold interaction with left and right threading:

```scheme
#lang racket/base

(require qi)

(display "Racket foldr: ")
(foldr
 string-append
 "0"
 (map
  number->string
  (filter odd? '(1 2 3 4 5))))

(display "Qi foldr under right threading: ")
((flow
  (~> (filter odd?)
      (map number->string)
      (foldr string-append "0")))
 '(1 2 3 4 5))

(display "Qi foldr under left threading: ")
((flow
  (~>> (filter odd?)
      (map number->string)
      (foldr string-append "0")))
 '(1 2 3 4 5))

(display "Racket foldl: ")
(foldl
 string-append
 "0"
 (map
  number->string
  (filter odd? '(1 2 3 4 5))))

(display "Qi foldl under left threading: ")
((flow
  (~>> (filter odd?)
      (map number->string)
      (foldl string-append "0")))
 '(1 2 3 4 5))

(display "Qi foldl under right threading: ")
(with-handlers ((exn? (λ (ex)
                        (newline)
                        (raise ex))))
  ((flow
    (~> (filter odd?)
        (map number->string)
        (foldl string-append "0")))
   '(1 2 3 4 5)))

```

Basically the last example raises correctly an exception while the "Qi foldr under left threading" truly behaves like "Qi foldr under right threading". Which is the weird behavior you've already noticed.

Should the semantics remain the same (I assume they should) than foldr must work only with the right chirality and foldl only with left chirality.

Right now only the optimized foldr misbehaves - which means this is the right time to make sure it not only gets fixed but we put at least some tests in place so that this does not hit us in the future with other optimizations. I am pretty confident that other fusion-terminating operations will have similar problems with chirality. And I used non-commutative operation (string-append) to double-check. Commutative operations hide a lots of errors here so another suggestion is to make sure we include non-commutative operations in any tests for fold-like optimizations.

OTOH I hope I got it right: right chirality means the values go as the first (leftmost arguments) and left chirality means they go last (rightmost). I am not sure about this, on a second thought it might be the other way round. That means I might be using a flipped terminology here - yet still I am fairly confident the examples show a real problem. Can anyone re-check my naming of left/right chirality for threading macros in Qi?

```scheme
;; Right-threading is just normal threading but with a syntax
;; property attached to the components indicating the chirality
(define-qi-syntax-rule (thread-right onex:right-threading-clause ...)
  (~> onex.chiral ...))

```

This snippet probably means that default really is left and if chirality is set, the default is right (reverse).

---

<div class="post-metadata">

### Author: ![Gambiteer](https://avatars.discourse-cdn.com/v4/letter/g/779978/32.png) [@Gambiteer](https://racket.discourse.group/u/Gambiteer)
#### Post date: [September 17, 2023, 6:10pm UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323/3 "2023-09-17T18:10:06Z")

</div>

I like these reports, thanks.

---

<div class="post-metadata">

### Author: ![dominik.pantucek](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/dominik.pantucek/32/144_2.png) [@dominik.pantucek](https://racket.discourse.group/u/dominik.pantucek)
#### Post date: [September 18, 2023, 7:53am UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323/4 "2023-09-18T07:53:05Z")

</div>

And a little side note (I'll officially announce it later), the official Actor Basic is now hosted at:

> **[rrll-abasic · master · Dominik Joe Pantůček / rrll · GitLab](https://gitlab.com/racketeer/rrll/-/tree/master/rrll-abasic?ref_type=heads)**
>
> GitLab.com

It is just one package out of a collection of packages aimed at writing roguelike (more like rogue-lite as I am interested in the real-time nature of such environments) games.  
The splicing case syntax @countvajhula mentioned in the notes is:

> <https://gitlab.com/racketeer/rrll/-/blob/master/rrll-abasic/abasic/expander.rkt?ref_type=heads#L192>

> <https://gitlab.com/racketeer/rrll/-/blob/master/rrll-abasic/abasic/expander.rkt?ref_type=heads#L212>

> <https://gitlab.com/racketeer/rrll/-/blob/master/rrll-abasic/abasic/expander.rkt?ref_type=heads#L427>

It's very rudimentary, but shows the purpose and simple implementation of splicing syntax in dispatching expressions.

---

<div class="post-metadata">

### Author: ![countvajhula](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/countvajhula/32/65_2.png) [@countvajhula](https://racket.discourse.group/u/countvajhula)
#### Post date: [September 18, 2023, 8:32am UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323/5 "2023-09-18T08:32:44Z")

</div>

Interesting, I'll have to think about this some more (or you could explain it at the next meeting!), but I think you may be confusing the "chirality" in the code with a different idea. In the code, chirality refers to where in the original expression the argument(s) should be placed. Right chirality means that the argument will be passed in the last argument position (it's very similar to the right threading operator in the threading library):

```scheme
(~>> (filter odd?) (map sqr))

```

would be equivalent to

```scheme
(~> (filter odd? _) (map sqr _))

```

(just for illustration), which, in the reference (non-optimizing) compiler (to use your terminology 🙂 ), compiles down to:

```scheme
(map sqr (filter odd (list 1 2 3)))

```

Left chirality is the default and means the argument will be passed in the first position of each application.

```scheme
(~> (filter odd?) (map sqr))

```

would be equivalent to

```scheme
(~> (filter _ odd?) (map _ sqr))

```

which the reference compiler compiles to:

```scheme
(map (filter (list 1 2 3) odd?) sqr)

```

So use of left-threading should be an error for both `foldl` and `foldr` since all of these functions expect the list in the last position rather than the first position.

But it's quite possible that going through the stream elements from left-to-right vs right-to-left (which I think is what you're talking about) would have different considerations for `foldl` vs `foldr`. I don't recall how it is in St-Amour's writeup (mentioned in several places in recent meeting notes - for anyone following along) but maybe he already accounts for this?

---

<div class="post-metadata">

### Author: ![countvajhula](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/countvajhula/32/65_2.png) [@countvajhula](https://racket.discourse.group/u/countvajhula)
#### Post date: [September 23, 2023, 1:42am UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323/6 "2023-09-23T01:42:33Z")

</div>

Here are today's notes:

[Threading a Needle in a Haystack](https://github.com/drym-org/qi/wiki/Qi-Compiler-Sync-Sept-22-2023)

Enjoy!

---

<div class="post-metadata">

### Author: ![countvajhula](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/countvajhula/32/65_2.png) [@countvajhula](https://racket.discourse.group/u/countvajhula)
#### Post date: [September 30, 2023, 7:53am UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323/7 "2023-09-30T07:53:03Z")

</div>

Today's notes:

[Start Somewhere, and then, Continue.](https://github.com/drym-org/qi/wiki/Qi-Compiler-Sync-Sept-29-2023)

---

<div class="post-metadata">

### Author: ![countvajhula](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/countvajhula/32/65_2.png) [@countvajhula](https://racket.discourse.group/u/countvajhula)
#### Post date: [October 7, 2023, 4:33am UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323/8 "2023-10-07T04:33:09Z")

</div>

Today's:

[Validly Verifying that we're Compiling Correctly](https://github.com/drym-org/qi/wiki/Qi-Compiler-Sync-Oct-6-2023)

Among other things, we discussed the feedback on compiler testing approaches from [the other thread](https://racket.discourse.group/t/best-practices-for-testing-compiler-optimizations/2369/4). We'll likely continue that discussion in the coming weeks.

Enjoy, and hope to see you next time 🙂

---

<div class="post-metadata">

### Author: ![dominik.pantucek](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/dominik.pantucek/32/144_2.png) [@dominik.pantucek](https://racket.discourse.group/u/dominik.pantucek)
#### Post date: [October 7, 2023, 4:02pm UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323/9 "2023-10-07T16:02:31Z")

</div>

> **[GitHub - dzoep/qi at first-optimizations](https://github.com/dzoep/qi/tree/first-optimizations)**
>
> first-optimizations

Try this in macro stepper 🙂

It only covers the before/after optimization (just before introducing bindings), but this is probably the right approach. It allows us to keep some expansion to happen in different order than the plain macro expansion going from the outermost to the innermost expressions and yet present it as distinct transformation steps. All we need to do is to use `emit-local-step` in the right places of the Qi compiler (like it is probably used in the normal Racket macro expander).

I still have to verify that this is what the normal Racket expander does internally. Or perhaps @ryanc can chime in?

---

<div class="post-metadata">

### Author: ![ryanc](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/ryanc/32/71_2.png) [@ryanc](https://racket.discourse.group/u/ryanc)
#### Post date: [October 7, 2023, 5:34pm UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323/10 "2023-10-07T17:34:25Z")

</div>

The macro expander emits lots of different kinds of [events](https://github.com/racket/macro-debugger/blob/master/macro-debugger-text-lib/macro-debugger/model/deriv-tokens.rkt) that allow the macro stepper to reconstruct the context and steps of expansion. In the expander, the interface with the macro stepper is mainly in [`log.rkt`](https://github.com/racket/racket/blob/master/racket/src/expander/expand/log.rkt). Look for calls to `log-expand` etc in [`expr.rkt`](https://github.com/racket/racket/blob/master/racket/src/expander/expand/expr.rkt) and other files in that directory.

For example, in the expansion of a `lambda` expression, the expander would emit a `visit` event ("I'm about to start expanding _this_ expression"), then a `prim-lambda` event ("After inspecting the expression and resolving the head identifier, looks like Racket's `lambda` syntax"), then a `lambda-renames` event ("Here are the formal parameters with the new lexical scope applied"), then events for its body, then various events to indicate that it's exiting the context of the `lambda` expression. (I've skipped a few for simplicity.)

The macro stepper [parses](https://github.com/racket/macro-debugger/blob/master/macro-debugger-text-lib/macro-debugger/model/deriv-parser.rkt) that sequence of events into a tree --- yes, parses, using Racket's LALR(1) parser generator --- and then it uses that tree to generate reduction steps. The tree structure is used to determine the context of each expansion step, so macro steps within the `lambda` expression's body show the surrounding `lambda` expression, show arrows between `lambda`-bound variables and apparent references, etc.

The `macro-debugger/emit` API doesn't provide a way to set the context of a remark or artificial step, but that could probably be added, at least in a limited form.

---

<div class="post-metadata">

### Author: ![countvajhula](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/countvajhula/32/65_2.png) [@countvajhula](https://racket.discourse.group/u/countvajhula)
#### Post date: [October 14, 2023, 2:57am UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323/11 "2023-10-14T02:57:47Z")

</div>

[I Once Was Blind but Now I See (or, the Spectre of Friday the Thirteenth)](https://github.com/drym-org/qi/wiki/Qi-Compiler-Sync-Oct-13-2023)

Enjoy 😆

---

<div class="post-metadata">

### Author: ![countvajhula](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/countvajhula/32/65_2.png) [@countvajhula](https://racket.discourse.group/u/countvajhula)
#### Post date: [October 20, 2023, 10:23pm UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323/12 "2023-10-20T22:23:30Z")

</div>

Today's: [Challenges with Multiple Values in Streams](https://github.com/drym-org/qi/wiki/Qi-Compiler-Sync-Oct-20-2023)

Btw just want to put [Context is Everything](https://github.com/drym-org/qi/wiki/Qi-Compiler-Sync-Oct-13-2023#context-is-everything) (from last time) on your radar @ryanc and @michaelballantyne .

---

<div class="post-metadata">

### Author: ![countvajhula](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/countvajhula/32/65_2.png) [@countvajhula](https://racket.discourse.group/u/countvajhula)
#### Post date: [November 14, 2023, 2:35am UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323/13 "2023-11-14T02:35:08Z")

</div>

Friday's notes:

[Deforesting Vindaloo](https://github.com/drym-org/qi/wiki/Qi-Compiler-Sync-Nov-10-2023)

The discussion on how to allow users to extend Qi compiler optimizations (starting at "deforestation for bepoke datatypes") was an especially interesting topic that came up.

Incidentally, next time, @dominik.pantucek is planning to give a demo of the 3D rendering engine for the [Racket Roguelike Library](https://gitlab.com/racketeer/rrll), powered by Actor Basic (another flow-oriented language like Qi). If you're a fan of 80s/90s era games, I think you wouldn't wanna miss it.

---

<div class="post-metadata">

### Author: ![countvajhula](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/countvajhula/32/65_2.png) [@countvajhula](https://racket.discourse.group/u/countvajhula)
#### Post date: [November 19, 2023, 5:27am UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323/14 "2023-11-19T05:27:58Z")

</div>

Friday's notes:

[Rogue's Gambit](https://github.com/drym-org/qi/wiki/Qi-Compiler-Sync-Nov-17-2023)

Highlights:

- Dominik gave an awesome demo of the Racket Roguelike Library
- Brad (@Gambiteer ), author of SRFI 231, described at a high level a deforestation-like approach in generalized arrays
- Why bother deforesting `range` when it doesn't improve performance on its own?
- Why do we still need `begin-encourage-inline` when we have already said `define-inline`? (we don't know. Any ideas?)
- The huge potential of Qi's "no accidental side effects" policy

We also finally returned to [the discussion about good ways to test the compiler](https://racket.discourse.group/t/best-practices-for-testing-compiler-optimizations/2369), and adopted a clever technique suggested by @samth and @gus-massa to [test the compiler's initial normalization pass](https://github.com/drym-org/qi/pull/115/commits/317173f6d90b64e816fb0b29ca040849f45979d8). We're going to continue exploring this next time so you're welcome to join if you're interested in either sharing or learning more here.

---

<div class="post-metadata">

### Author: ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)
#### Post date: [November 20, 2023, 4:01pm UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323/15 "2023-11-20T16:01:08Z")

</div>

The notes on delayed computation by building a description and executing is (IIUC) essentially the monad-interpreter pattern: an algebraic datatype describes the operations and is equipped with monadic structure; the functions (such as `map`) return a value of the datatype rather than performing the computation. One can then independently specify how to execute the computation, such as via a reference interpreter or via an optimizing compiler, by writing programs over the type of the computation.

The classic IO monad does something like this internally in Haskell, and I think the pattern is commonly used for other problems.

---

<div class="post-metadata">

### Author: ![usao](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/usao/32/1375_2.png) [@usao](https://racket.discourse.group/u/usao)
#### Post date: [November 21, 2023, 1:10am UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323/16 "2023-11-21T01:10:15Z")

</div>

I’m interested in helping with the inlining issue if you’d like to provide more information.

Edit: I should probably leave a general note on this issue. The approach of `define-inline` is that it’s a macro, not normal inlining done by the compiler, while `begin-encourage-inline` attaches a `'compiler-hint:cross-module-inline` syntax property that, well, encourages inlining. In particular, higher-order use isn’t inlined by `define-inline` (it expands to a variable reference in this case), while there can be more things done by the compiler. This is likely what is causing the issue, because Qi is probably relying on the higher-order usage? I would suggest just simply use `begin-encourage-inline` and let the compiler figure out the optimization.

---

<div class="post-metadata">

### Author: ![countvajhula](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/countvajhula/32/65_2.png) [@countvajhula](https://racket.discourse.group/u/countvajhula)
#### Post date: [November 21, 2023, 8:35pm UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323/17 "2023-11-21T20:35:15Z")

</div>

[This commit](https://github.com/drym-org/qi/pull/76/commits/9f0f940ce6daf3e1bf9cb65947a2786f7ebf0ab8) is the context. If you clone the repo locally (you may find [Getting Started](https://github.com/drym-org/qi/wiki/Getting-Started) helpful) and run:

```scheme
$ make profile-competitive

```

The `filter-map` and `filter-map (large list)` benchmarks shows the most improvement with _both_ `begin-encourage-inline` and `define-inline`, but as I recall, if we remove either of those, it gets noticeably slower.

---

<div class="post-metadata">

### Author: ![usao](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/usao/32/1375_2.png) [@usao](https://racket.discourse.group/u/usao)
#### Post date: [November 22, 2023, 1:28am UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323/18 "2023-11-22T01:28:06Z")

</div>

So _only_ `begin-encourage-inline` doesn’t work well because the inlining very easily exceeds `schemify`’s fuel (which governs cross-module inlining), I guess. Actually, in such cases, I think a more aggressive `define-inline` form (in the sense that it also inlines variable-reference case) will be useful. This may be a good addition to `define-inline` itself. (And it also doesn’t handle `case-lambda`, right? So it’s another thing that can be done.)

---

<div class="post-metadata">

### Author: ![countvajhula](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/countvajhula/32/65_2.png) [@countvajhula](https://racket.discourse.group/u/countvajhula)
#### Post date: [November 28, 2023, 3:34am UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323/19 "2023-11-28T03:34:25Z")

</div>

[A fine-grained migraine](https://github.com/drym-org/qi/wiki/Qi-Compiler-Sync-Nov-24-2023)

Highlights (some of these issues affect compilers in general and aren't specific to Qi):

- we continued discussing good ways to test a compiler (still iterating there -- please join next week if you're interested)
- how to report good error messages in terms of the source code (rather than the target code)?
- how to deal with a combinatorial explosion in match patterns in deforesting "fine grained" argument templates like `(~> (range _ _ 10) (filter odd? _) (map sqr _))`?
- can we simpify match patterns by reducing inferred syntax properties like "`chirality`" (i.e. left- or right-threading) to an explicit use of a core language?
- can we deforest all of `racket/list`? Should we?

---

<div class="post-metadata">

### Author: ![countvajhula](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/countvajhula/32/65_2.png) [@countvajhula](https://racket.discourse.group/u/countvajhula)
#### Post date: [December 6, 2023, 8:02pm UTC](https://racket.discourse.group/t/todays-qi-meeting-notes/2323/20 "2023-12-06T20:02:13Z")

</div>

Last week's notes:

[Manic Macromancy](https://github.com/drym-org/qi/wiki/Qi-Compiler-Sync-Dec-1-2023)

There's a _lot_ in there, this was a long one. Some highlights:

- Qi's error messages with deforestation are better than Racket's and "even better than Qi" 😄
- "Tower of languages" vs "compiler macros" as ways to extend the Qi compiler (esp. for deforesting all of `racket/list`)
- We've adopted [some suggestions from the community](https://racket.discourse.group/t/best-practices-for-testing-compiler-optimizations/2369) for testing the compiler (cc @gus-massa @samth @stamourv -- btw, we still hope to adopt the "logging" approach to trace compilation, but haven't gotten there yet!)
- Cameo appearance by Typed Qi @scolobb @NoahStoryM

[Next page](https://racket.discourse.group/t/todays-qi-meeting-notes/2323.md?page=2)
