I had a couple stressful but then triumphal mastodon toots.
An ultralisp developer (quicklisp plus ultra) was wondering
how to optionally disable (declare (inline foo)) not/inling
foo.
The SBCL docs say to check the old cmucl docs, they are 95%
right.
I had replied quickly that I think optimize space is used
for this in sbcl. Then I was worrying about needing to
delete or edit that post if I had got i twrong.
Worry spurred me on to actually check. Indeed, the sbcl
extensions package sb-ext has in it an undocumented feature
from cmucl's extensions that lets you turn inlining off and
on using (space 0) and (space 1), and is recommended over
the (declare (inline foo)) idiom (in cmucl).
It's good to use optimize space like this, because optimize
space is not generally useful (inlining for speed is
controlled already and better by optimize speed).
;;; Extension allowing explicitly turning inlining on and
;;; off
(declaim (sb-ext:maybe-inline fmt-string))
;;; Just a user-defined function that compiles to a lot of
;;; ASM
(defun fmt-string (a) (format nil "~a" a))
;;; Define a function using fmt-string, inlining turned off
;;;; toggle inlining off just for this definition
(locally (declare (optimize (space 0)))
(defun thing-1 (x) (fmt-string x)))
;;;; toggle inlining on just for this definition
(locally (declare (optimize (space 1)))
(defun thing-2 (x) (fmt-string x)))
Voila. thing-1 is INLINEd and thing-2 is NOTINLINEd. You can
verify this using (disassemble 'thing-1) and (disassemble
'thing-2).
If you try it with the same local declares, (space 0) and
(space 1) result in the same assembly. But (declaim
(sb-ext:maybe-inline fmt-string)) turned on (space 0) and
(space 1) controls regarding our #'fmt-string function.
I was relieved and happy the undocumented
carried-over-from-cmucl feature in sbcl extensions worked
more or less like I had already said in the first place.
Mastodon thread:
fosstodon.org/@svetlyak40wt/109777982411031270
Publius shared an old BYTE cover of astronauts discovering
lisp secret alien technology on the moon.
PS:
I will NCONC '(ultralisp) to my list of topics for tomorrow.