1 ;;;; various compiler tests without side effects
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
14 ;;;; This file of tests was added because the tests in 'compiler.pure.lisp'
15 ;;;; are a total hodgepodge- there is often no hugely compelling reason for
16 ;;;; their being tests of the compiler per se, such as whether
17 ;;;; INPUT-ERROR-IN-COMPILED-FILE is a subclass of SERIOUS-CONDITION;
18 ;;;; in addition to which it is near impossible to wade through the
19 ;;;; ton of nameless, slow, and noisy tests.
21 ;;;; This file strives to do better on all fronts:
22 ;;;; the tests should be fast, named, and not noisy.
24 (cl:in-package
:cl-user
)
26 (load "compiler-test-util.lisp")
28 (with-test (:name
:ldb-recognize-local-macros
)
29 ;; Should not call %LDB
30 (assert (not (ctu:find-named-callees
33 (declare (optimize speed
))
34 (macrolet ((b () '(byte 2 2)))
35 (ldb (b) (the fixnum x
)))))))))
38 (with-test (:name
:dbp-eval-order
)
39 (sb-int:collect
((calls))
41 (dpb (progn (calls 'eval-new
) new
)
42 (progn (calls 'eval-byte
) (byte 10 10))
43 (progn (calls 'eval-old
) old
))))
45 (assert (equal (calls)
46 '(eval-new eval-byte eval-old
))))))
48 ;; Best practice treats TRULY-THE as a special operator, not a macro,
49 ;; in a context such as (DPB X (TRULY-THE SB-KERNEL:BYTE-SPECIFIER ...) Y).
50 ;; DPB used to expand its second argument using MACROEXPAND and lose
51 ;; the nuance of TRULY-THE. Strictly speaking, byte-specifier is not a
52 ;; type specifier that users are supposed to know about, so portable code
53 ;; should not care, but this might affect internal code.
54 (with-test (:name
:dpb-inner-macro
)
55 (flet ((source-xform (sexpr)
56 (funcall (sb-int:info
:function
:source-transform
(car sexpr
))
57 sexpr
(sb-kernel:make-null-lexenv
))))
58 (assert (equal-mod-gensyms
60 '(dpb (new) (truly-the sb-kernel
:byte-specifier bspec
) (old)))
62 (byte (truly-the sb-kernel
:byte-specifier bspec
)))
63 (sb-kernel:%dpb new
(byte-size byte
) (byte-position byte
)
66 (with-test (:name
:inline-satisfies-predicate
)
67 ;; If we remove the indirections in these functions,
68 ;; this test should visibly break so that we can write a new test
69 ;; that asserts that inlining F works in (THE (SATISFIES F) obj).
70 (assert (equal (sb-ext:typexpand
'sb-impl
::function-name
)
71 '(satisfies sb-int
:legal-fun-name-p
)))
72 (let ((f (compile nil
'(lambda (x) (the sb-impl
::function-name x
)))))
73 (assert (equal (list (symbol-function 'sb-int
:valid-function-name-p
))
74 (ctu:find-named-callees f
))))
75 (let ((f (compile nil
'(lambda (x)
76 (declare (notinline sb-int
:legal-fun-name-p
))
77 (the sb-impl
::function-name x
)))))
78 (assert (equal (list (symbol-function 'sb-int
:legal-fun-name-p
))
79 (ctu:find-named-callees f
)))))
81 (with-test (:name
:make-array-untestable-type-no-warning
)
83 (compile nil
`(lambda () (make-array '(2 2)
84 :element-type
`(satisfies foofa
))))))
86 (with-test (:name
:make-array-nil-no-warning
)
88 (compile nil
'(lambda () (make-array '(2 2) :element-type nil
)))))
90 (with-test (:name
:nth-value-huge-n-works
)
91 (flet ((return-a-ton-of-values ()
92 (values-list (loop for i below
5000 collect i
))))
93 (assert (= (nth-value 1 (return-a-ton-of-values)) 1))
94 (assert (= (nth-value 4000 (return-a-ton-of-values)) 4000))))
96 (defstruct (a-test-structure-foo
97 (:constructor make-a-foo-1
)
98 (:constructor make-a-foo-2
(b &optional a
)))
100 (b nil
:type integer
))
102 (with-test (:name
:improperly-initialized-slot-warns
)
103 (with-open-stream (*error-output
* (make-broadcast-stream))
104 (multiple-value-bind (f warn err
)
105 (compile nil
'(lambda () (make-a-foo-1 :a
'what
)))
106 ;; should warn because B's default is NIL, not an integer.
107 (assert (and f warn err
)))
108 (multiple-value-bind (f warn err
)
109 (compile nil
'(lambda () (make-a-foo-2 3)))
110 ;; should warn because A's default is 0
111 (assert (and f warn err
)))))
113 (with-test (:name
:inline-structure-ctor-no-declaim
)
114 (let ((f (compile nil
116 (make-a-foo-1 :a
'wat
:b
3)))))
117 (assert (ctu:find-named-callees f
)))
118 (let ((f (compile nil
120 (declare (inline make-a-foo-1
))
121 (make-a-foo-1 :a
'wat
:b
3)))))
122 (assert (not (ctu:find-named-callees f
)))))