Skip to content

Commit c81e6a3

Browse files
committed
Rename send-to-egglog to egglog-send
1 parent 1404b15 commit c81e6a3

File tree

2 files changed

+80
-80
lines changed

2 files changed

+80
-80
lines changed

src/core/egglog-herbie.rkt

Lines changed: 72 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,20 @@
133133
(define-values (all-bindings extract-bindings)
134134
(egglog-add-exprs insert-batch insert-brfs (egglog-runner-ctx runner) subproc))
135135

136-
(send-to-egglog (list `(ruleset run-extract-commands)
137-
`(rule () (,@all-bindings) :ruleset run-extract-commands)
138-
`(run-schedule (repeat 1 run-extract-commands)))
139-
subproc)
136+
(egglog-send subproc
137+
(list `(ruleset run-extract-commands)
138+
`(rule () (,@all-bindings) :ruleset run-extract-commands)
139+
`(run-schedule (repeat 1 run-extract-commands))))
140140

141141
;; 4. Running the schedule : having code inside to emulate egraph-run-rules
142142

143143
(for ([step (in-list (egglog-runner-schedule runner))])
144144
(match step
145-
['lift (send-to-egglog (list '(run-schedule (saturate lift))) subproc)]
145+
['lift (egglog-send subproc (list '(run-schedule (saturate lift))))]
146146

147-
['lower (send-to-egglog (list '(run-schedule (saturate lower))) subproc)]
147+
['lower (egglog-send subproc (list '(run-schedule (saturate lower))))]
148148

149-
['unsound (send-to-egglog (list '(run-schedule (saturate unsound))) subproc)]
149+
['unsound (egglog-send subproc (list '(run-schedule (saturate unsound))))]
150150

