|
294 | 294 | [`(Explanation ,body ...) `(Explanation ,@(map (lambda (e) (loop e type)) body))] |
295 | 295 | [(list 'Rewrite=> rule expr) (list 'Rewrite=> (get-canon-rule-name rule rule) (loop expr type))] |
296 | 296 | [(list 'Rewrite<= rule expr) (list 'Rewrite<= (get-canon-rule-name rule rule) (loop expr type))] |
297 | | - [(list (? impl-exists? impl) args ...) (cons impl (map loop args (impl-info impl 'itype)))] |
298 | 297 | [(list op args ...) |
299 | 298 | #:when (string-contains? (~a op) "unsound") |
300 | 299 | (define op* (string->symbol (string-replace (symbol->string (car expr)) "unsound-" ""))) |
301 | 300 | (cons op* (map loop args (map (const 'real) args)))] |
302 | | - [(list op args ...) (cons op (map loop args (operator-info op 'itype)))]))) |
| 301 | + [(list op args ...) |
| 302 | + ;; Unfortunately the type parameter doesn't tell us much because mixed exprs exist |
| 303 | + ;; so if we see something like (and a b) we literally don't know which "and" it is |
| 304 | + (cons op |
| 305 | + (map loop |
| 306 | + args |
| 307 | + (cond |
| 308 | + [(and (operator-exists? op) (impl-exists? op)) |
| 309 | + (if (representation? type) |
| 310 | + (impl-info op 'itype) |
| 311 | + (operator-info op 'itype))] |
| 312 | + [(impl-exists? op) (impl-info op 'itype)] |
| 313 | + [(operator-exists? op) (operator-info op 'itype)])))]))) |
303 | 314 |
|
304 | 315 | ;; Parses a string from egg into a single S-expr. |
305 | 316 | (define (egg-expr->expr egg-expr ctx) |
|
537 | 548 | (cond |
538 | 549 | [(eq? f '$approx) (platform-reprs (*active-platform*))] |
539 | 550 | [(string-contains? (~a f) "unsound") (list 'real)] |
540 | | - [(impl-exists? f) (list (impl-info f 'otype))] |
541 | | - [(eq? f 'if) '(real bool)] |
542 | | - [else (list (operator-info f 'otype))])])) |
| 551 | + [else |
| 552 | + (filter values |
| 553 | + (list (and (impl-exists? f) (impl-info f 'otype)) |
| 554 | + (and (operator-exists? f) (operator-info f 'otype))))])])) |
543 | 555 |
|
544 | 556 | ;; Rebuilds an e-node using typed e-classes |
545 | 557 | (define (rebuild-enode enode type lookup) |
|
558 | 570 | [else |
559 | 571 | (define itypes |
560 | 572 | (cond |
561 | | - [(impl-exists? f) (impl-info f 'itype)] |
562 | | - [(eq? f 'if) (list 'bool type type)] |
| 573 | + [(representation? type) (impl-info f 'itype)] |
563 | 574 | [else (operator-info f 'itype)])) |
564 | 575 | ; unsafe since we don't check that |itypes| = |ids| |
565 | 576 | ; optimize for common cases to avoid extra allocations |
|
1016 | 1027 | (representation-type type) |
1017 | 1028 | type)) |
1018 | 1029 | (approx (loop spec spec-type) (loop impl type))] |
1019 | | - [(list (? impl-exists? impl) args ...) (cons impl (map loop args (impl-info impl 'itype)))] |
1020 | | - [(list 'if c t f) (list 'if (loop c 'bool) (loop t 'real) (loop f 'real))] |
1021 | | - [(list op args ...) (cons op (map loop args (operator-info op 'itype)))]))) |
| 1030 | + [(list op args ...) |
| 1031 | + (cons op |
| 1032 | + (map loop |
| 1033 | + args |
| 1034 | + (if (representation? type) |
| 1035 | + (impl-info op 'itype) |
| 1036 | + (operator-info op 'itype))))]))) |
1022 | 1037 |
|
1023 | 1038 | (define (eggref id) |
1024 | 1039 | (cdr (vector-ref egg-nodes id))) |
|
1048 | 1063 | (define final-spec (egg-parsed->expr spec* spec-type)) |
1049 | 1064 | (define final-spec-idx (mutable-batch-munge! out final-spec)) |
1050 | 1065 | (approx final-spec-idx (loop impl type))] |
1051 | | - [(list (? impl-exists? impl) (app eggref args) ...) |
1052 | | - (define args* |
1053 | | - (for/list ([arg (in-list args)] |
1054 | | - [type (in-list (impl-info impl 'itype))]) |
1055 | | - (loop arg type))) |
1056 | | - (cons impl args*)] |
1057 | | - [(list 'if c t f) |
1058 | | - (list 'if (loop (eggref c) 'bool) (loop (eggref t) type) (loop (eggref f) type))] |
1059 | | - [(list (? operator-exists? op) (app eggref args) ...) |
| 1066 | + [(list impl (app eggref args) ...) |
1060 | 1067 | (define args* |
1061 | 1068 | (for/list ([arg (in-list args)] |
1062 | | - [type (in-list (operator-info op 'itype))]) |
| 1069 | + [type (in-list (if (representation? type) |
| 1070 | + (impl-info impl 'itype) |
| 1071 | + (operator-info impl 'itype)))]) |
1063 | 1072 | (loop arg type))) |
1064 | | - (cons op args*)])) |
| 1073 | + (cons impl args*)])) |
1065 | 1074 | (mutable-batch-push! out enode*))) |
1066 | 1075 | (batchref input-batch idx)) |
1067 | 1076 |
|
|
0 commit comments