Skip to content

Commit fbd5e42

Browse files
authored
Merge pull request #1281 from herbie-fp/remove-more-preprocessing
Remove more preprocessing code
2 parents 6bee7b8 + 332a480 commit fbd5e42

File tree

10 files changed

+18
-81
lines changed

10 files changed

+18
-81
lines changed

infra/ci.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
(match-define (job-result _ test status time timeline profile warnings backend) result)
4848
(match status
4949
['success
50-
(match-define (improve-result preprocess _ start targets end) backend)
50+
(match-define (improve-result _ start targets end) backend)
5151
(match-define (alt-analysis start-alt start-error) start)
5252
(match-define (alt-analysis end-alt end-error) (first end))
5353

src/api/datafile.rkt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
(name identifier
1818
status
1919
pre
20-
preprocess
2120
precision
2221
conversions
2322
vars
@@ -98,7 +97,6 @@
9897
identifier
9998
status
10099
pre
101-
preprocess
102100
prec
103101
conversions
104102
vars
@@ -126,7 +124,6 @@
126124
(list cost error (~a expr))))]))
127125
(make-hash `((name . ,name) (identifier . ,(~s identifier))
128126
(pre . ,(~s pre))
129-
(preprocess . ,(~s preprocess))
130127
(prec . ,(~s prec))
131128
(bits . ,(representation-total-bits (get-representation prec)))
132129
(conversions . ,(map (curry map ~s) conversions))
@@ -207,7 +204,6 @@
207204
(parse-string (hash-ref test 'identifier "#f"))
208205
(get 'status)
209206
(parse-string (hash-ref test 'pre "TRUE"))
210-
(parse-string (hash-ref test 'preprocess "()"))
211207
(parse-string (hash-ref test 'prec "binary64"))
212208
(let ([cs (hash-ref test 'conversions "()")])
213209
(if (string? cs)

src/api/run.rkt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
(table-row-target-prog row)
3232
(fpcore->prog (table-row-spec row) ctx)
3333
(fpcore->prog (table-row-pre row) ctx)
34-
(table-row-preprocess row)
3534
(representation-name repr)
3635
(for/list ([(k v) (in-dict var-reprs)])
3736
(cons k (representation-name v)))

src/api/sandbox.rkt

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"../syntax/platform.rkt"
2121
"../core/points.rkt"
2222
"../core/explain.rkt"
23-
"../core/preprocess.rkt"
2423
"../utils/profile.rkt"
2524
"../utils/timeline.rkt"
2625
(submod "../utils/timeline.rkt" debug))
@@ -33,7 +32,7 @@
3332
(struct-out alt-analysis))
3433

3534
(struct job-result (command test status time timeline profile warnings backend))
36-
(struct improve-result (preprocess pcontext start target end))
35+
(struct improve-result (pcontext start target end))
3736
(struct alt-analysis (alt errors) #:prefab)
3837

3938
;; API users can supply their own, weird set of points, in which case
@@ -62,16 +61,12 @@
6261
(error 'get-alternatives "cannnot run without a pcontext"))
6362

6463
(define-values (train-pcontext test-pcontext) (partition-pcontext joint-pcontext))
65-
;; TODO: Ignoring all user-provided preprocessing right now
6664
(define alternatives (run-improve! (test-input test) (test-spec test) (*context*) train-pcontext))
6765

68-
(define preprocessing (alt-preprocessing (first alternatives)))
69-
(define test-pcontext* (preprocess-pcontext (*context*) test-pcontext preprocessing))
70-
7166
;; compute error/cost for input expression
7267
(define start-expr (test-input test))
73-
(define start-alt (make-alt-preprocessing start-expr (test-preprocess test)))
74-
(define start-errs (errors start-expr test-pcontext* (*context*)))
68+
(define start-alt (make-alt start-expr))
69+
(define start-errs (errors start-expr test-pcontext (*context*)))
7570
(define start-alt-data (alt-analysis start-alt start-errs))
7671

7772
;; optionally compute error/cost for input expression
@@ -80,18 +75,18 @@
8075
(for/list ([(expr is-valid?) (in-dict (test-output test))]
8176
#:when is-valid?)
8277
(define target-expr (fpcore->prog expr (*context*)))
83-
(define target-errs (errors target-expr test-pcontext* (*context*)))
78+
(define target-errs (errors target-expr test-pcontext (*context*)))
8479
(alt-analysis (make-alt target-expr) target-errs)))
8580

8681
;; compute error/cost for output expression
8782
;; and sort alternatives by accuracy + cost on testing subset
88-
(define test-errs* (batch-errors (map alt-expr alternatives) test-pcontext* (*context*)))
89-
(define sorted-end-exprs (sort-alts alternatives test-errs*))
83+
(define test-errs (batch-errors (map alt-expr alternatives) test-pcontext (*context*)))
84+
(define sorted-end-exprs (sort-alts alternatives test-errs))
9085
(define end-exprs (map (compose alt-expr car) sorted-end-exprs))
9186
(define end-errs (map cdr sorted-end-exprs))
9287
(define end-data (map alt-analysis alternatives end-errs))
9388

94-
(improve-result preprocessing test-pcontext* start-alt-data target-alt-data end-data))
89+
(improve-result test-pcontext start-alt-data target-alt-data end-data))
9590

9691
(define (get-cost test)
9792
(define cost-proc (platform-cost-proc (*active-platform*)))
@@ -219,16 +214,10 @@
219214
(define (dummy-table-row-from-hash result-hash status link)
220215
(define test (car (load-tests (open-input-string (hash-ref result-hash 'test)))))
221216
(define repr (test-output-repr test))
222-
(define preprocess
223-
(if (eq? (hash-ref result-hash 'status) 'success)
224-
(map (compose read open-input-string)
225-
(hash-ref (hash-ref result-hash 'backend) 'preprocessing))
226-
(test-preprocess test)))
227217
(table-row (test-name test)
228218
(test-identifier test)
229219
status
230220
(prog->fpcore (test-pre test) (test-context test))
231-
preprocess
232221
(representation-name repr)
233222
'() ; TODO: eliminate field
234223
(test-vars test)

src/api/server.rkt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,7 @@
415415
(make-hash (map cons exprs (batch-errors exprs pcontext ctx)))]
416416
[else #f]))
417417

418-
(define test-fpcore
419-
(alt->fpcore test (make-alt-preprocessing (test-input test) (test-preprocess test))))
418+
(define test-fpcore (alt->fpcore test (make-alt (test-input test))))
420419

421420
(define fpcores
422421
(if (equal? (job-result-status herbie-result) 'success)
@@ -461,9 +460,7 @@
461460
(define (backend-improve-result-hash-table backend test errcache)
462461
(define repr (context-repr (test-context test)))
463462
(define pcontext (improve-result-pcontext backend))
464-
(hasheq 'preprocessing
465-
(map ~s (improve-result-preprocess backend))
466-
'pcontext
463+
(hasheq 'pcontext
467464
(pcontext->json pcontext repr)
468465
'start
469466
(analysis->json (improve-result-start backend) pcontext test errcache)
@@ -519,9 +516,6 @@
519516
,@(if (equal? (test-spec test) empty)
520517
'()
521518
`(:herbie-spec ,(prog->fpcore (test-spec test) (test-context test))))
522-
,@(if (equal? (alt-preprocessing altn) empty)
523-
'()
524-
`(:herbie-preprocess ,(alt-preprocessing altn)))
525519
,@(if (equal? (test-expected test) #t)
526520
'()
527521
`(:herbie-expected ,(test-expected test)))

