Hello Luis,
Indeed, I am guilty as well of writing a compiler-macro based Lisp-form compiler - as hinted in the
pro@c-l.net post :)
It was one of the motivations to add FTYPEs everywhere. Thank you for the interesting pointer.
As stated in the quoted comment, double-float boxing is one of the reasons why we inline CFFI stubs.
It's not like SBCL could chose a different call convention depending on known type declarations.
Once inlined, there will be no difference for FABS-1 and FABS-2 - with or without type of ftype declarations.
Thank you for the excellent example illustrating this classic issue.
The FTYPEs help SBCL produce better code if the double-float function stubs are not inlined (for some reason).
Also, going back to the post you have mentioned, having FTYPEs on CFFI could help compiler-macros
take informed decisions about code transformations.
E.g. (quickly typed - might not compile)
(declaim (ftype (function (double-float double-float) (values double-float &optional)) pow) (inline pow))
(defcfun pow :double (base :double) (exp :double))
(defun test (&rest nums)
(sum (bind #'pow 2) nums))
Could expand to:
(defun test (&rest nums)
(flet ((#:f1 (#:e1)
(declare (double-float #:e1))
(pow 2 #:e1)))
(declare (ftype (function (double-float) (values double-float &optional)) #:f1)
(dynamic-extent #'#:f1))
(let ((#:a1 (first nums)))
(declare (double-float #:a1))
(dolist (#:n1 (rest nums) #:a1)
(setf #:a1 (+ #:a1 (funcall #'#:f1 #:n1)))))))
Which should allow the compiler to choose an unboxed representation for passing arguments to the internal #'#:f1.
BTW: I am sure SBCL would do just fine with just 1/3rd of the declarations above - but unsure which 1/3rd ... this time of year.
Cheers,