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 (rnrs bytevectors) ;; for the bytevector primitives
28 #:use-module (srfi srfi-13))
31 ;; The partial evaluator.
32 (@@ (language tree-il optimize) peval))
34 (define-syntax pass-if-peval
40 (compile 'in #:from 'scheme #:to 'tree-il)
44 (let ((evaled (unparse-tree-il (peval code))))
47 (_ (pk 'peval-mismatch)
48 ((@ (ice-9 pretty-print) pretty-print)
51 ((@ (ice-9 pretty-print) pretty-print)
54 ((@ (ice-9 pretty-print) pretty-print)
60 (with-test-prefix "partial evaluation"
63 ;; First order, primitive.
64 (let ((x 1) (y 2)) (+ x y))
68 ;; First order, thunk.
70 (let ((f (lambda () (+ x y))))
75 ;; First order, let-values (requires primitive expansion for
76 ;; `call-with-values'.)
79 (lambda () (if (zero? x) (values 1 2) (values 3 4)))
85 ;; First order, multiple values.
88 (primcall values (const 1) (const 2)))
91 ;; First order, multiple values truncated.
92 (let ((x (values 1 'a)) (y 2))
94 (primcall values (const 1) (const 2)))
97 ;; First order, multiple values truncated.
102 ;; First order, coalesced, mutability preserved.
103 (cons 0 (cons 1 (cons 2 (list 3 4 5))))
105 (const 0) (const 1) (const 2) (const 3) (const 4) (const 5)))
108 ;; First order, coalesced, immutability preserved.
109 (cons 0 (cons 1 (cons 2 '(3 4 5))))
110 (primcall cons (const 0)
111 (primcall cons (const 1)
112 (primcall cons (const 2)
115 ;; These two tests doesn't work any more because we changed the way we
116 ;; deal with constants -- now the algorithm will see a construction as
117 ;; being bound to the lexical, so it won't propagate it. It can't
118 ;; even propagate it in the case that it is only referenced once,
121 ;; (let ((x (cons 1 2))) (lambda () x))
123 ;; is not the same as
125 ;; (lambda () (cons 1 2))
127 ;; Perhaps if we determined that not only was it only referenced once,
128 ;; it was not closed over by a lambda, then we could propagate it, and
129 ;; re-enable these two tests.
133 ;; First order, mutability preserved.
134 (let loop ((i 3) (r '()))
137 (loop (1- i) (cons (cons i i) r))))
139 (primcall cons (const 1) (const 1))
140 (primcall cons (const 2) (const 2))
141 (primcall cons (const 3) (const 3))))
146 ;; First order, evaluated.
151 (loop (1- i) (cons i r))))
154 ;; Instead here are tests for what happens for the above cases: they
155 ;; unroll but they don't fold.
157 (let loop ((i 3) (r '()))
160 (loop (1- i) (cons (cons i i) r))))
163 (primcall cons (const 3) (const 3))))
166 (primcall cons (const 2) (const 2))
169 (primcall cons (const 1) (const 1))
178 (loop (1- i) (cons i r))))
180 ((primcall list (const 4)))
198 (let loop ((l '(1 2 3 4)) (sum 0))
201 (loop (cdr l) (+ sum (car l)))))
216 (string->chars "yo"))
217 (primcall list (const #\y) (const #\o)))
220 ;; Primitives in module-refs are resolved (the expansion of `pmatch'
221 ;; below leads to calls to (@@ (system base pmatch) car) and
222 ;; similar, which is what we want to be inlined.)
224 (use-modules (system base pmatch))
232 ;; Mutability preserved.
233 ((lambda (x y z) (list x y z)) 1 2 3)
234 (primcall list (const 1) (const 2) (const 3)))
237 ;; Don't propagate effect-free expressions that operate on mutable
243 (let (x) (_) ((primcall list (const 1)))
244 (let (y) (_) ((primcall car (lexical x _)))
246 (primcall set-car! (lexical x _) (const 0))
250 ;; Don't propagate effect-free expressions that operate on objects we
255 (let (y) (_) ((primcall car (toplevel x)))
257 (primcall set-car! (toplevel x) (const 0))
261 ;; Infinite recursion
262 ((lambda (x) (x x)) (lambda (x) (x x)))
267 (call (lexical x _) (lexical x _))))))
268 (call (lexical x _) (lexical x _))))
271 ;; First order, aliased primitive.
272 (let* ((x *) (y (x 1 2))) y)
276 ;; First order, shadowed primitive.
278 (define (+ x y) (pk x y))
284 (((x y) #f #f #f () (_ _))
285 (call (toplevel pk) (lexical x _) (lexical y _))))))
286 (call (toplevel +) (const 1) (const 2))))
289 ;; First-order, effects preserved.
294 (call (toplevel do-something!))
298 ;; First order, residual bindings removed.
301 (primcall * (const 5) (toplevel z)))
304 ;; First order, with lambda.
306 (define (bar z) (* z z))
311 (((x) #f #f #f () (_))
312 (primcall + (lexical x _) (const 9)))))))
315 ;; First order, with lambda inlined & specialized twice.
316 (let ((f (lambda (x y)
325 (primcall + ; (f 2 3)
330 (let (x) (_) ((toplevel something)) ; (f something 2)
331 ;; `something' is not const, so preserve order of
332 ;; effects with a lexical binding.
340 ;; First order, with lambda inlined & specialized 3 times.
341 (let ((f (lambda (x y) (if (> x 0) y x))))
353 (const -1) ; (f -1 0)
354 (seq (toplevel y) (const -1))) ; (f -1 y)
355 (toplevel y)) ; (f 2 y)
356 (let (x y) (_ _) ((toplevel z) (toplevel y)) ; (f z y)
357 (if (primcall > (lexical x _) (const 0))
362 ;; First order, conditional.
370 (((x) #f #f #f () (_))
371 (call (toplevel display) (lexical x _))))))
374 ;; First order, recursive procedure.
375 (letrec ((fibo (lambda (n)
384 ;; Don't propagate toplevel references, as intervening expressions
385 ;; could alter their bindings.
389 (let (x) (_) ((toplevel top))
391 (call (toplevel foo))
397 (f (* (car x) (cadr x))))
404 ;; Higher order with optional argument (default value).
405 ((lambda* (f x #:optional (y 0))
406 (+ y (f (* (car x) (cadr x)))))
413 ;; Higher order with optional argument (caller-supplied value).
414 ((lambda* (f x #:optional (y 0))
415 (+ y (f (* (car x) (cadr x)))))
423 ;; Higher order with optional argument (side-effecting default
425 ((lambda* (f x #:optional (y (foo)))
426 (+ y (f (* (car x) (cadr x)))))
430 (let (y) (_) ((call (toplevel foo)))
431 (primcall + (lexical y _) (const 7))))
434 ;; Higher order with optional argument (caller-supplied value).
435 ((lambda* (f x #:optional (y (foo)))
436 (+ y (f (* (car x) (cadr x)))))
445 ((lambda (f) (f x)) (lambda (x) x))
450 ;; <https://lists.gnu.org/archive/html/bug-guile/2011-09/msg00019.html>.
451 (let ((fold (lambda (f g) (f (g top)))))
452 (fold 1+ (lambda (x) x)))
453 (primcall 1+ (toplevel top)))
456 ;; Procedure not inlined when residual code contains recursive calls.
457 ;; <http://debbugs.gnu.org/9542>
458 (letrec ((fold (lambda (f x3 b null? car cdr)
461 (f (car x3) (fold f (cdr x3) b null? car cdr))))))
462 (fold * x 1 zero? (lambda (x1) x1) (lambda (x2) (- x2 1))))
463 (letrec (fold) (_) (_)
464 (call (lexical fold _)
471 (((x1) #f #f #f () (_))
475 (((x2) #f #f #f () (_))
476 (primcall 1- (lexical x2 _))))))))
478 (pass-if "inlined lambdas are alpha-renamed"
479 ;; In this example, `make-adder' is inlined more than once; thus,
480 ;; they should use different gensyms for their arguments, because
481 ;; the various optimization passes assume uniquely-named variables.
484 ;; <https://lists.gnu.org/archive/html/bug-guile/2011-09/msg00019.html> and
485 ;; <https://lists.gnu.org/archive/html/bug-guile/2011-09/msg00029.html>.
486 (pmatch (unparse-tree-il
487 (peval (expand-primitives
491 (lambda (x) (lambda (y) (+ x y)))))
492 (cons (make-adder 1) (make-adder 2)))
498 (((y) #f #f #f () (,gensym1))
501 (lexical y ,ref1)))))
504 (((y) #f #f #f () (,gensym2))
507 (lexical y ,ref2))))))
508 (and (eq? gensym1 ref1)
510 (not (eq? gensym1 gensym2))))
514 ;; Unused letrec bindings are pruned.
515 (letrec ((a (lambda () (b)))
522 ;; Unused letrec bindings are pruned.
527 (seq (call (toplevel foo!))
531 ;; Higher order, mutually recursive procedures.
532 (letrec ((even? (lambda (x)
537 (and (even? 4) (odd? 7)))
541 ;; Memv with constants.
546 ;; Memv with non-constant list. It could fold but doesn't
548 (memv 1 (list 3 2 1))
551 (primcall list (const 3) (const 2) (const 1))))
554 ;; Memv with non-constant key, constant list, test context
558 (let (key) (_) ((toplevel foo))
559 (if (if (primcall eqv? (lexical key _) (const 3))
561 (if (primcall eqv? (lexical key _) (const 2))
563 (primcall eqv? (lexical key _) (const 1))))
568 ;; Memv with non-constant key, empty list, test context.
572 (seq (toplevel foo) (const 'b)))
575 ;; Below are cases where constant propagation should bail out.
579 ;; Non-constant lexical is not propagated.
580 (let ((v (make-vector 6 #f)))
582 (vector-set! v n n)))
584 ((primcall make-vector (const 6) (const #f)))
587 (((n) #f #f #f () (_))
588 (primcall vector-set!
589 (lexical v _) (lexical n _) (lexical n _)))))))
592 ;; Mutable lexical is not propagated.
593 (let ((v (vector 1 2 3)))
597 ((primcall vector (const 1) (const 2) (const 3)))
604 ;; Lexical that is not provably pure is not inlined nor propagated.
605 (let* ((x (if (> p q) (frob!) (display 'chbouib)))
608 (let (x) (_) ((if (primcall > (toplevel p) (toplevel q))
609 (call (toplevel frob!))
610 (call (toplevel display) (const chbouib))))
611 (let (y) (_) ((primcall * (lexical x _) (const 2)))
613 (primcall + (lexical x _) (lexical x _))
617 ;; Non-constant arguments not propagated to lambdas.
626 ((primcall vector (const 1) (const 2) (const 3))
627 (call (toplevel make-list) (const 10))
628 (primcall list (const 1) (const 2) (const 3)))
630 (primcall vector-set!
631 (lexical x _) (const 0) (const 0))
632 (seq (primcall set-car!
633 (lexical y _) (const 0))
635 (lexical z _) (const ()))))))
638 (let ((foo top-foo) (bar top-bar))
639 (let* ((g (lambda (x y) (+ x y)))
640 (f (lambda (g x) (g x x))))
641 (+ (f g foo) (f g bar))))
642 (let (foo bar) (_ _) ((toplevel top-foo) (toplevel top-bar))
644 (primcall + (lexical foo _) (lexical foo _))
645 (primcall + (lexical bar _) (lexical bar _)))))
648 ;; Fresh objects are not turned into constants, nor are constants
649 ;; turned into fresh objects.
654 (let (x) (_) ((primcall cons (const 1) (const (2 3))))
655 (primcall cons (const 0) (lexical x _))))
662 (let (x) (_) ((const 2))
664 (set! (lexical x _) (const 3))
673 (frob f) ; may mutate `x'
675 (letrec (x) (_) ((const 0))
677 (call (toplevel frob) (lambda _ _))
682 (letrec ((f (lambda (x)
683 (set! f (lambda (_) x))
689 ;; Bindings possibly mutated.
690 (let ((x (make-foo)))
691 (frob! x) ; may mutate `x'
693 (let (x) (_) ((call (toplevel make-foo)))
695 (call (toplevel frob!) (lexical x _))
699 ;; Inlining stops at recursive calls with dynamic arguments.
701 (if (< x 0) x (loop (1- x))))
702 (letrec (loop) (_) ((lambda (_)
704 (((x) #f #f #f () (_))
706 (call (lexical loop _)
709 (call (lexical loop _) (toplevel x))))
712 ;; Recursion on the 2nd argument is fully evaluated.
714 (let loop ((x x) (y 10))
718 (let (x) (_) ((call (toplevel top)))
719 (call (toplevel foo) (lexical x _) (const 0))))
722 ;; Inlining aborted when residual code contains recursive calls.
724 ;; <http://debbugs.gnu.org/9542>
725 (let loop ((x x) (y 0))
730 (loop (1+ x) (1+ y)))))
731 (letrec (loop) (_) ((lambda (_)
733 (((x y) #f #f #f () (_ _))
735 (lexical y _) (const 0))
737 (call (lexical loop _) (toplevel x) (const 0))))
740 ;; Infinite recursion: `peval' gives up and leaves it as is.
741 (letrec ((f (lambda (x) (g (1- x))))
742 (g (lambda (x) (h (1+ x))))
743 (h (lambda (x) (f x))))
748 ;; Infinite recursion: all the arguments to `loop' are static, but
749 ;; unrolling it would lead `peval' to enter an infinite loop.
753 (letrec (loop) (_) ((lambda . _))
754 (call (lexical loop _) (const 0))))
757 ;; This test checks that the `start' binding is indeed residualized.
758 ;; See the `referenced?' procedure in peval's `prune-bindings'.
760 (let ((here (let ((start pos)) (lambda () start))))
761 (set! pos 1) ;; Cause references to `pos' to residualize.
763 (let (pos) (_) ((const 0))
766 (set! (lexical pos _) (const 1))
767 (call (lexical here _))))))
770 ;; FIXME: should this one residualize the binding?
776 ;; This is a fun one for peval to handle.
779 (letrec (a) (_) ((lexical a _))
783 ;; Another interesting recursive case.
784 (letrec ((a b) (b a))
786 (letrec (a) (_) ((lexical a _))
790 ;; Another pruning case, that `a' is residualized.
791 (letrec ((a (lambda () (a)))
797 ;; "b c a" is the current order that we get with unordered letrec,
798 ;; but it's not important to this test, so if it changes, just adapt
800 (letrec (b c a) (_ _ _)
804 (call (lexical a _)))))
807 (((x) #f #f #f () (_))
812 (call (lexical a _))))))
815 ((call (toplevel foo) (lexical b _)))
816 (call (lexical c _) (lexical d _)))))
819 ;; In this case, we can prune the bindings. `a' ends up being copied
820 ;; because it is only referenced once in the source program. Oh
822 (letrec* ((a (lambda (x) (top x)))
828 (((x) #f #f #f () (_))
829 (call (toplevel top) (lexical x _)))))
832 (((x) #f #f #f () (_))
833 (call (toplevel top) (lexical x _)))))))
836 ;; The inliner sees through a `let'.
837 ((let ((a 10)) (lambda (b) (* b 2))) 30)
842 (define (const x) (lambda (_) x))
848 ;; Applications of procedures with rest arguments can get inlined.
852 (let (z) (_) ((primcall list (const 3) (const 4)))
853 (primcall list (const 1) (const 2) (lexical z _))))
856 ;; Unmutated lists can get inlined.
857 (let ((args (list 2 3)))
858 (apply (lambda (x y z w)
861 (primcall list (const 0) (const 1) (const 2) (const 3)))
864 ;; However if the list might have been mutated, it doesn't propagate.
865 (let ((args (list 2 3)))
867 (apply (lambda (x y z w)
870 (let (args) (_) ((primcall list (const 2) (const 3)))
872 (call (toplevel foo!) (lexical args _))
876 (((x y z w) #f #f #f () (_ _ _ _))
878 (lexical x _) (lexical y _)
879 (lexical z _) (lexical w _)))))
885 ;; Here the `args' that gets built by the application of the lambda
886 ;; takes more than effort "10" to visit. Test that we fall back to
887 ;; the source expression of the operand, which is still a call to
888 ;; `list', so the inlining still happens.
889 (lambda (bv offset n)
890 (let ((x (bytevector-ieee-single-native-ref
893 (y (bytevector-ieee-single-native-ref
896 (let ((args (list x y)))
898 (lambda (bv offset x y)
899 (bytevector-ieee-single-native-set!
903 (bytevector-ieee-single-native-set!
912 (((bv offset n) #f #f #f () (_ _ _))
913 (let (x y) (_ _) ((primcall bytevector-ieee-single-native-ref
916 (lexical offset _) (const 0)))
917 (primcall bytevector-ieee-single-native-ref
920 (lexical offset _) (const 4))))
922 (primcall bytevector-ieee-single-native-set!
925 (lexical offset _) (const 0))
927 (primcall bytevector-ieee-single-native-set!
930 (lexical offset _) (const 4))
934 ;; Here we ensure that non-constant expressions are not copied.
936 (let ((args (list (foo!))))
940 ;; This toplevel ref might raise an unbound variable exception.
941 ;; The effects of `(foo!)' must be visible before this effect.
947 (let (_) (_) ((call (toplevel foo!)))
948 (let (z) (_) ((toplevel z))
954 ;; Rest args referenced more than once are not destructured.
956 (let ((args (list 'foo)))
967 ((primcall list (const foo)))
969 (primcall set-car! (lexical args _) (const bar))
973 (lexical args _))))))))
976 ;; Let-values inlining, even with consumers with rest args.
977 (call-with-values (lambda () (values 1 2))
980 (primcall list (const 1) (const 2)))
983 ;; When we can't inline let-values but can prove that the producer
984 ;; has just one value, reduce to "let" (which can then fold
986 (call-with-values (lambda () (if foo 1 2))
988 (apply values args)))
989 (if (toplevel foo) (const 1) (const 2)))
992 ;; Constant folding: cons of #nil does not make list
994 (primcall cons (const 1) (const '#nil)))
997 ;; Constant folding: cons
998 (begin (cons 1 2) #f)
1002 ;; Constant folding: cons
1003 (begin (cons (foo) 2) #f)
1004 (seq (call (toplevel foo)) (const #f)))
1007 ;; Constant folding: cons
1012 ;; Constant folding: car+cons
1017 ;; Constant folding: cdr+cons
1022 ;; Constant folding: car+cons, impure
1023 (car (cons 1 (bar)))
1024 (seq (call (toplevel bar)) (const 1)))
1027 ;; Constant folding: cdr+cons, impure
1028 (cdr (cons (bar) 0))
1029 (seq (call (toplevel bar)) (const 0)))
1032 ;; Constant folding: car+list
1037 ;; Constant folding: cdr+list
1039 (primcall list (const 0)))
1042 ;; Constant folding: car+list, impure
1043 (car (list 1 (bar)))
1044 (seq (call (toplevel bar)) (const 1)))
1047 ;; Constant folding: cdr+list, impure
1048 (cdr (list (bar) 0))
1049 (seq (call (toplevel bar)) (primcall list (const 0))))
1052 ;; Equality primitive: same lexical
1053 (let ((x (random))) (eq? x x))
1054 (seq (call (toplevel random)) (const #t)))
1057 ;; Equality primitive: merge lexical identities
1058 (let* ((x (random)) (y x)) (eq? x y))
1059 (seq (call (toplevel random)) (const #t)))
1062 ;; Non-constant guards get lexical bindings, invocation of winder and
1063 ;; unwinder lifted out. Unfortunately both have the generic variable
1064 ;; name "tmp", so we can't distinguish them in this test, and they
1065 ;; also collide in generic names with the single-value result from
1066 ;; the dynwind; alack.
1067 (dynamic-wind foo (lambda () bar) baz)
1068 (let (tmp tmp) (_ _) ((toplevel foo) (toplevel baz))
1069 (seq (seq (if (primcall thunk? (lexical tmp _))
1070 (call (lexical tmp _))
1071 (primcall scm-error . _))
1072 (primcall wind (lexical tmp _) (lexical tmp _)))
1073 (let (tmp) (_) ((toplevel bar))
1074 (seq (seq (primcall unwind)
1075 (call (lexical tmp _)))
1076 (lexical tmp _))))))
1079 ;; Constant guards don't need lexical bindings or thunk? checks.
1080 (dynamic-wind (lambda () foo) (lambda () bar) (lambda () baz))
1081 (seq (seq (toplevel foo)
1085 ((() #f #f #f () ()) (toplevel foo))))
1088 ((() #f #f #f () ()) (toplevel baz))))))
1089 (let (tmp) (_) ((toplevel bar))
1090 (seq (seq (primcall unwind)
1095 ;; Dynwind bodies that return an unknown number of values need a
1097 (dynamic-wind (lambda () foo) (lambda () (bar)) (lambda () baz))
1098 (seq (seq (toplevel foo)
1102 ((() #f #f #f () ()) (toplevel foo))))
1105 ((() #f #f #f () ()) (toplevel baz))))))
1106 (let-values (call (toplevel bar))
1108 ((() #f vals #f () (_))
1109 (seq (seq (primcall unwind)
1111 (primcall apply (primitive values) (lexical vals _))))))))
1114 ;; Prompt is removed if tag is unreferenced
1115 (let ((tag (make-prompt-tag)))
1116 (call-with-prompt tag
1118 (lambda args args)))
1122 ;; Prompt is removed if tag is unreferenced, with explicit stem
1123 (let ((tag (make-prompt-tag "foo")))
1124 (call-with-prompt tag
1126 (lambda args args)))
1129 ;; Handler lambda inlined
1131 (call-with-prompt tag
1139 (((k x) #f #f #f () (_ _))
1142 ;; Handler toplevel not inlined
1144 (call-with-prompt tag
1151 ((() #f #f #f () ())
1153 (toplevel handler)))
1156 ;; `while' without `break' or `continue' has no prompts and gets its
1157 ;; condition folded. Unfortunately the outer `lp' does not yet get
1158 ;; elided, and the continuation tag stays around. (The continue tag
1159 ;; stays around because although it is not referenced, recursively
1160 ;; visiting the loop in the continue handler manages to visit the tag
1161 ;; twice before aborting. The abort doesn't unroll the recursive
1164 (let (_) (_) ((primcall make-prompt-tag . _))
1168 ((() #f #f #f () ())
1172 ((() #f #f #f () ())
1173 (call (lexical loop _))))))
1174 (call (lexical loop _)))))))
1175 (call (lexical lp _)))))
1179 (apply (lambda (x y) (+ x y))
1183 (((x y) #f #f #f () (_ _))
1190 ;; If we bail out when inlining an identifier because it's too big,
1191 ;; but the identifier simply aliases some other identifier, then avoid
1192 ;; residualizing a reference to the leaf identifier. The bailout is
1193 ;; driven by the recursive-effort-limit, which is currently 100. We
1194 ;; make sure to trip it with this recursive sum thing.
1196 (let ((x (let sum ((n 0) (out 0))
1198 (sum (1+ n) (+ out n))
1200 ((lambda (y) (list y)) x))
1202 (primcall list (lexical x _))))
1204 ;; Here we test that a common test in a chain of ifs gets lifted.
1206 (if (and (struct? x) (eq? (struct-vtable x) A))
1208 (if (and (struct? x) (eq? (struct-vtable x) B))
1210 (if (and (struct? x) (eq? (struct-vtable x) C))
1213 (let (failure) (_) ((lambda _
1215 ((() #f #f #f () ())
1216 (call (toplevel qux) (toplevel x))))))
1217 (if (primcall struct? (toplevel x))
1219 (primcall struct-vtable (toplevel x))
1221 (call (toplevel foo) (toplevel x))
1223 (primcall struct-vtable (toplevel x))
1225 (call (toplevel bar) (toplevel x))
1227 (primcall struct-vtable (toplevel x))
1229 (call (toplevel baz) (toplevel x))
1230 (call (lexical failure _)))))
1231 (call (lexical failure _)))))
1233 ;; Multiple common tests should get lifted as well.
1235 (if (and (struct? x) (eq? (struct-vtable x) A) B)
1237 (if (and (struct? x) (eq? (struct-vtable x) A) C)
1239 (if (and (struct? x) (eq? (struct-vtable x) A) D)
1242 (let (failure) (_) ((lambda _
1244 ((() #f #f #f () ())
1245 (call (toplevel qux) (toplevel x))))))
1246 (if (primcall struct? (toplevel x))
1248 (primcall struct-vtable (toplevel x))
1251 (call (toplevel foo) (toplevel x))
1253 (call (toplevel bar) (toplevel x))
1255 (call (toplevel baz) (toplevel x))
1256 (call (lexical failure _)))))
1257 (call (lexical failure _)))
1258 (call (lexical failure _)))))
1261 (apply (lambda (x y) (cons x y)) '(1 2))
1262 (primcall cons (const 1) (const 2)))
1265 (apply (lambda (x y) (cons x y)) (list 1 2))
1266 (primcall cons (const 1) (const 2)))
1268 ;; Disable after removal of abort-in-tail-position optimization, in
1269 ;; hopes that CPS does a uniformly better job.
1272 (let ((t (make-prompt-tag)))
1274 (lambda () (abort-to-prompt t 1 2 3))
1275 (lambda (k x y z) (list x y z))))
1276 (primcall list (const 1) (const 2) (const 3)))
1279 (call-with-values foo (lambda (x) (bar x)))
1280 (let (x) (_) ((call (toplevel foo)))
1281 (call (toplevel bar) (lexical x _))))
1285 (define* (bar a #:optional (b (1+ a)))
1289 (primcall list (const 1) (const 2))))