src/core/mainloop.rkt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
(define pcontext* (preprocess-pcontext context pcontext preprocessing))
4646
(*pcontext* pcontext*)
4747
(*start-prog* initial)
48-
(^table^ (make-alt-table pcontext (make-alt-preprocessing initial preprocessing) context))
48+
(define start-alt (alt initial 'start '() preprocessing))
49+
(^table^ (make-alt-table pcontext start-alt context))
4950

5051
(for ([iteration (in-range (*num-iterations*))]
5152
#:break (atab-completed? (^table^)))
@@ -123,7 +124,7 @@
123124
[(< (length altns) (*pareto-pick-limit*)) altns] ; take max
124125
[else
125126
(define best (argmin score-alt altns))
126-
(define altns* (sort (filter-not (curry alt-equal? best) altns) < #:key (curryr alt-cost repr)))
127+
(define altns* (sort (set-remove altns best) < #:key (curryr alt-cost repr)))
127128
(define simplest (car altns*))
128129
(define altns** (cdr altns*))
129130
(define div-size (round (/ (length altns**) (- (*pareto-pick-limit*) 1))))

src/reports/common.rkt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,7 @@
154154
(core->tex prog* #:loc (and loc (cons 2 loc)) #:color "blue")
155155
"ERROR"))
156156

157-
(define (render-program expr
158-
ctx
159-
#:ident [identifier #f]
160-
#:pre [precondition '(TRUE)]
161-
#:instructions [instructions empty])
157+
(define (render-program expr ctx #:ident [identifier #f] #:pre [precondition '(TRUE)])
162158
(define output-repr (context-repr ctx))
163159
(define out-prog
164160
(parameterize ([*expr-cse-able?* at-least-two-ops?])

src/reports/make-graph.rkt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
(define ctx (test-context test))
3838
(define identifier (test-identifier test))
3939

40-
(define preprocessing (map (compose read open-input-string) (hash-ref backend 'preprocessing)))
4140
(define start-expr (read (open-input-string (hash-ref (hash-ref backend 'start) 'expr))))
4241
(define start-cost (hash-ref (hash-ref backend 'start) 'cost))
4342
(define start-error (hash-ref (hash-ref backend 'start) 'errors))
@@ -151,8 +150,7 @@
151150
[errs end-errors]
152151
[cost end-costs]
153152
[history end-histories])
154-
(define-values (dropdown body)
155-
(render-program expr ctx #:ident identifier #:instructions preprocessing))
153+
(define-values (dropdown body) (render-program expr ctx #:ident identifier))
156154
`(section ([id ,(format "alternative~a" i)] (class "programs"))
157155
(h2 "Alternative "
158156
,(~a i)

src/syntax/read.rkt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,7 @@
1818
load-tests
1919
parse-test)
2020

21-
(struct test
22-
(name identifier
23-
vars
24-
input
25-
output
26-
expected
27-
spec
28-
pre
29-
preprocess
30-
output-repr-name
31-
var-repr-names)
21+
(struct test (name identifier vars input output expected spec pre output-repr-name var-repr-names)
3222
#:prefab)
3323

3424
(define (test-output-repr test)
@@ -216,7 +206,6 @@
216206
(dict-ref prop-dict ':herbie-expected #t)
217207
spec
218208
pre*
219-
(dict-ref prop-dict ':herbie-preprocess empty)
220209
(representation-name default-repr)
221210
(for/list ([var (in-list var-names)]
222211
[repr (in-list var-reprs)])

src/utils/alternative.rkt

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,19 @@
33
(require "../syntax/platform.rkt")
44
(provide (struct-out alt)
55
make-alt
6-
alt?
7-
alt-expr
8-
alt-add-event
9-
*all-alts*
106
alt-cost
11-
alt-equal?
12-
alt-map
13-
alt-add-preprocessing
14-
make-alt-preprocessing)
7+
alt-map)
158

16-
;; Alts are a lightweight audit trail.
17-
;; An alt records a low-level view of how Herbie got
18-
;; from one program to another.
19-
;; They are a labeled linked list of changes.
9+
;; Alts are an expression plus a derivation for it.
2010

2111
(struct alt (expr event prevs preprocessing) #:prefab)
2212

2313
(define (make-alt expr)
2414
(alt expr 'start '() '()))
2515

26-
(define (make-alt-preprocessing expr preprocessing)
27-
(alt expr 'start '() preprocessing))
28-
29-
(define (alt-equal? x y)
30-
(equal? (alt-expr x) (alt-expr y)))
31-
32-
(define (alt-add-event altn event)
33-
(alt (alt-expr altn) event (list altn) (alt-preprocessing altn)))
34-
35-
(define (alt-add-preprocessing altn preprocessing)
36-
(alt (alt-expr altn) 'add-preprocessing (list altn) preprocessing))
37-
3816
(define (alt-cost altn repr)
3917
(define expr-cost (platform-cost-proc (*active-platform*)))
4018
(expr-cost (alt-expr altn) repr))
4119

4220
(define (alt-map f altn)
4321
(f (struct-copy alt altn [prevs (map (curry alt-map f) (alt-prevs altn))])))
44-
45-
;; Keeps track of all alts so far.
46-
(define *all-alts* (make-parameter '()))

0 commit comments

Comments
 (0)