ccl icon indicating copy to clipboard operation
ccl copied to clipboard

Fix https://github.com/Clozure/ccl/issues/350 : set lfun-bits inside set-funcallable-instance-function

Open digikar99 opened this issue 4 years ago • 5 comments
trafficstars

Please review if the bits set in the commit are the relevant ones.

digikar99 avatar May 17 '21 16:05 digikar99

What is the root cause of the error? Why does this particular case of bit-setting fix it?

phoe avatar May 17 '21 16:05 phoe

The most I have been able to figure out so far is that the warning comes from compile-named-function (and nx1-check-call-args, which calls innermost-lfun-bits-keyvect -> lfun-bits, so I presumed the bits themselves are not being set anywhere.)

However, specialization-store does not still work well with this:

(in-package :specialization-store)

(defstore foo (x))
(defspecialization foo (x) t
  x)

(defun foo-caller (x)
  (foo x))

Compiling the last form still yields:

;   In FOO-CALLER: In the call to FOO with arguments (X),
;     1 argument was provided, but at most 0 are accepted
;     by the current global definition of FOO

digikar99 avatar May 17 '21 16:05 digikar99

Is the logand required? Are the bits allowed to be longer than 16 bits?

phoe avatar May 17 '21 16:05 phoe

The logand is required, because at least the first few bits are relevant for the type. If those bits are set, the object no longer remains a adhoc-polymorphic-functions:adhoc-polymorphic-function.

(lfun-bits funcallable-instance (lfun-bits function)) definitely results in a type-error

And the following works, but I'm not sure why it should work:

(lfun-bits funcallable-instance
           (logior (lfun-bits funcallable-instance)
                   (lfun-bits function)))

Change in required arguments seems to change the last 10 bits - or, no...? Something elaborate:

;;; Ignoring the warnings; and using https://www.rapidtables.com/convert/number/decimal-to-binary.html with 2s complement
;;; Is there a CL tool for the same?
CCL> (lfun-bits (lambda (a)))
-528482048 ;=> 11100000100000000000000100000000
CCL> (lfun-bits (lambda (a b)))
-528481792 ;=> 11100000100000000000001000000000
CCL> (lfun-bits (lambda (a b c d)))
-528481280 ;=> 11100000100000000000010000000000
CCL> (lfun-bits (lambda (&key a)))
-528482302 ;=> 11100000100000000000000000000010
CCL> (lfun-bits (lambda (&key a b)))
-528482302 ;=> 11100000100000000000000000000010
CCL> (lfun-bits (lambda (&optional a)))
-528482300 ;=> 11100000100000000000000000000100
CCL> (lfun-bits (lambda (&optional a b)))
-528482296 ;=> 11100000100000000000000000001000
CCL> (lfun-bits (lambda (&optional a b c d)))
-528482288 ;=> 11100000100000000000000000010000
CCL> (lfun-bits (lambda (&rest a)))
-528449536 ;=> 11100000100000001000000000000000
CCL> (lfun-bits (lambda (a &rest a)))
-528449280 ;=> 11100000100000001000000100000000
CCL>                  (length "1000000100000000")
16




digikar99 avatar May 17 '21 17:05 digikar99

;;; Is there a CL tool for the same?

Yes, format ~b:

CL-USER> (format nil "~32,'0B" (mod -528482288 (ash 1 32)))
"11100000100000000000000000010000"

phoe avatar May 17 '21 17:05 phoe