Skip to content

Commit

Permalink
a boog + moving batchref out of run-rr
Browse files Browse the repository at this point in the history
  • Loading branch information
AYadrov committed Aug 30, 2024
1 parent 8b553f0 commit c759360
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 27 deletions.
7 changes: 6 additions & 1 deletion src/core/batch.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
batch-ref ; Batch -> Index -> Expr
deref ; Batchref -> Expr
batch-replace ; Batch -> Lambda -> Batch
egg-nodes->batch) ; Nodes -> Spec-maps -> Batch -> Batch
egg-nodes->batch ; Nodes -> Spec-maps -> Batch -> Batch
batchref->expr) ; Batchref -> Expr

;; This function defines the recursive structure of expressions

Expand Down Expand Up @@ -59,6 +60,10 @@
(match-define (batchref b idx) x)
(expr-recurse (vector-ref (batch-nodes b) idx) (lambda (ref) (batchref b ref))))

(define (batchref->expr x)
(match-define (batchref b idx) x)
(batch-ref b idx))

(define (progs->batch exprs #:timeline-push [timeline-push #f] #:vars [vars '()])

(define out (make-mutable-batch))
Expand Down
4 changes: 1 addition & 3 deletions src/core/egg-herbie.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
make-egg-runner
run-egg
get-canon-rule-name
remove-rewrites
egg-parsed->expr)
remove-rewrites)

(module+ test
(require rackunit)
Expand Down Expand Up @@ -1271,7 +1270,6 @@
; -------------------------

roots]
; no extractable expressions
[else (list)]))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
30 changes: 7 additions & 23 deletions src/core/patch.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -142,29 +142,8 @@
(reap [sow]
(for ([roots (in-list rootss)]
[altn (in-list altns)])
(for ([root (in-list roots)])
(sow (alt (batch-ref global-batch root) (list 'rr runner #f #f) (list altn) '()))))))

#;(define rewritten
(reap [sow]
(for ([batch (in-list batches)]
[altn (in-list altns)])
(for ([root (in-vector (batch-roots batch))])
(sow (alt (batch-ref batch root) (list 'rr runner #f #f) (list altn) '()))))))

; batchified
#;(for ([batch (in-list batches)]
[altn (in-list altns)])
(for ([root (in-vector (batch-roots batch))]
[n (in-naturals)])
(define prev-root (batch-add-expr! batch altn))
(vector-set! (batch-events batch)
n
(cons (list 'rr runner #f #f) (vector-ref (batch-events batch) n)))
(vector-set! (batch-prevs batch) n (cons prev-root (vector-ref (batch-prevs batch) n)))))
#;(define rewritten* (map batch->alts batches))
#;(println rewritten*)
; TODO, check whether batchified is equal to sequential version
(for ([root (in-list (remove-duplicates roots))])
(sow (alt (batchref global-batch root) (list 'rr runner #f #f) (list altn) '()))))))

(timeline-push! 'outputs (map (compose ~a alt-expr) rewritten))
(timeline-push! 'count (length altns) (length rewritten))
Expand All @@ -187,4 +166,9 @@
; Recursive rewrite
(define rewritten (if (flag-set? 'generate 'rr) (run-rr start-altns global-batch) '()))

; deref everything in rewritten
(set! rewritten
(for/list ([r (in-list rewritten)])
(alt (batchref->expr (alt-expr r)) (alt-event r) (alt-prevs r) (alt-preprocessing r))))

(append approximations rewritten))

0 comments on commit c759360

Please sign in to comment.