1 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; The software is in the public domain and is provided with
5 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
8 (defpackage :sb-cltl2-tests
9 (:use :sb-cltl2 :cl :sb-rt))
11 (in-package :sb-cltl2-tests)
15 (defmacro *x*-value ()
16 (declare (special *x*))
19 (deftest compiler-let.1
21 (compiler-let ((*x* :inner))
22 (list *x* (*x*-value))))
25 (defvar *expansions* nil)
26 (defmacro macroexpand-macro (arg)
27 (push arg *expansions*)
30 (deftest macroexpand-all.1
32 (macroexpand-all '(defmethod foo ((x fixnum)) (1+ x)))
36 (deftest macroexpand-all.2
37 (let ((*expansions* nil))
38 (macroexpand-all '(list (macroexpand-macro 1)
39 (let (macroexpand-macro :no)
40 (macroexpand-macro 2))))
41 (remove-duplicates (sort *expansions* #'<)))
44 (deftest macroexpand-all.3
45 (let ((*expansions* nil))
46 (compile nil '(lambda ()
47 (macrolet ((foo (key &environment env)
48 (macroexpand-all `(bar ,key) env)))
51 (push key *expansions*)
54 (remove-duplicates *expansions*))
58 (multiple-value-bind (expansion macro-p)
59 (macroexpand 'srlt env)
60 (when macro-p (eval expansion))))
61 (defmacro testr (&environment env)
62 `',(getf (smv env) nil))
64 (deftest macroexpand-all.4
65 (macroexpand-all '(symbol-macrolet ((srlt '(nil zool))) (testr)))
66 (symbol-macrolet ((srlt '(nil zool))) 'zool))
68 (defmacro dinfo (thing &environment env)
69 `',(declaration-information thing env))
72 `(macrolet ((frob (suffix answer &optional declaration)
73 `(deftest ,(intern (concatenate 'string
74 "DECLARATION-INFORMATION."
77 (locally (declare ,@(when declaration
79 (cadr (assoc ',',x (dinfo optimize))))
82 (frob ".0" 0 (optimize (,x 0)))
83 (frob ".1" 1 (optimize (,x 1)))
84 (frob ".2" 2 (optimize (,x 2)))
85 (frob ".3" 3 (optimize (,x 3)))
86 (frob ".IMPLICIT" 3 (optimize ,x)))))
90 (def compilation-speed)
93 (deftest declaration-information.muffle-conditions.default
94 (dinfo sb-ext:muffle-conditions)
96 (deftest declaration-information.muffle-conditions.1
97 (locally (declare (sb-ext:muffle-conditions warning))
98 (dinfo sb-ext:muffle-conditions))
100 (deftest declaration-information.muffle-conditions.2
101 (let ((junk (dinfo sb-ext:muffle-conditions)))
102 (declare (sb-ext:muffle-conditions warning))
103 (locally (declare (sb-ext:unmuffle-conditions style-warning))
104 (let ((dinfo (dinfo sb-ext:muffle-conditions)))
107 (and (subtypep dinfo `(or (and warning (not style-warning))
108 (and ,junk (not style-warning))))
109 (subtypep '(and warning (not style-warning)) dinfo)))))))
112 ;;;; VARIABLE-INFORMATION
116 (defmacro var-info (var &environment env)
117 (list 'quote (multiple-value-list (variable-information var env))))
119 (deftest variable-info.global-special/unbound
123 (deftest variable-info.global-special/unbound/extra-decl
124 (locally (declare (special *foo*))
128 (deftest variable-info.global-special/bound
133 (deftest variable-info.global-special/bound/extra-decl
135 (declare (special *foo*))
139 (deftest variable-info.local-special/unbound
140 (locally (declare (special x))
144 (deftest variable-info.local-special/bound
146 (declare (special x))
150 (deftest variable-info.local-special/shadowed
152 (declare (special x))
159 (deftest variable-info.local-special/shadows-lexical
162 (declare (special x))
166 (deftest variable-info.lexical
171 (deftest variable-info.lexical.type
175 (:lexical t ((type . fixnum))))
177 (deftest variable-info.lexical.type.2
181 (locally (declare (fixnum x))
182 (assert (plusp x)))))
185 (deftest variable-info.lexical.type.2
187 (locally (declare (fixnum x))
189 (:lexical t ((type . fixnum))))
191 (deftest variable-info.ignore
195 (:lexical t ((ignore . t))))
197 (deftest variable-info.symbol-macro/local
198 (symbol-macrolet ((x 8))
200 (:symbol-macro t nil))
202 (define-symbol-macro my-symbol-macro t)
204 (deftest variable-info.symbol-macro/global
205 (var-info my-symbol-macro)
206 (:symbol-macro nil nil))
208 (deftest variable-info.undefined
209 (var-info #:undefined)
212 ;;;; FUNCTION-INFORMATION
214 (defmacro fun-info (var &environment env)
215 (list 'quote (multiple-value-list (function-information var env))))
217 (defun my-global-fun (x) x)
219 (deftest function-info.global/no-ftype
220 (fun-info my-global-fun)
223 (declaim (ftype (function (cons) (values t &optional)) my-global-fun-2))
225 (defun my-global-fun-2 (x) x)
227 (deftest function-info.global/ftype
228 (fun-info my-global-fun-2)
229 (:function nil ((ftype function (cons) (values t &optional)))))
231 (defmacro my-macro (x) x)
233 (deftest function-info.macro
237 (deftest function-info.macrolet
238 (macrolet ((thingy () nil))
242 (deftest function-info.special-form
244 (:special-form nil nil))
246 (deftest function-info.notinline/local
248 (declare (notinline x))
251 (:function t ((inline . notinline))))
253 (declaim (notinline my-notinline))
254 (defun my-notinline (x) x)
256 (deftest function-info.notinline/global
257 (fun-info my-notinline)
258 (:function nil ((inline . notinline))))
260 (declaim (inline my-inline))
261 (defun my-inline (x) x)
263 (deftest function-info.inline/global
265 (:function nil ((inline . inline))))
267 (deftest function-information.known-inline
268 (locally (declare (inline identity))
270 (:function nil ((inline . inline)
271 (ftype function (t) (values t &optional)))))