151151
;; Run the rewrite ruleset interleaved with const-fold until the best iteration
152152
['rewrite (egglog-unsound-detected-subprocess step subproc)]))
@@ -157,7 +157,7 @@
157157
`(extract (,constructor-name) ,(*egglog-variants-limit*))))
158158

159159
(define stdout-content
160-
(send-to-egglog extract-commands subproc #:num-extracts (length extract-commands)))
160+
(egglog-send subproc extract-commands #:num-extracts (length extract-commands)))
161161

162162
;; (Listof (Listof exprs))
163163
(define herbie-exprss
@@ -206,39 +206,40 @@
206206
(define (prelude subproc #:mixed-egraph? [mixed-egraph? #t])
207207
(define pform (*active-platform*))
208208

209-
(send-to-egglog
210-
(list
211-
`(datatype M (Num BigRat :cost 4294967295) (Var String :cost 4294967295) ,@(platform-spec-nodes)))
212-
subproc)
213-
214-
(send-to-egglog (append (list `(datatype MTy
215-
,@(num-typed-nodes pform)
216-
,@(var-typed-nodes pform)
217-
(Approx M MTy)
218-
,@(platform-impl-nodes pform))
219-
`(constructor do-lower (M String) MTy :unextractable)
220-
`(constructor do-lift (MTy) M :unextractable)
221-
`(ruleset const-fold)
222-
`(ruleset lower)
223-
`(ruleset lift)
224-
`(ruleset unsound)
225-
`(function bad-merge? () bool :merge (or old new))
226-
`(ruleset bad-merge-rule)
227-
`(set (bad-merge?) false)
228-
`(rule ((= (Num c1) (Num c2)) (!= c1 c2))
229-
((set (bad-merge?) true))
230-
:ruleset
231-
bad-merge-rule))
232-
const-fold
233-
(impl-lowering-rules pform)
234-
(impl-lifting-rules pform)
235-
(num-lowering-rules)
236-
(num-lifting-rules)
237-
(list (approx-lifting-rule))
238-
(egglog-rewrite-rules (*sound-removal-rules*) 'unsound)
239-
(list `(ruleset rewrite))
240-
(egglog-rewrite-rules (*rules*) 'rewrite))
241-
subproc)
209+
(egglog-send subproc
210+
(list `(datatype M
211+
(Num BigRat :cost 4294967295)
212+
(Var String :cost 4294967295)
213+
,@(platform-spec-nodes))))
214+
215+
(egglog-send subproc
216+
(append (list `(datatype MTy
217+
,@(num-typed-nodes pform)
218+
,@(var-typed-nodes pform)
219+
(Approx M MTy)
220+
,@(platform-impl-nodes pform))
221+
`(constructor do-lower (M String) MTy :unextractable)
222+
`(constructor do-lift (MTy) M :unextractable)
223+
`(ruleset const-fold)
224+
`(ruleset lower)
225+
`(ruleset lift)
226+
`(ruleset unsound)
227+
`(function bad-merge? () bool :merge (or old new))
228+
`(ruleset bad-merge-rule)
229+
`(set (bad-merge?) false)
230+
`(rule ((= (Num c1) (Num c2)) (!= c1 c2))
231+
((set (bad-merge?) true))
232+
:ruleset
233+
bad-merge-rule))
234+
const-fold
235+
(impl-lowering-rules pform)
236+
(impl-lifting-rules pform)
237+
(num-lowering-rules)
238+
(num-lifting-rules)
239+
(list (approx-lifting-rule))
240+
(egglog-rewrite-rules (*sound-removal-rules*) 'unsound)
241+
(list `(ruleset rewrite))
242+
(egglog-rewrite-rules (*rules*) 'rewrite)))
242243

243244
(void))
244245

@@ -544,30 +545,30 @@
544545
(set! root-bindings (cons (vector-ref mappings n) root-bindings))))
545546

546547
; Var-lowering-rules
547-
(send-to-egglog (for/list ([var (in-list (context-vars ctx))]
548-
[repr (in-list (context-var-reprs ctx))])
549-
`(rule ((= e (Var ,(symbol->string var))))
550-
((let ty ,(symbol->string (representation-name repr))
551-
)
552-
(let ety (,(typed-var-id (representation-name repr))
553-
,(symbol->string var))
554-
)
555-
(union (do-lower e ty) ety))
556-
:ruleset
557-
lower))
558-
subproc)
548+
(egglog-send subproc
549+
(for/list ([var (in-list (context-vars ctx))]
550+
[repr (in-list (context-var-reprs ctx))])
551+
`(rule ((= e (Var ,(symbol->string var))))
552+
((let ty ,(symbol->string (representation-name repr))
553+
)
554+
(let ety (,(typed-var-id (representation-name repr))
555+
,(symbol->string var))
556+
)
557+
(union (do-lower e ty) ety))
558+
:ruleset
559+
lower)))
559560

560561
; Var-lifting-rules
561-
(send-to-egglog (for/list ([var (in-list (context-vars ctx))]
562-
[repr (in-list (context-var-reprs ctx))])
563-
`(rule ((= e (,(typed-var-id (representation-name repr)) ,(symbol->string var))))
564-
((let se (Var
565-
,(symbol->string var))
566-
)
567-
(union (do-lift e) se))
568-
:ruleset
569-
lift))
570-
subproc)
562+
(egglog-send subproc
563+
(for/list ([var (in-list (context-vars ctx))]
564+
[repr (in-list (context-var-reprs ctx))])
565+
`(rule ((= e (,(typed-var-id (representation-name repr)) ,(symbol->string var))))
566+
((let se (Var
567+
,(symbol->string var))
568+
)
569+
(union (do-lift e) se))
570+
:ruleset
571+
lift)))
571572

572573
(define all-bindings '())
573574
(define binding->constructor (make-hash)) ; map from binding name to constructor name
@@ -585,7 +586,7 @@
585586
(define curr-var-spec-binding `(let ,binding-name (Var ,(symbol->string var))))
586587

587588
; Send the constructor definition
588-
(send-to-egglog (list `(constructor ,constructor-name () M :unextractable)) subproc)
589+
(egglog-send subproc (list `(constructor ,constructor-name () M :unextractable)))
589590

590591
; Add the binding and constructor set to all-bindings for the future rule
591592
(set! all-bindings (cons curr-var-spec-binding all-bindings))
@@ -606,7 +607,7 @@
606607
`(let ,binding-name (,(typed-var-id (representation-name repr)) ,(symbol->string var))))
607608

608609
; Send the constructor definition
609-
(send-to-egglog (list `(constructor ,constructor-name () MTy :unextractable)) subproc)
610+
(egglog-send subproc (list `(constructor ,constructor-name () MTy :unextractable)))
610611

611612
; Add the binding and constructor set to all-bindings for the future rule
612613
(set! all-bindings (cons curr-var-typed-binding all-bindings))
@@ -639,7 +640,7 @@
639640

640641
(define curr-binding-exprs `(let ,binding-name ,actual-binding))
641642

642-
(send-to-egglog (list `(constructor ,constructor-name () ,curr-datatype :unextractable)) subproc)
643+
(egglog-send subproc (list `(constructor ,constructor-name () ,curr-datatype :unextractable)))
643644

644645
(set! all-bindings (cons curr-binding-exprs all-bindings))
645646
(set! all-bindings (cons `(set (,constructor-name) ,binding-name) all-bindings))
@@ -728,14 +729,14 @@
728729
;; e-graph while extracting. For now, popping provides a smaller e-graph and gives
729730
;; performance comparable to Egg-Herbie, thought it doesn't affect correctness too much
730731
[math-node-limit?
731-
(send-to-egglog (list '(pop)) subproc)
732+
(egglog-send subproc (list '(pop)))
732733
(values (sub1 curr-iter) #t)]
733734

734735
;; If Unsoundness detected or node-limit reached, then return the
735736
;; optimal iter limit (one less than current) and run (pop)
736737
[math-unsound?
737738
;; Pop once at the end since the egraph isn't valid
738-
(send-to-egglog (list '(pop)) subproc)
739+
(egglog-send subproc (list '(pop)))
739740

740741
;; Return one less than current iteration and indicate that we need to run again because pop
741742
(values (sub1 curr-iter) #t)]
@@ -760,11 +761,11 @@
760761
;; TODO: See the TODO from above
761762
[(equal? const-total-nodes prev-number-nodes) (values curr-iter #f)]
762763
[const-node-limit?
763-
(send-to-egglog (list '(pop)) subproc)
764+
(egglog-send subproc (list '(pop)))
764765
(values (sub1 curr-iter) #t)]
765766

766767
[const-unsound?
767-
(send-to-egglog (list '(pop)) subproc)
768+
(egglog-send subproc (list '(pop)))
768769
(values (sub1 curr-iter) #t)]
769770

770771
[else
@@ -774,7 +775,7 @@
774775
(loop (add1 curr-iter))])])])))
775776

776777
(define (get-egglog-output curr-schedule subproc node-limit)
777-
(define-values (node-values unsound?) (send-to-egglog-unsound-detection curr-schedule subproc))
778+
(define-values (node-values unsound?) (egglog-send-unsound-detection subproc curr-schedule))
778779

779780
; (when unsound?
780781
; (printf "ALERT : UNSOUNDNESS DETECTED when...\n"))

src/core/egglog-subprocess.rkt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
(provide (struct-out egglog-subprocess)
66
create-new-egglog-subprocess
7-
send-to-egglog
8-
send-to-egglog-unsound-detection
7+
egglog-send
8+
egglog-send-unsound-detection
99
egglog-subprocess-close)
1010

1111
;; Struct to hold egglog subprocess handles
@@ -47,7 +47,7 @@
4747

4848
(egglog-subprocess egglog-process egglog-output egglog-in err dump-file))
4949

50-
(define (send-to-egglog commands subproc #:num-extracts [num-extracts 0])
50+
(define (egglog-send subproc commands #:num-extracts [num-extracts 0])
5151
(match-define (egglog-subprocess egglog-process egglog-output egglog-in err dump-file) subproc)
5252

5353
(define egglog-program (apply ~s #:separator "\n" commands))
@@ -79,7 +79,7 @@
7979
(for/list ([i (in-range num-extracts)])
8080
(read egglog-output))))
8181

82-
(define (send-to-egglog-unsound-detection commands subproc)
82+
(define (egglog-send-unsound-detection subproc commands)
8383
(match-define (egglog-subprocess egglog-process egglog-output egglog-in err dump-file) subproc)
8484

8585
(define egglog-program (apply ~s #:separator "\n" commands))
@@ -159,20 +159,19 @@
159159
'(run init 1)))
160160

161161
; Nothing to output
162-
(send-to-egglog first-commands subproc)
162+
(egglog-send subproc first-commands)
163163

164164
; Has extract 1 thing
165165
(define second-commands (list '(extract (const1))))
166166

167-
(define lines1 (send-to-egglog second-commands subproc #:num-extracts 1))
167+
(define lines1 (egglog-send subproc second-commands #:num-extracts 1))
168168
(printf "\noutput-vals1 : ~a\n\n" lines1)
169169

170170
;; Print size
171171

172172
(define print-size-commands (list '(print-size) '(run unsound-rule 1) '(extract (unsound))))
173173

174-
(define-values (node-values unsound?)
175-
(send-to-egglog-unsound-detection print-size-commands subproc))
174+
(define-values (node-values unsound?) (egglog-send-unsound-detection subproc print-size-commands))
176175

177176
(for ([line node-values]
178177
#:when (> (string-length line) 0))
@@ -185,7 +184,7 @@
185184
;; last two
186185
(define third-commands (list '(extract (const2)) '(extract (const3))))
187186

188-
(define lines2 (send-to-egglog third-commands subproc #:num-extracts 2))
187+
(define lines2 (egglog-send subproc third-commands #:num-extracts 2))
189188
(printf "\noutput-vals2 : ~a\n\n" lines2)
190189

191190
(egglog-subprocess-close subproc)))

0 commit comments

Comments
 (0)