Skip to content

Define deforestable runtime#207

Open
dzoep wants to merge 70 commits into
mainfrom
define-deforestable-runtime
Open

Define deforestable runtime#207
dzoep wants to merge 70 commits into
mainfrom
define-deforestable-runtime

Conversation

@dzoep

@dzoep dzoep commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator

Summary of Changes

  • adds unified interface for defining producers, transformers and consumers
  • removes the need for manual addition of deforestable forms to respective syntax classes
  • removes the need for separately written runtime to match those syntax classes
  • implements all the current and many new deforestable forms using the new interface

Remaining Work

  • code review

WIP

  • TODO

Won't Do

  • TODO

Done

  • TODO

Release steps

  • TODO

Public Domain Dedication

  • In contributing, we relinquish any copyright claims on our contributions and freely release them into the public domain in the simple hope that they 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.)

dzoep added 30 commits March 13, 2026 20:09
- extend the info struct to contain syntax with CPS runtime reference
  (as a bound identifier)
- amend define-deforestable to allow lambda with CPS runtime
- move map-cstream-next into define-deforestable of map form
  fix fallback codegen to properly match on extended info struct
- filter
- filter-map
- take
- require racket/contract/base to allow virtual contract failures within
  the deforested pipeline - needed by take
- extend the deforestable-info with `kind` field
  - when `'T`, it is a transformer
- add #:transformer, #:producer, and #:consumer keywords to define-deforestable
- use #:transformer to define all transformers in list.rkt
- remove all old remaining transformer classes:
  - `fst` (from cps.rkt)
  - `fst-filter-map`, `fst-map`, and `fst-take` (from syntax.rkt)
- add new `fst-new` syntax class providing both:
  - ability to match deforestable transformers within a sequence
    (see `make-deforest-rewrite` in fusion.rkt)
  - providing all attributes needed for generating fused operation
    (see `deforest-pass` in cps.rkt)
- add `filter-not` form using (define-deforestable #:transformer ...)
- add test for it (including support predicate)
- documentation:
  - new `list-tail` form with `drop` alias
  - add all new forms to the overall grammar
  - document previously added `filter-not` form
- deforested `list-tail`
  - add the new form using (define-deforestable #:transformer ...)
  - provide it twice - including variant as `drop`
- tests
  - deforested sequence including `list-tail`
  - testing functionality with basic use-cases
- remove make-producer-curry
- remove make-blanket-curry
- simplify make-fine-curry
- make both producers' prepare a lambda instead of case-lambda
- remove make-fine-curry
- add preliminary producer state expression to the syntax classes
- remove unused attributes of range syntax class
- simplify contract to specify only in-flow arguments
  (none for range, list? for implicit producer)
- merge `curry` and `prepare` attributes (and prepare's runtime)
  into the `prepare` attribute
- simplify `deforest-pass`
  - remove curry
  - fill-in contract details
  - cleanup consing
- remove runtime implementations for producers' prepare
- start preliminary work on `fsp-new`
- remove range->cstream-next
- support producer-specific identifiers
- implement rest alias for (list-tail 1)
- implement cdr, cddr, cdddr, cddddr, and cdddddr aliases
- document the new aliases
- add prepare field to deforestable-info struct
- expand arguments upon matching actual deforestable producer (range)
- copy deforestable-clause-parser temporarily to deforest/syntax.rkt
- add separate define-deforestable #:producer pattern
THIS IS BROKEN WORK IN PROGRESS

- move list->cstream-next into list.rkt as define-deforestable (list->cstream)
- matching (#%deforestable ...) on the injected list->cstream->cstream-next does not work
  - the naming issue is not the probllem (this IS the generated name for the moment)
  - (list->cstream->cstream-next) is injected in fusion.rkt, lines 63-76
  - generate-fused operation sees only the identifier, not the expanded form (to core language)
  - those loops thru hoops with local-expand and friends are just one of many random attempts
- use expand-flow from invoke submod flow/extended/expander
- expand both use-cases in fusion.rkt
- fix fsp-new pattern - #%deforestable - NOT #:deforestable
- explicitly name the info struct for producers
- remove original fsp syntax class
- remove unused requires from cps.rkt
- remove unused list->cstream-next producer runtime
- fix and remove unused requires in syntax.rkt
- remove fsp-* syntax classes
- reduce fsp-new attributes
@dzoep
dzoep marked this pull request as draft April 3, 2026 20:31
The deforestation tests should be improved, but for now just update
them to reflect the current code.
@dzoep
dzoep marked this pull request as ready for review July 3, 2026 18:48
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.

2 participants