File: error-source-path.impure.lisp

package info (click to toggle)
sbcl 2%3A2.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 52,008 kB
  • sloc: lisp: 535,135; ansic: 42,629; sh: 5,737; asm: 2,406; pascal: 717; makefile: 432; python: 56; cpp: 27
file content (363 lines) | stat: -rw-r--r-- 10,569 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
;;;; This software is part of the SBCL system. See the README file for
;;;; more information.
;;;;
;;;; While most of SBCL is derived from the CMU CL system, the test
;;;; files (like this one) were written from scratch after the fork
;;;; from CMU CL.
;;;;
;;;; This software is in the public domain and is provided with
;;;; absolutely no warranty. See the COPYING and CREDITS files for
;;;; more information.


;;; Utilities

(defmacro assert-condition-source-paths (form &rest source-paths)
  `(assert (equal (checked-compile-condition-source-paths
                   '(lambda () ,form))
                  (mapcar (lambda (path)
                            (append path '(2 0)))
                          '(,@source-paths)))))

(defmacro warning-signalling-macro (&body body)
  (warn "warning from macro")
  `(progn ,@body))

(defmacro error-signalling-macro (&body body)
  (declare (ignore body))
  (error "error from macro"))


;;; Tests

(with-test (:name (:source-path multiple-value-bind))
  (assert-condition-source-paths
   (multiple-value-bind (1 2) (list 1 2))
   (1)))

(with-test (:name (:source-path multiple-value-setq))
  (assert-condition-source-paths
   (multiple-value-setq (1 2) (list 1 2))
   (1)))

