Skip to content

Commit 6d3c726

Browse files
authored
Merge pull request #1337 from herbie-fp/codex/locate-itypes-and-otype-usages
Simplify rule struct by dropping type info
2 parents 63d831e + 7e403c8 commit 6d3c726

File tree

5 files changed

+20
-51
lines changed

5 files changed

+20
-51
lines changed

src/core/egg-herbie.rkt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,16 +464,13 @@
464464
(cond
465465
[(symbol? input)
466466
; expansive rules
467-
(define itype (dict-ref (rule-itypes ru) input))
468467
(for/list ([op (all-operators)]
469-
#:when (eq? (operator-info op 'otype) itype))
468+
#:when (eq? (operator-info op 'otype) 'real))
470469
(define itypes (operator-info op 'itype))
471470
(define vars (map (lambda (_) (gensym)) itypes))
472471
(rule (sym-append (rule-name ru) '-expand- op)
473472
(cons op vars)
474473
(replace-expression (rule-output ru) input (cons op vars))
475-
(map cons vars itypes)
476-
(rule-otype ru)
477474
(rule-tags ru)))]
478475
; non-expansive rule
479476
[else (list (rule->egg-rule ru))]))

src/core/egglog-herbie.rkt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -609,15 +609,10 @@
609609
(define (egglog-rewrite-rules rules tag)
610610
(for/list ([rule (in-list rules)]
611611
#:when (not (symbol? (rule-input rule))))
612-
(if (not (representation? (rule-otype rule)))
613-
`(rewrite ,(expr->e1-pattern (rule-input rule))
614-
,(expr->e1-pattern (rule-output rule))
615-
:ruleset
616-
,tag)
617-
`(rewrite ,(expr->e2-pattern (rule-input rule) (rule-otype rule))
618-
,(expr->e2-pattern (rule-output rule) (rule-otype rule))
619-
:ruleset
620-
,tag))))
612+
`(rewrite ,(expr->e1-pattern (rule-input rule))
613+
,(expr->e1-pattern (rule-output rule))
614+
:ruleset
615+
,tag)))
621616

622617
(define (egglog-add-exprs batch ctx curr-program)
623618
(define mappings (build-vector (batch-length batch) values))

src/core/rules.rkt

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
;; A rule represents "find-and-replacing" `input` by `output`. Both
1414
;; are patterns, meaning that symbols represent pattern variables.
15-
(struct rule (name input output itypes otype tags)
15+
(struct rule (name input output tags)
1616
#:methods gen:custom-write
1717
[(define (write-proc rule port mode)
1818
(fprintf port "#<rule ~a>" (rule-name rule)))])
@@ -31,16 +31,6 @@
3131
(define (*sound-rules*)
3232
(filter (conjoin rule-enabled? rule-sound?) *all-rules*))
3333

34-
; An analog of free-variables due to cycles in loading
35-
(define (get-input-variables prog)
36-
(match prog
37-
[(? number?) '()]
38-
[(? symbol?) (list prog)]
39-
[(list _ args ...) (remove-duplicates (append-map get-input-variables args))]))
40-
41-
(define (make-rule-context input output)
42-
(map (curryr cons 'real) (set-union (get-input-variables input) (get-input-variables output))))
43-
4434
(define (add-unsound expr)
4535
(match expr
4636
[(list op args ...) (cons (sym-append "unsound-" op) (map add-unsound args))]
@@ -49,15 +39,9 @@
4939
(define-syntax define-rule
5040
(syntax-rules ()
5141
[(define-rule rname group input output)
52-
(set! *all-rules*
53-
(cons (rule 'rname 'input 'output (make-rule-context 'input 'output) 'real '(group sound))
54-
*all-rules*))]
42+
(set! *all-rules* (cons (rule 'rname 'input 'output '(group sound)) *all-rules*))]
5543
[(define-rule rname group input output #:unsound)
56-
(set!
57-
*all-rules*
58-
(cons
59-
(rule 'rname 'input (add-unsound 'output) (make-rule-context 'input 'output) 'real '(group))
60-
*all-rules*))]))
44+
(set! *all-rules* (cons (rule 'rname 'input (add-unsound 'output) '(group)) *all-rules*))]))
6145

6246
(define-syntax-rule (define-rules group
6347
[rname input output flags ...] ...)

src/core/test-rules.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
[_ expr]))
3030

3131
(define (check-rule test-rule)
32-
(match-define (rule name p1 p2 _ _ _) test-rule)
32+
(match-define (rule name p1 p2 _) test-rule)
3333
(define ctx (env->ctx p1 p2))
3434

3535
(match-define (list pts exs1 exs2)

src/syntax/platform.rkt

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -256,30 +256,23 @@
256256
(cons impl pform)
257257
(lambda ()
258258
(define name (sym-append 'lift- impl))
259-
(define itypes (impl-info impl 'itype))
260-
(define otype (impl-info impl 'otype))
261259
(define-values (vars spec-expr impl-expr) (impl->rule-parts impl))
262-
(rule name impl-expr spec-expr (map cons vars itypes) otype '(lifting))))))
260+
(rule name impl-expr spec-expr '(lifting))))))
263261

264262
;; Synthesizes lowering rules for a given platform.
265263
(define (platform-lowering-rules [pform (*active-platform*)])
266264
(define impls (platform-impls pform))
267265
(append* (for/list ([impl (in-list impls)])
268-
(hash-ref!
269-
(*lowering-rules*)
270-
(cons impl pform)
271-
(lambda ()
272-
(define name (sym-append 'lower- impl))
273-
(define-values (vars spec-expr impl-expr) (impl->rule-parts impl))
274-
(define itypes (map representation-type (impl-info impl 'itype)))
275-
(define otype (representation-type (impl-info impl 'otype)))
276-
(list (rule name spec-expr impl-expr (map cons vars itypes) otype '(lowering))
277-
(rule (sym-append 'lower-unsound- impl)
278-
(add-unsound spec-expr)
279-
impl-expr
280-
(map cons vars itypes)
281-
otype
282-
'(lowering))))))))
266+
(hash-ref! (*lowering-rules*)
267+
(cons impl pform)
268+
(lambda ()
269+
(define name (sym-append 'lower- impl))
270+
(define-values (vars spec-expr impl-expr) (impl->rule-parts impl))
271+
(list (rule name spec-expr impl-expr '(lowering))
272+
(rule (sym-append 'lower-unsound- impl)
273+
(add-unsound spec-expr)
274+
impl-expr
275+
'(lowering))))))))
283276

284277
;; Extracts the `fpcore` field of an operator implementation
285278
;; as a property dictionary and expression.

0 commit comments

Comments
 (0)