Skip to content

Commit 10641a7

Browse files
committed
all the added crap removed. reconstruct is rolled back
1 parent b7e5341 commit 10641a7

File tree

4 files changed

+13
-93
lines changed

4 files changed

+13
-93
lines changed

src/core/batch.rkt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
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
1312
batch-length ; Batch -> Integer
1413
batch-ref ; Batch -> Idx -> Expr
1514
deref ; Batchref -> Expr
@@ -20,10 +19,8 @@
2019
mutable-batch-munge! ; Mutable-batch -> Root
2120
mutable-batch->batch ; Mutable-batch -> Batch
2221
make-mutable-batch ; Mutable-batch
23-
make-batch ; Batch
2422
mutable-batch-devour-batchref! ; Mutable-batch -> Batchref -> Idx
2523
batch->mutable-batch ; Batch -> Mutable-batch
26-
batch-copy-mutable-nodes! ; Batch -> Mutable-batch -> Void
2724
batch-push!) ; Mutable-batch -> Expr -> Idx
2825

2926
;; This function defines the recursive structure of expressions
@@ -47,9 +44,6 @@
4744
(define (make-mutable-batch)
4845
(mutable-batch '() (make-hash) '()))
4946

50-
(define (make-batch)
51-
(batch (vector) (vector) '()))
52-
5347
(define (batch-push! b term)
5448
(define hashcons (mutable-batch-index b))
5549
(hash-ref! hashcons
@@ -70,9 +64,6 @@
7064
(batch-restore-index b)
7165
(reverse (batch-vars b))))
7266

73-
(define (batch-copy-mutable-nodes! b mb)
74-
(set-batch-nodes! b (list->vector (reverse (mutable-batch-nodes mb)))))
75-
7667
(struct batchref (batch idx))
7768

7869
(define (deref x)

src/core/mainloop.rkt

Lines changed: 9 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -221,52 +221,15 @@
221221

222222
;; Converts a patch to full alt with valid history
223223
(define (reconstruct! alts)
224-
(define reconstruct-batch (make-batch))
225-
(define reconstruct-batch-mutable (make-mutable-batch))
226-
224+
(define reconstruct-batch (make-mutable-batch))
227225
;; extracts the base expressions of a patch as a batchref
228226
(define (get-starting-expr altn)
229227
(match* ((alt-event altn) (alt-prevs altn))
230-
[((list 'patch expr _) _) expr]
228+
[((list 'patch expr _) _) expr] ; here original Expr can be pulled as well
231229
[(_ (list prev)) (get-starting-expr prev)]
232230
[(_ _) (error 'get-starting-spec "unexpected: ~a" altn)]))
233231

234232
;; takes a patch and converts it to a full alt
235-
(define (reconstruct-alt-batch altn loc0 orig)
236-
(let loop ([altn altn])
237-
(match-define (alt _ event prevs _) altn)
238-
(match event
239-
[(list 'patch _ _) orig]
240-
[_
241-
(define event*
242-
(match event
243-
[(list 'taylor name var) (list 'taylor loc0 name var)]
244-
[(list 'rr input proof soundiness) (list 'rr loc0 input proof soundiness)]
245-
[(list 'simplify input proof soundiness) (list 'simplify loc0 input proof soundiness)]))
246-
(define idx
247-
(location-do-batch loc0 reconstruct-batch-mutable (alt-expr orig) (alt-expr altn)))
248-
(define expr* (batchref reconstruct-batch idx))
249-
(alt expr* event* (list (loop (first prevs))) (alt-preprocessing orig))])))
250-
251-
(define batchified-out
252-
(reap [sow]
253-
(for ([altn (in-list alts)]) ;; does not have preproc
254-
(define start-expr (get-starting-expr altn)) ; batchref
255-
(for ([full-altn (in-list (^next-alts^))])
256-
(define expr (alt-expr full-altn))
257-
(for ([loc (in-list (get-locations expr start-expr))])
258-
(sow (reconstruct-alt-batch altn loc full-altn)))))))
259-
(batch-copy-mutable-nodes! reconstruct-batch reconstruct-batch-mutable)
260-
261-
(define (rebuild-alts x)
262-
(match-define (alt expr event prevs preprocessing) x)
263-
(match (batchref? expr)
264-
[#t (alt (batchref->expr expr) event (map rebuild-alts prevs) preprocessing)]
265-
[#f (alt expr event (map rebuild-alts prevs) preprocessing)]))
266-
(set! batchified-out (map rebuild-alts batchified-out))
267-
268-
;; takes a patch and converts it to a full alt
269-
#;
270233
(define (reconstruct-alt altn loc0 orig)
271234
(let loop ([altn altn])
272235
(match-define (alt _ event prevs _) altn)
@@ -281,23 +244,13 @@
281244
(define expr* (location-do loc0 (alt-expr orig) (const (batchref->expr (alt-expr altn)))))
282245
(alt expr* event* (list (loop (first prevs))) (alt-preprocessing orig))])))
283246

284-
#;(define out
285-
(reap [sow]
286-
(for ([altn (in-list alts)]) ;; does not have preproc
287-
(define start-expr (get-starting-expr altn))
288-
(if start-expr
289-
(for ([full-altn (in-list (^next-alts^))])
290-
(define expr (alt-expr full-altn))
291-
(for ([loc (in-list (get-locations expr start-expr))])
292-
(sow (reconstruct-alt altn loc full-altn))))
293-
; altn is a full alt (probably iter 0 simplify)
294-
(sow altn)))))
295-
296-
(^patched^ batchified-out)
297-
#;(for ([p (in-list out)]
298-
[p* (in-list batchified-out)])
299-
(printf "\tp=~a\n" p)
300-
(printf "\tp*=~a\n\n" p*))
247+
(^patched^ (reap [sow]
248+
(for ([altn (in-list alts)]) ;; does not have preproc
249+
(define start-expr (get-starting-expr altn))
250+
(for ([full-altn (in-list (^next-alts^))])
251+
(define expr (alt-expr full-altn))
252+
(for ([loc (in-list (get-locations expr start-expr))])
253+
(sow (reconstruct-alt altn loc full-altn)))))))
301254

302255
(void))
303256

src/core/patch.rkt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
(sow (alt (batchref global-batch idx) `(simplify ,runner #f #f) (list altn) '()))))))
7272

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

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

123123
; Commit changes to global-batch
124-
(batch-copy-mutable-nodes! global-batch global-batch-mutable)
124+
(set-batch-nodes! global-batch (list->vector (reverse (mutable-batch-nodes global-batch-mutable))))
125125
; End of global-batch modification
126126
; ----------------------------------
127127

src/core/programs.rkt

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
(require "../syntax/syntax.rkt"
44
"../syntax/types.rkt"
55
"../utils/common.rkt"
6-
"batch.rkt")
6+
(only-in "batch.rkt" batch-nodes))
77

88
(provide expr?
99
expr-contains?
@@ -15,7 +15,6 @@
1515
repr-of
1616
repr-of-node
1717
location-do
18-
location-do-batch
1918
location-get
2019
free-variables
2120
replace-expression
@@ -41,8 +40,7 @@
4140
(match node
4241
[(? literal?) (get-representation (literal-precision node))]
4342
[(? variable?) (context-lookup ctx node)]
44-
[(list '$approx _ impl)
45-
(repr-of-node batch impl ctx)] ; this is ugly, but egraph-add-exprs relies on this match
43+
[(approx _ impl) (repr-of-node batch impl ctx)]
4644
[(list 'if cond ift iff) (repr-of-node batch ift ctx)]
4745
[(list op args ...) (impl-info op 'otype)]))
4846

@@ -181,28 +179,6 @@
181179
[else (cons (car elts) (seek (cdr elts) (sub1 idx)))]))]
182180
[(_ _) (invalid! prog loc)])))
183181

184-
(define/contract (location-do-batch loc mbatch prog replace-batchref)
185-
(-> location? mutable-batch? expr? batchref? number?)
186-
(define (invalid! where loc)
187-
(error 'location-do "invalid location `~a` for `~a` in `~a`" loc where prog))
188-
189-
(define (rewrite prog loc)
190-
(match* (prog loc)
191-
[(_ (? null?)) (mutable-batch-devour-batchref! mbatch replace-batchref)]
192-
[((or (? literal?) (? number?) (? symbol?)) _) (invalid! prog loc)]
193-
[((approx spec impl) (cons idx rest))
194-
(case idx
195-
[(2) (batch-push! mbatch (approx (mutable-batch-munge! mbatch spec) (rewrite impl rest)))]
196-
[else (invalid! prog loc)])]
197-
[((list op args ...) (cons idx rest))
198-
(define args*
199-
(for/list ([arg (in-list args)]
200-
[n (in-naturals 1)])
201-
(if (equal? n idx) (rewrite arg rest) (mutable-batch-munge! mbatch arg))))
202-
(batch-push! mbatch (cons op args*))]
203-
[(_ _) (invalid! prog loc)]))
204-
(rewrite prog loc))
205-
206182
(define/contract (location-get loc prog)
207183
(-> location? expr? expr?)
208184
; Clever continuation usage to early-return

0 commit comments

Comments
 (0)