(with-test (:name (:source-path cond))
  (assert-condition-source-paths (cond 1) (1))
  (assert-condition-source-paths (cond #()) (1))
  (assert-condition-source-paths (cond "foo") (1))
  (assert-condition-source-paths (cond (t t) 1) (2)))

(with-test (:name (:source-path do))
  (assert-condition-source-paths (do () 1) ())
  (assert-condition-source-paths (do 1 (t)) ()) ; should be improved
  (assert-condition-source-paths (do (1) (t)) (1))
  (assert-condition-source-paths (do (x (1)) (t)) (1 1)))

(with-test (:name (:source-path do*))
  (assert-condition-source-paths (do* () 1) ())
  (assert-condition-source-paths (do* 1 (t)) ()) ; should be improved
  (assert-condition-source-paths (do* (1) (t)) (1))
  (assert-condition-source-paths (do* (x (1)) (t)) (1 1)))

(with-test (:name (:source-path dolist))
  (assert-condition-source-paths (dolist (x (1 . 2))) (1 1)))

(with-test (:name (:source-path restart-bind))
  (assert-condition-source-paths (restart-bind ((continue (lambda ()) 1))) (0 1))
  (assert-condition-source-paths (restart-bind ((nil (lambda ()) 1))) (0 1)))

(with-test (:name (:source-path restart-case))
  (assert-condition-source-paths (restart-case 1 (1)) (2))
  (assert-condition-source-paths (restart-case 1 (continue 1)) (2)))

(with-test (:name (:source-path handler-bind))
  (assert-condition-source-paths (handler-bind (1)) (1))
  (assert-condition-source-paths
   (handler-bind ((error (lambda (c) (declare (ignore c))) 1)))
   (0 1))

  ;; Not sure what's going on with this one.
  #+nil (assert-condition-source-paths
   (handler-bind ((no-such-type #'continue)))
   (0 1)))

(with-test (:name (:source-path handler-case))
  (assert-condition-source-paths (handler-case 1 (error)) (2)))

(with-test (:name (:source-path case))
  (assert-condition-source-paths (case 1 1) (2))
  (assert-condition-source-paths (case 1 (a :a) 1) (3))
  (assert-condition-source-paths (case 1 (a :a) (a :b)) (3))
  (assert-condition-source-paths (case 1 (t :a) (b :b)) (2)))

(with-test (:name (:source-path declare))
  (assert-condition-source-paths (declare (1)) (1))
  (assert-condition-source-paths (declare (type integer) (1)) (2)))

(with-test (:name (:source-path defclass :slot :type :initform))
  (assert-condition-source-paths
   (defclass foo () ((x :type string :initform 1)))
   (0 3))
  (assert-condition-source-paths
   (defclass foo () ((x :type string :initform (+ 1 5))))
   (4 0 3)))

(with-test (:name (:source-path defclass :slot :type :malformed))
  (assert-condition-source-paths
   (defclass foo () ((x :type 1)))
   (0 3))
  (assert-condition-source-paths
   (defclass foo () ((x :type (null cons))))
   (2 0 3))
  (assert-condition-source-paths
   (define-condition foo () ((x :type 1)))
   (0 3))
  (assert-condition-source-paths
   (define-condition foo () ((x :type (null cons))))
   (2 0 3)))

(with-test (:name (:source-path :&key :initform))
  (assert-condition-source-paths
   (defun foo (&key (x 15))
     (declare (float x))
     x)
   (1 2))
  (assert-condition-source-paths
   (defun foo (&key (x /))
     (declare (float x))
     x)
   (1 2))
  (assert-condition-source-paths
   (defun foo (&key (x (print 16)))
     (declare (float x))
     x)
   (1 1 2)))

(with-test (:name (:source-path :defstruct :initform))
  (assert-condition-source-paths
   (locally (declare (optimize (safety 0)))
    (defstruct f
      (x (print t) :type fixnum)))
   (1 2 2))
  (assert-condition-source-paths
   (locally (declare (optimize (safety 0)))
     (defstruct f
       (x 33 :type cons)))
   (2 2))
  (assert-condition-source-paths
   (locally (declare (optimize (safety 0)))
     (defstruct f
       (x mm)))
   (2 2)))

(with-test (:name (:source-path defgeneric :lambda-list))
  (assert-condition-source-paths
   (defgeneric foo (x x))
   (2)))

(with-test (:name (:source-path defmethod :lambda-list))
  (assert-condition-source-paths
   (defmethod foo (x x))
   (2)))

(defclass deprecated-class () ())
(declaim (deprecated :early "1.0" (type deprecated-class)))
(defgeneric using-deprecated (thing))
(with-test (:name (:source-path defmethod deprecated :specializer))
  (assert-condition-source-paths
   (defmethod using-deprecated ((thing deprecated-class)))
   (0 2)))

(with-test (:name (:source-path defclass deprecated :slot :type))
  (assert-condition-source-paths
   (defclass foo ()
     ((bar :type deprecated-class)))
   (0 3))
  (assert-condition-source-paths
   (define-condition foo ()
     ((bar :type deprecated-class)))
   (0 3)))

(with-test (:name (:source-path defmethod :walk-body))
  (assert-condition-source-paths
   (defmethod using-deprecated ((thing t))
     (progn (warning-signalling-macro)))
   (1 3) (1 3)) ; FIXME duplication is an artifact of DEFMETHOD's implementation
  (assert-condition-source-paths
   (defmethod using-deprecated ((thing t))
     (progn (error-signalling-macro)))
   (1 3)))

;;; In the following two tests, using 1 as the instance avoids
;;; "undefined variable" noise. The strange "slot names" EVEN and ODD
;;; stem from that (and would work with WITH-ACCESSORS).

(with-test (:name (:source-path with-slots))
  ;; instance sub-form
  (assert-condition-source-paths
   (with-slots (even) (the integer 1 2))
   (2))
  ;; slot-entry sub-forms
  (assert-condition-source-paths
   (with-slots (1) 1)
   (1))
  (assert-condition-source-paths
   (with-slots (()) 1)
   (1))
  (assert-condition-source-paths
   (with-slots ((even)) 1)
   (0 1))
  (assert-condition-source-paths
   (with-slots ((even 1)) 1)
   (0 1))
  (assert-condition-source-paths
   (with-slots ((even even) (odd odd 1)) 1)
   (1 1)))

(with-test (:name (:source-path with-accessors))
  ;; instance sub-form
  (assert-condition-source-paths
   (with-accessors ((even evenp)) (the integer 1 2))
   (2))
  ;; slot-entry sub-forms
  (assert-condition-source-paths
   (with-accessors (1) 1)
   (1))
  (assert-condition-source-paths
   (with-accessors (()) 1)
   (1))
  (assert-condition-source-paths
   (with-accessors ((even)) 1)
   (0 1))
  (assert-condition-source-paths
   (with-accessors ((even evenp) (odd oddp 1)) 1)
   (1 1)))

(with-test (:name (:source-path flet :unused))
  (assert-condition-source-paths
   (flet ((f ())))
   (0 1)))

(with-test (:name (:source-path flet :malformed))
  (assert-condition-source-paths
   (flet ((f)))
   (0 1))
  (assert-condition-source-paths
   (flet #())
   ()))

(with-test (:name (:source-path labels :unused))
  (assert-condition-source-paths
   (labels ((f ())))
   (0 1)))

(with-test (:name (:source-path labels :malformed))
  (assert-condition-source-paths
   (labels ((f)))
   (0 1))
  (assert-condition-source-paths
   (labels #())
   ()))

(with-test (:name (:source-path let :malformed))
  (assert-condition-source-paths
   (let ((x 1 2)))
   (0 1))
  (assert-condition-source-paths
   (let #())
   ()))

(with-test (:name (:source-path let* :malformed))
  (assert-condition-source-paths
   (let* ((x 1 2)))
   (0 1))
  (assert-condition-source-paths
   (let* #())
   ()))

(with-test (:name (:source-path typep :unknown-type-specifier))
  (assert-condition-source-paths
   (typep 1 'undefined-type)
   (2)))

(with-test (:name :dead-code-note-after-transforms)
  (assert
   (typep (nth-value 4
                     (checked-compile
                      `(lambda (x)
                         (when nil
                           (funcall x)))))
          '(cons sb-ext:code-deletion-note null))))

(with-test (:name :dead-code-note-after-transforms.2)
  (assert
   (typep (nth-value 4
                     (checked-compile
                      `(lambda (a v)
                         (declare (vector v))
                         (block nil
                           (when (integerp a)
                             (if (integerp a)
                                 (return))
                             (length v))))))
          '(cons sb-ext:code-deletion-note null))))

(with-test (:name :ignore-deleted-subforms)
  (assert-condition-source-paths
   (lambda (x m)
     (when nil
       (funcall x
                (if m
                    (print 20)
                    (print x)))))
   (2 2)))

(with-test (:name :ignore-deleted-subforms.2)
  (assert-condition-source-paths
   (lambda ()
     (when nil
       (let ((z (print 10)))
         z)))
   (2 2)))

(with-test (:name :ignore-deleted-subforms.3)
  (assert-condition-source-paths
   (lambda (x)
     (when x
       (unless x
         (let ((z (print 10)))
           (if z
               10
               (funcall x))))))
   (2 2 2)))

(with-test (:name :ignore-deleted-subforms.4)
  (assert-condition-source-paths
   (lambda (x)
     (when nil
       (if (print 10)
           10
           x)))
   (2 2)))

(with-test (:name (:backquote-comma-error :lp1361502))
  (assert-condition-source-paths
   (lambda () `(1 2 3 4 ,(progn (/ 1 0))))
   (1 1 4 1 2)))

(with-test (:name :dotted-comma-source-paths)
  (assert-condition-source-paths
   (lambda ()
     `(progn . ,(progn (progn (setq x 1)))))
   (1 1 2 1 2)))

(with-test (:name :dotted-double-comma-source-paths)
  (assert-condition-source-paths
   (lambda ()
     ``(progn . ,,(progn (progn (setq x 1)))))
   (1 1 1 2 1 1 2)))

(with-test (:name :dotted-triple-comma-source-paths)
  (assert-condition-source-paths
   (lambda ()
     ```(progn . ,,,(progn (progn (setq x 1)))))
   (1 1 1 1 2 1 1 1 2)))