Fix grammar in lossage message
[sbcl.git] / doc / manual / deprecation.texinfo
blob8f4e8e4b0d0e258d93d5576b2058a9383daa9c72
1 @node Deprecation
2 @comment  node-name,  next,  previous,  up
3 @chapter Deprecation
5 In order to support evolution of interfaces in SBCL as well as in user
6 code, SBCL allows declaring functions, variables and types as
7 deprecated. Users of deprecated things are notified by means of warnings
8 while the deprecated thing in question is still available.
10 This chapter documents the interfaces for being notified when using
11 deprecated thing and declaring things as deprecated, the deprecation
12 process used for SBCL interfaces, and lists legacy interfaces in various
13 stages of deprecation.
15 @dfn{Deprecation} in this context should not be confused with those
16 things the ANSI Common Lisp standard calls @dfn{deprecated}: the
17 entirety of ANSI CL is supported by SBCL, and none of those interfaces
18 are subject to censure.
20 @menu
21 * Why Deprecate?::
22 * The Deprecation Pipeline::
23 * Deprecation Conditions::
24 * Introspecting Deprecation Information::
25 * Deprecation Declaration::
26 * Deprecation Examples::
27 * Deprecated Interfaces in SBCL::
28 @end menu
30 @node Why Deprecate?
31 @comment  node-name,  next,  previous,  up
32 @section Why Deprecate?
33 @cindex Why Deprecate?
35 While generally speaking we try to keep SBCL changes as backwards
36 compatible as feasible, there are situations when existing interfaces
37 are deprecated:
39 @itemize
41 @item @strong{Broken Interfaces}
43 Sometimes it turns out that an interface is sufficiently misdesigned
44 that fixing it would be worse than deprecating it and replacing it
45 with another.
47 This is typically the case when fixing the interface would change its
48 semantics in ways that could break user code subtly: in such cases we
49 may end up considering the obvious breakage caused by deprecation to
50 be preferable.
52 Another example are functions or macros whose current signature makes
53 them hard or impossible to extend in the future: backwards compatible
54 extensions would either make the interface intolerably hairy, or are
55 sometimes outright impossible.
57 @item @strong{Internal Interfaces}
59 SBCL has several internal interfaces that were never meant to be used
60 in user code -- or at least never meant to be used in user code
61 unwilling to track changes to SBCL internals.
63 Ideally we'd like to be free to refactor our own internals as we
64 please, without even going through the hassle of deprecating things.
65 Sometimes, however, it turns out that our internal interfaces have
66 several external users who aren't using them advisedly, but due to
67 misunderstandings regarding their status or stability.
69 Consider a deprecated internal interface a reminder for SBCL
70 maintainers not to delete the thing just yet, even though it is seems
71 unused -- because it has external users.
73 When internal interfaces are deprecated we try our best to provide
74 supported alternatives.
76 @item @strong{Aesthetics & Ease of Maintenance}
78 Sometimes an interface isn't broken or internal, but just inconsistent
79 somehow.
81 This mostly happens only with historical interfaces inherited from
82 CMUCL which often haven't been officially supported in SBCL before, or
83 with new extensions to SBCL that haven't been around for very long in
84 the first place.
86 The alternative would be to keep the suboptimal version around
87 forever, possibly alongside an improved version. Sometimes we may do
88 just that, but because every line of code comes with a maintenance
89 cost, sometimes we opt to deprecate the suboptimal version instead:
90 SBCL doesn't have infinite developer resources.
92 We also believe that sometimes cleaning out legacy interfaces helps
93 keep the whole system more comprehensible to users, and makes
94 introspective tools such as @code{apropos} more useful.
96 @end itemize
98 @node The Deprecation Pipeline
99 @comment  node-name,  next,  previous,  up
100 @section The Deprecation Pipeline
101 @cindex The Deprecation Pipeline
103 SBCL uses a @dfn{deprecation pipeline} with multiple stages: as time
104 goes by, deprecated things move from earlier stages of deprecation to
105 later stages before finally being removed. The intention is making users
106 aware of necessary changes early but allowing a migration to new
107 interfaces at a reasonable pace.
109 Deprecation proceeds in three stages, each lasting approximately a
110 year. In some cases it might move slower or faster, but one year per
111 stage is what we aim at in general. During each stage warnings (and
112 errors) of increasing severity are signaled, which note that the
113 interface is deprecated, and point users towards any replacements when
114 applicable.
116 @enumerate
118 @item @strong{Early Deprecation}
120 During early deprecation the interface is kept in working
121 condition. However, when a thing in this deprecation stage is used, an
122 @sbext{early-deprecation-warning}, which is a @cl{style-warning}, is
123 signaled at compile-time.
125 The internals may change at this stage: typically because the interface
126 is re-implemented on top of its successor. While we try to keep things
127 as backwards-compatible as feasible (taking maintenance costs into account),
128 sometimes semantics change slightly.
130 For example, when the spinlock API was deprecated, spinlock objects ceased
131 to exist, and the whole spinlock API became a synonym for the mutex
132 API -- so code using the spinlock API continued working, but silently
133 switched to mutexes instead. However, if someone relied on
135    @code{(typep lock 'spinlock)}
137 returning @code{NIL} for a mutexes, trouble could ensue.
139 @item @strong{Late Deprecation}
141 During late deprecation the interface remains as it was during early
142 deprecation, but the compile-time warning is upgraded: when a thing in
143 this deprecation stage is used, a @sbext{late-deprecation-warning},
144 which is a full @cl{warning}, is signaled at compile-time.
146 @item @strong{Final Deprecation}
148 During final deprecation the symbols still exist. However, when a thing
149 in this deprecation stage is used, a @sbext{final-deprecation-warning},
150 which is a full @cl{warning}, is signaled at compile-time and an
151 @cl{error} is signaled at run-time.
153 @item @strong{After Final Deprecation}
155 The interface is deleted entirely.
157 @end enumerate
159 @node Deprecation Conditions
160 @comment  node-name,  next,  previous,  up
161 @section Deprecation Conditions
162 @cindex Deprecation Conditions
164 @sbext{deprecation-condition} is the superclass of all
165 deprecation-related warning and error conditions. All common slots and
166 readers are defined in this condition class.
168 @include condition-sb-ext-deprecation-condition.texinfo
170 @include condition-sb-ext-early-deprecation-warning.texinfo
172 @include condition-sb-ext-late-deprecation-warning.texinfo
174 @include condition-sb-ext-final-deprecation-warning.texinfo
176 @include condition-sb-ext-deprecation-error.texinfo
178 @node Introspecting Deprecation Information
179 @comment node-name,  next,  previous,  up
180 @section Introspecting Deprecation Information
181 @cindex Introspecting Deprecation Information
182 @comment TODO @findex @sbcltl{function-information}
183 @comment TODO @findex @sbcltl{variable-information}
185 The deprecation status of functions and variables can be inspected using
186 the @code{sb-cltl2:function-information} and
187 @code{sb-cltl2:variable-information} functions provided by the
188 @code{sb-cltl2} contributed module.
190 @node Deprecation Declaration
191 @comment  node-name,  next,  previous,  up
192 @section Deprecation Declaration
193 @cindex Deprecation Declaration
194 @findex @sbext{deprecated}
196 The @code{sb-ext:deprecated} declaration can be used to declare objects
197 in various namespaces@footnote{See ``namespace'' entry in the glossary
198 of the Common Lisp Hyperspec.} as deprecated.
200 @deffn {Declaration} @sbext{deprecated}
202 Syntax:
203 @example
204 @code{sb-ext:deprecated} stage since @{object-clause@}*
206 stage ::= @{:early | :late | :final@}
208 since ::= @{@var{version} | (@var{software} @var{version})@}
210 object-clause ::= (namespace @var{name} [:replacement @var{replacement}])
212 namespace ::= @{cl:variable | cl:function | cl:type@}
213 @end example
215 @noindent were @var{name} is the name of the deprecated thing,
216 @var{version} and @var{software} are strings describing the version in
217 which the thing has been deprecated and @var{replacement} is a name or a
218 list of names designating things that should be used instead of the
219 deprecated thing.
221 Currently the following namespaces are supported:
223 @table @code
225 @item cl:function
226 Declare functions, compiler-macros or macros as deprecated.
228 @quotation note
229 When declaring a function to be in @code{:final} deprecation, there
230 should be no actual definition of the function as the declaration emits
231 a stub function that signals a @sbext{deprecation-error} at run-time
232 when called.
233 @end quotation
235 @item cl:variable
236 Declare special and global variables, constants and symbol-macros as
237 deprecated.
239 @quotation note
240 When declaring a variable to be in @code{:final} deprecation, there
241 should be no actual definition of the variable as the declaration emits
242 a symbol-macro that signals a @code{sb-ext:deprecation-error} at
243 run-time when accessed.
244 @end quotation
246 @item cl:type
247 Declare named types (i.e. defined via @code{deftype}), standard classes,
248 structure classes and condition classes as deprecated.
250 @end table
251 @end deffn
253 @node Deprecation Examples
254 @comment  node-name,  next,  previous,  up
255 @section Deprecation Examples
256 @cindex Deprecation Examples
258 Marking functions as deprecated:
259 @lisp
260 (defun foo ())
261 (defun bar ())
262 (declaim (deprecated :early ("my-system" "1.2.3")
263                      (function foo :replacement bar)))
265 ;; Remember: do not define the actual function or variable in case of
266 ;; :final deprecation:
267 (declaim (deprecated :final ("my-system" "1.2.3")
268                      (function fez :replacement whoop)))
269 @end lisp
271 @noindent Attempting to use the deprecated functions:
272 @lisp
273 (defun baz ()
274   (foo))
275 | STYLE-WARNING: The function CL-USER::FOO has been deprecated...
276 => BAZ
277 (baz)
278 => NIL ; no error
280 (defun danger ()
281   (fez))
282 | WARNING: The function CL-USER::FEZ has been deprecated...
283 => DANGER
284 (danger)
285 |- ERROR: The function CL-USER::FEZ has been deprecated...
286 @end lisp
288 @node Deprecated Interfaces in SBCL
289 @comment  node-name,  next,  previous,  up
290 @section Deprecated Interfaces in SBCL
292 This sections lists legacy interfaces in various stages of deprecation.
294 @subsection List of Deprecated Interfaces
296 @subsubsection Early Deprecation
298 @itemize
300 @item @strong{SOCKINT::WIN32-*}
302 Deprecated in favor of the corresponding prefix-less functions
303 (e.g. @code{sockint::bind} replaces @code{sockint::win32-bind}) as of
304 1.2.10 in March 2015. Expected to move into late deprecation in August
305 2015.
307 @item @strong{SB-EXT:QUIT}
309 Deprecated in favor of @code{sb-ext:exit} as of 1.0.56.55 in May 2012.
310 Expected to move into late deprecation in May 2013.
312 The design of @code{sb-ext:quit} proved too broken to fix in a
313 backwards-compatible manner, so it had to be deprecated and replaced.
315 Problems with it were manifold: when called in the main thread it
316 cause the entire process to exit. When called in another thread with
317 @code{:recklessly-p} it also caused the entire process to exit.
318 However, when called in another thread without @code{:recklessly-p} it
319 instead caused that thread to terminate abnormally without terminating
320 the process. Its behaviour versus other threads than the one it was
321 called in was also underspecified, and dependent on things such as the
322 current session. Any conceivable change that would have made it sane
323 would also have silently broken code that depended on the old
324 behaviour.
326 @strong{Remedy}
328 For code needing to work with legacy SBCLs, if you were calling
329 @code{quit} with @code{:recklessly-p t}, use
331 @sp 1
332 @lisp
333 (defun system-exit (&optional (code 0))
334   (alien-funcall (extern-alien "exit" (function void int)) code))
335 @end lisp
336 @sp 1
338 instead. In modern SBCLs simply call either @code{sb-posix:exit} or
339 @code{sb-ext:exit}.
341 If you were calling it without @code{:recklessly-p}, be advised
342 that your code may not function as expected when called from threads
343 other than the main one (see above) -- in any case, you can support
344 legacy SBCLs using the following conditionalization:
346 @sp 1
347 @lisp
348 (defun lisp-exit (&key (code 0) abort)
349   #+#.(cl:if (cl:find-symbol "EXIT" :sb-ext) '(and) '(or))
350   ;; Assuming process exit is what is desired -- if thread termination
351   ;; is intended, use SB-THREAD:ABORT-THREAD instead.
352   (sb-ext:exit :code code :abort abort)
353   #-#.(cl:if (cl:find-symbol "EXIT" :sb-ext) '(and) '(or))
354   (sb-ext:quit :unix-status code :recklessly-p abort))
355 @end lisp
356 @sp 1
358 @sp 1
359 @item @strong{SB-UNIX:UNIX-EXIT}
361 Deprecated as of 1.0.56.55 in May 2012. Expected to move into late
362 deprecation in May 2013.
364 When the SBCL process termination was refactored as part of changes that
365 led to @code{sb-ext:quit} being deprecated, @code{sb-unix:unix-exit}
366 ceased to be used internally. Since @code{SB-UNIX} is an internal package
367 not intended for user code to use, and since we're slowly in the process
368 of refactoring things to be less Unix-oriented, @code{sb-unix:unix-exit}
369 was initially deleted as it was no longer used. Unfortunately it became
370 apparent that it was used by several external users, so it was re-instated
371 in deprecated form.
373 While the cost of keeping @code{sb-unix:unix-exit} indefinitely is
374 trivial, the ability to refactor our internals is important, so its
375 deprecation was taken as an opportunity to highlight that
376 @code{SB-UNIX} is an internal package and @code{SB-POSIX} should be
377 used by user-programs instead -- or alternatively calling the foreign
378 function directly if the desired interface doesn't for some reason
379 exist in @code{SB-POSIX}.
381 @strong{Remedy}
383 For code needing to work with legacy SBCLs, use e.g. @code{system-exit}
384 as show above in remedies for @code{sb-ext:quit}. In modern SBCLs
385 simply call either @code{sb-posix:exit} or @code{sb-ext:exit} with
386 appropriate arguments.
388 @sp 1
389 @item @strong{SB-C::MERGE-TAIL-CALLS Compiler Policy}
391 Deprecated as of 1.0.53.74 in November 2011. Expected to move into
392 late deprecation in November 2012.
394 This compiler policy was never functional: SBCL has always merged tail
395 calls when it could, regardless of this policy setting. (It was also
396 never officially supported, but several code-bases have historically
397 used it.)
399 @strong{Remedy}
401 Simply remove the policy declarations. They were never necessary: SBCL
402 always merged tail-calls when possible. To disable tail merging,
403 structure the code to avoid the tail position instead.
405 @sp 1
406 @item @strong{Spinlock API}
408 Deprecated as of 1.0.53.11 in August 2011. Expected to move into late
409 deprecation in August 2012.
411 Spinlocks were an internal interface, but had a number of external users
412 and were hence deprecated instead of being simply deleted.
414 Affected symbols: @code{sb-thread::spinlock},
415 @code{sb-thread::make-spinlock}, @code{sb-thread::with-spinlock},
416 @code{sb-thread::with-recursive-spinlock},
417 @code{sb-thread::get-spinlock}, @code{sb-thread::release-spinlock},
418 @code{sb-thread::spinlock-value}, and @code{sb-thread::spinlock-name}.
420 @strong{Remedy}
422 Use the mutex API instead, or implement spinlocks suiting your needs
423 on top of @code{sb-ext:compare-and-swap},
424 @code{sb-ext:spin-loop-hint}, etc.
426 @item @strong{SOCKINT::HANDLE->FD}, @strong{SOCKINT::FD->HANDLE}
428 Internally deprecated in 2012. Declared deprecated as of 1.2.10 in March
429 2015. Expected to move into final deprecation in August 2015.
431 @end itemize
433 @subsubsection Late Deprecation
435 @itemize
437 @item @strong{SB-THREAD:JOIN-THREAD-ERROR-THREAD and SB-THREAD:INTERRUPT-THREAD-ERROR-THREAD}
439 Deprecated in favor of @code{sb-thread:thread-error-thread} as of
440 1.0.29.17 in June 2009. Expected to move into final deprecation in
441 June 2012.
443 @strong{Remedy}
445 For code that needs to support legacy SBCLs, use e.g.:
447 @sp 1
448 @lisp
449 (defun get-thread-error-thread (condition)
450   #+#.(cl:if (cl:find-symbol "THREAD-ERROR-THREAD" :sb-thread)
451              '(and) '(or))
452   (sb-thread:thread-error-thread condition)
453   #-#.(cl:if (cl:find-symbol "THREAD-ERROR-THREAD" :sb-thread)
454              '(and) '(or))
455   (etypecase condition
456    (sb-thread:join-thread-error
457     (sb-thread:join-thread-error-thread condition))
458    (sb-thread:interrupt-thread-error
459     (sb-thread:interrupt-thread-error-thread condition))))
460 @end lisp
461 @sp 1
463 @sp 1
464 @item @strong{SB-INTROSPECT:FUNCTION-ARGLIST}
466 Deprecated in favor of @code{sb-introspect:function-lambda-list} as of
467 1.0.24.5 in January 2009. Expected to move into final deprecation in
468 January 2012.
470 Renamed for consistency and aesthetics. Functions have lambda-lists,
471 not arglists.
473 @strong{Remedy}
475 For code that needs to support legacy SBCLs, use e.g.:
477 @sp 1
478 @lisp
479 (defun get-function-lambda-list (function)
480   #+#.(cl:if (cl:find-symbol "FUNCTION-LAMBDA-LIST" :sb-introspect)
481              '(and) '(or))
482   (sb-introspect:function-lambda-list function)
483   #-#.(cl:if (cl:find-symbol "FUNCTION-LAMBDA-LIST" :sb-introspect)
484              '(and) '(or))
485   (sb-introspect:function-arglist function))
486 @end lisp
487 @sp 1
489 @sp 1
490 @item @strong{Stack Allocation Policies}
492 Deprecated in favor of @code{sb-ext:*stack-allocate-dynamic-extent*}
493 as of 1.0.19.7 in August 2008, and are expected to be removed in
494 August 2012.
496 Affected symbols: @code{sb-c::stack-allocate-dynamic-extent},
497 @code{sb-c::stack-allocate-vector}, and
498 @code{sb-c::stack-allocate-value-cells}.
500 These compiler policies were never officially supported, and turned
501 out the be a flawed design.
503 @strong{Remedy}
505 For code that needs stack-allocation in legacy SBCLs, conditionalize
506 using:
508 @sp 1
509 @lisp
510 #-#.(cl:if (cl:find-symbol "*STACK-ALLOCATE-DYNAMIC-EXTENT*" :sb-ext)
511            '(and) '(or))
512 (declare (optimize sb-c::stack-allocate-dynamic-extent))
513 @end lisp
514 @sp 1
516 However, unless stack allocation is essential, we recommend simply
517 removing these declarations. Refer to documentation on
518 @code{sb-ext:*stack-allocate-dynamic*} for details on stack allocation
519 control in modern SBCLs.
521 @sp 1
522 @item @strong{SB-SYS:OUTPUT-RAW-BYTES}
524 Deprecated as of 1.0.8.16 in June 2007. Expected to move into final
525 deprecation in June 2012.
527 Internal interface with some external users. Never officially
528 supported, deemed unnecessary in presence of @code{write-sequence} and
529 bivalent streams.
531 @strong{Remedy}
533 Use streams with element-type @code{(unsigned-byte 8)}
534 or @code{:default} -- the latter allowing both binary and
535 character IO -- in conjunction with @code{write-sequence}.
537 @end itemize
539 @subsubsection Final Deprecation
541 No interfaces are currently in final deprecation.
543 @subsection Historical Interfaces
545 The following is a partial list of interfaces present in historical
546 versions of SBCL, which have since then been deleted.
548 @itemize
550 @item @strong{SB-KERNEL:INSTANCE-LAMBDA}
552 Historically needed for CLOS code. Deprecated as of 0.9.3.32 in August
553 2005. Deleted as of 1.0.47.8 in April 2011. Plain @code{lambda} can be
554 used where @code{sb-kernel:instance-lambda} used to be needed.
556 @sp 1
557 @item @strong{SB-ALIEN:DEF-ALIEN-ROUTINE, SB-ALIEN:DEF-ALIEN-VARIABLE, SB-ALIEN:DEF-ALIEN-TYPE}
559 Inherited from CMUCL, naming convention not consistent with preferred
560 SBCL style. Deprecated as of 0.pre7.90 in December 2001. Deleted as of
561 1.0.9.17 in September 2007. Replaced by
562 @code{sb-alien:define-alien-routine},
563 @code{sb-alien:define-alien-variable}, and
564 @code{sb-alien:define-alien-type}.
566 @end itemize