1 ;;;; tree-il.test --- test suite for compiling tree-il -*- scheme -*-
2 ;;;; Andy Wingo <wingo@pobox.com> --- May 2009
4 ;;;; Copyright (C) 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
6 ;;;; This library is free software; you can redistribute it and/or
7 ;;;; modify it under the terms of the GNU Lesser General Public
8 ;;;; License as published by the Free Software Foundation; either
9 ;;;; version 3 of the License, or (at your option) any later version.
11 ;;;; This library is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;;;; Lesser General Public License for more details.
16 ;;;; You should have received a copy of the GNU Lesser General Public
17 ;;;; License along with this library; if not, write to the Free Software
18 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 (define-module (test-suite tree-il)
21 #:use-module (test-suite lib)
22 #:use-module (system base compile)
23 #:use-module (system base pmatch)
24 #:use-module (system base message)
25 #:use-module (language tree-il)
26 #:use-module (language tree-il primitives)
27 #:use-module (language glil)
28 #:use-module (rnrs bytevectors) ;; for the bytevector primitives
29 #:use-module (srfi srfi-13))
32 ;; The partial evaluator.
33 (@@ (language tree-il optimize) peval))
35 (define-syntax pass-if-peval
41 (compile 'in #:from 'scheme #:to 'tree-il)
45 (let ((evaled (unparse-tree-il (peval code))))
48 (_ (pk 'peval-mismatch)
49 ((@ (ice-9 pretty-print) pretty-print)
52 ((@ (ice-9 pretty-print) pretty-print)
55 ((@ (ice-9 pretty-print) pretty-print)
61 (with-test-prefix "partial evaluation"
64 ;; First order, primitive.
65 (let ((x 1) (y 2)) (+ x y))
69 ;; First order, thunk.
71 (let ((f (lambda () (+ x y))))
76 ;; First order, let-values (requires primitive expansion for
77 ;; `call-with-values'.)
80 (lambda () (if (zero? x) (values 1 2) (values 3 4)))
86 ;; First order, multiple values.
89 (primcall values (const 1) (const 2)))
92 ;; First order, multiple values truncated.
93 (let ((x (values 1 'a)) (y 2))
95 (primcall values (const 1) (const 2)))
98 ;; First order, multiple values truncated.
103 ;; First order, coalesced, mutability preserved.
104 (cons 0 (cons 1 (cons 2 (list 3 4 5))))
106 (const 0) (const 1) (const 2) (const 3) (const 4) (const 5)))
109 ;; First order, coalesced, immutability preserved.
110 (cons 0 (cons 1 (cons 2 '(3 4 5))))
111 (primcall cons (const 0)
112 (primcall cons (const 1)
113 (primcall cons (const 2)
116 ;; These two tests doesn't work any more because we changed the way we
117 ;; deal with constants -- now the algorithm will see a construction as
118 ;; being bound to the lexical, so it won't propagate it. It can't
119 ;; even propagate it in the case that it is only referenced once,
122 ;; (let ((x (cons 1 2))) (lambda () x))
124 ;; is not the same as
126 ;; (lambda () (cons 1 2))
128 ;; Perhaps if we determined that not only was it only referenced once,
129 ;; it was not closed over by a lambda, then we could propagate it, and
130 ;; re-enable these two tests.
134 ;; First order, mutability preserved.
135 (let loop ((i 3) (r '()))
138 (loop (1- i) (cons (cons i i) r))))
140 (primcall cons (const 1) (const 1))
141 (primcall cons (const 2) (const 2))
142 (primcall cons (const 3) (const 3))))
147 ;; First order, evaluated.
152 (loop (1- i) (cons i r))))
155 ;; Instead here are tests for what happens for the above cases: they
156 ;; unroll but they don't fold.
158 (let loop ((i 3) (r '()))
161 (loop (1- i) (cons (cons i i) r))))
164 (primcall cons (const 3) (const 3))))
167 (primcall cons (const 2) (const 2))
170 (primcall cons (const 1) (const 1))
179 (loop (1- i) (cons i r))))
181 ((primcall list (const 4)))
199 (let loop ((l '(1 2 3 4)) (sum 0))
202 (loop (cdr l) (+ sum (car l)))))
217 (string->chars "yo"))
218 (primcall list (const #\y) (const #\o)))
221 ;; Primitives in module-refs are resolved (the expansion of `pmatch'
222 ;; below leads to calls to (@@ (system base pmatch) car) and
223 ;; similar, which is what we want to be inlined.)
225 (use-modules (system base pmatch))
233 ;; Mutability preserved.
234 ((lambda (x y z) (list x y z)) 1 2 3)
235 (primcall list (const 1) (const 2) (const 3)))
238 ;; Don't propagate effect-free expressions that operate on mutable
244 (let (x) (_) ((primcall list (const 1)))
245 (let (y) (_) ((primcall car (lexical x _)))
247 (primcall set-car! (lexical x _) (const 0))
251 ;; Don't propagate effect-free expressions that operate on objects we
256 (let (y) (_) ((primcall car (toplevel x)))
258 (primcall set-car! (toplevel x) (const 0))
262 ;; Infinite recursion
263 ((lambda (x) (x x)) (lambda (x) (x x)))
268 (call (lexical x _) (lexical x _))))))
269 (call (lexical x _) (lexical x _))))
272 ;; First order, aliased primitive.
273 (let* ((x *) (y (x 1 2))) y)
277 ;; First order, shadowed primitive.
279 (define (+ x y) (pk x y))
285 (((x y) #f #f #f () (_ _))
286 (call (toplevel pk) (lexical x _) (lexical y _))))))
287 (call (toplevel +) (const 1) (const 2))))
290 ;; First-order, effects preserved.
295 (call (toplevel do-something!))
299 ;; First order, residual bindings removed.
302 (primcall * (const 5) (toplevel z)))
305 ;; First order, with lambda.
307 (define (bar z) (* z z))
312 (((x) #f #f #f () (_))
313 (primcall + (lexical x _) (const 9)))))))
316 ;; First order, with lambda inlined & specialized twice.
317 (let ((f (lambda (x y)
326 (primcall + ; (f 2 3)
331 (let (x) (_) ((toplevel something)) ; (f something 2)
332 ;; `something' is not const, so preserve order of
333 ;; effects with a lexical binding.
341 ;; First order, with lambda inlined & specialized 3 times.
342 (let ((f (lambda (x y) (if (> x 0) y x))))
354 (const -1) ; (f -1 0)
355 (seq (toplevel y) (const -1))) ; (f -1 y)
356 (toplevel y)) ; (f 2 y)
357 (let (x y) (_ _) ((toplevel z) (toplevel y)) ; (f z y)
358 (if (primcall > (lexical x _) (const 0))
363 ;; First order, conditional.
371 (((x) #f #f #f () (_))
372 (call (toplevel display) (lexical x _))))))
375 ;; First order, recursive procedure.
376 (letrec ((fibo (lambda (n)
385 ;; Don't propagate toplevel references, as intervening expressions
386 ;; could alter their bindings.
390 (let (x) (_) ((toplevel top))
392 (call (toplevel foo))
398 (f (* (car x) (cadr x))))
405 ;; Higher order with optional argument (default value).
406 ((lambda* (f x #:optional (y 0))
407 (+ y (f (* (car x) (cadr x)))))
414 ;; Higher order with optional argument (caller-supplied value).
415 ((lambda* (f x #:optional (y 0))
416 (+ y (f (* (car x) (cadr x)))))
424 ;; Higher order with optional argument (side-effecting default
426 ((lambda* (f x #:optional (y (foo)))
427 (+ y (f (* (car x) (cadr x)))))
431 (let (y) (_) ((call (toplevel foo)))
432 (primcall + (lexical y _) (const 7))))
435 ;; Higher order with optional argument (caller-supplied value).
436 ((lambda* (f x #:optional (y (foo)))
437 (+ y (f (* (car x) (cadr x)))))
446 ((lambda (f) (f x)) (lambda (x) x))
451 ;; <https://lists.gnu.org/archive/html/bug-guile/2011-09/msg00019.html>.
452 (let ((fold (lambda (f g) (f (g top)))))
453 (fold 1+ (lambda (x) x)))
454 (primcall 1+ (toplevel top)))
457 ;; Procedure not inlined when residual code contains recursive calls.
458 ;; <http://debbugs.gnu.org/9542>
459 (letrec ((fold (lambda (f x3 b null? car cdr)
462 (f (car x3) (fold f (cdr x3) b null? car cdr))))))
463 (fold * x 1 zero? (lambda (x1) x1) (lambda (x2) (- x2 1))))
464 (letrec (fold) (_) (_)
465 (call (lexical fold _)
472 (((x1) #f #f #f () (_))
476 (((x2) #f #f #f () (_))
477 (primcall 1- (lexical x2 _))))))))
479 (pass-if "inlined lambdas are alpha-renamed"
480 ;; In this example, `make-adder' is inlined more than once; thus,
481 ;; they should use different gensyms for their arguments, because
482 ;; the various optimization passes assume uniquely-named variables.
485 ;; <https://lists.gnu.org/archive/html/bug-guile/2011-09/msg00019.html> and
486 ;; <https://lists.gnu.org/archive/html/bug-guile/2011-09/msg00029.html>.
487 (pmatch (unparse-tree-il
488 (peval (expand-primitives
492 (lambda (x) (lambda (y) (+ x y)))))
493 (cons (make-adder 1) (make-adder 2)))
499 (((y) #f #f #f () (,gensym1))
502 (lexical y ,ref1)))))
505 (((y) #f #f #f () (,gensym2))
508 (lexical y ,ref2))))))
509 (and (eq? gensym1 ref1)
511 (not (eq? gensym1 gensym2))))
515 ;; Unused letrec bindings are pruned.
516 (letrec ((a (lambda () (b)))
523 ;; Unused letrec bindings are pruned.
528 (seq (call (toplevel foo!))
532 ;; Higher order, mutually recursive procedures.
533 (letrec ((even? (lambda (x)
538 (and (even? 4) (odd? 7)))
542 ;; Memv with constants.
547 ;; Memv with non-constant list. It could fold but doesn't
549 (memv 1 (list 3 2 1))
552 (primcall list (const 3) (const 2) (const 1))))
555 ;; Memv with non-constant key, constant list, test context
559 (let (key) (_) ((toplevel foo))
560 (if (if (primcall eqv? (lexical key _) (const 3))
562 (if (primcall eqv? (lexical key _) (const 2))
564 (primcall eqv? (lexical key _) (const 1))))
569 ;; Memv with non-constant key, empty list, test context.
573 (seq (toplevel foo) (const 'b)))
576 ;; Below are cases where constant propagation should bail out.
580 ;; Non-constant lexical is not propagated.
581 (let ((v (make-vector 6 #f)))
583 (vector-set! v n n)))
585 ((call (toplevel make-vector) (const 6) (const #f)))
588 (((n) #f #f #f () (_))
589 (primcall vector-set!
590 (lexical v _) (lexical n _) (lexical n _)))))))
593 ;; Mutable lexical is not propagated.
594 (let ((v (vector 1 2 3)))
598 ((primcall vector (const 1) (const 2) (const 3)))
605 ;; Lexical that is not provably pure is not inlined nor propagated.
606 (let* ((x (if (> p q) (frob!) (display 'chbouib)))
609 (let (x) (_) ((if (primcall > (toplevel p) (toplevel q))
610 (call (toplevel frob!))
611 (call (toplevel display) (const chbouib))))
612 (let (y) (_) ((primcall * (lexical x _) (const 2)))
614 (primcall + (lexical x _) (lexical x _))
618 ;; Non-constant arguments not propagated to lambdas.
627 ((primcall vector (const 1) (const 2) (const 3))
628 (call (toplevel make-list) (const 10))
629 (primcall list (const 1) (const 2) (const 3)))
631 (primcall vector-set!
632 (lexical x _) (const 0) (const 0))
633 (seq (primcall set-car!
634 (lexical y _) (const 0))
636 (lexical z _) (const ()))))))
639 (let ((foo top-foo) (bar top-bar))
640 (let* ((g (lambda (x y) (+ x y)))
641 (f (lambda (g x) (g x x))))
642 (+ (f g foo) (f g bar))))
643 (let (foo bar) (_ _) ((toplevel top-foo) (toplevel top-bar))
645 (primcall + (lexical foo _) (lexical foo _))
646 (primcall + (lexical bar _) (lexical bar _)))))
649 ;; Fresh objects are not turned into constants, nor are constants
650 ;; turned into fresh objects.
655 (let (x) (_) ((primcall cons (const 1) (const (2 3))))
656 (primcall cons (const 0) (lexical x _))))
663 (let (x) (_) ((const 2))
665 (set! (lexical x _) (const 3))
674 (frob f) ; may mutate `x'
676 (letrec (x) (_) ((const 0))
678 (call (toplevel frob) (lambda _ _))
683 (letrec ((f (lambda (x)
684 (set! f (lambda (_) x))
690 ;; Bindings possibly mutated.
691 (let ((x (make-foo)))
692 (frob! x) ; may mutate `x'
694 (let (x) (_) ((call (toplevel make-foo)))
696 (call (toplevel frob!) (lexical x _))
700 ;; Inlining stops at recursive calls with dynamic arguments.
702 (if (< x 0) x (loop (1- x))))
703 (letrec (loop) (_) ((lambda (_)
705 (((x) #f #f #f () (_))
707 (call (lexical loop _)
710 (call (lexical loop _) (toplevel x))))
713 ;; Recursion on the 2nd argument is fully evaluated.
715 (let loop ((x x) (y 10))
719 (let (x) (_) ((call (toplevel top)))
720 (call (toplevel foo) (lexical x _) (const 0))))
723 ;; Inlining aborted when residual code contains recursive calls.
725 ;; <http://debbugs.gnu.org/9542>
726 (let loop ((x x) (y 0))
731 (loop (1+ x) (1+ y)))))
732 (letrec (loop) (_) ((lambda (_)
734 (((x y) #f #f #f () (_ _))
736 (lexical y _) (const 0))
738 (call (lexical loop _) (toplevel x) (const 0))))
741 ;; Infinite recursion: `peval' gives up and leaves it as is.
742 (letrec ((f (lambda (x) (g (1- x))))
743 (g (lambda (x) (h (1+ x))))
744 (h (lambda (x) (f x))))
749 ;; Infinite recursion: all the arguments to `loop' are static, but
750 ;; unrolling it would lead `peval' to enter an infinite loop.
754 (letrec (loop) (_) ((lambda . _))
755 (call (lexical loop _) (const 0))))
758 ;; This test checks that the `start' binding is indeed residualized.
759 ;; See the `referenced?' procedure in peval's `prune-bindings'.
761 (let ((here (let ((start pos)) (lambda () start))))
762 (set! pos 1) ;; Cause references to `pos' to residualize.
764 (let (pos) (_) ((const 0))
767 (set! (lexical pos _) (const 1))
768 (call (lexical here _))))))
771 ;; FIXME: should this one residualize the binding?
777 ;; This is a fun one for peval to handle.
780 (letrec (a) (_) ((lexical a _))
784 ;; Another interesting recursive case.
785 (letrec ((a b) (b a))
787 (letrec (a) (_) ((lexical a _))
791 ;; Another pruning case, that `a' is residualized.
792 (letrec ((a (lambda () (a)))
798 ;; "b c a" is the current order that we get with unordered letrec,
799 ;; but it's not important to this test, so if it changes, just adapt
801 (letrec (b c a) (_ _ _)
805 (call (lexical a _)))))
808 (((x) #f #f #f () (_))
813 (call (lexical a _))))))
816 ((call (toplevel foo) (lexical b _)))
817 (call (lexical c _) (lexical d _)))))
820 ;; In this case, we can prune the bindings. `a' ends up being copied
821 ;; because it is only referenced once in the source program. Oh
823 (letrec* ((a (lambda (x) (top x)))
829 (((x) #f #f #f () (_))
830 (call (toplevel top) (lexical x _)))))
833 (((x) #f #f #f () (_))
834 (call (toplevel top) (lexical x _)))))))
837 ;; The inliner sees through a `let'.
838 ((let ((a 10)) (lambda (b) (* b 2))) 30)
843 (define (const x) (lambda (_) x))
849 ;; Applications of procedures with rest arguments can get inlined.
853 (let (z) (_) ((primcall list (const 3) (const 4)))
854 (primcall list (const 1) (const 2) (lexical z _))))
857 ;; Unmutated lists can get inlined.
858 (let ((args (list 2 3)))
859 (apply (lambda (x y z w)
862 (primcall list (const 0) (const 1) (const 2) (const 3)))
865 ;; However if the list might have been mutated, it doesn't propagate.
866 (let ((args (list 2 3)))
868 (apply (lambda (x y z w)
871 (let (args) (_) ((primcall list (const 2) (const 3)))
873 (call (toplevel foo!) (lexical args _))
877 (((x y z w) #f #f #f () (_ _ _ _))
879 (lexical x _) (lexical y _)
880 (lexical z _) (lexical w _)))))
886 ;; Here the `args' that gets built by the application of the lambda
887 ;; takes more than effort "10" to visit. Test that we fall back to
888 ;; the source expression of the operand, which is still a call to
889 ;; `list', so the inlining still happens.
890 (lambda (bv offset n)
891 (let ((x (bytevector-ieee-single-native-ref
894 (y (bytevector-ieee-single-native-ref
897 (let ((args (list x y)))
899 (lambda (bv offset x y)
900 (bytevector-ieee-single-native-set!
904 (bytevector-ieee-single-native-set!
913 (((bv offset n) #f #f #f () (_ _ _))
914 (let (x y) (_ _) ((primcall bytevector-ieee-single-native-ref
917 (lexical offset _) (const 0)))
918 (primcall bytevector-ieee-single-native-ref
921 (lexical offset _) (const 4))))
923 (primcall bytevector-ieee-single-native-set!
926 (lexical offset _) (const 0))
928 (primcall bytevector-ieee-single-native-set!
931 (lexical offset _) (const 4))
935 ;; Here we ensure that non-constant expressions are not copied.
937 (let ((args (list (foo!))))
941 ;; This toplevel ref might raise an unbound variable exception.
942 ;; The effects of `(foo!)' must be visible before this effect.
948 (let (_) (_) ((call (toplevel foo!)))
949 (let (z) (_) ((toplevel z))
955 ;; Rest args referenced more than once are not destructured.
957 (let ((args (list 'foo)))
968 ((primcall list (const foo)))
970 (primcall set-car! (lexical args _) (const bar))
974 (lexical args _))))))))
977 ;; Let-values inlining, even with consumers with rest args.
978 (call-with-values (lambda () (values 1 2))
981 (primcall list (const 1) (const 2)))
984 ;; When we can't inline let-values but can prove that the producer
985 ;; has just one value, reduce to "let" (which can then fold
987 (call-with-values (lambda () (if foo 1 2))
989 (apply values args)))
990 (if (toplevel foo) (const 1) (const 2)))
993 ;; Constant folding: cons of #nil does not make list
995 (primcall cons (const 1) (const '#nil)))
998 ;; Constant folding: cons
999 (begin (cons 1 2) #f)
1003 ;; Constant folding: cons
1004 (begin (cons (foo) 2) #f)
1005 (seq (call (toplevel foo)) (const #f)))
1008 ;; Constant folding: cons
1013 ;; Constant folding: car+cons
1018 ;; Constant folding: cdr+cons
1023 ;; Constant folding: car+cons, impure
1024 (car (cons 1 (bar)))
1025 (seq (call (toplevel bar)) (const 1)))
1028 ;; Constant folding: cdr+cons, impure
1029 (cdr (cons (bar) 0))
1030 (seq (call (toplevel bar)) (const 0)))
1033 ;; Constant folding: car+list
1038 ;; Constant folding: cdr+list
1040 (primcall list (const 0)))
1043 ;; Constant folding: car+list, impure
1044 (car (list 1 (bar)))
1045 (seq (call (toplevel bar)) (const 1)))
1048 ;; Constant folding: cdr+list, impure
1049 (cdr (list (bar) 0))
1050 (seq (call (toplevel bar)) (primcall list (const 0))))
1053 ;; Equality primitive: same lexical
1054 (let ((x (random))) (eq? x x))
1055 (seq (call (toplevel random)) (const #t)))
1058 ;; Equality primitive: merge lexical identities
1059 (let* ((x (random)) (y x)) (eq? x y))
1060 (seq (call (toplevel random)) (const #t)))
1063 ;; Non-constant guards get lexical bindings, invocation of winder and
1064 ;; unwinder lifted out. Unfortunately both have the generic variable
1065 ;; name "tmp", so we can't distinguish them in this test, and they
1066 ;; also collide in generic names with the single-value result from
1067 ;; the dynwind; alack.
1068 (dynamic-wind foo (lambda () bar) baz)
1069 (let (tmp tmp) (_ _) ((toplevel foo) (toplevel baz))
1070 (seq (seq (if (primcall thunk? (lexical tmp _))
1071 (call (lexical tmp _))
1072 (primcall scm-error . _))
1073 (primcall wind (lexical tmp _) (lexical tmp _)))
1074 (let (tmp) (_) ((toplevel bar))
1075 (seq (seq (primcall unwind)
1076 (call (lexical tmp _)))
1077 (lexical tmp _))))))
1080 ;; Constant guards don't need lexical bindings or thunk? checks.
1081 (dynamic-wind (lambda () foo) (lambda () bar) (lambda () baz))
1082 (seq (seq (toplevel foo)
1086 ((() #f #f #f () ()) (toplevel foo))))
1089 ((() #f #f #f () ()) (toplevel baz))))))
1090 (let (tmp) (_) ((toplevel bar))
1091 (seq (seq (primcall unwind)
1096 ;; Dynwind bodies that return an unknown number of values need a
1098 (dynamic-wind (lambda () foo) (lambda () (bar)) (lambda () baz))
1099 (seq (seq (toplevel foo)
1103 ((() #f #f #f () ()) (toplevel foo))))
1106 ((() #f #f #f () ()) (toplevel baz))))))
1107 (let-values (call (toplevel bar))
1109 ((() #f vals #f () (_))
1110 (seq (seq (primcall unwind)
1112 (primcall apply (primitive values) (lexical vals _))))))))
1115 ;; Prompt is removed if tag is unreferenced
1116 (let ((tag (make-prompt-tag)))
1117 (call-with-prompt tag
1119 (lambda args args)))
1123 ;; Prompt is removed if tag is unreferenced, with explicit stem
1124 (let ((tag (make-prompt-tag "foo")))
1125 (call-with-prompt tag
1127 (lambda args args)))
1130 ;; Handler lambda inlined
1132 (call-with-prompt tag
1140 (((k x) #f #f #f () (_ _))
1143 ;; Handler toplevel not inlined
1145 (call-with-prompt tag
1152 ((() #f #f #f () ())
1154 (toplevel handler)))
1157 ;; `while' without `break' or `continue' has no prompts and gets its
1158 ;; condition folded. Unfortunately the outer `lp' does not yet get
1159 ;; elided, and the continuation tag stays around. (The continue tag
1160 ;; stays around because although it is not referenced, recursively
1161 ;; visiting the loop in the continue handler manages to visit the tag
1162 ;; twice before aborting. The abort doesn't unroll the recursive
1165 (let (_) (_) ((primcall make-prompt-tag . _))
1169 ((() #f #f #f () ())
1173 ((() #f #f #f () ())
1174 (call (lexical loop _))))))
1175 (call (lexical loop _)))))))
1176 (call (lexical lp _)))))
1180 (apply (lambda (x y) (+ x y))
1184 (((x y) #f #f #f () (_ _))
1191 ;; If we bail out when inlining an identifier because it's too big,
1192 ;; but the identifier simply aliases some other identifier, then avoid
1193 ;; residualizing a reference to the leaf identifier. The bailout is
1194 ;; driven by the recursive-effort-limit, which is currently 100. We
1195 ;; make sure to trip it with this recursive sum thing.
1197 (let ((x (let sum ((n 0) (out 0))
1199 (sum (1+ n) (+ out n))
1201 ((lambda (y) (list y)) x))
1203 (primcall list (lexical x _))))
1205 ;; Here we test that a common test in a chain of ifs gets lifted.
1207 (if (and (struct? x) (eq? (struct-vtable x) A))
1209 (if (and (struct? x) (eq? (struct-vtable x) B))
1211 (if (and (struct? x) (eq? (struct-vtable x) C))
1214 (let (failure) (_) ((lambda _
1216 ((() #f #f #f () ())
1217 (call (toplevel qux) (toplevel x))))))
1218 (if (primcall struct? (toplevel x))
1220 (primcall struct-vtable (toplevel x))
1222 (call (toplevel foo) (toplevel x))
1224 (primcall struct-vtable (toplevel x))
1226 (call (toplevel bar) (toplevel x))
1228 (primcall struct-vtable (toplevel x))
1230 (call (toplevel baz) (toplevel x))
1231 (call (lexical failure _)))))
1232 (call (lexical failure _)))))
1234 ;; Multiple common tests should get lifted as well.
1236 (if (and (struct? x) (eq? (struct-vtable x) A) B)
1238 (if (and (struct? x) (eq? (struct-vtable x) A) C)
1240 (if (and (struct? x) (eq? (struct-vtable x) A) D)
1243 (let (failure) (_) ((lambda _
1245 ((() #f #f #f () ())
1246 (call (toplevel qux) (toplevel x))))))
1247 (if (primcall struct? (toplevel x))
1249 (primcall struct-vtable (toplevel x))
1252 (call (toplevel foo) (toplevel x))
1254 (call (toplevel bar) (toplevel x))
1256 (call (toplevel baz) (toplevel x))
1257 (call (lexical failure _)))))
1258 (call (lexical failure _)))
1259 (call (lexical failure _)))))
1262 (apply (lambda (x y) (cons x y)) '(1 2))
1263 (primcall cons (const 1) (const 2)))
1266 (apply (lambda (x y) (cons x y)) (list 1 2))
1267 (primcall cons (const 1) (const 2)))
1269 ;; Disable after removal of abort-in-tail-position optimization, in
1270 ;; hopes that CPS does a uniformly better job.
1273 (let ((t (make-prompt-tag)))
1275 (lambda () (abort-to-prompt t 1 2 3))
1276 (lambda (k x y z) (list x y z))))
1277 (primcall list (const 1) (const 2) (const 3)))
1280 (call-with-values foo (lambda (x) (bar x)))
1281 (let (x) (_) ((call (toplevel foo)))
1282 (call (toplevel bar) (lexical x _)))))