Skip to content

Commit d9e44c1

Browse files
authored
Merge pull request #1358 from herbie-fp/codex/move-lifting-and-lowering-rules-to-egg-herbie.rkt
Move platform rule generation into egg-herbie
2 parents 8760810 + 67b9ae2 commit d9e44c1

File tree

2 files changed

+38
-41
lines changed

2 files changed

+38
-41
lines changed

src/core/egg-herbie.rkt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,44 @@
503503
(cons egg-rule ffi-rule)))))
504504
(for-each sow egg&ffi-rules))))
505505

506+
;; Rules from impl to spec (fixed for a particular platform)
507+
(define/reset *lifting-rules* (make-hash))
508+
509+
;; Rules from spec to impl (fixed for a particular platform)
510+
(define/reset *lowering-rules* (make-hash))
511+
512+
;; Synthesizes the LHS and RHS of lifting/lowering rules.
513+
(define (impl->rule-parts impl)
514+
(define vars (impl-info impl 'vars))
515+
(define spec (impl-info impl 'spec))
516+
(values vars spec (cons impl vars)))
517+
518+
;; Synthesizes lifting rules for a platform platform.
519+
(define (platform-lifting-rules [pform (*active-platform*)])
520+
(define impls (platform-impls pform))
521+
(for/list ([impl (in-list impls)])
522+
(hash-ref! (*lifting-rules*)
523+
(cons impl pform)
524+
(lambda ()
525+
(define name (sym-append 'lift- impl))
526+
(define-values (vars spec-expr impl-expr) (impl->rule-parts impl))
527+
(rule name impl-expr spec-expr '(lifting))))))
528+
529+
;; Synthesizes lowering rules for a given platform.
530+
(define (platform-lowering-rules [pform (*active-platform*)])
531+
(define impls (platform-impls pform))
532+
(append* (for/list ([impl (in-list impls)])
533+
(hash-ref! (*lowering-rules*)
534+
(cons impl pform)
535+
(lambda ()
536+
(define name (sym-append 'lower- impl))
537+
(define-values (vars spec-expr impl-expr) (impl->rule-parts impl))
538+
(list (rule name spec-expr impl-expr '(lowering))
539+
(rule (sym-append 'lower-unsound- impl)
540+
(add-unsound spec-expr)
541+
impl-expr
542+
'(lowering))))))))
543+
506544
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
507545
;; Racket egraph
508546
;;

src/syntax/platform.rkt

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
(require "../utils/common.rkt"
55
"../utils/errors.rkt"
66
"../config.rkt"
7-
"../core/rules.rkt"
87
"matcher.rkt"
98
"types.rkt"
109
"syntax.rkt"
@@ -29,8 +28,6 @@
2928
(fprintf port "#<platform>"))])
3029

3130
(provide *active-platform*
32-
platform-lifting-rules
33-
platform-lowering-rules
3431
platform-copy
3532
repr-exists?
3633
get-representation
@@ -170,44 +167,6 @@
170167
(define itypes (impl-info impl 'itype))
171168
(apply cost-proc (map loop args itypes))]))))
172169

173-
;; Rules from impl to spec (fixed for a particular platform)
174-
(define/reset *lifting-rules* (make-hash))
175-
176-
;; Rules from spec to impl (fixed for a particular platform)
177-
(define/reset *lowering-rules* (make-hash))
178-
179-
;; Synthesizes the LHS and RHS of lifting/lowering rules.
180-
(define (impl->rule-parts impl)
181-
(define vars (impl-info impl 'vars))
182-
(define spec (impl-info impl 'spec))
183-
(values vars spec (cons impl vars)))
184-
185-
;; Synthesizes lifting rules for a platform platform.
186-
(define (platform-lifting-rules [pform (*active-platform*)])
187-
(define impls (platform-impls pform))
188-
(for/list ([impl (in-list impls)])
189-
(hash-ref! (*lifting-rules*)
190-
(cons impl pform)
191-
(lambda ()
192-
(define name (sym-append 'lift- impl))
193-
(define-values (vars spec-expr impl-expr) (impl->rule-parts impl))
194-
(rule name impl-expr spec-expr '(lifting))))))
195-
196-
;; Synthesizes lowering rules for a given platform.
197-
(define (platform-lowering-rules [pform (*active-platform*)])
198-
(define impls (platform-impls pform))
199-
(append* (for/list ([impl (in-list impls)])
200-
(hash-ref! (*lowering-rules*)
201-
(cons impl pform)
202-
(lambda ()
203-
(define name (sym-append 'lower- impl))
204-
(define-values (vars spec-expr impl-expr) (impl->rule-parts impl))
205-
(list (rule name spec-expr impl-expr '(lowering))
206-
(rule (sym-append 'lower-unsound- impl)
207-
(add-unsound spec-expr)
208-
impl-expr
209-
'(lowering))))))))
210-
211170
;; Extracts the `fpcore` field of an operator implementation
212171
;; as a property dictionary and expression.
213172
(define (impl->fpcore impl)

0 commit comments

Comments
 (0)