Skip to content

Commit 2b27f77

Browse files
authored
Merge pull request #1351 from herbie-fp/batch-no-roots
Batch without `roots` field
2 parents eb30dc8 + 246e967 commit 2b27f77

19 files changed

+547
-533
lines changed

src/api/sandbox.rkt

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

8383
;; compute error/cost for output expression
8484
;; and sort alternatives by accuracy + cost on testing subset
85-
(define test-errs (batch-errors (map alt-expr alternatives) test-pcontext (*context*)))
85+
(define test-errs (exprs-errors (map alt-expr alternatives) test-pcontext (*context*)))
8686
(define sorted-end-exprs (sort-alts alternatives test-errs))
8787
(define end-exprs (map (compose alt-expr car) sorted-end-exprs))
8888
(define end-errs (map cdr sorted-end-exprs))

src/api/server.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@
515515
(improve-result-target backend)
516516
(improve-result-end backend))))
517517
(define exprs (append-map collect-expressions all-alts))
518-
(make-hash (map cons exprs (batch-errors exprs pcontext ctx)))]
518+
(make-hash (map cons exprs (exprs-errors exprs pcontext ctx)))]
519519
[else #f]))
520520

521521
(define test-fpcore (alt->fpcore test (make-alt (test-input test))))

src/core/alt-table.rkt

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,22 @@
2626

2727
(struct alt-table (point-idx->alts alt->point-idxs alt->done? alt->cost pcontext all) #:prefab)
2828

29-
(define (alt-batch-cost batch repr)
29+
(define (alt-batch-cost batch brfs repr)
3030
(define node-cost-proc (platform-node-cost-proc (*active-platform*)))
31-
(define costs (make-vector (batch-length batch) 0))
32-
(for ([node (in-batch batch)]
33-
[i (in-naturals)])
34-
(define cost
35-
(match node
36-
[(? literal?) ((node-cost-proc node repr))]
37-
[(? symbol?) ((node-cost-proc node repr))]
38-
[(? number?) 0] ; specs
39-
[(approx _ impl) (vector-ref costs impl)]
40-
[(list (? (negate impl-exists?) impl) args ...) 0] ; specs
41-
[(list impl args ...)
42-
(define cost-proc (node-cost-proc node repr))
43-
(define itypes (impl-info impl 'itype))
44-
(apply cost-proc (map (curry vector-ref costs) args))]))
45-
(vector-set! costs i cost))
46-
(for/list ([root (in-vector (batch-roots batch))])
47-
(vector-ref costs root)))
31+
(define costs
32+
(batch-map batch
33+
(λ (get-args-costs node)
34+
(match node
35+
[(? literal?) ((node-cost-proc node repr))]
36+
[(? symbol?) ((node-cost-proc node repr))]
37+
[(? number?) 0] ; specs
38+
[(approx _ impl) (get-args-costs impl)]
39+
[(list (? (negate impl-exists?) impl) args ...) 0] ; specs
40+
[(list impl args ...)
41+
(define cost-proc (node-cost-proc node repr))
42+
(define itypes (impl-info impl 'itype))
43+
(apply cost-proc (map get-args-costs args))]))))
44+
(map costs brfs))
4845

4946
(define (make-alt-table pcontext initial-alt ctx)
5047
(define cost (alt-cost initial-alt (context-repr ctx)))
@@ -184,9 +181,9 @@
184181
[alt->cost (hash-remove* alt->cost altns)]))
185182

186183
(define (atab-eval-altns atab altns ctx)
187-
(define batch (progs->batch (map alt-expr altns) #:vars (context-vars ctx)))
188-
(define errss (batch-errors batch (alt-table-pcontext atab) ctx))
189-
(define costs (alt-batch-cost batch (context-repr ctx)))
184+
(define-values (batch brfs) (progs->batch (map alt-expr altns) #:vars (context-vars ctx)))
185+
(define errss (batch-errors batch brfs (alt-table-pcontext atab) ctx))
186+
(define costs (alt-batch-cost batch brfs (context-repr ctx)))
190187
(values errss costs))
191188

192189
(define (atab-add-altns atab altns errss costs ctx)

0 commit comments

Comments
 (0)