Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining deforestable operations #185

Conversation

countvajhula
Copy link
Collaborator

@countvajhula countvajhula commented Nov 22, 2024

Summary of Changes

WIP to integrate the proof-of-concept "deep macro" extension scheme for deforestation.

Useful context: see the meeting notes, No More Unknowns!

Planned:

  • translate map
  • translate the remaining qi/list operations
  • rename #%deforestable2 to #%deforestable (replacing it)
  • remove the codegen for #%deforestable, replacing it with the new version for #%deforestable2

Public Domain Dedication

  • In contributing, I relinquish any copyright claims on my contribution and freely release it into the public domain in the simple hope that it will provide value.

(Why: The freely released, copyright-free work in this repository represents an investment in a better way of doing things called attribution-based economics. Attribution-based economics is based on the simple idea that we gain more by giving more, not by holding on to things that, truly, we could only create because we, in our turn, received from others. As it turns out, an economic system based on attribution -- where those who give more are more empowered -- is significantly more efficient than capitalism while also being stable and fair (unlike capitalism, on both counts), giving it transformative power to elevate the human condition and address the problems that face us today along with a host of others that have been intractable since the beginning. You can help make this a reality by releasing your work in the same way -- freely into the public domain in the simple hope of providing value. Learn more about attribution-based economics at drym.org, tell your friends, do your part.)


(define (deforestable2-parser e)
(syntax-parse e
#:datum-literals (#%optimizable-app)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove copypasta

Copy link
Collaborator

@benknoble benknoble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few style things I noticed. Non-blocking/non-urgent.

qi-lib/flow/core/compiler/1000-qi0.rkt Outdated Show resolved Hide resolved
qi-lib/macro.rkt Outdated Show resolved Hide resolved
qi-lib/macro.rkt Outdated Show resolved Hide resolved
@countvajhula
Copy link
Collaborator Author

Thanks @benknoble , I've adopted those suggestions!

@countvajhula countvajhula marked this pull request as ready for review November 23, 2024 07:34
@countvajhula countvajhula force-pushed the defining-deforestable-operations branch from 1b33ca5 to 62db17b Compare November 23, 2024 07:58
@@ -78,28 +78,29 @@
(define-syntax-class fst-filter
#:attributes (f)
#:literal-sets (fs-literals)
#:datum-literals (filter)
(pattern (#%deforestable filter (f-uncompiled))
#:datum-literals (#%deforestable filter)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more consistent to put #%deforestable in the fs-literals literals set

(syntax-parse spec
[([tag arg-name] ...)
(syntax-parser
[(_ e ...+)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this pattern matching will achieve what you want when someone tries (car) instead of car, or filter instead of (filter odd?).

The error shows up later when the codegen is called, as an arity error there.

`define-qi-syntax` was written before `define-dsl-syntax` existed, and
it's better to use standard utilities from infrastructure libraries
like `syntax-spec` where we can.

(done in yesterday's Qi meeting)
This integrates the proof-of-concept "deep macro" extension scheme for
deforestation that we have been working on in the weekly meetings. For
now, only `map` is implemented using the new approach, and though
user-level tests pass, some compiler tests are currently failing.

To keep things simple, this temporarily introduces a parallel
`#%deforestable2` form for this purpose so that we can implement list
operations one at a time and test things in isolation before going
whole hog and replacing `#%deforestable` with the new version.
The deforestation pass needs a name (e.g. `map`) to match in order to
apply optimizations. This updates the syntax class responsible for
matching `map` to use the new deforestable core form syntax and fixes
the failing compiler tests.

(done in today's meeting)
Our extension scheme did not support identifier-based forms like
`car`, so a few modifications to it were necessary.
This avoids an "unused binding" warning
We'd like to support multiple syntaxes for `range` that all expand to
a canonical form, and at the same time, provide a single codegen for
that canonical form. We don't already have a way to do this with
`define-deforestable` directly, so we just write `range` as an
ordinary Qi macro that expands to a use of the canonically-defined
`range2`.

See today's meeting notes for more on this.
Use `range` internally, and re-export the user-facing `range2` so it
is also visible as `range` externally, for the best of both worlds.
This replaces the original implementation of the `#%deforestable` core
form with the new one that had been named `#%deforestable2` during the
process of incrementally integrating the proof-of-concept for this
scheme. With that complete, this now gets rid of the hardcoded codegen
for the `qi/list` forms in the Qi compiler, instead replacing it with
the ability to specify this in the `define-deforestable` macro which
then conveys the codegen through to the final stage of compilation via
a compile-time datatype.

This also removes some tests that are no longer relevant and updates
others.

The recent Qi meeting notes provide more context on this approach.
Ensure that the `spec` contains all the information that's needed to
parse the syntax in terms of floe and expr positions, instead of
having a parallel path for identifier forms.

(done in today's meeting)
E.g. `filter` is a syntax error but `car` isn't. This ensures that the
former provides a helpful error message (syntax-parse's default for
the latter is already fine).
@countvajhula countvajhula force-pushed the defining-deforestable-operations branch from a35c1b9 to 61f6561 Compare December 6, 2024 18:15
@countvajhula countvajhula merged commit 4d6ed0d into drym-org:deforest-all-the-things Dec 6, 2024
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants