Skip to content

Commit 42d7a11

Browse files
committed
useless code + some minor batch API updates
1 parent 23cc561 commit 42d7a11

File tree

6 files changed

+22
-25
lines changed

6 files changed

+22
-25
lines changed

src/core/batch.rkt

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,24 @@
55
"../syntax/types.rkt")
66

77
(provide progs->batch ; (Listof Expr) -> Batch
8-
batch->progs ; Batch -> *(or (Listof Root) (Vectorof Root)) -> (Listof Expr)
8+
batch->progs ; Batch -> ?(or (Listof Root) (Vectorof Root)) -> (Listof Expr)
99
(struct-out batch)
1010
(struct-out batchref) ; temporarily for patch.rkt
1111
(struct-out mutable-batch) ; temporarily for patch.rkt
12+
expr-recurse ; Expr -> (Expr -> ?) -> Expr
1213
batch-length ; Batch -> Integer
1314
batch-ref ; Batch -> Idx -> Expr
1415
deref ; Batchref -> Expr
1516
batch-replace ; Batch -> (Expr<Batchref> -> Expr<Batchref>) -> Batch
1617
egg-nodes->batch ; Nodes -> Spec-maps -> Batch -> (Listof Batchref)
17-
batchref->expr ; Batchref -> Expr
18-
batch-remove-zombie ; Batch -> *(Vectorof Root) -> Batch
19-
mutable-batch-munge! ; Mutable-batch -> Root
18+
debatchref ; Batchref -> Expr
19+
batch-remove-zombie ; Batch -> ?(Vectorof Root) -> Batch
20+
mutable-batch-munge! ; Mutable-batch -> Expr -> Root
2021
mutable-batch->batch ; Mutable-batch -> Batch
2122
make-mutable-batch ; Mutable-batch
22-
mutable-batch-devour-batchref! ; Mutable-batch -> Batchref -> Idx
2323
batch->mutable-batch ; Batch -> Mutable-batch
24-
batch-push!) ; Mutable-batch -> Expr -> Idx
24+
batch-copy-mutable-nodes! ; Batch -> Mutable-batch -> Void
25+
batch-push!) ; Mutable-batch -> Node -> Idx
2526

2627
;; This function defines the recursive structure of expressions
2728
(define (expr-recurse expr f)
@@ -64,13 +65,16 @@
6465
(batch-restore-index b)
6566
(reverse (batch-vars b))))
6667

68+
(define (batch-copy-mutable-nodes! b mb)
69+
(set-batch-nodes! b (list->vector (reverse (mutable-batch-nodes mb)))))
70+
6771
(struct batchref (batch idx))
6872

6973
(define (deref x)
7074
(match-define (batchref b idx) x)
7175
(expr-recurse (vector-ref (batch-nodes b) idx) (lambda (ref) (batchref b ref))))
7276

73-
(define (batchref->expr x)
77+
(define (debatchref x)
7478
(match-define (batchref b idx) x)
7579
(batch-ref b idx))
7680

@@ -96,13 +100,6 @@
96100
(batch-push! b (expr-recurse prog munge)))
97101
(munge expr))
98102

99-
(define (mutable-batch-devour-batchref! b ref)
100-
(match-define (batchref b* idx) ref)
101-
(define nodes* (batch-nodes b*))
102-
(define (munge idx)
103-
(batch-push! b (expr-recurse (vector-ref nodes* idx) munge)))
104-
(munge idx))
105-
106103
(define (batch->progs b [roots (batch-roots b)])
107104
(define exprs (make-vector (batch-length b)))
108105
(for ([node (in-vector (batch-nodes b))]

src/core/localize.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
; run egg
5151
(define simplified
52-
(map batchref->expr
52+
(map debatchref
5353
(map last
5454
(simplify-batch runner
5555
(typed-egg-batch-extractor (if (*egraph-platform-cost*)

src/core/mainloop.rkt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241
[(list 'taylor name var) (list 'taylor loc0 name var)]
242242
[(list 'rr input proof soundiness) (list 'rr loc0 input proof soundiness)]
243243
[(list 'simplify input proof soundiness) (list 'simplify loc0 input proof soundiness)]))
244-
(define expr* (location-do loc0 (alt-expr orig) (const (batchref->expr (alt-expr altn)))))
244+
(define expr* (location-do loc0 (alt-expr orig) (const (debatchref (alt-expr altn)))))
245245
(alt expr* event* (list (loop (first prevs))) (alt-preprocessing orig))])))
246246

247247
(^patched^ (reap [sow]
@@ -378,7 +378,7 @@
378378

379379
; run egg
380380
(define simplified
381-
(map batchref->expr
381+
(map debatchref
382382
(map last
383383
(simplify-batch runner
384384
(typed-egg-batch-extractor (if (*egraph-platform-cost*)

src/core/patch.rkt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
(define reprs
2525
(for/list ([approx (in-list approxs)])
2626
(define prev (car (alt-prevs approx)))
27-
(repr-of (batchref->expr (alt-expr prev)) (*context*))))
27+
(repr-of (debatchref (alt-expr prev)) (*context*))))
2828

2929
; generate real rules
3030
(define rules (real-rules (*simplify-rules*)))
@@ -63,15 +63,15 @@
6363
(match-define (cons _ simplified) outputs)
6464
(define prev (car (alt-prevs altn)))
6565
(for ([expr (in-list simplified)])
66-
(define spec (prog->spec (batchref->expr (alt-expr prev))))
66+
(define spec (prog->spec (debatchref (alt-expr prev))))
6767
(define idx
6868
(batch-push! global-batch-mutable
6969
(approx (mutable-batch-munge! global-batch-mutable spec)
7070
(batchref-idx expr))))
7171
(sow (alt (batchref global-batch idx) `(simplify ,runner #f #f) (list altn) '()))))))
7272

7373
; Commit changes to global-batch
74-
(set-batch-nodes! global-batch (list->vector (reverse (mutable-batch-nodes global-batch-mutable))))
74+
(batch-copy-mutable-nodes! global-batch global-batch-mutable)
7575
; End of global-batch modification
7676
; ---------------------------------
7777

@@ -93,7 +93,7 @@
9393
(define (taylor-alts altns global-batch)
9494
(define exprs
9595
(for/list ([altn (in-list altns)])
96-
(prog->spec (batchref->expr (alt-expr altn)))))
96+
(prog->spec (debatchref (alt-expr altn)))))
9797
(define free-vars (map free-variables exprs))
9898
(define vars (list->set (append* free-vars)))
9999

@@ -121,7 +121,7 @@
121121
(timeline-stop!))))
122122

123123
; Commit changes to global-batch
124-
(set-batch-nodes! global-batch (list->vector (reverse (mutable-batch-nodes global-batch-mutable))))
124+
(batch-copy-mutable-nodes! global-batch global-batch-mutable)
125125
; End of global-batch modification
126126
; ----------------------------------
127127
approxs)
@@ -161,7 +161,7 @@
161161
(,lowering-rules . ((iteration . 1) (scheduler . simple)))))
162162

163163
; run egg
164-
(define exprs (map (compose batchref->expr alt-expr) altns))
164+
(define exprs (map (compose debatchref alt-expr) altns))
165165
(define roots (list->vector (map (compose batchref-idx alt-expr) altns)))
166166
(define reprs (map (curryr repr-of (*context*)) exprs))
167167
(timeline-push! 'inputs (map ~a exprs))

src/core/preprocess.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
(cons start-alt
8383
(remove-duplicates
8484
(for/list ([expr (rest simplified)])
85-
(alt (batchref->expr expr) `(simplify () ,runner #f #f) (list start-alt) '()))
85+
(alt (debatchref expr) `(simplify () ,runner #f #f) (list start-alt) '()))
8686
alt-equal?)))
8787

8888
;; See https://pavpanchekha.com/blog/symmetric-expressions.html

src/core/simplify.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
(map (lambda (_) 'real) args)
5959
`((,(*simplify-rules*) . ((node . ,(*node-limit*)))))))
6060
(define extractor (typed-egg-batch-extractor default-egg-cost-proc batch))
61-
(map (compose batchref->expr last) (simplify-batch runner extractor)))
61+
(map (compose debatchref last) (simplify-batch runner extractor)))
6262

6363
(define test-exprs
6464
'((1 . 1) (0 . 0)

0 commit comments

Comments
 (0)