Skip to content

Commit f613c0a

Browse files
committed
Remove the sound-X rules with a separate rewrite pass
1 parent 4dceae1 commit f613c0a

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/core/egg-herbie.rkt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,6 @@
287287
[`(Explanation ,body ...) `(Explanation ,@(map (lambda (e) (loop e type)) body))]
288288
[(list 'Rewrite=> rule expr) (list 'Rewrite=> (get-canon-rule-name rule rule) (loop expr type))]
289289
[(list 'Rewrite<= rule expr) (list 'Rewrite<= (get-canon-rule-name rule rule) (loop expr type))]
290-
[(list op args ...)
291-
#:when (string-prefix? (symbol->string op) "sound-")
292-
(define op* (string->symbol (substring (symbol->string (car expr)) (string-length "sound-"))))
293-
(define args* (drop-right args 1))
294-
(cons op* (map loop args* (map (const 'real) args*)))]
295290
[(list op args ...)
296291
;; Unfortunately the type parameter doesn't tell us much because mixed exprs exist
297292
;; so if we see something like (and a b) we literally don't know which "and" it is

src/core/patch.rkt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@
9090
approxs*)
9191

9292
(define (run-lowering altns global-batch)
93-
(define schedule `((lower . ((iteration . 1) (scheduler . simple)))))
93+
(define schedule
94+
`((,(*sound-removal-rules*) . ((iteration . 1) (scheduler . simple)))
95+
(lower . ((iteration . 1) (scheduler . simple)))))
9496

9597
; run egg
9698
(define brfs (map alt-expr altns))
@@ -160,10 +162,11 @@
160162
; generate required rules
161163
(define rules (*rules*))
162164

163-
; egg schedule (3-phases for mathematical rewrites and implementation selection)
165+
; egg schedule (4-phases for mathematical rewrites, sound-X removal, and implementation selection)
164166
(define schedule
165167
(list `(lift . ((iteration . 1) (scheduler . simple)))
166168
`(,rules . ((node . ,(*node-limit*))))
169+
`(,(*sound-removal-rules*) . ((iteration . 1) (scheduler . simple)))
167170
`(lower . ((iteration . 1) (scheduler . simple)))))
168171

169172
(define brfs (map alt-expr altns))

src/core/rules.rkt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"../syntax/syntax.rkt")
77

88
(provide *rules*
9+
*sound-removal-rules*
910
(struct-out rule)
1011
add-sound)
1112

@@ -612,3 +613,9 @@
612613
[cosh-atanh-rev (/ 1 (sqrt (- 1 (* x x)))) (cosh (atanh x))]
613614
[asinh-2 (acosh (+ (* 2 (* x x)) 1)) (* 2 (asinh (fabs x)))]
614615
[acosh-2-rev (* 2 (acosh x)) (acosh (- (* 2 (* x x)) 1))])
616+
617+
; Sound-X removal rules: run these before lowering
618+
(define (*sound-removal-rules*)
619+
(list (rule 'remove-sound-/ '(sound-/ a b fallback) '(/ a b) '(sound-removal))
620+
(rule 'remove-sound-pow '(sound-pow a b fallback) '(pow a b) '(sound-removal))
621+
(rule 'remove-sound-log '(sound-log a fallback) '(log a) '(sound-removal))))

0 commit comments

Comments
 (0)