diff --git a/src/core/batch.rkt b/src/core/batch.rkt index a2e82a83a..e9e3ada6e 100644 --- a/src/core/batch.rkt +++ b/src/core/batch.rkt @@ -158,6 +158,7 @@ (define out (make-mutable-batch)) (set-mutable-batch-index! out (batch-restore-index input-batch)) + ; This fuction here is only because of cycles in loads:( (define (egg-parsed->expr expr rename-dict type) (let loop ([expr expr] [type type]) @@ -170,9 +171,6 @@ [(list '$approx spec impl) ; approx (define spec-type (if (representation? type) (representation-type type) type)) (approx (loop spec spec-type) (loop impl type))] - [`(Explanation ,body ...) `(Explanation ,@(map (lambda (e) (loop e type)) body))] - [(list 'Rewrite=> rule expr) (list 'Rewrite=> rule (loop expr type))] - [(list 'Rewrite<= rule expr) (list 'Rewrite<= rule (loop expr type))] [(list 'if cond ift iff) (if (representation? type) (list 'if (loop cond (get-representation 'bool)) (loop ift type) (loop iff type)) @@ -220,14 +218,10 @@ (batch-push! out (cons op args))])) ; Returns roots while updating nodes of input-batch - (define (finalize-batch roots) + (define (finalize-batch) (set-batch-nodes! input-batch (vector-append (batch-nodes input-batch) - (list->vector (reverse (mutable-batch-nodes out))))) - #;(list->vector (reverse roots)) - - (for/list ([root (in-list roots)]) - (batch-ref input-batch root))) + (list->vector (reverse (mutable-batch-nodes out)))))) ; Cleaning the batch to start over (define (clean-batch) diff --git a/src/core/egg-herbie.rkt b/src/core/egg-herbie.rkt index 8a402f495..5fb33e6da 100644 --- a/src/core/egg-herbie.rkt +++ b/src/core/egg-herbie.rkt @@ -1217,77 +1217,60 @@ ; at least one extractable expression [(hash-has-key? canon key) (define id* (hash-ref canon key)) - - (define egg-exprs - (for/list ([enode (vector-ref eclasses id*)]) - (match enode - [(? number?) enode] - [(? symbol?) enode] - [(list '$approx spec impl) - (define spec* (vector-ref id->spec spec)) - (unless spec* - (error 'regraph-extract-variants "no initial approx node in eclass ~a" id*)) - (define impl* (build-expr impl)) - (list '$approx spec* impl*)] - [(list 'if cond ift iff) - (define cond* (build-expr cond)) - (define ift* (build-expr ift)) - (define iff* (build-expr iff)) - (list 'if cond* ift* iff*)] - [(list (? impl-exists? impl) ids ...) - (define args - (for/list ([id (in-list ids)]) - (define expr (build-expr id)) - expr)) - (cons impl args)] - [(list (? operator-exists? op) ids ...) - (define args - (for/list ([id (in-list ids)]) - (define expr (build-expr id)) - expr)) - (cons op args)]))) - (clean-batch) (define roots (for/list ([enode (vector-ref eclasses id*)]) (add-root enode type))) - (define exprs* (finalize-batch roots)) + (finalize-batch) ; -------------------------- Debooging - ; This debooging crashes if unparsed approx nodes exist in the batch - #;(printf "roots#=~a, eclasses#=~a\n" - (vector-length (batch-roots batch)) - (vector-length (vector-ref eclasses id*))) - #;(define egg-exprs-batch (batch->progs batch)) - #;(when (not (equal? egg-exprs-batch egg-exprs)) + ; translate egg IR to Herbie IR + #;(define egg-exprs + (for/list ([enode (vector-ref eclasses id*)]) + (match enode + [(? number?) enode] + [(? symbol?) enode] + [(list '$approx spec impl) + (define spec* (vector-ref id->spec spec)) + (unless spec* + (error 'regraph-extract-variants "no initial approx node in eclass ~a" id*)) + (define impl* (build-expr impl)) + (list '$approx spec* impl*)] + [(list 'if cond ift iff) + (define cond* (build-expr cond)) + (define ift* (build-expr ift)) + (define iff* (build-expr iff)) + (list 'if cond* ift* iff*)] + [(list (? impl-exists? impl) ids ...) + (define args + (for/list ([id (in-list ids)]) + (define expr (build-expr id)) + expr)) + (cons impl args)] + [(list (? operator-exists? op) ids ...) + (define args + (for/list ([id (in-list ids)]) + (define expr (build-expr id)) + expr)) + (cons op args)]))) + + #;(define egg->herbie (regraph-egg->herbie regraph)) + #;(define exprs + (for/list ([egg-expr (in-list egg-exprs)]) + (egg-parsed->expr (flatten-let egg-expr) egg->herbie type))) + + #;(define exprs* (batch->progs batch)) + #;(when (not (equal? exprs* exprs)) (println (vector-ref eclasses id*)) - (for ([expr* (in-list egg-exprs-batch)] - [expr (in-list egg-exprs)]) + (for ([expr* (in-list exprs*)] + [expr (in-list exprs)]) (printf "expr* = ~a\n" expr*) (printf "expr = ~a\n\n" expr) (sleep 5))) - #;(println "oolright\n") - ; --------------------------- - - ; translate egg IR to Herbie IR - (define egg->herbie (regraph-egg->herbie regraph)) - (define exprs - (for/list ([egg-expr (in-list egg-exprs)]) - (egg-parsed->expr (flatten-let egg-expr) egg->herbie type))) - - ; -------------------------- Debooging - #;(define exprs* (batch->progs batch)) - (when (not (equal? exprs* exprs)) - (println (vector-ref eclasses id*)) - (for ([expr* (in-list exprs*)] - [expr (in-list exprs)]) - (printf "expr* = ~a\n" expr*) - (printf "expr = ~a\n\n" expr) - (sleep 5))) ;(println "oolright\n") ; ------------------------- - exprs*] + roots] ; no extractable expressions [else (list)])) diff --git a/src/core/patch.rkt b/src/core/patch.rkt index da9487e62..68ae94910 100644 --- a/src/core/patch.rkt +++ b/src/core/patch.rkt @@ -134,16 +134,16 @@ (define reprs (map (curryr repr-of (*context*)) exprs)) (timeline-push! 'inputs (map ~a exprs)) (define runner (make-egg-runner exprs reprs schedule #:context (*context*))) - ; variantss is a (listof batch)) - (define batches (run-egg runner `(multi . ,extractor))) + ; variantss is a (listof roots)) + (define rootss (run-egg runner `(multi . ,extractor))) ; apply changelists (define rewritten (reap [sow] - (for ([batch (in-list batches)] + (for ([roots (in-list rootss)] [altn (in-list altns)]) - (for ([root (in-list batch)]) - (sow (alt root (list 'rr runner #f #f) (list altn) '())))))) + (for ([root (in-list roots)]) + (sow (alt (batch-ref global-batch root) (list 'rr runner #f #f) (list altn) '())))))) #;(define rewritten (reap [sow]